-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnk_font.h
More file actions
74 lines (64 loc) · 2.02 KB
/
Copy pathnk_font.h
File metadata and controls
74 lines (64 loc) · 2.02 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
#ifndef FONT_H
#define FONT_H
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#include "nuklear.h"
#include "glad/glad.h"
#include "stb_rect_pack.h"
#include "stb_truetype.h"
#ifdef NKF_DEBUG
#include "stb_image_write.h"
#endif // NKF_DEBUG
/**
* Options
* =======
* NKF_CHARS_PER_GROUP Number of characters in a group (default 128).
* NKF_ATLAS_WIDTH Fixed width of atlas (default 512).
* NKF_MAX_GROUP_HEIGHT Maximum height of a group (default 512).
* NKF_DEBUG If defined, store font atlas as "atlas.png".
*
* Characters may not show correctly if there isn't enough space to store a
* group.
*
* If you have this issue, either reduce the font size, reduce oversampling,
* increase NKF_ATLAS_WIDTH, increase NKF_MAX_GROUP_HEIGHT or decrease
* NKF_CHARS_PER_GROUP.
*/
#ifndef NKF_CHARS_PER_GROUP
#define NKF_CHARS_PER_GROUP 128
#endif // NKF_CHARS_PER_GROUP
#ifndef NKF_ATLAS_WIDTH
#define NKF_ATLAS_WIDTH 512
#endif // NKF_ATLAS_WIDTH
#ifndef NKF_MAX_GROUP_HEIGHT
#define NKF_MAX_GROUP_HEIGHT 512
#endif // NKF_MAX_GROUP_HEIGHT
#define NK_FONT_NUM_GROUPS (150000 / NKF_CHARS_PER_GROUP) + NKF_CHARS_PER_GROUP
struct nkf_font_group {
stbtt_packedchar chars[NKF_CHARS_PER_GROUP];
unsigned y_begin;
};
struct nkf_font {
struct nk_user_font handle;
struct nkf_font_group *groups[NK_FONT_NUM_GROUPS];
unsigned tex_height;
unsigned char *font_buf;
unsigned oversample_x;
unsigned oversample_y;
int ascent;
struct nk_context *ctx;
};
void nkf_init_font(
struct nkf_font *dst,
struct nk_context *ctx,
const char *font_filename,
float px_height,
unsigned oversample_x,
unsigned oversample_y
);
static void nkf_init_group(struct nkf_font *font, unsigned atlas_idx);
void nkf_clean_font(struct nkf_font *font);
void nkf_clear_atlas(struct nkf_font *font);
static float nkf_get_text_width(nk_handle handle, float height, const char *text, int len);
static void nkf_query_font(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint);
#endif // FONT_H