From 3897335c7620c37e9a0224b0c42ade0dfdce4053 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 8 Aug 2011 23:37:41 +0200 Subject: [PATCH] [API] Sort out get_blob API hb_face_get_blob() renamed to hb_face_reference_blob(), returns a reference now. hb_face_[sg]et_index() added. hb_face_set_upem() added. --- src/hb-font-private.hh | 3 +- src/hb-font.cc | 67 +++++++++++++++++++++++++++++++++++---------- src/hb-font.h | 17 ++++++++++-- src/hb-ft.cc | 3 +- src/hb-ot-layout-private.hh | 9 ------ src/hb-ot-layout.cc | 21 -------------- src/hb-uniscribe-shape.cc | 3 +- 7 files changed, 72 insertions(+), 51 deletions(-) diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 06a5bc4..d896e72 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -94,6 +94,7 @@ struct _hb_face_t { struct hb_ot_layout_t *ot_layout; + unsigned int index; unsigned int upem; }; @@ -154,7 +155,7 @@ struct _hb_font_t { private: - inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / this->face->upem; } + inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / hb_face_get_upem (this->face); } }; diff --git a/src/hb-font.cc b/src/hb-font.cc index c795c8a..4be2a2e 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -31,6 +31,7 @@ #include "hb-font-private.hh" #include "hb-blob.h" #include "hb-open-file-private.hh" +#include "hb-ot-head-private.hh" #include @@ -538,7 +539,8 @@ static hb_face_t _hb_face_nil = { NULL, /* ot_layout */ - 1000 + 0, /* index */ + 1000 /* upem */ }; @@ -561,7 +563,7 @@ hb_face_create_for_tables (hb_reference_table_func_t reference_table, face->ot_layout = _hb_ot_layout_create (face); - face->upem = _hb_ot_layout_get_upem (face); + face->upem = 0; return face; } @@ -599,6 +601,9 @@ _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void { hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) user_data; + if (tag == HB_TAG_NONE) + return hb_blob_reference (data->blob); + const OpenTypeFontFile &ot_file = *Sanitizer::lock_instance (data->blob); const OpenTypeFontFace &ot_face = ot_file.get_face (data->index); @@ -613,6 +618,8 @@ hb_face_t * hb_face_create (hb_blob_t *blob, unsigned int index) { + hb_face_t *face; + if (unlikely (!blob || !hb_blob_get_length (blob))) return &_hb_face_nil; @@ -621,9 +628,13 @@ hb_face_create (hb_blob_t *blob, if (unlikely (!closure)) return &_hb_face_nil; - return hb_face_create_for_tables (_hb_face_for_data_reference_table, + face = hb_face_create_for_tables (_hb_face_for_data_reference_table, closure, (hb_destroy_func_t) _hb_face_for_data_closure_destroy); + + hb_face_set_index (face, index); + + return face; } hb_face_t * @@ -685,16 +696,6 @@ hb_face_is_immutable (hb_face_t *face) hb_blob_t * -hb_face_get_blob (hb_face_t *face) -{ - if (face->destroy != (hb_destroy_func_t) _hb_face_for_data_closure_destroy) - return hb_blob_get_empty (); - - hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) face->user_data; - return data->blob; -} - -hb_blob_t * hb_face_reference_table (hb_face_t *face, hb_tag_t tag) { @@ -710,10 +711,48 @@ hb_face_reference_table (hb_face_t *face, return blob; } +hb_blob_t * +hb_face_reference_blob (hb_face_t *face) +{ + return hb_face_reference_table (face, HB_TAG_NONE); +} + +void +hb_face_set_index (hb_face_t *face, + unsigned int index) +{ + if (hb_object_is_inert (face)) + return; + + face->index = 0; +} + +unsigned int +hb_face_get_index (hb_face_t *face) +{ + return face->index; +} + +void +hb_face_set_upem (hb_face_t *face, + unsigned int upem) +{ + if (hb_object_is_inert (face)) + return; + + face->upem = upem; +} + unsigned int hb_face_get_upem (hb_face_t *face) { - return _hb_ot_layout_get_upem (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; } diff --git a/src/hb-font.h b/src/hb-font.h index 187c156..7f8cd5e 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -80,12 +80,23 @@ hb_face_is_immutable (hb_face_t *face); hb_blob_t * -hb_face_get_blob (hb_face_t *face); - -hb_blob_t * hb_face_reference_table (hb_face_t *face, hb_tag_t tag); +hb_blob_t * +hb_face_reference_blob (hb_face_t *face); + +void +hb_face_set_index (hb_face_t *face, + unsigned int index); + +unsigned int +hb_face_get_index (hb_face_t *face); + +void +hb_face_set_upem (hb_face_t *face, + unsigned int upem); + unsigned int hb_face_get_upem (hb_face_t *face); diff --git a/src/hb-ft.cc b/src/hb-ft.cc index e757524..953f0a6 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -250,8 +250,7 @@ reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) FT_ULong length = 0; FT_Error error; - if (unlikely (tag == HB_TAG_NONE)) - return NULL; + /* Note: FreeType like HarfBuzz uses the NONE tag for fetching the entire blob */ error = FT_Load_Sfnt_Table (ft_face, tag, 0, NULL, &length); if (error) diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 1f6e20b..bf7e43b 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -70,13 +70,6 @@ _hb_ot_layout_skip_mark (hb_face_t *face, unsigned int *property_out); -/* - * head - */ - -HB_INTERNAL unsigned int -_hb_ot_layout_get_upem (hb_face_t *face); - /* * hb_ot_layout_t @@ -87,12 +80,10 @@ struct hb_ot_layout_t hb_blob_t *gdef_blob; hb_blob_t *gsub_blob; hb_blob_t *gpos_blob; - hb_blob_t *head_blob; const struct GDEF *gdef; const struct GSUB *gsub; const struct GPOS *gpos; - const struct head *head; }; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index ceae824..d5829b0 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -33,7 +33,6 @@ #include "hb-ot-layout-gdef-private.hh" #include "hb-ot-layout-gsub-private.hh" #include "hb-ot-layout-gpos-private.hh" -#include "hb-ot-head-private.hh" #include "hb-ot-maxp-private.hh" @@ -57,9 +56,6 @@ _hb_ot_layout_create (hb_face_t *face) layout->gpos_blob = Sanitizer::sanitize (hb_face_reference_table (face, HB_OT_TAG_GPOS)); layout->gpos = Sanitizer::lock_instance (layout->gpos_blob); - layout->head_blob = Sanitizer::sanitize (hb_face_reference_table (face, HB_OT_TAG_head)); - layout->head = Sanitizer::lock_instance (layout->head_blob); - return layout; } @@ -69,7 +65,6 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout) hb_blob_destroy (layout->gdef_blob); hb_blob_destroy (layout->gsub_blob); hb_blob_destroy (layout->gpos_blob); - hb_blob_destroy (layout->head_blob); free (layout); } @@ -89,11 +84,6 @@ _get_gpos (hb_face_t *face) { return likely (face->ot_layout && face->ot_layout->gpos) ? *face->ot_layout->gpos : Null(GPOS); } -static inline const head& -_get_head (hb_face_t *face) -{ - return likely (face->ot_layout && face->ot_layout->head) ? *face->ot_layout->head : Null(head); -} /* @@ -505,14 +495,3 @@ hb_ot_layout_position_finish (hb_buffer_t *buffer) } -/* - * head - */ - -unsigned int -_hb_ot_layout_get_upem (hb_face_t *face) -{ - return _get_head (face).get_upem (); -} - - diff --git a/src/hb-uniscribe-shape.cc b/src/hb-uniscribe-shape.cc index 82ef648..4315d34 100644 --- a/src/hb-uniscribe-shape.cc +++ b/src/hb-uniscribe-shape.cc @@ -189,7 +189,7 @@ retry: /* XXX setup ranges */ } - hb_blob_t *blob = hb_face_get_blob (font->face); + hb_blob_t *blob = hb_face_reference_blob (font->face); unsigned int blob_length; const char *blob_data = hb_blob_get_data (blob, &blob_length); if (unlikely (!blob_length)) @@ -197,6 +197,7 @@ retry: DWORD num_fonts_installed; HANDLE fh = AddFontMemResourceEx ((void *) blob_data, blob_length, 0, &num_fonts_installed); + hb_blob_destroy (blob); if (unlikely (!fh)) FAIL ("AddFontMemResourceEx() failed"); -- 2.7.4