platform init/uninit refactoring - move common parts to platform.d

This commit is contained in:
Vadim Lopatin 2015-03-27 09:13:58 +03:00
parent dbd6b84794
commit afea75828e
7 changed files with 291 additions and 252 deletions

View File

@ -25,6 +25,13 @@ Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "tetris", "examples\tetris\t
EndProject
Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "libdparse", "..\dlangide\libdparse\libdparse.visualdproj", "{C4F86459-686F-4841-A6BE-7FCC38DC47FE}"
EndProject
Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "dlanguisfml", "..\dsfml_project\dlanguisfml\dlanguisfml.visualdproj", "{5867E363-515A-4C7E-82C7-D1C1D35F55FC}"
ProjectSection(ProjectDependencies) = postProject
{DB490C05-D9F8-431C-91DD-CEE646A64FDA} = {DB490C05-D9F8-431C-91DD-CEE646A64FDA}
EndProjectSection
EndProject
Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "dsfml", "..\DSFML\dsfml\dsfml.visualdproj", "{DB490C05-D9F8-431C-91DD-CEE646A64FDA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug COFF32|Any CPU = Debug COFF32|Any CPU
@ -269,6 +276,78 @@ Global
{C4F86459-686F-4841-A6BE-7FCC38DC47FE}.TestDebug|Win32.ActiveCfg = Debug|Win32
{C4F86459-686F-4841-A6BE-7FCC38DC47FE}.TestDebug|Win32.Build.0 = Debug|Win32
{C4F86459-686F-4841-A6BE-7FCC38DC47FE}.TestDebug|x64.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug COFF32|Any CPU.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug COFF32|Mixed Platforms.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug COFF32|Mixed Platforms.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug COFF32|Win32.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug COFF32|Win32.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug COFF32|x64.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug GDC|Any CPU.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug GDC|Mixed Platforms.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug GDC|Mixed Platforms.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug GDC|Win32.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug GDC|Win32.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug GDC|x64.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug LDC|Any CPU.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug LDC|Mixed Platforms.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug LDC|Mixed Platforms.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug LDC|Win32.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug LDC|Win32.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug LDC|x64.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug|Any CPU.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug|Win32.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug|Win32.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Debug|x64.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Release|Any CPU.ActiveCfg = Release|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Release|Mixed Platforms.Build.0 = Release|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Release|Win32.ActiveCfg = Release|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Release|Win32.Build.0 = Release|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.Release|x64.ActiveCfg = Release|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.TestDebug|Any CPU.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.TestDebug|Mixed Platforms.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.TestDebug|Mixed Platforms.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.TestDebug|Win32.ActiveCfg = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.TestDebug|Win32.Build.0 = Debug|Win32
{5867E363-515A-4C7E-82C7-D1C1D35F55FC}.TestDebug|x64.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug COFF32|Any CPU.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug COFF32|Mixed Platforms.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug COFF32|Mixed Platforms.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug COFF32|Win32.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug COFF32|Win32.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug COFF32|x64.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug GDC|Any CPU.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug GDC|Mixed Platforms.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug GDC|Mixed Platforms.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug GDC|Win32.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug GDC|Win32.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug GDC|x64.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug LDC|Any CPU.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug LDC|Mixed Platforms.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug LDC|Mixed Platforms.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug LDC|Win32.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug LDC|Win32.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug LDC|x64.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug|Any CPU.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug|Win32.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug|Win32.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Debug|x64.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Release|Any CPU.ActiveCfg = Release|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Release|Mixed Platforms.Build.0 = Release|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Release|Win32.ActiveCfg = Release|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Release|Win32.Build.0 = Release|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.Release|x64.ActiveCfg = Release|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.TestDebug|Any CPU.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.TestDebug|Mixed Platforms.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.TestDebug|Mixed Platforms.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.TestDebug|Win32.ActiveCfg = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.TestDebug|Win32.Build.0 = Debug|Win32
{DB490C05-D9F8-431C-91DD-CEE646A64FDA}.TestDebug|x64.ActiveCfg = Debug|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -260,8 +260,10 @@
<File path="..\de_image\source\png\devisualization\image\png\writer_chunks_IDAT.d" />
</Folder>
<Folder name="dlib_image">
<File path="..\dlib\dlib\image\io\bitio.d" />
<File path="..\dlib\dlib\container\aarray.d" />
<File path="..\dlib\dlib\container\array.d" />
<File path="..\dlib\dlib\image\io\bmp.d" />
<File path="..\dlib\dlib\container\bst.d" />
<File path="..\dlib\dlib\image\color.d" />
<File path="..\dlib\dlib\filesystem\windows\common.d" />
<File path="..\dlib\dlib\core\compound.d" />
@ -271,24 +273,30 @@
<File path="..\dlib\dlib\filesystem\dirrange.d" />
<File path="..\dlib\dlib\filesystem\windows\file.d" />
<File path="..\dlib\dlib\filesystem\filesystem.d" />
<File path="..\dlib\dlib\image\io\huffman.d" />
<File path="..\dlib\dlib\container\hash.d" />
<File path="..\dlib\dlib\coding\huffman.d" />
<File path="..\dlib\dlib\image\io\idct.d" />
<File path="..\dlib\dlib\image\image.d" />
<File path="..\dlib\dlib\math\interpolation.d" />
<File path="..\dlib\dlib\image\io\io.d" />
<File path="..\dlib\dlib\image\io\jpeg.d" />
<File path="..\dlib\dlib\container\linkedlist.d" />
<File path="..\dlib\dlib\math\linsolve.d" />
<File path="..\dlib\dlib\filesystem\local.d" />
<File path="..\dlib\dlib\math\matrix.d" />
<File path="..\dlib\dlib\core\memory.d" />
<File path="..\dlib\dlib\container\package.d" />
<File path="..\dlib\dlib\image\io\png.d" />
<File path="..\dlib\dlib\container\queue.d" />
<File path="..\dlib\dlib\functional\range.d" />
<File path="..\dlib\dlib\container\stack.d" />
<File path="..\dlib\dlib\core\stream.d" />
<File path="..\dlib\dlib\image\io\tga.d" />
<File path="..\dlib\dlib\core\tuple.d" />
<File path="..\dlib\dlib\math\utils.d" />
<File path="..\dlib\dlib\image\io\utils.d" />
<File path="..\dlib\dlib\math\vector.d" />
<File path="..\dlib\dlib\image\io\zstream.d" />
<File path="..\dlib\dlib\coding\zlib.d" />
</Folder>
<Folder name="gl3n">
<File path="..\gl3n\gl3n\aabb.d" />

View File

@ -4,7 +4,6 @@
"homepage": "https://github.com/buggins/dlangui",
"license": "Boost",
"authors": ["Vadim Lopatin"],
"targetType": "none",
"buildRequirements":[
"allowWarnings"
],

View File

@ -1388,3 +1388,179 @@ mixin template APP_ENTRY_POINT() {
}
}
}
version (Windows) {
/// initialize font manager - default implementation
/// On win32 - first it tries to init freetype, and falls back to win32 fonts.
/// On linux/mac - tries to init freetype with some hardcoded font paths
bool initFontManager() {
import win32.windows;
import std.utf;
import dlangui.platforms.windows.win32fonts;
try {
/// testing freetype font manager
version(USE_FREETYPE) {
import dlangui.graphics.ftfonts;
// trying to create font manager
FreeTypeFontManager ftfontMan = new FreeTypeFontManager();
import win32.shlobj;
string fontsPath = "c:\\Windows\\Fonts\\";
static if (true) { // SHGetFolderPathW not found in shell32.lib
WCHAR[MAX_PATH] szPath;
static if (false) {
const CSIDL_FLAG_NO_ALIAS = 0x1000;
const CSIDL_FLAG_DONT_UNEXPAND = 0x2000;
if(SUCCEEDED(SHGetFolderPathW(NULL,
CSIDL_FONTS|CSIDL_FLAG_NO_ALIAS|CSIDL_FLAG_DONT_UNEXPAND,
NULL,
0,
szPath.ptr)))
{
fontsPath = toUTF8(fromWStringz(szPath));
}
} else {
if (GetWindowsDirectory(szPath.ptr, MAX_PATH - 1)) {
fontsPath = toUTF8(fromWStringz(szPath));
Log.i("Windows directory: ", fontsPath);
fontsPath ~= "\\Fonts\\";
Log.i("Fonts directory: ", fontsPath);
}
}
}
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);
ftfontMan.registerFont(fontsPath ~ "ariali.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "cour.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "courbd.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "courbi.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "couri.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "times.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "timesbd.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "timesbi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "timesi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consola.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consolab.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "consolai.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consolaz.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "verdana.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "verdanab.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "verdanai.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "verdanaz.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Bold);
if (ftfontMan.registeredFontCount()) {
FontManager.instance = ftfontMan;
} else {
Log.w("No fonts registered in FreeType font manager. Disabling FreeType.");
destroy(ftfontMan);
}
}
} catch (Exception e) {
Log.e("Cannot create FreeTypeFontManager - falling back to win32");
}
// use Win32 font manager
if (FontManager.instance is null) {
FontManager.instance = new Win32FontManager();
}
return true;
}
} else {
version(USE_FREETYPE) {
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;
}
}
/// initialize font manager - default implementation
/// On win32 - first it tries to init freetype, and falls back to win32 fonts.
/// On linux/mac - tries to init freetype with some hardcoded font paths
bool initFontManager() {
FreeTypeFontManager ft = new FreeTypeFontManager();
// TODO: use FontConfig
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/");
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);
ft.registerFont("/Library/Fonts/Arial Bold.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Arial Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Arial Bold Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Arial Narrow.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Arial Narrow Bold.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Arial Narrow Italic.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Arial Narrow Bold Italic.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Courier New.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Courier New Bold.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Courier New Italic.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Courier New Bold Italic.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Bold);
}
if (!ft.registeredFontCount)
return false;
FontManager.instance = ft;
return true;
}
}
/// call this when all resources are supposed to be freed to report counts of non-freed resources by type
void releaseResourcesOnAppExit() {
//
debug setAppShuttingDownFlag();
currentTheme = null;
drawableCache = null;
imageCache = null;
FontManager.instance = null;
debug {
if (DrawBuf.instanceCount > 0) {
Log.e("Non-zero DrawBuf instance count when exiting: ", DrawBuf.instanceCount);
}
if (Style.instanceCount > 0) {
Log.e("Non-zero Style instance count when exiting: ", Style.instanceCount);
}
if (Widget.instanceCount() > 0) {
Log.e("Non-zero Widget instance count when exiting: ", Widget.instanceCount);
}
if (ImageDrawable.instanceCount > 0) {
Log.e("Non-zero ImageDrawable instance count when exiting: ", ImageDrawable.instanceCount);
}
if (Drawable.instanceCount > 0) {
Log.e("Non-zero Drawable instance count when exiting: ", Drawable.instanceCount);
}
version (USE_FREETYPE) {
import dlangui.graphics.ftfonts;
if (FreeTypeFontFile.instanceCount > 0) {
Log.e("Non-zero FreeTypeFontFile instance count when exiting: ", FreeTypeFontFile.instanceCount);
}
if (FreeTypeFont.instanceCount > 0) {
Log.e("Non-zero FreeTypeFont instance count when exiting: ", FreeTypeFont.instanceCount);
}
}
}
}

View File

@ -1251,94 +1251,20 @@ version (Windows) {
string[] args = splitCmdLine(cmdline);
Log.i("Command line params: ", args);
//_cmdShow = iCmdShow;
//_hInstance = hInstance;
try {
/// testing freetype font manager
version(USE_FREETYPE) {
import dlangui.graphics.ftfonts;
// trying to create font manager
FreeTypeFontManager ftfontMan = new FreeTypeFontManager();
import win32.shlobj;
string fontsPath = "c:\\Windows\\Fonts\\";
static if (true) { // SHGetFolderPathW not found in shell32.lib
WCHAR[MAX_PATH] szPath;
static if (false) {
const CSIDL_FLAG_NO_ALIAS = 0x1000;
const CSIDL_FLAG_DONT_UNEXPAND = 0x2000;
if(SUCCEEDED(SHGetFolderPathW(NULL,
CSIDL_FONTS|CSIDL_FLAG_NO_ALIAS|CSIDL_FLAG_DONT_UNEXPAND,
NULL,
0,
szPath.ptr)))
{
fontsPath = toUTF8(fromWStringz(szPath));
}
} else {
if (GetWindowsDirectory(szPath.ptr, MAX_PATH - 1)) {
fontsPath = toUTF8(fromWStringz(szPath));
Log.i("Windows directory: ", fontsPath);
fontsPath ~= "\\Fonts\\";
Log.i("Fonts directory: ", fontsPath);
}
}
}
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);
ftfontMan.registerFont(fontsPath ~ "ariali.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "cour.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "courbd.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "courbi.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "couri.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "times.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "timesbd.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "timesbi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "timesi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consola.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consolab.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "consolai.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consolaz.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "verdana.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "verdanab.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "verdanai.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "verdanaz.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Bold);
if (ftfontMan.registeredFontCount()) {
FontManager.instance = ftfontMan;
} else {
Log.w("No fonts registered in FreeType font manager. Disabling FreeType.");
destroy(ftfontMan);
}
}
} catch (Exception e) {
Log.e("Cannot create FreeTypeFontManager - falling back to win32");
}
// use Win32 font manager
if (FontManager.instance is null) {
FontManager.instance = new Win32FontManager();
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);
}
return sdlmain(args);
}
} 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)
{
@ -1349,38 +1275,7 @@ version (Windows) {
Log.setLogLevel(LogLevel.Warn);
}
FreeTypeFontManager ft = new FreeTypeFontManager();
// TODO: use FontConfig
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/");
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);
ft.registerFont("/Library/Fonts/Arial Bold.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Arial Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Arial Bold Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Arial Narrow.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Arial Narrow Bold.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Arial Narrow Italic.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Arial Narrow Bold Italic.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Courier New.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Courier New Bold.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Courier New Italic.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Courier New Bold Italic.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Bold);
ft.registerFont("/Library/Fonts/Georgia Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Normal);
ft.registerFont("/Library/Fonts/Georgia Bold Italic.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Bold);
}
if (!ft.registeredFontCount) {
if (!initFontManager()) {
Log.e("******************************************************************");
Log.e("No font files found!!!");
Log.e("Currently, only hardcoded font paths implemented.");
@ -1390,8 +1285,6 @@ version (Windows) {
assert(false);
}
FontManager.instance = ft;
return sdlmain(args);
}
}
@ -1454,38 +1347,8 @@ int sdlmain(string[] args) {
Log.d("Destroying SDL platform");
Platform.setInstance(null);
//
debug setAppShuttingDownFlag();
releaseResourcesOnAppExit();
currentTheme = null;
drawableCache = null;
imageCache = null;
FontManager.instance = null;
debug {
if (DrawBuf.instanceCount > 0) {
Log.e("Non-zero DrawBuf instance count when exiting: ", DrawBuf.instanceCount);
}
if (Style.instanceCount > 0) {
Log.e("Non-zero Style instance count when exiting: ", Style.instanceCount);
}
if (Widget.instanceCount() > 0) {
Log.e("Non-zero Widget instance count when exiting: ", Widget.instanceCount);
}
if (ImageDrawable.instanceCount > 0) {
Log.e("Non-zero ImageDrawable instance count when exiting: ", ImageDrawable.instanceCount);
}
if (Drawable.instanceCount > 0) {
Log.e("Non-zero Drawable instance count when exiting: ", Drawable.instanceCount);
}
version (USE_FREETYPE) {
if (FreeTypeFontFile.instanceCount > 0) {
Log.e("Non-zero FreeTypeFontFile instance count when exiting: ", FreeTypeFontFile.instanceCount);
}
if (FreeTypeFont.instanceCount > 0) {
Log.e("Non-zero FreeTypeFont instance count when exiting: ", FreeTypeFont.instanceCount);
}
}
}
Log.d("Exiting main");
return res;

View File

@ -946,78 +946,16 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
}
Platform.setInstance(w32platform);
// TODO
// Issue #72 Windows fix requeres following call
// SetProcessDPIAware();
// But it's not supported by current win32 D binding
try {
/// testing freetype font manager
version(USE_FREETYPE) {
import dlangui.graphics.ftfonts;
// trying to create font manager
FreeTypeFontManager ftfontMan = new FreeTypeFontManager();
import win32.shlobj;
string fontsPath = "c:\\Windows\\Fonts\\";
static if (true) { // SHGetFolderPathW not found in shell32.lib
WCHAR[MAX_PATH] szPath;
static if (false) {
const CSIDL_FLAG_NO_ALIAS = 0x1000;
const CSIDL_FLAG_DONT_UNEXPAND = 0x2000;
if(SUCCEEDED(SHGetFolderPathW(NULL,
CSIDL_FONTS|CSIDL_FLAG_NO_ALIAS|CSIDL_FLAG_DONT_UNEXPAND,
NULL,
0,
szPath.ptr)))
{
fontsPath = toUTF8(fromWStringz(szPath));
}
} else {
if (GetWindowsDirectory(szPath.ptr, MAX_PATH - 1)) {
fontsPath = toUTF8(fromWStringz(szPath));
Log.i("Windows directory: ", fontsPath);
fontsPath ~= "\\Fonts\\";
Log.i("Fonts directory: ", fontsPath);
}
}
}
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);
ftfontMan.registerFont(fontsPath ~ "ariali.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "cour.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "courbd.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "courbi.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "couri.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "times.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "timesbd.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "timesbi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "timesi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consola.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consolab.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "consolai.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "consolaz.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "verdana.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "verdanab.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "verdanai.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "verdanaz.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Bold);
if (ftfontMan.registeredFontCount()) {
FontManager.instance = ftfontMan;
} else {
Log.w("No fonts registered in FreeType font manager. Disabling FreeType.");
destroy(ftfontMan);
}
}
} catch (Exception e) {
Log.e("Cannot create FreeTypeFontManager - falling back to win32");
}
// use Win32 font manager
if (FontManager.instance is null) {
FontManager.instance = new Win32FontManager();
}
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);
}
currentTheme = createDefaultTheme();
@ -1048,32 +986,8 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
int result = UIAppMain(args);
Log.i("UIAppMain returned ", result);
debug {
if (DrawBuf.instanceCount > 0) {
Log.e("Non-zero DrawBuf instance count when exiting: ", DrawBuf.instanceCount);
}
if (Style.instanceCount > 0) {
Log.e("Non-zero Style instance count when exiting: ", Style.instanceCount);
}
if (Widget.instanceCount() > 0) {
Log.e("Non-zero Widget instance count when exiting: ", Widget.instanceCount);
}
if (ImageDrawable.instanceCount > 0) {
Log.e("Non-zero ImageDrawable instance count when exiting: ", ImageDrawable.instanceCount);
}
if (Drawable.instanceCount > 0) {
Log.e("Non-zero Drawable instance count when exiting: ", Drawable.instanceCount);
}
version (USE_FREETYPE) {
import dlangui.graphics.ftfonts;
if (FreeTypeFontFile.instanceCount > 0) {
Log.e("Non-zero FreeTypeFontFile instance count when exiting: ", FreeTypeFontFile.instanceCount);
}
if (FreeTypeFont.instanceCount > 0) {
Log.e("Non-zero FreeTypeFont instance count when exiting: ", FreeTypeFont.instanceCount);
}
}
}
releaseResourcesOnAppExit();
Log.d("Exiting main");
return result;

View File

@ -994,10 +994,10 @@ class ScrollBar : AbstractSlider, OnClickHandler {
}
}
/// interface - slot for onClick
interface OnDrawHandler {
void doDraw(CanvasWidget canvas, DrawBuf buf, Rect rc);
}
/// interface - slot for onClick
interface OnDrawHandler {
void doDraw(CanvasWidget canvas, DrawBuf buf, Rect rc);
}
/// canvas widget - draw on it either by overriding of doDraw() or by assigning of onDrawListener
class CanvasWidget : Widget {