Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 1 | /* |
| 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 Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 28 | #include "hb-open-type.hh" |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 29 | |
| 30 | /* |
Ebrahim Byagowi | a02c3ee | 2018-04-12 13:38:19 +0430 | [diff] [blame] | 31 | * SVG -- SVG (Scalable Vector Graphics) |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 32 | * 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 Byagowi | a02c3ee | 2018-04-12 13:38:19 +0430 | [diff] [blame] | 37 | |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 38 | namespace OT { |
| 39 | |
| 40 | |
| 41 | struct SVGDocumentIndexEntry |
| 42 | { |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 43 | friend struct SVG; |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 44 | |
| 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 Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 49 | (base+svgDoc).sanitize (c, svgDocLength)); |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | protected: |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 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. */ |
Behdad Esfahbod | 10642b3 | 2018-09-15 19:43:33 +0200 | [diff] [blame] | 57 | LOffsetTo<UnsizedArrayOf<HBUINT8>, false> |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 58 | svgDoc; /* Offset from the beginning of the SVG Document Index |
| 59 | * to an SVG document. Must be non-zero. */ |
Ebrahim Byagowi | 28f25f3 | 2018-03-12 14:00:11 +0330 | [diff] [blame] | 60 | HBUINT32 svgDocLength; /* Length of the SVG document. |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 61 | * Must be non-zero. */ |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 62 | public: |
| 63 | DEFINE_SIZE_STATIC (12); |
| 64 | }; |
| 65 | |
| 66 | struct SVGDocumentIndex |
| 67 | { |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 68 | friend struct SVG; |
| 69 | |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 70 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 71 | { |
| 72 | TRACE_SANITIZE (this); |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 73 | return_trace (c->check_struct (this) && |
Ebrahim Byagowi | a47070c | 2018-04-18 12:09:37 +0430 | [diff] [blame] | 74 | entries.sanitize (c, this)); |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 75 | } |
| 76 | |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 77 | protected: |
Ebrahim Byagowi | 28f25f3 | 2018-03-12 14:00:11 +0330 | [diff] [blame] | 78 | ArrayOf<SVGDocumentIndexEntry> |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 79 | entries; /* Array of SVG Document Index Entries. */ |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 80 | public: |
| 81 | DEFINE_SIZE_ARRAY (2, entries); |
| 82 | }; |
| 83 | |
| 84 | struct 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 Byagowi | a47070c | 2018-04-18 12:09:37 +0430 | [diff] [blame] | 91 | return_trace (likely (c->check_struct (this) && |
| 92 | (this+svgDocIndex).sanitize (c))); |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 93 | } |
| 94 | |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 95 | struct accelerator_t |
| 96 | { |
| 97 | inline void init (hb_face_t *face) |
| 98 | { |
Behdad Esfahbod | 36ed163 | 2018-07-23 11:57:45 -0700 | [diff] [blame] | 99 | svg_blob = hb_sanitize_context_t().reference_table<SVG> (face); |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 100 | svg_len = hb_blob_get_length (svg_blob); |
Behdad Esfahbod | 36ed163 | 2018-07-23 11:57:45 -0700 | [diff] [blame] | 101 | svg = svg_blob->as<SVG> (); |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | inline void fini (void) |
| 105 | { |
| 106 | hb_blob_destroy (svg_blob); |
| 107 | } |
| 108 | |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 109 | inline void |
| 110 | dump (void (*callback) (const uint8_t* data, unsigned int length, |
| 111 | unsigned int start_glyph, unsigned int end_glyph)) const |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 112 | { |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 113 | const SVGDocumentIndex &index = svg+svg->svgDocIndex; |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 114 | const ArrayOf<SVGDocumentIndexEntry> &entries = index.entries; |
| 115 | for (unsigned int i = 0; i < entries.len; ++i) |
| 116 | { |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 117 | const SVGDocumentIndexEntry &entry = entries[i]; |
| 118 | callback ((const uint8_t*) &entry.svgDoc (&index), entry.svgDocLength, |
| 119 | entry.startGlyphID, entry.endGlyphID); |
Ebrahim Byagowi | 8fd5542 | 2018-03-27 16:57:09 +0430 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | private: |
| 124 | hb_blob_t *svg_blob; |
| 125 | const SVG *svg; |
| 126 | |
| 127 | unsigned int svg_len; |
| 128 | }; |
| 129 | |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 130 | protected: |
Ebrahim Byagowi | 28f25f3 | 2018-03-12 14:00:11 +0330 | [diff] [blame] | 131 | HBUINT16 version; /* Table version (starting at 0). */ |
| 132 | LOffsetTo<SVGDocumentIndex> |
Ebrahim Byagowi | f8bb582 | 2018-04-11 17:13:20 +0430 | [diff] [blame] | 133 | svgDocIndex; /* Offset (relative to the start of the SVG table) to the |
Ebrahim Byagowi | 28f25f3 | 2018-03-12 14:00:11 +0330 | [diff] [blame] | 134 | * SVG Documents Index. Must be non-zero. */ |
| 135 | HBUINT32 reserved; /* Set to 0. */ |
Ebrahim Byagowi | 218fa71 | 2018-03-10 11:13:52 +0330 | [diff] [blame] | 136 | public: |
| 137 | DEFINE_SIZE_STATIC (10); |
| 138 | }; |
| 139 | |
| 140 | } /* namespace OT */ |
| 141 | |
| 142 | |
| 143 | #endif /* HB_OT_COLOR_SVG_TABLE_HH */ |