author | rubidium |
Sun, 25 May 2008 19:17:03 +0000 | |
changeset 9354 | 845e07db4549 |
parent 9111 | 48ce04029fe4 |
child 9716 | d58d69584eae |
permissions | -rw-r--r-- |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
2 |
|
9111
48ce04029fe4
(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
parents:
8411
diff
changeset
|
3 |
/** @file fontcache.cpp Cache for characters from fonts. */ |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
5937
diff
changeset
|
4 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
7 |
#include "debug.h" |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
8 |
#include "spritecache.h" |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
9 |
#include "fontcache.h" |
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
10 |
#include "spriteloader/spriteloader.hpp" |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6913
diff
changeset
|
11 |
#include "blitter/factory.hpp" |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
12 |
#include "gfx_func.h" |
8130
d2eb7d04f6e1
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
8123
diff
changeset
|
13 |
#include "core/alloc_func.hpp" |
8131
160939e24ed3
(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
parents:
8130
diff
changeset
|
14 |
#include "core/math_func.hpp" |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
15 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8214
diff
changeset
|
16 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8214
diff
changeset
|
17 |
#include "table/control_codes.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8214
diff
changeset
|
18 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
19 |
#ifdef WITH_FREETYPE |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
20 |
#include <ft2build.h> |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
21 |
#include FT_FREETYPE_H |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
22 |
#include FT_GLYPH_H |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
23 |
|
5117
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
24 |
#ifdef WITH_FONTCONFIG |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
25 |
#include <fontconfig/fontconfig.h> |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
26 |
#endif |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
27 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
28 |
static FT_Library _library = NULL; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
29 |
static FT_Face _face_small = NULL; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
30 |
static FT_Face _face_medium = NULL; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
31 |
static FT_Face _face_large = NULL; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
32 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
33 |
FreeTypeSettings _freetype; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
34 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
35 |
enum { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
36 |
FACE_COLOUR = 1, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
37 |
SHADOW_COLOUR = 2, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
38 |
}; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
39 |
|
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
40 |
/** Get the font loaded into a Freetype face by using a font-name. |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
41 |
* If no appropiate font is found, the function returns an error */ |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
42 |
#ifdef WIN32 |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
43 |
#include <windows.h> |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
44 |
#include <tchar.h> |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
45 |
#include <shlobj.h> // SHGetFolderPath |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
46 |
#include "win32.h" |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
47 |
|
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
48 |
/* Get the font file to be loaded into Freetype by looping the registry |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
49 |
* location where windows lists all installed fonts. Not very nice, will |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
50 |
* surely break if the registry path changes, but it works. Much better |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
51 |
* solution would be to use CreateFont, and extract the font data from it |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
52 |
* by GetFontData. The problem with this is that the font file needs to be |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
53 |
* kept in memory then until the font is no longer needed. This could mean |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
54 |
* an additional memory usage of 30MB (just for fonts!) when using an eastern |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
55 |
* font for all font sizes */ |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
56 |
#define FONT_DIR_NT "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
57 |
#define FONT_DIR_9X "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts" |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
58 |
static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
59 |
{ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
60 |
FT_Error err = FT_Err_Cannot_Open_Resource; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
61 |
HKEY hKey; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
62 |
LONG ret; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
63 |
TCHAR vbuffer[MAX_PATH], dbuffer[256]; |
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
64 |
TCHAR *font_namep; |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
65 |
char *font_path; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
66 |
uint index; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
67 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
68 |
/* On windows NT (2000, NT3.5, XP, etc.) the fonts are stored in the |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
69 |
* "Windows NT" key, on Windows 9x in the Windows key. To save us having |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
70 |
* to retrieve the windows version, we'll just query both */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
71 |
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_NT), 0, KEY_READ, &hKey); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
72 |
if (ret != ERROR_SUCCESS) ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_9X), 0, KEY_READ, &hKey); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
73 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
74 |
if (ret != ERROR_SUCCESS) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
75 |
DEBUG(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows (NT)\\CurrentVersion\\Fonts"); |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
76 |
return err; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
77 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
78 |
|
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
79 |
/* For Unicode we need some conversion between widechar and |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
80 |
* normal char to match the data returned by RegEnumValue, |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
81 |
* otherwise just use parameter */ |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
82 |
#if defined(UNICODE) |
5937
27e781a9554d
(svn r8576) -Fix: wrong type given to MallocT (VC2003, UNICODE build)
KUDr
parents:
5638
diff
changeset
|
83 |
font_namep = MallocT<TCHAR>(MAX_PATH); |
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
84 |
MB_TO_WIDE_BUFFER(font_name, font_namep, MAX_PATH * sizeof(TCHAR)); |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
85 |
#else |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
86 |
font_namep = (char*)font_name; // only cast because in unicode pointer is not const |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
87 |
#endif |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
88 |
|
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
89 |
for (index = 0;; index++) { |
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
90 |
TCHAR *s; |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
91 |
DWORD vbuflen = lengthof(vbuffer); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
92 |
DWORD dbuflen = lengthof(dbuffer); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
93 |
|
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
94 |
ret = RegEnumValue(hKey, index, vbuffer, &vbuflen, NULL, NULL, (byte*)dbuffer, &dbuflen); |
5240
56a1c6060364
(svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents:
5222
diff
changeset
|
95 |
if (ret != ERROR_SUCCESS) goto registry_no_font_found; |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
96 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
97 |
/* The font names in the registry are of the following 3 forms: |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
98 |
* - ADMUI3.fon |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
99 |
* - Book Antiqua Bold (TrueType) |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
100 |
* - Batang & BatangChe & Gungsuh & GungsuhChe (TrueType) |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
101 |
* We will strip the font-type '()' if any and work with the font name |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
102 |
* itself, which must match exactly; if... |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
103 |
* TTC files, font files which contain more than one font are seperated |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
104 |
* byt '&'. Our best bet will be to do substr match for the fontname |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
105 |
* and then let FreeType figure out which index to load */ |
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
106 |
s = _tcschr(vbuffer, _T('(')); |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
107 |
if (s != NULL) s[-1] = '\0'; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
108 |
|
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
109 |
if (_tcschr(vbuffer, _T('&')) == NULL) { |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
110 |
if (_tcsicmp(vbuffer, font_namep) == 0) break; |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
111 |
} else { |
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
112 |
if (_tcsstr(vbuffer, font_namep) != NULL) break; |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
113 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
114 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
115 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
116 |
if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, vbuffer))) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
117 |
DEBUG(freetype, 0, "SHGetFolderPath cannot return fonts directory"); |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
118 |
goto folder_error; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
119 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
120 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
121 |
/* Some fonts are contained in .ttc files, TrueType Collection fonts. These |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
122 |
* contain multiple fonts inside this single file. GetFontData however |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
123 |
* returns the whole file, so we need to check each font inside to get the |
5240
56a1c6060364
(svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents:
5222
diff
changeset
|
124 |
* proper font. |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
125 |
* Also note that FreeType does not support UNICODE filesnames! */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
126 |
#if defined(UNICODE) |
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
127 |
/* We need a cast here back from wide because FreeType doesn't support |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
128 |
* widechar filenames. Just use the buffer we allocated before for the |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
129 |
* font_name search */ |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
130 |
font_path = (char*)font_namep; |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
131 |
WIDE_TO_MB_BUFFER(vbuffer, font_path, MAX_PATH * sizeof(TCHAR)); |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
132 |
#else |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
133 |
font_path = vbuffer; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
134 |
#endif |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
135 |
|
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
136 |
ttd_strlcat(font_path, "\\", MAX_PATH * sizeof(TCHAR)); |
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
137 |
ttd_strlcat(font_path, WIDE_TO_MB(dbuffer), MAX_PATH * sizeof(TCHAR)); |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
138 |
index = 0; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
139 |
do { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
140 |
err = FT_New_Face(_library, font_path, index, face); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
141 |
if (err != FT_Err_Ok) break; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
142 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
143 |
if (strncasecmp(font_name, (*face)->family_name, strlen((*face)->family_name)) == 0) break; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
144 |
err = FT_Err_Cannot_Open_Resource; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
145 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
146 |
} while ((FT_Long)++index != (*face)->num_faces); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
147 |
|
5267
3ebadb629742
(svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents:
5240
diff
changeset
|
148 |
|
6388
278514553a20
(svn r9518) -Fix [Windows]: do not free an uninitialized pointer.
rubidium
parents:
6248
diff
changeset
|
149 |
folder_error: |
5240
56a1c6060364
(svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents:
5222
diff
changeset
|
150 |
registry_no_font_found: |
6389
e1331b03c6ce
(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
parents:
6388
diff
changeset
|
151 |
#if defined(UNICODE) |
e1331b03c6ce
(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
parents:
6388
diff
changeset
|
152 |
free(font_namep); |
e1331b03c6ce
(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
parents:
6388
diff
changeset
|
153 |
#endif |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
154 |
RegCloseKey(hKey); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
155 |
return err; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
156 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
157 |
#else |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
158 |
# ifdef WITH_FONTCONFIG |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
159 |
static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
160 |
{ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
161 |
FT_Error err = FT_Err_Cannot_Open_Resource; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
162 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
163 |
if (!FcInit()) { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
164 |
ShowInfoF("Unable to load font configuration"); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
165 |
} else { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
166 |
FcPattern *match; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
167 |
FcPattern *pat; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
168 |
FcFontSet *fs; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
169 |
FcResult result; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
170 |
char *font_style; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
171 |
char *font_family; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
172 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
173 |
/* Split & strip the font's style */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
174 |
font_family = strdup(font_name); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
175 |
font_style = strchr(font_family, ','); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
176 |
if (font_style != NULL) { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
177 |
font_style[0] = '\0'; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
178 |
font_style++; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
179 |
while (*font_style == ' ' || *font_style == '\t') font_style++; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
180 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
181 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
182 |
/* Resolve the name and populate the information structure */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
183 |
pat = FcNameParse((FcChar8*)font_family); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
184 |
if (font_style != NULL) FcPatternAddString(pat, FC_STYLE, (FcChar8*)font_style); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
185 |
FcConfigSubstitute(0, pat, FcMatchPattern); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
186 |
FcDefaultSubstitute(pat); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
187 |
fs = FcFontSetCreate(); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
188 |
match = FcFontMatch(0, pat, &result); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
189 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
190 |
if (fs != NULL && match != NULL) { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
191 |
int i; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
192 |
FcChar8 *family; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
193 |
FcChar8 *style; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
194 |
FcChar8 *file; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
195 |
FcFontSetAdd(fs, match); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
196 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
197 |
for (i = 0; err != FT_Err_Ok && i < fs->nfont; i++) { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
198 |
/* Try the new filename */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
199 |
if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, &file) == FcResultMatch && |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
200 |
FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch && |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
201 |
FcPatternGetString(fs->fonts[i], FC_STYLE, 0, &style) == FcResultMatch) { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
202 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
203 |
/* The correct style? */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
204 |
if (font_style != NULL && strcasecmp(font_style, (char*)style) != 0) continue; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
205 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
206 |
/* Font config takes the best shot, which, if the family name is spelled |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
207 |
* wrongly a 'random' font, so check whether the family name is the |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
208 |
* same as the supplied name */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
209 |
if (strcasecmp(font_family, (char*)family) == 0) { |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
210 |
err = FT_New_Face(_library, (char *)file, 0, face); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
211 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
212 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
213 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
214 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
215 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
216 |
free(font_family); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
217 |
FcPatternDestroy(pat); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
218 |
FcFontSetDestroy(fs); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
219 |
FcFini(); |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
220 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
221 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
222 |
return err; |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
223 |
} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
224 |
# else |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
225 |
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) {return FT_Err_Cannot_Open_Resource;} |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
226 |
# endif /* WITH_FONTCONFIG */ |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
227 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
228 |
#endif |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
229 |
|
5117
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
230 |
/** |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
231 |
* Loads the freetype font. |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
232 |
* First type to load the fontname as if it were a path. If that fails, |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
233 |
* try to resolve the filename of the font using fontconfig, where the |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
234 |
* format is 'font family name' or 'font family name, font style'. |
d64bf0093ff4
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
rubidium
parents:
5108
diff
changeset
|
235 |
*/ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
236 |
static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *type) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
237 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
238 |
FT_Error error; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
239 |
|
5638
ee1871005c80
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents:
5609
diff
changeset
|
240 |
if (StrEmpty(font_name)) return; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
241 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
242 |
error = FT_New_Face(_library, font_name, 0, face); |
5219
f8f37c282c2d
(svn r7334) -Revert accidentally committed file in r7333
Darkvater
parents:
5218
diff
changeset
|
243 |
|
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
244 |
if (error != FT_Err_Ok) error = GetFontByFaceName(font_name, face); |
5219
f8f37c282c2d
(svn r7334) -Revert accidentally committed file in r7333
Darkvater
parents:
5218
diff
changeset
|
245 |
|
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
246 |
if (error == FT_Err_Ok) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
247 |
DEBUG(freetype, 2, "Requested '%s', using '%s %s'", font_name, (*face)->family_name, (*face)->style_name); |
5219
f8f37c282c2d
(svn r7334) -Revert accidentally committed file in r7333
Darkvater
parents:
5218
diff
changeset
|
248 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
249 |
/* Attempt to select the unicode character map */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
250 |
error = FT_Select_Charmap(*face, ft_encoding_unicode); |
5222
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
251 |
if (error == FT_Err_Ok) return; // Success |
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
252 |
|
66a48f112460
(svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents:
5219
diff
changeset
|
253 |
if (error == FT_Err_Invalid_CharMap_Handle) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
254 |
/* Try to pick a different character map instead. We default to |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
255 |
* the first map, but platform_id 0 encoding_id 0 should also |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
256 |
* be unicode (strange system...) */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
257 |
FT_CharMap found = (*face)->charmaps[0]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
258 |
int i; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
259 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
260 |
for (i = 0; i < (*face)->num_charmaps; i++) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
261 |
FT_CharMap charmap = (*face)->charmaps[i]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
262 |
if (charmap->platform_id == 0 && charmap->encoding_id == 0) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
263 |
found = charmap; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
264 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
265 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
266 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
267 |
if (found != NULL) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
268 |
error = FT_Set_Charmap(*face, found); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
269 |
if (error == FT_Err_Ok) return; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
270 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
271 |
} |
5240
56a1c6060364
(svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents:
5222
diff
changeset
|
272 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
273 |
|
5240
56a1c6060364
(svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents:
5222
diff
changeset
|
274 |
FT_Done_Face(*face); |
56a1c6060364
(svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents:
5222
diff
changeset
|
275 |
*face = NULL; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
276 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
277 |
ShowInfoF("Unable to use '%s' for %s font, FreeType reported error 0x%X, using sprite font instead", font_name, type, error); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
278 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
279 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
280 |
|
6247 | 281 |
void InitFreeType() |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
282 |
{ |
5638
ee1871005c80
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents:
5609
diff
changeset
|
283 |
if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font)) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
284 |
DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead"); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
285 |
return; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
286 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
287 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
288 |
if (FT_Init_FreeType(&_library) != FT_Err_Ok) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
289 |
ShowInfoF("Unable to initialize FreeType, using sprite fonts instead"); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
290 |
return; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
291 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
292 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
293 |
DEBUG(freetype, 2, "Initialized"); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
294 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
295 |
/* Load each font */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
296 |
LoadFreeTypeFont(_freetype.small_font, &_face_small, "small"); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
297 |
LoadFreeTypeFont(_freetype.medium_font, &_face_medium, "medium"); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
298 |
LoadFreeTypeFont(_freetype.large_font, &_face_large, "large"); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
299 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
300 |
/* Set each font size */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
301 |
if (_face_small != NULL) FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
302 |
if (_face_medium != NULL) FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
303 |
if (_face_large != NULL) FT_Set_Pixel_Sizes(_face_large, 0, _freetype.large_size); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
304 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
305 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
306 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
307 |
static FT_Face GetFontFace(FontSize size) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
308 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
309 |
switch (size) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
310 |
default: NOT_REACHED(); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
311 |
case FS_NORMAL: return _face_medium; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
312 |
case FS_SMALL: return _face_small; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
313 |
case FS_LARGE: return _face_large; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
314 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
315 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
316 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
317 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
318 |
struct GlyphEntry { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
319 |
Sprite *sprite; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
320 |
byte width; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
321 |
}; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
322 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
323 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
324 |
/* The glyph cache. This is structured to reduce memory consumption. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
325 |
* 1) There is a 'segment' table for each font size. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
326 |
* 2) Each segment table is a discrete block of characters. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
327 |
* 3) Each block contains 256 (aligned) characters sequential characters. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
328 |
* |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
329 |
* The cache is accessed in the following way: |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
330 |
* For character 0x0041 ('A'): _glyph_ptr[FS_NORMAL][0x00][0x41] |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
331 |
* For character 0x20AC (Euro): _glyph_ptr[FS_NORMAL][0x20][0xAC] |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
332 |
* |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
333 |
* Currently only 256 segments are allocated, "limiting" us to 65536 characters. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
334 |
* This can be simply changed in the two functions Get & SetGlyphPtr. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
335 |
*/ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
336 |
static GlyphEntry **_glyph_ptr[FS_END]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
337 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
338 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
339 |
static GlyphEntry *GetGlyphPtr(FontSize size, WChar key) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
340 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
341 |
if (_glyph_ptr[size] == NULL) return NULL; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
342 |
if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) return NULL; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
343 |
return &_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
344 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
345 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
346 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
347 |
static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
348 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
349 |
if (_glyph_ptr[size] == NULL) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
350 |
DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size); |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
351 |
_glyph_ptr[size] = CallocT<GlyphEntry*>(256); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
352 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
353 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
354 |
if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
355 |
DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size); |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
356 |
_glyph_ptr[size][GB(key, 8, 8)] = CallocT<GlyphEntry>(256); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
357 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
358 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5270
diff
changeset
|
359 |
DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
360 |
_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
361 |
_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
362 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
363 |
|
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
364 |
void *AllocateFont(size_t size) |
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
365 |
{ |
8037
8aa4ace04383
(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
parents:
7928
diff
changeset
|
366 |
return MallocT<byte>(size); |
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
367 |
} |
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
368 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
369 |
|
6913
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
370 |
/* Check if a glyph should be rendered with antialiasing */ |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
371 |
static bool GetFontAAState(FontSize size) |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
372 |
{ |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
373 |
/* AA is only supported for 32 bpp */ |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
374 |
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 32) return false; |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
375 |
|
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
376 |
switch (size) { |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
377 |
default: NOT_REACHED(); |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
378 |
case FS_NORMAL: return _freetype.medium_aa; |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
379 |
case FS_SMALL: return _freetype.small_aa; |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
380 |
case FS_LARGE: return _freetype.large_aa; |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
381 |
} |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
382 |
} |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
383 |
|
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
384 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
385 |
const Sprite *GetGlyph(FontSize size, WChar key) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
386 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
387 |
FT_Face face = GetFontFace(size); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
388 |
FT_GlyphSlot slot; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
389 |
GlyphEntry new_glyph; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
390 |
GlyphEntry *glyph; |
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
391 |
SpriteLoader::Sprite sprite; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
392 |
int width; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
393 |
int height; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
394 |
int x; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
395 |
int y; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
396 |
int y_adj; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
397 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
398 |
assert(IsPrintable(key)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
399 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
400 |
/* Bail out if no face loaded, or for our special characters */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
401 |
if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
402 |
SpriteID sprite = GetUnicodeGlyph(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
403 |
if (sprite == 0) sprite = GetUnicodeGlyph(size, '?'); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
404 |
return GetSprite(sprite); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
405 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
406 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
407 |
/* Check for the glyph in our cache */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
408 |
glyph = GetGlyphPtr(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
409 |
if (glyph != NULL && glyph->sprite != NULL) return glyph->sprite; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
410 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
411 |
slot = face->glyph; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
412 |
|
6913
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
413 |
bool aa = GetFontAAState(size); |
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
414 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
415 |
FT_Load_Char(face, key, FT_LOAD_DEFAULT); |
6913
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
416 |
FT_Render_Glyph(face->glyph, aa ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
417 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
418 |
/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
419 |
width = max(1, slot->bitmap.width + (size == FS_NORMAL)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
420 |
height = max(1, slot->bitmap.rows + (size == FS_NORMAL)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
421 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
422 |
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */ |
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
423 |
sprite.data = CallocT<SpriteLoader::CommonPixel>(width * height); |
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
424 |
sprite.width = width; |
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
425 |
sprite.height = height; |
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
426 |
sprite.x_offs = slot->bitmap_left; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
427 |
// XXX 2 should be determined somehow... it's right for the normal face |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
428 |
y_adj = (size == FS_NORMAL) ? 2 : 0; |
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
429 |
sprite.y_offs = GetCharacterHeight(size) - slot->bitmap_top - y_adj; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
430 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
431 |
/* Draw shadow for medium size */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
432 |
if (size == FS_NORMAL) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
433 |
for (y = 0; y < slot->bitmap.rows; y++) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
434 |
for (x = 0; x < slot->bitmap.width; x++) { |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
6937
diff
changeset
|
435 |
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
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
436 |
sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR; |
6913
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
437 |
sprite.data[1 + x + (1 + y) * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
438 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
439 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
440 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
441 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
442 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
443 |
for (y = 0; y < slot->bitmap.rows; y++) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
444 |
for (x = 0; x < slot->bitmap.width; x++) { |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
6937
diff
changeset
|
445 |
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
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
446 |
sprite.data[x + y * sprite.width].m = FACE_COLOUR; |
6913
ff5f8a9c1747
(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
parents:
6895
diff
changeset
|
447 |
sprite.data[x + y * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
448 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
449 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
450 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
451 |
|
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
452 |
new_glyph.sprite = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, AllocateFont); |
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
453 |
free(sprite.data); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
454 |
new_glyph.width = (slot->advance.x >> 6) + (size != FS_NORMAL); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
455 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
456 |
SetGlyphPtr(size, key, &new_glyph); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
457 |
|
6856
aa95d0fd29f1
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents:
6852
diff
changeset
|
458 |
return new_glyph.sprite; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
459 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
460 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
461 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
462 |
uint GetGlyphWidth(FontSize size, WChar key) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
463 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
464 |
FT_Face face = GetFontFace(size); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
465 |
GlyphEntry *glyph; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
466 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
467 |
if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
468 |
SpriteID sprite = GetUnicodeGlyph(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
469 |
if (sprite == 0) sprite = GetUnicodeGlyph(size, '?'); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
470 |
return SpriteExists(sprite) ? GetSprite(sprite)->width + (size != FS_NORMAL) : 0; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
471 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
472 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
473 |
glyph = GetGlyphPtr(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
474 |
if (glyph == NULL || glyph->sprite == NULL) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
475 |
GetGlyph(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
476 |
glyph = GetGlyphPtr(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
477 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
478 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
479 |
return glyph->width; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
480 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
481 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
482 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
483 |
#endif /* WITH_FREETYPE */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
484 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
485 |
/* Sprite based glyph mapping */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
486 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
487 |
#include "table/unicode.h" |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
488 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
489 |
static SpriteID **_unicode_glyph_map[FS_END]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
490 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
491 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
492 |
/** Get the SpriteID of the first glyph for the given font size */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
493 |
static SpriteID GetFontBase(FontSize size) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
494 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
495 |
switch (size) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
496 |
default: NOT_REACHED(); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
497 |
case FS_NORMAL: return SPR_ASCII_SPACE; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
498 |
case FS_SMALL: return SPR_ASCII_SPACE_SMALL; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
499 |
case FS_LARGE: return SPR_ASCII_SPACE_BIG; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
500 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
501 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
502 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
503 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
504 |
SpriteID GetUnicodeGlyph(FontSize size, uint32 key) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
505 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
506 |
if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) return 0; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
507 |
return _unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
508 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
509 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
510 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
511 |
void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
512 |
{ |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
513 |
if (_unicode_glyph_map[size] == NULL) _unicode_glyph_map[size] = CallocT<SpriteID*>(256); |
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
514 |
if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) _unicode_glyph_map[size][GB(key, 8, 8)] = CallocT<SpriteID>(256); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
515 |
_unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
516 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
517 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
518 |
|
6247 | 519 |
void InitializeUnicodeGlyphMap() |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
520 |
{ |
8411
591f0c085e10
(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
parents:
8264
diff
changeset
|
521 |
for (FontSize size = FS_NORMAL; size != FS_END; size++) { |
5153
5e6b2790264f
(svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents:
5117
diff
changeset
|
522 |
/* Clear out existing glyph map if it exists */ |
5e6b2790264f
(svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents:
5117
diff
changeset
|
523 |
if (_unicode_glyph_map[size] != NULL) { |
8411
591f0c085e10
(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
parents:
8264
diff
changeset
|
524 |
for (uint i = 0; i < 256; i++) { |
5153
5e6b2790264f
(svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents:
5117
diff
changeset
|
525 |
if (_unicode_glyph_map[size][i] != NULL) free(_unicode_glyph_map[size][i]); |
5e6b2790264f
(svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents:
5117
diff
changeset
|
526 |
} |
5154 | 527 |
free(_unicode_glyph_map[size]); |
5153
5e6b2790264f
(svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents:
5117
diff
changeset
|
528 |
_unicode_glyph_map[size] = NULL; |
5e6b2790264f
(svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents:
5117
diff
changeset
|
529 |
} |
5e6b2790264f
(svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents:
5117
diff
changeset
|
530 |
|
8411
591f0c085e10
(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
parents:
8264
diff
changeset
|
531 |
SpriteID base = GetFontBase(size); |
591f0c085e10
(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
parents:
8264
diff
changeset
|
532 |
|
591f0c085e10
(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
parents:
8264
diff
changeset
|
533 |
for (uint i = ASCII_LETTERSTART; i < 256; i++) { |
591f0c085e10
(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
parents:
8264
diff
changeset
|
534 |
SpriteID sprite = base + i - ASCII_LETTERSTART; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
535 |
if (!SpriteExists(sprite)) continue; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
536 |
SetUnicodeGlyph(size, i, sprite); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
537 |
SetUnicodeGlyph(size, i + SCC_SPRITE_START, sprite); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
538 |
} |
8411
591f0c085e10
(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
parents:
8264
diff
changeset
|
539 |
|
591f0c085e10
(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
parents:
8264
diff
changeset
|
540 |
for (uint i = 0; i < lengthof(_default_unicode_map); i++) { |
591f0c085e10
(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
parents:
8264
diff
changeset
|
541 |
byte key = _default_unicode_map[i].key; |
591f0c085e10
(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
parents:
8264
diff
changeset
|
542 |
if (key == CLRA || key == CLRL) { |
591f0c085e10
(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
parents:
8264
diff
changeset
|
543 |
/* Clear the glyph. This happens if the glyph at this code point |
591f0c085e10
(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
parents:
8264
diff
changeset
|
544 |
* is non-standard and should be accessed by an SCC_xxx enum |
591f0c085e10
(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
parents:
8264
diff
changeset
|
545 |
* entry only. */ |
591f0c085e10
(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
parents:
8264
diff
changeset
|
546 |
if (key == CLRA || size == FS_LARGE) { |
591f0c085e10
(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
parents:
8264
diff
changeset
|
547 |
SetUnicodeGlyph(size, _default_unicode_map[i].code, 0); |
591f0c085e10
(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
parents:
8264
diff
changeset
|
548 |
} |
591f0c085e10
(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
parents:
8264
diff
changeset
|
549 |
} else { |
591f0c085e10
(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
parents:
8264
diff
changeset
|
550 |
SpriteID sprite = base + key - ASCII_LETTERSTART; |
591f0c085e10
(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
parents:
8264
diff
changeset
|
551 |
SetUnicodeGlyph(size, _default_unicode_map[i].code, sprite); |
591f0c085e10
(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
parents:
8264
diff
changeset
|
552 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
553 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
554 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
diff
changeset
|
555 |
} |