Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: third_party/harfbuzz-ng/src/hb-graphite2.cc

Issue 10915172: harfbuzz-ng roll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-graphite2.h ('k') | third_party/harfbuzz-ng/src/hb-icu.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright © 2011 Martin Hosken 2 * Copyright © 2011 Martin Hosken
3 * Copyright © 2011 SIL International 3 * Copyright © 2011 SIL International
4 * Copyright © 2011 Google, Inc. 4 * Copyright © 2011,2012 Google, Inc.
5 * 5 *
6 * This is part of HarfBuzz, a text shaping library. 6 * This is part of HarfBuzz, a text shaping library.
7 * 7 *
8 * Permission is hereby granted, without written agreement and without 8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this 9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the 10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in 11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software. 12 * all copies of this software.
13 * 13 *
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE. 18 * DAMAGE.
19 * 19 *
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * 25 *
26 * Google Author(s): Behdad Esfahbod 26 * Google Author(s): Behdad Esfahbod
27 */ 27 */
28 28
29 #include "hb-private.hh" 29 #define HB_SHAPER graphite2
30 30 #define hb_graphite2_shaper_font_data_t gr_font
31 #include "hb-graphite2.h" 31 #include "hb-shaper-impl-private.hh"
32
33 #include "hb-buffer-private.hh"
34 #include "hb-font-private.hh"
35 #include "hb-ot-tag.h"
36 32
37 #include <graphite2/Font.h> 33 #include <graphite2/Font.h>
38 #include <graphite2/Segment.h> 34 #include <graphite2/Segment.h>
39 35
36 #include "hb-graphite2.h"
40 37
41 struct hb_gr_cluster_t { 38 #include "hb-ot-tag.h"
42 unsigned int base_char; 39
43 unsigned int num_chars; 40
44 unsigned int base_glyph; 41 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, face)
45 unsigned int num_glyphs; 42 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, font)
43
44
45 /*
46 * shaper face data
47 */
48
49 typedef struct hb_graphite2_tablelist_t {
50 struct hb_graphite2_tablelist_t *next;
51 hb_blob_t *blob;
52 unsigned int tag;
53 } hb_graphite2_tablelist_t;
54
55 struct hb_graphite2_shaper_face_data_t {
56 hb_face_t *face;
57 gr_face *grface;
58 hb_graphite2_tablelist_t *tlist;
46 }; 59 };
47 60
61 static const void *hb_graphite2_get_table (const void *data, unsigned int tag, s ize_t *len)
62 {
63 hb_graphite2_shaper_face_data_t *face_data = (hb_graphite2_shaper_face_data_t *) data;
64 hb_graphite2_tablelist_t *tlist = face_data->tlist;
48 65
49 typedef struct hb_gr_tablelist_t { 66 hb_blob_t *blob = NULL;
50 hb_blob_t *blob;
51 struct hb_gr_tablelist_t *next;
52 unsigned int tag;
53 } hb_gr_tablelist_t;
54 67
55 static struct hb_gr_face_data_t { 68 for (hb_graphite2_tablelist_t *p = tlist; p; p = p->next)
56 hb_face_t *face; 69 if (p->tag == tag) {
57 gr_face *grface; 70 blob = p->blob;
58 hb_gr_tablelist_t *tlist; 71 break;
59 } _hb_gr_face_data_nil = {NULL, NULL}; 72 }
60 73
61 static struct hb_gr_font_data_t { 74 if (unlikely (!blob))
62 gr_font *grfont; 75 {
63 gr_face *grface; 76 blob = face_data->face->reference_table (tag);
64 } _hb_gr_font_data_nil = {NULL, NULL};
65 77
66 78 hb_graphite2_tablelist_t *p = (hb_graphite2_tablelist_t *) calloc (1, sizeof (hb_graphite2_tablelist_t));
67 static const void *hb_gr_get_table (const void *data, unsigned int tag, size_t * len) 79 if (unlikely (!p)) {
68 {
69 hb_gr_tablelist_t *pl = NULL, *p;
70 hb_gr_face_data_t *face = (hb_gr_face_data_t *) data;
71 hb_gr_tablelist_t *tlist = face->tlist;
72
73 for (p = tlist; p; p = p->next)
74 if (p->tag == tag ) {
75 unsigned int tlen;
76 const char *d = hb_blob_get_data (p->blob, &tlen);
77 *len = tlen;
78 return d;
79 } else
80 pl = p;
81
82 if (!face->face)
83 return NULL;
84 hb_blob_t *blob = hb_face_reference_table (face->face, tag);
85
86 if (!pl || pl->blob)
87 {
88 p = (hb_gr_tablelist_t *) malloc (sizeof (hb_gr_tablelist_t));
89 if (!p) {
90 hb_blob_destroy (blob); 80 hb_blob_destroy (blob);
91 return NULL; 81 return NULL;
92 } 82 }
93 p->next = NULL; 83 p->blob = blob;
94 if (pl) 84 p->tag = tag;
95 pl->next = p; 85
96 else 86 /* TODO Not thread-safe, but fairly harmless.
97 face->tlist = p; 87 * We can do the double-chcked pointer cmpexch thing here. */
98 pl = p; 88 p->next = face_data->tlist;
89 face_data->tlist = p;
99 } 90 }
100 pl->blob = blob;
101 pl->tag = tag;
102 91
103 unsigned int tlen; 92 unsigned int tlen;
104 const char *d = hb_blob_get_data (blob, &tlen); 93 const char *d = hb_blob_get_data (blob, &tlen);
105 *len = tlen; 94 *len = tlen;
106 return d; 95 return d;
107 } 96 }
108 97
109 static float hb_gr_get_advance (const void *hb_font, unsigned short gid) 98 hb_graphite2_shaper_face_data_t *
99 _hb_graphite2_shaper_face_data_create (hb_face_t *face)
110 { 100 {
111 return hb_font_get_glyph_h_advance ((hb_font_t *) hb_font, gid); 101 hb_blob_t *silf_blob = face->reference_table (HB_GRAPHITE2_TAG_SILF);
112 } 102 /* Umm, we just reference the table to check whether it exists.
113 103 * Maybe add better API for this? */
114 static void _hb_gr_face_data_destroy (void *data)
115 {
116 hb_gr_face_data_t *f = (hb_gr_face_data_t *) data;
117 hb_gr_tablelist_t *tlist = f->tlist;
118 while (tlist)
119 {
120 hb_gr_tablelist_t *old = tlist;
121 hb_blob_destroy (tlist->blob);
122 tlist = tlist->next;
123 free (old);
124 }
125 gr_face_destroy (f->grface);
126 }
127
128 static void _hb_gr_font_data_destroy (void *data)
129 {
130 hb_gr_font_data_t *f = (hb_gr_font_data_t *) data;
131
132 gr_font_destroy (f->grfont);
133 free (f);
134 }
135
136 static hb_user_data_key_t hb_gr_data_key;
137
138 static hb_gr_face_data_t *
139 _hb_gr_face_get_data (hb_face_t *face)
140 {
141 hb_gr_face_data_t *data = (hb_gr_face_data_t *) hb_face_get_user_data (face, & hb_gr_data_key);
142 if (likely (data)) return data;
143
144 data = (hb_gr_face_data_t *) calloc (1, sizeof (hb_gr_face_data_t));
145 if (unlikely (!data))
146 return &_hb_gr_face_data_nil;
147
148
149 hb_blob_t *silf_blob = hb_face_reference_table (face, HB_GRAPHITE_TAG_Silf);
150 if (!hb_blob_get_length (silf_blob)) 104 if (!hb_blob_get_length (silf_blob))
151 { 105 {
152 hb_blob_destroy (silf_blob); 106 hb_blob_destroy (silf_blob);
153 return &_hb_gr_face_data_nil; 107 return NULL;
154 } 108 }
109 hb_blob_destroy (silf_blob);
110
111 hb_graphite2_shaper_face_data_t *data = (hb_graphite2_shaper_face_data_t *) ca lloc (1, sizeof (hb_graphite2_shaper_face_data_t));
112 if (unlikely (!data))
113 hb_blob_destroy (silf_blob);
155 114
156 data->face = face; 115 data->face = face;
157 data->grface = gr_make_face (data, &hb_gr_get_table, gr_face_default); 116 data->grface = gr_make_face (data, &hb_graphite2_get_table, gr_face_default);
158 117
159 118 if (unlikely (!data->grface)) {
160 if (unlikely (!hb_face_set_user_data (face, &hb_gr_data_key, data, 119 free (data);
161 » » » » » (hb_destroy_func_t) _hb_gr_face_data_des troy, 120 return NULL;
162 » » » » » false)))
163 {
164 _hb_gr_face_data_destroy (data);
165 data = (hb_gr_face_data_t *) hb_face_get_user_data (face, &hb_gr_data_key);
166 if (data)
167 return data;
168 else
169 return &_hb_gr_face_data_nil;
170 } 121 }
171 122
172 return data; 123 return data;
173 } 124 }
174 125
175 static hb_gr_font_data_t * 126 void
176 _hb_gr_font_get_data (hb_font_t *font) 127 _hb_graphite2_shaper_face_data_destroy (hb_graphite2_shaper_face_data_t *data)
177 { 128 {
178 hb_gr_font_data_t *data = (hb_gr_font_data_t *) hb_font_get_user_data (font, & hb_gr_data_key); 129 hb_graphite2_tablelist_t *tlist = data->tlist;
179 if (likely (data)) return data;
180 130
181 data = (hb_gr_font_data_t *) calloc (1, sizeof (hb_gr_font_data_t)); 131 while (tlist)
182 if (unlikely (!data))
183 return &_hb_gr_font_data_nil;
184
185
186 hb_blob_t *silf_blob = hb_face_reference_table (font->face, HB_GRAPHITE_TAG_Si lf);
187 if (!hb_blob_get_length (silf_blob))
188 { 132 {
189 hb_blob_destroy (silf_blob); 133 hb_graphite2_tablelist_t *old = tlist;
190 return &_hb_gr_font_data_nil; 134 hb_blob_destroy (tlist->blob);
135 tlist = tlist->next;
136 free (old);
191 } 137 }
192 138
193 data->grface = _hb_gr_face_get_data (font->face)->grface; 139 gr_face_destroy (data->grface);
194 int scale;
195 hb_font_get_scale (font, &scale, NULL);
196 data->grfont = gr_make_font_with_advance_fn (scale, font, &hb_gr_get_advance, data->grface);
197 140
198 141 free (data);
199 if (unlikely (!hb_font_set_user_data (font, &hb_gr_data_key, data,
200 » » » » » (hb_destroy_func_t) _hb_gr_font_data_des troy,
201 » » » » » false)))
202 {
203 _hb_gr_font_data_destroy (data);
204 data = (hb_gr_font_data_t *) hb_font_get_user_data (font, &hb_gr_data_key);
205 if (data)
206 return data;
207 else
208 return &_hb_gr_font_data_nil;
209 }
210
211 return data;
212 } 142 }
213 143
214 144
145 /*
146 * shaper font data
147 */
148
149 static float hb_graphite2_get_advance (const void *hb_font, unsigned short gid)
150 {
151 return ((hb_font_t *) hb_font)->get_glyph_h_advance (gid);
152 }
153
154 hb_graphite2_shaper_font_data_t *
155 _hb_graphite2_shaper_font_data_create (hb_font_t *font)
156 {
157 if (unlikely (!hb_graphite2_shaper_face_data_ensure (font->face))) return NULL ;
158
159 hb_face_t *face = font->face;
160 hb_graphite2_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
161
162 return gr_make_font_with_advance_fn (font->x_scale, font, &hb_graphite2_get_ad vance, face_data->grface);
163 }
164
165 void
166 _hb_graphite2_shaper_font_data_destroy (hb_graphite2_shaper_font_data_t *data)
167 {
168 gr_font_destroy (data);
169 }
170
171
172 /*
173 * shaper shape_plan data
174 */
175
176 struct hb_graphite2_shaper_shape_plan_data_t {};
177
178 hb_graphite2_shaper_shape_plan_data_t *
179 _hb_graphite2_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_U NUSED,
180 const hb_feature_t *user_features H B_UNUSED,
181 unsigned int num_user_featur es HB_UNUSED)
182 {
183 return (hb_graphite2_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
184 }
185
186 void
187 _hb_graphite2_shaper_shape_plan_data_destroy (hb_graphite2_shaper_shape_plan_dat a_t *data HB_UNUSED)
188 {
189 }
190
191
192 /*
193 * shaper
194 */
195
196 struct hb_graphite2_cluster_t {
197 unsigned int base_char;
198 unsigned int num_chars;
199 unsigned int base_glyph;
200 unsigned int num_glyphs;
201 };
202
215 hb_bool_t 203 hb_bool_t
216 _hb_graphite_shape (hb_font_t *font, 204 _hb_graphite2_shape (hb_shape_plan_t *shape_plan,
217 » » hb_buffer_t *buffer, 205 » » hb_font_t *font,
218 » » const hb_feature_t *features, 206 » » hb_buffer_t *buffer,
219 » » unsigned int num_features) 207 » » const hb_feature_t *features,
208 » » unsigned int num_features)
220 { 209 {
221 210 hb_face_t *face = font->face;
222 buffer->guess_properties (); 211 gr_face *grface = HB_SHAPER_DATA_GET (face)->grface;
223 212 gr_font *grfont = HB_SHAPER_DATA_GET (font);
224 /* XXX We do a hell of a lot of stuff just to figure out this font
225 * is not graphite! Shouldn't do. */
226
227 hb_gr_font_data_t *data = _hb_gr_font_get_data (font);
228 if (!data->grface) return false;
229
230 unsigned int charlen;
231 hb_glyph_info_t *bufferi = hb_buffer_get_glyph_infos (buffer, &charlen);
232
233 int success = 0;
234
235 if (!charlen) return true;
236 213
237 const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); 214 const char *lang = hb_language_to_string (hb_buffer_get_language (buffer));
238 const char *lang_end = strchr (lang, '-'); 215 const char *lang_end = strchr (lang, '-');
239 int lang_len = lang_end ? lang_end - lang : -1; 216 int lang_len = lang_end ? lang_end - lang : -1;
240 gr_feature_val *feats = gr_face_featureval_for_lang (data->grface, lang ? hb_t ag_from_string (lang, lang_len) : 0); 217 gr_feature_val *feats = gr_face_featureval_for_lang (grface, lang ? hb_tag_fro m_string (lang, lang_len) : 0);
241 218
242 while (num_features--) 219 while (num_features--)
243 { 220 {
244 const gr_feature_ref *fref = gr_face_find_fref (data->grface, features->tag) ; 221 const gr_feature_ref *fref = gr_face_find_fref (grface, features->tag);
245 if (fref) 222 if (fref)
246 gr_fref_set_feature_value (fref, features->value, feats); 223 gr_fref_set_feature_value (fref, features->value, feats);
247 features++; 224 features++;
248 } 225 }
249 226
250 hb_codepoint_t *gids = NULL, *pg;
251 hb_gr_cluster_t *clusters = NULL;
252 gr_segment *seg = NULL; 227 gr_segment *seg = NULL;
253 uint32_t *text = NULL;
254 const gr_slot *is; 228 const gr_slot *is;
255 unsigned int ci = 0, ic = 0; 229 unsigned int ci = 0, ic = 0;
256 float curradvx = 0., curradvy = 0.; 230 float curradvx = 0., curradvy = 0.;
257 unsigned int glyphlen = 0;
258 unsigned int *p;
259 231
260 text = (uint32_t *) malloc ((charlen + 1) * sizeof (uint32_t)); 232 unsigned int scratch_size;
261 if (!text) goto dieout; 233 char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size);
262 234
263 p = text; 235 #define ALLOCATE_ARRAY(Type, name, len) \
264 for (unsigned int i = 0; i < charlen; ++i) 236 Type *name = (Type *) scratch; \
265 *p++ = bufferi++->codepoint; 237 scratch += (len) * sizeof ((name)[0]); \
266 *p = 0; 238 scratch_size -= (len) * sizeof ((name)[0]);
239
240 ALLOCATE_ARRAY (uint32_t, chars, buffer->len);
241
242 for (unsigned int i = 0; i < buffer->len; ++i)
243 chars[i] = buffer->info[i].codepoint;
267 244
268 hb_tag_t script_tag[2]; 245 hb_tag_t script_tag[2];
269 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script _tag[1]); 246 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script _tag[1]);
270 247
271 seg = gr_make_seg (data->grfont, data->grface, 248 seg = gr_make_seg (grfont, grface,
272 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1 ], 249 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1 ],
273 feats, 250 feats,
274 » » gr_utf32, text, charlen, 251 » » gr_utf32, chars, buffer->len,
275 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ? 1 : 0)); 252 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ? 1 : 0));
276 if (!seg) goto dieout;
277 253
278 glyphlen = gr_seg_n_slots (seg); 254 if (unlikely (!seg)) {
279 clusters = (hb_gr_cluster_t *) calloc (charlen, sizeof (hb_gr_cluster_t)); 255 if (feats) gr_featureval_destroy (feats);
280 if (!glyphlen || !clusters) goto dieout; 256 return false;
257 }
281 258
282 gids = (hb_codepoint_t *) malloc (glyphlen * sizeof (hb_codepoint_t)); 259 unsigned int glyph_count = gr_seg_n_slots (seg);
283 if (!gids) goto dieout; 260 if (unlikely (!glyph_count)) {
261 if (feats) gr_featureval_destroy (feats);
262 gr_seg_destroy (seg);
263 return false;
264 }
284 265
285 pg = gids; 266 scratch = (char *) buffer->get_scratch_buffer (&scratch_size);
267 while ((sizeof (hb_graphite2_cluster_t) * buffer->len +
268 » sizeof (hb_codepoint_t) * glyph_count) > scratch_size)
269 {
270 buffer->ensure (buffer->allocated * 2);
271 if (unlikely (buffer->in_error)) {
272 if (feats) gr_featureval_destroy (feats);
273 gr_seg_destroy (seg);
274 return false;
275 }
276 scratch = (char *) buffer->get_scratch_buffer (&scratch_size);
277 }
278
279 ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len);
280 ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count);
281
282 memset (clusters, 0, sizeof (clusters[0]) * buffer->len);
283
284 hb_codepoint_t *pg = gids;
286 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i s), ic++) 285 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i s), ic++)
287 { 286 {
288 unsigned int before = gr_slot_before (is); 287 unsigned int before = gr_slot_before (is);
289 unsigned int after = gr_slot_after (is); 288 unsigned int after = gr_slot_after (is);
290 *pg = gr_slot_gid (is); 289 *pg = gr_slot_gid (is);
291 pg++; 290 pg++;
292 while (clusters[ci].base_char > before && ci) 291 while (clusters[ci].base_char > before && ci)
293 { 292 {
294 clusters[ci-1].num_chars += clusters[ci].num_chars; 293 clusters[ci-1].num_chars += clusters[ci].num_chars;
295 clusters[ci-1].num_glyphs += clusters[ci].num_glyphs; 294 clusters[ci-1].num_glyphs += clusters[ci].num_glyphs;
296 ci--; 295 ci--;
297 } 296 }
298 297
299 if (gr_slot_can_insert_before (is) && clusters[ci].num_chars && before >= cl usters[ci].base_char + clusters[ci].num_chars) 298 if (gr_slot_can_insert_before (is) && clusters[ci].num_chars && before >= cl usters[ci].base_char + clusters[ci].num_chars)
300 { 299 {
301 hb_gr_cluster_t *c = clusters + ci + 1; 300 hb_graphite2_cluster_t *c = clusters + ci + 1;
302 c->base_char = clusters[ci].base_char + clusters[ci].num_chars; 301 c->base_char = clusters[ci].base_char + clusters[ci].num_chars;
303 c->num_chars = before - c->base_char; 302 c->num_chars = before - c->base_char;
304 c->base_glyph = ic; 303 c->base_glyph = ic;
305 c->num_glyphs = 0; 304 c->num_glyphs = 0;
306 ci++; 305 ci++;
307 } 306 }
308 clusters[ci].num_glyphs++; 307 clusters[ci].num_glyphs++;
309 308
310 if (clusters[ci].base_char + clusters[ci].num_chars < after + 1) 309 if (clusters[ci].base_char + clusters[ci].num_chars < after + 1)
311 clusters[ci].num_chars = after + 1 - clusters[ci].base_char; 310 clusters[ci].num_chars = after + 1 - clusters[ci].base_char;
312 } 311 }
313 ci++; 312 ci++;
314 313
315 buffer->clear_output (); 314 buffer->clear_output ();
316 for (unsigned int i = 0; i < ci; ++i) 315 for (unsigned int i = 0; i < ci; ++i)
317 buffer->replace_glyphs (clusters[i].num_chars, clusters[i].num_glyphs, gids + clusters[i].base_glyph); 316 buffer->replace_glyphs (clusters[i].num_chars, clusters[i].num_glyphs, gids + clusters[i].base_glyph);
318 buffer->swap_buffers (); 317 buffer->swap_buffers ();
319 318
319 if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
320 curradvx = gr_seg_advance_X(seg);
321
320 hb_glyph_position_t *pPos; 322 hb_glyph_position_t *pPos;
321 for (pPos = hb_buffer_get_glyph_positions (buffer, NULL), is = gr_seg_first_sl ot (seg); 323 for (pPos = hb_buffer_get_glyph_positions (buffer, NULL), is = gr_seg_first_sl ot (seg);
322 is; pPos++, is = gr_slot_next_in_segment (is)) 324 is; pPos++, is = gr_slot_next_in_segment (is))
323 { 325 {
324 pPos->x_offset = gr_slot_origin_X(is) - curradvx; 326 pPos->x_offset = gr_slot_origin_X (is) - curradvx;
325 pPos->y_offset = gr_slot_origin_Y(is) - curradvy; 327 pPos->y_offset = gr_slot_origin_Y (is) - curradvy;
326 pPos->x_advance = gr_slot_advance_X(is, data->grface, data->grfont); 328 pPos->x_advance = gr_slot_advance_X (is, grface, grfont);
327 pPos->y_advance = gr_slot_advance_Y(is, data->grface, data->grfont); 329 pPos->y_advance = gr_slot_advance_Y (is, grface, grfont);
328 // if (pPos->x_advance < 0 && gr_slot_attached_to(is)) 330 if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
329 // pPos->x_advance = 0; 331 curradvx -= pPos->x_advance;
330 curradvx += pPos->x_advance; 332 pPos->x_offset = gr_slot_origin_X (is) - curradvx;
333 if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
334 curradvx += pPos->x_advance;
335 pPos->y_offset = gr_slot_origin_Y (is) - curradvy;
331 curradvy += pPos->y_advance; 336 curradvy += pPos->y_advance;
332 } 337 }
333 pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx; 338 if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
339 pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx;
334 340
335 /* TODO(behdad): 341 if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
336 * This shaper is badly broken with RTL text. It returns glyphs 342 hb_buffer_reverse_clusters (buffer);
337 * in the logical order!
338 */
339 // if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
340 // hb_buffer_reverse (buffer);
341 343
342 success = 1; 344 if (feats) gr_featureval_destroy (feats);
345 gr_seg_destroy (seg);
343 346
344 dieout: 347 return true;
345 if (gids) free (gids);
346 if (clusters) free (clusters);
347 if (seg) gr_seg_destroy (seg);
348 if (text) free (text);
349 return success;
350 } 348 }
OLDNEW
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-graphite2.h ('k') | third_party/harfbuzz-ng/src/hb-icu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698