OpenTTD Source: src/fontcache.cpp File Reference

OpenTTD Source 15.0-beta1

Functions | Variables
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 (bool monospace)
| (Re)initialize the font cache related things, i.e.
void | UninitFontCache ()
| Free everything allocated w.r.t.

## 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

  size | Font 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(), TextfileWindow::CheckHyperlinkClick(), CargoesField::Draw(), StationViewWindow::DrawAcceptedCargo(), TownAuthorityWindow::DrawActions(), DrawAircraftDetails(), DrawAircraftPurchaseInfo(), TimetableWindow::DrawArrivalDeparturePanel(), DrawButtonDropdown(), StationViewWindow::DrawCargoRatings(), DrawCategories(), DrawCategory(), DrawCharCentered(), NetworkClientListWindow::DrawCompany(), CompanyInfrastructureWindow::DrawCountLine(), 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(), TimetableWindow::DrawSummaryPanel(), TimetableWindow::DrawTimetablePanel(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), CheatWindow::DrawWidget(), SelectCompanyLiveryWindow::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(), GameSettingsWindow::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(), GetAutoPlacePosition(), TownViewWindow::GetDesiredInfoHeight(), GetEngineListHeight(), StoryBookWindow::GetHeadHeight(), SmallMapWindow::GetLegendHeight(), SmallMapWindow::GetPositionOnLegend(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), GetTotalCategoriesHeight(), GetVehicleListHeight(), LocalGetWindowPlacement(), ViewportSign::MarkDirty(), NetworkDrawChatMessage(), NetworkReInitChatBoxSize(), FramerateWindow::OnClick(), BaseGraphWindow::OnClick(), MusicTrackSelectionWindow::OnClick(), StationViewWindow::OnClick(), TownAuthorityWindow::OnClick(), IConsoleWindow::OnInit(), PaymentRatesGraphWindow::OnInit(), IndustryProductionGraphWindow::OnInit(), BuildIndustryWindow::OnInit(), IndustryViewWindow::OnInit(), IndustryCargoesWindow::OnInit(), SmallMapWindow::OnInit(), BuildAirportWindow::OnPaint(), ReplaceVehicleWindow::OnPaint(), BuildVehicleWindow::OnPaint(), HighScoreWindow::OnPaint(), GameSettingsWindow::OnPaint(), FramerateWindow::OnResize(), TextfileWindow::ReflowContent(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetBackground::SetupSmallestSize(), StationsWndShowStationRating(), NWidgetResizeBase::UpdateMultilineWidgetSize(), AIConfigWindow::UpdateWidgetSize(), BuildAirportWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), SelectCompanyLiveryWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), EnginePreviewWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), FramerateWindow::UpdateWidgetSize(), GSConfigWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), PaymentRatesGraphWindow::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(), GameSettingsWindow::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

  fs | Font 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

  fs | Font 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

  fs | Font 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

  fs | FontSize 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 | ( | bool | monospace | ) |

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

load the non-sprite fonts.

Parameters

  monospace | Whether to initialise the monospace or regular fonts.

Definition at line 218 of file fontcache.cpp.

References FS_BEGIN, FS_MONO, 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

  fs | The 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 241 of file fontcache.cpp.

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

Referenced by ShutdownGame().

## ◆ UninitFreeType()

void UninitFreeType | ( |  | ) |
| extern

Free everything allocated w.r.t.

freetype.

Definition at line 303 of file freetypefontcache.cpp.

Referenced by UninitFontCache().

## Variable Documentation

## ◆ _default_font_ascender

const int _default_font_ascender[FS_END] = { 8, 5, 15, 8}
| static

Definition at line 27 of file fontcache.cpp.

## ◆ _default_font_height

const int _default_font_height[FS_END] = {10, 6, 18, 10}
| static

Default heights for the different sizes of fonts.

Definition at line 26 of file fontcache.cpp.

## ◆ _fcsettings

FontCacheSettings _fcsettings

Definition at line 29 of file fontcache.cpp.