From 5cb1ce868138a10c0663a18c3891bc717aa4bc64 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 25 Oct 2018 22:39:58 +0330 Subject: [PATCH] [svg] Collapse SVGDocumentIndex into SVG --- src/hb-ot-color-svg-table.hh | 54 ++++++++++++------------------------ src/hb-ot-color.cc | 2 +- test/api/test-ot-color.c | 2 +- 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 9e03ef762..4ef380745 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -50,7 +50,7 @@ struct SVGDocumentIndexEntry return b->cmp (*a); } - inline hb_blob_t* create_blob (hb_blob_t *svg_blob, unsigned int index_offset) const + inline hb_blob_t* reference_blob (hb_blob_t *svg_blob, unsigned int index_offset) const { if (svgDocLength == 0) return hb_blob_get_empty (); return hb_blob_create_sub_blob (svg_blob, (unsigned int) svgDoc + index_offset, @@ -77,35 +77,6 @@ struct SVGDocumentIndexEntry DEFINE_SIZE_STATIC (12); }; -struct SVGDocumentIndex -{ - friend struct SVG; - - inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const - { - const SVGDocumentIndexEntry *rec; - rec = (SVGDocumentIndexEntry *) bsearch (&glyph_id, - &entries.arrayZ, - entries.len, - sizeof (SVGDocumentIndexEntry), - SVGDocumentIndexEntry::cmp); - return likely (rec) ? *rec : Null(SVGDocumentIndexEntry); - } - - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - entries.sanitize_shallow (c)); - } - - protected: - ArrayOf - entries; /* Array of SVG Document Index Entries. */ - public: - DEFINE_SIZE_ARRAY (2, entries); -}; - struct SVG { static const hb_tag_t tableTag = HB_OT_TAG_SVG; @@ -124,12 +95,11 @@ struct SVG hb_blob_destroy (svg_blob); } - inline hb_blob_t* create_blob_for_glyph (hb_codepoint_t glyph_id) const + inline hb_blob_t* reference_blob_for_glyph (hb_codepoint_t glyph_id) const { if (unlikely (svg_len == 0)) return hb_blob_get_empty (); - return (svg+svg->svgDocIndex).get_glyph_entry (glyph_id).create_blob (svg_blob, - svg->svgDocIndex); + return svg->get_glyph_entry (glyph_id).reference_blob (svg_blob, svg->svgDocEntries); } inline bool has_data () const @@ -142,18 +112,30 @@ struct SVG unsigned int svg_len; }; + inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const + { + const SVGDocumentIndexEntry *rec; + rec = (SVGDocumentIndexEntry *) bsearch (&glyph_id, + &(this+svgDocEntries).arrayZ, + (this+svgDocEntries).len, + sizeof (SVGDocumentIndexEntry), + SVGDocumentIndexEntry::cmp); + return likely (rec) ? *rec : Null(SVGDocumentIndexEntry); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); return_trace (likely (c->check_struct (this) && - (this+svgDocIndex).sanitize (c))); + (this+svgDocEntries).sanitize_shallow (c))); } protected: HBUINT16 version; /* Table version (starting at 0). */ - LOffsetTo - svgDocIndex; /* Offset (relative to the start of the SVG table) to the + LOffsetTo > + svgDocEntries; /* Offset (relative to the start of the SVG table) to the * SVG Documents Index. Must be non-zero. */ + /* Array of SVG Document Index Entries. */ HBUINT32 reserved; /* Set to 0. */ public: DEFINE_SIZE_STATIC (10); diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index cdfbaade1..3d9f1c1ba 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -270,5 +270,5 @@ hb_ot_color_has_svg (hb_face_t *face) hb_blob_t * hb_ot_color_glyph_svg_create_blob (hb_face_t *face, hb_codepoint_t glyph) { - return _get_svg (face).create_blob_for_glyph (glyph); + return _get_svg (face).reference_blob_for_glyph (glyph); } diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c index 8e4ec0a06..13a25b0b8 100644 --- a/test/api/test-ot-color.c +++ b/test/api/test-ot-color.c @@ -388,7 +388,7 @@ test_hb_ot_color_svg (void) g_assert (strncmp (data + 140, "", 5) == 0); hb_blob_destroy (blob); - blob = hb_ot_color_glyph_svg_create_blob (empty, 0, &start_glyph, &end_glyph); + blob = hb_ot_color_glyph_svg_create_blob (empty, 0); g_assert (hb_blob_get_length (blob) == 0); }