OpenTTD Source  20241121-master-g67a0fccfad
fontcache.cpp File Reference

Cache for characters from fonts. More...

#include "stdafx.h"
#include "fontcache.h"
#include "fontdetection.h"
#include "blitter/factory.hpp"
#include "gfx_layout.h"
#include "fontcache/spritefontcache.h"
#include "openttd.h"
#include "settings_func.h"
#include "strings_func.h"
#include "viewport_func.h"
#include "window_func.h"
#include "fileio_func.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

int GetCharacterHeight (FontSize size)
 Get height of a character for a given font size. More...
 
bool GetFontAAState ()
 
void SetFont (FontSize fontsize, const std::string &font, uint size)
 
void LoadFreeTypeFont (FontSize fs)
 Loads the freetype font. More...
 
void UninitFreeType ()
 Free everything allocated w.r.t. More...
 
static bool IsDefaultFont (const FontCacheSubSetting &setting)
 Test if a font setting uses the default font. More...
 
uint GetFontCacheFontSize (FontSize fs)
 Get the scalable font size to use for a FontSize. More...
 
static std::string GetDefaultTruetypeFont (FontSize fs)
 Get name of default font file for a given font size. More...
 
static std::string GetDefaultTruetypeFontFile ([[maybe_unused]] FontSize fs)
 Get path of default font file for a given font size. More...
 
std::string GetFontCacheFontName (FontSize fs)
 Get font to use for a given font size. More...
 
void InitFontCache (bool monospace)
 (Re)initialize the font cache related things, i.e. More...
 
void UninitFontCache ()
 Free everything allocated w.r.t. More...
 

Variables

static const int _default_font_height [FS_END] = {10, 6, 18, 10}
 Default heights for the different sizes of fonts.
 
static const int _default_font_ascender [FS_END] = { 8, 5, 15, 8}
 
FontCacheSettings _fcsettings
 

Detailed Description

Cache for characters from fonts.

Definition in file fontcache.cpp.

Function Documentation

◆ GetCharacterHeight()

int GetCharacterHeight ( FontSize  size)

Get height of a character for a given font size.

Parameters
sizeFont size to get height of
Returns
Height of characters in the given font (pixels)

Definition at line 77 of file fontcache.cpp.

References FontCache::Get(), and FontCache::GetHeight().

Referenced by TextfileWindow::CheckHyperlinkClick(), CargoesField::Draw(), StationViewWindow::DrawAcceptedCargo(), TownAuthorityWindow::DrawActions(), StationViewWindow::DrawCargoRatings(), DrawCategory(), NetworkClientListWindow::DrawCompany(), NetworkContentListWindow::DrawDetails(), IndustryViewWindow::DrawInfo(), NetworkContentListWindow::DrawMatrix(), TownAuthorityWindow::DrawRatings(), DrawSliderWidget(), DrawString(), TimetableWindow::DrawSummaryPanel(), StoryBookWindow::EnsureStoryPageElementLayout(), TownViewWindow::GetDesiredInfoHeight(), GetEngineListHeight(), StoryBookWindow::GetHeadHeight(), SmallMapWindow::GetLegendHeight(), SmallMapWindow::GetPositionOnLegend(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), GetTotalCategoriesHeight(), GetVehicleListHeight(), LocalGetWindowPlacement(), ViewportSign::MarkDirty(), NetworkReInitChatBoxSize(), IConsoleWindow::OnInit(), PaymentRatesGraphWindow::OnInit(), IndustryProductionGraphWindow::OnInit(), BuildIndustryWindow::OnInit(), IndustryViewWindow::OnInit(), IndustryCargoesWindow::OnInit(), ReplaceVehicleWindow::OnPaint(), BuildVehicleWindow::OnPaint(), TextfileWindow::ReflowContent(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetBackground::SetupSmallestSize(), and ViewportAddString().

◆ GetDefaultTruetypeFont()

static std::string GetDefaultTruetypeFont ( FontSize  fs)
static

Get name of default font file for a given font size.

Parameters
fsFont size.
Returns
Name of default font file.

Definition at line 174 of file fontcache.cpp.

References FS_LARGE, FS_MONO, FS_NORMAL, and FS_SMALL.

Referenced by GetDefaultTruetypeFontFile().

◆ GetDefaultTruetypeFontFile()

static std::string GetDefaultTruetypeFontFile ( [[maybe_unused] ] FontSize  fs)
static

Get path of default font file for a given font size.

Parameters
fsFont size.
Returns
Full path of default font file.

Definition at line 191 of file fontcache.cpp.

References BASESET_DIR, FioFindFullPath(), and GetDefaultTruetypeFont().

◆ GetFontCacheFontName()

std::string GetFontCacheFontName ( FontSize  fs)

Get font to use for a given font size.

Parameters
fsFont size.
Returns
If configured, the font name to use, or the path of the default TrueType font if sprites are not preferred.

Definition at line 206 of file fontcache.cpp.

References GetFontCacheSubSetting(), and settings.

Referenced by LoadCoreTextFont(), LoadFreeTypeFont(), and LoadWin32Font().

◆ GetFontCacheFontSize()

uint GetFontCacheFontSize ( FontSize  fs)

Get the scalable font size to use for a FontSize.

Parameters
fsFontSize to get the scalable font size for.
Returns
Scalable font size to use.

Definition at line 162 of file fontcache.cpp.

References GetFontCacheSubSetting(), IsDefaultFont(), and FontCacheSubSetting::size.

◆ InitFontCache()

void InitFontCache ( bool  monospace)

(Re)initialize the font cache related things, i.e.

load the non-sprite fonts.

Parameters
monospaceWhether to initialise the monospace or regular fonts.

Definition at line 218 of file fontcache.cpp.

References FS_BEGIN.

Referenced by MissingGlyphSearcher::FindMissingGlyphs(), and SetFallbackFont().

◆ IsDefaultFont()

static bool IsDefaultFont ( const FontCacheSubSetting setting)
static

Test if a font setting uses the default font.

Returns
true iff the font is not configured and no fallback font data is present.

Definition at line 152 of file fontcache.cpp.

References FontCacheSubSetting::font, and FontCacheSubSetting::os_handle.

Referenced by GetFontCacheFontSize().

◆ LoadFreeTypeFont()

void LoadFreeTypeFont ( FontSize  fs)

Loads the freetype font.

First type to load the fontname as if it were a path. If that fails, try to resolve the filename of the font using fontconfig, where the format is 'font family name' or 'font family name, font style'.

Parameters
fsThe font size to load.

Definition at line 159 of file freetypefontcache.cpp.

References GetFontCacheFontName(), GetFontCacheSubSetting(), and settings.

◆ UninitFontCache()

void UninitFontCache ( )

Free everything allocated w.r.t.

fonts.

Definition at line 241 of file fontcache.cpp.

References FS_BEGIN.

◆ UninitFreeType()

void UninitFreeType ( )

Free everything allocated w.r.t.

freetype.

Definition at line 303 of file freetypefontcache.cpp.