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