OLD | NEW |
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 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 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 free (old); | 123 free (old); |
124 } | 124 } |
125 gr_face_destroy (f->grface); | 125 gr_face_destroy (f->grface); |
126 } | 126 } |
127 | 127 |
128 static void _hb_gr_font_data_destroy (void *data) | 128 static void _hb_gr_font_data_destroy (void *data) |
129 { | 129 { |
130 hb_gr_font_data_t *f = (hb_gr_font_data_t *) data; | 130 hb_gr_font_data_t *f = (hb_gr_font_data_t *) data; |
131 | 131 |
132 gr_font_destroy (f->grfont); | 132 gr_font_destroy (f->grfont); |
| 133 free (f); |
133 } | 134 } |
134 | 135 |
135 static hb_user_data_key_t hb_gr_data_key; | 136 static hb_user_data_key_t hb_gr_data_key; |
136 | 137 |
137 static hb_gr_face_data_t * | 138 static hb_gr_face_data_t * |
138 _hb_gr_face_get_data (hb_face_t *face) | 139 _hb_gr_face_get_data (hb_face_t *face) |
139 { | 140 { |
140 hb_gr_face_data_t *data = (hb_gr_face_data_t *) hb_face_get_user_data (face, &
hb_gr_data_key); | 141 hb_gr_face_data_t *data = (hb_gr_face_data_t *) hb_face_get_user_data (face, &
hb_gr_data_key); |
141 if (likely (data)) return data; | 142 if (likely (data)) return data; |
142 | 143 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 return data; | 206 return data; |
206 else | 207 else |
207 return &_hb_gr_font_data_nil; | 208 return &_hb_gr_font_data_nil; |
208 } | 209 } |
209 | 210 |
210 return data; | 211 return data; |
211 } | 212 } |
212 | 213 |
213 | 214 |
214 hb_bool_t | 215 hb_bool_t |
215 hb_graphite_shape (hb_font_t *font, | 216 _hb_graphite_shape (hb_font_t *font, |
216 hb_buffer_t *buffer, | 217 hb_buffer_t *buffer, |
217 const hb_feature_t *features, | 218 const hb_feature_t *features, |
218 » » unsigned int num_features, | 219 » » unsigned int num_features) |
219 » » const char * const *shaper_options) | |
220 { | 220 { |
221 | 221 |
222 buffer->guess_properties (); | 222 buffer->guess_properties (); |
223 | 223 |
| 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 |
224 hb_gr_font_data_t *data = _hb_gr_font_get_data (font); | 227 hb_gr_font_data_t *data = _hb_gr_font_get_data (font); |
225 if (!data->grface) return FALSE; | 228 if (!data->grface) return FALSE; |
226 | 229 |
227 unsigned int charlen; | 230 unsigned int charlen; |
228 hb_glyph_info_t *bufferi = hb_buffer_get_glyph_infos (buffer, &charlen); | 231 hb_glyph_info_t *bufferi = hb_buffer_get_glyph_infos (buffer, &charlen); |
229 | 232 |
230 int success = 0; | 233 int success = 0; |
231 | 234 |
232 if (!charlen) return TRUE; | 235 if (!charlen) return TRUE; |
233 | 236 |
234 const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); | 237 const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); |
235 const char *lang_end = strchr (lang, '-'); | 238 const char *lang_end = strchr (lang, '-'); |
236 int lang_len = lang_end ? lang_end - lang : -1; | 239 int lang_len = lang_end ? lang_end - lang : -1; |
237 gr_feature_val *feats = gr_face_featureval_for_lang (data->grface, lang ? hb_t
ag_from_string (lang, lang_len) : 0); | 240 gr_feature_val *feats = gr_face_featureval_for_lang (data->grface, lang ? hb_t
ag_from_string (lang, lang_len) : 0); |
238 | 241 |
239 while (num_features--) | 242 while (num_features--) |
240 { | 243 { |
241 const gr_feature_ref *fref = gr_face_find_fref (data->grface, features->tag)
; | 244 const gr_feature_ref *fref = gr_face_find_fref (data->grface, features->tag)
; |
242 if (fref) | 245 if (fref) |
243 gr_fref_set_feature_value (fref, features->value, feats); | 246 gr_fref_set_feature_value (fref, features->value, feats); |
244 features++; | 247 features++; |
245 } | 248 } |
246 | 249 |
247 unsigned short *gids = NULL; | 250 hb_codepoint_t *gids = NULL, *pg; |
248 hb_gr_cluster_t *clusters = NULL; | 251 hb_gr_cluster_t *clusters = NULL; |
249 gr_segment *seg = NULL; | 252 gr_segment *seg = NULL; |
250 uint32_t *text = NULL; | 253 uint32_t *text = NULL; |
251 unsigned short *pg; | |
252 const gr_slot *is; | 254 const gr_slot *is; |
253 unsigned int ci = 0, ic = 0; | 255 unsigned int ci = 0, ic = 0; |
254 float curradvx = 0., curradvy = 0.; | 256 float curradvx = 0., curradvy = 0.; |
255 unsigned int glyphlen = 0; | 257 unsigned int glyphlen = 0; |
256 unsigned int *p; | 258 unsigned int *p; |
257 | 259 |
258 text = (uint32_t *) malloc ((charlen + 1) * sizeof (uint32_t)); | 260 text = (uint32_t *) malloc ((charlen + 1) * sizeof (uint32_t)); |
259 if (!text) goto dieout; | 261 if (!text) goto dieout; |
260 | 262 |
261 p = text; | 263 p = text; |
262 for (unsigned int i = 0; i < charlen; ++i) | 264 for (unsigned int i = 0; i < charlen; ++i) |
263 *p++ = bufferi++->codepoint; | 265 *p++ = bufferi++->codepoint; |
264 *p = 0; | 266 *p = 0; |
265 | 267 |
266 hb_tag_t script_tag[2]; | 268 hb_tag_t script_tag[2]; |
267 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script
_tag[1]); | 269 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script
_tag[1]); |
268 | 270 |
269 seg = gr_make_seg (data->grfont, data->grface, | 271 seg = gr_make_seg (data->grfont, data->grface, |
270 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1
], | 272 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1
], |
271 feats, | 273 feats, |
272 gr_utf32, text, charlen, | 274 gr_utf32, text, charlen, |
273 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ?
1 : 0)); | 275 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ?
1 : 0)); |
274 if (!seg) goto dieout; | 276 if (!seg) goto dieout; |
275 | 277 |
276 glyphlen = gr_seg_n_slots (seg); | 278 glyphlen = gr_seg_n_slots (seg); |
277 clusters = (hb_gr_cluster_t *) calloc (charlen, sizeof (hb_gr_cluster_t)); | 279 clusters = (hb_gr_cluster_t *) calloc (charlen, sizeof (hb_gr_cluster_t)); |
278 if (!glyphlen || !clusters) goto dieout; | 280 if (!glyphlen || !clusters) goto dieout; |
279 | 281 |
280 gids = (uint16_t *) malloc (glyphlen * sizeof (uint16_t)); | 282 gids = (hb_codepoint_t *) malloc (glyphlen * sizeof (hb_codepoint_t)); |
281 if (!gids) goto dieout; | 283 if (!gids) goto dieout; |
282 | 284 |
283 pg = gids; | 285 pg = gids; |
284 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i
s), ic++) | 286 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i
s), ic++) |
285 { | 287 { |
286 unsigned int before = gr_slot_before (is); | 288 unsigned int before = gr_slot_before (is); |
287 unsigned int after = gr_slot_after (is); | 289 unsigned int after = gr_slot_after (is); |
288 *pg = gr_slot_gid (is); | 290 *pg = gr_slot_gid (is); |
289 pg++; | 291 pg++; |
290 while (clusters[ci].base_char > before && ci) | 292 while (clusters[ci].base_char > before && ci) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 341 |
340 success = 1; | 342 success = 1; |
341 | 343 |
342 dieout: | 344 dieout: |
343 if (gids) free (gids); | 345 if (gids) free (gids); |
344 if (clusters) free (clusters); | 346 if (clusters) free (clusters); |
345 if (seg) gr_seg_destroy (seg); | 347 if (seg) gr_seg_destroy (seg); |
346 if (text) free (text); | 348 if (text) free (text); |
347 return success; | 349 return success; |
348 } | 350 } |
OLD | NEW |