Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016 Google, Inc. |
| 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 | * Google Author(s): Seigo Nonaka |
| 25 | */ |
| 26 | |
Behdad Esfahbod | efca7bf | 2016-12-02 15:11:37 -0800 | [diff] [blame] | 27 | #ifndef HB_OT_CBDT_TABLE_HH |
| 28 | #define HB_OT_CBDT_TABLE_HH |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 29 | |
| 30 | #include "hb-open-type-private.hh" |
| 31 | |
| 32 | namespace OT { |
| 33 | |
| 34 | struct SmallGlyphMetrics |
| 35 | { |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 36 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 37 | { |
| 38 | TRACE_SANITIZE (this); |
| 39 | return_trace (c->check_struct (this)); |
| 40 | } |
| 41 | |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 42 | inline void get_extents (hb_glyph_extents_t *extents) const |
| 43 | { |
| 44 | extents->x_bearing = bearingX; |
| 45 | extents->y_bearing = bearingY; |
| 46 | extents->width = width; |
Behdad Esfahbod | 654f9ab | 2016-12-04 18:56:24 -0800 | [diff] [blame] | 47 | extents->height = -height; |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 50 | BYTE height; |
| 51 | BYTE width; |
Behdad Esfahbod | b92ba7b | 2016-12-02 15:21:43 -0800 | [diff] [blame] | 52 | CHAR bearingX; |
| 53 | CHAR bearingY; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 54 | BYTE advance; |
| 55 | |
| 56 | DEFINE_SIZE_STATIC(5); |
| 57 | }; |
| 58 | |
Behdad Esfahbod | e4bfccf | 2016-12-04 19:43:33 -0800 | [diff] [blame] | 59 | struct BigGlyphMetrics : SmallGlyphMetrics |
| 60 | { |
| 61 | CHAR vertBearingX; |
| 62 | CHAR vertBearingY; |
| 63 | BYTE vertAdvance; |
| 64 | |
| 65 | DEFINE_SIZE_STATIC(8); |
| 66 | }; |
| 67 | |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 68 | struct SBitLineMetrics |
| 69 | { |
| 70 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 71 | { |
| 72 | TRACE_SANITIZE (this); |
| 73 | return_trace (c->check_struct (this)); |
| 74 | } |
| 75 | |
Behdad Esfahbod | b92ba7b | 2016-12-02 15:21:43 -0800 | [diff] [blame] | 76 | CHAR ascender; |
| 77 | CHAR decender; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 78 | BYTE widthMax; |
Behdad Esfahbod | b92ba7b | 2016-12-02 15:21:43 -0800 | [diff] [blame] | 79 | CHAR caretSlopeNumerator; |
| 80 | CHAR caretSlopeDenominator; |
| 81 | CHAR caretOffset; |
| 82 | CHAR minOriginSB; |
| 83 | CHAR minAdvanceSB; |
| 84 | CHAR maxBeforeBL; |
| 85 | CHAR minAfterBL; |
| 86 | CHAR padding1; |
| 87 | CHAR padding2; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 88 | |
| 89 | DEFINE_SIZE_STATIC(12); |
| 90 | }; |
| 91 | |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 92 | |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 93 | /* |
| 94 | * Index Subtables. |
| 95 | */ |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 96 | |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 97 | struct IndexSubtableHeader |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 98 | { |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 99 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 100 | { |
| 101 | TRACE_SANITIZE (this); |
| 102 | return_trace (c->check_struct (this)); |
| 103 | } |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 104 | |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 105 | USHORT indexFormat; |
| 106 | USHORT imageFormat; |
| 107 | ULONG imageDataOffset; |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 108 | |
| 109 | DEFINE_SIZE_STATIC(8); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Behdad Esfahbod | a141d1d | 2016-12-04 19:26:54 -0800 | [diff] [blame] | 112 | template <typename OffsetType> |
| 113 | struct IndexSubtableFormat1Or3 |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 114 | { |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 115 | inline bool sanitize (hb_sanitize_context_t *c, unsigned int glyph_count) const |
| 116 | { |
| 117 | TRACE_SANITIZE (this); |
| 118 | return_trace (c->check_struct (this) && |
| 119 | c->check_array (offsetArrayZ, offsetArrayZ[0].static_size, glyph_count + 1)); |
| 120 | } |
| 121 | |
| 122 | bool get_image_data (unsigned int idx, |
| 123 | unsigned int *offset, |
| 124 | unsigned int *length) const |
| 125 | { |
| 126 | if (unlikely (offsetArrayZ[idx + 1] <= offsetArrayZ[idx])) |
| 127 | return false; |
| 128 | |
| 129 | *offset = header.imageDataOffset + offsetArrayZ[idx]; |
| 130 | *length = offsetArrayZ[idx + 1] - offsetArrayZ[idx]; |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | IndexSubtableHeader header; |
Behdad Esfahbod | a141d1d | 2016-12-04 19:26:54 -0800 | [diff] [blame] | 135 | Offset<OffsetType> offsetArrayZ[VAR]; |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 136 | |
| 137 | DEFINE_SIZE_ARRAY(8, offsetArrayZ); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
Behdad Esfahbod | a141d1d | 2016-12-04 19:26:54 -0800 | [diff] [blame] | 140 | struct IndexSubtableFormat1 : IndexSubtableFormat1Or3<ULONG> {}; |
| 141 | struct IndexSubtableFormat3 : IndexSubtableFormat1Or3<USHORT> {}; |
| 142 | |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 143 | struct IndexSubtable |
| 144 | { |
| 145 | inline bool sanitize (hb_sanitize_context_t *c, unsigned int glyph_count) const |
| 146 | { |
| 147 | TRACE_SANITIZE (this); |
| 148 | if (!u.header.sanitize (c)) return_trace (false); |
| 149 | switch (u.header.indexFormat) { |
| 150 | case 1: return_trace (u.format1.sanitize (c, glyph_count)); |
Behdad Esfahbod | a141d1d | 2016-12-04 19:26:54 -0800 | [diff] [blame] | 151 | case 3: return_trace (u.format3.sanitize (c, glyph_count)); |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 152 | default:return_trace (true); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | inline bool get_extents (hb_glyph_extents_t *extents) const |
| 157 | { |
| 158 | switch (u.header.indexFormat) { |
| 159 | case 2: case 5: /* TODO */ |
| 160 | case 1: case 3: case 4: /* Variable-metrics formats do not have metrics here. */ |
| 161 | default:return (false); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | bool get_image_data (unsigned int idx, |
| 166 | unsigned int *offset, |
| 167 | unsigned int *length, |
| 168 | unsigned int *format) const |
| 169 | { |
| 170 | *format = u.header.imageFormat; |
| 171 | switch (u.header.indexFormat) { |
| 172 | case 1: return u.format1.get_image_data (idx, offset, length); |
Behdad Esfahbod | a141d1d | 2016-12-04 19:26:54 -0800 | [diff] [blame] | 173 | case 3: return u.format3.get_image_data (idx, offset, length); |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 174 | default: return false; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | protected: |
| 179 | union { |
| 180 | IndexSubtableHeader header; |
| 181 | IndexSubtableFormat1 format1; |
Behdad Esfahbod | a141d1d | 2016-12-04 19:26:54 -0800 | [diff] [blame] | 182 | IndexSubtableFormat3 format3; |
Behdad Esfahbod | e4bfccf | 2016-12-04 19:43:33 -0800 | [diff] [blame] | 183 | /* TODO: Format 2, 4, 5. */ |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 184 | } u; |
| 185 | public: |
| 186 | DEFINE_SIZE_UNION (8, header); |
| 187 | }; |
| 188 | |
| 189 | struct IndexSubtableRecord |
| 190 | { |
| 191 | inline bool sanitize (hb_sanitize_context_t *c, const void *base) const |
| 192 | { |
| 193 | TRACE_SANITIZE (this); |
| 194 | return_trace (c->check_struct (this) && |
| 195 | firstGlyphIndex <= lastGlyphIndex && |
| 196 | offsetToSubtable.sanitize (c, this, lastGlyphIndex - firstGlyphIndex + 1)); |
| 197 | } |
| 198 | |
| 199 | inline bool get_extents (hb_glyph_extents_t *extents) const |
| 200 | { |
| 201 | return (this+offsetToSubtable).get_extents (extents); |
| 202 | } |
| 203 | |
| 204 | bool get_image_data (unsigned int gid, |
| 205 | unsigned int *offset, |
| 206 | unsigned int *length, |
| 207 | unsigned int *format) const |
| 208 | { |
| 209 | if (gid < firstGlyphIndex || gid > lastGlyphIndex) |
| 210 | { |
| 211 | return false; |
| 212 | } |
| 213 | return (this+offsetToSubtable).get_image_data (gid - firstGlyphIndex, |
| 214 | offset, length, format); |
| 215 | } |
| 216 | |
| 217 | USHORT firstGlyphIndex; |
| 218 | USHORT lastGlyphIndex; |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 219 | LOffsetTo<IndexSubtable> offsetToSubtable; |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 220 | |
| 221 | DEFINE_SIZE_STATIC(8); |
| 222 | }; |
| 223 | |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 224 | struct IndexSubtableArray |
| 225 | { |
Behdad Esfahbod | ce09e90 | 2016-12-02 20:12:57 -0800 | [diff] [blame] | 226 | inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const |
| 227 | { |
| 228 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b7068af | 2016-12-04 19:36:30 -0800 | [diff] [blame] | 229 | if (unlikely (!c->check_array (&indexSubtablesZ, indexSubtablesZ[0].static_size, count))) |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 230 | return_trace (false); |
| 231 | for (unsigned int i = 0; i < count; i++) |
| 232 | if (unlikely (!indexSubtablesZ[i].sanitize (c, this))) |
| 233 | return_trace (false); |
| 234 | return_trace (true); |
Behdad Esfahbod | ce09e90 | 2016-12-02 20:12:57 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 237 | public: |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 238 | const IndexSubtableRecord* find_table (hb_codepoint_t glyph, unsigned int numTables) const |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 239 | { |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 240 | for (unsigned int i = 0; i < numTables; ++i) |
| 241 | { |
| 242 | unsigned int firstGlyphIndex = indexSubtablesZ[i].firstGlyphIndex; |
| 243 | unsigned int lastGlyphIndex = indexSubtablesZ[i].lastGlyphIndex; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 244 | if (firstGlyphIndex <= glyph && glyph <= lastGlyphIndex) { |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 245 | return &indexSubtablesZ[i]; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 248 | return nullptr; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | protected: |
Behdad Esfahbod | d495fc5 | 2016-12-02 21:36:42 -0800 | [diff] [blame] | 252 | IndexSubtableRecord indexSubtablesZ[VAR]; |
Behdad Esfahbod | ce09e90 | 2016-12-02 20:12:57 -0800 | [diff] [blame] | 253 | |
| 254 | public: |
| 255 | DEFINE_SIZE_ARRAY(0, indexSubtablesZ); |
| 256 | }; |
| 257 | |
| 258 | struct BitmapSizeTable |
| 259 | { |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 260 | friend struct CBLC; |
| 261 | |
Behdad Esfahbod | ce09e90 | 2016-12-02 20:12:57 -0800 | [diff] [blame] | 262 | inline bool sanitize (hb_sanitize_context_t *c, const void *base) const |
| 263 | { |
| 264 | TRACE_SANITIZE (this); |
| 265 | return_trace (c->check_struct (this) && |
| 266 | indexSubtableArrayOffset.sanitize (c, base, numberOfIndexSubtables) && |
| 267 | c->check_range (&(base+indexSubtableArrayOffset), indexTablesSize) && |
| 268 | horizontal.sanitize (c) && |
| 269 | vertical.sanitize (c)); |
| 270 | } |
| 271 | |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 272 | const IndexSubtableRecord *find_table (hb_codepoint_t glyph, const void *base) const |
| 273 | { |
| 274 | return (base+indexSubtableArrayOffset).find_table (glyph, numberOfIndexSubtables); |
| 275 | } |
| 276 | |
| 277 | protected: |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 278 | LOffsetTo<IndexSubtableArray> indexSubtableArrayOffset; |
Behdad Esfahbod | ce09e90 | 2016-12-02 20:12:57 -0800 | [diff] [blame] | 279 | ULONG indexTablesSize; |
| 280 | ULONG numberOfIndexSubtables; |
| 281 | ULONG colorRef; |
| 282 | SBitLineMetrics horizontal; |
| 283 | SBitLineMetrics vertical; |
| 284 | USHORT startGlyphIndex; |
| 285 | USHORT endGlyphIndex; |
| 286 | BYTE ppemX; |
| 287 | BYTE ppemY; |
| 288 | BYTE bitDepth; |
| 289 | CHAR flags; |
| 290 | |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 291 | public: |
Behdad Esfahbod | ce09e90 | 2016-12-02 20:12:57 -0800 | [diff] [blame] | 292 | DEFINE_SIZE_STATIC(48); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 295 | |
| 296 | /* |
| 297 | * Glyph Bitmap Data Formats. |
| 298 | */ |
| 299 | |
| 300 | struct GlyphBitmapDataFormat17 |
| 301 | { |
| 302 | SmallGlyphMetrics glyphMetrics; |
| 303 | ULONG dataLen; |
| 304 | BYTE dataZ[VAR]; |
| 305 | |
| 306 | DEFINE_SIZE_ARRAY(9, dataZ); |
| 307 | }; |
| 308 | |
| 309 | |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 310 | /* |
| 311 | * CBLC -- Color Bitmap Location Table |
| 312 | */ |
| 313 | |
| 314 | #define HB_OT_TAG_CBLC HB_TAG('C','B','L','C') |
| 315 | |
| 316 | struct CBLC |
| 317 | { |
| 318 | static const hb_tag_t tableTag = HB_OT_TAG_CBLC; |
| 319 | |
| 320 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 321 | { |
| 322 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 323 | return_trace (c->check_struct (this) && |
| 324 | likely (version.major == 2 || version.major == 3) && |
Behdad Esfahbod | ce09e90 | 2016-12-02 20:12:57 -0800 | [diff] [blame] | 325 | sizeTables.sanitize (c, this)); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | public: |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 329 | const IndexSubtableRecord *find_table (hb_codepoint_t glyph, |
| 330 | unsigned int *x_ppem, unsigned int *y_ppem) const |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 331 | { |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 332 | /* TODO: Make it possible to select strike. */ |
| 333 | |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 334 | unsigned int count = sizeTables.len; |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 335 | for (uint32_t i = 0; i < count; ++i) |
| 336 | { |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 337 | unsigned int startGlyphIndex = sizeTables.array[i].startGlyphIndex; |
| 338 | unsigned int endGlyphIndex = sizeTables.array[i].endGlyphIndex; |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 339 | if (startGlyphIndex <= glyph && glyph <= endGlyphIndex) |
| 340 | { |
Behdad Esfahbod | e4bfccf | 2016-12-04 19:43:33 -0800 | [diff] [blame] | 341 | *x_ppem = sizeTables[i].ppemX; |
| 342 | *y_ppem = sizeTables[i].ppemY; |
| 343 | return sizeTables[i].find_table (glyph, this); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 344 | } |
| 345 | } |
Behdad Esfahbod | 9eda74c | 2016-12-04 19:12:52 -0800 | [diff] [blame] | 346 | |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 347 | return nullptr; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | protected: |
Behdad Esfahbod | b732c53 | 2017-01-22 20:31:53 -0800 | [diff] [blame] | 351 | FixedVersion<> version; |
| 352 | LArrayOf<BitmapSizeTable> sizeTables; |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 353 | |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 354 | public: |
| 355 | DEFINE_SIZE_ARRAY(8, sizeTables); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | /* |
| 359 | * CBDT -- Color Bitmap Data Table |
| 360 | */ |
| 361 | #define HB_OT_TAG_CBDT HB_TAG('C','B','D','T') |
| 362 | |
| 363 | struct CBDT |
| 364 | { |
| 365 | static const hb_tag_t tableTag = HB_OT_TAG_CBDT; |
| 366 | |
| 367 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 368 | { |
| 369 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 370 | return_trace (c->check_struct (this) && |
| 371 | likely (version.major == 2 || version.major == 3)); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Behdad Esfahbod | c4e18e5 | 2017-11-14 19:47:31 -0800 | [diff] [blame^] | 374 | struct accelerator_t |
| 375 | { |
| 376 | inline void init (hb_face_t *face) |
| 377 | { |
| 378 | upem = face->get_upem(); |
| 379 | |
| 380 | cblc_blob = Sanitizer<CBLC>::sanitize (face->reference_table (HB_OT_TAG_CBLC)); |
| 381 | cbdt_blob = Sanitizer<CBDT>::sanitize (face->reference_table (HB_OT_TAG_CBDT)); |
| 382 | cbdt_len = hb_blob_get_length (cbdt_blob); |
| 383 | |
| 384 | if (hb_blob_get_length (cblc_blob) == 0) { |
| 385 | cblc = nullptr; |
| 386 | cbdt = nullptr; |
| 387 | return; /* Not a bitmap font. */ |
| 388 | } |
| 389 | cblc = Sanitizer<CBLC>::lock_instance (cblc_blob); |
| 390 | cbdt = Sanitizer<CBDT>::lock_instance (cbdt_blob); |
| 391 | |
| 392 | } |
| 393 | |
| 394 | inline void fini (void) |
| 395 | { |
| 396 | hb_blob_destroy (this->cblc_blob); |
| 397 | hb_blob_destroy (this->cbdt_blob); |
| 398 | } |
| 399 | |
| 400 | inline bool get_extents (hb_codepoint_t glyph, hb_glyph_extents_t *extents) const |
| 401 | { |
| 402 | unsigned int x_ppem = upem, y_ppem = upem; /* TODO Use font ppem if available. */ |
| 403 | |
| 404 | if (!cblc) |
| 405 | return false; // Not a color bitmap font. |
| 406 | |
| 407 | const IndexSubtableRecord *subtable_record = this->cblc->find_table(glyph, &x_ppem, &y_ppem); |
| 408 | if (!subtable_record || !x_ppem || !y_ppem) |
| 409 | return false; |
| 410 | |
| 411 | if (subtable_record->get_extents (extents)) |
| 412 | return true; |
| 413 | |
| 414 | unsigned int image_offset = 0, image_length = 0, image_format = 0; |
| 415 | if (!subtable_record->get_image_data (glyph, &image_offset, &image_length, &image_format)) |
| 416 | return false; |
| 417 | |
| 418 | { |
| 419 | if (unlikely (image_offset > cbdt_len || cbdt_len - image_offset < image_length)) |
| 420 | return false; |
| 421 | |
| 422 | switch (image_format) |
| 423 | { |
| 424 | case 17: { |
| 425 | if (unlikely (image_length < GlyphBitmapDataFormat17::min_size)) |
| 426 | return false; |
| 427 | |
| 428 | const GlyphBitmapDataFormat17& glyphFormat17 = |
| 429 | StructAtOffset<GlyphBitmapDataFormat17> (this->cbdt, image_offset); |
| 430 | glyphFormat17.glyphMetrics.get_extents (extents); |
| 431 | } |
| 432 | break; |
| 433 | default: |
| 434 | // TODO: Support other image formats. |
| 435 | return false; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* Convert to the font units. */ |
| 440 | extents->x_bearing *= upem / (float) x_ppem; |
| 441 | extents->y_bearing *= upem / (float) y_ppem; |
| 442 | extents->width *= upem / (float) x_ppem; |
| 443 | extents->height *= upem / (float) y_ppem; |
| 444 | |
| 445 | return true; |
| 446 | } |
| 447 | |
| 448 | private: |
| 449 | hb_blob_t *cblc_blob; |
| 450 | hb_blob_t *cbdt_blob; |
| 451 | const CBLC *cblc; |
| 452 | const CBDT *cbdt; |
| 453 | |
| 454 | unsigned int cbdt_len; |
| 455 | unsigned int upem; |
| 456 | }; |
| 457 | |
| 458 | |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 459 | protected: |
Behdad Esfahbod | 4b58c9e | 2016-12-02 19:25:54 -0800 | [diff] [blame] | 460 | FixedVersion<>version; |
| 461 | BYTE dataZ[VAR]; |
| 462 | |
| 463 | public: |
| 464 | DEFINE_SIZE_ARRAY(4, dataZ); |
Seigo Nonaka | 8318525 | 2016-12-02 15:03:50 -0800 | [diff] [blame] | 465 | }; |
| 466 | |
| 467 | } /* namespace OT */ |
| 468 | |
Behdad Esfahbod | efca7bf | 2016-12-02 15:11:37 -0800 | [diff] [blame] | 469 | #endif /* HB_OT_CBDT_TABLE_HH */ |