src/hb-font.cc | 9 - src/hb-graphite2.cc | 271 +++++++++++++++++------------------ src/hb-graphite2.h | 2 src/hb-ot-shape-normalize-private.hh | 2 src/hb-shaper-list.hh | 2 util/options.cc | 2 util/options.hh | 2 7 files changed, 141 insertions(+), 149 deletions(-)
New commits: commit 030ac5022e8a43b9329c26e72527bafc582ef44b Author: Behdad Esfahbod <[email protected]> Date: Tue Aug 7 13:01:12 2012 -0400 Remove enum trailing comma ...again. diff --git a/src/hb-ot-shape-normalize-private.hh b/src/hb-ot-shape-normalize-private.hh index 4c89a8f..f222c07 100644 --- a/src/hb-ot-shape-normalize-private.hh +++ b/src/hb-ot-shape-normalize-private.hh @@ -38,7 +38,7 @@ enum hb_ot_shape_normalization_mode_t { HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS, /* never composes base-to-base */ HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL, /* including base-to-base composition */ - HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT = HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS, + HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT = HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS }; HB_INTERNAL void _hb_ot_shape_normalize (hb_font_t *font, commit 368b4e7649f9bc8c6bebf7c7ff03c9b9ec425a25 Author: Behdad Esfahbod <[email protected]> Date: Mon Aug 6 23:06:04 2012 -0400 Minor diff --git a/src/hb-font.cc b/src/hb-font.cc index f0683e4..409b9e8 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -200,7 +200,6 @@ hb_font_get_glyph_name_nil (hb_font_t *font, if (font->parent) return hb_font_get_glyph_name (font->parent, glyph, name, size); - snprintf (name, size, "gid%u", glyph); return false; } @@ -411,7 +410,10 @@ hb_font_get_glyph_name (hb_font_t *font, hb_codepoint_t glyph, char *name, unsigned int size) { - return font->get_glyph_name (glyph, name, size); + hb_bool_t ret = font->get_glyph_name (glyph, name, size); + if (!ret) + snprintf (name, size, "gid%u", glyph); + return ret; } hb_bool_t commit ade7459ea7c75b4f33f7cfa43dd5bdfa0c18d6d5 Author: Behdad Esfahbod <[email protected]> Date: Mon Aug 6 19:42:47 2012 -0700 [util] Fix leaks diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index 54d70cb..074ec36 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -102,20 +102,28 @@ static const void *hb_gr_get_table (const void *data, unsigned int tag, size_t * hb_graphite2_shaper_face_data_t * _hb_graphite2_shaper_face_data_create (hb_face_t *face) { - hb_graphite2_shaper_face_data_t *data = (hb_graphite2_shaper_face_data_t *) calloc (1, sizeof (hb_graphite2_shaper_face_data_t)); - if (unlikely (!data)) - return NULL; - hb_blob_t *silf_blob = hb_face_reference_table (face, HB_GRAPHITE2_TAG_SILF); + /* Umm, we just reference the table to check whether it exists. + * Maybe add better API for this? */ if (!hb_blob_get_length (silf_blob)) { hb_blob_destroy (silf_blob); return NULL; } + hb_blob_destroy (silf_blob); + + hb_graphite2_shaper_face_data_t *data = (hb_graphite2_shaper_face_data_t *) calloc (1, sizeof (hb_graphite2_shaper_face_data_t)); + if (unlikely (!data)) + hb_blob_destroy (silf_blob); data->face = face; data->grface = gr_make_face (data, &hb_gr_get_table, gr_face_default); + if (unlikely (!data->grface)) { + free (data); + return NULL; + } + return data; } @@ -225,6 +233,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan, features++; } + /* TODO Use scratch buffer for these. */ hb_codepoint_t *gids = NULL, *pg; hb_graphite2_cluster_t *clusters = NULL; gr_segment *seg = NULL; @@ -323,6 +332,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan, success = 1; dieout: + if (feats) gr_featureval_destroy (feats); if (gids) free (gids); if (clusters) free (clusters); if (seg) gr_seg_destroy (seg); diff --git a/util/options.cc b/util/options.cc index 3a9496b..d2a3846 100644 --- a/util/options.cc +++ b/util/options.cc @@ -178,7 +178,7 @@ parse_shapers (const char *name G_GNUC_UNUSED, GError **error G_GNUC_UNUSED) { shape_options_t *shape_opts = (shape_options_t *) data; - g_free (shape_opts->shapers); + g_strfreev (shape_opts->shapers); shape_opts->shapers = g_strsplit (arg, ",", 0); return true; } diff --git a/util/options.hh b/util/options.hh index 2485230..5d25d9e 100644 --- a/util/options.hh +++ b/util/options.hh @@ -155,7 +155,7 @@ struct shape_options_t : option_group_t ~shape_options_t (void) { free (features); - g_free (shapers); + g_strfreev (shapers); } void add_options (option_parser_t *parser); commit 2fef993460dcfd94c92ab35413bdde18ad2b0ceb Author: Behdad Esfahbod <[email protected]> Date: Mon Aug 6 19:35:04 2012 -0700 [Graphite] Fix graphite2 backend with RTL text Patch from Martin Hosken. diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index 4950f72..54d70cb 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -295,27 +295,30 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan, buffer->replace_glyphs (clusters[i].num_chars, clusters[i].num_glyphs, gids + clusters[i].base_glyph); buffer->swap_buffers (); + if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) + curradvx = gr_seg_advance_X(seg); + hb_glyph_position_t *pPos; for (pPos = hb_buffer_get_glyph_positions (buffer, NULL), is = gr_seg_first_slot (seg); is; pPos++, is = gr_slot_next_in_segment (is)) { - pPos->x_offset = gr_slot_origin_X(is) - curradvx; - pPos->y_offset = gr_slot_origin_Y(is) - curradvy; - pPos->x_advance = gr_slot_advance_X(is, grface, grfont); - pPos->y_advance = gr_slot_advance_Y(is, grface, grfont); -// if (pPos->x_advance < 0 && gr_slot_attached_to(is)) -// pPos->x_advance = 0; - curradvx += pPos->x_advance; + pPos->x_offset = gr_slot_origin_X (is) - curradvx; + pPos->y_offset = gr_slot_origin_Y (is) - curradvy; + pPos->x_advance = gr_slot_advance_X (is, grface, grfont); + pPos->y_advance = gr_slot_advance_Y (is, grface, grfont); + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + curradvx -= pPos->x_advance; + pPos->x_offset = gr_slot_origin_X (is) - curradvx; + if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + curradvx += pPos->x_advance; + pPos->y_offset = gr_slot_origin_Y (is) - curradvy; curradvy += pPos->y_advance; } - pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx; - - /* TODO(behdad): - * This shaper is badly broken with RTL text. It returns glyphs - * in the logical order! - */ -// if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) -// hb_buffer_reverse (buffer); + if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx; + + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + hb_buffer_reverse_clusters (buffer); success = 1; commit e4992e13e19877a73ea05fc1d31005a262c685ad Author: Behdad Esfahbod <[email protected]> Date: Mon Aug 6 19:25:39 2012 -0700 [Graphite] Port graphite2 backend to new shaper infrastructure diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index c14eea5..4950f72 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -1,7 +1,7 @@ /* * Copyright © 2011 Martin Hosken * Copyright © 2011 SIL International - * Copyright © 2011 Google, Inc. + * Copyright © 2011,2012 Google, Inc. * * This is part of HarfBuzz, a text shaping library. * @@ -26,49 +26,43 @@ * Google Author(s): Behdad Esfahbod */ -#include "hb-private.hh" +#define HB_SHAPER graphite2 +#define hb_graphite2_shaper_font_data_t gr_font +#include "hb-shaper-impl-private.hh" + +#include <graphite2/Font.h> +#include <graphite2/Segment.h> #include "hb-graphite2.h" -#include "hb-buffer-private.hh" -#include "hb-font-private.hh" #include "hb-ot-tag.h" -#include <graphite2/Font.h> -#include <graphite2/Segment.h> +HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, face) +HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, font) -struct hb_gr_cluster_t { - unsigned int base_char; - unsigned int num_chars; - unsigned int base_glyph; - unsigned int num_glyphs; -}; +/* + * shaper face data + */ -typedef struct hb_gr_tablelist_t { - hb_blob_t *blob; - struct hb_gr_tablelist_t *next; +typedef struct hb_graphite2_tablelist_t { + hb_blob_t *blob; + struct hb_graphite2_tablelist_t *next; unsigned int tag; -} hb_gr_tablelist_t; - -static struct hb_gr_face_data_t { - hb_face_t *face; - gr_face *grface; - hb_gr_tablelist_t *tlist; -} _hb_gr_face_data_nil = {NULL, NULL}; +} hb_graphite2_tablelist_t; -static struct hb_gr_font_data_t { - gr_font *grfont; +struct hb_graphite2_shaper_face_data_t { + hb_face_t *face; gr_face *grface; -} _hb_gr_font_data_nil = {NULL, NULL}; - + hb_graphite2_tablelist_t *tlist; +}; static const void *hb_gr_get_table (const void *data, unsigned int tag, size_t *len) { - hb_gr_tablelist_t *pl = NULL, *p; - hb_gr_face_data_t *face = (hb_gr_face_data_t *) data; - hb_gr_tablelist_t *tlist = face->tlist; + hb_graphite2_tablelist_t *pl = NULL, *p; + hb_graphite2_shaper_face_data_t *face = (hb_graphite2_shaper_face_data_t *) data; + hb_graphite2_tablelist_t *tlist = face->tlist; for (p = tlist; p; p = p->next) if (p->tag == tag ) { @@ -79,13 +73,12 @@ static const void *hb_gr_get_table (const void *data, unsigned int tag, size_t * } else pl = p; - if (!face->face) - return NULL; hb_blob_t *blob = hb_face_reference_table (face->face, tag); + /* TODO Not thread-safe. */ if (!pl || pl->blob) { - p = (hb_gr_tablelist_t *) malloc (sizeof (hb_gr_tablelist_t)); + p = (hb_graphite2_tablelist_t *) calloc (1, sizeof (hb_graphite2_tablelist_t)); if (!p) { hb_blob_destroy (blob); return NULL; @@ -106,147 +99,134 @@ static const void *hb_gr_get_table (const void *data, unsigned int tag, size_t * return d; } -static float hb_gr_get_advance (const void *hb_font, unsigned short gid) +hb_graphite2_shaper_face_data_t * +_hb_graphite2_shaper_face_data_create (hb_face_t *face) { - return ((hb_font_t *) font)->get_glyph_h_advance (gid); + hb_graphite2_shaper_face_data_t *data = (hb_graphite2_shaper_face_data_t *) calloc (1, sizeof (hb_graphite2_shaper_face_data_t)); + if (unlikely (!data)) + return NULL; + + hb_blob_t *silf_blob = hb_face_reference_table (face, HB_GRAPHITE2_TAG_SILF); + if (!hb_blob_get_length (silf_blob)) + { + hb_blob_destroy (silf_blob); + return NULL; + } + + data->face = face; + data->grface = gr_make_face (data, &hb_gr_get_table, gr_face_default); + + return data; } -static void _hb_gr_face_data_destroy (void *data) +void +_hb_graphite2_shaper_face_data_destroy (hb_graphite2_shaper_face_data_t *data) { - hb_gr_face_data_t *f = (hb_gr_face_data_t *) data; - hb_gr_tablelist_t *tlist = f->tlist; + hb_graphite2_tablelist_t *tlist = data->tlist; + while (tlist) { - hb_gr_tablelist_t *old = tlist; + hb_graphite2_tablelist_t *old = tlist; hb_blob_destroy (tlist->blob); tlist = tlist->next; free (old); } - gr_face_destroy (f->grface); -} -static void _hb_gr_font_data_destroy (void *data) -{ - hb_gr_font_data_t *f = (hb_gr_font_data_t *) data; + gr_face_destroy (data->grface); - gr_font_destroy (f->grfont); - free (f); + free (data); } -static hb_user_data_key_t hb_gr_data_key; - -static hb_gr_face_data_t * -_hb_gr_face_get_data (hb_face_t *face) -{ - hb_gr_face_data_t *data = (hb_gr_face_data_t *) hb_face_get_user_data (face, &hb_gr_data_key); - if (likely (data)) return data; - - data = (hb_gr_face_data_t *) calloc (1, sizeof (hb_gr_face_data_t)); - if (unlikely (!data)) - return &_hb_gr_face_data_nil; - - hb_blob_t *silf_blob = hb_face_reference_table (face, HB_GRAPHITE_TAG_Silf); - if (!hb_blob_get_length (silf_blob)) - { - hb_blob_destroy (silf_blob); - return &_hb_gr_face_data_nil; - } +/* + * shaper font data + */ - data->face = face; - data->grface = gr_make_face (data, &hb_gr_get_table, gr_face_default); +static float hb_gr_get_advance (const void *hb_font, unsigned short gid) +{ + return ((hb_font_t *) hb_font)->get_glyph_h_advance (gid); +} +hb_graphite2_shaper_font_data_t * +_hb_graphite2_shaper_font_data_create (hb_font_t *font) +{ + if (unlikely (!hb_graphite2_shaper_face_data_ensure (font->face))) return NULL; - if (unlikely (!hb_face_set_user_data (face, &hb_gr_data_key, data, - (hb_destroy_func_t) _hb_gr_face_data_destroy, - false))) - { - _hb_gr_face_data_destroy (data); - data = (hb_gr_face_data_t *) hb_face_get_user_data (face, &hb_gr_data_key); - if (data) - return data; - else - return &_hb_gr_face_data_nil; - } + hb_face_t *face = font->face; + hb_graphite2_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); - return data; + return gr_make_font_with_advance_fn (font->x_scale, font, &hb_gr_get_advance, face_data->grface); } -static hb_gr_font_data_t * -_hb_gr_font_get_data (hb_font_t *font) +void +_hb_graphite2_shaper_font_data_destroy (hb_graphite2_shaper_font_data_t *data) { - hb_gr_font_data_t *data = (hb_gr_font_data_t *) hb_font_get_user_data (font, &hb_gr_data_key); - if (likely (data)) return data; + gr_font_destroy (data); +} - data = (hb_gr_font_data_t *) calloc (1, sizeof (hb_gr_font_data_t)); - if (unlikely (!data)) - return &_hb_gr_font_data_nil; +/* + * shaper shape_plan data + */ - hb_blob_t *silf_blob = hb_face_reference_table (font->face, HB_GRAPHITE_TAG_Silf); - if (!hb_blob_get_length (silf_blob)) - { - hb_blob_destroy (silf_blob); - return &_hb_gr_font_data_nil; - } +struct hb_graphite2_shaper_shape_plan_data_t {}; - data->grface = _hb_gr_face_get_data (font->face)->grface; - data->grfont = gr_make_font_with_advance_fn (font->x_scale, font, &hb_gr_get_advance, data->grface); +hb_graphite2_shaper_shape_plan_data_t * +_hb_graphite2_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, + const hb_feature_t *user_features, + unsigned int num_user_features) +{ + return (hb_graphite2_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} +void +_hb_graphite2_shaper_shape_plan_data_destroy (hb_graphite2_shaper_shape_plan_data_t *data) +{ +} - if (unlikely (!hb_font_set_user_data (font, &hb_gr_data_key, data, - (hb_destroy_func_t) _hb_gr_font_data_destroy, - false))) - { - _hb_gr_font_data_destroy (data); - data = (hb_gr_font_data_t *) hb_font_get_user_data (font, &hb_gr_data_key); - if (data) - return data; - else - return &_hb_gr_font_data_nil; - } - return data; -} +/* + * shaper + */ +struct hb_graphite2_cluster_t { + unsigned int base_char; + unsigned int num_chars; + unsigned int base_glyph; + unsigned int num_glyphs; +}; hb_bool_t -_hb_graphite_shape (hb_font_t *font, - hb_buffer_t *buffer, - const hb_feature_t *features, - unsigned int num_features) +_hb_graphite2_shape (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) { - - buffer->guess_properties (); - - /* XXX We do a hell of a lot of stuff just to figure out this font - * is not graphite! Shouldn't do. */ - - hb_gr_font_data_t *data = _hb_gr_font_get_data (font); - if (!data->grface) return false; + hb_face_t *face = font->face; + gr_face *grface = HB_SHAPER_DATA_GET (face)->grface; + gr_font *grfont = HB_SHAPER_DATA_GET (font); unsigned int charlen; hb_glyph_info_t *bufferi = hb_buffer_get_glyph_infos (buffer, &charlen); int success = 0; - if (!charlen) return true; - const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); const char *lang_end = strchr (lang, '-'); int lang_len = lang_end ? lang_end - lang : -1; - gr_feature_val *feats = gr_face_featureval_for_lang (data->grface, lang ? hb_tag_from_string (lang, lang_len) : 0); + gr_feature_val *feats = gr_face_featureval_for_lang (grface, lang ? hb_tag_from_string (lang, lang_len) : 0); while (num_features--) { - const gr_feature_ref *fref = gr_face_find_fref (data->grface, features->tag); + const gr_feature_ref *fref = gr_face_find_fref (grface, features->tag); if (fref) gr_fref_set_feature_value (fref, features->value, feats); features++; } hb_codepoint_t *gids = NULL, *pg; - hb_gr_cluster_t *clusters = NULL; + hb_graphite2_cluster_t *clusters = NULL; gr_segment *seg = NULL; uint32_t *text = NULL; const gr_slot *is; @@ -266,7 +246,7 @@ _hb_graphite_shape (hb_font_t *font, hb_tag_t script_tag[2]; hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script_tag[1]); - seg = gr_make_seg (data->grfont, data->grface, + seg = gr_make_seg (grfont, grface, script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1], feats, gr_utf32, text, charlen, @@ -274,7 +254,7 @@ _hb_graphite_shape (hb_font_t *font, if (!seg) goto dieout; glyphlen = gr_seg_n_slots (seg); - clusters = (hb_gr_cluster_t *) calloc (charlen, sizeof (hb_gr_cluster_t)); + clusters = (hb_graphite2_cluster_t *) calloc (charlen, sizeof (hb_graphite2_cluster_t)); if (!glyphlen || !clusters) goto dieout; gids = (hb_codepoint_t *) malloc (glyphlen * sizeof (hb_codepoint_t)); @@ -296,7 +276,7 @@ _hb_graphite_shape (hb_font_t *font, if (gr_slot_can_insert_before (is) && clusters[ci].num_chars && before >= clusters[ci].base_char + clusters[ci].num_chars) { - hb_gr_cluster_t *c = clusters + ci + 1; + hb_graphite2_cluster_t *c = clusters + ci + 1; c->base_char = clusters[ci].base_char + clusters[ci].num_chars; c->num_chars = before - c->base_char; c->base_glyph = ic; @@ -321,8 +301,8 @@ _hb_graphite_shape (hb_font_t *font, { pPos->x_offset = gr_slot_origin_X(is) - curradvx; pPos->y_offset = gr_slot_origin_Y(is) - curradvy; - pPos->x_advance = gr_slot_advance_X(is, data->grface, data->grfont); - pPos->y_advance = gr_slot_advance_Y(is, data->grface, data->grfont); + pPos->x_advance = gr_slot_advance_X(is, grface, grfont); + pPos->y_advance = gr_slot_advance_Y(is, grface, grfont); // if (pPos->x_advance < 0 && gr_slot_attached_to(is)) // pPos->x_advance = 0; curradvx += pPos->x_advance; diff --git a/src/hb-graphite2.h b/src/hb-graphite2.h index 2d16cc8..8122495 100644 --- a/src/hb-graphite2.h +++ b/src/hb-graphite2.h @@ -31,7 +31,7 @@ HB_BEGIN_DECLS -#define HB_GRAPHITE_TAG_Silf HB_TAG('S','i','l','f') +#define HB_GRAPHITE2_TAG_SILF HB_TAG('S','i','l','f') /* TODO add gr_font/face etc getters and other glue API */ diff --git a/src/hb-shaper-list.hh b/src/hb-shaper-list.hh index ff1fdfd..8e67dbd 100644 --- a/src/hb-shaper-list.hh +++ b/src/hb-shaper-list.hh @@ -29,7 +29,7 @@ #endif /* HB_SHAPER_LIST_HH */ /* Dummy header guards */ /* v--- Add new shapers in the right place here. */ -#ifdef HAVE_GRAPHITE +#ifdef HAVE_GRAPHITE2 HB_SHAPER_IMPLEMENT (graphite2) #endif #ifdef HAVE_UNISCRIBE commit 66591ececfba9791de06c814f5f30131e95e5fd2 Author: Behdad Esfahbod <[email protected]> Date: Mon Aug 6 17:07:19 2012 -0700 Remove unnecessary lifecycle bits We already set recount to INVALID when destroying. This block was not necessary. diff --git a/src/hb-font.cc b/src/hb-font.cc index 48bfaab..f0683e4 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -624,9 +624,6 @@ hb_face_destroy (hb_face_t *face) { if (!hb_object_destroy (face)) return; - /* The cached shape_plans think they have a reference on us, and - * try to release it. Make sure that doesn't mess up. */ - face->header.ref_count.ref_count = HB_REFERENCE_COUNT_INVALID_VALUE; for (hb_face_t::plan_node_t *node = face->shape_plans; node; ) { hb_face_t::plan_node_t *next = node->next;
_______________________________________________ HarfBuzz mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/harfbuzz
