The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
bragi_internal.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file bragi_internal.h
5 * @brief what the bragi sources share: the font, the face and the glyph.
6 */
7
8#include "bragi.h"
9
10#define STBTT_assert(x) ((void)0)
11#include "../stb/stb_truetype.h"
12
13// positions along a line are kept in 1/64 pixels
14#define BRAGI_UNITS 64
15
16// glyphs are made at 4 horizontal positions: 0, 0.25, 0.5 and 0.75 px
17#define BRAGI_SUBPIXELS 4
18
19#define BRAGI_HASH_SIZE 256
20
22{
23 stbtt_fontinfo info;
26};
27
28/**
29 * one glyph image in a face's cache.
30 */
31typedef struct bragi_glyph
32{
33 uint32_t key; // glyph index * BRAGI_SUBPIXELS + subpixel position
34 int16_t left; // from the pen to the mask's left edge
35 int16_t top; // from the baseline to the mask's top edge (negative: above)
38 uint8_t *mask; // width * height coverage bytes (NULL when empty)
40 struct bragi_glyph *newer; // the cache's use order (newest first)
43
45{
48 float scale; // font units to pixels
49 float size; // the pixel size it was made with
50 int32_t tracking; // added after each character, 1/64 pixels
51 int32_t ascent; // pixels
54
58 uint32_t budget; // bytes the cached masks may use
60};
61
62/**
63 * find the face (this one or a fallback) and the glyph for a character.
64 * with no face that has it, the face itself and glyph 0 (the "missing
65 * glyph" box).
66 */
67bragi_face_t *bragi_find_glyph(bragi_face_t *face, uint32_t codepoint, int *glyph);
68
69/**
70 * the advance of a glyph in 1/64 pixels.
71 */
72int32_t bragi_advance(const bragi_face_t *face, int glyph);
73
74/**
75 * the kerning between two glyphs of the same face, in 1/64 pixels.
76 */
77int32_t bragi_kerning(const bragi_face_t *face, int left, int right);
78
79/**
80 * a glyph image from the cache, made if it is not there.
81 * @param subpixel 0 to BRAGI_SUBPIXELS - 1.
82 * @return the glyph, or NULL when out of memory.
83 */
84const bragi_glyph_t *bragi_glyph(bragi_face_t *face, int glyph, int subpixel);
85
86/**
87 * blend a coverage mask in a colour over buf (in sRGB, as browsers do).
88 * @param color premultiplied; its alpha scales the coverage.
89 */
90void bragi_blend_mask(gfx_buffer_t *buf, int32_t x, int32_t y, const uint8_t *mask,
91 int32_t width, int32_t height, int32_t stride, gfx_color_t color);
bragi: TrueType text for libgfx buffers.
struct bragi_face bragi_face_t
Definition bragi.h:26
struct bragi_font bragi_font_t
Definition bragi.h:25
void bragi_blend_mask(gfx_buffer_t *buf, int32_t x, int32_t y, const uint8_t *mask, int32_t width, int32_t height, int32_t stride, gfx_color_t color)
blend a coverage mask in a colour over buf (in sRGB, as browsers do).
Definition bragi_cache.c:132
bragi_face_t * bragi_find_glyph(bragi_face_t *face, uint32_t codepoint, int *glyph)
find the face (this one or a fallback) and the glyph for a character.
Definition bragi_font.c:167
int32_t bragi_kerning(const bragi_face_t *face, int left, int right)
the kerning between two glyphs of the same face, in 1/64 pixels.
Definition bragi_font.c:192
int32_t bragi_advance(const bragi_face_t *face, int glyph)
the advance of a glyph in 1/64 pixels.
Definition bragi_font.c:184
#define BRAGI_HASH_SIZE
Definition bragi_internal.h:19
struct bragi_glyph bragi_glyph_t
one glyph image in a face's cache.
uint32_t gfx_color_t
a premultiplied ARGB colour, 0xAARRGGBB.
Definition gfx.h:30
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
unsigned short uint16_t
Definition stdint.h:13
int int32_t
Definition stdint.h:14
short int16_t
Definition stdint.h:12
Definition bragi_internal.h:45
bragi_glyph_t * oldest
Definition bragi_internal.h:57
float size
Definition bragi_internal.h:49
bragi_font_t * font
Definition bragi_internal.h:46
int32_t line_height
Definition bragi_internal.h:53
bragi_glyph_t * newest
Definition bragi_internal.h:56
bragi_glyph_t * hash[BRAGI_HASH_SIZE]
Definition bragi_internal.h:55
uint32_t budget
Definition bragi_internal.h:58
bragi_stats_t stats
Definition bragi_internal.h:59
float scale
Definition bragi_internal.h:48
int32_t tracking
Definition bragi_internal.h:50
bragi_face_t * fallback
Definition bragi_internal.h:47
int32_t ascent
Definition bragi_internal.h:51
int32_t descent
Definition bragi_internal.h:52
Definition bragi_internal.h:22
uint8_t * data
Definition bragi_internal.h:24
stbtt_fontinfo info
Definition bragi_internal.h:23
bool owns_data
Definition bragi_internal.h:25
one glyph image in a face's cache.
Definition bragi_internal.h:32
struct bragi_glyph * newer
Definition bragi_internal.h:40
int16_t top
Definition bragi_internal.h:35
uint16_t height
Definition bragi_internal.h:37
uint32_t key
Definition bragi_internal.h:33
struct bragi_glyph * hash_next
Definition bragi_internal.h:39
struct bragi_glyph * older
Definition bragi_internal.h:41
uint16_t width
Definition bragi_internal.h:36
int16_t left
Definition bragi_internal.h:34
uint8_t * mask
Definition bragi_internal.h:38
Definition bragi.h:178
Definition gfx.h:41