gpforge
An advanced bitmap font editor
Loading...
Searching...
No Matches
compose.c
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
/*
3
* Copyright (C) 2026 Cyril Hrubis <metan@ucw.cz>
4
*/
5
6
#include <stdlib.h>
7
#include <string.h>
8
9
#include "
edit.h
"
10
#include "
resolve.h
"
11
#include "
undo.h
"
12
#include "
compose.h
"
13
14
/*
15
* Generated from the unicode decompositions, do not hand edit the table.
16
*
17
* Each row is an accented letter, the letter it is an accented form of, the
18
* letter it is drawn from, the combining mark unicode decomposes it into, the
19
* spacing accent a font carries for typing, and where the accent sits. The
20
* letter and the one it is drawn from differ only for an accent above i or j,
21
* which is drawn on the dotless letter, so í is an accented form of i drawn
22
* from ı. The i and j themselves are not in here: unicode says they are
23
* atomic.
24
*/
25
const
struct
gpf_decomposition
gpf_decompositions[] = {
26
{0x00c0, 0x0041, 0x0041, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
27
{0x00c1, 0x0041, 0x0041, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
28
{0x00c2, 0x0041, 0x0041, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
29
{0x00c3, 0x0041, 0x0041, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
30
{0x00c4, 0x0041, 0x0041, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
31
{0x00c5, 0x0041, 0x0041, 0x030a, 0x02da,
GPF_ACCENT_ABOVE
},
32
{0x00c7, 0x0043, 0x0043, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
33
{0x00c8, 0x0045, 0x0045, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
34
{0x00c9, 0x0045, 0x0045, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
35
{0x00ca, 0x0045, 0x0045, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
36
{0x00cb, 0x0045, 0x0045, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
37
{0x00cc, 0x0049, 0x0049, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
38
{0x00cd, 0x0049, 0x0049, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
39
{0x00ce, 0x0049, 0x0049, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
40
{0x00cf, 0x0049, 0x0049, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
41
{0x00d1, 0x004e, 0x004e, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
42
{0x00d2, 0x004f, 0x004f, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
43
{0x00d3, 0x004f, 0x004f, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
44
{0x00d4, 0x004f, 0x004f, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
45
{0x00d5, 0x004f, 0x004f, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
46
{0x00d6, 0x004f, 0x004f, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
47
{0x00d9, 0x0055, 0x0055, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
48
{0x00da, 0x0055, 0x0055, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
49
{0x00db, 0x0055, 0x0055, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
50
{0x00dc, 0x0055, 0x0055, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
51
{0x00dd, 0x0059, 0x0059, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
52
{0x00e0, 0x0061, 0x0061, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
53
{0x00e1, 0x0061, 0x0061, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
54
{0x00e2, 0x0061, 0x0061, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
55
{0x00e3, 0x0061, 0x0061, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
56
{0x00e4, 0x0061, 0x0061, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
57
{0x00e5, 0x0061, 0x0061, 0x030a, 0x02da,
GPF_ACCENT_ABOVE
},
58
{0x00e7, 0x0063, 0x0063, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
59
{0x00e8, 0x0065, 0x0065, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
60
{0x00e9, 0x0065, 0x0065, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
61
{0x00ea, 0x0065, 0x0065, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
62
{0x00eb, 0x0065, 0x0065, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
63
{0x00ec, 0x0069, 0x0131, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
64
{0x00ed, 0x0069, 0x0131, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
65
{0x00ee, 0x0069, 0x0131, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
66
{0x00ef, 0x0069, 0x0131, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
67
{0x00f1, 0x006e, 0x006e, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
68
{0x00f2, 0x006f, 0x006f, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
69
{0x00f3, 0x006f, 0x006f, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
70
{0x00f4, 0x006f, 0x006f, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
71
{0x00f5, 0x006f, 0x006f, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
72
{0x00f6, 0x006f, 0x006f, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
73
{0x00f9, 0x0075, 0x0075, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
74
{0x00fa, 0x0075, 0x0075, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
75
{0x00fb, 0x0075, 0x0075, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
76
{0x00fc, 0x0075, 0x0075, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
77
{0x00fd, 0x0079, 0x0079, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
78
{0x00ff, 0x0079, 0x0079, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
79
{0x0100, 0x0041, 0x0041, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
80
{0x0101, 0x0061, 0x0061, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
81
{0x0102, 0x0041, 0x0041, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
82
{0x0103, 0x0061, 0x0061, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
83
{0x0104, 0x0041, 0x0041, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
84
{0x0105, 0x0061, 0x0061, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
85
{0x0106, 0x0043, 0x0043, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
86
{0x0107, 0x0063, 0x0063, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
87
{0x0108, 0x0043, 0x0043, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
88
{0x0109, 0x0063, 0x0063, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
89
{0x010a, 0x0043, 0x0043, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
90
{0x010b, 0x0063, 0x0063, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
91
{0x010c, 0x0043, 0x0043, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
92
{0x010d, 0x0063, 0x0063, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
93
{0x010e, 0x0044, 0x0044, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
94
{0x010f, 0x0064, 0x0064, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
95
{0x0112, 0x0045, 0x0045, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
96
{0x0113, 0x0065, 0x0065, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
97
{0x0114, 0x0045, 0x0045, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
98
{0x0115, 0x0065, 0x0065, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
99
{0x0116, 0x0045, 0x0045, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
100
{0x0117, 0x0065, 0x0065, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
101
{0x0118, 0x0045, 0x0045, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
102
{0x0119, 0x0065, 0x0065, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
103
{0x011a, 0x0045, 0x0045, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
104
{0x011b, 0x0065, 0x0065, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
105
{0x011c, 0x0047, 0x0047, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
106
{0x011d, 0x0067, 0x0067, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
107
{0x011e, 0x0047, 0x0047, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
108
{0x011f, 0x0067, 0x0067, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
109
{0x0120, 0x0047, 0x0047, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
110
{0x0121, 0x0067, 0x0067, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
111
{0x0122, 0x0047, 0x0047, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
112
{0x0123, 0x0067, 0x0067, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
113
{0x0124, 0x0048, 0x0048, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
114
{0x0125, 0x0068, 0x0068, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
115
{0x0128, 0x0049, 0x0049, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
116
{0x0129, 0x0069, 0x0131, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
117
{0x012a, 0x0049, 0x0049, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
118
{0x012b, 0x0069, 0x0131, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
119
{0x012c, 0x0049, 0x0049, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
120
{0x012d, 0x0069, 0x0131, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
121
{0x012e, 0x0049, 0x0049, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
122
{0x012f, 0x0069, 0x0069, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
123
{0x0130, 0x0049, 0x0049, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
124
{0x0134, 0x004a, 0x004a, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
125
{0x0135, 0x006a, 0x0237, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
126
{0x0136, 0x004b, 0x004b, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
127
{0x0137, 0x006b, 0x006b, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
128
{0x0139, 0x004c, 0x004c, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
129
{0x013a, 0x006c, 0x006c, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
130
{0x013b, 0x004c, 0x004c, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
131
{0x013c, 0x006c, 0x006c, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
132
{0x013d, 0x004c, 0x004c, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
133
{0x013e, 0x006c, 0x006c, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
134
{0x0143, 0x004e, 0x004e, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
135
{0x0144, 0x006e, 0x006e, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
136
{0x0145, 0x004e, 0x004e, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
137
{0x0146, 0x006e, 0x006e, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
138
{0x0147, 0x004e, 0x004e, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
139
{0x0148, 0x006e, 0x006e, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
140
{0x014c, 0x004f, 0x004f, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
141
{0x014d, 0x006f, 0x006f, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
142
{0x014e, 0x004f, 0x004f, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
143
{0x014f, 0x006f, 0x006f, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
144
{0x0150, 0x004f, 0x004f, 0x030b, 0x02dd,
GPF_ACCENT_ABOVE
},
145
{0x0151, 0x006f, 0x006f, 0x030b, 0x02dd,
GPF_ACCENT_ABOVE
},
146
{0x0154, 0x0052, 0x0052, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
147
{0x0155, 0x0072, 0x0072, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
148
{0x0156, 0x0052, 0x0052, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
149
{0x0157, 0x0072, 0x0072, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
150
{0x0158, 0x0052, 0x0052, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
151
{0x0159, 0x0072, 0x0072, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
152
{0x015a, 0x0053, 0x0053, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
153
{0x015b, 0x0073, 0x0073, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
154
{0x015c, 0x0053, 0x0053, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
155
{0x015d, 0x0073, 0x0073, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
156
{0x015e, 0x0053, 0x0053, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
157
{0x015f, 0x0073, 0x0073, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
158
{0x0160, 0x0053, 0x0053, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
159
{0x0161, 0x0073, 0x0073, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
160
{0x0162, 0x0054, 0x0054, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
161
{0x0163, 0x0074, 0x0074, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
162
{0x0164, 0x0054, 0x0054, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
163
{0x0165, 0x0074, 0x0074, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
164
{0x0168, 0x0055, 0x0055, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
165
{0x0169, 0x0075, 0x0075, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
166
{0x016a, 0x0055, 0x0055, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
167
{0x016b, 0x0075, 0x0075, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
168
{0x016c, 0x0055, 0x0055, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
169
{0x016d, 0x0075, 0x0075, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
170
{0x016e, 0x0055, 0x0055, 0x030a, 0x02da,
GPF_ACCENT_ABOVE
},
171
{0x016f, 0x0075, 0x0075, 0x030a, 0x02da,
GPF_ACCENT_ABOVE
},
172
{0x0170, 0x0055, 0x0055, 0x030b, 0x02dd,
GPF_ACCENT_ABOVE
},
173
{0x0171, 0x0075, 0x0075, 0x030b, 0x02dd,
GPF_ACCENT_ABOVE
},
174
{0x0172, 0x0055, 0x0055, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
175
{0x0173, 0x0075, 0x0075, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
176
{0x0174, 0x0057, 0x0057, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
177
{0x0175, 0x0077, 0x0077, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
178
{0x0176, 0x0059, 0x0059, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
179
{0x0177, 0x0079, 0x0079, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
180
{0x0178, 0x0059, 0x0059, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
181
{0x0179, 0x005a, 0x005a, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
182
{0x017a, 0x007a, 0x007a, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
183
{0x017b, 0x005a, 0x005a, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
184
{0x017c, 0x007a, 0x007a, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
185
{0x017d, 0x005a, 0x005a, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
186
{0x017e, 0x007a, 0x007a, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
187
{0x01cd, 0x0041, 0x0041, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
188
{0x01ce, 0x0061, 0x0061, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
189
{0x01cf, 0x0049, 0x0049, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
190
{0x01d0, 0x0069, 0x0131, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
191
{0x01d1, 0x004f, 0x004f, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
192
{0x01d2, 0x006f, 0x006f, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
193
{0x01d3, 0x0055, 0x0055, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
194
{0x01d4, 0x0075, 0x0075, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
195
{0x01e2, 0x00c6, 0x00c6, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
196
{0x01e3, 0x00e6, 0x00e6, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
197
{0x01e6, 0x0047, 0x0047, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
198
{0x01e7, 0x0067, 0x0067, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
199
{0x01e8, 0x004b, 0x004b, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
200
{0x01e9, 0x006b, 0x006b, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
201
{0x01ea, 0x004f, 0x004f, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
202
{0x01eb, 0x006f, 0x006f, 0x0328, 0x02db,
GPF_ACCENT_OGONEK
},
203
{0x01ee, 0x01b7, 0x01b7, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
204
{0x01ef, 0x0292, 0x0292, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
205
{0x01f0, 0x006a, 0x0237, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
206
{0x01f4, 0x0047, 0x0047, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
207
{0x01f5, 0x0067, 0x0067, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
208
{0x01f8, 0x004e, 0x004e, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
209
{0x01f9, 0x006e, 0x006e, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
210
{0x01fc, 0x00c6, 0x00c6, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
211
{0x01fd, 0x00e6, 0x00e6, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
212
{0x01fe, 0x00d8, 0x00d8, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
213
{0x01ff, 0x00f8, 0x00f8, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
214
{0x021e, 0x0048, 0x0048, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
215
{0x021f, 0x0068, 0x0068, 0x030c, 0x02c7,
GPF_ACCENT_ABOVE
},
216
{0x0226, 0x0041, 0x0041, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
217
{0x0227, 0x0061, 0x0061, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
218
{0x0228, 0x0045, 0x0045, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
219
{0x0229, 0x0065, 0x0065, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
220
{0x022e, 0x004f, 0x004f, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
221
{0x022f, 0x006f, 0x006f, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
222
{0x0232, 0x0059, 0x0059, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
223
{0x0233, 0x0079, 0x0079, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
224
{0x0386, 0x0391, 0x0391, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
225
{0x0388, 0x0395, 0x0395, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
226
{0x0389, 0x0397, 0x0397, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
227
{0x038a, 0x0399, 0x0399, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
228
{0x038c, 0x039f, 0x039f, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
229
{0x038e, 0x03a5, 0x03a5, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
230
{0x038f, 0x03a9, 0x03a9, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
231
{0x03aa, 0x0399, 0x0399, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
232
{0x03ab, 0x03a5, 0x03a5, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
233
{0x03ac, 0x03b1, 0x03b1, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
234
{0x03ad, 0x03b5, 0x03b5, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
235
{0x03ae, 0x03b7, 0x03b7, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
236
{0x03af, 0x03b9, 0x03b9, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
237
{0x03ca, 0x03b9, 0x03b9, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
238
{0x03cb, 0x03c5, 0x03c5, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
239
{0x03cc, 0x03bf, 0x03bf, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
240
{0x03cd, 0x03c5, 0x03c5, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
241
{0x03ce, 0x03c9, 0x03c9, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
242
{0x0400, 0x0415, 0x0415, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
243
{0x0401, 0x0415, 0x0415, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
244
{0x0403, 0x0413, 0x0413, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
245
{0x0407, 0x0406, 0x0406, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
246
{0x040c, 0x041a, 0x041a, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
247
{0x040d, 0x0418, 0x0418, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
248
{0x040e, 0x0423, 0x0423, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
249
{0x0419, 0x0418, 0x0418, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
250
{0x0439, 0x0438, 0x0438, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
251
{0x0450, 0x0435, 0x0435, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
252
{0x0451, 0x0435, 0x0435, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
253
{0x0453, 0x0433, 0x0433, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
254
{0x0457, 0x0456, 0x0456, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
255
{0x045c, 0x043a, 0x043a, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
256
{0x045d, 0x0438, 0x0438, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
257
{0x045e, 0x0443, 0x0443, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
258
{0x04c1, 0x0416, 0x0416, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
259
{0x04c2, 0x0436, 0x0436, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
260
{0x04d0, 0x0410, 0x0410, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
261
{0x04d1, 0x0430, 0x0430, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
262
{0x04d2, 0x0410, 0x0410, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
263
{0x04d3, 0x0430, 0x0430, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
264
{0x04d6, 0x0415, 0x0415, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
265
{0x04d7, 0x0435, 0x0435, 0x0306, 0x02d8,
GPF_ACCENT_ABOVE
},
266
{0x04da, 0x04d8, 0x04d8, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
267
{0x04db, 0x04d9, 0x04d9, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
268
{0x04dc, 0x0416, 0x0416, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
269
{0x04dd, 0x0436, 0x0436, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
270
{0x04de, 0x0417, 0x0417, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
271
{0x04df, 0x0437, 0x0437, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
272
{0x04e2, 0x0418, 0x0418, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
273
{0x04e3, 0x0438, 0x0438, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
274
{0x04e4, 0x0418, 0x0418, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
275
{0x04e5, 0x0438, 0x0438, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
276
{0x04e6, 0x041e, 0x041e, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
277
{0x04e7, 0x043e, 0x043e, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
278
{0x04ea, 0x04e8, 0x04e8, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
279
{0x04eb, 0x04e9, 0x04e9, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
280
{0x04ec, 0x042d, 0x042d, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
281
{0x04ed, 0x044d, 0x044d, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
282
{0x04ee, 0x0423, 0x0423, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
283
{0x04ef, 0x0443, 0x0443, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
284
{0x04f0, 0x0423, 0x0423, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
285
{0x04f1, 0x0443, 0x0443, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
286
{0x04f2, 0x0423, 0x0423, 0x030b, 0x02dd,
GPF_ACCENT_ABOVE
},
287
{0x04f3, 0x0443, 0x0443, 0x030b, 0x02dd,
GPF_ACCENT_ABOVE
},
288
{0x04f4, 0x0427, 0x0427, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
289
{0x04f5, 0x0447, 0x0447, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
290
{0x04f8, 0x042b, 0x042b, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
291
{0x04f9, 0x044b, 0x044b, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
292
{0x1e02, 0x0042, 0x0042, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
293
{0x1e03, 0x0062, 0x0062, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
294
{0x1e0a, 0x0044, 0x0044, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
295
{0x1e0b, 0x0064, 0x0064, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
296
{0x1e10, 0x0044, 0x0044, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
297
{0x1e11, 0x0064, 0x0064, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
298
{0x1e1e, 0x0046, 0x0046, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
299
{0x1e1f, 0x0066, 0x0066, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
300
{0x1e20, 0x0047, 0x0047, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
301
{0x1e21, 0x0067, 0x0067, 0x0304, 0x00af,
GPF_ACCENT_ABOVE
},
302
{0x1e22, 0x0048, 0x0048, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
303
{0x1e23, 0x0068, 0x0068, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
304
{0x1e26, 0x0048, 0x0048, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
305
{0x1e27, 0x0068, 0x0068, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
306
{0x1e28, 0x0048, 0x0048, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
307
{0x1e29, 0x0068, 0x0068, 0x0327, 0x00b8,
GPF_ACCENT_BELOW
},
308
{0x1e30, 0x004b, 0x004b, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
309
{0x1e31, 0x006b, 0x006b, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
310
{0x1e3e, 0x004d, 0x004d, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
311
{0x1e3f, 0x006d, 0x006d, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
312
{0x1e40, 0x004d, 0x004d, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
313
{0x1e41, 0x006d, 0x006d, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
314
{0x1e44, 0x004e, 0x004e, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
315
{0x1e45, 0x006e, 0x006e, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
316
{0x1e54, 0x0050, 0x0050, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
317
{0x1e55, 0x0070, 0x0070, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
318
{0x1e56, 0x0050, 0x0050, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
319
{0x1e57, 0x0070, 0x0070, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
320
{0x1e58, 0x0052, 0x0052, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
321
{0x1e59, 0x0072, 0x0072, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
322
{0x1e60, 0x0053, 0x0053, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
323
{0x1e61, 0x0073, 0x0073, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
324
{0x1e6a, 0x0054, 0x0054, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
325
{0x1e6b, 0x0074, 0x0074, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
326
{0x1e7c, 0x0056, 0x0056, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
327
{0x1e7d, 0x0076, 0x0076, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
328
{0x1e80, 0x0057, 0x0057, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
329
{0x1e81, 0x0077, 0x0077, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
330
{0x1e82, 0x0057, 0x0057, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
331
{0x1e83, 0x0077, 0x0077, 0x0301, 0x00b4,
GPF_ACCENT_ABOVE
},
332
{0x1e84, 0x0057, 0x0057, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
333
{0x1e85, 0x0077, 0x0077, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
334
{0x1e86, 0x0057, 0x0057, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
335
{0x1e87, 0x0077, 0x0077, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
336
{0x1e8a, 0x0058, 0x0058, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
337
{0x1e8b, 0x0078, 0x0078, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
338
{0x1e8c, 0x0058, 0x0058, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
339
{0x1e8d, 0x0078, 0x0078, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
340
{0x1e8e, 0x0059, 0x0059, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
341
{0x1e8f, 0x0079, 0x0079, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
342
{0x1e90, 0x005a, 0x005a, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
343
{0x1e91, 0x007a, 0x007a, 0x0302, 0x005e,
GPF_ACCENT_ABOVE
},
344
{0x1e97, 0x0074, 0x0074, 0x0308, 0x00a8,
GPF_ACCENT_ABOVE
},
345
{0x1e98, 0x0077, 0x0077, 0x030a, 0x02da,
GPF_ACCENT_ABOVE
},
346
{0x1e99, 0x0079, 0x0079, 0x030a, 0x02da,
GPF_ACCENT_ABOVE
},
347
{0x1e9b, 0x017f, 0x017f, 0x0307, 0x02d9,
GPF_ACCENT_ABOVE
},
348
{0x1ebc, 0x0045, 0x0045, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
349
{0x1ebd, 0x0065, 0x0065, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
350
{0x1ef2, 0x0059, 0x0059, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
351
{0x1ef3, 0x0079, 0x0079, 0x0300, 0x0060,
GPF_ACCENT_ABOVE
},
352
{0x1ef8, 0x0059, 0x0059, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
353
{0x1ef9, 0x0079, 0x0079, 0x0303, 0x007e,
GPF_ACCENT_ABOVE
},
354
{}
355
};
356
357
const
struct
gpf_decomposition
*
gpf_decompose
(uint32_t
code
)
358
{
359
unsigned
int
i;
360
361
for
(i = 0; gpf_decompositions[i].code; i++) {
362
if
(gpf_decompositions[i].
code
==
code
)
363
return
&gpf_decompositions[i];
364
365
if
(gpf_decompositions[i].
code
>
code
)
366
break
;
367
}
368
369
return
NULL;
370
}
371
372
unsigned
int
gpf_decompose_accented
(uint32_t base, uint32_t *codes,
373
unsigned
int
max)
374
{
375
unsigned
int
i, cnt = 0;
376
377
for
(i = 0; gpf_decompositions[i].code && cnt < max; i++) {
378
if
(gpf_decompositions[i].
base_code
!= base)
379
continue
;
380
381
codes[cnt++] = gpf_decompositions[i].code;
382
}
383
384
return
cnt;
385
}
386
387
/*
388
* Either name of the accent matches: a font carries the spacing accent far
389
* more often than the combining mark, and both are the same shape to the
390
* person drawing it.
391
*/
392
unsigned
int
gpf_decompose_by_accent
(uint32_t
accent
, uint32_t *codes,
393
unsigned
int
max)
394
{
395
unsigned
int
i, cnt = 0;
396
397
if
(!
accent
)
398
return
0;
399
400
for
(i = 0; gpf_decompositions[i].code && cnt < max; i++) {
401
if
(gpf_decompositions[i].
mark
!=
accent
&&
402
gpf_decompositions[i].
accent
!=
accent
)
403
continue
;
404
405
codes[cnt++] = gpf_decompositions[i].code;
406
}
407
408
return
cnt;
409
}
410
411
uint32_t
gpf_decompose_base
(uint32_t
code
)
412
{
413
const
struct
gpf_decomposition
*decomp =
gpf_decompose
(
code
);
414
415
return
decomp ? decomp->
base_code
:
code
;
416
}
417
418
void
gpf_accent_offset
(
const
struct
gpf_font
*font,
419
const
struct
gpf_glyph
*base,
420
const
struct
gpf_glyph
*
accent
,
421
enum
gpf_accent_place
place
,
int
*dx,
int
*dy)
422
{
423
int
base_mid = base->
bearing_x
+ (int)base->
width
/ 2;
424
int
accent_mid =
accent
->bearing_x + (int)
accent
->width / 2;
425
int
base_bottom = base->
bearing_y
- (int)base->
height
;
426
int
top, bottom;
427
428
*dx = base_mid - accent_mid;
429
430
switch
(
place
) {
431
case
GPF_ACCENT_ABOVE
:
432
/*
433
* One clear row between the letter and the accent, not the
434
* accent sitting straight on it. That is what the corpus
435
* draws: taking the accent off every accented letter of the
436
* ten unicode fonts and measuring where it sits, a blank row
437
* fits 824 of the 989 and touching fits 271. The letters
438
* drawn touching are in the smallest fonts, where there is no
439
* room for the row — which the clamp below takes care of.
440
*/
441
*dy = base->
bearing_y
+ 1 + (int)
accent
->height -
442
accent
->bearing_y;
443
break
;
444
case
GPF_ACCENT_BELOW
:
445
/* and below, its top edge on the base's bottom edge */
446
*dy = base_bottom -
accent
->bearing_y;
447
break
;
448
case
GPF_ACCENT_OGONEK
:
449
/* an ogonek hangs off the right hand side of the base */
450
*dx = base->
bearing_x
+ (int)base->
width
-
451
accent
->bearing_x - (
int
)
accent
->width;
452
*dy = base_bottom -
accent
->bearing_y;
453
break
;
454
}
455
456
if
(!font || !
accent
->height)
457
return
;
458
459
/*
460
* And then it is pushed back inside the box. A letter that reaches
461
* the ascent leaves nothing above it, and ink outside the box is ink
462
* in the line above or below — it has to give way, and the accent is
463
* what gives.
464
*/
465
top =
accent
->bearing_y + *dy;
466
bottom = top - (int)
accent
->height + 1;
467
468
if
(top > font->
meta
.
ascent
)
469
*dy -= top - font->
meta
.
ascent
;
470
471
if
(bottom < -font->meta.descent)
472
*dy += -font->
meta
.
descent
- bottom;
473
}
474
475
/*
476
* Paints the glyph ink into a buffer whose top left pixel is at the column
477
* left and at the height top above the baseline.
478
*/
479
static
void
paint(uint8_t *bits,
unsigned
int
w,
int
left,
int
top,
480
const
struct
gpf_glyph
*glyph,
int
dx,
int
dy)
481
{
482
unsigned
int
x, y;
483
int
ox = glyph->
bearing_x
+ dx - left;
484
int
oy = top - (glyph->
bearing_y
+ dy);
485
486
for
(y = 0; y < glyph->
height
; y++) {
487
for
(x = 0; x < glyph->
width
; x++) {
488
if
(glyph->
bits
[y * glyph->
width
+ x])
489
bits[(y + oy) * w + x + ox] = 1;
490
}
491
}
492
}
493
494
int
gpf_compose
(
struct
gpf_glyph
*dst,
const
struct
gpf_glyph
*base,
495
const
struct
gpf_glyph
*
accent
,
int
dx,
int
dy)
496
{
497
int
left, right, top, bottom;
498
unsigned
int
w, h;
499
uint8_t *bits;
500
int
ret;
501
502
dst->
kind
=
GPF_GLYPH_INK
;
503
dst->
has_advance
= 1;
504
dst->
has_bearing
= 1;
505
dst->
advance
= base->
advance
;
506
507
if
(!
accent
->width)
508
return
gpf_glyph_set_bits(dst, base->
bits
, base->
width
,
509
base->
height
, base->
bearing_x
,
510
base->
bearing_y
);
511
512
if
(!base->
width
) {
513
return
gpf_glyph_set_bits(dst,
accent
->
bits
,
accent
->width,
514
accent
->height,
515
accent
->bearing_x + dx,
516
accent
->bearing_y + dy);
517
}
518
519
left =
GPF_MIN
(base->
bearing_x
,
accent
->bearing_x + dx);
520
right =
GPF_MAX
(base->
bearing_x
+ (
int
)base->
width
,
521
accent
->bearing_x + dx + (
int
)
accent
->width);
522
top =
GPF_MAX
(base->
bearing_y
,
accent
->bearing_y + dy);
523
bottom =
GPF_MIN
(base->
bearing_y
- (
int
)base->
height
,
524
accent
->bearing_y + dy - (
int
)
accent
->height);
525
526
w = right - left;
527
h = top - bottom;
528
529
bits = calloc(1, (
size_t
)w * h);
530
if
(!bits)
531
return
1;
532
533
paint(bits, w, left, top, base, 0, 0);
534
paint(bits, w, left, top,
accent
, dx, dy);
535
536
ret = gpf_glyph_set_bits(dst, bits, w, h, left, top);
537
538
free(bits);
539
540
return
ret;
541
}
542
543
int
gpf_compose_remainder
(
const
struct
gpf_glyph
*glyph,
544
const
struct
gpf_glyph
*base,
struct
gpf_glyph
*rem)
545
{
546
int
left = 0, right = 0, top = 0, bottom = 0, found = 0;
547
unsigned
int
x, y, w, h;
548
uint8_t *bits;
549
int
ret;
550
551
if
(!glyph->
width
|| !base->
width
)
552
return
1;
553
554
/* the base has to be in there, or this is not that base with anything */
555
for
(y = 0; y < base->
height
; y++) {
556
for
(x = 0; x < base->
width
; x++) {
557
if
(!
gpf_glyph_pixel
(base, x, y))
558
continue
;
559
560
if
(!gpf_glyph_pixel_get(glyph, base->
bearing_x
+ (
int
)x,
561
base->
bearing_y
- (
int
)y))
562
return
1;
563
}
564
}
565
566
for
(y = 0; y < glyph->
height
; y++) {
567
for
(x = 0; x < glyph->
width
; x++) {
568
int
col = glyph->
bearing_x
+ (int)x;
569
int
height = glyph->
bearing_y
- (int)y;
570
571
if
(!
gpf_glyph_pixel
(glyph, x, y))
572
continue
;
573
574
if
(gpf_glyph_pixel_get(base, col, height))
575
continue
;
576
577
if
(!found) {
578
left = right = col;
579
top = bottom = height;
580
found = 1;
581
continue
;
582
}
583
584
left =
GPF_MIN
(left, col);
585
right =
GPF_MAX
(right, col);
586
top =
GPF_MAX
(top, height);
587
bottom =
GPF_MIN
(bottom, height);
588
}
589
}
590
591
if
(!found)
592
return
1;
593
594
w = right - left + 1;
595
h = top - bottom + 1;
596
597
bits = calloc(1, (
size_t
)w * h);
598
if
(!bits)
599
return
1;
600
601
for
(y = 0; y < h; y++) {
602
for
(x = 0; x < w; x++) {
603
int
col = left + (int)x, height = top - (
int
)y;
604
605
bits[y * w + x] = gpf_glyph_pixel_get(glyph, col, height) &&
606
!gpf_glyph_pixel_get(base, col, height);
607
}
608
}
609
610
rem->
kind
=
GPF_GLYPH_INK
;
611
rem->
has_advance
= 1;
612
rem->
has_bearing
= 1;
613
rem->
advance
= glyph->
advance
;
614
615
ret = gpf_glyph_set_bits(rem, bits, w, h, left, top);
616
617
free(bits);
618
619
return
ret;
620
}
621
622
/*
623
* The dot of an i or a j: the ink above the first blank row from the top.
624
* With no blank row the letter has no dot to take off, and it is left alone.
625
*/
626
static
int
remove_dot(
struct
gpf_glyph
*glyph)
627
{
628
unsigned
int
x, y, gap = 0;
629
uint8_t *bits;
630
int
ret;
631
632
for
(y = 1; y < glyph->
height
&& !gap; y++) {
633
for
(x = 0; x < glyph->
width
; x++) {
634
if
(
gpf_glyph_pixel
(glyph, x, y))
635
break
;
636
}
637
638
if
(x == glyph->
width
)
639
gap = y;
640
}
641
642
if
(!gap)
643
return
0;
644
645
bits = malloc((
size_t
)glyph->
width
* glyph->
height
);
646
if
(!bits)
647
return
1;
648
649
memcpy(bits, glyph->
bits
, (
size_t
)glyph->
width
* glyph->
height
);
650
memset(bits, 0, (
size_t
)gap * glyph->
width
);
651
652
ret = gpf_glyph_set_bits(glyph, bits, glyph->
width
, glyph->
height
,
653
glyph->
bearing_x
, glyph->
bearing_y
);
654
655
free(bits);
656
657
return
ret;
658
}
659
660
int
gpf_draw_base
(
struct
gpf_font
*font,
enum
gpf_variant_id
id
,
661
const
struct
gpf_decomposition
*decomp,
662
struct
gpf_resolved
*res)
663
{
664
if
(!gpf_resolve(font,
id
, decomp->
draw_base
, res))
665
return
0;
666
667
if
(decomp->
draw_base
== decomp->
base_code
)
668
return
1;
669
670
/* few fonts have ı and fewer ȷ, the letter with its dot taken off is */
671
if
(gpf_resolve(font,
id
, decomp->
base_code
, res))
672
return
1;
673
674
if
(remove_dot(&res->
glyph
)) {
675
gpf_resolved_clear(res);
676
return
1;
677
}
678
679
return
0;
680
}
681
682
/*
683
* The accent as this font draws it, taken off a letter that carries it: the
684
* caron is `Č` minus `C`. Any letter with the same accent will do, and the
685
* first one that gives a clean subtraction is used — the base has to sit
686
* inside it pixel for pixel, so a letter whose accent touches its base is
687
* rejected rather than mangled.
688
*/
689
static
int
accent_from_letter(
struct
gpf_font
*font,
enum
gpf_variant_id
id
,
690
const
struct
gpf_decomposition
*decomp,
691
struct
gpf_glyph
*out)
692
{
693
unsigned
int
i;
694
695
for
(i = 0; gpf_decompositions[i].code; i++) {
696
struct
gpf_resolved
letter = {0}, base = {0};
697
int
ret;
698
699
if
(gpf_decompositions[i].mark != decomp->
mark
)
700
continue
;
701
702
if
(gpf_decompositions[i].code == decomp->
code
)
703
continue
;
704
705
if
(
gpf_resolve
(font,
id
, gpf_decompositions[i].code, &letter))
706
continue
;
707
708
if
(gpf_draw_base(font,
id
, &gpf_decompositions[i], &base)) {
709
gpf_resolved_clear
(&letter);
710
continue
;
711
}
712
713
ret = gpf_compose_remainder(&letter.
glyph
, &base.glyph, out);
714
715
gpf_resolved_clear
(&letter);
716
gpf_resolved_clear
(&base);
717
718
if
(!ret)
719
return
0;
720
}
721
722
return
1;
723
}
724
725
int
gpf_accent_ink(
struct
gpf_font
*font,
enum
gpf_variant_id
id
,
726
const
struct
gpf_decomposition
*decomp,
727
struct
gpf_glyph
*out)
728
{
729
uint32_t codes[2] = {decomp->
mark
, decomp->
accent
};
730
unsigned
int
i;
731
732
memset(out, 0,
sizeof
(*out));
733
734
if
(!accent_from_letter(font,
id
, decomp, out))
735
return
0;
736
737
/* no letter to take it from: the mark, and then the spacing accent */
738
for
(i = 0; i < 2; i++) {
739
struct
gpf_resolved
res = {0};
740
741
if
(!codes[i] ||
gpf_resolve
(font,
id
, codes[i], &res))
742
continue
;
743
744
*out = res.
glyph
;
745
746
/* the ink is handed over, not copied */
747
res.
glyph
.
bits
= NULL;
748
749
gpf_resolved_clear
(&res);
750
751
return
0;
752
}
753
754
return
1;
755
}
compose.h
Accented letters: the decomposition table and accent composition.
gpf_compose_remainder
int gpf_compose_remainder(const struct gpf_glyph *glyph, const struct gpf_glyph *base, struct gpf_glyph *rem)
Subtracts the base ink from a glyph.
Definition
compose.c:543
gpf_decompose_accented
unsigned int gpf_decompose_accented(uint32_t base_code, uint32_t *codes, unsigned int max)
Returns all accented forms of a letter.
Definition
compose.c:372
gpf_draw_base
int gpf_draw_base(struct gpf_font *font, enum gpf_variant_id id, const struct gpf_decomposition *decomp, struct gpf_resolved *res)
The letter a new accented letter is drawn from.
Definition
compose.c:660
gpf_decompose_base
uint32_t gpf_decompose_base(uint32_t code)
Looks up the base letter of an accented letter.
Definition
compose.c:411
gpf_compose
int gpf_compose(struct gpf_glyph *dst, const struct gpf_glyph *base, const struct gpf_glyph *accent, int dx, int dy)
Composes the base ink with the accent ink.
Definition
compose.c:494
gpf_decompose_by_accent
unsigned int gpf_decompose_by_accent(uint32_t accent, uint32_t *codes, unsigned int max)
Looks up all glyphs for a given accent.
Definition
compose.c:392
gpf_accent_offset
void gpf_accent_offset(const struct gpf_font *font, const struct gpf_glyph *base, const struct gpf_glyph *accent, enum gpf_accent_place place, int *dx, int *dy)
The default offset for an accent on a base.
Definition
compose.c:418
gpf_decompose
const struct gpf_decomposition * gpf_decompose(uint32_t code)
Looks up the decomposition of an accented letter.
Definition
compose.c:357
gpf_accent_place
gpf_accent_place
Accent location in the glyph rectangle.
Definition
compose.h:28
GPF_ACCENT_ABOVE
@ GPF_ACCENT_ABOVE
Centred over the ink, one blank row above it.
Definition
compose.h:30
GPF_ACCENT_BELOW
@ GPF_ACCENT_BELOW
Centred under the ink, right below it.
Definition
compose.h:32
GPF_ACCENT_OGONEK
@ GPF_ACCENT_OGONEK
Right aligned with the ink, right below it.
Definition
compose.h:34
edit.h
Glyph editing.
gpf_glyph_pixel
static int gpf_glyph_pixel(const struct gpf_glyph *self, unsigned int x, unsigned int y)
Returns a glyph ink pixel.
Definition
font.h:623
GPF_MAX
#define GPF_MAX(a, b)
Returns the larger of two values, evaluates them twice.
Definition
font.h:29
gpf_variant_id
gpf_variant_id
Font face variant.
Definition
font.h:34
GPF_GLYPH_INK
@ GPF_GLYPH_INK
Glyph with ink.
Definition
font.h:62
GPF_MIN
#define GPF_MIN(a, b)
Returns the smaller of two values, evaluates them twice.
Definition
font.h:27
resolve.h
The glyph variant lattice.
gpf_resolved_clear
void gpf_resolved_clear(struct gpf_resolved *self)
Clears the resolved glyph.
Definition
resolve.c:30
gpf_resolve
int gpf_resolve(struct gpf_font *font, enum gpf_variant_id id, uint32_t code, struct gpf_resolved *res)
Resolves a glyph variant metric and ink.
Definition
resolve.c:521
gpf_decomposition
A glyph decomposition.
Definition
compose.h:40
gpf_decomposition::draw_base
uint32_t draw_base
What a new one is drawn from.
Definition
compose.h:51
gpf_decomposition::place
enum gpf_accent_place place
Where the accent is placed in the glyph rectangle.
Definition
compose.h:69
gpf_decomposition::accent
uint32_t accent
The spacing accent, the one that gets typed.
Definition
compose.h:67
gpf_decomposition::mark
uint32_t mark
The combining mark unicode decomposes the letter into.
Definition
compose.h:60
gpf_decomposition::base_code
uint32_t base_code
The letter this is an accented form of, e.g. 'i' for 'í'.
Definition
compose.h:44
gpf_decomposition::code
uint32_t code
A unicode code point of the accented letter.
Definition
compose.h:42
gpf_family_meta::descent
int descent
Font descent.
Definition
font.h:241
gpf_family_meta::ascent
int ascent
Font ascent.
Definition
font.h:239
gpf_font
A font family.
Definition
font.h:274
gpf_font::meta
struct gpf_family_meta meta
Font meta data.
Definition
font.h:276
gpf_glyph
A glyph.
Definition
font.h:80
gpf_glyph::kind
uint8_t kind
enum gpf_glyph_kind
Definition
font.h:88
gpf_glyph::bits
uint8_t * bits
Glyph ink.
Definition
font.h:145
gpf_glyph::bearing_y
int bearing_y
Glyph bearing y.
Definition
font.h:128
gpf_glyph::has_advance
uint8_t has_advance
The entry carries an advance.
Definition
font.h:97
gpf_glyph::has_bearing
uint8_t has_bearing
The entry carries both bearings, see has_advance.
Definition
font.h:99
gpf_glyph::height
unsigned int height
Glyph ink height.
Definition
font.h:137
gpf_glyph::width
unsigned int width
Glyph ink width.
Definition
font.h:133
gpf_glyph::advance
int advance
Glyph advance.
Definition
font.h:116
gpf_glyph::bearing_x
int bearing_x
Glyph bearing x.
Definition
font.h:122
gpf_resolved
A resolved glyph and where it was drawn from.
Definition
resolve.h:36
gpf_resolved::glyph
struct gpf_glyph glyph
Freshly allocated glyph with copied/generated ink.
Definition
resolve.h:42
undo.h
The undo journal.
compose.c
Generated by
1.15.0