35 static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
42 ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] -
_default_font_height[fs]),
75 void ClearGlyphToSpriteMap();
88 virtual const void *
GetFontTable(uint32 tag,
size_t &length) { length = 0;
return nullptr; }
130 default: NOT_REACHED();
132 case FS_NORMAL: base = SPR_ASCII_SPACE;
break;
133 case FS_SMALL: base = SPR_ASCII_SPACE_SMALL;
break;
134 case FS_LARGE: base = SPR_ASCII_SPACE_BIG;
break;
139 if (!SpriteExists(sprite))
continue;
144 for (uint i = 0; i <
lengthof(_default_unicode_map); i++) {
145 byte key = _default_unicode_map[i].key;
165 for (uint i = 0; i < 256; i++) {
181 return GetSprite(sprite,
ST_FONT);
203 #if defined(WITH_FREETYPE) || defined(_WIN32) 207 static const byte FACE_COLOUR = 1;
208 static const byte SHADOW_COLOUR = 2;
244 virtual const void *InternalGetFontTable(uint32 tag,
size_t &length) = 0;
245 virtual const Sprite *InternalGetGlyph(
GlyphID key,
bool aa) = 0;
255 virtual const void *
GetFontTable(uint32 tag,
size_t &length);
279 free(iter.second.second);
290 for (
int i = 0; i < 256; i++) {
293 for (
int j = 0; j < 256; j++) {
315 void TrueTypeFontCache::SetGlyphPtr(
GlyphID key,
const GlyphEntry *glyph,
bool duplicate)
318 DEBUG(freetype, 3,
"Allocating root glyph cache for size %u", this->
fs);
323 DEBUG(freetype, 3,
"Allocating glyph cache for range 0x%02X00, size %u",
GB(key, 8, 8), this->
fs);
327 DEBUG(freetype, 4,
"Set glyph for unicode character 0x%04X, size %u", key, this->
fs);
333 static void *AllocateFont(
size_t size)
335 return MallocT<byte>(size);
340 static bool GetFontAAState(
FontSize size)
346 default: NOT_REACHED();
364 if (glyph ==
nullptr || glyph->
sprite ==
nullptr) {
366 glyph = this->GetGlyphPtr(key);
374 if ((key & SPRITE_GLYPH) != 0)
return this->
parent->
GetGlyph(key);
378 if (glyph !=
nullptr && glyph->
sprite !=
nullptr)
return glyph->
sprite;
382 if (question_glyph == 0) {
385 #define CPSET { 0, 0, 0, 0, 1 } 386 #define CP___ { 0, 0, 0, 0, 0 } 388 CP___, CP___, CPSET, CPSET, CPSET, CPSET, CP___, CP___,
389 CP___, CPSET, CPSET, CP___, CP___, CPSET, CPSET, CP___,
390 CP___, CP___, CP___, CP___, CP___, CPSET, CPSET, CP___,
391 CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, CP___,
392 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
393 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
394 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
395 CP___, CP___, CP___, CP___, CP___, CP___, CP___, CP___,
396 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
397 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
407 builtin_questionmark_data
411 assert(spr !=
nullptr);
415 this->SetGlyphPtr(key, &new_glyph,
false);
420 glyph = this->GetGlyphPtr(question_glyph);
421 this->SetGlyphPtr(key, glyph,
true);
426 return this->InternalGetGlyph(key, GetFontAAState(this->
fs));
433 length = iter->second.first;
434 return iter->second.second;
437 const void *result = this->InternalGetFontTable(tag, length);
445 #include <ft2build.h> 446 #include FT_FREETYPE_H 448 #include FT_TRUETYPE_TABLES_H 455 void SetFontSize(
FontSize fs, FT_Face face,
int pixels);
456 virtual const void *InternalGetFontTable(uint32 tag,
size_t &length);
457 virtual const Sprite *InternalGetGlyph(
GlyphID key,
bool aa);
468 FT_Library _library =
nullptr;
479 assert(face !=
nullptr);
481 this->SetFontSize(fs, face, pixels);
484 void FreeTypeFontCache::SetFontSize(
FontSize fs, FT_Face
face,
int pixels)
489 pixels = scaled_height;
491 TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(this->
face, ft_sfnt_head);
492 if (head !=
nullptr) {
503 FT_Error err = FT_Set_Pixel_Sizes(this->
face, 0, pixels);
504 if (err != FT_Err_Ok) {
507 FT_Bitmap_Size *bs = this->
face->available_sizes;
508 int i = this->
face->num_fixed_sizes;
513 if (
abs(pixels - bs->height) >=
abs(pixels - n))
continue;
515 chosen = this->
face->num_fixed_sizes - i;
520 err = FT_Select_Size(this->
face, chosen);
524 if (err == FT_Err_Ok) {
526 this->
ascender = this->
face->size->metrics.ascender >> 6;
531 DEBUG(freetype, 0,
"Font size selection failed. Using FontCache defaults.");
546 default: NOT_REACHED();
555 if (_library ==
nullptr) {
556 if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
557 ShowInfoF(
"Unable to initialize FreeType, using sprite fonts instead");
561 DEBUG(freetype, 2,
"Initialized");
564 FT_Face
face =
nullptr;
565 FT_Error
error = FT_New_Face(_library, settings->
font, 0, &face);
569 if (error == FT_Err_Ok) {
570 DEBUG(freetype, 2,
"Requested '%s', using '%s %s'", settings->
font, face->family_name, face->style_name);
573 error = FT_Select_Charmap(face, ft_encoding_unicode);
574 if (error == FT_Err_Ok)
goto found_face;
576 if (error == FT_Err_Invalid_CharMap_Handle) {
580 FT_CharMap found = face->charmaps[0];
583 for (i = 0; i < face->num_charmaps; i++) {
584 FT_CharMap charmap = face->charmaps[i];
585 if (charmap->platform_id == 0 && charmap->encoding_id == 0) {
590 if (found !=
nullptr) {
591 error = FT_Set_Charmap(face, found);
592 if (error == FT_Err_Ok)
goto found_face;
599 static const char *SIZE_TO_NAME[] = {
"medium",
"small",
"large",
"mono" };
600 ShowInfoF(
"Unable to use '%s' for %s font, FreeType reported error 0x%X, using sprite font instead", settings->
font, SIZE_TO_NAME[fs], error);
613 FT_Done_Face(this->
face);
614 this->
face =
nullptr;
630 const Sprite *FreeTypeFontCache::InternalGetGlyph(
GlyphID key,
bool aa)
632 FT_GlyphSlot slot = this->
face->glyph;
634 FT_Load_Glyph(this->
face, key, aa ? FT_LOAD_TARGET_NORMAL : FT_LOAD_TARGET_MONO);
635 FT_Render_Glyph(this->
face->glyph, aa ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
638 aa = (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
641 uint width =
max(1U, (uint)slot->bitmap.width + (this->fs ==
FS_NORMAL));
645 if (width > 256 || height > 256)
usererror(
"Font glyph is too large");
651 sprite.
width = width;
653 sprite.
x_offs = slot->bitmap_left;
658 for (uint y = 0; y < (uint)slot->bitmap.rows; y++) {
659 for (uint x = 0; x < (uint)slot->bitmap.width; x++) {
660 if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) :
HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
661 sprite.
data[1 + x + (1 + y) * sprite.
width].
m = SHADOW_COLOUR;
662 sprite.
data[1 + x + (1 + y) * sprite.
width].
a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
668 for (uint y = 0; y < (uint)slot->bitmap.rows; y++) {
669 for (uint x = 0; x < (uint)slot->bitmap.width; x++) {
670 if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) :
HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
671 sprite.
data[x + y * sprite.
width].
m = FACE_COLOUR;
672 sprite.
data[x + y * sprite.
width].
a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
679 new_glyph.
width = slot->advance.x >> 6;
681 this->SetGlyphPtr(key, &new_glyph);
689 assert(IsPrintable(key));
691 if (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END) {
695 return FT_Get_Char_Index(this->
face, key);
698 const void *FreeTypeFontCache::InternalGetFontTable(uint32 tag,
size_t &length)
701 FT_Byte *result =
nullptr;
703 FT_Load_Sfnt_Table(this->
face, tag, 0,
nullptr, &len);
706 result = MallocT<FT_Byte>(len);
707 FT_Load_Sfnt_Table(this->
face, tag, 0, result, &len);
714 #elif defined(_WIN32) 717 #ifndef ANTIALIASED_QUALITY 718 #define ANTIALIASED_QUALITY 4 725 HFONT font =
nullptr;
731 virtual const void *InternalGetFontTable(uint32 tag,
size_t &length);
732 virtual const Sprite *InternalGetGlyph(
GlyphID key,
bool aa);
735 Win32FontCache(
FontSize fs,
const LOGFONT &logfont,
int pixels);
739 virtual const char *
GetFontName() {
return WIDE_TO_MB(this->logfont.lfFaceName); }
741 virtual void *
GetOSHandle() {
return &this->logfont; }
753 this->dc = CreateCompatibleDC(
nullptr);
754 this->SetFontSize(
fs, pixels);
757 Win32FontCache::~Win32FontCache()
761 DeleteObject(this->font);
764 void Win32FontCache::SetFontSize(
FontSize fs,
int pixels)
769 pixels = scaled_height;
771 HFONT temp = CreateFontIndirect(&this->logfont);
772 if (temp !=
nullptr) {
773 HGDIOBJ old = SelectObject(this->dc, temp);
775 UINT size = GetOutlineTextMetrics(this->dc, 0,
nullptr);
776 LPOUTLINETEXTMETRIC otm = (LPOUTLINETEXTMETRIC)
AllocaM(BYTE, size);
777 GetOutlineTextMetrics(this->dc, size, otm);
784 SelectObject(dc, old);
793 this->logfont.lfHeight = -pixels;
794 this->logfont.lfWidth = 0;
795 this->logfont.lfOutPrecision = ANTIALIASED_QUALITY;
797 if (this->font !=
nullptr) {
798 SelectObject(dc, this->old_font);
799 DeleteObject(this->font);
801 this->font = CreateFontIndirect(&this->logfont);
802 this->old_font = SelectObject(this->dc, this->font);
805 UINT otmSize = GetOutlineTextMetrics(this->dc, 0,
nullptr);
806 POUTLINETEXTMETRIC otm = (POUTLINETEXTMETRIC)
AllocaM(BYTE, otmSize);
807 GetOutlineTextMetrics(this->dc, otmSize, otm);
810 this->
ascender = otm->otmTextMetrics.tmAscent;
811 this->
descender = otm->otmTextMetrics.tmDescent;
813 this->glyph_size.cx = otm->otmTextMetrics.tmMaxCharWidth;
814 this->glyph_size.cy = otm->otmTextMetrics.tmHeight;
816 DEBUG(freetype, 2,
"Loaded font '%s' with size %d",
FS2OTTD((LPTSTR)((BYTE *)otm + (ptrdiff_t)otm->otmpFullName)), pixels);
822 void Win32FontCache::ClearFontCache()
825 if (this->font !=
nullptr) this->SetFontSize(this->
fs, this->
req_size);
830 const Sprite *Win32FontCache::InternalGetGlyph(
GlyphID key,
bool aa)
833 MAT2 mat = { {0, 1}, {0, 0}, {0, 0}, {0, 1} };
836 DWORD size = this->glyph_size.cy *
Align(aa ? this->glyph_size.cx :
max(this->glyph_size.cx / 8l, 1l), 4);
837 byte *bmp =
AllocaM(byte, size);
838 size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
840 if (size == GDI_ERROR) {
846 size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, 0,
nullptr, &mat);
847 if (size == GDI_ERROR)
usererror(
"Unable to render font glyph");
849 GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
853 uint width =
max(1U, (uint)gm.gmBlackBoxX + (this->fs ==
FS_NORMAL));
857 if (width > 256 || height > 256)
usererror(
"Font glyph is too large");
863 sprite.
width = width;
865 sprite.
x_offs = gm.gmptGlyphOrigin.x;
874 uint pitch =
Align(aa ? gm.gmBlackBoxX :
max(gm.gmBlackBoxX / 8u, 1u), 4);
878 for (uint y = 0; y < gm.gmBlackBoxY; y++) {
879 for (uint x = 0; x < gm.gmBlackBoxX; x++) {
880 if (aa ? (bmp[x + y * pitch] > 0) :
HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
881 sprite.
data[1 + x + (1 + y) * sprite.
width].
m = SHADOW_COLOUR;
882 sprite.
data[1 + x + (1 + y) * sprite.
width].
a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
888 for (uint y = 0; y < gm.gmBlackBoxY; y++) {
889 for (uint x = 0; x < gm.gmBlackBoxX; x++) {
890 if (aa ? (bmp[x + y * pitch] > 0) :
HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
891 sprite.
data[x + y * sprite.
width].
m = FACE_COLOUR;
892 sprite.
data[x + y * sprite.
width].
a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
900 new_glyph.
width = gm.gmCellIncX;
902 this->SetGlyphPtr(key, &new_glyph);
904 return new_glyph.sprite;
909 assert(IsPrintable(key));
911 if (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END) {
917 if (key >= 0x010000U) {
918 chars[0] = (WCHAR)(((key - 0x010000U) >> 10) + 0xD800);
919 chars[1] = (WCHAR)(((key - 0x010000U) & 0x3FF) + 0xDC00);
921 chars[0] = (WCHAR)(key & 0xFFFF);
924 WORD glyphs[2] = {0, 0};
925 GetGlyphIndicesW(this->dc, chars, key >= 0x010000U ? 2 : 1, glyphs, GGI_MARK_NONEXISTING_GLYPHS);
927 return glyphs[0] != 0xFFFF ? glyphs[0] : 0;
930 const void *Win32FontCache::InternalGetFontTable(uint32 tag,
size_t &length)
932 DWORD len = GetFontData(this->dc, tag, 0,
nullptr, 0);
934 void *result =
nullptr;
935 if (len != GDI_ERROR && len > 0) {
936 result = MallocT<BYTE>(len);
937 GetFontData(this->dc, tag, 0, result, len);
952 static const char *SIZE_TO_NAME[] = {
"medium",
"small",
"large",
"mono" };
956 default: NOT_REACHED();
967 logfont.lfPitchAndFamily = fs ==
FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
968 logfont.lfCharSet = DEFAULT_CHARSET;
969 logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
970 logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
973 logfont = *(
const LOGFONT *)settings->
os_handle;
976 TCHAR fontPath[MAX_PATH];
979 if (AddFontResourceEx(fontPath, FR_PRIVATE, 0) != 0) {
982 typedef BOOL(WINAPI * PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
984 static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T(
"Gdi32")),
"GetFontResourceInfoW");
986 static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T(
"Gdi32")),
"GetFontResourceInfoA");
989 if (GetFontResourceInfo !=
nullptr) {
992 if (GetFontResourceInfo(fontPath, &len,
nullptr, 2) && len >=
sizeof(LOGFONT)) {
993 LOGFONT *buf = (LOGFONT *)
AllocaM(byte, len);
994 if (GetFontResourceInfo(fontPath, &len, buf, 2)) {
1001 if (logfont.lfFaceName[0] == 0) {
1002 TCHAR fname[_MAX_FNAME];
1003 _tsplitpath(fontPath,
nullptr,
nullptr, fname,
nullptr);
1005 _tcsncpy_s(logfont.lfFaceName,
lengthof(logfont.lfFaceName), fname, _TRUNCATE);
1006 logfont.lfWeight = strcasestr(settings->
font,
" bold") !=
nullptr || strcasestr(settings->
font,
"-bold") !=
nullptr ? FW_BOLD : FW_NORMAL;
1009 ShowInfoF(
"Unable to load file '%s' for %s font, using default windows font selection instead", settings->
font, SIZE_TO_NAME[fs]);
1013 if (logfont.lfFaceName[0] == 0) {
1014 logfont.lfWeight = strcasestr(settings->
font,
" bold") !=
nullptr ? FW_BOLD : FW_NORMAL;
1018 HFONT font = CreateFontIndirect(&logfont);
1019 if (font ==
nullptr) {
1020 ShowInfoF(
"Unable to use '%s' for %s font, Win32 reported error 0x%lX, using sprite font instead", settings->
font, SIZE_TO_NAME[fs], GetLastError());
1025 new Win32FontCache(fs, logfont, settings->
size);
1039 if (monospace != (
fs ==
FS_MONO))
continue;
1044 #ifdef WITH_FREETYPE 1046 #elif defined(_WIN32) 1062 #ifdef WITH_FREETYPE 1063 FT_Done_FreeType(_library);
Functions related to OTTD's strings.
Character mapping for using Unicode characters in OTTD.
virtual void InitializeUnicodeGlyphMap()
Initialize the glyph map.
int height
The height of the font.
Control codes that are embedded in the translation strings.
TCHAR * convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp)
Convert from OpenTTD's encoding to that of the environment in UNICODE.
const char * FS2OTTD(const TCHAR *name)
Convert to OpenTTD's encoding from that of the local environment.
virtual SpriteID GetUnicodeGlyph(WChar key)
Get the SpriteID mapped to the given key.
SpriteFontCache(FontSize fs)
Create a new sprite font cache.
virtual void * GetOSHandle()
Get the native OS font handle, if there is one.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int descender
The descender value of the font.
Settings for a single freetype font.
~FreeTypeFontCache()
Free everything that was allocated for this font cache.
Index of the monospaced font in the font tables.
Data structure describing a sprite.
fluid_settings_t * settings
FluidSynth settings handle.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Implementation of simple mapping class.
Functions related to detecting/finding the right font.
virtual ~TrueTypeFontCache()
Free everything that was allocated for this font cache.
void AllocateData(ZoomLevel zoom, size_t size)
Allocate the sprite data of this sprite.
virtual void ClearFontCache()
Clear the font cache.
virtual bool IsBuiltInFont()
Is this a built-in sprite font?
Functions for Standard In/Out file operations.
FreeTypeSubSetting large
The largest font; mostly used for newspapers.
byte width
The width of the glyph.
int units_per_em
The units per EM value of the font.
virtual void SetUnicodeGlyph(WChar key, SpriteID sprite)=0
Map a SpriteID to the key.
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
Container for information about a glyph.
virtual const char * GetFontName()
Get the name of this font.
virtual Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)=0
Convert a sprite from the loader to our own format.
virtual GlyphID MapCharToGlyph(WChar key)
Map a character into a glyph.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
static T max(const T a, const T b)
Returns the maximum of two values.
Functions related to laying out the texts.
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
SmallMap< uint32, SmallPair< size_t, const void * > > FontTable
Table with font table cache.
Sprite * sprite
The loaded sprite.
Settings for the freetype fonts.
bool HasParent()
Check whether the font cache has a parent.
Definition of a common pixel in OpenTTD's realm.
SpriteType type
The sprite type.
Font cache for fonts that are based on a freetype font.
Types related to zooming in and out.
Simple mapping class targeted for small sets of data.
void InitFreeType(bool monospace)
(Re)initialize the freetype related things, i.e.
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
Functions to read fonts from files and cache them.
virtual void ClearFontCache()
Reset cached glyphs.
bool aa
Whether to do anti aliasing or not.
static T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
virtual ~FontCache()
Clean everything up.
FreeTypeSubSetting mono
The mono space font used for license/readme viewers.
FontCache(FontSize fs)
Create a new font cache.
FT_Face face
The font face associated with this font.
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
bool FileExists(const char *filename)
Test whether the given filename exists.
Definition of base types and functions in a cross-platform compatible way.
virtual bool IsBuiltInFont()
Is this a built-in sprite font?
int req_size
Requested font size.
Font cache for fonts that are based on a freetype font.
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
virtual bool GetDrawGlyphShadow()
Do we need to draw a glyph shadow?
A number of safeguards to prevent using unsafe methods.
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
Get the font loaded into a Freetype face by using a font-name.
virtual const void * GetFontTable(uint32 tag, size_t &length)
Read a font table from the font.
int16 x_offs
The x-offset of where the sprite will be drawn.
virtual int GetHeight() const
Get the height of the font.
virtual const Sprite * GetGlyph(GlyphID key)
Get the glyph (sprite) of the given key.
FreeTypeFontCache(FontSize fs, FT_Face face, int pixels)
Create a new FreeTypeFontCache.
~SpriteFontCache()
Free everything we allocated.
SpriteLoader::CommonPixel * data
The sprite itself.
virtual bool GetDrawGlyphShadow()
Do we need to draw a glyph shadow?
virtual SpriteID GetUnicodeGlyph(WChar key)
Get the SpriteID mapped to the given key.
virtual void InitializeUnicodeGlyphMap()
Initialize the glyph map.
Structure for passing information from the sprite loader to the blitter.
FreeTypeSubSetting medium
The normal font size.
bool Insert(const T &key, const U &data)
Adds new item to this map.
static const int MAX_FONT_SIZE
Maximum font size.
Font cache for fonts that are based on a TrueType font.
#define lengthof(x)
Return the length of an fixed size array.
bool duplicate
Whether this glyph entry is a duplicate, i.e. may this be freed?
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
static T min(const T a, const T b)
Returns the minimum of two values.
virtual GlyphID MapCharToGlyph(WChar key)=0
Map a character into a glyph.
static void ResetFontCache(FontSize size)
Reset cached font information.
virtual int GetFontSize() const
Get the nominal font size of the font.
Font cache for basic fonts.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
#define DEBUG(name, level,...)
Output a line of debugging information.
FontCache * parent
The parent of this font cache.
uint size
The (requested) size of the font.
uint16 width
Width of the sprite.
char font[MAX_PATH]
The name of the font, or path to the font.
uint16 width
Width of the sprite.
void ClearGlyphToSpriteMap()
Clear the glyph to sprite mapping.
const void * os_handle
Optional native OS font info.
SpriteID ** glyph_to_spriteid_map
Mapping of glyphs to sprite IDs.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static FontCache * caches[FS_END]
All the font caches.
virtual uint GetGlyphWidth(GlyphID key)
Get the width of the glyph with the given key.
virtual void SetUnicodeGlyph(WChar key, SpriteID sprite)
Map a SpriteID to the key.
virtual const char * GetFontName()
Get the name of this font.
TrueTypeFontCache(FontSize fs, int pixels)
Create a new TrueTypeFontCache.
virtual bool IsBuiltInFont()
Is this a built-in sprite font?
static const byte CLRA
Identifier to clear all glyphs at this codepoint.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
FreeTypeSubSetting small
The smallest font; mostly used for zoomed out view.
virtual const Sprite * GetGlyph(GlyphID key)=0
Get the glyph (sprite) of the given key.
Functions related to zooming.
FontSize
Available font sizes.
uint16 height
Height of the sprite.
static void LoadFreeTypeFont(FontSize fs)
Loads the freetype font.
Index of the normal font in the font tables.
virtual uint GetGlyphWidth(GlyphID key)
Get the width of the glyph with the given key.
virtual bool GetDrawGlyphShadow()=0
Do we need to draw a glyph shadow?
virtual int GetHeight() const
Get the height of the font.
static const int _default_font_height[FS_END]
Default heights for the different sizes of fonts.
void UninitFreeType()
Free everything allocated w.r.t.
int16 y_offs
The y-offset of where the sprite will be drawn.
Index of the small font in the font tables.
virtual void InitializeUnicodeGlyphMap()=0
Initialize the glyph map.
int ascender
The ascender value of the font.
int used_size
Used font size.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Index of the large font in the font tables.
const FontSize fs
The size of the font.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
virtual const void * GetFontTable(uint32 tag, size_t &length)
Read a font table from the font.
virtual GlyphID MapCharToGlyph(WChar key)
Map a character into a glyph.
uint32 GlyphID
Glyphs are characters from a font.
virtual void ClearFontCache()=0
Clear the font cache.
virtual const Sprite * GetGlyph(GlyphID key)
Get the glyph (sprite) of the given key.
virtual void SetUnicodeGlyph(WChar key, SpriteID sprite)
Map a SpriteID to the key.
uint32 WChar
Type for wide characters, i.e.
GlyphEntry ** glyph_to_sprite
The glyph cache.
declarations of functions for MS windows systems
This file contains all sprite-related enums and defines.
Factory to 'query' all available blitters.
virtual SpriteID GetUnicodeGlyph(WChar key)=0
Get the SpriteID mapped to the given key.
virtual void ClearFontCache()
Reset cached glyphs.
static const int ASCII_LETTERSTART
First printable ASCII letter.
FontTable font_tables
Cached font tables.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().