Skip to content

Commit

Permalink
[sbix] Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Mar 11, 2018
1 parent 218fa71 commit fb0f3e3
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions src/hb-ot-color-sbix-table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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]));

This comment has been minimized.

Copy link
@ebraminio

ebraminio Mar 11, 2018

Collaborator

Hmm, we should have someway to check imageOffsetsZ values themselves are in range also I guess. This check wanted to check that but now that I am thinking it was based on the assumption that the list is ordered, which can be not the case on a malicious font.

This comment has been minimized.

Copy link
@ebraminio

ebraminio Mar 12, 2018

Collaborator
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<SBIXGlyph> 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);
};
Expand All @@ -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<LOffsetTo<ImageTable>, 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<LOffsetTo<SBIXStrike>, 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 */
Expand Down

1 comment on commit fb0f3e3

@ebraminio
Copy link
Collaborator

@ebraminio ebraminio commented on fb0f3e3 Mar 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thank you Behdad. I hope you find some use on them also :)

Something perhaps is not a concern for HarfBuzz. Apple Color Emoji is a huge font and most of it is on sbix, is there maybe someway not to have all of it on RAM? I guess on the case of Chrome that probably will be concerning, or maybe not, as it will be paged on disk anyway.

Please sign in to comment.