docs
Docs
C++ API
C API
Search API
Ctrl K
2.0
2.0
latest
1.4
Ultralight C API
2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
CAPI_FontLoader.h
Go to the documentation of this file.
1
///
2
/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3
/// A license is required for commercial use. https://ultralig.ht
4
///
5
6
///
7
/// @file CAPI_FontLoader.h
8
///
9
/// User-defined font loader interface.
10
///
11
/// `#include <Ultralight/CAPI/CAPI_FontLoader.h>`
12
///
13
/// The library uses this to load a font file (eg, `Arial.ttf`) for a given font description (eg,
14
/// `font-family: Arial;`).
15
///
16
/// Every OS has its own library of installed system fonts. The FontLoader interface is used to
17
/// lookup these fonts and fetch the actual font data (raw TTF/OTF file data) for a given font
18
/// description.
19
///
20
/// You can provide the library with your own font loader implementation so that you can bundle
21
/// fonts with your application rather than relying on the system's installed fonts.
22
///
23
/// ## Threading
24
///
25
/// The library calls these callbacks from the thread you created the Renderer on and from the
26
/// threads that run Web Workers. Those calls can overlap, so your implementation **must** be safe
27
/// to call from more than one thread at once (guard any state your callbacks share).
28
///
29
/// @see ulPlatformSetFontLoader
30
///
31
#ifndef ULTRALIGHT_CAPI_FONTLOADER_H
32
#define ULTRALIGHT_CAPI_FONTLOADER_H
33
34
#include <
Ultralight/CAPI/CAPI_Defines.h
>
35
#include <
Ultralight/CAPI/CAPI_FontFile.h
>
36
37
#ifdef __cplusplus
38
extern
"C"
{
39
#endif
40
41
/******************************************************************************
42
* Font Loader
43
*****************************************************************************/
44
45
///
46
/// Fallback font family name. Will be used if all other fonts fail to load.
47
///
48
/// \parblock
49
/// @note This font should be guaranteed to exist (eg, ULFontLoader::load should not fail when
50
/// when passed this font family name).
51
/// \endparblock
52
///
53
/// \parblock
54
/// @note The returned ULString instance will be consumed (ulDestroyString will be called on it).
55
/// \endparblock
56
///
57
typedef
ULString
(*
ULFontLoaderGetFallbackFont
)(void);
58
59
///
60
/// Fallback font family name that can render the specified characters. This is mainly used to
61
/// support CJK (Chinese, Japanese, Korean) text display.
62
///
63
/// @param characters One or more UTF-16 characters. This is almost always a single character.
64
///
65
/// @param weight Font weight.
66
///
67
/// @param italic Whether or not italic is requested.
68
///
69
/// @return Return a font family name that can render the text. The returned ULString
70
/// instance will be consumed (ulDestroyString will be called on it).
71
///
72
typedef
ULString
(*
ULFontLoaderGetFallbackFontForCharacters
)(
ULString
characters,
int
weight,
73
bool
italic);
74
75
///
76
/// Get the actual font file data (TTF/OTF) for a given font description.
77
///
78
/// @param family Font family name.
79
///
80
/// @param weight Font weight.
81
///
82
/// @param italic Whether or not italic is requested.
83
///
84
/// @return Returns a font file matching the given description (either an on-disk font filepath or an
85
/// in-memory file buffer). You can return NULL here and the loader will fallback to
86
/// another font. The returned ULFontFile instance will be consumed (ulDestroyFontFile
87
/// will be called on it).
88
///
89
typedef
ULFontFile
(*
ULFontLoaderLoad
)(
ULString
family,
int
weight,
bool
italic);
90
91
///
92
/// User-defined font loader interface.
93
///
94
/// You should implement each of these callbacks, then pass an instance of this struct containing
95
/// your callbacks to ulPlatformSetFontLoader().
96
///
97
typedef
struct
{
98
ULFontLoaderGetFallbackFont
get_fallback_font
;
99
ULFontLoaderGetFallbackFontForCharacters
get_fallback_font_for_characters
;
100
ULFontLoaderLoad
load
;
101
}
ULFontLoader
;
102
103
#ifdef __cplusplus
104
}
// extern "C"
105
#endif
106
107
#endif
// ULTRALIGHT_CAPI_FONTLOADER_H
CAPI_FontFile.h
Font file interface.
ULFontLoaderGetFallbackFont
ULString(*) ULFontLoaderGetFallbackFont(void)
Fallback font family name.
Definition
CAPI_FontLoader.h:57
ULFontLoaderGetFallbackFontForCharacters
ULString(*) ULFontLoaderGetFallbackFontForCharacters(ULString characters, int weight, bool italic)
Fallback font family name that can render the specified characters.
Definition
CAPI_FontLoader.h:72
ULFontLoaderLoad
ULFontFile(*) ULFontLoaderLoad(ULString family, int weight, bool italic)
Get the actual font file data (TTF/OTF) for a given font description.
Definition
CAPI_FontLoader.h:89
CAPI_Defines.h
Various defines and utility functions for the C API.
ULFontFile
struct C_FontFile * ULFontFile
Opaque handle to a FontFile object.
Definition
CAPI_Defines.h:128
ULString
struct C_String * ULString
Opaque handle to a String object.
Definition
CAPI_Defines.h:96
ULFontLoader
User-defined font loader interface.
Definition
CAPI_FontLoader.h:97
ULFontLoader::get_fallback_font_for_characters
ULFontLoaderGetFallbackFontForCharacters get_fallback_font_for_characters
Definition
CAPI_FontLoader.h:99
ULFontLoader::get_fallback_font
ULFontLoaderGetFallbackFont get_fallback_font
Definition
CAPI_FontLoader.h:98
ULFontLoader::load
ULFontLoaderLoad load
Definition
CAPI_FontLoader.h:100
Ultralight
CAPI
CAPI_FontLoader.h
Docs
C++ API
C API
Version
2.0
2.0
latest
1.4