Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/harfbuzz-ng/src/hb-ot-cmap-table.hh

Issue 1401363002: Roll harfbuzz-ng to 1.0.5 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing header Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright © 2014 Google, Inc. 2 * Copyright © 2014 Google, Inc.
3 * 3 *
4 * This is part of HarfBuzz, a text shaping library. 4 * This is part of HarfBuzz, a text shaping library.
5 * 5 *
6 * Permission is hereby granted, without written agreement and without 6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this 7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the 8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in 9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software. 10 * all copies of this software.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 hb_codepoint_t gid = codepoint < 256 ? glyphIdArray[codepoint] : 0; 47 hb_codepoint_t gid = codepoint < 256 ? glyphIdArray[codepoint] : 0;
48 if (!gid) 48 if (!gid)
49 return false; 49 return false;
50 *glyph = gid; 50 *glyph = gid;
51 return true; 51 return true;
52 } 52 }
53 53
54 inline bool sanitize (hb_sanitize_context_t *c) const 54 inline bool sanitize (hb_sanitize_context_t *c) const
55 { 55 {
56 TRACE_SANITIZE (this); 56 TRACE_SANITIZE (this);
57 return TRACE_RETURN (c->check_struct (this)); 57 return_trace (c->check_struct (this));
58 } 58 }
59 59
60 protected: 60 protected:
61 USHORT format; /* Format number is set to 0. */ 61 USHORT format; /* Format number is set to 0. */
62 USHORT lengthZ; /* Byte length of this subtable. */ 62 USHORT lengthZ; /* Byte length of this subtable. */
63 USHORT languageZ; /* Ignore. */ 63 USHORT languageZ; /* Ignore. */
64 BYTE glyphIdArray[256];/* An array that maps character 64 BYTE glyphIdArray[256];/* An array that maps character
65 * code to glyph index values. */ 65 * code to glyph index values. */
66 public: 66 public:
67 DEFINE_SIZE_STATIC (6 + 256); 67 DEFINE_SIZE_STATIC (6 + 256);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 *glyph = gid & 0xFFFFu; 125 *glyph = gid & 0xFFFFu;
126 return true; 126 return true;
127 } 127 }
128 128
129 inline bool sanitize (hb_sanitize_context_t *c) const 129 inline bool sanitize (hb_sanitize_context_t *c) const
130 { 130 {
131 TRACE_SANITIZE (this); 131 TRACE_SANITIZE (this);
132 if (unlikely (!c->check_struct (this))) 132 if (unlikely (!c->check_struct (this)))
133 return TRACE_RETURN (false); 133 return_trace (false);
134 134
135 if (unlikely (!c->check_range (this, length))) 135 if (unlikely (!c->check_range (this, length)))
136 { 136 {
137 /* Some broken fonts have too long of a "length" value. 137 /* Some broken fonts have too long of a "length" value.
138 * If that is the case, just change the value to truncate 138 * If that is the case, just change the value to truncate
139 * the subtable at the end of the blob. */ 139 * the subtable at the end of the blob. */
140 uint16_t new_length = (uint16_t) MIN ((uintptr_t) 65535, 140 uint16_t new_length = (uint16_t) MIN ((uintptr_t) 65535,
141 (uintptr_t) (c->end - 141 (uintptr_t) (c->end -
142 (char *) this)); 142 (char *) this));
143 if (!c->try_set (&length, new_length)) 143 if (!c->try_set (&length, new_length))
144 » return TRACE_RETURN (false); 144 » return_trace (false);
145 } 145 }
146 146
147 return TRACE_RETURN (16 + 4 * (unsigned int) segCountX2 <= length); 147 return_trace (16 + 4 * (unsigned int) segCountX2 <= length);
148 } 148 }
149 149
150 protected: 150 protected:
151 USHORT format; /* Format number is set to 4. */ 151 USHORT format; /* Format number is set to 4. */
152 USHORT length; /* This is the length in bytes of the 152 USHORT length; /* This is the length in bytes of the
153 * subtable. */ 153 * subtable. */
154 USHORT languageZ; /* Ignore. */ 154 USHORT languageZ; /* Ignore. */
155 USHORT segCountX2; /* 2 x segCount. */ 155 USHORT segCountX2; /* 2 x segCount. */
156 USHORT searchRangeZ; /* 2 * (2**floor(log2(segCount))) */ 156 USHORT searchRangeZ; /* 2 * (2**floor(log2(segCount))) */
157 USHORT entrySelectorZ; /* log2(searchRange/2) */ 157 USHORT entrySelectorZ; /* log2(searchRange/2) */
(...skipping 22 matching lines...) Expand all
180 int cmp (hb_codepoint_t codepoint) const 180 int cmp (hb_codepoint_t codepoint) const
181 { 181 {
182 if (codepoint < startCharCode) return -1; 182 if (codepoint < startCharCode) return -1;
183 if (codepoint > endCharCode) return +1; 183 if (codepoint > endCharCode) return +1;
184 return 0; 184 return 0;
185 } 185 }
186 186
187 inline bool sanitize (hb_sanitize_context_t *c) const 187 inline bool sanitize (hb_sanitize_context_t *c) const
188 { 188 {
189 TRACE_SANITIZE (this); 189 TRACE_SANITIZE (this);
190 return TRACE_RETURN (c->check_struct (this)); 190 return_trace (c->check_struct (this));
191 } 191 }
192 192
193 private: 193 private:
194 ULONG startCharCode; /* First character code in this group. */ 194 ULONG startCharCode; /* First character code in this group. */
195 ULONG endCharCode; /* Last character code in this group. */ 195 ULONG endCharCode; /* Last character code in this group. */
196 ULONG glyphID; /* Glyph index; interpretation depends on 196 ULONG glyphID; /* Glyph index; interpretation depends on
197 * subtable format. */ 197 * subtable format. */
198 public: 198 public:
199 DEFINE_SIZE_STATIC (12); 199 DEFINE_SIZE_STATIC (12);
200 }; 200 };
201 201
202 template <typename UINT> 202 template <typename UINT>
203 struct CmapSubtableTrimmed 203 struct CmapSubtableTrimmed
204 { 204 {
205 inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const 205 inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
206 { 206 {
207 /* Rely on our implicit array bound-checking. */ 207 /* Rely on our implicit array bound-checking. */
208 hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode]; 208 hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode];
209 if (!gid) 209 if (!gid)
210 return false; 210 return false;
211 *glyph = gid; 211 *glyph = gid;
212 return true; 212 return true;
213 } 213 }
214 214
215 inline bool sanitize (hb_sanitize_context_t *c) const 215 inline bool sanitize (hb_sanitize_context_t *c) const
216 { 216 {
217 TRACE_SANITIZE (this); 217 TRACE_SANITIZE (this);
218 return TRACE_RETURN (c->check_struct (this) && glyphIdArray.sanitize (c)); 218 return_trace (c->check_struct (this) && glyphIdArray.sanitize (c));
219 } 219 }
220 220
221 protected: 221 protected:
222 UINT formatReserved; /* Subtable format and (maybe) padding. */ 222 UINT formatReserved; /* Subtable format and (maybe) padding. */
223 UINT lengthZ; /* Byte length of this subtable. */ 223 UINT lengthZ; /* Byte length of this subtable. */
224 UINT languageZ; /* Ignore. */ 224 UINT languageZ; /* Ignore. */
225 UINT startCharCode; /* First character code covered. */ 225 UINT startCharCode; /* First character code covered. */
226 ArrayOf<GlyphID, UINT> 226 ArrayOf<GlyphID, UINT>
227 glyphIdArray; /* Array of glyph index values for character 227 glyphIdArray; /* Array of glyph index values for character
228 * codes in the range. */ 228 * codes in the range. */
(...skipping 12 matching lines...) Expand all
241 int i = groups.bsearch (codepoint); 241 int i = groups.bsearch (codepoint);
242 if (i == -1) 242 if (i == -1)
243 return false; 243 return false;
244 *glyph = T::group_get_glyph (groups[i], codepoint); 244 *glyph = T::group_get_glyph (groups[i], codepoint);
245 return true; 245 return true;
246 } 246 }
247 247
248 inline bool sanitize (hb_sanitize_context_t *c) const 248 inline bool sanitize (hb_sanitize_context_t *c) const
249 { 249 {
250 TRACE_SANITIZE (this); 250 TRACE_SANITIZE (this);
251 return TRACE_RETURN (c->check_struct (this) && groups.sanitize (c)); 251 return_trace (c->check_struct (this) && groups.sanitize (c));
252 } 252 }
253 253
254 protected: 254 protected:
255 USHORT format; /* Subtable format; set to 12. */ 255 USHORT format; /* Subtable format; set to 12. */
256 USHORT reservedZ; /* Reserved; set to 0. */ 256 USHORT reservedZ; /* Reserved; set to 0. */
257 ULONG lengthZ; /* Byte length of this subtable. */ 257 ULONG lengthZ; /* Byte length of this subtable. */
258 ULONG languageZ; /* Ignore. */ 258 ULONG languageZ; /* Ignore. */
259 SortedArrayOf<CmapSubtableLongGroup, ULONG> 259 SortedArrayOf<CmapSubtableLongGroup, ULONG>
260 groups; /* Groupings. */ 260 groups; /* Groupings. */
261 public: 261 public:
(...skipping 26 matching lines...) Expand all
288 inline int cmp (const hb_codepoint_t &codepoint) const 288 inline int cmp (const hb_codepoint_t &codepoint) const
289 { 289 {
290 if (codepoint < startUnicodeValue) return -1; 290 if (codepoint < startUnicodeValue) return -1;
291 if (codepoint > startUnicodeValue + additionalCount) return +1; 291 if (codepoint > startUnicodeValue + additionalCount) return +1;
292 return 0; 292 return 0;
293 } 293 }
294 294
295 inline bool sanitize (hb_sanitize_context_t *c) const 295 inline bool sanitize (hb_sanitize_context_t *c) const
296 { 296 {
297 TRACE_SANITIZE (this); 297 TRACE_SANITIZE (this);
298 return TRACE_RETURN (c->check_struct (this)); 298 return_trace (c->check_struct (this));
299 } 299 }
300 300
301 UINT24 startUnicodeValue; /* First value in this range. */ 301 UINT24 startUnicodeValue; /* First value in this range. */
302 BYTE additionalCount; /* Number of additional values in this 302 BYTE additionalCount; /* Number of additional values in this
303 * range. */ 303 * range. */
304 public: 304 public:
305 DEFINE_SIZE_STATIC (4); 305 DEFINE_SIZE_STATIC (4);
306 }; 306 };
307 307
308 typedef SortedArrayOf<UnicodeValueRange, ULONG> DefaultUVS; 308 typedef SortedArrayOf<UnicodeValueRange, ULONG> DefaultUVS;
309 309
310 struct UVSMapping 310 struct UVSMapping
311 { 311 {
312 inline int cmp (const hb_codepoint_t &codepoint) const 312 inline int cmp (const hb_codepoint_t &codepoint) const
313 { 313 {
314 return unicodeValue.cmp (codepoint); 314 return unicodeValue.cmp (codepoint);
315 } 315 }
316 316
317 inline bool sanitize (hb_sanitize_context_t *c) const 317 inline bool sanitize (hb_sanitize_context_t *c) const
318 { 318 {
319 TRACE_SANITIZE (this); 319 TRACE_SANITIZE (this);
320 return TRACE_RETURN (c->check_struct (this)); 320 return_trace (c->check_struct (this));
321 } 321 }
322 322
323 UINT24 unicodeValue; /* Base Unicode value of the UVS */ 323 UINT24 unicodeValue; /* Base Unicode value of the UVS */
324 GlyphID glyphID; /* Glyph ID of the UVS */ 324 GlyphID glyphID; /* Glyph ID of the UVS */
325 public: 325 public:
326 DEFINE_SIZE_STATIC (5); 326 DEFINE_SIZE_STATIC (5);
327 }; 327 };
328 328
329 typedef SortedArrayOf<UVSMapping, ULONG> NonDefaultUVS; 329 typedef SortedArrayOf<UVSMapping, ULONG> NonDefaultUVS;
330 330
(...skipping 19 matching lines...) Expand all
350 } 350 }
351 351
352 inline int cmp (const hb_codepoint_t &variation_selector) const 352 inline int cmp (const hb_codepoint_t &variation_selector) const
353 { 353 {
354 return varSelector.cmp (variation_selector); 354 return varSelector.cmp (variation_selector);
355 } 355 }
356 356
357 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const 357 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
358 { 358 {
359 TRACE_SANITIZE (this); 359 TRACE_SANITIZE (this);
360 return TRACE_RETURN (c->check_struct (this) && 360 return_trace (c->check_struct (this) &&
361 » » » defaultUVS.sanitize (c, base) && 361 » » defaultUVS.sanitize (c, base) &&
362 » » » nonDefaultUVS.sanitize (c, base)); 362 » » nonDefaultUVS.sanitize (c, base));
363 } 363 }
364 364
365 UINT24 varSelector; /* Variation selector. */ 365 UINT24 varSelector; /* Variation selector. */
366 OffsetTo<DefaultUVS, ULONG> 366 OffsetTo<DefaultUVS, ULONG>
367 defaultUVS; /* Offset to Default UVS Table. May be 0. */ 367 defaultUVS; /* Offset to Default UVS Table. May be 0. */
368 OffsetTo<NonDefaultUVS, ULONG> 368 OffsetTo<NonDefaultUVS, ULONG>
369 nonDefaultUVS; /* Offset to Non-Default UVS Table. May be 0. */ 369 nonDefaultUVS; /* Offset to Non-Default UVS Table. May be 0. */
370 public: 370 public:
371 DEFINE_SIZE_STATIC (11); 371 DEFINE_SIZE_STATIC (11);
372 }; 372 };
373 373
374 struct CmapSubtableFormat14 374 struct CmapSubtableFormat14
375 { 375 {
376 inline glyph_variant_t get_glyph_variant (hb_codepoint_t codepoint, 376 inline glyph_variant_t get_glyph_variant (hb_codepoint_t codepoint,
377 hb_codepoint_t variation_selector, 377 hb_codepoint_t variation_selector,
378 hb_codepoint_t *glyph) const 378 hb_codepoint_t *glyph) const
379 { 379 {
380 return record[record.bsearch(variation_selector)].get_glyph (codepoint, glyp h, this); 380 return record[record.bsearch(variation_selector)].get_glyph (codepoint, glyp h, this);
381 } 381 }
382 382
383 inline bool sanitize (hb_sanitize_context_t *c) const 383 inline bool sanitize (hb_sanitize_context_t *c) const
384 { 384 {
385 TRACE_SANITIZE (this); 385 TRACE_SANITIZE (this);
386 return TRACE_RETURN (c->check_struct (this) && 386 return_trace (c->check_struct (this) &&
387 » » » record.sanitize (c, this)); 387 » » record.sanitize (c, this));
388 } 388 }
389 389
390 protected: 390 protected:
391 USHORT format; /* Format number is set to 0. */ 391 USHORT format; /* Format number is set to 0. */
392 ULONG lengthZ; /* Byte length of this subtable. */ 392 ULONG lengthZ; /* Byte length of this subtable. */
393 SortedArrayOf<VariationSelectorRecord, ULONG> 393 SortedArrayOf<VariationSelectorRecord, ULONG>
394 record; /* Variation selector records; sorted 394 record; /* Variation selector records; sorted
395 * in increasing order of `varSelector'. */ 395 * in increasing order of `varSelector'. */
396 public: 396 public:
397 DEFINE_SIZE_ARRAY (10, record); 397 DEFINE_SIZE_ARRAY (10, record);
(...skipping 24 matching lines...) Expand all
422 { 422 {
423 switch (u.format) { 423 switch (u.format) {
424 case 14: return u.format14.get_glyph_variant(codepoint, variation_selector, glyph); 424 case 14: return u.format14.get_glyph_variant(codepoint, variation_selector, glyph);
425 default: return GLYPH_VARIANT_NOT_FOUND; 425 default: return GLYPH_VARIANT_NOT_FOUND;
426 } 426 }
427 } 427 }
428 428
429 inline bool sanitize (hb_sanitize_context_t *c) const 429 inline bool sanitize (hb_sanitize_context_t *c) const
430 { 430 {
431 TRACE_SANITIZE (this); 431 TRACE_SANITIZE (this);
432 if (!u.format.sanitize (c)) return TRACE_RETURN (false); 432 if (!u.format.sanitize (c)) return_trace (false);
433 switch (u.format) { 433 switch (u.format) {
434 case 0: return TRACE_RETURN (u.format0 .sanitize (c)); 434 case 0: return_trace (u.format0 .sanitize (c));
435 case 4: return TRACE_RETURN (u.format4 .sanitize (c)); 435 case 4: return_trace (u.format4 .sanitize (c));
436 case 6: return TRACE_RETURN (u.format6 .sanitize (c)); 436 case 6: return_trace (u.format6 .sanitize (c));
437 case 10: return TRACE_RETURN (u.format10.sanitize (c)); 437 case 10: return_trace (u.format10.sanitize (c));
438 case 12: return TRACE_RETURN (u.format12.sanitize (c)); 438 case 12: return_trace (u.format12.sanitize (c));
439 case 13: return TRACE_RETURN (u.format13.sanitize (c)); 439 case 13: return_trace (u.format13.sanitize (c));
440 case 14: return TRACE_RETURN (u.format14.sanitize (c)); 440 case 14: return_trace (u.format14.sanitize (c));
441 default:return TRACE_RETURN (true); 441 default:return_trace (true);
442 } 442 }
443 } 443 }
444 444
445 protected: 445 protected:
446 union { 446 union {
447 USHORT format; /* Format identifier */ 447 USHORT format; /* Format identifier */
448 CmapSubtableFormat0 format0; 448 CmapSubtableFormat0 format0;
449 CmapSubtableFormat4 format4; 449 CmapSubtableFormat4 format4;
450 CmapSubtableFormat6 format6; 450 CmapSubtableFormat6 format6;
451 CmapSubtableFormat10 format10; 451 CmapSubtableFormat10 format10;
(...skipping 14 matching lines...) Expand all
466 ret = platformID.cmp (other.platformID); 466 ret = platformID.cmp (other.platformID);
467 if (ret) return ret; 467 if (ret) return ret;
468 ret = encodingID.cmp (other.encodingID); 468 ret = encodingID.cmp (other.encodingID);
469 if (ret) return ret; 469 if (ret) return ret;
470 return 0; 470 return 0;
471 } 471 }
472 472
473 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const 473 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
474 { 474 {
475 TRACE_SANITIZE (this); 475 TRACE_SANITIZE (this);
476 return TRACE_RETURN (c->check_struct (this) && 476 return_trace (c->check_struct (this) &&
477 » » » subtable.sanitize (c, base)); 477 » » subtable.sanitize (c, base));
478 } 478 }
479 479
480 USHORT platformID; /* Platform ID. */ 480 USHORT platformID; /* Platform ID. */
481 USHORT encodingID; /* Platform-specific encoding ID. */ 481 USHORT encodingID; /* Platform-specific encoding ID. */
482 OffsetTo<CmapSubtable, ULONG> 482 OffsetTo<CmapSubtable, ULONG>
483 subtable; /* Byte offset from beginning of table to the su btable for this encoding. */ 483 subtable; /* Byte offset from beginning of table to the su btable for this encoding. */
484 public: 484 public:
485 DEFINE_SIZE_STATIC (8); 485 DEFINE_SIZE_STATIC (8);
486 }; 486 };
487 487
(...skipping 14 matching lines...) Expand all
502 int result = encodingRecord./*bsearch*/lsearch (key); 502 int result = encodingRecord./*bsearch*/lsearch (key);
503 if (result == -1 || !encodingRecord[result].subtable) 503 if (result == -1 || !encodingRecord[result].subtable)
504 return NULL; 504 return NULL;
505 505
506 return &(this+encodingRecord[result].subtable); 506 return &(this+encodingRecord[result].subtable);
507 } 507 }
508 508
509 inline bool sanitize (hb_sanitize_context_t *c) const 509 inline bool sanitize (hb_sanitize_context_t *c) const
510 { 510 {
511 TRACE_SANITIZE (this); 511 TRACE_SANITIZE (this);
512 return TRACE_RETURN (c->check_struct (this) && 512 return_trace (c->check_struct (this) &&
513 » » » likely (version == 0) && 513 » » likely (version == 0) &&
514 » » » encodingRecord.sanitize (c, this)); 514 » » encodingRecord.sanitize (c, this));
515 } 515 }
516 516
517 USHORT version; /* Table version number (0). */ 517 USHORT version; /* Table version number (0). */
518 SortedArrayOf<EncodingRecord> 518 SortedArrayOf<EncodingRecord>
519 encodingRecord; /* Encoding tables. */ 519 encodingRecord; /* Encoding tables. */
520 public: 520 public:
521 DEFINE_SIZE_ARRAY (4, encodingRecord); 521 DEFINE_SIZE_ARRAY (4, encodingRecord);
522 }; 522 };
523 523
524 524
525 } /* namespace OT */ 525 } /* namespace OT */
526 526
527 527
528 #endif /* HB_OT_CMAP_TABLE_HH */ 528 #endif /* HB_OT_CMAP_TABLE_HH */
OLDNEW
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-open-type-private.hh ('k') | third_party/harfbuzz-ng/src/hb-ot-font.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698