diff --git a/src/check-internal-symbols.sh b/src/check-internal-symbols.sh index bc643dafa..7ad57431e 100755 --- a/src/check-internal-symbols.sh +++ b/src/check-internal-symbols.sh @@ -14,18 +14,12 @@ else exit 77 fi -if which c++filt 2>/dev/null >/dev/null; then - cplusplusfilt=c++filt -else - cplusplusfilt=cat -fi - tested=false -for suffix in .so -*.dll; do +for suffix in .so; do so=`echo .libs/libharfbuzz$suffix` if test -f "$so"; then echo "Checking that we are not exposing internal symbols" - if nm $so | grep ' [TW] ' | $cplusplusfilt | grep -v ' T _fini\>\| T _init\>\| T hb_'; then + if nm $so | grep ' [TW] ' | grep -v ' T _fini\>\| T _init\>\| T hb_'; then echo "Ouch, internal symbols exposed" stat=1 fi diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 6bbf8d8db..b6dafbf47 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -94,12 +94,12 @@ struct hb_face_t { hb_bool_t immutable; - hb_reference_table_func_t reference_table; + hb_reference_table_func_t reference_table_func; void *user_data; hb_destroy_func_t destroy; unsigned int index; - unsigned int upem; + mutable unsigned int upem; struct hb_shaper_data_t shaper_data; @@ -107,6 +107,31 @@ struct hb_face_t { hb_shape_plan_t *shape_plan; plan_node_t *next; } *shape_plans; + + + inline hb_blob_t *reference_table (hb_tag_t tag) const + { + hb_blob_t *blob; + + if (unlikely (!this || !reference_table_func)) + return hb_blob_get_empty (); + + blob = reference_table_func (/*XXX*/const_cast (this), tag, user_data); + if (unlikely (!blob)) + return hb_blob_get_empty (); + + return blob; + } + + inline unsigned int get_upem (void) const + { + if (unlikely (!upem)) + load_upem (); + return upem; + } + + private: + HB_INTERNAL void load_upem (void) const; }; #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS diff --git a/src/hb-font.cc b/src/hb-font.cc index e5e4af723..922dee334 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -54,7 +54,7 @@ hb_font_get_glyph_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) - return hb_font_get_glyph (font->parent, unicode, variation_selector, glyph); + return font->parent->get_glyph (unicode, variation_selector, glyph); *glyph = 0; return false; @@ -67,7 +67,7 @@ hb_font_get_glyph_h_advance_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) - return font->parent_scale_x_distance (hb_font_get_glyph_h_advance (font->parent, glyph)); + return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); return font->x_scale; } @@ -79,7 +79,7 @@ hb_font_get_glyph_v_advance_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) - return font->parent_scale_y_distance (hb_font_get_glyph_v_advance (font->parent, glyph)); + return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph)); return font->y_scale; } @@ -93,7 +93,7 @@ hb_font_get_glyph_h_origin_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_h_origin (font->parent, glyph, x, y); + hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y); if (ret) font->parent_scale_position (x, y); return ret; @@ -112,7 +112,7 @@ hb_font_get_glyph_v_origin_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_v_origin (font->parent, glyph, x, y); + hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y); if (ret) font->parent_scale_position (x, y); return ret; @@ -130,7 +130,7 @@ hb_font_get_glyph_h_kerning_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) - return font->parent_scale_x_distance (hb_font_get_glyph_h_kerning (font->parent, left_glyph, right_glyph)); + return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph)); return 0; } @@ -143,7 +143,7 @@ hb_font_get_glyph_v_kerning_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) - return font->parent_scale_y_distance (hb_font_get_glyph_v_kerning (font->parent, top_glyph, bottom_glyph)); + return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph)); return 0; } @@ -156,9 +156,7 @@ hb_font_get_glyph_extents_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_extents (font->parent, - glyph, - extents); + hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents); if (ret) { font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); font->parent_scale_distance (&extents->width, &extents->height); @@ -180,7 +178,7 @@ hb_font_get_glyph_contour_point_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_contour_point (font->parent, glyph, point_index, x, y); + hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y); if (ret) font->parent_scale_position (x, y); return ret; @@ -198,7 +196,7 @@ hb_font_get_glyph_name_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) - return hb_font_get_glyph_name (font->parent, glyph, name, size); + return font->parent->get_glyph_name (glyph, name, size); if (size) *name = '\0'; return false; @@ -212,7 +210,7 @@ hb_font_get_glyph_from_name_nil (hb_font_t *font, void *user_data HB_UNUSED) { if (font->parent) - return hb_font_get_glyph_from_name (font->parent, name, len, glyph); + return font->parent->get_glyph_from_name (name, len, glyph); *glyph = 0; return false; @@ -516,7 +514,7 @@ static const hb_face_t _hb_face_nil = { true, /* immutable */ - NULL, /* reference_table */ + NULL, /* reference_table_func */ NULL, /* user_data */ NULL, /* destroy */ @@ -534,19 +532,19 @@ static const hb_face_t _hb_face_nil = { hb_face_t * -hb_face_create_for_tables (hb_reference_table_func_t reference_table, +hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, void *user_data, hb_destroy_func_t destroy) { hb_face_t *face; - if (!reference_table || !(face = hb_object_create ())) { + if (!reference_table_func || !(face = hb_object_create ())) { if (destroy) destroy (user_data); return hb_face_get_empty (); } - face->reference_table = reference_table; + face->reference_table_func = reference_table_func; face->user_data = user_data; face->destroy = destroy; @@ -697,22 +695,13 @@ hb_blob_t * hb_face_reference_table (hb_face_t *face, hb_tag_t tag) { - hb_blob_t *blob; - - if (unlikely (!face || !face->reference_table)) - return hb_blob_get_empty (); - - blob = face->reference_table (face, tag, face->user_data); - if (unlikely (!blob)) - return hb_blob_get_empty (); - - return blob; + return face->reference_table (tag); } hb_blob_t * hb_face_reference_blob (hb_face_t *face) { - return hb_face_reference_table (face, HB_TAG_NONE); + return face->reference_table (HB_TAG_NONE); } void @@ -744,13 +733,17 @@ hb_face_set_upem (hb_face_t *face, unsigned int hb_face_get_upem (hb_face_t *face) { - if (unlikely (!face->upem)) { - hb_blob_t *head_blob = Sanitizer::sanitize (hb_face_reference_table (face, HB_OT_TAG_head)); - const head *head_table = Sanitizer::lock_instance (head_blob); - face->upem = head_table->get_upem (); - hb_blob_destroy (head_blob); - } - return face->upem; + return face->get_upem (); +} + + +void +hb_face_t::load_upem (void) const +{ + hb_blob_t *head_blob = Sanitizer::sanitize (reference_table (HB_OT_TAG_head)); + const head *head_table = Sanitizer::lock_instance (head_blob); + upem = head_table->get_upem (); + hb_blob_destroy (head_blob); } diff --git a/src/hb-font.h b/src/hb-font.h index 4a043be5e..d796856f3 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -52,7 +52,7 @@ typedef hb_blob_t * (*hb_reference_table_func_t) (hb_face_t *face, hb_tag_t tag /* calls destroy() when not needing user_data anymore */ hb_face_t * -hb_face_create_for_tables (hb_reference_table_func_t reference_table, +hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, void *user_data, hb_destroy_func_t destroy); diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index 70103d54b..1b657a6c0 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -73,7 +73,7 @@ static const void *hb_graphite2_get_table (const void *data, unsigned int tag, s if (unlikely (!blob)) { - blob = hb_face_reference_table (face_data->face, tag); + blob = face_data->face->reference_table (tag); hb_graphite2_tablelist_t *p = (hb_graphite2_tablelist_t *) calloc (1, sizeof (hb_graphite2_tablelist_t)); if (unlikely (!p)) { @@ -98,7 +98,7 @@ static const void *hb_graphite2_get_table (const void *data, unsigned int tag, s hb_graphite2_shaper_face_data_t * _hb_graphite2_shaper_face_data_create (hb_face_t *face) { - hb_blob_t *silf_blob = hb_face_reference_table (face, HB_GRAPHITE2_TAG_SILF); + hb_blob_t *silf_blob = face->reference_table (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)) diff --git a/src/hb-old.cc b/src/hb-old.cc index ec25e522e..197e62093 100644 --- a/src/hb-old.cc +++ b/src/hb-old.cc @@ -188,7 +188,7 @@ static HB_Error table_func (void *font, HB_Tag tag, HB_Byte *buffer, HB_UInt *length) { hb_face_t *face = (hb_face_t *) font; - hb_blob_t *blob = hb_face_reference_table (face, (hb_tag_t) tag); + hb_blob_t *blob = face->reference_table ((hb_tag_t) tag); unsigned int capacity = *length; *length = hb_blob_get_length (blob); memcpy (buffer, hb_blob_get_data (blob, NULL), MIN (capacity, *length)); diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 91deaa2ca..e4d84e82a 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -49,13 +49,13 @@ _hb_ot_layout_create (hb_face_t *face) if (unlikely (!layout)) return NULL; - layout->gdef_blob = Sanitizer::sanitize (hb_face_reference_table (face, HB_OT_TAG_GDEF)); + layout->gdef_blob = Sanitizer::sanitize (face->reference_table (HB_OT_TAG_GDEF)); layout->gdef = Sanitizer::lock_instance (layout->gdef_blob); - layout->gsub_blob = Sanitizer::sanitize (hb_face_reference_table (face, HB_OT_TAG_GSUB)); + layout->gsub_blob = Sanitizer::sanitize (face->reference_table (HB_OT_TAG_GSUB)); layout->gsub = Sanitizer::lock_instance (layout->gsub_blob); - layout->gpos_blob = Sanitizer::sanitize (hb_face_reference_table (face, HB_OT_TAG_GPOS)); + layout->gpos_blob = Sanitizer::sanitize (face->reference_table (HB_OT_TAG_GPOS)); layout->gpos = Sanitizer::lock_instance (layout->gpos_blob); layout->gsub_lookup_count = layout->gsub->get_lookup_count (); diff --git a/src/hb-ot-shape-fallback.cc b/src/hb-ot-shape-fallback.cc index 54ffdb008..71aed89b5 100644 --- a/src/hb-ot-shape-fallback.cc +++ b/src/hb-ot-shape-fallback.cc @@ -109,9 +109,8 @@ position_mark (const hb_ot_shape_plan_t *plan, unsigned int combining_class) { hb_glyph_extents_t mark_extents; - if (!hb_font_get_glyph_extents (font, - buffer->info[i].codepoint, - &mark_extents)) + if (!font->get_glyph_extents (buffer->info[i].codepoint, + &mark_extents)) return; hb_position_t y_gap = font->y_scale / 16; @@ -193,9 +192,8 @@ position_around_base (const hb_ot_shape_plan_t *plan, unsigned int end) { hb_glyph_extents_t base_extents; - if (!hb_font_get_glyph_extents (font, - buffer->info[base].codepoint, - &base_extents)) + if (!font->get_glyph_extents (buffer->info[base].codepoint, + &base_extents)) { /* If extents don't work, zero marks and go home. */ zero_mark_advances (buffer, base + 1, end); diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 41ec329a8..4c055d33a 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -578,7 +578,7 @@ hb_ot_shape_glyphs_closure (hb_font_t *font, * if that's what they desire. */ unsigned int count = buffer->len; for (unsigned int i = 0; i < count; i++) - hb_set_add (glyphs, buffer->info[i].codepoint); + glyphs->add (buffer->info[i].codepoint); /* And find transitive closure. */ hb_set_t copy; diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index f7a78e41d..038f6af32 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -37,7 +37,7 @@ #undef HB_SHAPER_IMPLEMENT -void +static void hb_shape_plan_plan (hb_shape_plan_t *shape_plan, const hb_feature_t *user_features, unsigned int num_user_features, diff --git a/src/hb-shape-plan.h b/src/hb-shape-plan.h index fbce5ddfa..f1a14a999 100644 --- a/src/hb-shape-plan.h +++ b/src/hb-shape-plan.h @@ -47,7 +47,7 @@ hb_shape_plan_create (hb_face_t *face, unsigned int num_user_features, const char * const *shaper_list); -hb_shape_plan_t * +HB_INTERNAL hb_shape_plan_t * hb_shape_plan_create_cached (hb_face_t *face, const hb_segment_properties_t *props, const hb_feature_t *user_features, diff --git a/src/hb-tt-font.cc b/src/hb-tt-font.cc index 0055ae9cd..b7198efdc 100644 --- a/src/hb-tt-font.cc +++ b/src/hb-tt-font.cc @@ -51,7 +51,7 @@ _hb_tt_font_create (hb_font_t *font) /* TODO Remove this object altogether */ hb_tt_font_t *tt = (hb_tt_font_t *) calloc (1, sizeof (hb_tt_font_t)); - tt->hhea_blob = Sanitizer::sanitize (hb_face_reference_table (font->face, HB_OT_TAG_hhea)); + tt->hhea_blob = Sanitizer::sanitize (font->face->reference_table (HB_OT_TAG_hhea)); tt->hhea = Sanitizer::lock_instance (tt->hhea_blob); return tt; @@ -76,168 +76,4 @@ _get_hhea (hb_face_t *face) * hb_tt_font_funcs_t */ -static hb_bool_t -hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t unicode, - hb_codepoint_t variation_selector, - hb_codepoint_t *glyph, - void *user_data HB_UNUSED) -{ - if (font->parent) - return hb_font_get_glyph (font->parent, unicode, variation_selector, glyph); - - *glyph = 0; - return false; -} - -static hb_position_t -hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t glyph, - void *user_data HB_UNUSED) -{ - if (font->parent) - return font->parent_scale_x_distance (hb_font_get_glyph_h_advance (font->parent, glyph)); - - return font->x_scale; -} - -static hb_position_t -hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t glyph, - void *user_data HB_UNUSED) -{ - if (font->parent) - return font->parent_scale_y_distance (hb_font_get_glyph_v_advance (font->parent, glyph)); - - return font->y_scale; -} - -static hb_bool_t -hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t glyph, - hb_position_t *x, - hb_position_t *y, - void *user_data HB_UNUSED) -{ - if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_h_origin (font->parent, - glyph, - x, y); - if (ret) - font->parent_scale_position (x, y); - return ret; - } - - *x = *y = 0; - return false; -} - -static hb_bool_t -hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t glyph, - hb_position_t *x, - hb_position_t *y, - void *user_data HB_UNUSED) -{ - if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_v_origin (font->parent, - glyph, - x, y); - if (ret) - font->parent_scale_position (x, y); - return ret; - } - - *x = *y = 0; - return false; -} - -static hb_position_t -hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t left_glyph, - hb_codepoint_t right_glyph, - void *user_data HB_UNUSED) -{ - if (font->parent) - return font->parent_scale_x_distance (hb_font_get_glyph_h_kerning (font->parent, left_glyph, right_glyph)); - - return 0; -} - -static hb_position_t -hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t top_glyph, - hb_codepoint_t bottom_glyph, - void *user_data HB_UNUSED) -{ - if (font->parent) - return font->parent_scale_y_distance (hb_font_get_glyph_v_kerning (font->parent, top_glyph, bottom_glyph)); - - return 0; -} - -static hb_bool_t -hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t glyph, - hb_glyph_extents_t *extents, - void *user_data HB_UNUSED) -{ - if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_extents (font->parent, - glyph, - extents); - if (ret) { - font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); - font->parent_scale_distance (&extents->width, &extents->height); - } - return ret; - } - - memset (extents, 0, sizeof (*extents)); - return false; -} - -static hb_bool_t -hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED, - void *font_data HB_UNUSED, - hb_codepoint_t glyph, - unsigned int point_index, - hb_position_t *x, - hb_position_t *y, - void *user_data HB_UNUSED) -{ - if (font->parent) { - hb_bool_t ret = hb_font_get_glyph_contour_point (font->parent, - glyph, point_index, - x, y); - if (ret) - font->parent_scale_position (x, y); - return ret; - } - - *x = *y = 0; - return false; -} - - -static hb_font_funcs_t _hb_font_funcs_nil = { - HB_OBJECT_HEADER_STATIC, - - true, /* immutable */ - - { -#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil, - HB_FONT_FUNCS_IMPLEMENT_CALLBACKS -#undef HB_FONT_FUNC_IMPLEMENT - } -}; #endif -