ttext-common.h - ltkx - GUI toolkit for X11 (WIP)
HTML git clone git://lumidify.org/ltkx.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
ttext-common.h (4307B)
---
1 /*
2 * This file is part of the Lumidify ToolKit (LTK)
3 * Copyright (c) 2017, 2018, 2020 lumidify <nobody@lumidify.org>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef _TEXT_COMMON_H_
25 #define _TEXT_COMMON_H_
26
27 /*
28 Requires the following includes:
29 <X11/Xlib.h>, <X11/Xutil.h>, "stb_truetype.h",
30 "khash.h", <harfbuzz/hb.h>, <fribidi.h>,
31 <fontconfig/fontconfig.h>
32 */
33
34 typedef struct {
35 stbtt_fontinfo info;
36 hb_font_t *hb;
37 uint16_t id;
38 unsigned int refs;
39 } LtkFont;
40
41 /* Contains general info on glyphs that doesn't change regardless of the context */
42 typedef struct _LtkGlyphInfo {
43 unsigned int id;
44 unsigned char *alphamap;
45 unsigned int w;
46 unsigned int h;
47 unsigned int xoff; /* x offset from origin to top left corner of glyph */
48 unsigned int yoff; /* y offset from origin to top left corner of glyph */
49 unsigned int refs;
50 /* FIXME: does refs need to be long? It could cause problems if a
51 program tries to cache/"keep alive" a lot of pages of text. */
52 } LtkGlyphInfo;
53
54 /* Contains glyph info specific to one run of text */
55 typedef struct _LtkGlyph {
56 LtkGlyphInfo *info;
57 int x_offset; /* additional x offset given by harfbuzz */
58 int y_offset; /* additional y offset given by harfbuzz */
59 int x_advance;
60 int y_advance;
61 int x_abs;
62 int y_abs;
63 uint32_t cluster; /* index of char in original text - from harfbuzz */
64 struct _LtkGlyph *next;
65 } LtkGlyph;
66
67 /* Hash definitions */
68 /* glyph id -> glyph info struct */
69 KHASH_MAP_INIT_INT(glyphinfo, LtkGlyphInfo*)
70 /* font path, size -> glyph cache hash */
71 KHASH_MAP_INIT_INT(glyphcache, khash_t(glyphinfo)*)
72 /* font path -> font id */
73 KHASH_MAP_INIT_STR(fontid, uint16_t)
74 /* font id -> font struct */
75 KHASH_MAP_INIT_INT(fontstruct, LtkFont*)
76
77 typedef struct LtkTextManager {
78 khash_t(fontid) *font_paths;
79 khash_t(fontstruct) *font_cache;
80 khash_t(glyphcache) *glyph_cache;
81 FcPattern *fcpattern;
82 uint16_t default_font;
83 uint16_t font_id_cur;
84 } LtkTextManager;
85
86 uint32_t u8_nextmemchar(const char *s, size_t *i);
87
88 size_t u8_strlen(const char *s);
89
90 size_t u8_wc_toutf8(char *dest, uint32_t ch);
91
92 LtkTextManager *ltk_init_text(char *font_name);
93
94 void ltk_destroy_text_manager(LtkTextManager *tm);
95
96 LtkGlyphInfo *ltk_create_glyph_info(LtkFont *font, unsigned int id, float scale);
97
98 void ltk_destroy_glyph_info(LtkGlyphInfo *gi);
99
100 LtkGlyphInfo *ltk_get_glyph_info(LtkFont *font, unsigned int id, float scale, khash_t(glyphinfo) *cache);
101
102 khint_t ltk_create_glyph_cache(LtkTextManager *tm, uint16_t font_id, uint16_t font_size);
103
104 void ltk_destroy_glyph_cache(khash_t(glyphinfo) *cache);
105
106 void ltk_load_default_font(LtkTextManager *tm, char *name);
107
108 LtkFont *ltk_create_font(char *path, uint16_t id);
109
110 void ltk_destroy_font(LtkFont *font);
111
112 /* FIXME: need to figure out how exactly the whole font system is going to work, especially with default fonts, etc. */
113 uint16_t ltk_load_font(LtkTextManager *tm, char *path);
114
115 uint16_t ltk_get_font(LtkTextManager *tm, char *path);
116
117 void ltk_destroy_glyph(LtkGlyph *glyph, khash_t(glyphinfo) *cache);
118
119 /*
120 XImage *ltk_render_text_line(LtkTextLine *tl, Display *dpy, Window window, GC gc, Colormap colormap, XColor fg, XColor bg);
121
122 void ltk_render_text_segment(LtkTextSegment *ts, unsigned int start_x, unsigned int start_y, XImage *img, XColor fg);
123 */
124
125 #endif /* _TEXT_COMMON_H_ */