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-private.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
45 inline bool sanitize (hb_sanitize_context_t *c, const void* base) const
47 TRACE_SANITIZE (this);
48 return_trace (c->check_struct (this) &&
49 (base+svgDoc).sanitize (c, svgDocLength));
53 HBUINT16 startGlyphID; /* The first glyph ID in the range described by
54 * this index entry. */
55 HBUINT16 endGlyphID; /* The last glyph ID in the range described by
56 * this index entry. Must be >= startGlyphID. */
57 LOffsetTo<UnsizedArrayOf<HBUINT8> >
58 svgDoc; /* Offset from the beginning of the SVG Document Index
59 * to an SVG document. Must be non-zero. */
60 HBUINT32 svgDocLength; /* Length of the SVG document.
61 * Must be non-zero. */
63 DEFINE_SIZE_STATIC (12);
66 struct SVGDocumentIndex
70 inline bool sanitize (hb_sanitize_context_t *c) const
72 TRACE_SANITIZE (this);
73 return_trace (c->check_struct (this) &&
74 entries.sanitize (c, this));
78 ArrayOf<SVGDocumentIndexEntry>
79 entries; /* Array of SVG Document Index Entries. */
81 DEFINE_SIZE_ARRAY (2, entries);
86 static const hb_tag_t tableTag = HB_OT_TAG_SVG;
88 inline bool sanitize (hb_sanitize_context_t *c) const
90 TRACE_SANITIZE (this);
91 return_trace (likely (c->check_struct (this) &&
92 (this+svgDocIndex).sanitize (c)));
97 inline void init (hb_face_t *face)
99 OT::Sanitizer<OT::SVG> sanitizer;
100 svg_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_SVG));
101 svg_len = hb_blob_get_length (svg_blob);
102 svg = svg_blob->as<OT::SVG> ();
106 inline void fini (void)
108 hb_blob_destroy (svg_blob);
112 dump (void (*callback) (const uint8_t* data, unsigned int length,
113 unsigned int start_glyph, unsigned int end_glyph)) const
115 const SVGDocumentIndex &index = svg+svg->svgDocIndex;
116 const ArrayOf<SVGDocumentIndexEntry> &entries = index.entries;
117 for (unsigned int i = 0; i < entries.len; ++i)
119 const SVGDocumentIndexEntry &entry = entries[i];
120 callback ((const uint8_t*) &entry.svgDoc (&index), entry.svgDocLength,
121 entry.startGlyphID, entry.endGlyphID);
129 unsigned int svg_len;
133 HBUINT16 version; /* Table version (starting at 0). */
134 LOffsetTo<SVGDocumentIndex>
135 svgDocIndex; /* Offset (relative to the start of the SVG table) to the
136 * SVG Documents Index. Must be non-zero. */
137 HBUINT32 reserved; /* Set to 0. */
139 DEFINE_SIZE_STATIC (10);
145 #endif /* HB_OT_COLOR_SVG_TABLE_HH */