From f3336580dd0c6959a1871f92b4a37f7c0a4b2160 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 22 Oct 2018 16:16:21 -0700 Subject: [PATCH] [color] Use hb_array_t in CPAL Doesn't work though, ouch :(. Need to figure out if it's unreasonable to expect Null(T) inside hb_array_t to see the later specialization of Null for NameID. --- src/hb-open-type.hh | 3 ++- src/hb-ot-color-cpal-table.hh | 47 ++++++++++++++++++----------------- src/hb-static.cc | 1 + 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index be0d8b016..dc2f1f7c0 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -150,7 +150,8 @@ struct Tag : HBUINT32 typedef HBUINT16 GlyphID; /* Name-table index, same as uint16 (length = 16 bits) */ -typedef HBUINT16 NameID; +struct NameID : HBUINT16 {}; +DECLARE_NULL_NAMESPACE_BYTES (OT, NameID); /* Script/language-system/feature index */ struct Index : HBUINT16 { diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index beef2fce9..205613e47 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -53,10 +53,9 @@ struct CPALV1Tail unsigned int palette_index, unsigned int palette_count) const { - if (unlikely (palette_index >= palette_count || !paletteFlagsZ)) - return HB_OT_COLOR_PALETTE_FLAG_DEFAULT; - - return (hb_ot_color_palette_flags_t) (uint32_t) (base+paletteFlagsZ)[palette_index]; + if (!paletteFlagsZ) return HB_OT_COLOR_PALETTE_FLAG_DEFAULT; + return (hb_ot_color_palette_flags_t) (uint32_t) + hb_array_t ((base+paletteFlagsZ).arrayZ, palette_count)[palette_index]; } inline unsigned int @@ -64,10 +63,10 @@ struct CPALV1Tail unsigned int palette_index, unsigned int palette_count) const { - if (unlikely (palette_index >= palette_count || !paletteLabelZ)) - return HB_NAME_ID_INVALID; - - return (base+paletteLabelZ)[palette_index]; + /* XXX the Null(NameID) returned by hb_array_t is wrong. Figure out why + * and remove the explicit bound check. */ + if (!paletteLabelsZ || palette_index >= palette_count) return HB_NAME_ID_INVALID; + return hb_array_t ((base+paletteLabelsZ).arrayZ, palette_count)[palette_index]; } inline unsigned int @@ -75,21 +74,23 @@ struct CPALV1Tail unsigned int color_index, unsigned int color_count) const { - if (unlikely (color_index >= color_count || !paletteEntryLabelZ)) - return HB_NAME_ID_INVALID; - - return (base+paletteEntryLabelZ)[color_index]; + /* XXX the Null(NameID) returned by hb_array_t is wrong. Figure out why + * and remove the explicit bound check. */ + if (!colorLabelsZ || color_index >= color_count) return HB_NAME_ID_INVALID; + return hb_array_t ((base+colorLabelsZ).arrayZ, color_count)[color_index]; } public: - inline bool sanitize (hb_sanitize_context_t *c, const void *base, - unsigned int palette_count, unsigned int color_count) const + inline bool sanitize (hb_sanitize_context_t *c, + const void *base, + unsigned int palette_count, + unsigned int color_count) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - (!paletteFlagsZ || (base+paletteFlagsZ).sanitize (c, palette_count)) && - (!paletteLabelZ || (base+paletteLabelZ).sanitize (c, palette_count)) && - (!paletteEntryLabelZ || (base+paletteEntryLabelZ).sanitize (c, color_count))); + (!paletteFlagsZ || (base+paletteFlagsZ).sanitize (c, palette_count)) && + (!paletteLabelsZ || (base+paletteLabelsZ).sanitize (c, palette_count)) && + (!colorLabelsZ || (base+colorLabelsZ).sanitize (c, color_count))); } protected: @@ -97,13 +98,13 @@ struct CPALV1Tail paletteFlagsZ; /* Offset from the beginning of CPAL table to * the Palette Type Array. Set to 0 if no array * is provided. */ - LOffsetTo, false> - paletteLabelZ; /* Offset from the beginning of CPAL table to - * the Palette Labels Array. Set to 0 if no + LOffsetTo, false> + paletteLabelsZ; /* Offset from the beginning of CPAL table to + * the palette labels array. Set to 0 if no * array is provided. */ - LOffsetTo, false> - paletteEntryLabelZ; /* Offset from the beginning of CPAL table to - * the Palette Entry Label Array. Set to 0 + LOffsetTo, false> + colorLabelsZ; /* Offset from the beginning of CPAL table to + * the color labels array. Set to 0 * if no array is provided. */ public: DEFINE_SIZE_STATIC (12); diff --git a/src/hb-static.cc b/src/hb-static.cc index e5507960d..53889a5a6 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -40,6 +40,7 @@ hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; /*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; +DEFINE_NULL_NAMESPACE_BYTES (OT, NameID) = {0xFF,0xFF}; DEFINE_NULL_NAMESPACE_BYTES (OT, Index) = {0xFF,0xFF}; DEFINE_NULL_NAMESPACE_BYTES (OT, LangSys) = {0x00,0x00, 0xFF,0xFF, 0x00,0x00}; DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x00,0x01, 0x00,0x00, 0x00, 0x00};