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_COLR_TABLE_HH
26 #define HB_OT_COLOR_COLR_TABLE_HH
28 #include "hb-open-type-private.hh"
32 * http://www.microsoft.com/typography/otspec/colr.htm
35 #define HB_OT_TAG_COLR HB_TAG('C','O','L','R')
44 inline bool sanitize (hb_sanitize_context_t *c) const
46 TRACE_SANITIZE (this);
47 return_trace (c->check_struct (this));
51 GlyphID gID; /* Glyph ID of layer glyph */
52 HBUINT16 paletteIndex; /* Index value to use with a selected color palette */
54 DEFINE_SIZE_STATIC (4);
57 struct BaseGlyphRecord
61 inline bool sanitize (hb_sanitize_context_t *c) const
63 TRACE_SANITIZE (this);
64 return_trace (c->check_struct (this));
68 GlyphID gID; /* Glyph ID of reference glyph */
69 HBUINT16 firstLayerIndex; /* Index to the layer record */
70 HBUINT16 numLayers; /* Number of color layers associated with this glyph */
72 DEFINE_SIZE_STATIC (6);
77 static const hb_tag_t tableTag = HB_OT_TAG_COLR;
79 inline bool sanitize (hb_sanitize_context_t *c) const
81 TRACE_SANITIZE (this);
82 if (!(c->check_struct (this) &&
83 c->check_array ((const void*) &layerRecordsOffsetZ, sizeof (LayerRecord), numLayerRecords) &&
84 c->check_array ((const void*) &baseGlyphRecordsZ, sizeof (BaseGlyphRecord), numBaseGlyphRecords)))
87 const BaseGlyphRecord* base_glyph_records = &baseGlyphRecordsZ (this);
88 for (unsigned int i = 0; i < numBaseGlyphRecords; ++i)
89 if (base_glyph_records[i].firstLayerIndex +
90 base_glyph_records[i].numLayers > numLayerRecords)
96 inline bool get_base_glyph_record (
97 hb_codepoint_t glyph_id, unsigned int &first_layer, unsigned int &num_layers) const
99 const BaseGlyphRecord* base_glyph_records = &baseGlyphRecordsZ (this);
100 unsigned int min = 0, max = numBaseGlyphRecords - 1;
103 unsigned int mid = (min + max) / 2;
104 hb_codepoint_t gID = base_glyph_records[mid].gID;
107 else if (gID < glyph_id)
111 first_layer = base_glyph_records[mid].firstLayerIndex;
112 num_layers = base_glyph_records[mid].numLayers;
119 inline void get_layer_record (int layer,
120 hb_codepoint_t &glyph_id, unsigned int &palette_index) const
122 const LayerRecord* records = &layerRecordsOffsetZ (this);
123 glyph_id = records[layer].gID;
124 palette_index = records[layer].paletteIndex;
128 HBUINT16 version; /* Table version number */
129 HBUINT16 numBaseGlyphRecords; /* Number of Base Glyph Records */
130 LOffsetTo<BaseGlyphRecord>
131 baseGlyphRecordsZ; /* Offset to Base Glyph records. */
132 LOffsetTo<LayerRecord>
133 layerRecordsOffsetZ; /* Offset to Layer Records */
134 HBUINT16 numLayerRecords; /* Number of Layer Records */
136 DEFINE_SIZE_STATIC (14);
142 #endif /* HB_OT_COLOR_COLR_TABLE_HH */