XenevaOS
Loading...
Searching...
No Matches
font.h
Go to the documentation of this file.
1
30#ifndef __FONT_H__
31#define __FONT_H__
32
33#include <stdint.h>
34#include <sys/_keftmngr.h>
35#include <freetype/ftglyph.h>
36#include <_xeneva.h>
37#include "chitralekha.h"
38#include "draw.h"
39#include <ft2build.h>
40#include FT_FREETYPE_H
41#include "stb_truetype.h"
42
43#ifdef __cplusplus
45#endif
46
47 /* pre-defined system fonts */
48#define ROBOTO_LIGHT "Roboto-Light"
49#define ROBOTO_LIGHT_ITALIC "Roboto-Light-Italic"
50#define ROBOTO_THIN "Roboto-Thin"
51#define CORBEL "Corbel"
52#define CALIBRI "Calibri"
53#define FORTE "Forte"
54#define CONSOLAS "Consolas"
55
56#ifndef _USE_FREETYPE
57#define CH_FONT_GLYPH_CACHE_SIZE 256
58#define CH_FONT_ATLAS_FIRST 32
59#define CH_FONT_ATLAS_COUNT 95
60#define CH_FONT_ATLAS_W 512
61#define CH_FONT_ATLAS_H 512
62
63 /* caching the rasterized glyph + metrics here so we're not
64 * re-rasterizing the same char every repaint, thats wasteful as hell --axiss */
74#endif
75
76#ifdef ARCH_ARM64
77#define XENEVA_DEFAULT_FONT CALIBRI //FORTE
78#else
79/* default font for xeneva */
80#define XENEVA_DEFAULT_FONT CALIBRI
81#endif
82
83 typedef struct _ch_font_ {
84 int fileSz;
93#ifdef _USE_FREETYPE
94 FT_Library lib;
95 FT_Face face;
96 FT_GlyphSlot slot;
97#else
98 /* fallback path for when freetype isnt built for the target (aa64/llvm rn).
99 * reusing font->kern up above as the "previous codepoint" for kerning
100 * lookups here too, didnt want another field just for that --axiss */
102 float stbScale;
112#endif
114
115 /*
116 * ChInitialiseFont -- initialise a font by a name
117 * @param fontname -- name of the font
118 */
119 XE_LIB ChFont* ChInitialiseFont(char* fontname);
120
121 /*
122 * ChFontSetSize -- set a font size
123 * @param font -- Pointer to font
124 * @param size -- size of the font
125 */
126 XE_LIB void ChFontSetSize(ChFont * font, int size);
127
128 /*
129 * ChFontDrawText -- draws a text using desired font
130 * @param canv -- Pointer to canvas
131 * @param font -- Pointer to font
132 * @param string -- string to draw
133 * @param penx -- x coordinate
134 * @param peny -- y coordinate
135 * @param sz -- font size
136 * @param color -- color of the font
137 */
138 XE_LIB void ChFontDrawText(ChCanvas * canv,
139 ChFont * font,
140 char* string,
141 int penx,
142 int peny,
143 uint32_t sz,
145
146 /*
147 * ChFontDrawCharClipped -- draws a character using desired font
148 * @param canv -- Pointer to canvas
149 * @param font -- Pointer to font
150 * @param string -- string to draw
151 * @param penx -- x coordinate
152 * @param peny -- y coordinate
153 * @param sz -- font size
154 * @param color -- color of the font
155 * @param limit -- clippings
156 */
158 ChCanvas * canv, ChFont * font, char c, int penx, int peny, uint32_t color, ChRect* limit);
159
160 /*
161 * ChFontDrawChar -- draws a character using desired font
162 * @param canv -- Pointer to canvas
163 * @param font -- Pointer to font
164 * @param string -- string to draw
165 * @param penx -- x coordinate
166 * @param peny -- y coordinate
167 * @param sz -- font size
168 * @param color -- color of the font
169 */
171 ChCanvas * canv, ChFont * font, char c, int penx, int peny, uint32_t sz, uint32_t color);
172
173 /*
174 * ChFontDrawTextClipped -- draws text using specific font within
175 * a clipped boundary
176 * @param canv -- Pointer to Canvas
177 * @param font -- Pointer to font to use
178 * @param string -- string to draw
179 * @param penx -- x position
180 * @param peny -- y position
181 * @param color -- color to use
182 * @param limit -- boundary of the rectangle
183 */
185 ChFont * font,
186 char* string,
187 int penx,
188 int peny,
190 ChRect* limit);
191
192 /*
193 * ChFontGetWidth -- return the total width of font in
194 * pixel size
195 * @param font -- Pointer to font
196 * @param string -- total string
197 */
198 XE_LIB int64_t ChFontGetWidth(ChFont * font, char* string);
199
200 /*
201 * ChFontGetWidthChar -- return the total width of font in
202 * pixel size of one character
203 * @param font -- Pointer to font
204 * @param c -- character
205 */
206 XE_LIB int64_t ChFontGetWidthChar(ChFont * font, char c);
207
208 /*
209 * ChFontGetHeight -- return the total height of font
210 * in pixel size
211 * @param font -- Pointer to font
212 * @param string -- total string
213 */
214 XE_LIB int64_t ChFontGetHeight(ChFont * font, char* string);
215
216 /*
217 * ChFontGetHeightChar -- return the total width of font in
218 * pixel size of one character
219 * @param font -- Pointer to font
220 * @param c -- character
221 */
223
224 /*
225 * ChFontClose -- closes an opened font
226 * @param font -- Pointer to font
227 */
228 XE_LIB int ChFontClose(ChFont * font);
229
230#ifdef __cplusplus
231}
232#endif
233
234#endif
XE_LIB int ChFontDrawTextClipped(ChCanvas *canv, ChFont *font, char *string, int penx, int peny, uint32_t color, ChRect *limit)
Definition font.cpp:1054
XE_LIB int64_t ChFontGetHeightChar(ChFont *font, char c)
Definition font.cpp:1007
void ChFontDrawCharClipped(ChCanvas *canv, ChFont *font, char c, int penx, int peny, uint32_t color, ChRect *limit)
Definition font.cpp:705
#define CH_FONT_GLYPH_CACHE_SIZE
Definition font.h:57
XE_LIB int64_t ChFontGetHeight(ChFont *font, char *string)
Definition font.cpp:971
XE_LIB void ChFontSetSize(ChFont *font, int size)
Definition font.cpp:467
XE_LIB int64_t ChFontGetWidth(ChFont *font, char *string)
Definition font.cpp:859
struct _ch_font_glyph_cache_entry_ ChFontGlyphCacheEntry
XE_LIB int64_t ChFontGetWidthChar(ChFont *font, char c)
Definition font.cpp:914
XE_LIB int ChFontClose(ChFont *font)
Definition font.cpp:1187
XE_LIB ChFont * ChInitialiseFont(char *fontname)
Definition font.cpp:389
XE_LIB void ChFontDrawChar(ChCanvas *canv, ChFont *font, char c, int penx, int peny, uint32_t sz, uint32_t color)
Definition font.cpp:591
struct _ch_font_ ChFont
#define CH_FONT_ATLAS_COUNT
Definition font.h:59
XE_LIB void ChFontDrawText(ChCanvas *canv, ChFont *font, char *string, int penx, int peny, uint32_t sz, uint32_t color)
Definition font.cpp:498
#define XE_LIB
Definition _xeneva.h:55
#define XE_EXTERN
Definition _xeneva.h:50
unsigned int uint32_t
Definition acefiex.h:163
COMPILER_DEPENDENT_INT64 int64_t
Definition acefiex.h:164
short int int16_t
Definition acefiex.h:159
unsigned char uint8_t
Definition acefiex.h:161
unsigned short int uint16_t
Definition acefiex.h:162
size_t size
Definition drm_bridge.h:1299
Definition freetype.h:1042
Definition freetype.h:1878
Definition ftobjs.h:896
Definition chitralekha.h:40
Definition font.h:83
float stbScale
Definition font.h:102
int stbDescent
Definition font.h:104
ChFontGlyphCacheEntry glyphCache[CH_FONT_GLYPH_CACHE_SIZE]
Definition font.h:106
int stbAscent
Definition font.h:103
uint32_t fontSz
Definition font.h:86
uint8_t * buffer
Definition font.h:85
uint32_t utf8_cp
Definition font.h:91
int stbLineGap
Definition font.h:105
int atlasReady
Definition font.h:110
int utf8_remaining
Definition font.h:92
uint32_t kern
Definition font.h:88
uint16_t key
Definition font.h:87
int atlasH
Definition font.h:109
int atlasW
Definition font.h:108
uint8_t * atlasPixels
Definition font.h:107
stbtt_fontinfo stbFont
Definition font.h:101
uint32_t lineHeight
Definition font.h:89
int fileSz
Definition font.h:84
uint32_t fontHeight
Definition font.h:90
stbtt_bakedchar atlasChars[CH_FONT_ATLAS_COUNT]
Definition font.h:111
Definition font.h:65
int16_t width
Definition font.h:67
uint8_t * bitmap
Definition font.h:66
uint8_t loaded
Definition font.h:72
int16_t yOffset
Definition font.h:70
int16_t xOffset
Definition font.h:69
int16_t height
Definition font.h:68
int16_t advance
Definition font.h:71
Definition draw.h:42
Definition i_video.h:141
Definition stb_truetype.h:529
Definition stb_truetype.h:715