OpenCPN Partial API docs
Loading...
Searching...
No Matches
FontMgr Class Reference

Manages the font list. More...

#include <FontMgr.h>

Public Member Functions

void SetLocale (wxString &newLocale)
 
wxFont * GetFont (const wxString &TextElement, int requested_font_size=0)
 Gets a font object for a UI element.
 
wxColour GetFontColor (const wxString &TextElement) const
 Gets the text color for a UI element.
 
wxColour GetDefaultFontColor (const wxString &TextElement)
 Gets the default text color for a UI element.
 
bool SetFontColor (const wxString &TextElement, const wxColour color) const
 Sets the text color for a UI element.
 
int GetNumFonts (void) const
 Gets the total number of font configurations currently loaded.
 
const wxString & GetConfigString (int i) const
 Gets the locale-specific configuration key for a font at index i.
 
const wxString & GetDialogString (int i) const
 Gets the UI element identifier string for the font at index i.
 
wxArrayString GetDialogStrings (const wxString &locale=wxEmptyString) const
 Gets the list of unique dialog strings.
 
const wxString & GetNativeDesc (int i) const
 Gets the native font descriptor string for the font at index i.
 
wxString GetFullConfigDesc (int i) const
 Gets description of font at index i.
 
wxArrayString & GetAuxKeyArray ()
 Gets array of plugin-defined font configuration keys.
 
bool AddAuxKey (wxString key)
 Adds new plugin-defined font configuration key.
 
void LoadFontNative (wxString *pConfigString, wxString *pNativeDesc)
 Loads font settings from a string descriptor.
 
bool SetFont (const wxString &TextElement, wxFont *pFont, wxColour color)
 Sets the default font properties for a UI element.
 
void ScrubList ()
 Cleans up stale font entries after a locale change.
 
MyFontDescFindFontByConfigString (wxString pConfigString)
 Finds font descriptor by its configuration key.
 
wxFont * FindOrCreateFont (int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &facename=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
 Creates or finds a matching font in the font cache.
 
wxFont * FindOrCreateFont (int pointSize, int family, int style, int weight, bool underline=false, const wxString &face=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
 
bool ResetFontToDefault (const wxString &TextElement)
 Resets the font configuration for a UI element back to system defaults.
 

Static Public Member Functions

static FontMgrGet ()
 
static wxString GetFontConfigKey (const wxString &description)
 Creates configuration key from UI element name by combining locale with hash.
 
static void Shutdown ()
 

Detailed Description

Manages the font list.

Singleton.

Definition at line 37 of file FontMgr.h.

Member Function Documentation

◆ AddAuxKey()

bool FontMgr::AddAuxKey ( wxString  key)

Adds new plugin-defined font configuration key.

Allows plugins to register their UI elements for font configuration. Each element must have a unique identifier.

Parameters
keyNew plugin UI element identifier to add
Returns
True if key was added, false if already exists

Definition at line 668 of file FontMgr.cpp.

◆ FindFontByConfigString()

MyFontDesc * FontMgr::FindFontByConfigString ( wxString  pConfigString)

Finds font descriptor by its configuration key.

Parameters
pConfigStringKey in "locale-hash" format
Returns
Matching font descriptor or NULL if not found

Definition at line 376 of file FontMgr.cpp.

◆ FindOrCreateFont() [1/2]

wxFont * FontMgr::FindOrCreateFont ( int  point_size,
wxFontFamily  family,
wxFontStyle  style,
wxFontWeight  weight,
bool  underline = false,
const wxString &  facename = wxEmptyString,
wxFontEncoding  encoding = wxFONTENCODING_DEFAULT 
)

Creates or finds a matching font in the font cache.

If a font with the specified characteristics exists in the cache, returns that font. Otherwise, creates a new font, adds it to the cache and returns it.

Parameters
point_sizeFont size in points.
familyFont family like wxFONTFAMILY_SWISS.
styleFont style like wxFONTSTYLE_NORMAL.
weightFont weight like wxFONTWEIGHT_NORMAL.
underlineTrue to underline the font.
facenameName of the font face, empty for default.
encodingFont encoding, wxFONTENCODING_DEFAULT for default.
Returns
Pointer to the cached wxFont object.

Definition at line 450 of file FontMgr.cpp.

◆ FindOrCreateFont() [2/2]

wxFont * FontMgr::FindOrCreateFont ( int  pointSize,
int  family,
int  style,
int  weight,
bool  underline = false,
const wxString &  face = wxEmptyString,
wxFontEncoding  encoding = wxFONTENCODING_DEFAULT 
)
inline

Definition at line 258 of file FontMgr.h.

◆ Get()

FontMgr & FontMgr::Get ( )
static

Definition at line 83 of file FontMgr.cpp.

◆ GetAuxKeyArray()

wxArrayString & FontMgr::GetAuxKeyArray ( )
inline

Gets array of plugin-defined font configuration keys.

Plugins can add their own UI elements requiring font configuration beyond the standard elements defined in FontCandidates[] (like "AISTargetAlert", "StatusBar"). These plugin-specific keys allow plugins to participate in OpenCPN's font management system.

Returns
Reference to array containing plugin-defined font element identifiers

Definition at line 177 of file FontMgr.h.

◆ GetConfigString()

const wxString & FontMgr::GetConfigString ( int  i) const

Gets the locale-specific configuration key for a font at index i.

Used to store and retrieve font configurations by combining the current locale with a hash of the font's text element name (e.g. "AISTargetAlert", "StatusBar").

For example, given a text element "Dialog" in French locale "fr_FR", the returned key might be "fr_FR-a7b9c123" where a7b9c123 is the hash of "Dialog".

Parameters
iFont index between 0 and GetNumFonts()-1
Returns
Configuration string in format "locale-hash" used for storage
See also
GetFontConfigKey() for the hash generation
s_locale for current locale tracking

Definition at line 327 of file FontMgr.cpp.

◆ GetDefaultFontColor()

wxColour FontMgr::GetDefaultFontColor ( const wxString &  TextElement)

Gets the default text color for a UI element.

Returns predefined defaults for certain elements like Console Legend (green), Marks (black). Falls back to system window text color if no special default. On macOS, always returns black to support light/dark mode.

Parameters
TextElementUI element identifier
Returns
Default text color for this element
See also
[GetFont]

Definition at line 265 of file FontMgr.cpp.

◆ GetDialogString()

const wxString & FontMgr::GetDialogString ( int  i) const

Gets the UI element identifier string for the font at index i.

Returns the human-readable identifier like "AISTargetAlert" or "StatusBar" used to reference this font in the UI.

Parameters
iFont index between 0 and GetNumFonts()-1
Returns
UI element name for this font configuration

Definition at line 332 of file FontMgr.cpp.

◆ GetDialogStrings()

wxArrayString FontMgr::GetDialogStrings ( const wxString &  locale = wxEmptyString) const

Gets the list of unique dialog strings.

Parameters
localeIf provided, only returns strings for this locale.
Returns
Vector of unique dialog strings

Definition at line 337 of file FontMgr.cpp.

◆ GetFont()

wxFont * FontMgr::GetFont ( const wxString &  TextElement,
int  requested_font_size = 0 
)

Gets a font object for a UI element.

Each UI element (like "AISTargetAlert", "StatusBar") has a font configuration. Returns existing font if found, otherwise creates a new one using system defaults or user preferences.

Supported TextElements: AISTargetAlert, AISTargetQuery, StatusBar, AIS Target Name, ObjectQuery, RouteLegInfoRollover, ExtendedTideIcon, CurrentValue, Console Legend, Console Value, AISRollover, TideCurrentGraphRollover, Marks, ChartTexts, ToolTips, Dialog, Menu, GridText

Parameters
TextElementUI element identifier (e.g., "AISTargetAlert", "StatusBar")
requested_font_sizeRequested font size in points, 0 to use system/user default
Returns
Pointer to the font to use

Definition at line 186 of file FontMgr.cpp.

◆ GetFontColor()

wxColour FontMgr::GetFontColor ( const wxString &  TextElement) const

Gets the text color for a UI element.

Looks up stored color for the element. Returns black if not found.

Parameters
TextElementUI element identifier
Returns
Text color to use, defaults to black if not found
See also
[GetFont]

Definition at line 117 of file FontMgr.cpp.

◆ GetFontConfigKey()

wxString FontMgr::GetFontConfigKey ( const wxString &  description)
static

Creates configuration key from UI element name by combining locale with hash.

Parameters
descriptionUI element name to hash (e.g. "AISTargetAlert")
Returns
String in format "locale-hash" for storage.

Definition at line 132 of file FontMgr.cpp.

◆ GetFullConfigDesc()

wxString FontMgr::GetFullConfigDesc ( int  i) const

Gets description of font at index i.

Parameters
iFont index between 0 and GetNumFonts()-1
Returns
String in format "elementname:nativedesc:color"

Definition at line 362 of file FontMgr.cpp.

◆ GetNativeDesc()

const wxString & FontMgr::GetNativeDesc ( int  i) const

Gets the native font descriptor string for the font at index i.

Returns platform-specific complete font specification string that can be used to recreate the exact font. Contains size, family, style, weight and other attributes. Format varies by platform.

Parameters
iFont index between 0 and GetNumFonts()-1
Returns
Native font description string

Definition at line 357 of file FontMgr.cpp.

◆ GetNumFonts()

int FontMgr::GetNumFonts ( void  ) const

Gets the total number of font configurations currently loaded.

Each configuration defines the font and color for a specific UI element like "AISTargetAlert" in a specific locale.

Returns
Number of font configurations
See also
[m_fontlist]

Definition at line 325 of file FontMgr.cpp.

◆ LoadFontNative()

void FontMgr::LoadFontNative ( wxString *  pConfigString,
wxString *  pNativeDesc 
)

Loads font settings from a string descriptor.

Parameters
[in]pConfigStringLookup key in "locale-hash" format to find font config
[in]pNativeDescFont settings to load, format: "TextElement:NativeFontString:rgb(r,g,b)" where:
  • TextElement: UI element identifier (e.g. "AISTargetAlert")
  • NativeFontString: Platform-specific font description
  • rgb(r,g,b): Text color in CSS RGB

Updates the font configuration in m_fontlist matching pConfigString with the settings from pNativeDesc. Creates new entry if not found.

Definition at line 392 of file FontMgr.cpp.

◆ ResetFontToDefault()

bool FontMgr::ResetFontToDefault ( const wxString &  TextElement)

Resets the font configuration for a UI element back to system defaults.

This function:

  1. Creates a font with system default properties.
  2. Updates the font descriptor in the font list to use this default font.
  3. Resets the text color to the default for this element.
Parameters
TextElementThe UI element identifier (e.g. "AISTargetAlert").
Returns
true if the font was reset successfully, false if element not found.

Definition at line 676 of file FontMgr.cpp.

◆ ScrubList()

void FontMgr::ScrubList ( )

Cleans up stale font entries after a locale change.

The function preserves customized font settings while removing outdated entries that might reference old translations.

Definition at line 565 of file FontMgr.cpp.

◆ SetFont()

bool FontMgr::SetFont ( const wxString &  TextElement,
wxFont *  pFont,
wxColour  color 
)

Sets the default font properties for a UI element.

Updates the font and color of the default font entry for the given TextElement. Creates a copy of the provided font to avoid memory management issues. Only affects the default font entry - specific size variants are unchanged.

Parameters
TextElementUI element identifier (e.g., "AISTargetAlert")
pFontNew font to use
colorNew text color
Returns
true if default font entry was found and updated, false if not found

Definition at line 305 of file FontMgr.cpp.

◆ SetFontColor()

bool FontMgr::SetFontColor ( const wxString &  TextElement,
const wxColour  color 
) const

Sets the text color for a UI element.

Updates stored color for the element in the current locale.

Parameters
TextElementUI element identifier
colorNew text color to set
Returns
True if element was found and color was set, false if not found
See also
[GetFont]

Definition at line 122 of file FontMgr.cpp.

◆ SetLocale()

void FontMgr::SetLocale ( wxString &  newLocale)

Definition at line 115 of file FontMgr.cpp.

◆ Shutdown()

void FontMgr::Shutdown ( )
static

Definition at line 88 of file FontMgr.cpp.


The documentation for this class was generated from the following files: