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
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
#pragma once
9
#include <
Ultralight/Defines.h
>
10
#include <
Ultralight/String.h
>
11
#include <
Ultralight/Buffer.h
>
12
13
namespace
ultralight
{
14
15
///
16
/// Represents a font file, either on-disk path or in-memory file contents.
17
///
18
class
UExport
FontFile
:
public
RefCounted
{
19
public
:
20
///
21
/// Create a font file from an on-disk file path.
22
///
23
/// @note The file path should already exist.
24
///
25
static
RefPtr<FontFile>
Create
(
const
String
&
filepath
);
26
27
///
28
/// Create a font file from an in-memory buffer.
29
///
30
static
RefPtr<FontFile>
Create
(
RefPtr<Buffer>
buffer
);
31
32
///
33
/// Whether or not this font file was created from an in-memory buffer.
34
///
35
virtual
bool
is_in_memory
()
const
= 0;
36
37
///
38
/// The file path (if any).
39
///
40
virtual
String
filepath
()
const
= 0;
41
42
///
43
/// The in-memory buffer (if any).
44
///
45
virtual
RefPtr<Buffer>
buffer
()
const
= 0;
46
47
///
48
/// Unique hash (if this is a filepath, only the path string is hashed).
49
///
50
virtual
uint32_t
hash
()
const
= 0;
51
52
protected
:
53
FontFile
();
54
virtual
~FontFile
();
55
FontFile
(
const
FontFile
&);
56
void
operator=
(
const
FontFile
&);
57
};
58
59
///
60
/// User-defined font loader interface.
61
///
62
/// The library uses this to load a font file (eg, `Arial.ttf`) for a given font description (eg,
63
/// `font-family: Arial;`).
64
///
65
/// Every OS has its own library of installed system fonts. The FontLoader interface is used to
66
/// lookup these fonts and fetch the actual font data (raw TTF/OTF file data) for a given font
67
/// description.
68
///
69
/// You can provide the library with your own font loader implementation so that you can bundle
70
/// fonts with your application rather than relying on the system's installed fonts.
71
///
72
/// ## Default Implementation
73
///
74
/// A platform-specific implementation of FontLoader is provided for you when you call
75
/// App::Create().
76
///
77
/// If you are using Renderer::Create(), you **must** provide your own. You can still use AppCore's
78
/// implementation however-- see the helper functions defined in <AppCore/Platform.h>.
79
///
80
/// ## Setting the Font Loader
81
///
82
/// To provide your own custom FontLoader implementation, you should inherit from this class,
83
/// handle the virtual member functions, and then pass an instance of your class to
84
/// Platform::set_font_loader() before calling Renderer::Create() or App::Create().
85
///
86
class
UExport
FontLoader
{
87
public
:
88
virtual
~FontLoader
();
89
90
///
91
/// Fallback font family name. Will be used if all other fonts fail to load.
92
///
93
/// @note This font should be guaranteed to exist (eg, FontLoader::Load won't fail when passed
94
/// this font family name).
95
///
96
virtual
String
fallback_font
()
const
= 0;
97
98
///
99
/// Fallback font family name that can render the specified characters. Mainly used to support
100
/// CJK (Chinese, Japanese, Korean) text display.
101
///
102
/// @param characters One or more UTF-16 characters. This is almost always a single character.
103
///
104
/// @param weight Font weight.
105
///
106
/// @param italic Whether or not italic is requested.
107
///
108
/// @return Returns a font family name that can render the text.
109
///
110
virtual
String
fallback_font_for_characters
(
const
String
& characters,
int
weight,
111
bool
italic)
const
= 0;
112
113
///
114
/// Get the actual font file data (TTF/OTF) for a given font description.
115
///
116
/// @param family Font family name.
117
///
118
/// @param weight Font weight.
119
///
120
/// @param italic Whether or not italic is requested.
121
///
122
/// @return A font file matching the given description (either an on-disk font filepath or an
123
/// in-memory file contents). You can return NULL here and the loader will fallback to
124
/// another font.
125
///
126
virtual
RefPtr<FontFile>
Load
(
const
String
& family,
int
weight,
bool
italic) = 0;
127
};
128
129
}
// namespace ultralight
Buffer.h
UExport
#define UExport
Definition
Exports.h:25
String.h
Defines.h
ultralight::FontFile::~FontFile
virtual ~FontFile()
ultralight::FontFile::FontFile
FontFile(const FontFile &)
ultralight::FontFile::Create
static RefPtr< FontFile > Create(RefPtr< Buffer > buffer)
Create a font file from an in-memory buffer.
ultralight::FontFile::Create
static RefPtr< FontFile > Create(const String &filepath)
Create a font file from an on-disk file path.
ultralight::FontFile::buffer
virtual RefPtr< Buffer > buffer() const =0
The in-memory buffer (if any).
ultralight::FontFile::FontFile
FontFile()
ultralight::FontFile::hash
virtual uint32_t hash() const =0
Unique hash (if this is a filepath, only the path string is hashed).
ultralight::FontFile::is_in_memory
virtual bool is_in_memory() const =0
Whether or not this font file was created from an in-memory buffer.
ultralight::FontFile::filepath
virtual String filepath() const =0
The file path (if any).
ultralight::FontFile::operator=
void operator=(const FontFile &)
ultralight::FontLoader
User-defined font loader interface.
Definition
FontLoader.h:86
ultralight::FontLoader::fallback_font_for_characters
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.
ultralight::FontLoader::Load
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.
ultralight::FontLoader::~FontLoader
virtual ~FontLoader()
ultralight::FontLoader::fallback_font
virtual String fallback_font() const =0
Fallback font family name.
ultralight::RefCounted
Interface for all ref-counted objects that will be managed using the RefPtr<> smart pointer.
Definition
RefPtr.h:47
ultralight::RefPtr
A nullable smart pointer.
Definition
RefPtr.h:79
ultralight::String
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition
String.h:34
ultralight
Definition
Bitmap.h:14
Ultralight
platform
FontLoader.h
Docs
C++ API
C API
Version
1.4
2.0
latest
1.4