[hmtx/port] Use hb_blob_ptr_t

This commit is contained in:
Behdad Esfahbod 2018-11-11 00:39:52 -05:00
parent 0e2680a6e8
commit bb9abb4efd
2 changed files with 15 additions and 20 deletions

View File

@ -113,7 +113,7 @@ struct hmtxvmtx
DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in src has %d advances, %d lsbs", HB_UNTAG(T::tableTag), _mtx.num_advances, _mtx.num_metrics - _mtx.num_advances);
DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in dest has %d advances, %d lsbs, %u bytes", HB_UNTAG(T::tableTag), num_advances, gids.len - num_advances, (unsigned int) dest_sz);
const char *source_table = hb_blob_get_data (_mtx.blob, nullptr);
const char *source_table = hb_blob_get_data (_mtx.table.get_blob (), nullptr);
// Copy everything over
LongMetric * old_metrics = (LongMetric *) source_table;
FWORD *lsbs = (FWORD *) (old_metrics + _mtx.num_advances);
@ -221,10 +221,10 @@ struct hmtxvmtx
has_font_extents = got_font_extents;
blob = hb_sanitize_context_t().reference_table<hmtxvmtx> (face, T::tableTag);
table = hb_sanitize_context_t().reference_table<hmtxvmtx> (face, T::tableTag);
/* Cap num_metrics() and num_advances() based on table length. */
unsigned int len = hb_blob_get_length (blob);
unsigned int len = table.get_length ();
if (unlikely (num_advances * 4 > len))
num_advances = len / 4;
num_metrics = num_advances + (len - 4 * num_advances) / 2;
@ -234,19 +234,17 @@ struct hmtxvmtx
if (unlikely (!num_advances))
{
num_metrics = num_advances = 0;
hb_blob_destroy (blob);
blob = hb_blob_get_empty ();
hb_blob_destroy (table.get_blob ());
table = hb_blob_get_empty ();
}
table = blob->as<hmtxvmtx> ();
var_blob = hb_sanitize_context_t().reference_table<HVARVVAR> (face, T::variationsTag);
var_table = var_blob->as<HVARVVAR> ();
var_table = hb_sanitize_context_t().reference_table<HVARVVAR> (face, T::variationsTag);
}
inline void fini (void)
{
hb_blob_destroy (blob);
hb_blob_destroy (var_blob);
hb_blob_destroy (table.get_blob ());
hb_blob_destroy (var_table.get_blob ());
}
/* TODO Add variations version. */
@ -301,10 +299,8 @@ struct hmtxvmtx
unsigned int default_advance;
private:
const hmtxvmtx *table;
hb_blob_t *blob;
const HVARVVAR *var_table;
hb_blob_t *var_blob;
hb_blob_ptr_t<hmtxvmtx> table;
hb_blob_ptr_t<HVARVVAR> var_table;
};
protected:

View File

@ -101,9 +101,8 @@ struct post
{
index_to_offset.init ();
blob = hb_sanitize_context_t().reference_table<post> (face);
const post *table = blob->as<post> ();
unsigned int table_length = blob->length;
table = hb_sanitize_context_t().reference_table<post> (face);
unsigned int table_length = table.get_length ();
version = table->version.to_int ();
if (version != 0x00020000)
@ -114,7 +113,7 @@ struct post
glyphNameIndex = &v2.glyphNameIndex;
pool = &StructAfter<uint8_t> (v2.glyphNameIndex);
const uint8_t *end = (uint8_t *) table + table_length;
const uint8_t *end = (const uint8_t *) (const void *) table + table_length;
for (const uint8_t *data = pool;
index_to_offset.len < 65535 && data < end && data + *data < end;
data += 1 + *data)
@ -124,7 +123,7 @@ struct post
{
index_to_offset.fini ();
free (gids_sorted_by_name.get ());
hb_blob_destroy (blob);
hb_blob_destroy (table.get_blob ());
}
inline bool get_glyph_name (hb_codepoint_t glyph,
@ -244,7 +243,7 @@ struct post
}
private:
hb_blob_t *blob;
hb_blob_ptr_t<post> table;
uint32_t version;
const ArrayOf<HBUINT16> *glyphNameIndex;
hb_vector_t<uint32_t, 1> index_to_offset;