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_SBIX_TABLE_HH
26 #define HB_OT_COLOR_SBIX_TABLE_HH
28 #include "hb-open-type-private.hh"
31 * sbix -- Standard Bitmap Graphics
32 * https://docs.microsoft.com/en-us/typography/opentype/spec/sbix
33 * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6sbix.html
35 #define HB_OT_TAG_sbix HB_TAG('s','b','i','x')
43 HBINT16 xOffset; /* The horizontal (x-axis) offset from the left
44 * edge of the graphic to the glyph’s origin.
45 * That is, the x-coordinate of the point on the
46 * baseline at the left edge of the glyph. */
47 HBINT16 yOffset; /* The vertical (y-axis) offset from the bottom
48 * edge of the graphic to the glyph’s origin.
49 * That is, the y-coordinate of the point on the
50 * baseline at the left edge of the glyph. */
51 Tag graphicType; /* Indicates the format of the embedded graphic
52 * data: one of 'jpg ', 'png ' or 'tiff', or the
53 * special format 'dupe'. */
54 UnsizedArrayOf<HBUINT8>
55 data; /* The actual embedded graphic data. The total
56 * length is inferred from sequential entries in
57 * the glyphDataOffsets array and the fixed size
58 * (8 bytes) of the preceding fields. */
60 DEFINE_SIZE_ARRAY (8, data);
67 inline bool sanitize (hb_sanitize_context_t *c) const
69 TRACE_SANITIZE (this);
70 return_trace (c->check_struct (this) &&
71 imageOffsetsZ.sanitize_shallow (c, c->num_glyphs + 1));
75 HBUINT16 ppem; /* The PPEM size for which this strike was designed. */
76 HBUINT16 resolution; /* The device pixel density (in PPI) for which this
77 * strike was designed. (E.g., 96 PPI, 192 PPI.) */
78 UnsizedArrayOf<LOffsetTo<SBIXGlyph> >
79 imageOffsetsZ; /* Offset from the beginning of the strike data header
80 * to bitmap data for an individual glyph ID. */
82 DEFINE_SIZE_STATIC (8);
87 static const hb_tag_t tableTag = HB_OT_TAG_sbix;
89 inline bool sanitize (hb_sanitize_context_t *c) const
91 TRACE_SANITIZE (this);
92 return_trace (likely (c->check_struct (this) && strikes.sanitize (c, this)));
97 inline void init (hb_face_t *face)
99 num_glyphs = hb_face_get_glyph_count (face);
101 OT::Sanitizer<OT::sbix> sanitizer;
102 sanitizer.set_num_glyphs (num_glyphs);
103 sbix_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_sbix));
104 sbix_len = hb_blob_get_length (sbix_blob);
105 sbix_table = sbix_blob->as<OT::sbix> ();
109 inline void fini (void)
111 hb_blob_destroy (sbix_blob);
114 inline void dump (void (*callback) (const uint8_t* data, unsigned int length,
115 unsigned int group, unsigned int gid)) const
117 for (unsigned group = 0; group < sbix_table->strikes.len; ++group)
119 const SBIXStrike &strike = sbix_table->strikes[group](sbix_table);
120 for (unsigned int glyph = 0; glyph < num_glyphs; ++glyph)
121 if (strike.imageOffsetsZ[glyph + 1] - strike.imageOffsetsZ[glyph] > 0)
123 const SBIXGlyph &sbixGlyph = strike.imageOffsetsZ[glyph]((const void *) &strike);
124 callback ((const uint8_t*) &sbixGlyph.data,
125 strike.imageOffsetsZ[glyph + 1] - strike.imageOffsetsZ[glyph] - 8,
132 hb_blob_t *sbix_blob;
133 const sbix *sbix_table;
135 unsigned int sbix_len;
136 unsigned int num_glyphs;
141 HBUINT16 version; /* Table version number — set to 1 */
142 HBUINT16 flags; /* Bit 0: Set to 1. Bit 1: Draw outlines.
143 * Bits 2 to 15: reserved (set to 0). */
144 LArrayOf<LOffsetTo<SBIXStrike> >
145 strikes; /* Offsets from the beginning of the 'sbix'
146 * table to data for each individual bitmap strike. */
148 DEFINE_SIZE_ARRAY (8, strikes);
153 #endif /* HB_OT_COLOR_SBIX_TABLE_HH */