[cbdt] Move some more code around

This commit is contained in:
Behdad Esfahbod 2016-12-04 19:12:52 -08:00
parent 654f9ab0d8
commit 9eda74c92c
2 changed files with 49 additions and 30 deletions

View File

@ -80,9 +80,11 @@ struct SBitLineMetrics
DEFINE_SIZE_STATIC(12);
};
/*
* Index Subtables.
*/
struct IndexSubtableHeader
{
inline bool sanitize (hb_sanitize_context_t *c) const
@ -202,19 +204,6 @@ struct IndexSubtableRecord
DEFINE_SIZE_STATIC(8);
};
/*
* Glyph Bitmap Data Formats.
*/
struct GlyphBitmapDataFormat17
{
SmallGlyphMetrics glyphMetrics;
ULONG dataLen;
BYTE dataZ[VAR];
DEFINE_SIZE_ARRAY(9, dataZ);
};
struct IndexSubtableArray
{
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
@ -251,6 +240,8 @@ struct IndexSubtableArray
struct BitmapSizeTable
{
friend struct CBLC;
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
{
TRACE_SANITIZE (this);
@ -261,6 +252,12 @@ struct BitmapSizeTable
vertical.sanitize (c));
}
const IndexSubtableRecord *find_table (hb_codepoint_t glyph, const void *base) const
{
return (base+indexSubtableArrayOffset).find_table (glyph, numberOfIndexSubtables);
}
protected:
OffsetTo<IndexSubtableArray, ULONG> indexSubtableArrayOffset;
ULONG indexTablesSize;
ULONG numberOfIndexSubtables;
@ -274,9 +271,25 @@ struct BitmapSizeTable
BYTE bitDepth;
CHAR flags;
public:
DEFINE_SIZE_STATIC(48);
};
/*
* Glyph Bitmap Data Formats.
*/
struct GlyphBitmapDataFormat17
{
SmallGlyphMetrics glyphMetrics;
ULONG dataLen;
BYTE dataZ[VAR];
DEFINE_SIZE_ARRAY(9, dataZ);
};
/*
* CBLC -- Color Bitmap Location Table
*/
@ -296,18 +309,28 @@ struct CBLC
}
public:
const BitmapSizeTable* find_table (hb_codepoint_t glyph) const
const IndexSubtableRecord *find_table (hb_codepoint_t glyph,
unsigned int *x_ppem, unsigned int *y_ppem) const
{
// TODO: Make it possible to select strike.
/* TODO: Make it possible to select strike. */
const BitmapSizeTable *sizeTable = &Null(BitmapSizeTable);
unsigned int count = sizeTables.len;
for (uint32_t i = 0; i < count; ++i) {
for (uint32_t i = 0; i < count; ++i)
{
unsigned int startGlyphIndex = sizeTables.array[i].startGlyphIndex;
unsigned int endGlyphIndex = sizeTables.array[i].endGlyphIndex;
if (startGlyphIndex <= glyph && glyph <= endGlyphIndex) {
return &sizeTables[i];
if (startGlyphIndex <= glyph && glyph <= endGlyphIndex)
{
sizeTable = &sizeTables[i];
break;
}
}
return NULL;
*x_ppem = sizeTable->ppemX;
*y_ppem = sizeTable->ppemY;
return sizeTable->find_table (glyph, this);
}
protected:

View File

@ -244,17 +244,13 @@ struct hb_ot_face_cbdt_accelerator_t
inline bool get_extents (hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
{
unsigned int x_ppem = upem, y_ppem = upem; /* TODO Use font ppem if available. */
if (cblc == NULL) {
return false; // Not a color bitmap font.
}
const OT::BitmapSizeTable* sizeTable = this->cblc->find_table(glyph);
if (sizeTable == NULL) {
return false;
}
const OT::IndexSubtableArray& subtables = this->cblc + sizeTable->indexSubtableArrayOffset;
const OT::IndexSubtableRecord *subtable_record = subtables.find_table (glyph, sizeTable->numberOfIndexSubtables);
const OT::IndexSubtableRecord *subtable_record = this->cblc->find_table(glyph, &x_ppem, &y_ppem);
if (subtable_record == NULL) {
return false;
}
@ -286,10 +282,10 @@ struct hb_ot_face_cbdt_accelerator_t
}
/* Convert to the font units. */
extents->x_bearing *= upem / (float)(sizeTable->ppemX);
extents->y_bearing *= upem / (float)(sizeTable->ppemY);
extents->width *= upem / (float)(sizeTable->ppemX);
extents->height *= upem / (float)(sizeTable->ppemY);
extents->x_bearing *= upem / (float) x_ppem;
extents->y_bearing *= upem / (float) y_ppem;
extents->width *= upem / (float) x_ppem;
extents->height *= upem / (float) y_ppem;
return true;
}