OpenTTD Source 20260421-master-gc2fbc6fdeb
fontcache.cpp File Reference

Cache for characters from fonts. More...

#include "stdafx.h"
#include "fontcache.h"
#include "blitter/factory.hpp"
#include "gfx_layout.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)
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.
static std::string GetFontCacheFontName (FontSize fs)
 Get font to use for a given font size.

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 88 of file fontcache.cpp.

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

Referenced by NWidgetResizeBase::AdjustPaddingForZoom(), CargoesField::CargoClickedAt(), CargoesField::CargoLabelClickedAt(), CheckClickOnViewportSign(), CargoesField::Draw(), ClientButtonLine::Draw(), CompanyButtonLine::Draw(), StationViewWindow::DrawAcceptedCargo(), TownAuthorityWindow::DrawActions(), DrawAircraftDetails(), DrawAircraftPurchaseInfo(), TimetableWindow::DrawArrivalDeparturePanel(), DrawButtonDropdown(), StationViewWindow::DrawCargoRatings(), DrawCategories(), DrawCategory(), DrawCharCentered(), 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(), BaseGraphWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), FramerateWindow::DrawWidget(), FrametimeGraphWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), GSConfigWindow::DrawWidget(), LandInfoWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), SavePresetWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), ScriptListWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), StatusBarWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownViewWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), DrawYearCategory(), DrawYearColumn(), StoryBookWindow::EnsureStoryPageElementLayout(), CompanyInfrastructureWindow::FindWindowPlacementAndResize(), GetAutoPlacePosition(), TownViewWindow::GetDesiredInfoHeight(), GetEngineListHeight(), DropdownWindow::GetFilterBoxHeight(), StoryBookWindow::GetHeadHeight(), TextfileWindow::GetHyperlink(), SmallMapWindow::GetLegendHeight(), SmallMapWindow::GetPositionOnLegend(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), GetTotalCategoriesHeight(), DepotWindow::GetVehicleFromDepotWndPt(), GetVehicleListHeight(), LocalGetWindowPlacement(), ViewportSign::MarkDirty(), NetworkDrawChatMessage(), NetworkReInitChatBoxSize(), BaseGraphWindow::OnClick(), FramerateWindow::OnClick(), MusicTrackSelectionWindow::OnClick(), StationViewWindow::OnClick(), TownAuthorityWindow::OnClick(), BaseCargoGraphWindow::OnInit(), BuildIndustryWindow::OnInit(), GameOptionsWindow::OnInit(), IConsoleWindow::OnInit(), IndustryCargoesWindow::OnInit(), IndustryViewWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), SmallMapWindow::OnInit(), StationViewWindow::OnInit(), BaseGraphWindow::OnMouseOver(), BuildAirportWindow::OnPaint(), BuildVehicleWindow::OnPaint(), GameOptionsWindow::OnPaint(), HighScoreWindow::OnPaint(), MainWindow::OnPaint(), ReplaceVehicleWindow::OnPaint(), FramerateWindow::OnResize(), StationsWndShowStationRating(), NWidgetResizeBase::UpdateMultilineWidgetSize(), AboutWindow::UpdateWidgetSize(), AIConfigWindow::UpdateWidgetSize(), BaseCargoGraphWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), EnginePreviewWindow::UpdateWidgetSize(), FramerateWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), GSConfigWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), NetworkContentListWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NewGRFInspectWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), PerformanceLeagueWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), PickerWindow::UpdateWidgetSize(), RefitWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), SavePresetWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), ScriptDebugWindow::UpdateWidgetSize(), ScriptLeagueWindow::UpdateWidgetSize(), ScriptListWindow::UpdateWidgetSize(), ScriptSettingsWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), StationViewWindow::UpdateWidgetSize(), StoryBookWindow::UpdateWidgetSize(), SubsidyListWindow::UpdateWidgetSize(), TextfileWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), VehicleDetailsWindow::UpdateWidgetSize(), VehicleViewWindow::UpdateWidgetSize(), and ViewportAddString().

◆ GetDefaultTruetypeFont()

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 181 of file fontcache.cpp.

References Large, Monospace, Normal, and Small.

Referenced by GetDefaultTruetypeFontFile().

◆ GetDefaultTruetypeFontFile()

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 198 of file fontcache.cpp.

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

Referenced by GetFontCacheFontName().

◆ GetFontAAState()

bool GetFontAAState ( )

Definition at line 108 of file fontcache.cpp.

◆ GetFontCacheFontName()

std::string GetFontCacheFontName ( FontSize fs)
static

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 213 of file fontcache.cpp.

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

Referenced by FontCache::LoadFontCaches().

◆ 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 169 of file fontcache.cpp.

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

Referenced by CoreTextFontCacheFactory::LoadFont(), FreeTypeFontCacheFactory::LoadFont(), and Win32FontCacheFactory::LoadFont().

◆ IsDefaultFont()

bool IsDefaultFont ( const FontCacheSubSetting & setting)
static

Test if a font setting uses the default font.

Parameters
settingThe setting to consider.
Returns
true iff the font is not configured and no fallback font data is present.

Definition at line 159 of file fontcache.cpp.

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

Referenced by GetFontCacheFontSize().

◆ SetFont()

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

Definition at line 116 of file fontcache.cpp.

Variable Documentation

◆ _fcsettings

FontCacheSettings _fcsettings

Definition at line 28 of file fontcache.cpp.