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 OT_COLOR_SVG_SVG_HH
26 #define OT_COLOR_SVG_SVG_HH
28 #include "../../../hb-open-type.hh"
29 #include "../../../hb-blob.hh"
30 #include "../../../hb-paint.hh"
33 * SVG -- SVG (Scalable Vector Graphics)
34 * https://docs.microsoft.com/en-us/typography/opentype/spec/svg
37 #define HB_OT_TAG_SVG HB_TAG('S','V','G',' ')
43 struct SVGDocumentIndexEntry
45 int cmp (hb_codepoint_t g) const
46 { return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; }
48 hb_blob_t *reference_blob (hb_blob_t *svg_blob, unsigned int index_offset) const
50 return hb_blob_create_sub_blob (svg_blob,
51 index_offset + (unsigned int) svgDoc,
55 bool sanitize (hb_sanitize_context_t *c, const void *base) const
57 TRACE_SANITIZE (this);
58 return_trace (c->check_struct (this) &&
59 svgDoc.sanitize (c, base, svgDocLength));
63 HBUINT16 startGlyphID; /* The first glyph ID in the range described by
64 * this index entry. */
65 HBUINT16 endGlyphID; /* The last glyph ID in the range described by
66 * this index entry. Must be >= startGlyphID. */
67 NNOffset32To<UnsizedArrayOf<HBUINT8>>
68 svgDoc; /* Offset from the beginning of the SVG Document Index
69 * to an SVG document. Must be non-zero. */
70 HBUINT32 svgDocLength; /* Length of the SVG document.
71 * Must be non-zero. */
73 DEFINE_SIZE_STATIC (12);
78 static constexpr hb_tag_t tableTag = HB_OT_TAG_SVG;
80 bool has_data () const { return svgDocEntries; }
84 accelerator_t (hb_face_t *face)
85 { table = hb_sanitize_context_t ().reference_table<SVG> (face); }
86 ~accelerator_t () { table.destroy (); }
88 hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const
90 return table->get_glyph_entry (glyph_id).reference_blob (table.get_blob (),
91 table->svgDocEntries);
94 bool has_data () const { return table->has_data (); }
96 bool paint_glyph (hb_font_t *font HB_UNUSED, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const
101 hb_blob_t *blob = reference_blob_for_glyph (glyph);
103 if (blob == hb_blob_get_empty ())
109 HB_PAINT_IMAGE_FORMAT_SVG,
113 hb_blob_destroy (blob);
118 hb_blob_ptr_t<SVG> table;
120 DEFINE_SIZE_STATIC (sizeof (hb_blob_ptr_t<SVG>));
123 const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const
124 { return (this+svgDocEntries).bsearch (glyph_id); }
126 bool sanitize (hb_sanitize_context_t *c) const
128 TRACE_SANITIZE (this);
129 return_trace (likely (c->check_struct (this) &&
130 (this+svgDocEntries).sanitize_shallow (c)));
134 HBUINT16 version; /* Table version (starting at 0). */
135 Offset32To<SortedArray16Of<SVGDocumentIndexEntry>>
136 svgDocEntries; /* Offset (relative to the start of the SVG table) to the
137 * SVG Documents Index. Must be non-zero. */
138 /* Array of SVG Document Index Entries. */
139 HBUINT32 reserved; /* Set to 0. */
141 DEFINE_SIZE_STATIC (10);
144 struct SVG_accelerator_t : SVG::accelerator_t {
145 SVG_accelerator_t (hb_face_t *face) : SVG::accelerator_t (face) {}
151 #endif /* OT_COLOR_SVG_SVG_HH */