mirror of https://github.com/buggins/dlangui.git
fix font registration, logging on linux
This commit is contained in:
parent
1fc0db9e02
commit
5282fa9e00
2
dub.json
2
dub.json
|
@ -92,7 +92,7 @@
|
||||||
"derelict-gl3": "~master",
|
"derelict-gl3": "~master",
|
||||||
"derelict-ft": "~master",
|
"derelict-ft": "~master",
|
||||||
"de_image:png": ">=0.2.3",
|
"de_image:png": ">=0.2.3",
|
||||||
"dlib": ">=0.4.0"
|
"dlib": "~master"
|
||||||
},
|
},
|
||||||
"-ddoxFilterArgs": ["--unittest-examples", "--min-protection=Protected", "--ex", "win32.", "--ex", "src.dlangui"]
|
"-ddoxFilterArgs": ["--unittest-examples", "--min-protection=Protected", "--ex", "win32.", "--ex", "src.dlangui"]
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,6 +46,7 @@ import std.conv : to;
|
||||||
ColorDrawBuf loadImage(string filename) {
|
ColorDrawBuf loadImage(string filename) {
|
||||||
Log.d("Loading image from file " ~ filename);
|
Log.d("Loading image from file " ~ filename);
|
||||||
version (USE_DLIBIMAGE) {
|
version (USE_DLIBIMAGE) {
|
||||||
|
try {
|
||||||
SuperImage image = dlib.image.io.io.loadImage(filename);
|
SuperImage image = dlib.image.io.io.loadImage(filename);
|
||||||
if (!image)
|
if (!image)
|
||||||
return null;
|
return null;
|
||||||
|
@ -59,7 +60,13 @@ ColorDrawBuf loadImage(string filename) {
|
||||||
dstLine[x] = makeRGBA(pixel.r, pixel.g, pixel.b, 255 - pixel.a);
|
dstLine[x] = makeRGBA(pixel.r, pixel.g, pixel.b, 255 - pixel.a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
destroy(image);
|
||||||
return buf;
|
return buf;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("Failed to load image from file ", filename, " using dlib image");
|
||||||
|
Log.e(to!string(e));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else version (USE_DEIMAGE) {
|
} else version (USE_DEIMAGE) {
|
||||||
try {
|
try {
|
||||||
Image image = imageFromFile(filename);
|
Image image = imageFromFile(filename);
|
||||||
|
|
|
@ -1034,7 +1034,11 @@ version (Windows) {
|
||||||
int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
|
int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
|
||||||
{
|
{
|
||||||
Log.setFileLogger(std.stdio.File("ui.log", "w"));
|
Log.setFileLogger(std.stdio.File("ui.log", "w"));
|
||||||
|
debug {
|
||||||
Log.setLogLevel(LogLevel.Trace);
|
Log.setLogLevel(LogLevel.Trace);
|
||||||
|
} else {
|
||||||
|
Log.setLogLevel(LogLevel.Warn);
|
||||||
|
}
|
||||||
Log.d("myWinMain()");
|
Log.d("myWinMain()");
|
||||||
string basePath = exePath();
|
string basePath = exePath();
|
||||||
Log.i("Current executable: ", exePath());
|
Log.i("Current executable: ", exePath());
|
||||||
|
@ -1053,18 +1057,37 @@ version (Windows) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
bool registerFonts(FreeTypeFontManager ft, string path) {
|
||||||
|
if (!exists(path) || !isDir(path))
|
||||||
|
return false;
|
||||||
|
ft.registerFont(path ~ "DejaVuSans.ttf", FontFamily.SansSerif, "DejaVuSans", false, FontWeight.Normal);
|
||||||
|
ft.registerFont(path ~ "DejaVuSans-Bold.ttf", FontFamily.SansSerif, "DejaVuSans", false, FontWeight.Bold);
|
||||||
|
ft.registerFont(path ~ "DejaVuSans-Oblique.ttf", FontFamily.SansSerif, "DejaVuSans", true, FontWeight.Normal);
|
||||||
|
ft.registerFont(path ~ "DejaVuSans-BoldOblique.ttf", FontFamily.SansSerif, "DejaVuSans", true, FontWeight.Bold);
|
||||||
|
ft.registerFont(path ~ "DejaVuSansMono.ttf", FontFamily.MonoSpace, "DejaVuSansMono", false, FontWeight.Normal);
|
||||||
|
ft.registerFont(path ~ "DejaVuSansMono-Bold.ttf", FontFamily.MonoSpace, "DejaVuSansMono", false, FontWeight.Bold);
|
||||||
|
ft.registerFont(path ~ "DejaVuSansMono-Oblique.ttf", FontFamily.MonoSpace, "DejaVuSansMono", true, FontWeight.Normal);
|
||||||
|
ft.registerFont(path ~ "DejaVuSansMono-BoldOblique.ttf", FontFamily.MonoSpace, "DejaVuSansMono", true, FontWeight.Bold);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
Log.setStderrLogger();
|
Log.setStderrLogger();
|
||||||
|
debug {
|
||||||
|
Log.setLogLevel(LogLevel.Trace);
|
||||||
|
} else {
|
||||||
Log.setLogLevel(LogLevel.Warn);
|
Log.setLogLevel(LogLevel.Warn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FreeTypeFontManager ft = new FreeTypeFontManager();
|
FreeTypeFontManager ft = new FreeTypeFontManager();
|
||||||
// TODO: use FontConfig
|
// TODO: use FontConfig
|
||||||
ft.registerFont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FontFamily.SansSerif, "DejaVu", false, FontWeight.Normal);
|
Log.w("Only hardcoded paths to TTF fonts are supported under linux so far. TODO: implement fontconfig support.");
|
||||||
ft.registerFont("/usr/share/fonts/TTF/DejaVuSans.ttf", FontFamily.SansSerif, "DejaVu", false, FontWeight.Normal);
|
ft.registerFonts("/usr/share/fonts/truetype/dejavu/");
|
||||||
ft.registerFont("/usr/share/fonts/dejavu/DejaVuSans.ttf", FontFamily.SansSerif, "DejaVu", false, FontWeight.Normal);
|
ft.registerFonts("/usr/share/fonts/TTF/");
|
||||||
|
ft.registerFonts("/usr/share/fonts/dejavu/");
|
||||||
FontManager.instance = ft;
|
FontManager.instance = ft;
|
||||||
|
|
||||||
return sdlmain(args);
|
return sdlmain(args);
|
||||||
|
|
Loading…
Reference in New Issue