struct hb_ot_layout_t *ot_layout;
+ unsigned int index;
unsigned int upem;
};
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); }
};
#include "hb-font-private.hh"
#include "hb-blob.h"
#include "hb-open-file-private.hh"
+#include "hb-ot-head-private.hh"
#include <string.h>
NULL, /* ot_layout */
- 1000
+ 0, /* index */
+ 1000 /* upem */
};
face->ot_layout = _hb_ot_layout_create (face);
- face->upem = _hb_ot_layout_get_upem (face);
+ face->upem = 0;
return face;
}
{
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);
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;
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 *
}
-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)
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;
}
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);
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)
unsigned int *property_out);
-/*
- * head
- */
-
-HB_INTERNAL unsigned int
-_hb_ot_layout_get_upem (hb_face_t *face);
-
/*
* 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;
};
#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"
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;
}
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);
}
{
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);
-}
/*
}
-/*
- * head
- */
-
-unsigned int
-_hb_ot_layout_get_upem (hb_face_t *face)
-{
- return _get_head (face).get_upem ();
-}
-
-
/* 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))
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");