docs
Loading...
Searching...
No Matches
FontLoaderabstract

#include <Ultralight/platform/FontLoader.h>

Overview

User-defined font loader interface.

The library uses this to load a font file (eg, Arial.ttf) for a given font description (eg, font-family: Arial;).

Every OS has its own library of installed system fonts. The FontLoader interface is used to lookup these fonts and fetch the actual font data (raw TTF/OTF file data) for a given font description.

You can provide the library with your own font loader implementation so that you can bundle fonts with your application rather than relying on the system's installed fonts.

Default Implementation

A platform-specific implementation of FontLoader is provided for you when you call App::Create().

If you are using Renderer::Create(), you must provide your own. You can still use the default implementation however– see the helper functions defined in <AppCore/Platform.h>.

Threading

The library calls these methods from the thread you created the Renderer on and from the threads that run Web Workers. Those calls can overlap, so your implementation must be safe to call from more than one thread at once.

Setting the Font Loader

To provide your own custom FontLoader implementation, you should inherit from this class, handle the virtual member functions, and then pass an instance of your class to Platform::set_font_loader() before calling Renderer::Create() or App::Create().

Public Member Functions

virtual ~FontLoader ()
virtual String fallback_font () const =0
 Fallback font family name.
virtual String fallback_font_for_characters (const String &characters, int weight, bool italic) const =0
 Fallback font family name that can render the specified characters.
virtual RefPtr< FontFile > Load (const String &family, int weight, bool italic)=0
 Get the actual font file data (TTF/OTF) for a given font description.

Constructor & Destructor Documentation

◆ ~FontLoader()

virtual ~FontLoader ( )
virtual

Member Function Documentation

◆ fallback_font()

virtual String fallback_font ( ) const
pure virtual

Fallback font family name.

Will be used if all other fonts fail to load.

Note
This font should be guaranteed to exist (eg, FontLoader::Load won't fail when passed this font family name).

◆ fallback_font_for_characters()

virtual String fallback_font_for_characters ( const String & characters,
int weight,
bool italic ) const
pure virtual

Fallback font family name that can render the specified characters.

Mainly used to support CJK (Chinese, Japanese, Korean) text display.

Parameters
charactersOne or more UTF-16 characters. This is almost always a single character.
weightThe CSS numeric font weight, from 100 (thin) to 900 (black), rounded to the nearest multiple of 100. Normal is 400, bold is 700.
italicWhether or not italic is requested.
Returns
Returns a font family name that can render the text.

◆ Load()

virtual RefPtr< FontFile > Load ( const String & family,
int weight,
bool italic )
pure virtual

Get the actual font file data (TTF/OTF) for a given font description.

Parameters
familyFont family name.
weightThe CSS numeric font weight, from 100 (thin) to 900 (black), rounded to the nearest multiple of 100. Normal is 400, bold is 700.
italicWhether or not italic is requested.
Returns
A font file matching the given description (either an on-disk font filepath or an in-memory file contents). You can return NULL here and the library will fallback to another font.
Note
Return the closest face you have. When the face you return isn't already bold for a weight of 600 or heavier, or isn't already slanted for an italic request, the library synthesizes the difference by emboldening or slanting the outlines. A page can turn that off with the CSS font-synthesis property.

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