1 module dlangui.platforms.common.startup;
2
3 import dlangui.core.config;
4 import dlangui.core.events;
5 import dlangui.widgets.styles;
6 import dlangui.graphics.fonts;
7 import dlangui.graphics.resources;
8 import dlangui.widgets.widget;
9 import std.utf : toUTF32;
10
11 private immutable dstring DLANGUI_VERSION_VALUE = toUTF32(import("DLANGUI_VERSION"));
12 extern(C) @property dstring DLANGUI_VERSION() {
13 return DLANGUI_VERSION_VALUE;
14 }
15
16 static if (BACKEND_GUI) {
17 import dlangui.graphics.ftfonts;
18
19 version (Windows) {
20
21 /// initialize font manager - default implementation
22 /// On win32 - first it tries to init freetype, and falls back to win32 fonts.
23 /// On linux/mac - tries to init freetype with some hardcoded font paths
24 extern(C) bool initFontManager() {
25 import core.sys.windows.windows;
26 import std.utf;
27 import dlangui.platforms.windows.win32fonts;
28 try {
29 /// testing freetype font manager
30 static if (ENABLE_FREETYPE) {
31 Log.v("Trying to init FreeType font manager");
32
33 import dlangui.graphics.ftfonts;
34 // trying to create font manager
35 Log.v("Creating FreeTypeFontManager");
36 FreeTypeFontManager ftfontMan = new FreeTypeFontManager();
37
38 import core.sys.windows.shlobj;
39 string fontsPath = "c:\\Windows\\Fonts\\";
40 static if (true) { // SHGetFolderPathW not found in shell32.lib
41 WCHAR[MAX_PATH] szPath;
42 static if (false) {
43 const CSIDL_FLAG_NO_ALIAS = 0x1000;
44 const CSIDL_FLAG_DONT_UNEXPAND = 0x2000;
45 if(SUCCEEDED(SHGetFolderPathW(NULL,
46 CSIDL_FONTS|CSIDL_FLAG_NO_ALIAS|CSIDL_FLAG_DONT_UNEXPAND,
47 NULL,
48 0,
49 szPath.ptr)))
50 {
51 fontsPath = toUTF8(fromWStringz(szPath));
52 }
53 } else {
54 if (GetWindowsDirectory(szPath.ptr, MAX_PATH - 1)) {
55 fontsPath = toUTF8(fromWStringz(szPath));
56 Log.i("Windows directory: ", fontsPath);
57 fontsPath ~= "\\Fonts\\";
58 Log.i("Fonts directory: ", fontsPath);
59 }
60 }
61 }
62 Log.v("Registering fonts");
63 // arial
64 ftfontMan.registerFont(fontsPath ~ "arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal);
65 ftfontMan.registerFont(fontsPath ~ "arialbd.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold);
66 ftfontMan.registerFont(fontsPath ~ "arialbi.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold);
67 ftfontMan.registerFont(fontsPath ~ "ariali.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal);
68 // arial unicode ms
69 ftfontMan.registerFont(fontsPath ~ "arialni.ttf", FontFamily.SansSerif, "Arial Unicode MS", false, FontWeight.Normal);
70 // arial narrow
71 ftfontMan.registerFont(fontsPath ~ "arialn.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Normal);
72 ftfontMan.registerFont(fontsPath ~ "arialnb.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Bold);
73 ftfontMan.registerFont(fontsPath ~ "arialnbi.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Bold);
74 ftfontMan.registerFont(fontsPath ~ "arialni.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Normal);
75 // calibri
76 ftfontMan.registerFont(fontsPath ~ "calibri.ttf", FontFamily.SansSerif, "Calibri", false, FontWeight.Normal);
77 ftfontMan.registerFont(fontsPath ~ "calibrib.ttf", FontFamily.SansSerif, "Calibri", false, FontWeight.Bold);
78 ftfontMan.registerFont(fontsPath ~ "calibriz.ttf", FontFamily.SansSerif, "Calibri", true, FontWeight.Bold);
79 ftfontMan.registerFont(fontsPath ~ "calibrii.ttf", FontFamily.SansSerif, "Calibri", true, FontWeight.Normal);
80 // cambria
81 ftfontMan.registerFont(fontsPath ~ "cambria.ttc", FontFamily.SansSerif, "Cambria", false, FontWeight.Normal);
82 ftfontMan.registerFont(fontsPath ~ "cambriab.ttf", FontFamily.SansSerif, "Cambria", false, FontWeight.Bold);
83 ftfontMan.registerFont(fontsPath ~ "cambriaz.ttf", FontFamily.SansSerif, "Cambria", true, FontWeight.Bold);
84 ftfontMan.registerFont(fontsPath ~ "cambriai.ttf", FontFamily.SansSerif, "Cambria", true, FontWeight.Normal);
85 // candara
86 ftfontMan.registerFont(fontsPath ~ "Candara.ttf", FontFamily.SansSerif, "Candara", false, FontWeight.Normal);
87 ftfontMan.registerFont(fontsPath ~ "Candarab.ttf", FontFamily.SansSerif, "Candara", false, FontWeight.Bold);
88 ftfontMan.registerFont(fontsPath ~ "Candaraz.ttf", FontFamily.SansSerif, "Candara", true, FontWeight.Bold);
89 ftfontMan.registerFont(fontsPath ~ "Candarai.ttf", FontFamily.SansSerif, "Candara", true, FontWeight.Normal);
90 // century
91 ftfontMan.registerFont(fontsPath ~ "CENTURY.TTF", FontFamily.Serif, "Century", false, FontWeight.Normal);
92 // comic sans ms
93 ftfontMan.registerFont(fontsPath ~ "comic.ttf", FontFamily.Serif, "Comic Sans MS", false, FontWeight.Normal);
94 ftfontMan.registerFont(fontsPath ~ "comicbd.ttf", FontFamily.Serif, "Comic Sans MS", false, FontWeight.Bold);
95 // constantia
96 ftfontMan.registerFont(fontsPath ~ "constan.ttf", FontFamily.Serif, "Constantia", false, FontWeight.Normal);
97 ftfontMan.registerFont(fontsPath ~ "constanb.ttf", FontFamily.Serif, "Constantia", false, FontWeight.Bold);
98 ftfontMan.registerFont(fontsPath ~ "constanz.ttf", FontFamily.Serif, "Constantia", true, FontWeight.Bold);
99 ftfontMan.registerFont(fontsPath ~ "constani.ttf", FontFamily.Serif, "Constantia", true, FontWeight.Normal);
100 // corbel
101 ftfontMan.registerFont(fontsPath ~ "corbel.ttf", FontFamily.SansSerif, "Corbel", false, FontWeight.Normal);
102 ftfontMan.registerFont(fontsPath ~ "corbelb.ttf", FontFamily.SansSerif, "Corbel", false, FontWeight.Bold);
103 ftfontMan.registerFont(fontsPath ~ "corbelz.ttf", FontFamily.SansSerif, "Corbel", true, FontWeight.Bold);
104 ftfontMan.registerFont(fontsPath ~ "corbeli.ttf", FontFamily.SansSerif, "Corbel", true, FontWeight.Normal);
105 // courier new
106 ftfontMan.registerFont(fontsPath ~ "cour.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Normal);
107 ftfontMan.registerFont(fontsPath ~ "courbd.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Bold);
108 ftfontMan.registerFont(fontsPath ~ "courbi.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Bold);
109 ftfontMan.registerFont(fontsPath ~ "couri.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Normal);
110 // franklin gothic book
111 ftfontMan.registerFont(fontsPath ~ "frank.ttf", FontFamily.SansSerif, "Franklin Gothic Book", false, FontWeight.Normal);
112 // times new roman
113 ftfontMan.registerFont(fontsPath ~ "times.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Normal);
114 ftfontMan.registerFont(fontsPath ~ "timesbd.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Bold);
115 ftfontMan.registerFont(fontsPath ~ "timesbi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Bold);
116 ftfontMan.registerFont(fontsPath ~ "timesi.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Normal);
117 // consolas
118 ftfontMan.registerFont(fontsPath ~ "consola.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Normal);
119 ftfontMan.registerFont(fontsPath ~ "consolab.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Bold);
120 ftfontMan.registerFont(fontsPath ~ "consolai.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Normal);
121 ftfontMan.registerFont(fontsPath ~ "consolaz.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Bold);
122 // garamond
123 ftfontMan.registerFont(fontsPath ~ "GARA.TTF", FontFamily.Serif, "Garamond", false, FontWeight.Normal);
124 ftfontMan.registerFont(fontsPath ~ "GARABD.TTF", FontFamily.Serif, "Garamond", false, FontWeight.Bold);
125 ftfontMan.registerFont(fontsPath ~ "GARAIT.TTF", FontFamily.Serif, "Garamond", true, FontWeight.Normal);
126 // georgia
127 ftfontMan.registerFont(fontsPath ~ "georgia.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Normal);
128 ftfontMan.registerFont(fontsPath ~ "georgiab.ttf", FontFamily.SansSerif, "Georgia", false, FontWeight.Bold);
129 ftfontMan.registerFont(fontsPath ~ "georgiaz.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Bold);
130 ftfontMan.registerFont(fontsPath ~ "georgiai.ttf", FontFamily.SansSerif, "Georgia", true, FontWeight.Normal);
131 // KaiTi
132 ftfontMan.registerFont(fontsPath ~ "kaiu.ttf", FontFamily.SansSerif, "KaiTi", false, FontWeight.Normal);
133 // Lucida Console
134 ftfontMan.registerFont(fontsPath ~ "lucon.ttf", FontFamily.MonoSpace, "Lucida Console", false, FontWeight.Normal);
135 // malgun gothic
136 ftfontMan.registerFont(fontsPath ~ "malgun.ttf", FontFamily.Serif, "Malgun Gothic", false, FontWeight.Normal);
137 ftfontMan.registerFont(fontsPath ~ "malgunbd.ttf", FontFamily.Serif, "Malgun Gothic", false, FontWeight.Bold);
138 // meiryo
139 ftfontMan.registerFont(fontsPath ~ "meiryo.ttc", FontFamily.Serif, "Meiryo", false, FontWeight.Normal);
140 ftfontMan.registerFont(fontsPath ~ "meiryob.ttc", FontFamily.Serif, "Meiryo", false, FontWeight.Bold);
141 // ms mhei
142 ftfontMan.registerFont(fontsPath ~ "MSMHei.ttf", FontFamily.Serif, "Microsoft MHei", false, FontWeight.Normal);
143 ftfontMan.registerFont(fontsPath ~ "MSMHei-Bold.ttf", FontFamily.Serif, "Microsoft MHei", false, FontWeight.Bold);
144 // ms neo gothic
145 ftfontMan.registerFont(fontsPath ~ "MSNeoGothic.ttf", FontFamily.Serif, "Microsoft NeoGothic", false, FontWeight.Normal);
146 ftfontMan.registerFont(fontsPath ~ "MSNeoGothic-Bold.ttf", FontFamily.Serif, "Microsoft NeoGothic", false, FontWeight.Bold);
147 // palatino linotype
148 ftfontMan.registerFont(fontsPath ~ "pala.ttf", FontFamily.Serif, "Palatino Linotype", false, FontWeight.Normal);
149 ftfontMan.registerFont(fontsPath ~ "palab.ttf", FontFamily.Serif, "Palatino Linotype", false, FontWeight.Bold);
150 ftfontMan.registerFont(fontsPath ~ "palabi.ttf", FontFamily.Serif, "Palatino Linotype", true, FontWeight.Bold);
151 ftfontMan.registerFont(fontsPath ~ "palai.ttf", FontFamily.Serif, "Palatino Linotype", true, FontWeight.Normal);
152 // segoeui
153 ftfontMan.registerFont(fontsPath ~ "segoeui.ttf", FontFamily.SansSerif, "Segoe UI", false, FontWeight.Normal);
154 ftfontMan.registerFont(fontsPath ~ "segoeuib.ttf", FontFamily.SansSerif, "Segoe UI", false, FontWeight.Bold);
155 ftfontMan.registerFont(fontsPath ~ "segoeuiz.ttf", FontFamily.SansSerif, "Segoe UI", true, FontWeight.Bold);
156 ftfontMan.registerFont(fontsPath ~ "segoeuii.ttf", FontFamily.SansSerif, "Segoe UI", true, FontWeight.Normal);
157 // SimSun
158 ftfontMan.registerFont(fontsPath ~ "simsun.ttc", FontFamily.SansSerif, "SimSun", false, FontWeight.Normal);
159 ftfontMan.registerFont(fontsPath ~ "simsunb.ttf", FontFamily.SansSerif, "SimSun", false, FontWeight.Bold);
160 // tahoma
161 ftfontMan.registerFont(fontsPath ~ "tahoma.ttf", FontFamily.SansSerif, "Tahoma", false, FontWeight.Normal);
162 ftfontMan.registerFont(fontsPath ~ "tahomabd.ttf", FontFamily.SansSerif, "Tahoma", false, FontWeight.Bold);
163 // trebuchet ms
164 ftfontMan.registerFont(fontsPath ~ "trebuc.ttf", FontFamily.SansSerif, "Trebuchet MS", false, FontWeight.Normal);
165 ftfontMan.registerFont(fontsPath ~ "trebucbd.ttf", FontFamily.SansSerif, "Trebuchet MS", false, FontWeight.Bold);
166 ftfontMan.registerFont(fontsPath ~ "trebucbi.ttf", FontFamily.SansSerif, "Trebuchet MS", true, FontWeight.Bold);
167 ftfontMan.registerFont(fontsPath ~ "trebucit.ttf", FontFamily.SansSerif, "Trebuchet MS", true, FontWeight.Normal);
168 // verdana
169 ftfontMan.registerFont(fontsPath ~ "verdana.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Normal);
170 ftfontMan.registerFont(fontsPath ~ "verdanab.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Bold);
171 ftfontMan.registerFont(fontsPath ~ "verdanai.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Normal);
172 ftfontMan.registerFont(fontsPath ~ "verdanaz.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Bold);
173 if (ftfontMan.registeredFontCount()) {
174 FontManager.instance = ftfontMan;
175 } else {
176 Log.w("No fonts registered in FreeType font manager. Disabling FreeType.");
177 destroy(ftfontMan);
178 }
179 }
180 } catch (Exception e) {
181 Log.e("Cannot create FreeTypeFontManager - falling back to win32");
182 }
183
184 // use Win32 font manager
185 if (FontManager.instance is null) {
186 FontManager.instance = new Win32FontManager();
187 }
188 return true;
189 }
190
191 } else {
192 import dlangui.graphics.ftfonts;
193 bool registerFonts(FreeTypeFontManager ft, string path) {
194 import std.file;
195 if (!exists(path) || !isDir(path))
196 return false;
197 ft.registerFont(path ~ "DejaVuSans.ttf", FontFamily.SansSerif, "DejaVuSans", false, FontWeight.Normal);
198 ft.registerFont(path ~ "DejaVuSans-Bold.ttf", FontFamily.SansSerif, "DejaVuSans", false, FontWeight.Bold);
199 ft.registerFont(path ~ "DejaVuSans-Oblique.ttf", FontFamily.SansSerif, "DejaVuSans", true, FontWeight.Normal);
200 ft.registerFont(path ~ "DejaVuSans-BoldOblique.ttf", FontFamily.SansSerif, "DejaVuSans", true, FontWeight.Bold);
201 ft.registerFont(path ~ "DejaVuSansMono.ttf", FontFamily.MonoSpace, "DejaVuSansMono", false, FontWeight.Normal);
202 ft.registerFont(path ~ "DejaVuSansMono-Bold.ttf", FontFamily.MonoSpace, "DejaVuSansMono", false, FontWeight.Bold);
203 ft.registerFont(path ~ "DejaVuSansMono-Oblique.ttf", FontFamily.MonoSpace, "DejaVuSansMono", true, FontWeight.Normal);
204 ft.registerFont(path ~ "DejaVuSansMono-BoldOblique.ttf", FontFamily.MonoSpace, "DejaVuSansMono", true, FontWeight.Bold);
205 return true;
206 }
207
208 string[] findFontsInDirectory(string dir) {
209 import dlangui.core.files;
210 import std.file : DirEntry;
211 DirEntry[] entries;
212 try {
213 entries = listDirectory(dir, AttrFilter.files, ["*.ttf"]);
214 } catch(Exception e) {
215 return null;
216 }
217
218 string[] res;
219 foreach(entry; entries) {
220 res ~= entry.name;
221 }
222 return res;
223 }
224
225 void registerFontsFromDirectory(FreeTypeFontManager ft, string dir) {
226 string[] fontFiles = findFontsInDirectory(dir);
227 Log.d("Fonts in ", dir, " : ", fontFiles);
228 foreach(file; fontFiles)
229 ft.registerFont(file);
230 }
231
232 /// initialize font manager - default implementation
233 /// On win32 - first it tries to init freetype, and falls back to win32 fonts.
234 /// On linux/mac - tries to init freetype with some hardcoded font paths
235 extern(C) bool initFontManager() {
236 FreeTypeFontManager ft = new FreeTypeFontManager();
237
238 if (!registerFontConfigFonts(ft)) {
239 // TODO: use FontConfig
240 Log.w("No fonts found using FontConfig. Trying hardcoded paths.");
241 version (Android) {
242 ft.registerFontsFromDirectory("/system/fonts");
243 } else {
244 ft.registerFonts("/usr/share/fonts/truetype/dejavu/");
245 ft.registerFonts("/usr/share/fonts/TTF/");
246 ft.registerFonts("/usr/share/fonts/dejavu/");
247 ft.registerFonts("/usr/share/fonts/truetype/ttf-dejavu/"); // let it compile on Debian Wheezy
248 }
249 version(OSX) {
250 ft.registerFont("/Library/Fonts/Arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal, true);
251 ft.registerFont("/Library/Fonts/Arial Bold.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold, true);
252 ft.registerFont("/Library/Fonts/Arial Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal, true);
253 ft.registerFont("/Library/Fonts/Arial Bold Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold, true);
254 ft.registerFont("/Library/Fonts/Arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal, true);
255 ft.registerFont("/Library/Fonts/Arial Bold.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold, true);
256 ft.registerFont("/Library/Fonts/Arial Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal, true);
257 ft.registerFont("/Library/Fonts/Arial Bold Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold, true);
258 ft.registerFont("/Library/Fonts/Arial Narrow.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Normal, true);
259 ft.registerFont("/Library/Fonts/Arial Narrow Bold.ttf", FontFamily.SansSerif, "Arial Narrow", false, FontWeight.Bold, true);
260 ft.registerFont("/Library/Fonts/Arial Narrow Italic.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Normal, true);
261 ft.registerFont("/Library/Fonts/Arial Narrow Bold Italic.ttf", FontFamily.SansSerif, "Arial Narrow", true, FontWeight.Bold, true);
262 ft.registerFont("/Library/Fonts/Courier New.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Normal, true);
263 ft.registerFont("/Library/Fonts/Courier New Bold.ttf", FontFamily.MonoSpace, "Courier New", false, FontWeight.Bold, true);
264 ft.registerFont("/Library/Fonts/Courier New Italic.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Normal, true);
265 ft.registerFont("/Library/Fonts/Courier New Bold Italic.ttf", FontFamily.MonoSpace, "Courier New", true, FontWeight.Bold, true);
266 ft.registerFont("/Library/Fonts/Georgia.ttf", FontFamily.Serif, "Georgia", false, FontWeight.Normal, true);
267 ft.registerFont("/Library/Fonts/Georgia Bold.ttf", FontFamily.Serif, "Georgia", false, FontWeight.Bold, true);
268 ft.registerFont("/Library/Fonts/Georgia Italic.ttf", FontFamily.Serif, "Georgia", true, FontWeight.Normal, true);
269 ft.registerFont("/Library/Fonts/Georgia Bold Italic.ttf", FontFamily.Serif, "Georgia", true, FontWeight.Bold, true);
270 ft.registerFont("/Library/Fonts/Comic Sans MS.ttf", FontFamily.SansSerif, "Comic Sans", false, FontWeight.Normal, true);
271 ft.registerFont("/Library/Fonts/Comic Sans MS Bold.ttf", FontFamily.SansSerif, "Comic Sans", false, FontWeight.Bold, true);
272 ft.registerFont("/Library/Fonts/Tahoma.ttf", FontFamily.SansSerif, "Tahoma", false, FontWeight.Normal, true);
273 ft.registerFont("/Library/Fonts/Tahoma Bold.ttf", FontFamily.SansSerif, "Tahoma", false, FontWeight.Bold, true);
274
275 ft.registerFont("/Library/Fonts/Microsoft/Arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal, true);
276 ft.registerFont("/Library/Fonts/Microsoft/Arial Bold.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold, true);
277 ft.registerFont("/Library/Fonts/Microsoft/Arial Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Normal, true);
278 ft.registerFont("/Library/Fonts/Microsoft/Arial Bold Italic.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold, true);
279 ft.registerFont("/Library/Fonts/Microsoft/Calibri.ttf", FontFamily.SansSerif, "Calibri", false, FontWeight.Normal, true);
280 ft.registerFont("/Library/Fonts/Microsoft/Calibri Bold.ttf", FontFamily.SansSerif, "Calibri", false, FontWeight.Bold, true);
281 ft.registerFont("/Library/Fonts/Microsoft/Calibri Italic.ttf", FontFamily.SansSerif, "Calibri", true, FontWeight.Normal, true);
282 ft.registerFont("/Library/Fonts/Microsoft/Calibri Bold Italic.ttf", FontFamily.SansSerif, "Calibri", true, FontWeight.Bold, true);
283 ft.registerFont("/Library/Fonts/Microsoft/Times New Roman.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Normal, true);
284 ft.registerFont("/Library/Fonts/Microsoft/Times New Roman Bold.ttf", FontFamily.Serif, "Times New Roman", false, FontWeight.Bold, true);
285 ft.registerFont("/Library/Fonts/Microsoft/Times New Roman Italic.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Normal, true);
286 ft.registerFont("/Library/Fonts/Microsoft/Times New Roman Bold Italic.ttf", FontFamily.Serif, "Times New Roman", true, FontWeight.Bold, true);
287 ft.registerFont("/Library/Fonts/Microsoft/Verdana.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Normal, true);
288 ft.registerFont("/Library/Fonts/Microsoft/Verdana Bold.ttf", FontFamily.SansSerif, "Verdana", false, FontWeight.Bold, true);
289 ft.registerFont("/Library/Fonts/Microsoft/Verdana Italic.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Normal, true);
290 ft.registerFont("/Library/Fonts/Microsoft/Verdana Bold Italic.ttf", FontFamily.SansSerif, "Verdana", true, FontWeight.Bold, true);
291
292 ft.registerFont("/Library/Fonts/Microsoft/Consolas.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Normal, true);
293 ft.registerFont("/Library/Fonts/Microsoft/Consolas Bold.ttf", FontFamily.MonoSpace, "Consolas", false, FontWeight.Bold, true);
294 ft.registerFont("/Library/Fonts/Microsoft/Consolas Italic.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Normal, true);
295 ft.registerFont("/Library/Fonts/Microsoft/Consolas Bold Italic.ttf", FontFamily.MonoSpace, "Consolas", true, FontWeight.Bold, true);
296
297 ft.registerFont("/System/Library/Fonts/Menlo.ttc", FontFamily.MonoSpace, "Menlo", false, FontWeight.Normal, true);
298 }
299 }
300
301 if (!ft.registeredFontCount)
302 return false;
303
304 FontManager.instance = ft;
305 return true;
306 }
307 }
308 }
309
310 /// initialize logging (for win32 - to file ui.log, for other platforms - stderr; log level is TRACE for debug builds, and WARN for release builds)
311 extern (C) void initLogs() {
312 static if (BACKEND_CONSOLE) {
313 static import std.stdio;
314 debug {
315 Log.setFileLogger(new std.stdio.File("ui.log", "w"));
316 Log.i("Debug build. Logging to file ui.log");
317 Log.setLogLevel(LogLevel.Trace);
318 } else {
319 // no logging unless version ForceLogs is set
320 version(ForceLogs) {
321 Log.setFileLogger(new std.stdio.File("ui.log", "w"));
322 Log.i("Logging to file ui.log");
323 //Log.setLogLevel(LogLevel.Trace);
324 }
325 }
326 } else {
327 static import std.stdio;
328 version (Windows) {
329 debug {
330 Log.setFileLogger(new std.stdio.File("ui.log", "w"));
331 } else {
332 // no logging unless version ForceLogs is set
333 version(ForceLogs) {
334 Log.setFileLogger(new std.stdio.File("ui.log", "w"));
335 Log.i("Logging to file ui.log");
336 }
337 }
338 } else version(Android) {
339 Log.setLogTag("dlangui");
340 Log.setLogLevel(LogLevel.Trace);
341 } else {
342 Log.setStderrLogger();
343 }
344 debug {
345 Log.setLogLevel(LogLevel.Trace);
346 } else {
347 version(ForceLogs) {
348 Log.setLogLevel(LogLevel.Trace);
349 Log.i("Log level: trace");
350 } else {
351 Log.setLogLevel(LogLevel.Warn);
352 Log.i("Log level: warn");
353 }
354 }
355 }
356 Log.i("Logger is initialized");
357 }
358
359 /// call this on application initialization
360 extern (C) void initResourceManagers() {
361 Log.d("initResourceManagers()");
362 import dlangui.graphics.fonts;
363 _gamma65 = new glyph_gamma_table!65(1.0);
364 _gamma256 = new glyph_gamma_table!256(1.0);
365 static if (ENABLE_FREETYPE) {
366 import dlangui.graphics.ftfonts;
367 STD_FONT_FACES = [
368 "Arial": 12,
369 "Times New Roman": 12,
370 "Courier New": 10,
371 "DejaVu Serif": 10,
372 "DejaVu Sans": 10,
373 "DejaVu Sans Mono": 10,
374 "Liberation Serif": 11,
375 "Liberation Sans": 11,
376 "Liberation Mono": 11,
377 "Verdana": 10,
378 "Menlo": 13,
379 "Consolas": 12,
380 "DejaVuSansMono": 10,
381 "Lucida Sans Typewriter": 10,
382 "Lucida Console": 12,
383 "FreeMono": 8,
384 "FreeSans": 8,
385 "FreeSerif": 8,
386 ];
387 }
388 static if (ENABLE_OPENGL) {
389 import dlangui.graphics.gldrawbuf;
390 initGLCaches();
391 }
392 import dlangui.graphics.resources;
393 embedStandardDlangUIResources();
394 static if (BACKEND_GUI) {
395 _imageCache = new ImageCache();
396 }
397 _drawableCache = new DrawableCache();
398 static if (BACKEND_GUI) {
399 version (Windows) {
400 import dlangui.platforms.windows.win32fonts;
401 initWin32FontsTables();
402 }
403 }
404
405 Log.d("Calling initSharedResourceManagers()");
406 initSharedResourceManagers();
407
408 Log.d("Calling initStandardEditorActions()");
409 import dlangui.widgets.editors;
410 initStandardEditorActions();
411
412 Log.d("Calling registerStandardWidgets()");
413 registerStandardWidgets();
414
415
416 Log.d("initResourceManagers() -- finished");
417 }
418
419
420
421 /// call this from shared static this()
422 extern (C) void initSharedResourceManagers() {
423 //Log.d("initSharedResourceManagers()");
424 //import dlangui.core.i18n;
425 //if (!i18n) {
426 // Log.d("Creating i18n object");
427 // i18n = new shared UIStringTranslator();
428 //}
429 }
430
431 shared static this() {
432 //initSharedResourceManagers();
433 }
434
435 /// register standard widgets to use in DML
436 extern(C) void registerStandardWidgets();
437
438 /// call this when all resources are supposed to be freed to report counts of non-freed resources by type
439 extern (C) void releaseResourcesOnAppExit() {
440
441 //
442 debug setAppShuttingDownFlag();
443
444 debug {
445 if (Widget.instanceCount() > 0) {
446 Log.e("Non-zero Widget instance count when exiting: ", Widget.instanceCount);
447 }
448 }
449
450 currentTheme = null;
451 drawableCache = null;
452 static if (BACKEND_GUI) {
453 imageCache = null;
454 }
455 FontManager.instance = null;
456 static if (ENABLE_OPENGL) {
457 import dlangui.graphics.gldrawbuf;
458 destroyGLCaches();
459 }
460
461 debug {
462 if (DrawBuf.instanceCount > 0) {
463 Log.e("Non-zero DrawBuf instance count when exiting: ", DrawBuf.instanceCount);
464 }
465 if (Style.instanceCount > 0) {
466 Log.e("Non-zero Style instance count when exiting: ", Style.instanceCount);
467 }
468 if (ImageDrawable.instanceCount > 0) {
469 Log.e("Non-zero ImageDrawable instance count when exiting: ", ImageDrawable.instanceCount);
470 }
471 if (Drawable.instanceCount > 0) {
472 Log.e("Non-zero Drawable instance count when exiting: ", Drawable.instanceCount);
473 }
474 static if (ENABLE_FREETYPE) {
475 import dlangui.graphics.ftfonts;
476 if (FreeTypeFontFile.instanceCount > 0) {
477 Log.e("Non-zero FreeTypeFontFile instance count when exiting: ", FreeTypeFontFile.instanceCount);
478 }
479 if (FreeTypeFont.instanceCount > 0) {
480 Log.e("Non-zero FreeTypeFont instance count when exiting: ", FreeTypeFont.instanceCount);
481 }
482 }
483 }
484 }
485
486 version(unittest) {
487 version (Windows) {
488 mixin APP_ENTRY_POINT;
489
490 /// entry point for dlangui based application
491 extern (C) int UIAppMain(string[] args) {
492 // just to enable running unit tests
493 import core.runtime;
494 import std.stdio;
495 if (!runModuleUnitTests()) {
496 writeln("Error occured in unit tests. Press enter.");
497 readln();
498 return 1;
499 }
500 return 0;
501 }
502 }
503 }
504
505