Add hb_face_[sg]et_glyph_count()

This commit is contained in:
Behdad Esfahbod 2012-11-15 16:23:21 -08:00
parent aec89de564
commit e05a999495
3 changed files with 44 additions and 1 deletions

View File

@ -100,6 +100,7 @@ struct hb_face_t {
unsigned int index; unsigned int index;
mutable unsigned int upem; mutable unsigned int upem;
mutable unsigned int num_glyphs;
struct hb_shaper_data_t shaper_data; struct hb_shaper_data_t shaper_data;
@ -130,8 +131,16 @@ struct hb_face_t {
return upem; return upem;
} }
inline unsigned int get_num_glyphs (void) const
{
if (unlikely (num_glyphs == (unsigned int) -1))
load_num_glyphs ();
return num_glyphs;
}
private: private:
HB_INTERNAL void load_upem (void) const; HB_INTERNAL void load_upem (void) const;
HB_INTERNAL void load_num_glyphs (void) const;
}; };
#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS

View File

@ -34,6 +34,7 @@
#include "hb-blob.h" #include "hb-blob.h"
#include "hb-open-file-private.hh" #include "hb-open-file-private.hh"
#include "hb-ot-head-table.hh" #include "hb-ot-head-table.hh"
#include "hb-ot-maxp-table.hh"
#include "hb-cache-private.hh" #include "hb-cache-private.hh"
@ -520,6 +521,7 @@ static const hb_face_t _hb_face_nil = {
0, /* index */ 0, /* index */
1000, /* upem */ 1000, /* upem */
0, /* num_glyphs */
{ {
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
@ -549,6 +551,7 @@ hb_face_create_for_tables (hb_reference_table_func_t reference_table_func,
face->destroy = destroy; face->destroy = destroy;
face->upem = 0; face->upem = 0;
face->num_glyphs = (unsigned int) -1;
return face; return face;
} }
@ -736,7 +739,6 @@ hb_face_get_upem (hb_face_t *face)
return face->get_upem (); return face->get_upem ();
} }
void void
hb_face_t::load_upem (void) const hb_face_t::load_upem (void) const
{ {
@ -746,6 +748,31 @@ hb_face_t::load_upem (void) const
hb_blob_destroy (head_blob); hb_blob_destroy (head_blob);
} }
void
hb_face_set_glyph_count (hb_face_t *face,
unsigned int glyph_count)
{
if (hb_object_is_inert (face))
return;
face->num_glyphs = glyph_count;
}
unsigned int
hb_face_get_glyph_count (hb_face_t *face)
{
return face->get_num_glyphs ();
}
void
hb_face_t::load_num_glyphs (void) const
{
hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>::sanitize (reference_table (HB_OT_TAG_maxp));
const OT::maxp *maxp_table = OT::Sanitizer<OT::maxp>::lock_instance (maxp_blob);
num_glyphs = maxp_table->get_num_glyphs ();
hb_blob_destroy (maxp_blob);
}
/* /*
* hb_font_t * hb_font_t

View File

@ -105,6 +105,13 @@ hb_face_set_upem (hb_face_t *face,
unsigned int unsigned int
hb_face_get_upem (hb_face_t *face); hb_face_get_upem (hb_face_t *face);
void
hb_face_set_glyph_count (hb_face_t *face,
unsigned int glyph_count);
unsigned int
hb_face_get_glyph_count (hb_face_t *face);
/* /*
* hb_font_funcs_t * hb_font_funcs_t