mirror of https://github.com/buggins/dlangui.git
Android: freetype support
This commit is contained in:
parent
013e8e956b
commit
67bc536912
|
|
@ -19,6 +19,10 @@ import core.stdc.stdlib : malloc;
|
|||
import core.stdc.string : memset;
|
||||
import dlangui.core.logger;
|
||||
|
||||
import dlangui.widgets.styles;
|
||||
//import dlangui.widgets.widget;
|
||||
import dlangui.platforms.common.platform;
|
||||
|
||||
import EGL.eglplatform : EGLint;
|
||||
import EGL.egl, GLES.gl;
|
||||
|
||||
|
|
@ -26,8 +30,6 @@ import android.input, android.looper : ALooper_pollAll;
|
|||
import android.native_window : ANativeWindow_setBuffersGeometry;
|
||||
import android.sensor, android.log, android.android_native_app_glue;
|
||||
|
||||
//int LOGI(const(char)* fmt, float x, float y, float z) { return __android_log_print(android_LogPriority.ANDROID_LOG_INFO, "native-activity", fmt, x, y, z); }
|
||||
//int LOGW(const(char)* warning) { return __android_log_print(android_LogPriority.ANDROID_LOG_WARN, "native-activity", warning); }
|
||||
|
||||
/**
|
||||
* Our saved state data.
|
||||
|
|
@ -232,12 +234,26 @@ void main(){}
|
|||
* event loop for receiving input events and doing other things.
|
||||
*/
|
||||
extern (C) void android_main(android_app* state) {
|
||||
LOGI("Inside android_main");
|
||||
Log.setLogTag("myApp");
|
||||
Log.setLogLevel(LogLevel.Trace);
|
||||
//import dlangui.platforms.common.startup : initLogs, initFontManager, initResourceManagers, ;
|
||||
LOGI("Inside android_main");
|
||||
initLogs();
|
||||
Log.i("Testing logger - Log.i");
|
||||
Log.fi("Testing logger - Log.fi %d %s", 12345, "asdfgh");
|
||||
|
||||
if (!initFontManager()) {
|
||||
Log.e("******************************************************************");
|
||||
Log.e("No font files found!!!");
|
||||
Log.e("Currently, only hardcoded font paths implemented.");
|
||||
Log.e("Probably you can modify sdlapp.d to add some fonts for your system.");
|
||||
Log.e("TODO: use fontconfig");
|
||||
Log.e("******************************************************************");
|
||||
assert(false);
|
||||
}
|
||||
initResourceManagers();
|
||||
|
||||
currentTheme = createDefaultTheme();
|
||||
|
||||
|
||||
engine engine;
|
||||
|
||||
// Make sure glue isn't stripped.
|
||||
|
|
@ -295,6 +311,13 @@ extern (C) void android_main(android_app* state) {
|
|||
|
||||
// Check if we are exiting.
|
||||
if (state.destroyRequested != 0) {
|
||||
Log.d("Destroying Android platform");
|
||||
Platform.setInstance(null);
|
||||
|
||||
releaseResourcesOnAppExit();
|
||||
|
||||
Log.d("Exiting main");
|
||||
|
||||
engine_term_display(&engine);
|
||||
return;
|
||||
}
|
||||
|
|
@ -313,3 +336,4 @@ extern (C) void android_main(android_app* state) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -558,7 +558,12 @@ class FreeTypeFontManager : FontManager {
|
|||
Log.v("DerelictFT: Loading FreeType library");
|
||||
if (!DerelictFT) {
|
||||
Log.w("DerelictFT is null. Compiler bug? Applying workaround to fix it.");
|
||||
DerelictFT = new DerelictFTLoader;
|
||||
version(Android) {
|
||||
//DerelictFT = new DerelictFTLoader("libft2.so");
|
||||
DerelictFT = new DerelictFTLoader;
|
||||
} else {
|
||||
DerelictFT = new DerelictFTLoader;
|
||||
}
|
||||
}
|
||||
DerelictFT.missingSymbolCallback = &missingSymFunc;
|
||||
Log.v("DerelictFT: Missing symbols callback is registered");
|
||||
|
|
@ -621,9 +626,30 @@ class FreeTypeFontManager : FontManager {
|
|||
}
|
||||
}
|
||||
|
||||
bool registerFont(string filename, bool skipUnknown = false) {
|
||||
import std.path : baseName;
|
||||
FontFamily family = FontFamily.SansSerif;
|
||||
string face = null;
|
||||
bool italic = false;
|
||||
int weight = 0;
|
||||
string name = filename.baseName;
|
||||
switch(name) {
|
||||
case "DroidSans.ttf": face="Droid Sans"; weight = FontWeight.Normal; break;
|
||||
case "DroidSans-Bold.ttf": face="Droid Sans"; weight = FontWeight.Bold; break;
|
||||
case "DroidSansMono.ttf": face="Droid Sans Mono"; weight = FontWeight.Normal; family = FontFamily.MonoSpace; break;
|
||||
case "Roboto-Light.ttf": face="Roboto"; weight = FontWeight.Normal; break;
|
||||
case "Roboto-LightItalic.ttf": face="Roboto"; weight = FontWeight.Normal; italic = true; break;
|
||||
case "Roboto-Bold.ttf": face="Roboto"; weight = FontWeight.Bold; break;
|
||||
case "Roboto-BoldItalic.ttf": face="Roboto"; weight = FontWeight.Bold; italic = true; break;
|
||||
default:
|
||||
if (skipUnknown)
|
||||
return false;
|
||||
}
|
||||
return registerFont(filename, FontFamily.SansSerif, face, italic, weight);
|
||||
}
|
||||
|
||||
/// 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 dontLoadFile = false) {
|
||||
bool registerFont(string filename, FontFamily family, string face = null, bool italic = false, int weight = 0, bool dontLoadFile = false) {
|
||||
if (_library is null)
|
||||
return false;
|
||||
//Log.v("FreeTypeFontManager.registerFont ", filename, " ", family, " ", face, " italic=", italic, " weight=", weight);
|
||||
|
|
|
|||
|
|
@ -107,6 +107,27 @@ version (Windows) {
|
|||
ft.registerFont(path ~ "DejaVuSansMono-BoldOblique.ttf", FontFamily.MonoSpace, "DejaVuSansMono", true, FontWeight.Bold);
|
||||
return true;
|
||||
}
|
||||
|
||||
string[] findFontsInDirectory(string dir) {
|
||||
import dlangui.core.files;
|
||||
import std.file : DirEntry;
|
||||
DirEntry[] entries;
|
||||
if (!listDirectory(dir, false, true, true, ["*.ttf"], entries))
|
||||
return null;
|
||||
|
||||
string[] res;
|
||||
foreach(entry; entries) {
|
||||
res ~= entry.name;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void registerFontsFromDirectory(FreeTypeFontManager ft, string dir) {
|
||||
string[] fontFiles = findFontsInDirectory(dir);
|
||||
Log.d("Fonts in ", dir, " : ", fontFiles);
|
||||
foreach(file; fontFiles)
|
||||
ft.registerFont(file);
|
||||
}
|
||||
|
||||
/// initialize font manager - default implementation
|
||||
/// On win32 - first it tries to init freetype, and falls back to win32 fonts.
|
||||
|
|
@ -117,10 +138,14 @@ version (Windows) {
|
|||
if (!registerFontConfigFonts(ft)) {
|
||||
// TODO: use FontConfig
|
||||
Log.w("No fonts found using FontConfig. Trying hardcoded paths.");
|
||||
ft.registerFonts("/usr/share/fonts/truetype/dejavu/");
|
||||
ft.registerFonts("/usr/share/fonts/TTF/");
|
||||
ft.registerFonts("/usr/share/fonts/dejavu/");
|
||||
ft.registerFonts("/usr/share/fonts/truetype/ttf-dejavu/"); // let it compile on Debian Wheezy
|
||||
version (Android) {
|
||||
ft.registerFontsFromDirectory("/system/fonts");
|
||||
} else {
|
||||
ft.registerFonts("/usr/share/fonts/truetype/dejavu/");
|
||||
ft.registerFonts("/usr/share/fonts/TTF/");
|
||||
ft.registerFonts("/usr/share/fonts/dejavu/");
|
||||
ft.registerFonts("/usr/share/fonts/truetype/ttf-dejavu/"); // let it compile on Debian Wheezy
|
||||
}
|
||||
version(OSX) {
|
||||
ft.registerFont("/Library/Fonts/Arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal, true);
|
||||
ft.registerFont("/Library/Fonts/Arial Bold.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold, true);
|
||||
|
|
@ -195,6 +220,8 @@ extern (C) void initLogs() {
|
|||
Log.i("Logging to file ui.log");
|
||||
}
|
||||
}
|
||||
} else version(Android) {
|
||||
Log.setLogTag("dlangui");
|
||||
} else {
|
||||
Log.setStderrLogger();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue