fontcache.c
author KUDr
Sun, 31 Dec 2006 23:48:04 +0000
branchcustombridgeheads
changeset 5618 a7db50b9f817
parent 5568 75f13d7bfaed
permissions -rw-r--r--
(svn r7710) [cbh] - Fix: [YAPF] one more assert fixed. Call from the TrainController() added by (r7705) has broken YAPF because it was called when vehicle was already on the next tile (with cbh choice). Before it was always called before the train entered tile with choice.
5108
dc67d70b5a45 (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$ */
dc67d70b5a45 (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
dc67d70b5a45 (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
     3
#include "stdafx.h"
dc67d70b5a45 (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
     4
#include "openttd.h"
dc67d70b5a45 (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 "functions.h"
dc67d70b5a45 (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 "macros.h"
dc67d70b5a45 (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"
dc67d70b5a45 (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 "table/sprites.h"
dc67d70b5a45 (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 "table/control_codes.h"
dc67d70b5a45 (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
    10
#include "spritecache.h"
dc67d70b5a45 (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
    11
#include "gfx.h"
dc67d70b5a45 (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
    12
#include "string.h"
dc67d70b5a45 (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
    13
#include "fontcache.h"
dc67d70b5a45 (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
    14
dc67d70b5a45 (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
#ifdef WITH_FREETYPE
dc67d70b5a45 (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
    16
dc67d70b5a45 (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
    17
#include <ft2build.h>
dc67d70b5a45 (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
    18
#include FT_FREETYPE_H
dc67d70b5a45 (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
#include FT_GLYPH_H
dc67d70b5a45 (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
5117
a4a7fd847b77 (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
    21
#ifdef WITH_FONTCONFIG
a4a7fd847b77 (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
    22
#include <fontconfig/fontconfig.h>
a4a7fd847b77 (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
    23
#endif
a4a7fd847b77 (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
5108
dc67d70b5a45 (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
    25
static FT_Library _library = NULL;
dc67d70b5a45 (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
    26
static FT_Face _face_small = NULL;
dc67d70b5a45 (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
    27
static FT_Face _face_medium = NULL;
dc67d70b5a45 (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_Face _face_large = NULL;
dc67d70b5a45 (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
dc67d70b5a45 (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
FreeTypeSettings _freetype;
dc67d70b5a45 (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
dc67d70b5a45 (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
enum {
dc67d70b5a45 (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
	FACE_COLOUR = 1,
dc67d70b5a45 (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
	SHADOW_COLOUR = 2,
dc67d70b5a45 (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
};
dc67d70b5a45 (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
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    37
/** Get the font loaded into a Freetype face by using a font-name.
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    38
 * If no appropiate font is found, the function returns an error */
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    39
#ifdef WIN32
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    40
#include <windows.h>
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    41
#include <tchar.h>
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    42
#include <shlobj.h> // SHGetFolderPath
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    43
#include "win32.h"
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    44
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    45
/* Get the font file to be loaded into Freetype by looping the registry
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    46
 * location where windows lists all installed fonts. Not very nice, will
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    47
 * surely break if the registry path changes, but it works. Much better
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    48
 * solution would be to use CreateFont, and extract the font data from it
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    49
 * by GetFontData. The problem with this is that the font file needs to be
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    50
 * kept in memory then until the font is no longer needed. This could mean
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    51
 * an additional memory usage of 30MB (just for fonts!) when using an eastern
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    52
 * font for all font sizes */
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    53
#define FONT_DIR_NT "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    54
#define FONT_DIR_9X "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts"
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    55
static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    56
{
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    57
	FT_Error err = FT_Err_Cannot_Open_Resource;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    58
	HKEY hKey;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    59
	LONG ret;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    60
	TCHAR vbuffer[MAX_PATH], dbuffer[256];
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    61
	TCHAR *font_namep;
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    62
	char *font_path;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    63
	uint index;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    64
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    65
	/* On windows NT (2000, NT3.5, XP, etc.) the fonts are stored in the
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    66
	 * "Windows NT" key, on Windows 9x in the Windows key. To save us having
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    67
	 * to retrieve the windows version, we'll just query both */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    68
	ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_NT), 0, KEY_READ, &hKey);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    69
	if (ret != ERROR_SUCCESS) ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_9X), 0, KEY_READ, &hKey);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    70
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    71
	if (ret != ERROR_SUCCESS) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
    72
		DEBUG(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows (NT)\\CurrentVersion\\Fonts");
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    73
		return err;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    74
	}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    75
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    76
	/* For Unicode we need some conversion between widechar and
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    77
	 * normal char to match the data returned by RegEnumValue,
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    78
	 * otherwise just use parameter */
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    79
#if defined(UNICODE)
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    80
	font_namep = malloc(MAX_PATH * sizeof(TCHAR));
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    81
	MB_TO_WIDE_BUFFER(font_name, font_namep, MAX_PATH * sizeof(TCHAR));
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    82
#else
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    83
	font_namep = (char*)font_name; // only cast because in unicode pointer is not const
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    84
#endif
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    85
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    86
	for (index = 0;; index++) {
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    87
		TCHAR *s;
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    88
		DWORD vbuflen = lengthof(vbuffer);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    89
		DWORD dbuflen = lengthof(dbuffer);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    90
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
    91
		ret = RegEnumValue(hKey, index, vbuffer, &vbuflen, NULL, NULL, (byte*)dbuffer, &dbuflen);
5240
60cbd11d714c (svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents: 5222
diff changeset
    92
		if (ret != ERROR_SUCCESS) goto registry_no_font_found;
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    93
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    94
		/* The font names in the registry are of the following 3 forms:
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    95
		 * - ADMUI3.fon
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    96
		 * - Book Antiqua Bold (TrueType)
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    97
		 * - Batang & BatangChe & Gungsuh & GungsuhChe (TrueType)
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    98
		 * We will strip the font-type '()' if any and work with the font name
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
    99
		 * itself, which must match exactly; if...
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   100
		 * TTC files, font files which contain more than one font are seperated
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   101
		 * byt '&'. Our best bet will be to do substr match for the fontname
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   102
		 * and then let FreeType figure out which index to load */
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   103
		s = _tcschr(vbuffer, _T('('));
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   104
		if (s != NULL) s[-1] = '\0';
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   105
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   106
		if (_tcschr(vbuffer, _T('&')) == NULL) {
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   107
			if (_tcsicmp(vbuffer, font_namep) == 0) break;
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   108
		} else {
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   109
			if (_tcsstr(vbuffer, font_namep) != NULL) break;
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   110
		}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   111
	}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   112
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   113
	if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, vbuffer))) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   114
		DEBUG(freetype, 0, "SHGetFolderPath cannot return fonts directory");
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   115
		goto folder_error;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   116
	}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   117
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   118
	/* Some fonts are contained in .ttc files, TrueType Collection fonts. These
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   119
	 * contain multiple fonts inside this single file. GetFontData however
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   120
	 * returns the whole file, so we need to check each font inside to get the
5240
60cbd11d714c (svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents: 5222
diff changeset
   121
	 * proper font.
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   122
	 * Also note that FreeType does not support UNICODE filesnames! */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   123
#if defined(UNICODE)
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   124
	/* We need a cast here back from wide because FreeType doesn't support
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   125
	 * widechar filenames. Just use the buffer we allocated before for the
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   126
	 * font_name search */
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   127
	font_path = (char*)font_namep;
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   128
	WIDE_TO_MB_BUFFER(vbuffer, font_path, MAX_PATH * sizeof(TCHAR));
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   129
#else
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   130
	font_path = vbuffer;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   131
#endif
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   132
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   133
	ttd_strlcat(font_path, "\\", MAX_PATH * sizeof(TCHAR));
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   134
	ttd_strlcat(font_path, WIDE_TO_MB(dbuffer), MAX_PATH * sizeof(TCHAR));
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   135
	index = 0;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   136
	do {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   137
		err = FT_New_Face(_library, font_path, index, face);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   138
		if (err != FT_Err_Ok) break;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   139
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   140
		if (strncasecmp(font_name, (*face)->family_name, strlen((*face)->family_name)) == 0) break;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   141
		err = FT_Err_Cannot_Open_Resource;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   142
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   143
	} while ((FT_Long)++index != (*face)->num_faces);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   144
5267
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   145
af4a6aa071a7 (svn r7406) -Fix (r7377): [win32] Fontcache now also compiles in UNICODE mode; sorry, should've tested.
Darkvater
parents: 5240
diff changeset
   146
folder_error:
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   147
#if defined(UNICODE)
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   148
	free(font_path);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   149
#endif
5240
60cbd11d714c (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:
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   151
	RegCloseKey(hKey);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   152
	return err;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   153
}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   154
#else
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   155
# ifdef WITH_FONTCONFIG
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   156
static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   157
{
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   158
	FT_Error err = FT_Err_Cannot_Open_Resource;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   159
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   160
	if (!FcInit()) {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   161
		ShowInfoF("Unable to load font configuration");
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   162
	} else {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   163
		FcPattern *match;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   164
		FcPattern *pat;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   165
		FcFontSet *fs;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   166
		FcResult  result;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   167
		char *font_style;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   168
		char *font_family;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   169
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   170
		/* Split & strip the font's style */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   171
		font_family = strdup(font_name);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   172
		font_style = strchr(font_family, ',');
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   173
		if (font_style != NULL) {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   174
			font_style[0] = '\0';
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   175
			font_style++;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   176
			while (*font_style == ' ' || *font_style == '\t') font_style++;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   177
		}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   178
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   179
		/* Resolve the name and populate the information structure */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   180
		pat = FcNameParse((FcChar8*)font_family);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   181
		if (font_style != NULL) FcPatternAddString(pat, FC_STYLE, (FcChar8*)font_style);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   182
		FcConfigSubstitute(0, pat, FcMatchPattern);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   183
		FcDefaultSubstitute(pat);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   184
		fs = FcFontSetCreate();
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   185
		match = FcFontMatch(0, pat, &result);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   186
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   187
		if (fs != NULL && match != NULL) {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   188
			int i;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   189
			FcChar8 *family;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   190
			FcChar8 *style;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   191
			FcChar8 *file;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   192
			FcFontSetAdd(fs, match);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   193
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   194
			for (i = 0; err != FT_Err_Ok && i < fs->nfont; i++) {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   195
				/* Try the new filename */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   196
				if (FcPatternGetString(fs->fonts[i], FC_FILE,   0, &file)   == FcResultMatch &&
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   197
						FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch &&
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   198
						FcPatternGetString(fs->fonts[i], FC_STYLE,  0, &style)  == FcResultMatch) {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   199
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   200
					/* The correct style? */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   201
					if (font_style != NULL && strcasecmp(font_style, (char*)style) != 0) continue;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   202
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   203
					/* Font config takes the best shot, which, if the family name is spelled
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   204
					* wrongly a 'random' font, so check whether the family name is the
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   205
					* same as the supplied name */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   206
					if (strcasecmp(font_family, (char*)family) == 0) {
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   207
						err = FT_New_Face(_library, (char *)file, 0, face);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   208
					}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   209
				}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   210
			}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   211
		}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   212
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   213
		free(font_family);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   214
		FcPatternDestroy(pat);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   215
		FcFontSetDestroy(fs);
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   216
		FcFini();
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   217
	}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   218
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   219
	return err;
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   220
}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   221
# else
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   222
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) {return FT_Err_Cannot_Open_Resource;}
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   223
# endif /* WITH_FONTCONFIG */
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   224
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   225
#endif
5108
dc67d70b5a45 (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
   226
5117
a4a7fd847b77 (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
   227
/**
a4a7fd847b77 (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
   228
 * Loads the freetype font.
a4a7fd847b77 (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
   229
 * First type to load the fontname as if it were a path. If that fails,
a4a7fd847b77 (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
 * try to resolve the filename of the font using fontconfig, where the
a4a7fd847b77 (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
 * format is 'font family name' or 'font family name, font style'.
a4a7fd847b77 (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
 */
5108
dc67d70b5a45 (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
   233
static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *type)
dc67d70b5a45 (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
   234
{
dc67d70b5a45 (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
   235
	FT_Error error;
dc67d70b5a45 (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
dc67d70b5a45 (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
	if (strlen(font_name) == 0) return;
dc67d70b5a45 (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
dc67d70b5a45 (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
	error = FT_New_Face(_library, font_name, 0, face);
5219
bf1627501a26 (svn r7334) -Revert accidentally committed file in r7333
Darkvater
parents: 5218
diff changeset
   240
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   241
	if (error != FT_Err_Ok) error = GetFontByFaceName(font_name, face);
5219
bf1627501a26 (svn r7334) -Revert accidentally committed file in r7333
Darkvater
parents: 5218
diff changeset
   242
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   243
	if (error == FT_Err_Ok) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   244
		DEBUG(freetype, 2, "Requested '%s', using '%s %s'", font_name, (*face)->family_name, (*face)->style_name);
5219
bf1627501a26 (svn r7334) -Revert accidentally committed file in r7333
Darkvater
parents: 5218
diff changeset
   245
5108
dc67d70b5a45 (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
   246
		/* Attempt to select the unicode character map */
dc67d70b5a45 (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
   247
		error = FT_Select_Charmap(*face, ft_encoding_unicode);
5222
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   248
		if (error == FT_Err_Ok) return; // Success
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   249
4f4cfb2e248e (svn r7337) -Feature: [win32] Add font selection by specifying a font-name, ala Fontconfig. Pretty
Darkvater
parents: 5219
diff changeset
   250
		if (error == FT_Err_Invalid_CharMap_Handle) {
5108
dc67d70b5a45 (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
   251
			/* Try to pick a different character map instead. We default to
dc67d70b5a45 (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
   252
			 * the first map, but platform_id 0 encoding_id 0 should also
dc67d70b5a45 (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
   253
			 * be unicode (strange system...) */
dc67d70b5a45 (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
			FT_CharMap found = (*face)->charmaps[0];
dc67d70b5a45 (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
			int i;
dc67d70b5a45 (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
dc67d70b5a45 (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
			for (i = 0; i < (*face)->num_charmaps; i++) {
dc67d70b5a45 (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
				FT_CharMap charmap = (*face)->charmaps[i];
dc67d70b5a45 (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
				if (charmap->platform_id == 0 && charmap->encoding_id == 0) {
dc67d70b5a45 (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
					found = charmap;
dc67d70b5a45 (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
				}
dc67d70b5a45 (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
			}
dc67d70b5a45 (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
dc67d70b5a45 (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
			if (found != NULL) {
dc67d70b5a45 (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
				error = FT_Set_Charmap(*face, found);
dc67d70b5a45 (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
				if (error == FT_Err_Ok) return;
dc67d70b5a45 (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
			}
dc67d70b5a45 (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
		}
5240
60cbd11d714c (svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents: 5222
diff changeset
   269
	}
5108
dc67d70b5a45 (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
5240
60cbd11d714c (svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents: 5222
diff changeset
   271
	FT_Done_Face(*face);
60cbd11d714c (svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
Darkvater
parents: 5222
diff changeset
   272
	*face = NULL;
5108
dc67d70b5a45 (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
dc67d70b5a45 (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
   274
	ShowInfoF("Unable to use '%s' for %s font, FreeType reported error 0x%X, using sprite font instead", font_name, type, error);
dc67d70b5a45 (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
   275
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
void InitFreeType(void)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	if (strlen(_freetype.small_font) == 0 && strlen(_freetype.medium_font) == 0 && strlen(_freetype.large_font) == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   281
		DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead");
5108
dc67d70b5a45 (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
		return;
dc67d70b5a45 (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
   283
	}
dc67d70b5a45 (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
   284
dc67d70b5a45 (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
	if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
dc67d70b5a45 (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
		ShowInfoF("Unable to initialize FreeType, using sprite fonts instead");
dc67d70b5a45 (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
		return;
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   290
	DEBUG(freetype, 2, "Initialized");
5108
dc67d70b5a45 (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
dc67d70b5a45 (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
	/* Load each font */
dc67d70b5a45 (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
   293
	LoadFreeTypeFont(_freetype.small_font,  &_face_small,  "small");
dc67d70b5a45 (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
	LoadFreeTypeFont(_freetype.medium_font, &_face_medium, "medium");
dc67d70b5a45 (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
	LoadFreeTypeFont(_freetype.large_font,  &_face_large,  "large");
dc67d70b5a45 (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
dc67d70b5a45 (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
	/* Set each font size */
dc67d70b5a45 (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
	if (_face_small  != NULL) FT_Set_Pixel_Sizes(_face_small,  0, _freetype.small_size);
dc67d70b5a45 (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
	if (_face_medium != NULL) FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size);
dc67d70b5a45 (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
	if (_face_large  != NULL) FT_Set_Pixel_Sizes(_face_large,  0, _freetype.large_size);
dc67d70b5a45 (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
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
static FT_Face GetFontFace(FontSize size)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	switch (size) {
dc67d70b5a45 (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
		default: NOT_REACHED();
dc67d70b5a45 (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
		case FS_NORMAL: return _face_medium;
dc67d70b5a45 (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
		case FS_SMALL:  return _face_small;
dc67d70b5a45 (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
		case FS_LARGE:  return _face_large;
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
typedef struct GlyphEntry {
dc67d70b5a45 (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
	Sprite *sprite;
dc67d70b5a45 (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
	byte width;
dc67d70b5a45 (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
   318
} GlyphEntry;
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
   321
/* The glyph cache. This is structured to reduce memory consumption.
dc67d70b5a45 (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
 * 1) There is a 'segment' table for each font size.
dc67d70b5a45 (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
 * 2) Each segment table is a discrete block of characters.
dc67d70b5a45 (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
 * 3) Each block contains 256 (aligned) characters sequential characters.
dc67d70b5a45 (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
 *
dc67d70b5a45 (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
 * The cache is accessed in the following way:
dc67d70b5a45 (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
 * For character 0x0041  ('A'): _glyph_ptr[FS_NORMAL][0x00][0x41]
dc67d70b5a45 (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
 * For character 0x20AC (Euro): _glyph_ptr[FS_NORMAL][0x20][0xAC]
dc67d70b5a45 (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
 *
dc67d70b5a45 (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
 * Currently only 256 segments are allocated, "limiting" us to 65536 characters.
dc67d70b5a45 (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
 * This can be simply changed in the two functions Get & SetGlyphPtr.
dc67d70b5a45 (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
 */
dc67d70b5a45 (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
static GlyphEntry **_glyph_ptr[FS_END];
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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 *GetGlyphPtr(FontSize size, WChar key)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	if (_glyph_ptr[size] == NULL) return NULL;
dc67d70b5a45 (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
	if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) return NULL;
dc67d70b5a45 (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
	return &_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)];
dc67d70b5a45 (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
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	if (_glyph_ptr[size] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   347
		DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size);
5108
dc67d70b5a45 (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
		_glyph_ptr[size] = calloc(256, sizeof(**_glyph_ptr));
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
   350
dc67d70b5a45 (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
   351
	if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   352
		DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size);
5108
dc67d70b5a45 (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
		_glyph_ptr[size][GB(key, 8, 8)] = calloc(256, sizeof(***_glyph_ptr));
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
   355
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   356
	DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size);
5108
dc67d70b5a45 (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
	_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
dc67d70b5a45 (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
	_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width  = glyph->width;
dc67d70b5a45 (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
   359
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
const Sprite *GetGlyph(FontSize size, WChar key)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
   364
	FT_Face face = GetFontFace(size);
dc67d70b5a45 (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
   365
	FT_GlyphSlot slot;
dc67d70b5a45 (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
   366
	GlyphEntry new_glyph;
dc67d70b5a45 (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
   367
	GlyphEntry *glyph;
dc67d70b5a45 (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
   368
	Sprite *sprite;
dc67d70b5a45 (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
	int width;
dc67d70b5a45 (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
   370
	int height;
dc67d70b5a45 (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
   371
	int x;
dc67d70b5a45 (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
   372
	int y;
dc67d70b5a45 (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
   373
	int y_adj;
dc67d70b5a45 (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
   374
dc67d70b5a45 (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
   375
	assert(IsPrintable(key));
dc67d70b5a45 (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
   376
dc67d70b5a45 (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
   377
	/* Bail out if no face loaded, or for our special characters */
dc67d70b5a45 (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
   378
	if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) {
dc67d70b5a45 (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
   379
		SpriteID sprite = GetUnicodeGlyph(size, key);
dc67d70b5a45 (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
   380
		if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
dc67d70b5a45 (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
   381
		return GetSprite(sprite);
dc67d70b5a45 (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
   382
	}
dc67d70b5a45 (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
   383
dc67d70b5a45 (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
   384
	/* Check for the glyph in our cache */
dc67d70b5a45 (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
	glyph = GetGlyphPtr(size, key);
dc67d70b5a45 (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
	if (glyph != NULL && glyph->sprite != NULL) return glyph->sprite;
dc67d70b5a45 (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
dc67d70b5a45 (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
	slot = face->glyph;
dc67d70b5a45 (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
dc67d70b5a45 (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
	FT_Load_Char(face, key, FT_LOAD_DEFAULT);
dc67d70b5a45 (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
   391
	FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO);
dc67d70b5a45 (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
dc67d70b5a45 (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
	/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */
dc67d70b5a45 (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
	width  = max(1, slot->bitmap.width + (size == FS_NORMAL));
dc67d70b5a45 (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
	height = max(1, slot->bitmap.rows  + (size == FS_NORMAL));
dc67d70b5a45 (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
dc67d70b5a45 (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
	/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
dc67d70b5a45 (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
	sprite = calloc(width * height + 8, 1);
dc67d70b5a45 (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
	sprite->info   = 1;
dc67d70b5a45 (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
	sprite->width  = width;
dc67d70b5a45 (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
	sprite->height = height;
dc67d70b5a45 (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
	sprite->x_offs = slot->bitmap_left;
dc67d70b5a45 (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
	// XXX 2 should be determined somehow... it's right for the normal face
dc67d70b5a45 (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
	y_adj = (size == FS_NORMAL) ? 2 : 0;
dc67d70b5a45 (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
	sprite->y_offs = GetCharacterHeight(size) - slot->bitmap_top - y_adj;
dc67d70b5a45 (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
dc67d70b5a45 (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
	/* Draw shadow for medium size */
dc67d70b5a45 (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
	if (size == FS_NORMAL) {
dc67d70b5a45 (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
		for (y = 0; y < slot->bitmap.rows; y++) {
dc67d70b5a45 (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
			for (x = 0; x < slot->bitmap.width; x++) {
dc67d70b5a45 (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
				if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
dc67d70b5a45 (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
					sprite->data[1 + x + (1 + y) * sprite->width] = SHADOW_COLOUR;
dc67d70b5a45 (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
   413
				}
dc67d70b5a45 (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
   414
			}
dc67d70b5a45 (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
		}
dc67d70b5a45 (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
   416
	}
dc67d70b5a45 (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
dc67d70b5a45 (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
	for (y = 0; y < slot->bitmap.rows; y++) {
dc67d70b5a45 (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
		for (x = 0; x < slot->bitmap.width; x++) {
dc67d70b5a45 (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
			if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
dc67d70b5a45 (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
				sprite->data[x + y * sprite->width] = FACE_COLOUR;
dc67d70b5a45 (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
			}
dc67d70b5a45 (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
   423
		}
dc67d70b5a45 (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
   424
	}
dc67d70b5a45 (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
   425
dc67d70b5a45 (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
   426
	new_glyph.sprite = sprite;
dc67d70b5a45 (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
	new_glyph.width  = (slot->advance.x >> 6) + (size != FS_NORMAL);
dc67d70b5a45 (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
dc67d70b5a45 (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
   429
	SetGlyphPtr(size, key, &new_glyph);
dc67d70b5a45 (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
dc67d70b5a45 (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
	return sprite;
dc67d70b5a45 (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
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
   435
uint GetGlyphWidth(FontSize size, WChar key)
dc67d70b5a45 (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
   436
{
dc67d70b5a45 (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
   437
	FT_Face face = GetFontFace(size);
dc67d70b5a45 (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
	GlyphEntry *glyph;
dc67d70b5a45 (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
dc67d70b5a45 (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
	if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) {
dc67d70b5a45 (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
		SpriteID sprite = GetUnicodeGlyph(size, key);
dc67d70b5a45 (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
		if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
dc67d70b5a45 (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
		return SpriteExists(sprite) ? GetSprite(sprite)->width + (size != FS_NORMAL) : 0;
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
   445
dc67d70b5a45 (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
   446
	glyph = GetGlyphPtr(size, key);
dc67d70b5a45 (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
   447
	if (glyph == NULL || glyph->sprite == NULL) {
dc67d70b5a45 (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
		GetGlyph(size, key);
dc67d70b5a45 (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
		glyph = GetGlyphPtr(size, key);
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
dc67d70b5a45 (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
   452
	return glyph->width;
dc67d70b5a45 (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
   453
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
#endif /* WITH_FREETYPE */
dc67d70b5a45 (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
dc67d70b5a45 (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
   458
/* Sprite based glyph mapping */
dc67d70b5a45 (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
dc67d70b5a45 (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
#include "table/unicode.h"
dc67d70b5a45 (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
dc67d70b5a45 (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
static SpriteID **_unicode_glyph_map[FS_END];
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
/** Get the SpriteID of the first glyph for the given font size */
dc67d70b5a45 (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
static SpriteID GetFontBase(FontSize size)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	switch (size) {
dc67d70b5a45 (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
		default: NOT_REACHED();
dc67d70b5a45 (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
		case FS_NORMAL: return SPR_ASCII_SPACE;
dc67d70b5a45 (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
		case FS_SMALL:  return SPR_ASCII_SPACE_SMALL;
dc67d70b5a45 (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
		case FS_LARGE:  return SPR_ASCII_SPACE_BIG;
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
SpriteID GetUnicodeGlyph(FontSize size, uint32 key)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) return 0;
dc67d70b5a45 (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
	return _unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)];
dc67d70b5a45 (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
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	if (_unicode_glyph_map[size] == NULL) _unicode_glyph_map[size] = calloc(256, sizeof(*_unicode_glyph_map[size]));
dc67d70b5a45 (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
	if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) _unicode_glyph_map[size][GB(key, 8, 8)] = calloc(256, sizeof(**_unicode_glyph_map[size]));
dc67d70b5a45 (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
	_unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite;
dc67d70b5a45 (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
}
dc67d70b5a45 (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
dc67d70b5a45 (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
dc67d70b5a45 (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
void InitializeUnicodeGlyphMap(void)
dc67d70b5a45 (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
{
dc67d70b5a45 (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
	FontSize size;
dc67d70b5a45 (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
	SpriteID base;
dc67d70b5a45 (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
	SpriteID sprite;
dc67d70b5a45 (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
	uint i;
dc67d70b5a45 (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
dc67d70b5a45 (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
	for (size = FS_NORMAL; size != FS_END; size++) {
5153
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   500
		/* Clear out existing glyph map if it exists */
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   501
		if (_unicode_glyph_map[size] != NULL) {
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   502
			for (i = 0; i < 256; i++) {
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   503
				if (_unicode_glyph_map[size][i] != NULL) free(_unicode_glyph_map[size][i]);
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   504
			}
5154
80955f08ffc7 (svn r7249) -Fix (r7248): Missed a free()...
peter1138
parents: 5153
diff changeset
   505
			free(_unicode_glyph_map[size]);
5153
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   506
			_unicode_glyph_map[size] = NULL;
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   507
		}
3c82ff1acd6f (svn r7248) -Codechange: Support reinitializing the unicode glyph map.
peter1138
parents: 5117
diff changeset
   508
5108
dc67d70b5a45 (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
		base = GetFontBase(size);
dc67d70b5a45 (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
		for (i = ASCII_LETTERSTART; i < 256; i++) {
dc67d70b5a45 (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
			sprite = base + i - ASCII_LETTERSTART;
dc67d70b5a45 (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
			if (!SpriteExists(sprite)) continue;
dc67d70b5a45 (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
   513
			SetUnicodeGlyph(size, i, sprite);
dc67d70b5a45 (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
   514
			SetUnicodeGlyph(size, i + SCC_SPRITE_START, sprite);
dc67d70b5a45 (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
		}
dc67d70b5a45 (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
		for (i = 0; i < lengthof(_default_unicode_map); i++) {
dc67d70b5a45 (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
			sprite = base + _default_unicode_map[i].key - ASCII_LETTERSTART;
dc67d70b5a45 (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
			SetUnicodeGlyph(size, _default_unicode_map[i].code, sprite);
dc67d70b5a45 (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
   519
		}
dc67d70b5a45 (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
	}
dc67d70b5a45 (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
   521
}
dc67d70b5a45 (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
   522
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   523
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5270
diff changeset
   524