annotate src/fontcache.cpp @ 12946:560c26f15688 draft

(svn r17439) -Fix (r17436): you weren't paid for cargo delivered to houses and headquarters anymore
author smatz <smatz@openttd.org>
date Mon, 07 Sep 2009 07:39:08 +0000
parents 62f969bd7ff4
children afdfdda87cd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12198
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12198
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12198
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12198
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12198
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12198
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12198
diff changeset
9
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
10 /** @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
11
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 #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
13 #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
14 #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
15 #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
16 #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
17 #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
18 #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
19
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
20 #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
21 #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
22
12198
b730a91b2202 (svn r16612) -Fix (r16605): ASCII_LETTERSTART should be defined unconditionally (leeus)
alberth <alberth@openttd.org>
parents: 12192
diff changeset
23 static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
b730a91b2202 (svn r16612) -Fix (r16605): ASCII_LETTERSTART should be defined unconditionally (leeus)
alberth <alberth@openttd.org>
parents: 12192
diff changeset
24
11490
8bfd517e1898 (svn r15851) -Fix (r15849): compile failure when there's no freetype...
rubidium <rubidium@openttd.org>
parents: 11488
diff changeset
25 /** Semi-constant for the height of the different sizes of fonts. */
8bfd517e1898 (svn r15851) -Fix (r15849): compile failure when there's no freetype...
rubidium <rubidium@openttd.org>
parents: 11488
diff changeset
26 int _font_height[FS_END];
8bfd517e1898 (svn r15851) -Fix (r15849): compile failure when there's no freetype...
rubidium <rubidium@openttd.org>
parents: 11488
diff changeset
27
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
28 #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
29 #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
30 #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
31 #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
32
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
33 #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
34 #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
35 #endif
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 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
38 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
39 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
40 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
41
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
42 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
43
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
44 enum {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
45 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
46 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
47 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
48
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
49 /** 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
50 * 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
51 #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
52 #include <windows.h>
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
53 #include <shlobj.h> /* SHGetFolderPath */
12846
62f969bd7ff4 (svn r17336) -Codechange: move some os specific files into src/os/
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
54 #include "os/windows/win32.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
55
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
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 * 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
58 * 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
59 * 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
60 * 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
61 * 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
62 * 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
63 * @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
64 * @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
65 */
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 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
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 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
69 #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
70 /* 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
71 * 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
72 * 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
73 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
74 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
75
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
76 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
77 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
78
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
79 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
80 #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
81 /* 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
82 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
83 #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
84 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
85 }
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
86
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
87 /* 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
88 * 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
89 * 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
90 * 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
91 * 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
92 * 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
93 * 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
94 * 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
95 #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
96 #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
97 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
98 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
99 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
100 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
101 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
102 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
103 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
104 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
105 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
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 /* 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
108 * "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
109 * 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
110 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
111 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
112
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
113 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
114 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
115 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
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
118 /* 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
119 * 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
120 * 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
121 #if defined(UNICODE)
5937
50d3857901d4 (svn r8576) -Fix: wrong type given to MallocT (VC2003, UNICODE build)
KUDr <KUDr@openttd.org>
parents: 5638
diff changeset
122 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
123 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
124 #else
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
125 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
126 #endif
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
127
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
128 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
129 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
130 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
131 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
132
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
133 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
134 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
135
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
136 /* 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
137 * - 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
138 * - 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
139 * - 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
140 * 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
141 * 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
142 * 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
143 * 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
144 * 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
145 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
146 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
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 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
149 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
150 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
151 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
152 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
153 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
154
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
155 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
156 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
157 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
158 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
159
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
160 /* 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
161 * 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
162 * 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
163 * 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
164 * 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
165 #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
166 /* 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
167 * 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
168 * 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
169 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
170 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
171 #else
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
172 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
173 #endif
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 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
176 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
177
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
178 /* 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
179 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
180
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
181 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
182 do {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
183 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
184 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
185
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
186 if (strncasecmp(font_name, (*face)->family_name, strlen((*face)->family_name)) == 0) break;
11403
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
187 /* Try english name if font name failed */
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
188 if (strncasecmp(font_name + strlen(font_name) + 1, (*face)->family_name, strlen((*face)->family_name)) == 0) break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
189 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
190
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
191 } 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
192
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
193
6388
b699cfa343dc (svn r9518) -Fix [Windows]: do not free an uninitialized pointer.
rubidium <rubidium@openttd.org>
parents: 6248
diff changeset
194 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
195 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
196 #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
197 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
198 #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
199 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
200 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
201 }
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
202
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
203 /**
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 * 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
205 * 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
206 * 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
207 * 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
208 * 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
209 * 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
210 * 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
211 * 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
212 * 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
213 * @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
214 * @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
215 */
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 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
217 {
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 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
219 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
220 uint pos = 0;
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
221 HDC dc;
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
222 HGDIOBJ oldfont;
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
223 byte *buf;
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
224 DWORD dw;
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
225 uint16 format, count, stringOffset, platformId, encodingId, languageId, nameId, length, offset;
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
226
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 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
228 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
229
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
230 dc = GetDC(NULL);
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
231 oldfont = SelectObject(dc, font);
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
232 dw = GetFontData(dc, 'eman', 0, NULL, 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
233 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
234
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
235 buf = MallocT<byte>(dw);
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
236 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
237 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
238
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
239 format = buf[pos++] << 8;
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
240 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
241 assert(format == 0);
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
242 count = buf[pos++] << 8;
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
243 count += buf[pos++];
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
244 stringOffset = buf[pos++] << 8;
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
245 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
246 for (uint i = 0; i < count; i++) {
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
247 platformId = buf[pos++] << 8;
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
248 platformId += buf[pos++];
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
249 encodingId = buf[pos++] << 8;
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
250 encodingId += buf[pos++];
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
251 languageId = buf[pos++] << 8;
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
252 languageId += buf[pos++];
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
253 nameId = buf[pos++] << 8;
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
254 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
255 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
256 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
257 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
258 }
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
259 length = buf[pos++] << 8;
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
260 length += buf[pos++];
11460
e0f57dedd338 (svn r15818) -Fix [FS#2752]: some (newer) GCCs have trouble compiling the Win32 specific part of fontcache.cpp; jumps across variable declarations (Maeyanie)
rubidium <rubidium@openttd.org>
parents: 11404
diff changeset
261 offset = buf[pos++] << 8;
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
262 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
263
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 /* 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
265 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
266 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
267 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
268
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
269 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
270 (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
271 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
272 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
273 }
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
274 }
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
275
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
276 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
277 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
278 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
279 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
280 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
281 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
282 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
283
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
284 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
285 }
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
286
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 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
288 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
289 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
290 };
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
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 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
293 {
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 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
295
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 /* 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
297 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
298 /* 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
299 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
300
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
301 /* 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
302 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
303 /* 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 }
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 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
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
11403
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
318 const char *english_name = GetEnglishFontName(logfont);
11404
9920ef0f50c8 (svn r15758) -Fix (r15757): win9x compilation
glx <glx@openttd.org>
parents: 11403
diff changeset
319 const char *font_name = WIDE_TO_MB((const TCHAR*)logfont->elfFullName);
11403
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
320 DEBUG(freetype, 1, "Fallback font: %s (%s)", font_name, english_name);
10369
ff8d514403cc (svn r14620) -Fix (r14618): missing lines broke compilation on windows
glx <glx@openttd.org>
parents: 10367
diff changeset
321
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
322 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
323 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
324 strecpy(info->settings->large_font, font_name, lastof(info->settings->large_font));
11403
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
325
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
326 /* Add english name after font name */
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
327 strecpy(info->settings->small_font + strlen(info->settings->small_font) + 1, english_name, lastof(info->settings->small_font));
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
328 strecpy(info->settings->medium_font + strlen(info->settings->medium_font) + 1, english_name, lastof(info->settings->medium_font));
e4f221be9456 (svn r15757) -Fix/hackaround (r15314): of course on some system searching a font using its english name fails. So now we search the font using the localised name and use the english name for the final 'validation' only.
glx <glx@openttd.org>
parents: 11368
diff changeset
329 strecpy(info->settings->large_font + strlen(info->settings->large_font) + 1, english_name, lastof(info->settings->large_font));
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
330 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
331 }
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
332
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
333 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
334 {
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
335 EFCParam langInfo;
10371
9def9dbb8714 (svn r14622) -Fix (r14618): win9x compilation
glx <glx@openttd.org>
parents: 10370
diff changeset
336 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
337 /* 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
338 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
339 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
340 }
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
341 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
342
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
343 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
344 /* 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
345 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
346 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
347 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
348
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
349 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
350 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
351 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
352 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
353 }
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
354
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
355 #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
356 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
357 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
358 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
359
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
360 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
361 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
362 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
363 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
364 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
365 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
366 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
367 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
368 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
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 /* 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
371 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
372 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
373 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
374 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
375 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
376 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
377 }
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 /* 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
380 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
381 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
382 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
383 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
384 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
385 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
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 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
388 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
389 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
390 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
391 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
392 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
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 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
395 /* 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
396 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
397 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
398 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
399
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
400 /* 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
401 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
402
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
403 /* Font config takes the best shot, which, if the family name is spelled
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11360
diff changeset
404 * wrongly a 'random' font, so check whether the family name is the
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11360
diff changeset
405 * same as the supplied name */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
406 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
407 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
408 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
409 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
410 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
411 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
412
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
413 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
414 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
415 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
416 FcFini();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
417 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
418
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
419 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
420 }
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
421
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 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
423 {
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 (!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
425
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 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
427
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 /* 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
429 * 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
430 * 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
431 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
432 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
433 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
434 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
435
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 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
437 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
438 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
439 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
440 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
441 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
442 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
443 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
444
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 /* 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
446 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
447 /* 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
448 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
449 !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
450 !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
451 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
452 }
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 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
455
11021
0579a2f61770 (svn r15361) -Cleanup: minor comment style fixes (planetmaker)
smatz <smatz@openttd.org>
parents: 10978
diff changeset
456 /* Then create a font set and match that */
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
457 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
458
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 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
460 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
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
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
463 /* 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
464 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
465 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
466
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
467 /* 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
468 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
469 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
470 }
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
471
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
472 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
473 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
474 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
475
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
476 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
477
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
478 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
479 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
480 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
481 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
482 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
483 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
484 }
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
485
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
486 #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
487 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
488 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
489 #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
490
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
491 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
492 * 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
493 * 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
494 * 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
495 * 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
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 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
498 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
499 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
500
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
501 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
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 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
504
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
505 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
506
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
507 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
508 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
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 /* 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
511 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
512 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
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 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
515 /* 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
516 * 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
517 * 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
518 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
519 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
520
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
521 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
522 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
523 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
524 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
525 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
526 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
527
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
528 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
529 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
530 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
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
533 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
534
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
535 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
536 *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
537
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
538 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
539 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
540
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
541
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6179
diff changeset
542 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
543 {
11488
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
544 ResetFontSizes();
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
545
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
546 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
547 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
548 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
549 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
550
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
551 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
552 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
553 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
554 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
555
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
556 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
557
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
558 /* 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
559 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
560 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
561 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
562
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
563 /* Set each font size */
11488
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
564 if (_face_small != NULL) {
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
565 FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size);
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
566 _font_height[FS_SMALL] = _freetype.small_size;
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
567 }
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
568 if (_face_medium != NULL) {
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
569 FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size);
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
570 _font_height[FS_NORMAL] = _freetype.medium_size;
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
571 }
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
572 if (_face_large != NULL) {
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
573 FT_Set_Pixel_Sizes(_face_large, 0, _freetype.large_size);
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
574 _font_height[FS_LARGE] = _freetype.large_size;
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
575 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
576 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
577
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
578 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
579
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
580 /**
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
581 * 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
582 * @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
583 */
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
584 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
585 {
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
586 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
587
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
588 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
589 *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
590 }
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
591
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
592 /**
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
593 * 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
594 */
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
595 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
596 {
11488
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
597 ResetFontSizes();
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
598 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
599
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
600 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
601 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
602 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
603
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 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
605 _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
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
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
608
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
609 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
610 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
611 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
612 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
613 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
614 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
615 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
616 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
617 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
618
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
619
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
620 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
621 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
622 byte width;
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
623 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
624
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 /* 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
627 * 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
628 * 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
629 * 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
630 *
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
631 * 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
632 * 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
633 * 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
634 *
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
635 * 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
636 * 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
637 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
638 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
639
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
640 /** 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
641 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
642 {
12191
98caf4f386d6 (svn r16604) -Codechange: Use FS_BEGIN for iterating over fonts.
alberth <alberth@openttd.org>
parents: 12189
diff changeset
643 for (FontSize i = FS_BEGIN; i < FS_END; i++) {
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
644 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
645
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
646 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
647 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
648
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
649 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
650 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
651 }
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
652
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
653 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
654 }
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
655
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
656 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
657 _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
658 }
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
659 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
660
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
661 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
662 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
663 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
664 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
665 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
666 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
667
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
668
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
669 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
670 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
671 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
672 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
673 _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
674 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
675
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
676 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
677 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
678 _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
679 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
680
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
681 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
682 _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
683 _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
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
6856
7d2e01558528 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents: 6852
diff changeset
686 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
687 {
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
688 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
689 }
7d2e01558528 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents: 6852
diff changeset
690
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
691
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
692 /* 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
693 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
694 {
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
695 /* 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
696 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
697
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
698 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
699 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
700 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
701 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
702 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
703 }
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
704 }
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
705
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
706
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
707 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
708 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
709 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
710 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
711 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
712 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
713 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
714 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
715 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
716 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
717 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
718 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
719
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
720 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
721
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
722 /* 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
723 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
724 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
725 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
726 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
727 }
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 /* 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
730 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
731 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
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 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
734
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
735 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
736
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
737 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
738 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
739
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
740 /* Despite requesting a normal glyph, FreeType may have returned a bitmap */
12189
6684af314584 (svn r16602) -Fix (r13831): Antialiased fonts broken; check pixel_mode instead of palette_mode. (Why did it work at some point?)
peter1138 <peter1138@openttd.org>
parents: 11490
diff changeset
741 aa = (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
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
742
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
743 /* 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
744 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
745 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
746
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
747 /* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
11202
0d2b0575fcf1 (svn r15555) -Codechange: remove the mallocs + frees for temporary data from loading sprites.
rubidium <rubidium@openttd.org>
parents: 11021
diff changeset
748 sprite.AllocateData(width * height);
6856
7d2e01558528 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents: 6852
diff changeset
749 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
750 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
751 sprite.x_offs = slot->bitmap_left;
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
752 /* XXX 2 should be determined somehow... it's right for the normal face */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
753 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
754 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
755
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
756 /* 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
757 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
758 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
759 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
760 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
761 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
762 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
763 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
764 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
765 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
766 }
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 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
769 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
770 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
771 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
772 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
773 }
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
776
6856
7d2e01558528 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents: 6852
diff changeset
777 new_glyph.sprite = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, AllocateFont);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
778 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
779
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
780 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
781
6856
7d2e01558528 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight <truelight@openttd.org>
parents: 6852
diff changeset
782 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
783 }
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
786 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
787 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
788 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
789 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
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 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
792 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
793 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
794 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
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
797 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
798 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
799 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
800 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
801 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
802
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
803 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
804 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
805
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 #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
808
11488
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
809 /** Reset the font sizes to the defaults of the sprite based fonts. */
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
810 void ResetFontSizes()
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
811 {
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
812 _font_height[FS_SMALL] = 6;
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
813 _font_height[FS_NORMAL] = 10;
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
814 _font_height[FS_LARGE] = 18;
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
815 }
0395660bac3b (svn r15849) -Codechange: provide easy access to the real height of the used fonts
rubidium <rubidium@openttd.org>
parents: 11460
diff changeset
816
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
817 /* 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
818
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
819 #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
820
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
821 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
822
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
823
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
824 /** 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
825 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
826 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
827 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
828 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
829 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
830 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
831 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
832 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
833 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
834
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
835
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
836 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
837 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
838 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
839 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
840 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
841
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
842
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
843 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
844 {
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
845 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
846 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
847 _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
848 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
849
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
850
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6179
diff changeset
851 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
852 {
12191
98caf4f386d6 (svn r16604) -Codechange: Use FS_BEGIN for iterating over fonts.
alberth <alberth@openttd.org>
parents: 12189
diff changeset
853 for (FontSize size = FS_BEGIN; 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
854 /* 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
855 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
856 for (uint i = 0; i < 256; i++) {
12191
98caf4f386d6 (svn r16604) -Codechange: Use FS_BEGIN for iterating over fonts.
alberth <alberth@openttd.org>
parents: 12189
diff changeset
857 free(_unicode_glyph_map[size][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
858 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
859 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
860 _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
861 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
862
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
863 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
864
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
865 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
866 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
867 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
868 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
869 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
870 }
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
871
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
872 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
873 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
874 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
875 /* 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
876 * 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
877 * 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
878 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
879 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
880 }
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
881 } 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
882 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
883 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
884 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
885 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
886 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
887 }