forked from Chlumsky/msdfgen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
msdfgen-ext-c.h
114 lines (96 loc) · 4.67 KB
/
msdfgen-ext-c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
/*
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR
* ---------------------------------------------
* A utility by Viktor Chlumsky, (c) 2014 - 2024
*
* The technique used to generate multi-channel distance fields in this code
* has been developed by Viktor Chlumsky in 2014 for his master's thesis,
* "Shape Decomposition for Multi-Channel Distance Fields". It provides improved
* quality of sharp corners in glyphs and other 2D shapes compared to monochrome
* distance fields. To reconstruct an image of the shape, apply the median of three
* operation on the triplet of sampled signed distance values.
*/
#include "msdfgen-c.h"
/*
* A C-API modeled closely after the msdfgen C++ API
* to allow C-programs and other language runtimes to
* use the msdfgen library. Originally written for LWJGL.
*
* @since 11/05/2024
* @author Alexander Hinze
*/
#ifdef __cplusplus
extern "C" {
#endif
MSDF_DEFINE_HANDLE_TYPE(msdf_ft);
MSDF_DEFINE_HANDLE_TYPE(msdf_ft_font);
#ifdef MSDFGEN_DYNAMIC_FREETYPE // Runtime loader API
typedef void* (*msdf_ft_load_callback)(const char* functionName);
/**
* Overrides the default load callback function used for resolving FreeTypee function at runtime.
* @param callback A pointer to the function to call for resolving FreeType functions at runtime.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_set_load_callback(msdf_ft_load_callback callback);
/**
* Retrieves the current FreeType load callback.
* @returns A pointer to the current FreeType load callback function.
*/
MSDF_API msdf_ft_load_callback msdf_ft_get_load_callback();
#endif
/**
* Initializes a new FreeType instance to be used with msdfgen.
* @param handle A pointer to a handle to be populated with a new FreeType context.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_init(msdf_ft_handle* handle);
/**
* Loads a TrueType font from the given file(path) and populates
* the given font handle with the address of the newly loaded font.
* @param handle The handle to the FreeType context to use for loading the font.
* @param filename The name or path of/to the font file to load.
* @param font A pointer to a font handle to be populated with the address of the newly loaded font.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_load_font(msdf_ft_handle handle, const char* filename, msdf_ft_font_handle* font);
/**
* Adopts the given FreeType FT_Face pointer as a font handle.
* @param face An opaque pointer to the FT_Face to adopt.
* @param font A pointer to an address to be populated with the newly allocated font handle.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_adopt_font(void* face, msdf_ft_font_handle* font);
/**
* Loads a TrueType font from the given buffer and populates
* the given font handle with the address of the newly loaded font.
* @param handle The handle to the FreeType context to use for loading the font.
* @param data A pointer to the raw data of the TrueType font to load.
* @param size The size of the data buffer in bytes.
* @param font A pointer to a font handle to be populated with the address of the newly loaded font.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_load_font_data(msdf_ft_handle handle, const void* data, size_t size, msdf_ft_font_handle* font);
/**
* Loads a single glyph from the given font and converts it into a vector shape
* for rendering glyph sprites.
* @param font A handle to the font to use for generating the glyph shape.
* @param cp The codepoint to generate a shape for.
* @param shape A pointer to a handle to be populated with the address of the newly created shape.
* This shape must later be freed using msdf_shape_free!
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_ft_font_load_glyph(msdf_ft_font_handle font, unsigned cp, msdf_shape_handle* shape);
/**
* Frees the underlying instance of the given FreeType font.
* @param handle The handle to the font to free.
*/
MSDF_API void msdf_ft_font_destroy(msdf_ft_font_handle handle);
/**
* Frees the underlying FreeType instance of the given context.
* @param handle The handle to the FreeType context to free.
*/
MSDF_API void msdf_ft_deinit(msdf_ft_handle handle);
#ifdef __cplusplus
}
#endif