Mercurial > hg > openttd
annotate src/fontcache.cpp @ 10978:b1eb341d7081 draft
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 02 Feb 2009 15:01:19 +0000 |
parents | 205529598e13 |
children | 0579a2f61770 |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
8411
diff
changeset
|
3 /** @file fontcache.cpp Cache for characters from fonts. */ |
6179
e3e61b92574b
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5937
diff
changeset
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #include "stdafx.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
6 #include "spritecache.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
7 #include "fontcache.h" |
6937
b6cf3513b2c4
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight <truelight@openttd.org>
parents:
6913
diff
changeset
|
8 #include "blitter/factory.hpp" |
8123
c26c28875749
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium <rubidium@openttd.org>
parents:
8121
diff
changeset
|
9 #include "gfx_func.h" |
8130
0586823afe39
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium <rubidium@openttd.org>
parents:
8123
diff
changeset
|
10 #include "core/alloc_func.hpp" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8130
diff
changeset
|
11 #include "core/math_func.hpp" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
13 #include "table/sprites.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
14 #include "table/control_codes.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
15 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
16 #ifdef WITH_FREETYPE |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
17 #include <ft2build.h> |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
18 #include FT_FREETYPE_H |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
19 #include FT_GLYPH_H |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
21 #ifdef WITH_FONTCONFIG |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
22 #include <fontconfig/fontconfig.h> |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
23 #endif |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
24 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
25 static FT_Library _library = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
26 static FT_Face _face_small = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
27 static FT_Face _face_medium = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
28 static FT_Face _face_large = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
29 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
30 FreeTypeSettings _freetype; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
31 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
32 enum { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
33 FACE_COLOUR = 1, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
34 SHADOW_COLOUR = 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
35 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
36 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
37 /** Get the font loaded into a Freetype face by using a font-name. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
38 * If no appropiate font is found, the function returns an error */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
39 #ifdef WIN32 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
40 #include <windows.h> |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
41 #include <tchar.h> |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
42 #include <shlobj.h> // SHGetFolderPath |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
43 #include "win32.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
44 |
10978
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
45 /** |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
46 * Get the short DOS 8.3 format for paths. |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
47 * FreeType doesn't support Unicode filenames and Windows' fopen (as used |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
48 * by FreeType) doesn't support UTF-8 filenames. So we have to convert the |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
49 * filename into something that isn't UTF-8 but represents the Unicode file |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
50 * name. This is the short DOS 8.3 format. This does not contain any |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
51 * characters that fopen doesn't support. |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
52 * @param long_path the path in UTF-8. |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
53 * @return the short path in ANSI (ASCII). |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
54 */ |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
55 char *GetShortPath(const char *long_path) |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
56 { |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
57 static char short_path[MAX_PATH]; |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
58 #ifdef UNICODE |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
59 /* The non-unicode GetShortPath doesn't support UTF-8..., |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
60 * so convert the path to wide chars, then get the short |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
61 * path and convert it back again. */ |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
62 wchar_t long_path_w[MAX_PATH]; |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
63 MultiByteToWideChar(CP_UTF8, 0, long_path, -1, long_path_w, MAX_PATH); |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
64 |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
65 wchar_t short_path_w[MAX_PATH]; |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
66 GetShortPathNameW(long_path_w, short_path_w, MAX_PATH); |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
67 |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
68 WideCharToMultiByte(CP_ACP, 0, short_path_w, -1, short_path, MAX_PATH, NULL, NULL); |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
69 #else |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
70 /* Technically not needed, but do it for consistency. */ |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
71 GetShortPathNameA(long_path, short_path, MAX_PATH); |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
72 #endif |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
73 return short_path; |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
74 } |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
75 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
76 /* Get the font file to be loaded into Freetype by looping the registry |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
77 * location where windows lists all installed fonts. Not very nice, will |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 * surely break if the registry path changes, but it works. Much better |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
79 * solution would be to use CreateFont, and extract the font data from it |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 * by GetFontData. The problem with this is that the font file needs to be |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 * kept in memory then until the font is no longer needed. This could mean |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
82 * an additional memory usage of 30MB (just for fonts!) when using an eastern |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
83 * font for all font sizes */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
84 #define FONT_DIR_NT "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 #define FONT_DIR_9X "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
86 static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
87 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
88 FT_Error err = FT_Err_Cannot_Open_Resource; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
89 HKEY hKey; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
90 LONG ret; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
91 TCHAR vbuffer[MAX_PATH], dbuffer[256]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 TCHAR *font_namep; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 char *font_path; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 uint index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
95 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
96 /* On windows NT (2000, NT3.5, XP, etc.) the fonts are stored in the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
97 * "Windows NT" key, on Windows 9x in the Windows key. To save us having |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 * to retrieve the windows version, we'll just query both */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
99 ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_NT), 0, KEY_READ, &hKey); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
100 if (ret != ERROR_SUCCESS) ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_9X), 0, KEY_READ, &hKey); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
101 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
102 if (ret != ERROR_SUCCESS) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
103 DEBUG(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows (NT)\\CurrentVersion\\Fonts"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
104 return err; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
107 /* For Unicode we need some conversion between widechar and |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
108 * normal char to match the data returned by RegEnumValue, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 * otherwise just use parameter */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
110 #if defined(UNICODE) |
5937
50d3857901d4
(svn r8576) -Fix: wrong type given to MallocT (VC2003, UNICODE build)
KUDr <KUDr@openttd.org>
parents:
5638
diff
changeset
|
111 font_namep = MallocT<TCHAR>(MAX_PATH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
112 MB_TO_WIDE_BUFFER(font_name, font_namep, MAX_PATH * sizeof(TCHAR)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
113 #else |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
114 font_namep = (char*)font_name; // only cast because in unicode pointer is not const |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
115 #endif |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
116 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
117 for (index = 0;; index++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 TCHAR *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
119 DWORD vbuflen = lengthof(vbuffer); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
120 DWORD dbuflen = lengthof(dbuffer); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
121 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
122 ret = RegEnumValue(hKey, index, vbuffer, &vbuflen, NULL, NULL, (byte*)dbuffer, &dbuflen); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
123 if (ret != ERROR_SUCCESS) goto registry_no_font_found; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
124 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
125 /* The font names in the registry are of the following 3 forms: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
126 * - ADMUI3.fon |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
127 * - Book Antiqua Bold (TrueType) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
128 * - Batang & BatangChe & Gungsuh & GungsuhChe (TrueType) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
129 * We will strip the font-type '()' if any and work with the font name |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
130 * itself, which must match exactly; if... |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
131 * TTC files, font files which contain more than one font are seperated |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
132 * byt '&'. Our best bet will be to do substr match for the fontname |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
133 * and then let FreeType figure out which index to load */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
134 s = _tcschr(vbuffer, _T('(')); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
135 if (s != NULL) s[-1] = '\0'; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
136 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
137 if (_tcschr(vbuffer, _T('&')) == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
138 if (_tcsicmp(vbuffer, font_namep) == 0) break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
139 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
140 if (_tcsstr(vbuffer, font_namep) != NULL) break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
141 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
142 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
143 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
144 if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, vbuffer))) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
145 DEBUG(freetype, 0, "SHGetFolderPath cannot return fonts directory"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
146 goto folder_error; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
147 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 /* Some fonts are contained in .ttc files, TrueType Collection fonts. These |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
150 * contain multiple fonts inside this single file. GetFontData however |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
151 * returns the whole file, so we need to check each font inside to get the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
152 * proper font. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
153 * Also note that FreeType does not support UNICODE filesnames! */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
154 #if defined(UNICODE) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
155 /* We need a cast here back from wide because FreeType doesn't support |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
156 * widechar filenames. Just use the buffer we allocated before for the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
157 * font_name search */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
158 font_path = (char*)font_namep; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
159 WIDE_TO_MB_BUFFER(vbuffer, font_path, MAX_PATH * sizeof(TCHAR)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
160 #else |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
161 font_path = vbuffer; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
162 #endif |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
163 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
164 ttd_strlcat(font_path, "\\", MAX_PATH * sizeof(TCHAR)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
165 ttd_strlcat(font_path, WIDE_TO_MB(dbuffer), MAX_PATH * sizeof(TCHAR)); |
10978
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
166 |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
167 /* Convert the path into something that FreeType understands */ |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
168 font_path = GetShortPath(font_path); |
b1eb341d7081
(svn r15317) -Fix: support Windows fonts with non-ASCII characters in their file name. Windows doesn't come with them by default, but one can easily install a font with non-ASCII name.
rubidium <rubidium@openttd.org>
parents:
10976
diff
changeset
|
169 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
170 index = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
171 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
172 err = FT_New_Face(_library, font_path, index, face); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
173 if (err != FT_Err_Ok) break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
174 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
175 if (strncasecmp(font_name, (*face)->family_name, strlen((*face)->family_name)) == 0) break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
176 err = FT_Err_Cannot_Open_Resource; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
177 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
178 } while ((FT_Long)++index != (*face)->num_faces); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
179 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
180 |
6388
b699cfa343dc
(svn r9518) -Fix [Windows]: do not free an uninitialized pointer.
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
181 folder_error: |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
182 registry_no_font_found: |
6389
cb3cab32710f
(svn r9519) -Fix r7406 (revert r9518): free the malloced variable, not a pointer to that variable. Also free it if there's any error.
glx <glx@openttd.org>
parents:
6388
diff
changeset
|
183 #if defined(UNICODE) |
cb3cab32710f
(svn r9519) -Fix r7406 (revert r9518): free the malloced variable, not a pointer to that variable. Also free it if there's any error.
glx <glx@openttd.org>
parents:
6388
diff
changeset
|
184 free(font_namep); |
cb3cab32710f
(svn r9519) -Fix r7406 (revert r9518): free the malloced variable, not a pointer to that variable. Also free it if there's any error.
glx <glx@openttd.org>
parents:
6388
diff
changeset
|
185 #endif |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
186 RegCloseKey(hKey); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
187 return err; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
188 } |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
189 |
10975
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
190 /** |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
191 * Fonts can have localised names and when the system locale is the same as |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
192 * one of those localised names Windows will always return that localised name |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
193 * instead of allowing to get the non-localised (English US) name of the font. |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
194 * This will later on give problems as freetype uses the non-localised name of |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
195 * the font and we need to compare based on that name. |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
196 * Windows furthermore DOES NOT have an API to get the non-localised name nor |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
197 * can we override the system locale. This means that we have to actually read |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
198 * the font itself to gather the font name we want. |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
199 * Based on: http://blogs.msdn.com/michkap/archive/2006/02/13/530814.aspx |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
200 * @param logfont the font information to get the english name of. |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
201 * @return the English name (if it could be found). |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
202 */ |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
203 static const char *GetEnglishFontName(const ENUMLOGFONTEX *logfont) |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
204 { |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
205 static char font_name[MAX_PATH]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
206 const char *ret_font_name = NULL; |
10976
205529598e13
(svn r15315) -Fix (r15314): make gcc happy (for once)
glx <glx@openttd.org>
parents:
10975
diff
changeset
|
207 uint pos = 0; |
10975
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
208 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
209 HFONT font = CreateFontIndirect(&logfont->elfLogFont); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
210 if (font == NULL) goto err1; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
211 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
212 HDC dc = GetDC(NULL); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
213 HGDIOBJ oldfont = SelectObject(dc, font); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
214 DWORD dw = GetFontData(dc, 'eman', 0, NULL, 0); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
215 if (dw == GDI_ERROR) goto err2; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
216 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
217 byte *buf = MallocT<byte>(dw); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
218 dw = GetFontData(dc, 'eman', 0, buf, dw); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
219 if (dw == GDI_ERROR) goto err3; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
220 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
221 uint16 format = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
222 format += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
223 assert(format == 0); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
224 uint16 count = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
225 count += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
226 uint16 stringOffset = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
227 stringOffset += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
228 for (uint i = 0; i < count; i++) { |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
229 uint16 platformId = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
230 platformId += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
231 uint16 encodingId = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
232 encodingId += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
233 uint16 languageId = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
234 languageId += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
235 uint16 nameId = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
236 nameId += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
237 if (nameId != 1) { |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
238 pos += 4; // skip length and offset |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
239 continue; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
240 } |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
241 uint16 length = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
242 length += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
243 uint16 offset = buf[pos++] << 8; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
244 offset += buf[pos++]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
245 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
246 /* Don't buffer overflow */ |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
247 length = min(length, MAX_PATH - 1); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
248 for (uint j = 0; j < length; j++) font_name[j] = buf[stringOffset + offset + j]; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
249 font_name[length] = '\0'; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
250 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
251 if ((platformId == 1 && languageId == 0) || // Macintosh English |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
252 (platformId == 3 && languageId == 0x0409)) { // Microsoft English (US) |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
253 ret_font_name = font_name; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
254 break; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
255 } |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
256 } |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
257 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
258 err3: |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
259 free(buf); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
260 err2: |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
261 SelectObject(dc, oldfont); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
262 ReleaseDC(NULL, dc); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
263 err1: |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
264 DeleteObject(font); |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
265 |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
266 return ret_font_name == NULL ? WIDE_TO_MB((const TCHAR*)logfont->elfFullName) : ret_font_name; |
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
267 } |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
268 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
269 struct EFCParam { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
270 FreeTypeSettings *settings; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
271 LOCALESIGNATURE locale; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
272 }; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
273 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
274 static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXTMETRICEX *metric, DWORD type, LPARAM lParam) |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
275 { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
276 EFCParam *info = (EFCParam *)lParam; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
277 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
278 /* Only use TrueType fonts */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
279 if (!(type & TRUETYPE_FONTTYPE)) return 1; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
280 /* Don't use SYMBOL fonts */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
281 if (logfont->elfLogFont.lfCharSet == SYMBOL_CHARSET) return 1; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
282 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
283 /* The font has to have at least one of the supported locales to be usable. */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
284 if ((metric->ntmFontSig.fsCsb[0] & info->locale.lsCsbSupported[0]) == 0 && (metric->ntmFontSig.fsCsb[1] & info->locale.lsCsbSupported[1]) == 0) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
285 /* On win9x metric->ntmFontSig seems to contain garbage. */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
286 FONTSIGNATURE fs; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
287 memset(&fs, 0, sizeof(fs)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
288 HFONT font = CreateFontIndirect(&logfont->elfLogFont); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
289 if (font != NULL) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
290 HDC dc = GetDC(NULL); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
291 HGDIOBJ oldfont = SelectObject(dc, font); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
292 GetTextCharsetInfo(dc, &fs, 0); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
293 SelectObject(dc, oldfont); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
294 ReleaseDC(NULL, dc); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
295 DeleteObject(font); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
296 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
297 if ((fs.fsCsb[0] & info->locale.lsCsbSupported[0]) == 0 && (fs.fsCsb[1] & info->locale.lsCsbSupported[1]) == 0) return 1; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
298 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
299 |
10975
2542dbe3ecd3
(svn r15314) -Fix/hackaround [FS#2590]: fonts have a feature where they can have localised names. Windows thinks it's a feature to use the name matching the system's locale, Windows doesn't provide an API to get the font name given another locale and freetype uses the English locale to resolve the name when opening the font... This results in fonts that will can't be found and warnings that the fallback font can't be loaded. Work around this by 'manually' getting the non-localised font name from the font.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
300 const char *font_name = GetEnglishFontName(logfont); |
10369
ff8d514403cc
(svn r14620) -Fix (r14618): missing lines broke compilation on windows
glx <glx@openttd.org>
parents:
10367
diff
changeset
|
301 DEBUG(freetype, 1, "Fallback font: %s", font_name); |
ff8d514403cc
(svn r14620) -Fix (r14618): missing lines broke compilation on windows
glx <glx@openttd.org>
parents:
10367
diff
changeset
|
302 |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
303 strecpy(info->settings->small_font, font_name, lastof(info->settings->small_font)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
304 strecpy(info->settings->medium_font, font_name, lastof(info->settings->medium_font)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
305 strecpy(info->settings->large_font, font_name, lastof(info->settings->large_font)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
306 return 0; // stop enumerating |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
307 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
308 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
309 bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid) |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
310 { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
311 EFCParam langInfo; |
10371
9def9dbb8714
(svn r14622) -Fix (r14618): win9x compilation
glx <glx@openttd.org>
parents:
10370
diff
changeset
|
312 if (GetLocaleInfo(MAKELCID(winlangid, SORT_DEFAULT), LOCALE_FONTSIGNATURE, (LPTSTR)&langInfo.locale, sizeof(langInfo.locale) / sizeof(TCHAR)) == 0) { |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
313 /* Invalid langid or some other mysterious error, can't determine fallback font. */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
314 DEBUG(freetype, 1, "Can't get locale info for fallback font (langid=0x%x)", winlangid); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
315 return false; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
316 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
317 langInfo.settings = settings; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
318 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
319 LOGFONT font; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
320 /* Enumerate all fonts. */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
321 font.lfCharSet = DEFAULT_CHARSET; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
322 font.lfFaceName[0] = '\0'; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
323 font.lfPitchAndFamily = 0; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
324 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
325 HDC dc = GetDC(NULL); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
326 int ret = EnumFontFamiliesEx(dc, &font, (FONTENUMPROC)&EnumFontCallback, (LPARAM)&langInfo, 0); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
327 ReleaseDC(NULL, dc); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
328 return ret == 0; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
329 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
330 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
331 #elif defined(WITH_FONTCONFIG) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
332 static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
333 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
334 FT_Error err = FT_Err_Cannot_Open_Resource; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
335 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
336 if (!FcInit()) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
337 ShowInfoF("Unable to load font configuration"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
338 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
339 FcPattern *match; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
340 FcPattern *pat; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
341 FcFontSet *fs; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
342 FcResult result; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
343 char *font_style; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
344 char *font_family; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
345 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
346 /* Split & strip the font's style */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
347 font_family = strdup(font_name); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
348 font_style = strchr(font_family, ','); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 if (font_style != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
350 font_style[0] = '\0'; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
351 font_style++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
352 while (*font_style == ' ' || *font_style == '\t') font_style++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
353 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
354 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
355 /* Resolve the name and populate the information structure */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
356 pat = FcNameParse((FcChar8*)font_family); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
357 if (font_style != NULL) FcPatternAddString(pat, FC_STYLE, (FcChar8*)font_style); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
358 FcConfigSubstitute(0, pat, FcMatchPattern); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
359 FcDefaultSubstitute(pat); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
360 fs = FcFontSetCreate(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 match = FcFontMatch(0, pat, &result); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
362 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
363 if (fs != NULL && match != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
364 int i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
365 FcChar8 *family; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
366 FcChar8 *style; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
367 FcChar8 *file; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
368 FcFontSetAdd(fs, match); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 for (i = 0; err != FT_Err_Ok && i < fs->nfont; i++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
371 /* Try the new filename */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
372 if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, &file) == FcResultMatch && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
373 FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
374 FcPatternGetString(fs->fonts[i], FC_STYLE, 0, &style) == FcResultMatch) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
375 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 /* The correct style? */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
377 if (font_style != NULL && strcasecmp(font_style, (char*)style) != 0) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
378 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
379 /* Font config takes the best shot, which, if the family name is spelled |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
380 * wrongly a 'random' font, so check whether the family name is the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
381 * same as the supplied name */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
382 if (strcasecmp(font_family, (char*)family) == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
383 err = FT_New_Face(_library, (char *)file, 0, face); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
384 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
386 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
387 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
388 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
389 free(font_family); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
390 FcPatternDestroy(pat); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
391 FcFontSetDestroy(fs); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
392 FcFini(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
393 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
394 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
395 return err; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
396 } |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
397 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
398 bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid) |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
399 { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
400 if (!FcInit()) return false; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
401 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
402 bool ret = false; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
403 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
404 /* Fontconfig doesn't handle full language isocodes, only the part |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
405 * before the _ of e.g. en_GB is used, so "remove" everything after |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
406 * the _. */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
407 char lang[16]; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
408 strecpy(lang, language_isocode, lastof(lang)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
409 char *split = strchr(lang, '_'); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
410 if (split != NULL) *split = '\0'; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
411 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
412 FcPattern *pat; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
413 FcPattern *match; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
414 FcResult result; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
415 FcChar8 *file; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
416 FcFontSet *fs; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
417 FcValue val; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
418 val.type = FcTypeString; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
419 val.u.s = (FcChar8*)lang; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
420 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
421 /* First create a pattern to match the wanted language */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
422 pat = FcPatternCreate(); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
423 /* And fill it with the language and other defaults */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
424 if (pat == NULL || |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
425 !FcPatternAdd(pat, "lang", val, false) || |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
426 !FcConfigSubstitute(0, pat, FcMatchPattern)) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
427 goto error_pattern; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
428 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
429 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
430 FcDefaultSubstitute(pat); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
431 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
432 /* The create a font set and match that */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
433 match = FcFontMatch(0, pat, &result); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
434 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
435 if (match == NULL) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
436 goto error_pattern; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
437 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
438 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
439 /* Find all fonts that do match */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
440 fs = FcFontSetCreate(); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
441 FcFontSetAdd(fs, match); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
442 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
443 /* And take the first, if it exists */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
444 if (fs->nfont <= 0 || FcPatternGetString(fs->fonts[0], FC_FILE, 0, &file)) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
445 goto error_fontset; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
446 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
447 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
448 strecpy(settings->small_font, (const char*)file, lastof(settings->small_font)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
449 strecpy(settings->medium_font, (const char*)file, lastof(settings->medium_font)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
450 strecpy(settings->large_font, (const char*)file, lastof(settings->large_font)); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
451 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
452 ret = true; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
453 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
454 error_fontset: |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
455 FcFontSetDestroy(fs); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
456 error_pattern: |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
457 if (pat != NULL) FcPatternDestroy(pat); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
458 FcFini(); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
459 return ret; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
460 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
461 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
462 #else /* without WITH_FONTCONFIG */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
463 FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) {return FT_Err_Cannot_Open_Resource;} |
10370
b8ad60837ce3
(svn r14621) -Fix (r14618): link error when you aren't compiling for Windows or you don't have fontconfig.
rubidium <rubidium@openttd.org>
parents:
10369
diff
changeset
|
464 bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid) { return false; } |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
465 #endif /* WITH_FONTCONFIG */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
466 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
467 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
468 * Loads the freetype font. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
469 * First type to load the fontname as if it were a path. If that fails, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
470 * try to resolve the filename of the font using fontconfig, where the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
471 * format is 'font family name' or 'font family name, font style'. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
472 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
473 static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *type) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
474 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
475 FT_Error error; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
476 |
5638
f2a1b973c9b9
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron <tron@openttd.org>
parents:
5609
diff
changeset
|
477 if (StrEmpty(font_name)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
478 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
479 error = FT_New_Face(_library, font_name, 0, face); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
480 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
481 if (error != FT_Err_Ok) error = GetFontByFaceName(font_name, face); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
483 if (error == FT_Err_Ok) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
484 DEBUG(freetype, 2, "Requested '%s', using '%s %s'", font_name, (*face)->family_name, (*face)->style_name); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
485 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
486 /* Attempt to select the unicode character map */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
487 error = FT_Select_Charmap(*face, ft_encoding_unicode); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
488 if (error == FT_Err_Ok) return; // Success |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
489 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
490 if (error == FT_Err_Invalid_CharMap_Handle) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
491 /* Try to pick a different character map instead. We default to |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
492 * the first map, but platform_id 0 encoding_id 0 should also |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
493 * be unicode (strange system...) */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
494 FT_CharMap found = (*face)->charmaps[0]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
495 int i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
496 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
497 for (i = 0; i < (*face)->num_charmaps; i++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
498 FT_CharMap charmap = (*face)->charmaps[i]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
499 if (charmap->platform_id == 0 && charmap->encoding_id == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
500 found = charmap; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
501 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
502 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
503 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
504 if (found != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
505 error = FT_Set_Charmap(*face, found); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
506 if (error == FT_Err_Ok) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
507 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
509 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
510 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
511 FT_Done_Face(*face); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
512 *face = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
513 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
514 ShowInfoF("Unable to use '%s' for %s font, FreeType reported error 0x%X, using sprite font instead", font_name, type, error); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
516 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
517 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
518 void InitFreeType() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
519 { |
5638
f2a1b973c9b9
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron <tron@openttd.org>
parents:
5609
diff
changeset
|
520 if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
521 DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
522 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
523 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
525 if (FT_Init_FreeType(&_library) != FT_Err_Ok) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
526 ShowInfoF("Unable to initialize FreeType, using sprite fonts instead"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
528 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
529 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
530 DEBUG(freetype, 2, "Initialized"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
531 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
532 /* Load each font */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
533 LoadFreeTypeFont(_freetype.small_font, &_face_small, "small"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
534 LoadFreeTypeFont(_freetype.medium_font, &_face_medium, "medium"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
535 LoadFreeTypeFont(_freetype.large_font, &_face_large, "large"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
536 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
537 /* Set each font size */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
538 if (_face_small != NULL) FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
539 if (_face_medium != NULL) FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
540 if (_face_large != NULL) FT_Set_Pixel_Sizes(_face_large, 0, _freetype.large_size); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
541 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
542 |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
543 static void ResetGlyphCache(); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
544 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
545 /** |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
546 * Unload a face and set it to NULL. |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
547 * @param face the face to unload |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
548 */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
549 static void UnloadFace(FT_Face *face) |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
550 { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
551 if (*face == NULL) return; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
552 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
553 FT_Done_Face(*face); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
554 *face = NULL; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
555 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
556 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
557 /** |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
558 * Free everything allocated w.r.t. fonts. |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
559 */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
560 void UninitFreeType() |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
561 { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
562 ResetGlyphCache(); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
563 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
564 UnloadFace(&_face_small); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
565 UnloadFace(&_face_medium); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
566 UnloadFace(&_face_large); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
567 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
568 FT_Done_FreeType(_library); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
569 _library = NULL; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
570 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
571 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
572 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
573 static FT_Face GetFontFace(FontSize size) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
574 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
575 switch (size) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
576 default: NOT_REACHED(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
577 case FS_NORMAL: return _face_medium; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
578 case FS_SMALL: return _face_small; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
579 case FS_LARGE: return _face_large; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
580 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
581 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
582 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
583 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
584 struct GlyphEntry { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
585 Sprite *sprite; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
586 byte width; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
587 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
588 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
589 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
590 /* The glyph cache. This is structured to reduce memory consumption. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
591 * 1) There is a 'segment' table for each font size. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
592 * 2) Each segment table is a discrete block of characters. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
593 * 3) Each block contains 256 (aligned) characters sequential characters. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
594 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
595 * The cache is accessed in the following way: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
596 * For character 0x0041 ('A'): _glyph_ptr[FS_NORMAL][0x00][0x41] |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
597 * For character 0x20AC (Euro): _glyph_ptr[FS_NORMAL][0x20][0xAC] |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
598 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
599 * Currently only 256 segments are allocated, "limiting" us to 65536 characters. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
600 * This can be simply changed in the two functions Get & SetGlyphPtr. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
601 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
602 static GlyphEntry **_glyph_ptr[FS_END]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
603 |
10367
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
604 /** Clear the complete cache */ |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
605 static void ResetGlyphCache() |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
606 { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
607 for (int i = 0; i < FS_END; i++) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
608 if (_glyph_ptr[i] == NULL) continue; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
609 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
610 for (int j = 0; j < 256; j++) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
611 if (_glyph_ptr[i][j] == NULL) continue; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
612 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
613 for (int k = 0; k < 256; k++) { |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
614 if (_glyph_ptr[i][j][k].sprite == NULL) continue; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
615 free(_glyph_ptr[i][j][k].sprite); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
616 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
617 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
618 free(_glyph_ptr[i][j]); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
619 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
620 |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
621 free(_glyph_ptr[i]); |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
622 _glyph_ptr[i] = NULL; |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
623 } |
d4b8b071d3e2
(svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
624 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
625 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
626 static GlyphEntry *GetGlyphPtr(FontSize size, WChar key) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
627 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
628 if (_glyph_ptr[size] == NULL) return NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
629 if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) return NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
630 return &_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
631 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
632 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
633 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
634 static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
635 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
636 if (_glyph_ptr[size] == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
637 DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size); |
5609
358c07fb3212
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr <KUDr@openttd.org>
parents:
5587
diff
changeset
|
638 _glyph_ptr[size] = CallocT<GlyphEntry*>(256); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
639 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
640 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
641 if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
642 DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size); |
5609
358c07fb3212
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr <KUDr@openttd.org>
parents:
5587
diff
changeset
|
643 _glyph_ptr[size][GB(key, 8, 8)] = CallocT<GlyphEntry>(256); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
644 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
645 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
646 DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
647 _glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
648 _glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
649 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
650 |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
651 void *AllocateFont(size_t size) |
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
652 { |
8037
02252785b8d6
(svn r11597) -Change: replace all remaining instances of (re|m|c)alloc with (Re|M|C)allocT and add a check for out-of-memory situations to the *allocT functions.
rubidium <rubidium@openttd.org>
parents:
7928
diff
changeset
|
653 return MallocT<byte>(size); |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
654 } |
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
655 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
656 |
6913
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
657 /* Check if a glyph should be rendered with antialiasing */ |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
658 static bool GetFontAAState(FontSize size) |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
659 { |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
660 /* AA is only supported for 32 bpp */ |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
661 if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 32) return false; |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
662 |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
663 switch (size) { |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
664 default: NOT_REACHED(); |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
665 case FS_NORMAL: return _freetype.medium_aa; |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
666 case FS_SMALL: return _freetype.small_aa; |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
667 case FS_LARGE: return _freetype.large_aa; |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
668 } |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
669 } |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
670 |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
671 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
672 const Sprite *GetGlyph(FontSize size, WChar key) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
673 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
674 FT_Face face = GetFontFace(size); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
675 FT_GlyphSlot slot; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
676 GlyphEntry new_glyph; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
677 GlyphEntry *glyph; |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
678 SpriteLoader::Sprite sprite; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
679 int width; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
680 int height; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
681 int x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
682 int y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
683 int y_adj; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
685 assert(IsPrintable(key)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
686 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
687 /* Bail out if no face loaded, or for our special characters */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
688 if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
689 SpriteID sprite = GetUnicodeGlyph(size, key); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
690 if (sprite == 0) sprite = GetUnicodeGlyph(size, '?'); |
10056
7867701f63e4
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium <rubidium@openttd.org>
parents:
9716
diff
changeset
|
691 return GetSprite(sprite, ST_FONT); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
692 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
693 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
694 /* Check for the glyph in our cache */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
695 glyph = GetGlyphPtr(size, key); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 if (glyph != NULL && glyph->sprite != NULL) return glyph->sprite; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
698 slot = face->glyph; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
699 |
6913
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
700 bool aa = GetFontAAState(size); |
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
701 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
702 FT_Load_Char(face, key, FT_LOAD_DEFAULT); |
6913
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
703 FT_Render_Glyph(face->glyph, aa ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
704 |
9716
c5aa1a22224f
(svn r13832) -Fix [FS#2152]: FreeType may return a bitmap glyph even if a grey-scale glyph was requested.
peter1138 <peter1138@openttd.org>
parents:
9111
diff
changeset
|
705 /* Despite requesting a normal glyph, FreeType may have returned a bitmap */ |
c5aa1a22224f
(svn r13832) -Fix [FS#2152]: FreeType may return a bitmap glyph even if a grey-scale glyph was requested.
peter1138 <peter1138@openttd.org>
parents:
9111
diff
changeset
|
706 aa = (slot->bitmap.palette_mode == FT_PIXEL_MODE_GRAY); |
c5aa1a22224f
(svn r13832) -Fix [FS#2152]: FreeType may return a bitmap glyph even if a grey-scale glyph was requested.
peter1138 <peter1138@openttd.org>
parents:
9111
diff
changeset
|
707 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
708 /* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
709 width = max(1, slot->bitmap.width + (size == FS_NORMAL)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
710 height = max(1, slot->bitmap.rows + (size == FS_NORMAL)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
711 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
712 /* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */ |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
713 sprite.data = CallocT<SpriteLoader::CommonPixel>(width * height); |
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
714 sprite.width = width; |
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
715 sprite.height = height; |
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
716 sprite.x_offs = slot->bitmap_left; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
717 // XXX 2 should be determined somehow... it's right for the normal face |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
718 y_adj = (size == FS_NORMAL) ? 2 : 0; |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
719 sprite.y_offs = GetCharacterHeight(size) - slot->bitmap_top - y_adj; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
720 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
721 /* Draw shadow for medium size */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
722 if (size == FS_NORMAL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
723 for (y = 0; y < slot->bitmap.rows; y++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
724 for (x = 0; x < slot->bitmap.width; x++) { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
6937
diff
changeset
|
725 if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) { |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
726 sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR; |
6913
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
727 sprite.data[1 + x + (1 + y) * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
728 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
729 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
730 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
731 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
732 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
733 for (y = 0; y < slot->bitmap.rows; y++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
734 for (x = 0; x < slot->bitmap.width; x++) { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
6937
diff
changeset
|
735 if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) { |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
736 sprite.data[x + y * sprite.width].m = FACE_COLOUR; |
6913
3678f707eccf
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
peter1138 <peter1138@openttd.org>
parents:
6895
diff
changeset
|
737 sprite.data[x + y * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
738 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
739 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
740 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
741 |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
742 new_glyph.sprite = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, AllocateFont); |
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
743 free(sprite.data); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
744 new_glyph.width = (slot->advance.x >> 6) + (size != FS_NORMAL); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
745 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
746 SetGlyphPtr(size, key, &new_glyph); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
747 |
6856
7d2e01558528
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents:
6852
diff
changeset
|
748 return new_glyph.sprite; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
749 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
750 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
751 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
752 uint GetGlyphWidth(FontSize size, WChar key) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
753 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
754 FT_Face face = GetFontFace(size); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
755 GlyphEntry *glyph; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
756 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
757 if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
758 SpriteID sprite = GetUnicodeGlyph(size, key); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
759 if (sprite == 0) sprite = GetUnicodeGlyph(size, '?'); |
10056
7867701f63e4
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium <rubidium@openttd.org>
parents:
9716
diff
changeset
|
760 return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL) : 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
761 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
762 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
763 glyph = GetGlyphPtr(size, key); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
764 if (glyph == NULL || glyph->sprite == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
765 GetGlyph(size, key); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
766 glyph = GetGlyphPtr(size, key); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
767 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
768 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
769 return glyph->width; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
770 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
771 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
772 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 #endif /* WITH_FREETYPE */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
774 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
775 /* Sprite based glyph mapping */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
776 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
777 #include "table/unicode.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
778 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
779 static SpriteID **_unicode_glyph_map[FS_END]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
780 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
781 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
782 /** Get the SpriteID of the first glyph for the given font size */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
783 static SpriteID GetFontBase(FontSize size) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
784 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
785 switch (size) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
786 default: NOT_REACHED(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
787 case FS_NORMAL: return SPR_ASCII_SPACE; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
788 case FS_SMALL: return SPR_ASCII_SPACE_SMALL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
789 case FS_LARGE: return SPR_ASCII_SPACE_BIG; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
790 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
791 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
793 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
794 SpriteID GetUnicodeGlyph(FontSize size, uint32 key) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
795 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
796 if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) return 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
797 return _unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
798 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
799 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
800 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
801 void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
802 { |
5609
358c07fb3212
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr <KUDr@openttd.org>
parents:
5587
diff
changeset
|
803 if (_unicode_glyph_map[size] == NULL) _unicode_glyph_map[size] = CallocT<SpriteID*>(256); |
358c07fb3212
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr <KUDr@openttd.org>
parents:
5587
diff
changeset
|
804 if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) _unicode_glyph_map[size][GB(key, 8, 8)] = CallocT<SpriteID>(256); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
805 _unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
806 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
807 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
808 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
809 void InitializeUnicodeGlyphMap() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
810 { |
8411
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
811 for (FontSize size = FS_NORMAL; size != FS_END; size++) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
812 /* Clear out existing glyph map if it exists */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
813 if (_unicode_glyph_map[size] != NULL) { |
8411
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
814 for (uint i = 0; i < 256; i++) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
815 if (_unicode_glyph_map[size][i] != NULL) free(_unicode_glyph_map[size][i]); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
816 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
817 free(_unicode_glyph_map[size]); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
818 _unicode_glyph_map[size] = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
819 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
820 |
8411
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
821 SpriteID base = GetFontBase(size); |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
822 |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
823 for (uint i = ASCII_LETTERSTART; i < 256; i++) { |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
824 SpriteID sprite = base + i - ASCII_LETTERSTART; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
825 if (!SpriteExists(sprite)) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 SetUnicodeGlyph(size, i, sprite); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
827 SetUnicodeGlyph(size, i + SCC_SPRITE_START, sprite); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
828 } |
8411
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
829 |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
830 for (uint i = 0; i < lengthof(_default_unicode_map); i++) { |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
831 byte key = _default_unicode_map[i].key; |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
832 if (key == CLRA || key == CLRL) { |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
833 /* Clear the glyph. This happens if the glyph at this code point |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
834 * is non-standard and should be accessed by an SCC_xxx enum |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
835 * entry only. */ |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
836 if (key == CLRA || size == FS_LARGE) { |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
837 SetUnicodeGlyph(size, _default_unicode_map[i].code, 0); |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
838 } |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
839 } else { |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
840 SpriteID sprite = base + key - ASCII_LETTERSTART; |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
841 SetUnicodeGlyph(size, _default_unicode_map[i].code, sprite); |
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8264
diff
changeset
|
842 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
843 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
844 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
845 } |