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
59 /* caching the rasterized glyph + metrics here so we're not
60 * re-rasterizing the same char every repaint, thats wasteful as hell --axiss */
70#endif
71
72#ifdef ARCH_ARM64
73#define XENEVA_DEFAULT_FONT CALIBRI //FORTE
74#else
75 /* default font for xeneva */
76#define XENEVA_DEFAULT_FONT CALIBRI
77#endif
78
79 typedef struct _ch_font_ {
80 int fileSz;
87#ifdef _USE_FREETYPE
88 FT_Library lib;
89 FT_Face face;
90 FT_GlyphSlot slot;
91#else
92 /* fallback path for when freetype isnt built for the target (aa64/llvm rn).
93 * reusing font->kern up above as the "previous codepoint" for kerning
94 * lookups here too, didnt want another field just for that --axiss */
96 float stbScale;
101#endif
103
104
105
106 /*
107 * ChInitialiseFont -- initialise a font by a name
108 * @param fontname -- name of the font
109 */
110 XE_LIB ChFont *ChInitialiseFont(char* fontname);
111
112 /*
113 * ChFontSetSize -- set a font size
114 * @param font -- Pointer to font
115 * @param size -- size of the font
116 */
117 XE_LIB void ChFontSetSize(ChFont* font, int size);
118
119 /*
120 * ChFontDrawText -- draws a text using desired font
121 * @param canv -- Pointer to canvas
122 * @param font -- Pointer to font
123 * @param string -- string to draw
124 * @param penx -- x coordinate
125 * @param peny -- y coordinate
126 * @param sz -- font size
127 * @param color -- color of the font
128 */
129 XE_LIB void ChFontDrawText(ChCanvas *canv, ChFont* font, char* string, int penx, int peny, uint32_t sz, uint32_t color);
130
131 /*
132 * ChFontDrawCharClipped -- draws a character using desired font
133 * @param canv -- Pointer to canvas
134 * @param font -- Pointer to font
135 * @param string -- string to draw
136 * @param penx -- x coordinate
137 * @param peny -- y coordinate
138 * @param sz -- font size
139 * @param color -- color of the font
140 * @param limit -- clippings
141 */
142 void ChFontDrawCharClipped(ChCanvas* canv, ChFont* font, char c, int penx, int peny, uint32_t color, ChRect* limit);
143
144 /*
145 * ChFontDrawChar -- draws a character using desired font
146 * @param canv -- Pointer to canvas
147 * @param font -- Pointer to font
148 * @param string -- string to draw
149 * @param penx -- x coordinate
150 * @param peny -- y coordinate
151 * @param sz -- font size
152 * @param color -- color of the font
153 */
154 XE_LIB void ChFontDrawChar(ChCanvas *canv, ChFont* font, char c, int penx, int peny, uint32_t sz, uint32_t color);
155
156 /*
157 * ChFontDrawTextClipped -- draws text using specific font within
158 * a clipped boundary
159 * @param canv -- Pointer to Canvas
160 * @param font -- Pointer to font to use
161 * @param string -- string to draw
162 * @param penx -- x position
163 * @param peny -- y position
164 * @param color -- color to use
165 * @param limit -- boundary of the rectangle
166 */
167 XE_LIB int ChFontDrawTextClipped(ChCanvas *canv, ChFont* font, char* string, int penx, int peny, uint32_t color, ChRect* limit);
168
169 /*
170 * ChFontGetWidth -- return the total width of font in
171 * pixel size
172 * @param font -- Pointer to font
173 * @param string -- total string
174 */
175 XE_LIB int64_t ChFontGetWidth(ChFont* font, char* string);
176
177 /*
178 * ChFontGetWidthChar -- return the total width of font in
179 * pixel size of one character
180 * @param font -- Pointer to font
181 * @param c -- character
182 */
184
185 /*
186 * ChFontGetHeight -- return the total height of font
187 * in pixel size
188 * @param font -- Pointer to font
189 * @param string -- total string
190 */
191 XE_LIB int64_t ChFontGetHeight(ChFont* font, char* string);
192
193 /*
194 * ChFontGetHeightChar -- return the total width of font in
195 * pixel size of one character
196 * @param font -- Pointer to font
197 * @param c -- character
198 */
200
201 /*
202 * ChFontClose -- closes an opened font
203 * @param font -- Pointer to font
204 */
205 XE_LIB int ChFontClose(ChFont* font);
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif
XE_LIB int ChFontDrawTextClipped(ChCanvas *canv, ChFont *font, char *string, int penx, int peny, uint32_t color, ChRect *limit)
Definition font.cpp:677
XE_LIB int64_t ChFontGetHeightChar(ChFont *font, char c)
Definition font.cpp:631
void ChFontDrawCharClipped(ChCanvas *canv, ChFont *font, char c, int penx, int peny, uint32_t color, ChRect *limit)
Definition font.cpp:397
#define CH_FONT_GLYPH_CACHE_SIZE
Definition font.h:57
XE_LIB int64_t ChFontGetHeight(ChFont *font, char *string)
Definition font.cpp:595
XE_LIB void ChFontSetSize(ChFont *font, int size)
Definition font.cpp:213
XE_LIB int64_t ChFontGetWidth(ChFont *font, char *string)
Definition font.cpp:510
struct _ch_font_glyph_cache_entry_ ChFontGlyphCacheEntry
XE_LIB int64_t ChFontGetWidthChar(ChFont *font, char c)
Definition font.cpp:559
XE_LIB int ChFontClose(ChFont *font)
Definition font.cpp:798
XE_LIB ChFont * ChInitialiseFont(char *fontname)
Definition font.cpp:136
XE_LIB void ChFontDrawChar(ChCanvas *canv, ChFont *font, char c, int penx, int peny, uint32_t sz, uint32_t color)
Definition font.cpp:323
struct _ch_font_ ChFont
XE_LIB void ChFontDrawText(ChCanvas *canv, ChFont *font, char *string, int penx, int peny, uint32_t sz, uint32_t color)
Definition font.cpp:243
#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
Definition freetype.h:1042
Definition freetype.h:1878
Definition ftobjs.h:896
Definition chitralekha.h:40
Definition font.h:79
float stbScale
Definition font.h:96
int stbDescent
Definition font.h:98
ChFontGlyphCacheEntry glyphCache[CH_FONT_GLYPH_CACHE_SIZE]
Definition font.h:100
int stbAscent
Definition font.h:97
uint32_t fontSz
Definition font.h:82
uint8_t * buffer
Definition font.h:81
int stbLineGap
Definition font.h:99
uint32_t kern
Definition font.h:84
uint16_t key
Definition font.h:83
stbtt_fontinfo stbFont
Definition font.h:95
uint32_t lineHeight
Definition font.h:85
int fileSz
Definition font.h:80
uint32_t fontHeight
Definition font.h:86
Definition font.h:61
int16_t width
Definition font.h:63
uint8_t * bitmap
Definition font.h:62
uint8_t loaded
Definition font.h:68
int16_t yOffset
Definition font.h:66
int16_t xOffset
Definition font.h:65
int16_t height
Definition font.h:64
int16_t advance
Definition font.h:67
Definition draw.h:42
Definition stb_truetype.h:715