mirror of https://github.com/buggins/dlangui.git
optimize getting of font list from FontConfig
This commit is contained in:
parent
2c80ba3f23
commit
5a977066a4
|
@ -876,6 +876,12 @@ public Token[] tokenizeML(const(dstring[]) lines) {
|
||||||
return tokenizeML(code);
|
return tokenizeML(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// tokenize source into array of tokens (excluding EOF)
|
||||||
|
public Token[] tokenizeML(const(string[]) lines) {
|
||||||
|
string code = join(lines, "\n");
|
||||||
|
return tokenizeML(code);
|
||||||
|
}
|
||||||
|
|
||||||
/// tokenize source into array of tokens (excluding EOF)
|
/// tokenize source into array of tokens (excluding EOF)
|
||||||
public Token[] tokenizeML(string code) {
|
public Token[] tokenizeML(string code) {
|
||||||
Token[] res;
|
Token[] res;
|
||||||
|
|
|
@ -571,13 +571,14 @@ class FreeTypeFontManager : FontManager {
|
||||||
|
|
||||||
|
|
||||||
/// register freetype font by filename - optinally font properties can be passed if known (e.g. from libfontconfig).
|
/// register freetype font by filename - optinally font properties can be passed if known (e.g. from libfontconfig).
|
||||||
bool registerFont(string filename, FontFamily family = FontFamily.SansSerif, string face = null, bool italic = false, int weight = 0) {
|
bool registerFont(string filename, FontFamily family = FontFamily.SansSerif, string face = null, bool italic = false, int weight = 0, bool dontLoadFile = false) {
|
||||||
if (_library is null)
|
if (_library is null)
|
||||||
return false;
|
return false;
|
||||||
Log.d("FreeTypeFontManager.registerFont ", filename, " ", family, " ", face, " italic=", italic, " weight=", weight);
|
Log.d("FreeTypeFontManager.registerFont ", filename, " ", family, " ", face, " italic=", italic, " weight=", weight);
|
||||||
if (!exists(filename) || !isFile(filename))
|
if (!exists(filename) || !isFile(filename))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!dontLoadFile) {
|
||||||
FreeTypeFontFile font = new FreeTypeFontFile(_library, filename);
|
FreeTypeFontFile font = new FreeTypeFontFile(_library, filename);
|
||||||
if (!font.open(24)) {
|
if (!font.open(24)) {
|
||||||
Log.e("Failed to open font ", filename);
|
Log.e("Failed to open font ", filename);
|
||||||
|
@ -594,6 +595,7 @@ class FreeTypeFontManager : FontManager {
|
||||||
debug(FontResources)Log.d("Using properties from font file: face=", face, " weight=", weight, " italic=", italic);
|
debug(FontResources)Log.d("Using properties from font file: face=", face, " weight=", weight, " italic=", italic);
|
||||||
}
|
}
|
||||||
destroy(font);
|
destroy(font);
|
||||||
|
}
|
||||||
|
|
||||||
FontDef def = FontDef(family, face, italic, weight);
|
FontDef def = FontDef(family, face, italic, weight);
|
||||||
FontFileItem item = findFileItem(def);
|
FontFileItem item = findFileItem(def);
|
||||||
|
@ -777,7 +779,7 @@ bool registerFontConfigFonts(FreeTypeFontManager fontMan) {
|
||||||
else if (style16.indexOf("extralight") >= 0)
|
else if (style16.indexOf("extralight") >= 0)
|
||||||
face ~= " Extra Light";
|
face ~= " Extra Light";
|
||||||
|
|
||||||
if (fontMan.registerFont(fn, fontFamily, face, italic, weight))
|
if (fontMan.registerFont(fn, fontFamily, face, italic, weight, true))
|
||||||
facesFound++;
|
facesFound++;
|
||||||
/*
|
/*
|
||||||
LVFontDef def(
|
LVFontDef def(
|
||||||
|
|
|
@ -4,6 +4,20 @@ import dlangui.widgets.widget;
|
||||||
|
|
||||||
interface WidgetMetadataDef {
|
interface WidgetMetadataDef {
|
||||||
Widget create();
|
Widget create();
|
||||||
|
/// short class name, e.g. "EditLine"
|
||||||
|
string className();
|
||||||
|
/// module name, e.g. "dlangui.widgets.editors"
|
||||||
|
string moduleName();
|
||||||
|
/// full class name, e.g. "dlangui.widgets.editors.EditLine"
|
||||||
|
string fullName();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WidgetSignalMetadata {
|
||||||
|
string name;
|
||||||
|
string typeString;
|
||||||
|
//TypeTuple
|
||||||
|
TypeInfo returnType;
|
||||||
|
TypeInfo paramsType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private __gshared WidgetMetadataDef[string] _registeredWidgets;
|
private __gshared WidgetMetadataDef[string] _registeredWidgets;
|
||||||
|
@ -18,13 +32,43 @@ void registerWidgetMetadata(string name, WidgetMetadataDef metadata) {
|
||||||
_registeredWidgets[name] = metadata;
|
_registeredWidgets[name] = metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WidgetSignalMetadata[] getSignalList(alias T)() {
|
||||||
|
WidgetSignalMetadata[] res;
|
||||||
|
foreach(m; __traits(allMembers, T)) {
|
||||||
|
static if (__traits(compiles, (typeof(__traits(getMember, T, m))))){
|
||||||
|
// skip non-public members
|
||||||
|
static if (__traits(getProtection, __traits(getMember, T, m)) == "public") {
|
||||||
|
static if (__traits(compiles, __traits(getMember, T, m).params_t ) && __traits(compiles, __traits(getMember, T, m).return_t)) {
|
||||||
|
alias typeof(__traits(getMember, T, m)) ti;
|
||||||
|
res ~= WidgetSignalMetadata(m,
|
||||||
|
__traits(getMember, T, m).return_t.stringof ~ __traits(getMember, T, m).params_t.stringof,
|
||||||
|
typeid(__traits(getMember, T, m).return_t),
|
||||||
|
typeid(__traits(getMember, T, m).params_t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
string generateMetadataClass(alias t)() {
|
string generateMetadataClass(alias t)() {
|
||||||
|
//pragma(msg, moduleName!t);
|
||||||
import std.traits;
|
import std.traits;
|
||||||
|
pragma(msg, getSignalList!t);
|
||||||
immutable string metadataClassName = t.stringof ~ "Metadata";
|
immutable string metadataClassName = t.stringof ~ "Metadata";
|
||||||
return "class " ~ metadataClassName ~ " : WidgetMetadataDef { \n" ~
|
return "class " ~ metadataClassName ~ " : WidgetMetadataDef { \n" ~
|
||||||
" override Widget create() {\n" ~
|
" override Widget create() {\n" ~
|
||||||
" return new " ~ moduleName!t ~ "." ~ t.stringof ~ "();\n" ~
|
" return new " ~ moduleName!t ~ "." ~ t.stringof ~ "();\n" ~
|
||||||
" }\n" ~
|
" }\n" ~
|
||||||
|
" override string className() {\n" ~
|
||||||
|
" return \"" ~ t.stringof ~ "\";\n" ~
|
||||||
|
" }\n" ~
|
||||||
|
" override string moduleName() {\n" ~
|
||||||
|
" return \"" ~ moduleName!t ~ "\";\n" ~
|
||||||
|
" }\n" ~
|
||||||
|
" override string fullName() {\n" ~
|
||||||
|
" return \"" ~ moduleName!t ~ "." ~ t.stringof ~ "\";\n" ~
|
||||||
|
" }\n" ~
|
||||||
"}\n";
|
"}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue