[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.
This commit is contained in:
Behdad Esfahbod 2011-08-08 23:37:41 +02:00
parent e715784be3
commit 3897335c76
7 changed files with 72 additions and 51 deletions

View 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); }
};

View 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;
}

View 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);

View 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)

View 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;
};

View 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 ();
}

View 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");