[API] Sort out get_blob API
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 8 Aug 2011 21:37:41 +0000 (23:37 +0200)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 8 Aug 2011 21:37:41 +0000 (23:37 +0200)
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
src/hb-font.cc
src/hb-font.h
src/hb-ft.cc
src/hb-ot-layout-private.hh
src/hb-ot-layout.cc
src/hb-uniscribe-shape.cc

index 06a5bc49846eb7c2b1c62f7bf616efc268b3b297..d896e72efe80df3476f0c8552ab3b49658c68277 100644 (file)
@@ -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); }
 };
 
 
index c795c8abd1aa55951ee14be09a0464af51a93938..4be2a2e0f503663c2c0e4124f215305dc9f012cc 100644 (file)
@@ -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 <string.h>
 
@@ -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<OpenTypeFontFile>::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 *
@@ -684,16 +695,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<head>::sanitize (hb_face_reference_table (face, HB_OT_TAG_head));
+    const head *head_table = Sanitizer<head>::lock_instance (head_blob);
+    face->upem = head_table->get_upem ();
+    hb_blob_destroy (head_blob);
+  }
+  return face->upem;
 }
 
 
index 187c156db7142ca93dfb65eada81d47f1d6269fd..7f8cd5e69227f636839f3e09dc014cd3c0e5a00f 100644 (file)
@@ -79,13 +79,24 @@ hb_bool_t
 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);
 
index e757524c189e4383313d507230ee79e31779041e..953f0a6aaa6c3348896b8225427539a7348cd93a 100644 (file)
@@ -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)
index 1f6e20b9ff94f036159b5e108b12d8026903f1fe..bf7e43b6e4dd51065a14bcba558dbede23c63195 100644 (file)
@@ -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;
 };
 
 
index ceae824fd732a456f76428fa836df2cf25f46838..d5829b0eab879c46c347ac3cdc85e8fd0cb55d55 100644 (file)
@@ -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<GPOS>::sanitize (hb_face_reference_table (face, HB_OT_TAG_GPOS));
   layout->gpos = Sanitizer<GPOS>::lock_instance (layout->gpos_blob);
 
-  layout->head_blob = Sanitizer<head>::sanitize (hb_face_reference_table (face, HB_OT_TAG_head));
-  layout->head = Sanitizer<head>::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 ();
-}
-
-
index 82ef6482ea3115ee17ce69c89f521c1e074215ff..4315d3496b9c1fb3771e47048d5106bae879b8b3 100644 (file)
@@ -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");