Merge branch 'master' of github.com:buggins/dlangui

This commit is contained in:
Vadim Lopatin 2015-11-11 18:51:16 +03:00
commit 3980210b6f
11 changed files with 179 additions and 55 deletions

View File

@ -40,7 +40,7 @@
"configurations": [
{
"name": "default",
"versions": ["USE_OPENGL", "EmbedStandardResources", "USE_FREETYPE"],
"versions": ["USE_OPENGL", "EmbedStandardResources", "USE_FREETYPE", "ForceLogs"],
"versions-posix": ["USE_SDL"],
"versions-windows": ["Unicode"],
"dependencies": {
@ -50,7 +50,7 @@
"gl3n": "~>1.2.0"
},
"dependencies-posix": {
"derelict-sdl2": "~>1.9.1"
"derelict-sdl2": "~>1.9.7"
},
"copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll"
@ -59,6 +59,19 @@
"libs/windows/x86/libfreetype-6.dll"
]
},
{
"name": "minimal",
"versions": ["EmbedStandardResources", "ForceLogs"],
"versions-posix": ["USE_SDL", "USE_FREETYPE"],
"versions-windows": ["Unicode"],
"dependencies": {
"dlib": "~>0.7.0",
"gl3n": "~>1.2.0"
},
"dependencies-posix": {
"derelict-sdl2": "~>1.9.7"
}
},
{
"name": "sdl",
"versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"],
@ -88,7 +101,7 @@
"derelict-gl3": "~>1.0.16",
"derelict-ft": "~>1.0.2",
"gl3n": "~>1.2.0",
"dsfml": "~master"
"dsfml": "~>2.1.0"
},
"copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll"

View File

@ -13,7 +13,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources"],
"dependencies": {
"dlangui": "*",
"dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
}
}

View File

@ -13,7 +13,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources", "ForceLogs"],
"dependencies": {
"dlangui": "*"
"dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
}
}

View File

@ -189,8 +189,8 @@ enum : int {
extern (C) int UIAppMain(string[] args) {
// always use trace, even for release builds
Log.setLogLevel(LogLevel.Trace);
Log.setFileLogger(std.stdio.File("ui.log", "w"));
//Log.setLogLevel(LogLevel.Trace);
//Log.setFileLogger(new std.stdio.File("ui.log", "w"));
// resource directory search paths
// not required if only embedded resources are used

View File

@ -11,7 +11,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources"],
"dependencies": {
"dlangui": "*",
"dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
}
}

View File

@ -13,7 +13,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources", "ForceLogs"],
"dependencies": {
"dlangui": "*"
"dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
}
}

View File

@ -76,33 +76,56 @@ Log.e("exception while reading file", e);
----
*/
synchronized class Log {
static:
__gshared private LogLevel logLevel = LogLevel.Info;
__gshared private std.stdio.File logFile;
import core.sync.mutex;
class Log {
static __gshared private LogLevel logLevel = LogLevel.Info;
static __gshared private std.stdio.File * logFile = null;
static __gshared private Mutex mutex = null;
static this() {
Log.mutex = new Mutex();
}
/// Redirects output to stdout
void setStdoutLogger() {
logFile = stdout;
static public void setStdoutLogger() {
synchronized(mutex) {
logFile = &stdout;
}
}
/// Redirects output to stderr
void setStderrLogger() {
logFile = stderr;
static public void setStderrLogger() {
synchronized(mutex) {
logFile = &stderr;
}
}
/// Redirects output to file
void setFileLogger(File file) {
static public void setFileLogger(File * file) {
synchronized(mutex) {
if (logFile !is null && logFile != &stdout && logFile != &stderr) {
logFile.close();
destroy(logFile);
logFile = null;
}
logFile = file;
if (logFile !is null)
logFile.writeln("DlangUI log file");
}
}
/// Sets log level (one of LogLevel)
void setLogLevel(LogLevel level) {
static public void setLogLevel(LogLevel level) {
synchronized(mutex) {
logLevel = level;
i("Log level changed to ", level);
}
}
/// Log level to name helper function
string logLevelName(LogLevel level) {
static public string logLevelName(LogLevel level) {
switch (level) {
case LogLevel.Fatal: return "F";
case LogLevel.Error: return "E";
@ -114,8 +137,8 @@ synchronized class Log {
}
}
/// Log message with arbitrary log level
void log(S...)(LogLevel level, S args) {
if (logLevel >= level && logFile.isOpen) {
static public void log(S...)(LogLevel level, S args) {
if (logLevel >= level && logFile !is null && logFile.isOpen) {
SysTime ts = Clock.currTime();
logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level));
logFile.writeln(args);
@ -123,35 +146,47 @@ synchronized class Log {
}
}
/// Log verbose / trace message
void v(S...)(S args) {
if (logLevel >= LogLevel.Trace && logFile.isOpen)
static public void v(S...)(S args) {
synchronized(mutex) {
if (logLevel >= LogLevel.Trace && logFile !is null && logFile.isOpen)
log(LogLevel.Trace, args);
}
}
/// Log debug message
void d(S...)(S args) {
if (logLevel >= LogLevel.Debug && logFile.isOpen)
static public void d(S...)(S args) {
synchronized(mutex) {
if (logLevel >= LogLevel.Debug && logFile !is null && logFile.isOpen)
log(LogLevel.Debug, args);
}
}
/// Log info message
void i(S...)(S args) {
if (logLevel >= LogLevel.Info && logFile.isOpen)
static public void i(S...)(S args) {
synchronized(mutex) {
if (logLevel >= LogLevel.Info && logFile !is null && logFile.isOpen)
log(LogLevel.Info, args);
}
}
/// Log warn message
void w(S...)(S args) {
if (logLevel >= LogLevel.Warn && logFile.isOpen)
static public void w(S...)(S args) {
synchronized(mutex) {
if (logLevel >= LogLevel.Warn && logFile !is null && logFile.isOpen)
log(LogLevel.Warn, args);
}
}
/// Log error message
void e(S...)(S args) {
if (logLevel >= LogLevel.Error && logFile.isOpen)
static public void e(S...)(S args) {
synchronized(mutex) {
if (logLevel >= LogLevel.Error && logFile !is null && logFile.isOpen)
log(LogLevel.Error, args);
}
}
/// Log fatal error message
void f(S...)(S args) {
if (logLevel >= LogLevel.Fatal && logFile.isOpen)
static public void f(S...)(S args) {
synchronized(mutex) {
if (logLevel >= LogLevel.Fatal && logFile !is null && logFile.isOpen)
log(LogLevel.Fatal, args);
}
}
}
debug {
@ -168,3 +203,4 @@ debug {
void onResourceDestroyWhileShutdown(string resourceName, string objname = null) {
Log.e("Resource leak: destroying resource while shutdown! ", resourceName, " ", objname);
}

View File

@ -9,6 +9,8 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com
*/
module dlangui.graphics.ftfonts;
version(USE_FREETYPE):
import dlangui.graphics.fonts;
import derelict.freetype.ft;
@ -461,6 +463,17 @@ class FreeTypeFont : Font {
@property override bool isNull() { return _files.length == 0; }
}
private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) {
import std.algorithm : equal;
foreach(s; ["FT_New_Face", "FT_Attach_File", "FT_Set_Pixel_Sizes",
"FT_Get_Char_Index", "FT_Load_Glyph", "FT_Done_Face",
"FT_Init_FreeType", "FT_Done_FreeType"]) {
if (symName.equal(s)) // Symbol is used
return derelict.util.exception.ShouldThrow.Yes;
}
// Don't throw for unused symbol
return derelict.util.exception.ShouldThrow.No;
}
/// FreeType based font manager.
class FreeTypeFontManager : FontManager {
@ -513,11 +526,16 @@ class FreeTypeFontManager : FontManager {
this() {
// load dynaic library
try {
Log.v("DerelictFT: Loading FreeType library");
DerelictFT.missingSymbolCallback = &missingSymFunc;
Log.v("DerelictFT: Missing symbols callback is registered");
DerelictFT.load();
} catch (Exception e) {
Log.v("DerelictFT: Loaded");
} catch (Throwable e) {
Log.e("Derelict: cannot load freetype shared library: ", e.msg);
throw new Exception("Cannot load freetype library");
}
Log.v("Initializing FreeType library");
// init library
int error = FT_Init_FreeType(&_library);
if (error) {

View File

@ -1416,8 +1416,11 @@ version (Windows) {
try {
/// testing freetype font manager
version(USE_FREETYPE) {
Log.v("Trying to init FreeType font manager");
import dlangui.graphics.ftfonts;
// trying to create font manager
Log.v("Creating FreeTypeFontManager");
FreeTypeFontManager ftfontMan = new FreeTypeFontManager();
import win32.shlobj;
@ -1444,6 +1447,7 @@ version (Windows) {
}
}
}
Log.v("Registering fonts");
ftfontMan.registerFont(fontsPath ~ "arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "arialbd.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "arialbi.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold);
@ -1590,16 +1594,27 @@ void releaseResourcesOnAppExit() {
void initLogs() {
version (Windows) {
debug {
Log.setFileLogger(std.stdio.File("ui.log", "w"));
Log.setFileLogger(new std.stdio.File("ui.log", "w"));
} else {
// no logging
// no logging unless version ForceLogs is set
version(ForceLogs) {
Log.setFileLogger(new std.stdio.File("ui.log", "w"));
Log.i("Logging to file ui.log");
}
}
} else {
Log.setStderrLogger();
}
debug {
Log.setLogLevel(LogLevel.Trace);
} else {
version(ForceLogs) {
Log.setLogLevel(LogLevel.Trace);
Log.i("Log level: trace");
} else {
Log.setLogLevel(LogLevel.Warn);
Log.i("Log level: warn");
}
}
Log.i("Logger is initialized");
}

View File

@ -45,13 +45,28 @@ version (USE_OPENGL) {
import dlangui.graphics.glsupport;
}
// pragma(lib, "xcb");
// pragma(lib, "xcb-shm");
// pragma(lib, "xcb-image");
// pragma(lib, "X11-xcb");
// pragma(lib, "X11");
// pragma(lib, "dl");
private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) {
import std.algorithm : equal;
foreach(s; ["SDL_DestroyRenderer", "SDL_GL_DeleteContext", "SDL_DestroyWindow", "SDL_PushEvent",
"SDL_GL_SetAttribute", "SDL_GL_CreateContext", "SDL_GetError",
"SDL_CreateWindow", "SDL_CreateRenderer", "SDL_GetWindowSize",
"SDL_GL_GetDrawableSize", "SDL_GetWindowID", "SDL_SetWindowSize",
"SDL_ShowWindow", "SDL_SetWindowTitle", "SDL_CreateRGBSurfaceFrom",
"SDL_SetWindowIcon", "SDL_FreeSurface", "SDL_ShowCursor",
"SDL_SetCursor", "SDL_CreateSystemCursor", "SDL_DestroyTexture",
"SDL_CreateTexture", "SDL_UpdateTexture", "SDL_RenderCopy",
"SDL_GL_SwapWindow", "SDL_GL_MakeCurrent", "SDL_SetRenderDrawColor",
"SDL_RenderClear", "SDL_RenderPresent", "SDL_GetModState",
"SDL_RemoveTimer", "SDL_RemoveTimer", "SDL_PushEvent",
"SDL_RegisterEvents", "SDL_WaitEvent", "SDL_StartTextInput",
"SDL_Quit", "SDL_HasClipboardText", "SDL_GetClipboardText",
"SDL_free", "SDL_SetClipboardText", "SDL_Init"]) {
if (symName.equal(s)) // Symbol is used
return derelict.util.exception.ShouldThrow.Yes;
}
// Don't throw for unused symbol
return derelict.util.exception.ShouldThrow.No;
}
private __gshared uint USER_EVENT_ID;
private __gshared uint TIMER_EVENT_ID;
@ -1276,6 +1291,7 @@ int sdlmain(string[] args) {
currentTheme = createDefaultTheme();
try {
DerelictSDL2.missingSymbolCallback = &missingSymFunc;
// Load the SDL 2 library.
DerelictSDL2.load();
} catch (Exception e) {

View File

@ -905,8 +905,7 @@ int DLANGUIWinMain(void* hInstance, void* hPrevInstance,
char* lpCmdLine, int nCmdShow) {
int result;
try
{
try {
Runtime.initialize();
// call SetProcessDPIAware to support HI DPI - fix by Kapps
@ -973,7 +972,9 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
_cmdShow = iCmdShow;
_hInstance = hInstance;
Log.v("Creating platform");
w32platform = new Win32Platform();
Log.v("Registering window class");
if (!w32platform.registerWndClass()) {
MessageBoxA(null, "This program requires Windows NT!", "DLANGUI App".toStringz, MB_ICONERROR);
return 0;
@ -981,6 +982,7 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
Platform.setInstance(w32platform);
Log.v("Initializing font manager");
if (!initFontManager()) {
Log.e("******************************************************************");
Log.e("No font files found!!!");