[HarfBuzz] harfbuzz: Branch 'master' - 2 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Sat Mar 3 18:41:38 UTC 2018
src/hb-ot-colr-table.hh | 50 ++++++++++++++++++++++++++++++++++++++----------
src/hb-ot-cpal-table.hh | 18 ++++++++++++++---
2 files changed, 55 insertions(+), 13 deletions(-)
New commits:
commit 48ed15a2bcdc1999e2d39fdcb2644ba4c3beccfe
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Sat Mar 3 22:00:29 2018 +0330
[COLR/CPAL] Provide enough helper for rasterization (#855)
diff --git a/src/hb-ot-colr-table.hh b/src/hb-ot-colr-table.hh
index dae843ec..0a2b80e5 100644
--- a/src/hb-ot-colr-table.hh
+++ b/src/hb-ot-colr-table.hh
@@ -39,12 +39,15 @@ namespace OT {
struct LayerRecord
{
+ friend struct COLR;
+
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this));
}
+ protected:
GlyphID gID; /* Glyph ID of layer glyph */
HBUINT16 paletteIndex; /* Index value to use with a selected color palette */
public:
@@ -53,12 +56,15 @@ struct LayerRecord
struct BaseGlyphRecord
{
+ friend struct COLR;
+
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this));
}
+ protected:
GlyphID gID; /* Glyph ID of reference glyph */
HBUINT16 firstLayerIndex; /* Index to the layer record */
HBUINT16 numLayers; /* Number of color layers associated with this glyph */
@@ -73,9 +79,44 @@ struct COLR
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
- return_trace (c->check_struct (this) &&
- c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords) &&
- c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords));
+ if (!(c->check_struct (this) &&
+ c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords) &&
+ c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords)))
+ return_trace (false);
+
+ const BaseGlyphRecord* base_glyph_records = &baseGlyphRecords (this);
+ for (unsigned int i = 0; i < numBaseGlyphRecords; ++i)
+ if (base_glyph_records[i].firstLayerIndex +
+ base_glyph_records[i].numLayers > numLayerRecords)
+ return_trace (false);
+
+ /* XXX values of LayerRecord structs should be sanitized */
+
+ return_trace (true);
+ }
+
+ inline const bool get_base_glyph_record (
+ hb_codepoint_t glyph_id, unsigned int &first_layer, unsigned int &num_layers) const
+ {
+ /* TODO replace with bsearch */
+ const BaseGlyphRecord* base_glyph_records = &baseGlyphRecords (this);
+ unsigned int records = numBaseGlyphRecords;
+ for (unsigned int i = 0; i < records; ++i)
+ if (base_glyph_records[i].gID == glyph_id)
+ {
+ first_layer = base_glyph_records[i].firstLayerIndex;
+ num_layers = base_glyph_records[i].numLayers;
+ return true;
+ }
+ return false;
+ }
+
+ inline void get_layer_record (int layer,
+ hb_codepoint_t &glyph_id, unsigned int &palette_index) const
+ {
+ const LayerRecord* records = &layerRecordsOffset (this);
+ glyph_id = records[layer].gID;
+ palette_index = records[layer].paletteIndex;
}
protected:
diff --git a/src/hb-ot-cpal-table.hh b/src/hb-ot-cpal-table.hh
index 740a94b3..5adbbea4 100644
--- a/src/hb-ot-cpal-table.hh
+++ b/src/hb-ot-cpal-table.hh
@@ -42,12 +42,15 @@ namespace OT {
struct ColorRecord
{
+ friend struct CPAL;
+
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (true);
}
+ protected:
HBUINT8 blue;
HBUINT8 green;
HBUINT8 red;
@@ -74,14 +77,14 @@ struct CPALV1Tail
inline hb_ot_color_palette_flags_t
get_palette_flags (const void *base, unsigned int palette) const
{
- const HBUINT32* flags = (const HBUINT32*) (const void*) &paletteFlags (base);
+ const HBUINT32* flags = &paletteFlags (base);
return (hb_ot_color_palette_flags_t) (uint32_t) flags[palette];
}
inline unsigned int
get_palette_name_id (const void *base, unsigned int palette) const
{
- const HBUINT16* name_ids = (const HBUINT16*) (const void*) &paletteLabel (base);
+ const HBUINT16* name_ids = &paletteLabel (base);
return name_ids[palette];
}
@@ -148,9 +151,18 @@ struct CPAL
return numPalettes;
}
+ inline void get_color_record (int palette_index, uint8_t &r, uint8_t &g,
+ uint8_t &b, uint8_t &a) const
+ {
+ // We should check if palette_index is in range as it is not done on COLR sanitization
+ r = colorRecords[palette_index].red;
+ g = colorRecords[palette_index].green;
+ b = colorRecords[palette_index].blue;
+ a = colorRecords[palette_index].alpha;
+ }
+
protected:
HBUINT16 version;
-
/* Version 0 */
HBUINT16 numPaletteEntries;
HBUINT16 numPalettes;
commit 432758a7ac3c1a857e67069f157efbf4ebf5521b
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Sat Mar 3 01:05:59 2018 +0330
[COLR] Revert previous sanitization on the table
That sanitization wasn't right, firstLayerIndex is an index from beginning of the Layer Records
not the table itself.
diff --git a/src/hb-ot-colr-table.hh b/src/hb-ot-colr-table.hh
index 08a39a99..dae843ec 100644
--- a/src/hb-ot-colr-table.hh
+++ b/src/hb-ot-colr-table.hh
@@ -53,17 +53,14 @@ struct LayerRecord
struct BaseGlyphRecord
{
- inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
+ inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
- return_trace (c->check_struct (this) &&
- firstLayerIndex.sanitize (c, base) &&
- c->check_array ((const void*) &firstLayerIndex, sizeof (LayerRecord), numLayers));
+ return_trace (c->check_struct (this));
}
GlyphID gID; /* Glyph ID of reference glyph */
- OffsetTo<LayerRecord>
- firstLayerIndex; /* Index to the layer record */
+ HBUINT16 firstLayerIndex; /* Index to the layer record */
HBUINT16 numLayers; /* Number of color layers associated with this glyph */
public:
DEFINE_SIZE_STATIC (6);
@@ -76,17 +73,9 @@ struct COLR
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
- if (!(c->check_struct (this) &&
- c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords) &&
- c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords)))
- return_trace (false);
-
- const BaseGlyphRecord *base_glyph_records = &baseGlyphRecords (this);
- for (unsigned int i = 0; i < numBaseGlyphRecords; ++i)
- if (!(base_glyph_records[i].sanitize (c, this)))
- return_trace (false);
-
- return_trace (true);
+ return_trace (c->check_struct (this) &&
+ c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords) &&
+ c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords));
}
protected:
More information about the HarfBuzz
mailing list