diff --git a/dub.json b/dub.json index e4afc38c..6635d742 100644 --- a/dub.json +++ b/dub.json @@ -92,7 +92,7 @@ "derelict-gl3": "~master", "derelict-ft": "~master", "de_image:png": ">=0.2.3", - "dlib": ">=0.4.0" + "dlib": "~master" }, "-ddoxFilterArgs": ["--unittest-examples", "--min-protection=Protected", "--ex", "win32.", "--ex", "src.dlangui"] }, diff --git a/src/dlangui/graphics/images.d b/src/dlangui/graphics/images.d index 2df1ca48..960c9647 100644 --- a/src/dlangui/graphics/images.d +++ b/src/dlangui/graphics/images.d @@ -46,20 +46,27 @@ import std.conv : to; ColorDrawBuf loadImage(string filename) { Log.d("Loading image from file " ~ filename); version (USE_DLIBIMAGE) { - SuperImage image = dlib.image.io.io.loadImage(filename); - if (!image) - return null; - int w = image.width; - int h = image.height; - ColorDrawBuf buf = new ColorDrawBuf(w, h); - for (int y = 0; y < h; y++) { - uint * dstLine = buf.scanLine(y); - for (int x = 0; x < w; x++) { - auto pixel = image[x, h - 1 - y].convert(8); - dstLine[x] = makeRGBA(pixel.r, pixel.g, pixel.b, 255 - pixel.a); + try { + SuperImage image = dlib.image.io.io.loadImage(filename); + if (!image) + return null; + int w = image.width; + int h = image.height; + ColorDrawBuf buf = new ColorDrawBuf(w, h); + for (int y = 0; y < h; y++) { + uint * dstLine = buf.scanLine(y); + for (int x = 0; x < w; x++) { + auto pixel = image[x, h - 1 - y].convert(8); + dstLine[x] = makeRGBA(pixel.r, pixel.g, pixel.b, 255 - pixel.a); + } } + destroy(image); + return buf; + } catch (Exception e) { + Log.e("Failed to load image from file ", filename, " using dlib image"); + Log.e(to!string(e)); + return null; } - return buf; } else version (USE_DEIMAGE) { try { Image image = imageFromFile(filename); diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 4829924c..e7c69825 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -1034,7 +1034,11 @@ version (Windows) { int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { Log.setFileLogger(std.stdio.File("ui.log", "w")); - Log.setLogLevel(LogLevel.Trace); + debug { + Log.setLogLevel(LogLevel.Trace); + } else { + Log.setLogLevel(LogLevel.Warn); + } Log.d("myWinMain()"); string basePath = exePath(); Log.i("Current executable: ", exePath()); @@ -1053,18 +1057,37 @@ version (Windows) { } } 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) { Log.setStderrLogger(); - Log.setLogLevel(LogLevel.Warn); + debug { + Log.setLogLevel(LogLevel.Trace); + } else { + Log.setLogLevel(LogLevel.Warn); + } FreeTypeFontManager ft = new FreeTypeFontManager(); // TODO: use FontConfig - ft.registerFont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FontFamily.SansSerif, "DejaVu", false, FontWeight.Normal); - ft.registerFont("/usr/share/fonts/TTF/DejaVuSans.ttf", FontFamily.SansSerif, "DejaVu", false, FontWeight.Normal); - ft.registerFont("/usr/share/fonts/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.registerFonts("/usr/share/fonts/truetype/dejavu/"); + ft.registerFonts("/usr/share/fonts/TTF/"); + ft.registerFonts("/usr/share/fonts/dejavu/"); FontManager.instance = ft; return sdlmain(args);