wxMaxima
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends
wxPdfFontManager Class Reference

Class representing the font manager. More...

#include <pdffontmanager.h>

Public Member Functions

void AddSearchPath (const wxString &path)
 Add a path entry to the font search path list.
 
void AddSearchPath (const wxArrayString &pathArray)
 Add a list of path entries to the font search path list.
 
bool SetDefaultEmbed (bool embed)
 Set the default embedding mode.
 
bool GetDefaultEmbed ()
 Get the default embedding mode.
 
bool SetDefaultSubset (bool subset)
 Set the default subsetting mode.
 
bool GetDefaultSubset ()
 Get the default subsetting mode.
 
wxPdfFont RegisterFont (const wxString &fontFileName, const wxString &aliasName=wxEmptyString, int fontIndex=0)
 Register a font.
 
wxPdfFont RegisterFont (const wxFont &font, const wxString &aliasName=wxEmptyString)
 Register a font based on a wxFont object.
 
wxPdfFont RegisterFont (const char *fontData, size_t fontDataSize, const wxString &aliasName=wxEmptyString)
 Register a font based on a font data buffer.
 
int RegisterFontCollection (const wxString &fontCollectionFileName)
 Register a font collection.
 
bool RegisterFontCJK (const wxString &family)
 Register a CJK font family.
 
int RegisterSystemFonts ()
 Register the fonts known to the operating system.
 
int RegisterFontDirectory (const wxString &directory, bool recursive=false)
 Register all fonts located in a directory.
 
wxPdfFont GetFont (const wxString &fontName, int fontStyle=wxPDF_FONTSTYLE_REGULAR) const
 Get a font by name and style.
 
wxPdfFont GetFont (const wxString &fontName, const wxString &fontStyle) const
 Get a font by name and style.
 
wxPdfFont GetFontForWxFont (const wxFont &font)
 Get the font corresponding to a wxFont object.
 
wxPdfFont GetFont (size_t fontIndex) const
 Get a font by index.
 
wxPdfFont FindFallbackFont (wxUint32 unicodeChar, int fontStyle=wxPDF_FONTSTYLE_REGULAR)
 Find an installed font containing a glyph for a character.
 
size_t GetFontCount () const
 Get the number of registered fonts.
 
bool InitializeFontData (const wxPdfFont &font)
 Initialize the font data of a font.
 
bool RegisterEncoding (const wxPdfEncoding &encoding)
 Register a font encoding.
 
const wxPdfEncoding * GetEncoding (const wxString &encodingName)
 Get the encoding having the given name.
 
void SetEmbeddableFontReplacement (const wxString &fontFamily, const wxString &replacementFamily)
 Set the embeddable replacement for a font family.
 
wxString GetEmbeddableFontReplacement (const wxString &fontFamily) const
 Get the embeddable replacement defined for a font family.
 
wxPdfFont GetEmbeddableFont (const wxPdfFont &font, int fontStyle=wxPDF_FONTSTYLE_REGULAR, bool useBuiltInReplacements=true)
 Get an embeddable version of a font.
 
wxPdfFont GetEmbeddableFont (const wxString &fontFamily, int fontStyle=wxPDF_FONTSTYLE_REGULAR)
 Get an embeddable font by family name and style.
 

Static Public Member Functions

static wxPdfFontManager * GetFontManager ()
 Get the font manager.
 

Friends

class wxPdfDocumentModule
 

Detailed Description

Class representing the font manager.

Member Function Documentation

◆ AddSearchPath() [1/2]

void wxPdfFontManager::AddSearchPath ( const wxArrayString &  pathArray)

Add a list of path entries to the font search path list.

Parameters
pathArraya list of path entries to add to the search list

◆ AddSearchPath() [2/2]

void wxPdfFontManager::AddSearchPath ( const wxString &  path)

Add a path entry to the font search path list.

Parameters
pathpath to add to the search list

◆ FindFallbackFont()

wxPdfFont wxPdfFontManager::FindFallbackFont ( wxUint32  unicodeChar,
int  fontStyle = wxPDF_FONTSTYLE_REGULAR 
)

Find an installed font containing a glyph for a character.

Searches the fonts installed on the system for a font that can show the given character, preferably in the given style. This is the lookup used by wxPdfDocument::SetSystemFontFallback(), but it can also be used directly, for example to build an explicit fallback list with wxPdfDocument::AddFallbackFont().

On wxGTK the fontconfig library is queried (the mechanism Pango uses for its own font fallback). On other platforms a built-in list of well-known font families with a large Unicode coverage is checked (e.g. Segoe UI and Cambria Math on Windows, Lucida Grande and STIX Two Math on macOS, DejaVu Sans and Noto Sans everywhere). A font found is registered with the font manager.

Results, including negative ones, are cached, so repeated lookups are cheap.

Parameters
unicodeCharthe Unicode code point of the character
fontStylethe preferred font style (only weight and italic are considered)
Returns
a font containing the character, or an invalid font if none was found
Note
Only available in Unicode builds. The result depends on the fonts installed on the system.

◆ GetDefaultEmbed()

bool wxPdfFontManager::GetDefaultEmbed ( )

Get the default embedding mode.

Returns
the current state of the default embedding mode

◆ GetDefaultSubset()

bool wxPdfFontManager::GetDefaultSubset ( )

Get the default subsetting mode.

Returns
the state of the default subsetting mode

◆ GetEmbeddableFont() [1/2]

wxPdfFont wxPdfFontManager::GetEmbeddableFont ( const wxPdfFont &  font,
int  fontStyle = wxPDF_FONTSTYLE_REGULAR,
bool  useBuiltInReplacements = true 
)

Get an embeddable version of a font.

If the given font can be embedded, a copy of it with embedding enabled is returned. Otherwise an embeddable replacement font with matching style is searched in the following order:

  • the family defined by SetEmbeddableFontReplacement() for the font's family or alias;
  • for the Adobe standard fonts Helvetica, Times and Courier a built-in list of free fonts with compatible metrics (Liberation, Croscore, URW base 35, TeX Gyre, GNU FreeFont) followed by the common system fonts Arial, Times New Roman and Courier New.

Each candidate family is first searched among the registered fonts. If it is not registered yet, wxPdfDocument tries to locate the font via the operating system (on wxMSW, wxGTK and wxOSX, see RegisterFont(const wxFont&)) and registers it. A system font is only accepted if its family name equals the candidate family, so that a platform specific fallback font is never used silently.

Note
Locating a system font creates a wxFont object, so like RegisterFont(const wxFont&) this should be called from the main thread if the font is not registered yet.
Parameters
fontthe font to be made embeddable
fontStylethe requested font style (in addition to the style of the font itself)
useBuiltInReplacementsflag whether the built-in replacement lists are used; if false, only the replacement defined by SetEmbeddableFontReplacement() is tried
Returns
the embeddable font, or an invalid font if neither the font itself nor any replacement can be embedded
See also
SetEmbeddableFontReplacement(), wxPdfDocument::SetEmbedAllFonts()

◆ GetEmbeddableFont() [2/2]

wxPdfFont wxPdfFontManager::GetEmbeddableFont ( const wxString &  fontFamily,
int  fontStyle = wxPDF_FONTSTYLE_REGULAR 
)

Get an embeddable font by family name and style.

Like GetEmbeddableFont(const wxPdfFont&, int), but starts from a family name. If no font of that family is registered, the replacements for the family name are tried, and finally wxPdfDocument tries to locate the family itself via the operating system.

Parameters
fontFamilythe name of the requested font family
fontStylethe requested font style
Returns
the embeddable font, or an invalid font if no embeddable font could be found

◆ GetEmbeddableFontReplacement()

wxString wxPdfFontManager::GetEmbeddableFontReplacement ( const wxString &  fontFamily) const

Get the embeddable replacement defined for a font family.

Parameters
fontFamilythe font family (or family alias)
Returns
the replacement family set by SetEmbeddableFontReplacement(), or an empty string if no replacement was defined for this family

◆ GetEncoding()

const wxPdfEncoding * wxPdfFontManager::GetEncoding ( const wxString &  encodingName)

Get the encoding having the given name.

Parameters
encodingNamename of the encoding
Returns
the encoding

◆ GetFont() [1/3]

wxPdfFont wxPdfFontManager::GetFont ( const wxString &  fontName,
const wxString &  fontStyle 
) const

Get a font by name and style.

Based on the given name and style the list of registered fonts is searched for a matching font. The name is checked whether it represents a font family. If the name is not a family name then the name is checked whether it represents an alias for a font family. If the name is not an alias either the name is checked whether it is a full font name.

Parameters
fontNamethe name of the requested font
fontStylethe style of the requested font (string representation)
Returns
the requested font
Note
If no appropriate font is registered an invalid font object is returned. It's the user's responsibility to check the font object before further using it.

◆ GetFont() [2/3]

wxPdfFont wxPdfFontManager::GetFont ( const wxString &  fontName,
int  fontStyle = wxPDF_FONTSTYLE_REGULAR 
) const

Get a font by name and style.

Based on the given name and style the list of registered fonts is searched for a matching font. The name is checked whether it represents a font family. If the name is not a family name then the name is checked whether it represents an alias for a font family. If the name is not an alias either the name is checked whether it is a full font name.

Parameters
fontNamethe name of the requested font
fontStylethe style of the requested font
Returns
the requested font
Note
If no appropriate font is registered an invalid font object is returned. It's the user's responsibility to check the font object before further using it.

◆ GetFont() [3/3]

wxPdfFont wxPdfFontManager::GetFont ( size_t  fontIndex) const

Get a font by index.

Parameters
fontIndexthe index of the requested font in the list of registered fonts
Returns
the requested font
Note
If the index is out of range an invalid font object is returned. It's the user's responsibility to check the font object before further using it.

◆ GetFontCount()

size_t wxPdfFontManager::GetFontCount ( ) const

Get the number of registered fonts.

Returns
the number of registered fonts

◆ GetFontForWxFont()

wxPdfFont wxPdfFontManager::GetFontForWxFont ( const wxFont &  font)

Get the font corresponding to a wxFont object.

This method is used by wxPdfDocument::SetFont(const wxFont&), wxPdfDC and wxPdfGraphicsContext to map a wxFont to a PDF font.

First a registered font matching the face name and style of the wxFont is searched. If none is registered, the font is located via the operating system and registered (see RegisterFont(const wxFont&)).

If the face name denotes one of the 14 Adobe standard fonts or one of their aliases (for example Arial, Helvetica, Times, Courier or Symbol), the font installed on the system is preferred: a wxFont stands for the font the operating system renders on screen, while the standard fonts support only the WinAnsi character set (Symbol and ZapfDingbats only their own one) and are never embedded. Only if no font can be located via the operating system the standard font is used. The result is cached, so that the operating system is asked only once per face name and style.

Parameters
fontthe wxFont object
Returns
the matching font, or an invalid font if no font could be found
Note
It's the user's responsibility to check the font object before further using it.
This is not an overload of GetFont(): on wxMSW a wxFont can be constructed implicitly from a wxString, which made a call like GetFont(family) ambiguous.

◆ GetFontManager()

wxPdfFontManager * wxPdfFontManager::GetFontManager ( )
static

Get the font manager.

Returns
a reference to the font manager

◆ InitializeFontData()

bool wxPdfFontManager::InitializeFontData ( const wxPdfFont &  font)

Initialize the font data of a font.

On registering a font the associated font data are not completely loaded into memory to save time and memory resources, but as soon as the font is actually used it must be fully initialized. Usually this method is called automatically.

Parameters
fontthe font to be initialized
Returns
true if the font could be initialized successfully, false otherwise

◆ RegisterEncoding()

bool wxPdfFontManager::RegisterEncoding ( const wxPdfEncoding &  encoding)

Register a font encoding.

Parameters
encodingthe encoding to be registered
Returns
true if the encoding could be registered successfully

◆ RegisterFont() [1/3]

wxPdfFont wxPdfFontManager::RegisterFont ( const char *  fontData,
size_t  fontDataSize,
const wxString &  aliasName = wxEmptyString 
)

Register a font based on a font data buffer.

Register a font based on a font data buffer for later use in creating a PDF document.

Note
The registered font will not take ownership of the font data buffer. That is, the buffer must be accessible during the life time of the font.
Parameters
fontDatathe font data buffer holding a TrueType or OpenType font
fontDataSizethe size of the font data buffer
aliasNamean alias name for the font family (default: no alias)
Returns
the registered font

◆ RegisterFont() [2/3]

wxPdfFont wxPdfFontManager::RegisterFont ( const wxFont &  font,
const wxString &  aliasName = wxEmptyString 
)

Register a font based on a wxFont object.

Register a font based on a wxFont object for later use in creating a PDF document.

Parameters
fontthe wxFont object to be registered
aliasNamean alias name for the font family (default: no alias)
Returns
the registered font

◆ RegisterFont() [3/3]

wxPdfFont wxPdfFontManager::RegisterFont ( const wxString &  fontFileName,
const wxString &  aliasName = wxEmptyString,
int  fontIndex = 0 
)

Register a font.

Register a font for later use in creating a PDF document.

Parameters
fontFileNamethe name of the font file (if the name is not fully qualified, it will be searched in font search path)
aliasNamean alias name for the font family (default: no alias)
fontIndexthe index of the font in a font collection (default: 0)
Returns
the registered font

◆ RegisterFontCJK()

bool wxPdfFontManager::RegisterFontCJK ( const wxString &  family)

Register a CJK font family.

Register all fonts from a font collection for later use in creating a PDF document. The following CJK font families are currently known to wxPdfDocument:

  • GB, GB-HW - Simplified Chinese (Adobe-Font STSongStd-Light-Acro)
  • BIG5, BIG5-HW - Traditional Chinese (Adobe-Font MSungStd-Light-Acro)
  • SJIS - Japanese (Adobe-Font KozMinPro-Regular-Acro)
  • UHC, UHC-HW - Korean (Adobe-Font HYSMyeongJoStd-Medium-Acro)
  • GOTHIC, PGOTHIC, UIGOTHIC - Japanese (Microsoft-Font MS-Gothic/MS-PGothic/MS-UIGothic)
  • MINCHO, PMINCHO - Japanese (Microsoft-Font MS-Mincho/MS-PMincho)
Parameters
familythe name of the CJK font family
Returns
true if the CJK family could be registered successfully, false otherwise

◆ RegisterFontCollection()

int wxPdfFontManager::RegisterFontCollection ( const wxString &  fontCollectionFileName)

Register a font collection.

Register all fonts from a font collection for later use in creating a PDF document.

Parameters
fontCollectionFileNamethe name of the font collection file (if the name is not fully qualified, it will be searched in font search path)
Returns
the number of registered fonts

◆ RegisterFontDirectory()

int wxPdfFontManager::RegisterFontDirectory ( const wxString &  directory,
bool  recursive = false 
)

Register all fonts located in a directory.

Parameters
directorythe directory path to be searched for font files
recursiveflag whether the search should include subdirectories or not (Default: false)
Returns
the number of registered fonts

◆ SetDefaultEmbed()

bool wxPdfFontManager::SetDefaultEmbed ( bool  embed)

Set the default embedding mode.

Usually it is recommended to enable embedding, since this guarantees that no font substitution takes place on a target system not providing a required font.

The default embedding mode is enabled by default, but the embedding mode can be set for each font individually.

Note
For most fonts the embedding mode is predefined. For example the Adobe Standard fonts and the Adobe CJK fonts are never embedded independently of the setting of the default embedding mode, and TrueType/OpenType Unicode fonts need to be always embedded.
Parameters
embedflag whether to enable or disable embedding
Returns
the state of the default embedding mode prior to this call

◆ SetDefaultSubset()

bool wxPdfFontManager::SetDefaultSubset ( bool  subset)

Set the default subsetting mode.

Usually it is recommended to enable subsetting, since embedding only a font subset reduces the size of the resulting PDF file significantly.

The default subsetting mode is enabled by default, but the subsetting mode can be set for each font individually.

Parameters
subsetflag whether to enable or disable font subsetting
Returns
the state of the default subsetting mode prior to this call

◆ SetEmbeddableFontReplacement()

void wxPdfFontManager::SetEmbeddableFontReplacement ( const wxString &  fontFamily,
const wxString &  replacementFamily 
)

Set the embeddable replacement for a font family.

Some fonts can never be embedded into a PDF document: the 14 Adobe standard fonts (Courier, Helvetica, Times, Symbol and ZapfDingbats), the Adobe CJK fonts, and fonts whose licence does not allow embedding. If a document requests that all fonts are embedded (see wxPdfDocument::SetEmbedAllFonts()), such a font is replaced by an embeddable font family. This method defines which family is used as replacement for a given font family.

Every PDF reader provides the standard fonts, so in embed-all-fonts mode they are only replaced if a replacement was defined with this method, or if the document conforms to PDF/A (which forbids non-embedded fonts).

The replacement family is tried first. If it is not available, the built-in list of metric-compatible free fonts is tried (see GetEmbeddableFont()).

The replacement family should either be registered already (for example with RegisterFont() or RegisterFontDirectory()) or be installed on the system, so that it can be located via the operating system's font services.

Note
The fonts Symbol and ZapfDingbats use a font specific encoding. Text written with them is reinterpreted using the encoding of the replacement font, so they should only be replaced by fonts with the same built-in encoding. Therefore no built-in replacements exist for these two fonts.
Parameters
fontFamilythe font family (or family alias) to be replaced, i.e. Helvetica
replacementFamilythe family of the embeddable replacement font, i.e. Liberation Sans. An empty string removes a previously defined replacement.
See also
GetEmbeddableFontReplacement(), GetEmbeddableFont(), wxPdfDocument::SetEmbedAllFonts()

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