OpenTTD Source: src/os/unix/font_unix.cpp File Reference

OpenTTD Source 15.3

Functions | Variables
font_unix.cpp File Reference

Functions related to font handling on Unix/Fontconfig. More...

`#include "../../stdafx.h"`
`#include "../../misc/autorelease.hpp"`
`#include "../../debug.h"`
`#include "../../fontcache.h"`
`#include "../../string_func.h"`
`#include "../../strings_func.h"`
`#include "font_unix.h"`
`#include <fontconfig/fontconfig.h>`
`#include <ft2build.h>`
`#include <FT_FREETYPE_H>`
`#include "../../safeguards.h"`

Go to the source code of this file.

## Functions
static const FcChar8 * | ToFcString (const std::string &str)
| Get a FontConfig-style string from a std::string.
static const char * | FromFcString (const FcChar8 *str)
| Get a C-style string from a FontConfig-style string.
static std::tuple< std::string, std::string > | SplitFontFamilyAndStyle (std::string_view font_name)
| Split the font name into the font family and style.
FT_Error | GetFontByFaceName (std::string_view font_name, FT_Face *face)
| Load a freetype font face with the given font name.
static int | GetPreferredWeightDistance (int weight)
| Get distance between font weight and preferred font weights.
bool | FontConfigFindFallbackFont (FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)

## Variables
FT_Library | _ft_library

## Detailed Description

Functions related to font handling on Unix/Fontconfig.

Definition in file font_unix.cpp.

## Function Documentation

## ◆ FontConfigFindFallbackFont()

bool FontConfigFindFallbackFont | ( | FontCacheSettings * | settings,
|  | const std::string & | language_isocode,
|  | MissingGlyphSearcher * | callback
| ) |  |

Definition at line 142 of file font_unix.cpp.

## ◆ FromFcString()

static const char * FromFcString | ( | const FcChar8 * | str | ) |
| static

Get a C-style string from a FontConfig-style string.

Parameters

  str | String from FontConfig.

Returns
  C-style string.

Definition at line 42 of file font_unix.cpp.

Referenced by GetFontByFaceName().

## ◆ GetFontByFaceName()

FT_Error GetFontByFaceName | ( | std::string_view | font_name,
|  | FT_Face * | face
| ) |  |

Load a freetype font face with the given font name.

Parameters

  font_name | The name of the font to load.
  face | The face that has been found.

Returns
  The error we encountered.

Definition at line 70 of file font_unix.cpp.

References FromFcString(), SplitFontFamilyAndStyle(), StrEqualsIgnoreCase(), and ToFcString().

Referenced by FreeTypeFontCacheFactory::LoadFont().

## ◆ GetPreferredWeightDistance()

static int GetPreferredWeightDistance | ( | int | weight | ) |
| static

Get distance between font weight and preferred font weights.

Parameters

  weight | Font weight from FontConfig.

Returns
  Distance from preferred weight, where lower values are preferred.

Definition at line 131 of file font_unix.cpp.

## ◆ SplitFontFamilyAndStyle()

static std::tuple< std::string, std::string > SplitFontFamilyAndStyle | ( | std::string_view | font_name | ) |
| static

Split the font name into the font family and style.

These fields are separated by a comma, but the style does not necessarily need to exist.

Parameters

  font_name | The font name.

Returns
  The font family and style.

Definition at line 53 of file font_unix.cpp.

Referenced by GetFontByFaceName().

## ◆ ToFcString()

static const FcChar8 * ToFcString | ( | const std::string & | str | ) |
| static

Get a FontConfig-style string from a std::string.

Parameters

  str | String to be passed to FontConfig.

Returns
  FontConfig-style string.

Definition at line 32 of file font_unix.cpp.

Referenced by GetFontByFaceName().

## Variable Documentation

## ◆ _ft_library

FT_Library _ft_library
| extern

Definition at line 210 of file freetypefontcache.cpp.