text_buffer.h - ltkx - GUI toolkit for X11 (old)
HTML git clone git://lumidify.org/ltkx.git (fast, but not encrypted)
HTML git clone https://lumidify.org/ltkx.git (encrypted, but very slow)
HTML git clone git://4kcetb7mo7hj6grozzybxtotsub5bempzo4lirzc3437amof2c2impyd.onion/ltkx.git (over tor)
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
text_buffer.h (3766B)
---
1 /*
2 * This file is part of the Lumidify ToolKit (LTK)
3 * Copyright (c) 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_BUFFER_H_
25 #define _TEXT_BUFFER_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>, "text_common.h"
32 */
33
34 /* Note: hb_script_t and FriBidiLevel are really just uint32_t's, but
35 I'm not sure if I should rely on that, so they're separate here */
36 LTK_ARRAY_INIT_DECL(uint32, uint32_t)
37 LTK_ARRAY_INIT_DECL(script, hb_script_t)
38 LTK_ARRAY_INIT_DECL(level, FriBidiLevel)
39 LTK_ARRAY_INIT_DECL(int, int)
40
41 struct ltk_text_run {
42 LtkGlyph *glyphs;
43 unsigned int num_glyphs;
44 struct ltk_text_run *next;
45 struct ltk_text_run *last;
46 size_t start_index;
47 size_t len;
48 int start_x;
49 int start_y;
50 int w;
51 LtkFont *font;
52 uint16_t font_id;
53 uint16_t font_size;
54 hb_script_t script;
55 hb_direction_t dir;
56 };
57
58 struct ltk_soft_line {
59 size_t glyph_index;
60 size_t len;
61 int w;
62 struct ltk_text_run *run;
63 struct ltk_array_int *glyph_pos;
64 struct ltk_array_uint32 *glyph_clusters;
65 };
66
67 LTK_ARRAY_INIT_DECL(line, struct ltk_soft_line *)
68
69 struct ltk_text_line {
70 struct ltk_array_uint32 *log_buf; /* buffer of the logical text */
71 struct ltk_array_script *scripts;
72 struct ltk_array_uint32 *vis_buf; /* buffer of visual text */
73 struct ltk_array_int *log2vis;
74 struct ltk_array_int *vis2log;
75 struct ltk_array_level *bidi_levels;
76 struct ltk_array_line *soft_lines;
77 struct ltk_text_run *first_run; /* first node in the linked list of runs */
78 struct ltk_text_run *last_run; /* last node in the linked list of runs */
79 struct ltk_text_line *next; /* next text line in the buffer */
80 hb_direction_t dir; /* overall paragraph direction */
81 size_t len;
82 uint16_t font_size;
83 int w;
84 int h;
85 int w_wrapped;
86 int h_wrapped;
87 };
88
89 struct ltk_text_line_list {
90 struct ltk_text_line *tl;
91 XImage *img;
92 struct ltk_text_line_list *next;
93 struct ltk_text_line_list *last;
94 };
95
96 struct ltk_text_buffer {
97 struct ltk_text_line_list *head;
98 size_t cursor_pos;
99 };
100
101 void ltk_soft_line_destroy(struct ltk_soft_line *sl);
102 XImage *ltk_text_line_render(struct ltk_text_line *tl,
103 Display *dpy, Window window, GC gc, Colormap colormap, XColor fg, XColor bg);
104 uint32_t ltk_soft_line_get_index_from_pos(int x, struct ltk_text_line *tl, struct ltk_soft_line *sl, int *found_pos);
105 void ltk_text_line_insert_utf32(struct ltk_text_line *tl, size_t index, uint32_t *text, size_t len);
106 void ltk_text_line_insert_utf8(struct ltk_text_line *tl, size_t index, char *text);
107 struct ltk_text_line *ltk_text_line_create(uint16_t font_size);
108 void ltk_text_line_destroy(struct ltk_text_line *tl);
109
110 #endif /* _TEXT_BUFFER_H_ */