docs
Loading...
Searching...
No Matches
CAPI_FontFile.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_FontFile.h
8///
9/// Font file interface.
10///
11/// `#include <Ultralight/CAPI/CAPI_FontFile.h>`
12///
13/// The font file interface represents a font file: either on-disk path or in-memory file contents.
14///
15/// @see ULFontLoader
16///
17#ifndef ULTRALIGHT_CAPI_FONTFILE_H
18#define ULTRALIGHT_CAPI_FONTFILE_H
19
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28///
29/// Create a font file from an on-disk file path.
30///
31/// @param file_path The path to the font file on disk. The file should already exist.
32///
33/// @return A new font file instance. You must call ulDestroyFontFile() when finished.
34///
36
37///
38/// Create a font file from an in-memory buffer.
39///
40/// @param buffer A buffer containing the font file data (TTF/OTF).
41///
42/// @return A new font file instance. You must call ulDestroyFontFile() when finished.
43///
44/// @note The font file keeps its own reference to the buffer, so you still call
45/// ulDestroyBuffer() on `buffer` when you're done with it (right after this call is fine).
46///
48
49///
50/// Create a font file from an on-disk file path, naming the face within a font collection.
51///
52/// @param file_path The path to the font file on disk. The file should already exist.
53///
54/// @param face_index The index of the face to use when the file is a font collection (eg, a
55/// `.ttc` holding several families). Pass -1 to let the library choose the
56/// face that best matches the requested weight and style.
57///
58/// @return Returns a new font file instance. You must call ulDestroyFontFile() when finished.
59///
61
62///
63/// Create a font file from an in-memory buffer, naming the face within a font collection.
64///
65/// @param buffer A buffer containing the font file data (TTF/OTF, or a collection).
66///
67/// @param face_index The index of the face to use when the data is a font collection. Pass -1
68/// to let the library choose the face that best matches the requested weight
69/// and style.
70///
71/// @return Returns a new font file instance. You must call ulDestroyFontFile() when finished.
72///
73/// @note The font file keeps its own reference to the buffer, so you still call
74/// ulDestroyBuffer() on `buffer` when you're done with it (right after this call is fine).
75///
77
78///
79/// Destroy a font file previously created with ulFontFileCreateFromFilePath() or
80/// ulFontFileCreateFromBuffer().
81///
82/// @param font_file The font file to destroy.
83///
85
86///
87/// Whether or not this font file was created from an in-memory buffer.
88///
90
91///
92/// Get the file path for this font file (if created from a file path).
93///
94/// @return The file path, or an empty string if created from a buffer. Do not destroy the
95/// returned string. It stays valid until the next call to ulFontFileGetFilePath() on the
96/// same thread (for any font file); copy it via ulCreateStringFromCopy() to keep it.
97///
99
100///
101/// Get the in-memory buffer for this font file (if created from a buffer).
102///
103/// @return The buffer, or NULL if created from a file path. Do not destroy the returned buffer.
104/// It stays valid until the next call to ulFontFileGetBuffer() on the same thread (for
105/// any font file).
106///
108
109///
110/// Get the index of the face within a font collection, or -1 when the library chooses the face.
111///
113
114///
115/// Get the unique hash for this font file.
116///
117ULExport unsigned int ulFontFileGetHash(ULFontFile font_file);
118
119#ifdef __cplusplus
120} // extern "C"
121#endif
122
123#endif // ULTRALIGHT_CAPI_FONTFILE_H
A fixed-size container for raw byte data.
bool ulFontFileIsInMemory(ULFontFile font_file)
Whether or not this font file was created from an in-memory buffer.
ULFontFile ulFontFileCreateFromFilePathWithFaceIndex(ULString file_path, int face_index)
Create a font file from an on-disk file path, naming the face within a font collection.
ULFontFile ulFontFileCreateFromBufferWithFaceIndex(ULBuffer buffer, int face_index)
Create a font file from an in-memory buffer, naming the face within a font collection.
ULBuffer ulFontFileGetBuffer(ULFontFile font_file)
Get the in-memory buffer for this font file (if created from a buffer).
unsigned int ulFontFileGetHash(ULFontFile font_file)
Get the unique hash for this font file.
ULString ulFontFileGetFilePath(ULFontFile font_file)
Get the file path for this font file (if created from a file path).
void ulDestroyFontFile(ULFontFile font_file)
Destroy a font file previously created with ulFontFileCreateFromFilePath() or ulFontFileCreateFromBuf...
int ulFontFileGetFaceIndex(ULFontFile font_file)
Get the index of the face within a font collection, or -1 when the library chooses the face.
ULFontFile ulFontFileCreateFromFilePath(ULString file_path)
Create a font file from an on-disk file path.
ULFontFile ulFontFileCreateFromBuffer(ULBuffer buffer)
Create a font file from an in-memory buffer.
Unicode string container (natively UTF-8).
Various defines and utility functions for the C API.
struct C_FontFile * ULFontFile
Opaque handle to a FontFile object.
Definition CAPI_Defines.h:128
struct C_String * ULString
Opaque handle to a String object.
Definition CAPI_Defines.h:96
#define ULExport
Definition CAPI_Defines.h:42
struct C_Buffer * ULBuffer
Opaque handle to a Buffer object.
Definition CAPI_Defines.h:99