From fb0f3e3767b488651f13978c1fd8651aefdd6b83 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Mar 2018 20:38:40 +0100 Subject: [PATCH] [sbix] Clean up --- src/hb-ot-color-sbix-table.hh | 70 ++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 5f6a0ecbb..c0d8f9b3d 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -34,33 +34,43 @@ namespace OT { struct SBIXGlyph { - friend struct sbix; - - protected: - HBINT16 originOffsetX; - HBINT16 originOffsetY; - unsigned char tag[4]; - HBUINT8 data[VAR]; + HBINT16 xOffset; /* The horizontal (x-axis) offset from the left + * edge of the graphic to the glyph’s origin. + * That is, the x-coordinate of the point on the + * baseline at the left edge of the glyph. */ + HBINT16 yOffset; /* The vertical (y-axis) offset from the bottom + * edge of the graphic to the glyph’s origin. + * That is, the y-coordinate of the point on the + * baseline at the left edge of the glyph. */ + Tag graphicType; /* Indicates the format of the embedded graphic + * data: one of 'jpg ', 'png ' or 'tiff', or the + * special format 'dupe'. */ + HBUINT8 data[VAR]; /* The actual embedded graphic data. The total + * length is inferred from sequential entries in + * the glyphDataOffsets array and the fixed size + * (8 bytes) of the preceding fields. */ public: - DEFINE_SIZE_STATIC (9); + DEFINE_SIZE_ARRAY (8, data); }; -struct ImageTable +struct SBIXStrike { - friend struct sbix; - inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - c->check_array (imageOffsetsZ, sizeof (HBUINT32), c->num_glyphs) && - c->check_range (this, imageOffsetsZ[c->num_glyphs])); + c->check_array (imageOffsetsZ, + sizeof (HBUINT32), + 1 + c->num_glyphs)); } + HBUINT16 ppem; /* The PPEM size for which this strike was designed. */ + HBUINT16 resolution; /* The device pixel density (in PPI) for which this + * strike was designed. (E.g., 96 PPI, 192 PPI.) */ protected: - HBUINT16 ppem; - HBUINT16 resolution; LOffsetTo imageOffsetsZ[VAR]; // VAR=maxp.numGlyphs + 1 + /* Offset from the beginning of the strike data header + * to bitmap data for an individual glyph ID. */ public: DEFINE_SIZE_STATIC (8); }; @@ -87,40 +97,34 @@ struct sbix inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (!(c->check_struct (this) && imageTables.sanitize (c, this))) - return_trace (false); - - for (unsigned int i = 0; i < imageTables.len; ++i) - if (!(imageTables[i].sanitize (c, this))) - return_trace (false); - - // dump (c->num_glyphs, 8); - - return_trace (true); + return_trace (c->check_struct (this) && strikes.sanitize (c, this)); } // inline void dump (unsigned int num_glyphs, unsigned int group) const // { - // const ImageTable &imageTable = imageTables[group](this); + // const SBIXStrike &strike = strikes[group](this); // for (unsigned int i = 0; i < num_glyphs; ++i) - // if (imageTable.imageOffsetsZ[i + 1] - imageTable.imageOffsetsZ[i] > 0) + // if (strike.imageOffsetsZ[i + 1] - strike.imageOffsetsZ[i] > 0) // { - // const SBIXGlyph &sbixGlyph = imageTable.imageOffsetsZ[i]((const void *) &imageTable); + // const SBIXGlyph &sbixGlyph = strike.imageOffsetsZ[i]((const void *) &strike); // char outName[255]; // sprintf (outName, "out/%d-%d.png", group, i); // FILE *f = fopen (outName, "wb"); // fwrite (sbixGlyph.data, 1, - // imageTable.imageOffsetsZ[i + 1] - imageTable.imageOffsetsZ[i] - 8, f); + // strike.imageOffsetsZ[i + 1] - strike.imageOffsetsZ[i] - 8, f); // fclose (f); // } // } protected: - HBUINT16 version; - HBUINT16 flags; - ArrayOf, HBUINT32> imageTables; + HBUINT16 version; /* Table version number — set to 1 */ + HBUINT16 flags; /* Bit 0: Set to 1. Bit 1: Draw outlines. + * Bits 2 to 15: reserved (set to 0). */ + ArrayOf, HBUINT32> + strikes; /* Offsets from the beginning of the 'sbix' + * table to data for each individual bitmap strike. */ public: - DEFINE_SIZE_ARRAY (8, imageTables); + DEFINE_SIZE_ARRAY (8, strikes); }; } /* namespace OT */