forked from racket/racket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoretext.patch
More file actions
215 lines (192 loc) · 6.99 KB
/
coretext.patch
File metadata and controls
215 lines (192 loc) · 6.99 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
diff -r -u pango-1.29.5-orig/modules/basic/basic-coretext.c pango-1.29.5/modules/basic/basic-coretext.c
--- pango-1.29.5-orig/modules/basic/basic-coretext.c 2011-08-15 18:11:08.000000000 -0700
+++ pango-1.29.5/modules/basic/basic-coretext.c 2012-05-17 13:04:39.000000000 -0700
@@ -54,18 +54,26 @@
PangoGlyphString *glyphs,
int i,
int offset,
- PangoGlyph glyph)
+ PangoGlyph glyph,
+ const CGSize *adv)
{
PangoRectangle logical_rect;
+ if (!glyph) { glyph = PANGO_GET_UNKNOWN_GLYPH(glyph); }
+
glyphs->glyphs[i].glyph = glyph;
glyphs->glyphs[i].geometry.x_offset = 0;
glyphs->glyphs[i].geometry.y_offset = 0;
glyphs->log_clusters[i] = offset;
- pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect);
- glyphs->glyphs[i].geometry.width = logical_rect.width;
+ if (adv) {
+ /* by using the advances array, we get kerning */
+ glyphs->glyphs[i].geometry.width = adv->width * PANGO_SCALE;
+ } else {
+ pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect);
+ glyphs->glyphs[i].geometry.width = logical_rect.width;
+ }
}
static void
@@ -87,15 +95,17 @@
CFArrayRef runs;
CTRunRef run;
CTRunStatus run_status;
- CFIndex i, glyph_count;
+ CFIndex i, glyph_count, num_runs, run_index, run_offset, run_glyph_count;
const CGGlyph *cgglyphs;
+ const CGSize *cgadvs;
+ int free_cgglyphs = 0, free_cgadvs = 0;
CFTypeRef keys[] = {
- (CFTypeRef) kCTFontAttributeName
+ (CFTypeRef) kCTFontAttributeName
};
CFTypeRef values[] = {
- pango_core_text_font_get_ctfont (cfont)
+ pango_core_text_font_get_ctfont (cfont)
};
attributes = CFDictionaryCreate (kCFAllocatorDefault,
@@ -110,8 +120,6 @@
cstr = CFStringCreateWithCString (kCFAllocatorDefault, copy,
kCFStringEncodingUTF8);
- g_free (copy);
-
attstr = CFAttributedStringCreate (kCFAllocatorDefault,
cstr,
attributes);
@@ -120,13 +128,22 @@
runs = CTLineGetGlyphRuns (line);
- /* Since Pango divides things into runs already, we assume there is
- * only a single run in this line.
+ /* Since Pango divides things into runs already, we might assume there is
+ * only a single run in this line. However, unknown glyphs lead to
+ * separate runs.
*/
- run = CFArrayGetValueAtIndex (runs, 0);
- run_status = CTRunGetStatus (run);
- glyph_count = CTRunGetGlyphCount (run);
- cgglyphs = CTRunGetGlyphsPtr (run);
+ num_runs = CFArrayGetCount (runs);
+ glyph_count = 0;
+ for (i = 0; i < num_runs; i++) {
+ run = CFArrayGetValueAtIndex (runs, i);
+ glyph_count += CTRunGetGlyphCount (run);
+ }
+
+ g_free (copy);
+
+ run_offset = 0;
+ run_index = 0;
+ run_glyph_count = 0;
p = text;
pango_glyph_string_set_size (glyphs, glyph_count);
@@ -135,10 +152,41 @@
for (i = 0; i < glyph_count; i++)
{
- CFIndex real_i, prev_i;
+ CFIndex real_i, prev_i, run_real_i;
gunichar wc;
gunichar mirrored_ch;
+ if (i - run_offset >= run_glyph_count) {
+ run_offset = i;
+ run = CFArrayGetValueAtIndex (runs, run_index++);
+ run_glyph_count = CTRunGetGlyphCount (run);
+ run_status = CTRunGetStatus (run);
+
+ if (free_cgglyphs) {
+ free((void*)cgglyphs);
+ free_cgglyphs = 0;
+ }
+ cgglyphs = CTRunGetGlyphsPtr (run);
+ if (!cgglyphs) {
+ CFRange range = { 0, 0 };
+ cgglyphs = (CGGlyph *)malloc(run_glyph_count * sizeof(CGGlyph));
+ free_cgglyphs = 1;
+ CTRunGetGlyphs (run, range, (CGGlyph *)cgglyphs);
+ }
+
+ if (free_cgadvs) {
+ free((void*)cgadvs);
+ free_cgadvs = 0;
+ }
+ cgadvs = CTRunGetAdvancesPtr (run);
+ if (!cgadvs) {
+ CFRange range = { 0, 0 };
+ cgadvs = (CGSize *)malloc(run_glyph_count * sizeof(CGSize));
+ free_cgadvs = 1;
+ CTRunGetAdvances (run, range, (CGSize *)cgadvs);
+ }
+ }
+
wc = g_utf8_get_char (p);
if (analysis->level % 2)
@@ -147,11 +195,13 @@
if (run_status & kCTRunStatusRightToLeft)
{
+ run_real_i = run_glyph_count - (i - run_offset) - 1;
real_i = glyph_count - i - 1;
prev_i = real_i + 1;
}
else
{
+ run_real_i = i - run_offset;
real_i = i;
prev_i = real_i - 1;
}
@@ -161,7 +211,7 @@
if (pango_is_zero_width (wc))
{
- set_glyph (font, glyphs, real_i, p - text, PANGO_GLYPH_EMPTY);
+ set_glyph (font, glyphs, real_i, p - text, PANGO_GLYPH_EMPTY, NULL);
}
else
{
@@ -171,7 +221,7 @@
if (result != PANGO_COVERAGE_NONE)
{
- set_glyph (font, glyphs, real_i, p - text, cgglyphs[real_i]);
+ set_glyph (font, glyphs, real_i, p - text, cgglyphs[run_real_i], cgadvs + run_real_i);
if (g_unichar_type (wc) == G_UNICODE_NON_SPACING_MARK)
{
@@ -196,13 +246,18 @@
else
{
set_glyph (font, glyphs, real_i, p - text,
- PANGO_GET_UNKNOWN_GLYPH (wc));
+ PANGO_GET_UNKNOWN_GLYPH (wc), NULL);
}
}
p = g_utf8_next_char (p);
}
+ if (free_cgglyphs)
+ free((void *)cgglyphs);
+ if (free_cgadvs)
+ free((void *)cgadvs);
+
CFRelease (line);
CFRelease (attstr);
CFRelease (cstr);
diff -r -u pango-1.29.5-orig/pango/pangocairo-coretextfont.c pango-1.29.5/pango/pangocairo-coretextfont.c
--- pango-1.29.5-orig/pango/pangocairo-coretextfont.c 2011-08-15 18:11:08.000000000 -0700
+++ pango-1.29.5/pango/pangocairo-coretextfont.c 2012-05-17 14:14:02.000000000 -0700
@@ -147,6 +147,12 @@
metrics->strikethrough_position = metrics->ascent / 3;
metrics->strikethrough_thickness = CTFontGetUnderlineThickness (ctfont) * PANGO_SCALE;
+ metrics->underline_position = -metrics->underline_position;
+ pango_quantize_line_geometry (&metrics->underline_thickness,
+ &metrics->underline_position);
+ metrics->underline_position = -(metrics->underline_position
+ + metrics->underline_thickness);
+
layout = pango_layout_new (context);
font_desc = pango_font_describe_with_absolute_size ((PangoFont *) font);
pango_layout_set_font_description (layout, font_desc);
diff -r -u pango-1.29.5-orig/pango/pangocoretext-fontmap.c pango-1.29.5/pango/pangocoretext-fontmap.c
--- pango-1.29.5-orig/pango/pangocoretext-fontmap.c 2011-11-22 11:02:35.000000000 -0800
+++ pango-1.29.5/pango/pangocoretext-fontmap.c 2013-02-02 06:13:34.000000000 -0800
@@ -941,6 +941,8 @@
CTFontDescriptorRef desc = CFArrayGetValueAtIndex (ctfaces, i);
str = CTFontDescriptorCopyAttribute (desc, kCTFontFamilyNameAttribute);
+ if (!str) continue;
+
buffer = gchar_from_cf_string (str);
family_name = g_utf8_casefold (buffer, -1);