33 static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
40 ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] -
_default_font_height[fs]),
73 void ClearGlyphToSpriteMap();
86 virtual const void *
GetFontTable(uint32 tag,
size_t &length) { length = 0;
return nullptr; }
128 default: NOT_REACHED();
130 case FS_NORMAL: base = SPR_ASCII_SPACE;
break;
131 case FS_SMALL: base = SPR_ASCII_SPACE_SMALL;
break;
132 case FS_LARGE: base = SPR_ASCII_SPACE_BIG;
break;
137 if (!SpriteExists(sprite))
continue;
142 for (uint i = 0; i <
lengthof(_default_unicode_map); i++) {
143 byte key = _default_unicode_map[i].key;
163 for (uint i = 0; i < 256; i++) {
179 return GetSprite(sprite,
ST_FONT);
201 #if defined(WITH_FREETYPE) || defined(_WIN32) 205 static const byte FACE_COLOUR = 1;
206 static const byte SHADOW_COLOUR = 2;
242 virtual const void *InternalGetFontTable(uint32 tag,
size_t &length) = 0;
243 virtual const Sprite *InternalGetGlyph(
GlyphID key,
bool aa) = 0;
253 virtual const void *
GetFontTable(uint32 tag,
size_t &length);
277 free(iter.second.second);
288 for (
int i = 0; i < 256; i++) {
291 for (
int j = 0; j < 256; j++) {
313 void TrueTypeFontCache::SetGlyphPtr(
GlyphID key,
const GlyphEntry *glyph,
bool duplicate)
316 DEBUG(freetype, 3,
"Allocating root glyph cache for size %u", this->
fs);
321 DEBUG(freetype, 3,
"Allocating glyph cache for range 0x%02X00, size %u",
GB(key, 8, 8), this->
fs);
325 DEBUG(freetype, 4,
"Set glyph for unicode character 0x%04X, size %u", key, this->
fs);
331 static void *AllocateFont(
size_t size)
333 return MallocT<byte>(size);
338 static bool GetFontAAState(
FontSize size)
344 default: NOT_REACHED();
362 if (glyph ==
nullptr || glyph->
sprite ==
nullptr) {
364 glyph = this->GetGlyphPtr(key);
372 if ((key & SPRITE_GLYPH) != 0)
return this->
parent->
GetGlyph(key);
376 if (glyph !=
nullptr && glyph->
sprite !=
nullptr)
return glyph->
sprite;
380 if (question_glyph == 0) {
383 #define CPSET { 0, 0, 0, 0, 1 } 384 #define CP___ { 0, 0, 0, 0, 0 } 386 CP___, CP___, CPSET, CPSET, CPSET, CPSET, CP___, CP___,
387 CP___, CPSET, CPSET, CP___, CP___, CPSET, CPSET, CP___,
388 CP___, CP___, CP___, CP___, CP___, CPSET, CPSET, CP___,
389 CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, CP___,
390 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
391 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
392 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
393 CP___, CP___, CP___, CP___, CP___, CP___, CP___, CP___,
394 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
395 CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
405 builtin_questionmark_data
409 assert(spr !=
nullptr);
413 this->SetGlyphPtr(key, &new_glyph,
false);
418 glyph = this->GetGlyphPtr(question_glyph);
419 this->SetGlyphPtr(key, glyph,
true);
424 return this->InternalGetGlyph(key, GetFontAAState(this->
fs));
431 length = iter->second.first;
432 return iter->second.second;
435 const void *result = this->InternalGetFontTable(tag, length);
443 #include <ft2build.h> 444 #include FT_FREETYPE_H 446 #include FT_TRUETYPE_TABLES_H 453 void SetFontSize(
FontSize fs, FT_Face face,
int pixels);
454 virtual const void *InternalGetFontTable(uint32 tag,
size_t &length);
455 virtual const Sprite *InternalGetGlyph(
GlyphID key,
bool aa);
466 FT_Library _library =
nullptr;
477 assert(face !=
nullptr);
479 this->SetFontSize(fs, face, pixels);
482 void FreeTypeFontCache::SetFontSize(
FontSize fs, FT_Face
face,
int pixels)
487 pixels = scaled_height;
489 TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(this->
face, ft_sfnt_head);
490 if (head !=
nullptr) {
501 FT_Error err = FT_Set_Pixel_Sizes(this->
face, 0, pixels);
502 if (err != FT_Err_Ok) {
505 FT_Bitmap_Size *bs = this->
face->available_sizes;
506 int i = this->
face->num_fixed_sizes;
511 if (
abs(pixels - bs->height) >=
abs(pixels - n))
continue;
513 chosen = this->
face->num_fixed_sizes - i;
518 err = FT_Select_Size(this->
face, chosen);
522 if (err == FT_Err_Ok) {
524 this->
ascender = this->
face->size->metrics.ascender >> 6;
529 DEBUG(freetype, 0,
"Font size selection failed. Using FontCache defaults.");
544 default: NOT_REACHED();
553 if (_library ==
nullptr) {
554 if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
555 ShowInfoF(
"Unable to initialize FreeType, using sprite fonts instead");
559 DEBUG(freetype, 2,
"Initialized");
562 FT_Face
face =
nullptr;
563 FT_Error
error = FT_New_Face(_library, settings->
font, 0, &face);
567 if (error == FT_Err_Ok) {
568 DEBUG(freetype, 2,
"Requested '%s', using '%s %s'", settings->
font, face->family_name, face->style_name);
571 error = FT_Select_Charmap(face, ft_encoding_unicode);
572 if (error == FT_Err_Ok)
goto found_face;
574 if (error == FT_Err_Invalid_CharMap_Handle) {
578 FT_CharMap found = face->charmaps[0];
581 for (i = 0; i < face->num_charmaps; i++) {
582 FT_CharMap charmap = face->charmaps[i];
583 if (charmap->platform_id == 0 && charmap->encoding_id == 0) {
588 if (found !=
nullptr) {
589 error = FT_Set_Charmap(face, found);
590 if (error == FT_Err_Ok)
goto found_face;
597 static const char *SIZE_TO_NAME[] = {
"medium",
"small",
"large",
"mono" };
598 ShowInfoF(
"Unable to use '%s' for %s font, FreeType reported error 0x%X, using sprite font instead", settings->
font, SIZE_TO_NAME[fs], error);
611 FT_Done_Face(this->
face);
612 this->
face =
nullptr;
628 const Sprite *FreeTypeFontCache::InternalGetGlyph(
GlyphID key,
bool aa)
630 FT_GlyphSlot slot = this->
face->glyph;
632 FT_Load_Glyph(this->
face, key, aa ? FT_LOAD_TARGET_NORMAL : FT_LOAD_TARGET_MONO);
633 FT_Render_Glyph(this->
face->glyph, aa ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
636 aa = (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
639 uint width =
max(1U, (uint)slot->bitmap.width + (this->fs ==
FS_NORMAL));
643 if (width > 256 || height > 256)
usererror(
"Font glyph is too large");
649 sprite.
width = width;
651 sprite.
x_offs = slot->bitmap_left;
656 for (uint y = 0; y < (uint)slot->bitmap.rows; y++) {
657 for (uint x = 0; x < (uint)slot->bitmap.width; x++) {
658 if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) :
HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
659 sprite.
data[1 + x + (1 + y) * sprite.
width].
m = SHADOW_COLOUR;
660 sprite.
data[1 + x + (1 + y) * sprite.
width].
a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
666 for (uint y = 0; y < (uint)slot->bitmap.rows; y++) {
667 for (uint x = 0; x < (uint)slot->bitmap.width; x++) {
668 if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) :
HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
669 sprite.
data[x + y * sprite.
width].
m = FACE_COLOUR;
670 sprite.
data[x + y * sprite.
width].
a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
677 new_glyph.
width = slot->advance.x >> 6;
679 this->SetGlyphPtr(key, &new_glyph);
687 assert(IsPrintable(key));
689 if (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END) {
693 return FT_Get_Char_Index(this->
face, key);
696 const void *FreeTypeFontCache::InternalGetFontTable(uint32 tag,
size_t &length)
699 FT_Byte *result =
nullptr;
701 FT_Load_Sfnt_Table(this->
face, tag, 0,
nullptr, &len);
704 result = MallocT<FT_Byte>(len);
705 FT_Load_Sfnt_Table(this->
face, tag, 0, result, &len);
712 #elif defined(_WIN32) 715 #ifndef ANTIALIASED_QUALITY 716 #define ANTIALIASED_QUALITY 4 723 HFONT font =
nullptr;
729 virtual const void *InternalGetFontTable(uint32 tag,
size_t &length);
730 virtual const Sprite *InternalGetGlyph(
GlyphID key,
bool aa);
733 Win32FontCache(
FontSize fs,
const LOGFONT &logfont,
int pixels);
737 virtual const char *
GetFontName() {
return WIDE_TO_MB(this->logfont.lfFaceName); }
739 virtual void *
GetOSHandle() {
return &this->logfont; }
751 this->dc = CreateCompatibleDC(
nullptr);
752 this->SetFontSize(
fs, pixels);
755 Win32FontCache::~Win32FontCache()
759 DeleteObject(this->font);
762 void Win32FontCache::SetFontSize(
FontSize fs,
int pixels)
767 pixels = scaled_height;
769 HFONT temp = CreateFontIndirect(&this->logfont);
770 if (temp !=
nullptr) {
771 HGDIOBJ old = SelectObject(this->dc, temp);
773 UINT size = GetOutlineTextMetrics(this->dc, 0,
nullptr);
774 LPOUTLINETEXTMETRIC otm = (LPOUTLINETEXTMETRIC)
AllocaM(BYTE, size);
775 GetOutlineTextMetrics(this->dc, size, otm);
782 SelectObject(dc, old);
791 this->logfont.lfHeight = -pixels;
792 this->logfont.lfWidth = 0;
793 this->logfont.lfOutPrecision = ANTIALIASED_QUALITY;
795 if (this->font !=
nullptr) {
796 SelectObject(dc, this->old_font);
797 DeleteObject(this->font);
799 this->font = CreateFontIndirect(&this->logfont);
800 this->old_font = SelectObject(this->dc, this->font);
803 UINT otmSize = GetOutlineTextMetrics(this->dc, 0,
nullptr);
804 POUTLINETEXTMETRIC otm = (POUTLINETEXTMETRIC)
AllocaM(BYTE, otmSize);
805 GetOutlineTextMetrics(this->dc, otmSize, otm);
808 this->
ascender = otm->otmTextMetrics.tmAscent;
809 this->
descender = otm->otmTextMetrics.tmDescent;
811 this->glyph_size.cx = otm->otmTextMetrics.tmMaxCharWidth;
812 this->glyph_size.cy = otm->otmTextMetrics.tmHeight;
814 DEBUG(freetype, 2,
"Loaded font '%s' with size %d",
FS2OTTD((LPTSTR)((BYTE *)otm + (ptrdiff_t)otm->otmpFullName)), pixels);
820 void Win32FontCache::ClearFontCache()
823 if (this->font !=
nullptr) this->SetFontSize(this->
fs, this->
req_size);
828 const Sprite *Win32FontCache::InternalGetGlyph(
GlyphID key,
bool aa)
831 MAT2 mat = { {0, 1}, {0, 0}, {0, 0}, {0, 1} };
834 DWORD size = this->glyph_size.cy *
Align(aa ? this->glyph_size.cx :
max(this->glyph_size.cx / 8l, 1l), 4);
835 byte *bmp =
AllocaM(byte, size);
836 size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
838 if (size == GDI_ERROR) {
844 size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, 0,
nullptr, &mat);
845 if (size == GDI_ERROR)
usererror(
"Unable to render font glyph");
847 GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
851 uint width =
max(1U, (uint)gm.gmBlackBoxX + (this->fs ==
FS_NORMAL));
855 if (width > 256 || height > 256)
usererror(
"Font glyph is too large");
861 sprite.
width = width;
863 sprite.
x_offs = gm.gmptGlyphOrigin.x;
872 uint pitch =
Align(aa ? gm.gmBlackBoxX :
max(gm.gmBlackBoxX / 8u, 1u), 4);
876 for (uint y = 0; y < gm.gmBlackBoxY; y++) {
877 for (uint x = 0; x < gm.gmBlackBoxX; x++) {
878 if (aa ? (bmp[x + y * pitch] > 0) :
HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
879 sprite.
data[1 + x + (1 + y) * sprite.
width].
m = SHADOW_COLOUR;
880 sprite.
data[1 + x + (1 + y) * sprite.
width].
a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
886 for (uint y = 0; y < gm.gmBlackBoxY; y++) {
887 for (uint x = 0; x < gm.gmBlackBoxX; x++) {
888 if (aa ? (bmp[x + y * pitch] > 0) :
HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
889 sprite.
data[x + y * sprite.
width].
m = FACE_COLOUR;
890 sprite.
data[x + y * sprite.
width].
a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
898 new_glyph.
width = gm.gmCellIncX;
900 this->SetGlyphPtr(key, &new_glyph);
902 return new_glyph.sprite;
907 assert(IsPrintable(key));
909 if (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END) {
915 if (key >= 0x010000U) {
916 chars[0] = (WCHAR)(((key - 0x010000U) >> 10) + 0xD800);
917 chars[1] = (WCHAR)(((key - 0x010000U) & 0x3FF) + 0xDC00);
919 chars[0] = (WCHAR)(key & 0xFFFF);
922 WORD glyphs[2] = {0, 0};
923 GetGlyphIndicesW(this->dc, chars, key >= 0x010000U ? 2 : 1, glyphs, GGI_MARK_NONEXISTING_GLYPHS);
925 return glyphs[0] != 0xFFFF ? glyphs[0] : 0;
928 const void *Win32FontCache::InternalGetFontTable(uint32 tag,
size_t &length)
930 DWORD len = GetFontData(this->dc, tag, 0,
nullptr, 0);
932 void *result =
nullptr;
933 if (len != GDI_ERROR && len > 0) {
934 result = MallocT<BYTE>(len);
935 GetFontData(this->dc, tag, 0, result, len);
950 static const char *SIZE_TO_NAME[] = {
"medium",
"small",
"large",
"mono" };
954 default: NOT_REACHED();
965 logfont.lfPitchAndFamily = fs ==
FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
966 logfont.lfCharSet = DEFAULT_CHARSET;
967 logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
968 logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
971 logfont = *(
const LOGFONT *)settings->
os_handle;
974 TCHAR fontPath[MAX_PATH];
977 if (AddFontResourceEx(fontPath, FR_PRIVATE, 0) != 0) {
980 typedef BOOL(WINAPI * PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
982 static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T(
"Gdi32")),
"GetFontResourceInfoW");
984 static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T(
"Gdi32")),
"GetFontResourceInfoA");
987 if (GetFontResourceInfo !=
nullptr) {
990 if (GetFontResourceInfo(fontPath, &len,
nullptr, 2) && len >=
sizeof(LOGFONT)) {
991 LOGFONT *buf = (LOGFONT *)
AllocaM(byte, len);
992 if (GetFontResourceInfo(fontPath, &len, buf, 2)) {
999 if (logfont.lfFaceName[0] == 0) {
1000 TCHAR fname[_MAX_FNAME];
1001 _tsplitpath(fontPath,
nullptr,
nullptr, fname,
nullptr);
1003 _tcsncpy_s(logfont.lfFaceName,
lengthof(logfont.lfFaceName), fname, _TRUNCATE);
1004 logfont.lfWeight = strcasestr(settings->
font,
" bold") !=
nullptr || strcasestr(settings->
font,
"-bold") !=
nullptr ? FW_BOLD : FW_NORMAL;
1007 ShowInfoF(
"Unable to load file '%s' for %s font, using default windows font selection instead", settings->
font, SIZE_TO_NAME[fs]);
1011 if (logfont.lfFaceName[0] == 0) {
1012 logfont.lfWeight = strcasestr(settings->
font,
" bold") !=
nullptr ? FW_BOLD : FW_NORMAL;
1016 HFONT font = CreateFontIndirect(&logfont);
1017 if (font ==
nullptr) {
1018 ShowInfoF(
"Unable to use '%s' for %s font, Win32 reported error 0x%lX, using sprite font instead", settings->
font, SIZE_TO_NAME[fs], GetLastError());
1023 new Win32FontCache(fs, logfont, settings->
size);
1037 if (monospace != (
fs ==
FS_MONO))
continue;
1042 #ifdef WITH_FREETYPE 1044 #elif defined(_WIN32) 1060 #ifdef WITH_FREETYPE 1061 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().