-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfonts.h
More file actions
99 lines (86 loc) · 2.52 KB
/
Copy pathfonts.h
File metadata and controls
99 lines (86 loc) · 2.52 KB
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
/*
* fonts.h - Font handler & renderer
* Copyright 2026 Ian Ward
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef XPDRAW_FONTS_H
#define XPDRAW_FONTS_H
#include <limits.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "xpdraw.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XPD_CHAR_MAX (CHAR_MAX - CHAR_MIN)
typedef enum {
XPD_ALIGN_L,
XPD_ALIGN_C,
XPD_ALIGN_R
} xpd_text_align_t;
typedef struct {
char letter;
FT_Glyph_Metrics metrics;
xpd_texture_t bitmap;
} xpd_font_letter_t;
typedef struct {
FT_Face ftFace;
xpd_font_letter_t letters[XPD_CHAR_MAX];
} xpd_font_face_t;
/**
* @brief Load a new font
*
* @param font Pointer to the font we are loading
* @param fmt File path to load from
* @param size Size of font face to use
*/
void xpd_font_load(xpd_font_face_t *font, const char *fmt, int size, ...) __attribute__ ((format(printf, 2, 4)));
/**
* @brief Load a new font, but combine root and filename to create the filepath
*
* @param font Pointer to the font face
* @param root First half of filepath
* @param filename Second half of filepath
* @param size Size of the font face
*/
[[deprecated]]
inline void xpd_font_load2(xpd_font_face_t *font, const char *root, const char *filename, const int size) {
char *fnt_pth_tmp = xpd_tools_constr(root, filename);
xpd_font_load(font, fnt_pth_tmp, size);
free(fnt_pth_tmp);
}
/**
* @brief Returns the length of a string.
*
* @param font Font to use
* @param text Text to get the length of
* @return int
*/
int xpd_text_length(xpd_font_face_t *font, const char *text);
/**
* @brief Function to draw text
*
* @param font Font to use
* @param text Text to render
* @param x Lateral position to draw at relative to anchor
* @param y Vertical position to draw at relative to anchor
* @param align Alignment of the text relative to x
* @param color Color of the text; defaults to white
*/
void xpd_text_draw(xpd_font_face_t *font, const char *text, int x, int y, xpd_text_align_t align,
xpd_color_t color);
#ifdef __cplusplus
}
#endif
#endif