blob: 53d466846a4c6367a4b991a54176eabed3958eed [file] [log] [blame]
Ebrahim Byagowi218fa712018-03-10 11:13:52 +03301/*
2 * Copyright © 2018 Ebrahim Byagowi
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
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.
11 *
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
16 * DAMAGE.
17 *
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.
23 */
24
25#ifndef HB_OT_COLOR_SVG_TABLE_HH
26#define HB_OT_COLOR_SVG_TABLE_HH
27
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070028#include "hb-open-type.hh"
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033029
30/*
Ebrahim Byagowia02c3ee2018-04-12 13:38:19 +043031 * SVG -- SVG (Scalable Vector Graphics)
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033032 * https://docs.microsoft.com/en-us/typography/opentype/spec/svg
33 */
34
35#define HB_OT_TAG_SVG HB_TAG('S','V','G',' ')
36
Ebrahim Byagowia02c3ee2018-04-12 13:38:19 +043037
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033038namespace OT {
39
40
41struct SVGDocumentIndexEntry
42{
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +043043 friend struct SVG;
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033044
45 inline bool sanitize (hb_sanitize_context_t *c, const void* base) const
46 {
47 TRACE_SANITIZE (this);
48 return_trace (c->check_struct (this) &&
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +043049 (base+svgDoc).sanitize (c, svgDocLength));
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033050 }
51
52 protected:
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +043053 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. */
Behdad Esfahbod10642b32018-09-15 19:43:33 +020057 LOffsetTo<UnsizedArrayOf<HBUINT8>, false>
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +043058 svgDoc; /* Offset from the beginning of the SVG Document Index
59 * to an SVG document. Must be non-zero. */
Ebrahim Byagowi28f25f32018-03-12 14:00:11 +033060 HBUINT32 svgDocLength; /* Length of the SVG document.
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +043061 * Must be non-zero. */
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033062 public:
63 DEFINE_SIZE_STATIC (12);
64};
65
66struct SVGDocumentIndex
67{
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +043068 friend struct SVG;
69
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033070 inline bool sanitize (hb_sanitize_context_t *c) const
71 {
72 TRACE_SANITIZE (this);
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033073 return_trace (c->check_struct (this) &&
Ebrahim Byagowia47070c2018-04-18 12:09:37 +043074 entries.sanitize (c, this));
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033075 }
76
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033077 protected:
Ebrahim Byagowi28f25f32018-03-12 14:00:11 +033078 ArrayOf<SVGDocumentIndexEntry>
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +043079 entries; /* Array of SVG Document Index Entries. */
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033080 public:
81 DEFINE_SIZE_ARRAY (2, entries);
82};
83
84struct SVG
85{
86 static const hb_tag_t tableTag = HB_OT_TAG_SVG;
87
88 inline bool sanitize (hb_sanitize_context_t *c) const
89 {
90 TRACE_SANITIZE (this);
Ebrahim Byagowia47070c2018-04-18 12:09:37 +043091 return_trace (likely (c->check_struct (this) &&
92 (this+svgDocIndex).sanitize (c)));
Ebrahim Byagowi218fa712018-03-10 11:13:52 +033093 }
94
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +043095 struct accelerator_t
96 {
97 inline void init (hb_face_t *face)
98 {
Behdad Esfahbod36ed1632018-07-23 11:57:45 -070099 svg_blob = hb_sanitize_context_t().reference_table<SVG> (face);
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +0430100 svg_len = hb_blob_get_length (svg_blob);
Behdad Esfahbod36ed1632018-07-23 11:57:45 -0700101 svg = svg_blob->as<SVG> ();
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +0430102 }
103
104 inline void fini (void)
105 {
106 hb_blob_destroy (svg_blob);
107 }
108
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +0430109 inline void
110 dump (void (*callback) (const uint8_t* data, unsigned int length,
111 unsigned int start_glyph, unsigned int end_glyph)) const
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +0430112 {
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +0430113 const SVGDocumentIndex &index = svg+svg->svgDocIndex;
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +0430114 const ArrayOf<SVGDocumentIndexEntry> &entries = index.entries;
115 for (unsigned int i = 0; i < entries.len; ++i)
116 {
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +0430117 const SVGDocumentIndexEntry &entry = entries[i];
118 callback ((const uint8_t*) &entry.svgDoc (&index), entry.svgDocLength,
119 entry.startGlyphID, entry.endGlyphID);
Ebrahim Byagowi8fd55422018-03-27 16:57:09 +0430120 }
121 }
122
123 private:
124 hb_blob_t *svg_blob;
125 const SVG *svg;
126
127 unsigned int svg_len;
128 };
129
Ebrahim Byagowi218fa712018-03-10 11:13:52 +0330130 protected:
Ebrahim Byagowi28f25f32018-03-12 14:00:11 +0330131 HBUINT16 version; /* Table version (starting at 0). */
132 LOffsetTo<SVGDocumentIndex>
Ebrahim Byagowif8bb5822018-04-11 17:13:20 +0430133 svgDocIndex; /* Offset (relative to the start of the SVG table) to the
Ebrahim Byagowi28f25f32018-03-12 14:00:11 +0330134 * SVG Documents Index. Must be non-zero. */
135 HBUINT32 reserved; /* Set to 0. */
Ebrahim Byagowi218fa712018-03-10 11:13:52 +0330136 public:
137 DEFINE_SIZE_STATIC (10);
138};
139
140} /* namespace OT */
141
142
143#endif /* HB_OT_COLOR_SVG_TABLE_HH */