2 * Copyright © 2018 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 #ifndef HB_OT_COLOR_SVG_TABLE_HH
26 #define HB_OT_COLOR_SVG_TABLE_HH
28 #include "hb-open-type.hh"
31 * SVG -- SVG (Scalable Vector Graphics)
32 * https://docs.microsoft.com/en-us/typography/opentype/spec/svg
35 #define HB_OT_TAG_SVG HB_TAG('S','V','G',' ')
41 struct SVGDocumentIndexEntry
43 int cmp (hb_codepoint_t g) const
44 { return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; }
46 hb_blob_t *reference_blob (hb_blob_t *svg_blob, unsigned int index_offset) const
48 return hb_blob_create_sub_blob (svg_blob,
49 index_offset + (unsigned int) svgDoc,
53 bool sanitize (hb_sanitize_context_t *c, const void *base) const
55 TRACE_SANITIZE (this);
56 return_trace (c->check_struct (this) &&
57 svgDoc.sanitize (c, base, svgDocLength));
61 HBUINT16 startGlyphID; /* The first glyph ID in the range described by
62 * this index entry. */
63 HBUINT16 endGlyphID; /* The last glyph ID in the range described by
64 * this index entry. Must be >= startGlyphID. */
65 LNNOffsetTo<UnsizedArrayOf<HBUINT8>>
66 svgDoc; /* Offset from the beginning of the SVG Document Index
67 * to an SVG document. Must be non-zero. */
68 HBUINT32 svgDocLength; /* Length of the SVG document.
69 * Must be non-zero. */
71 DEFINE_SIZE_STATIC (12);
76 static constexpr hb_tag_t tableTag = HB_OT_TAG_SVG;
78 bool has_data () const { return svgDocEntries; }
82 void init (hb_face_t *face)
83 { table = hb_sanitize_context_t ().reference_table<SVG> (face); }
84 void fini () { table.destroy (); }
86 hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const
88 return table->get_glyph_entry (glyph_id).reference_blob (table.get_blob (),
89 table->svgDocEntries);
92 bool has_data () const { return table->has_data (); }
95 hb_blob_ptr_t<SVG> table;
98 const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const
99 { return (this+svgDocEntries).bsearch (glyph_id); }
101 bool sanitize (hb_sanitize_context_t *c) const
103 TRACE_SANITIZE (this);
104 return_trace (likely (c->check_struct (this) &&
105 (this+svgDocEntries).sanitize_shallow (c)));
109 HBUINT16 version; /* Table version (starting at 0). */
110 LOffsetTo<SortedArrayOf<SVGDocumentIndexEntry>>
111 svgDocEntries; /* Offset (relative to the start of the SVG table) to the
112 * SVG Documents Index. Must be non-zero. */
113 /* Array of SVG Document Index Entries. */
114 HBUINT32 reserved; /* Set to 0. */
116 DEFINE_SIZE_STATIC (10);
119 struct SVG_accelerator_t : SVG::accelerator_t {};
124 #endif /* HB_OT_COLOR_SVG_TABLE_HH */