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