OpenTTD Source 20250722-master-g6d95cea73a
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.
 
bool GetFontAAState ()
 
void SetFont (FontSize fontsize, const std::string &font, uint size)
 
void LoadFreeTypeFont (FontSize fs)
 Loads the freetype font.
 
void UninitFreeType ()
 Free everything allocated w.r.t.
 
static bool IsDefaultFont (const FontCacheSubSetting &setting)
 Test if a font setting uses the default font.
 
uint GetFontCacheFontSize (FontSize fs)
 Get the scalable font size to use for a FontSize.
 
static std::string GetDefaultTruetypeFont (FontSize fs)
 Get name of default font file for a given font size.
 
static std::string GetDefaultTruetypeFontFile (FontSize fs)
 Get path of default font file for a given font size.
 
std::string GetFontCacheFontName (FontSize fs)
 Get font to use for a given font size.
 
void InitFontCache (FontSizes fontsizes)
 (Re)initialize the font cache related things, i.e.
 
void UninitFontCache ()
 Free everything allocated w.r.t.
 

Variables

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 CargoesField::CargoClickedAt(), CargoesField::CargoLabelClickedAt(), CheckClickOnViewportSign(), CargoesField::Draw(), StationViewWindow::DrawAcceptedCargo(), TownAuthorityWindow::DrawActions(), DrawAircraftDetails(), DrawAircraftPurchaseInfo(), TimetableWindow::DrawArrivalDeparturePanel(), DrawButtonDropdown(), StationViewWindow::DrawCargoRatings(), DrawCategories(), DrawCategory(), DrawCharCentered(), NetworkClientListWindow::DrawCompany(), NetworkContentListWindow::DrawDetails(), FramerateWindow::DrawElementTimesColumn(), DrawEngineList(), StationViewWindow::DrawEntries(), DrawFrame(), BaseGraphWindow::DrawGraph(), SmallMapWindow::DrawIndustryNames(), IndustryViewWindow::DrawInfo(), GoalListWindow::DrawListColumn(), NetworkContentListWindow::DrawMatrix(), DrawOrderString(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), NetworkGameWindow::DrawServerLine(), SettingEntry::DrawSetting(), SettingsPage::DrawSetting(), DrawShipDetails(), DrawSliderWidget(), DrawSmallOrderList(), DrawString(), DrawStringMultiLineWithClipping(), TimetableWindow::DrawSummaryPanel(), TimetableWindow::DrawTimetablePanel(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), FramerateWindow::DrawWidget(), FrametimeGraphWindow::DrawWidget(), GSConfigWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), BaseGraphWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), LandInfoWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SavePresetWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), ScriptListWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), StatusBarWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), TownViewWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), DrawYearCategory(), DrawYearColumn(), StoryBookWindow::EnsureStoryPageElementLayout(), CompanyInfrastructureWindow::FindWindowPlacementAndResize(), GetAutoPlacePosition(), TownViewWindow::GetDesiredInfoHeight(), GetEngineListHeight(), StoryBookWindow::GetHeadHeight(), TextfileWindow::GetHyperlink(), SmallMapWindow::GetLegendHeight(), SmallMapWindow::GetPositionOnLegend(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), GetTotalCategoriesHeight(), GetVehicleListHeight(), LocalGetWindowPlacement(), ViewportSign::MarkDirty(), NetworkDrawChatMessage(), NetworkReInitChatBoxSize(), FramerateWindow::OnClick(), BaseGraphWindow::OnClick(), MusicTrackSelectionWindow::OnClick(), StationViewWindow::OnClick(), TownAuthorityWindow::OnClick(), SelectCompanyManagerFaceWindow::OnInit(), IConsoleWindow::OnInit(), BaseCargoGraphWindow::OnInit(), BuildIndustryWindow::OnInit(), IndustryViewWindow::OnInit(), IndustryCargoesWindow::OnInit(), SmallMapWindow::OnInit(), BaseGraphWindow::OnMouseOver(), BuildAirportWindow::OnPaint(), ReplaceVehicleWindow::OnPaint(), BuildVehicleWindow::OnPaint(), HighScoreWindow::OnPaint(), MainWindow::OnPaint(), GameOptionsWindow::OnPaint(), FramerateWindow::OnResize(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), StationsWndShowStationRating(), NWidgetResizeBase::UpdateMultilineWidgetSize(), AIConfigWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), EnginePreviewWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), FramerateWindow::UpdateWidgetSize(), GSConfigWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), BaseCargoGraphWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), PerformanceLeagueWindow::UpdateWidgetSize(), ScriptLeagueWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), AboutWindow::UpdateWidgetSize(), NetworkContentListWindow::UpdateWidgetSize(), BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), NewGRFInspectWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), SavePresetWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), PickerWindow::UpdateWidgetSize(), ScriptListWindow::UpdateWidgetSize(), ScriptSettingsWindow::UpdateWidgetSize(), ScriptDebugWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), SubsidyListWindow::UpdateWidgetSize(), TextfileWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), RefitWindow::UpdateWidgetSize(), VehicleDetailsWindow::UpdateWidgetSize(), VehicleViewWindow::UpdateWidgetSize(), 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 ( 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().

Referenced by GetFontCacheFontName().

◆ GetFontAAState()

bool GetFontAAState ( )

Definition at line 93 of file fontcache.cpp.

◆ 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 GetDefaultTruetypeFontFile(), GetFontCacheSubSetting(), FontCacheSettings::prefer_sprite, 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.

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

◆ InitFontCache()

void InitFontCache ( FontSizes  fontsizes)

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

load the non-sprite fonts.

Parameters
fontsizesFont sizes to be initialised.

Definition at line 218 of file fontcache.cpp.

References FontCache::Get(), FontCache::HasParent(), LoadCoreTextFont(), LoadFreeTypeFont(), and LoadWin32Font().

Referenced by CheckForMissingGlyphs(), MissingGlyphSearcher::FindMissingGlyphs(), GameOptionsWindow::OnClick(), openttd_main(), 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)
extern

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 BASE_DIR, Debug, FioFindFullPath(), GetFontByFaceName(), GetFontCacheFontName(), GetFontCacheFontSize(), GetFontCacheSubSetting(), and settings.

Referenced by InitFontCache().

◆ SetFont()

void SetFont ( FontSize  fontsize,
const std::string &  font,
uint  size 
)

Definition at line 101 of file fontcache.cpp.

◆ UninitFontCache()

void UninitFontCache ( )

Free everything allocated w.r.t.

fonts.

Definition at line 239 of file fontcache.cpp.

References FS_BEGIN, FontCache::Get(), and UninitFreeType().

Referenced by ShutdownGame().

◆ UninitFreeType()

void UninitFreeType ( )
extern

Free everything allocated w.r.t.

freetype.

Definition at line 302 of file freetypefontcache.cpp.

Referenced by UninitFontCache().

Variable Documentation

◆ _fcsettings

FontCacheSettings _fcsettings

Definition at line 30 of file fontcache.cpp.