OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
3 * Copyright © 2011,2012 Google, Inc. | 3 * Copyright © 2011,2012 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 inline void finish (void) | 370 inline void finish (void) |
371 { | 371 { |
372 if (array != static_array) | 372 if (array != static_array) |
373 free (array); | 373 free (array); |
374 array = NULL; | 374 array = NULL; |
375 allocated = len = 0; | 375 allocated = len = 0; |
376 } | 376 } |
377 }; | 377 }; |
378 | 378 |
| 379 #define HB_AUTO_ARRAY_PREALLOCED 64 |
| 380 template <typename Type> |
| 381 struct hb_auto_array_t : hb_prealloced_array_t <Type, HB_AUTO_ARRAY_PREALLOCED> |
| 382 { |
| 383 hb_auto_array_t (void) { hb_prealloced_array_t<Type, HB_AUTO_ARRAY_PREALLOCED>
::init (); } |
| 384 ~hb_auto_array_t (void) { hb_prealloced_array_t<Type, HB_AUTO_ARRAY_PREALLOCED
>::finish (); } |
| 385 }; |
| 386 |
379 | 387 |
380 #define HB_LOCKABLE_SET_INIT {HB_PREALLOCED_ARRAY_INIT} | 388 #define HB_LOCKABLE_SET_INIT {HB_PREALLOCED_ARRAY_INIT} |
381 template <typename item_t, typename lock_t> | 389 template <typename item_t, typename lock_t> |
382 struct hb_lockable_set_t | 390 struct hb_lockable_set_t |
383 { | 391 { |
384 hb_prealloced_array_t <item_t, 2> items; | 392 hb_prealloced_array_t <item_t, 2> items; |
385 | 393 |
386 inline void init (void) { items.init (); } | 394 inline void init (void) { items.init (); } |
387 | 395 |
388 template <typename T> | 396 template <typename T> |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 #define hb_be_uint32_get(v) (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2]
<< 8) + v[3]) | 517 #define hb_be_uint32_get(v) (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2]
<< 8) + v[3]) |
510 #define hb_be_uint32_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] &&
a[3] == b[3]) | 518 #define hb_be_uint32_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] &&
a[3] == b[3]) |
511 | 519 |
512 #define hb_be_uint24_put(v,V) HB_STMT_START { v[0] = (V>>16); v[1] = (V>>8); v
[2] (V); } HB_STMT_END | 520 #define hb_be_uint24_put(v,V) HB_STMT_START { v[0] = (V>>16); v[1] = (V>>8); v
[2] (V); } HB_STMT_END |
513 #define hb_be_uint24_get(v) (uint32_t) ((v[0] << 16) + (v[1] << 8) + v[2]) | 521 #define hb_be_uint24_get(v) (uint32_t) ((v[0] << 16) + (v[1] << 8) + v[2]) |
514 #define hb_be_uint24_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) | 522 #define hb_be_uint24_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) |
515 | 523 |
516 | 524 |
517 /* ASCII tag/character handling */ | 525 /* ASCII tag/character handling */ |
518 | 526 |
519 static inline unsigned char ISALPHA (unsigned char c) | 527 static inline bool ISALPHA (unsigned char c) |
520 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } | 528 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } |
521 static inline unsigned char ISALNUM (unsigned char c) | 529 static inline bool ISALNUM (unsigned char c) |
522 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '
9'); } | 530 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '
9'); } |
| 531 static inline bool ISSPACE (unsigned char c) |
| 532 { return c == ' ' || c =='\f'|| c =='\n'|| c =='\r'|| c =='\t'|| c =='\v'; } |
523 static inline unsigned char TOUPPER (unsigned char c) | 533 static inline unsigned char TOUPPER (unsigned char c) |
524 { return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; } | 534 { return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; } |
525 static inline unsigned char TOLOWER (unsigned char c) | 535 static inline unsigned char TOLOWER (unsigned char c) |
526 { return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } | 536 { return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } |
527 | 537 |
528 #define HB_TAG_CHAR4(s) (HB_TAG(((const char *) s)[0], \ | 538 #define HB_TAG_CHAR4(s) (HB_TAG(((const char *) s)[0], \ |
529 ((const char *) s)[1], \ | 539 ((const char *) s)[1], \ |
530 ((const char *) s)[2], \ | 540 ((const char *) s)[2], \ |
531 ((const char *) s)[3])) | 541 ((const char *) s)[3])) |
532 | 542 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 static const char bars[] = VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR
VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR
VBAR VBAR VBAR VBAR; | 597 static const char bars[] = VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR
VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR
VBAR VBAR VBAR VBAR; |
588 fprintf (stderr, "%2d %s" VRBAR "%s", | 598 fprintf (stderr, "%2d %s" VRBAR "%s", |
589 level, | 599 level, |
590 bars + sizeof (bars) - 1 - MIN ((unsigned int) sizeof (bars), (unsi
gned int) (sizeof (VBAR) - 1) * level), | 600 bars + sizeof (bars) - 1 - MIN ((unsigned int) sizeof (bars), (unsi
gned int) (sizeof (VBAR) - 1) * level), |
591 level_dir ? (level_dir > 0 ? DLBAR : ULBAR) : LBAR); | 601 level_dir ? (level_dir > 0 ? DLBAR : ULBAR) : LBAR); |
592 } else | 602 } else |
593 fprintf (stderr, " " VRBAR LBAR); | 603 fprintf (stderr, " " VRBAR LBAR); |
594 | 604 |
595 if (func) | 605 if (func) |
596 { | 606 { |
| 607 unsigned int func_len = strlen (func); |
| 608 #ifndef HB_DEBUG_VERBOSE |
597 /* Skip "typename" */ | 609 /* Skip "typename" */ |
598 if (0 == strncmp (func, "typename ", 9)) | 610 if (0 == strncmp (func, "typename ", 9)) |
599 func += 9; | 611 func += 9; |
600 /* Skip return type */ | 612 /* Skip return type */ |
601 const char *space = strchr (func, ' '); | 613 const char *space = strchr (func, ' '); |
602 if (space) | 614 if (space) |
603 func = space + 1; | 615 func = space + 1; |
604 /* Skip parameter list */ | 616 /* Skip parameter list */ |
605 const char *paren = strchr (func, '('); | 617 const char *paren = strchr (func, '('); |
606 unsigned int func_len = paren ? paren - func : strlen (func); | 618 if (paren) |
| 619 func_len = paren - func; |
| 620 #endif |
607 fprintf (stderr, "%.*s: ", func_len, func); | 621 fprintf (stderr, "%.*s: ", func_len, func); |
608 } | 622 } |
609 | 623 |
610 if (message) | 624 if (message) |
611 vfprintf (stderr, message, ap); | 625 vfprintf (stderr, message, ap); |
612 | 626 |
613 fprintf (stderr, "\n"); | 627 fprintf (stderr, "\n"); |
614 } | 628 } |
615 template <> inline void | 629 template <> inline void |
616 _hb_debug_msg_va<0> (const char *what HB_UNUSED, | 630 _hb_debug_msg_va<0> (const char *what HB_UNUSED, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) | 848 hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) |
835 { | 849 { |
836 hb_bubble_sort (array, len, compar, (int *) NULL); | 850 hb_bubble_sort (array, len, compar, (int *) NULL); |
837 } | 851 } |
838 | 852 |
839 static inline hb_bool_t | 853 static inline hb_bool_t |
840 hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
ut) | 854 hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
ut) |
841 { | 855 { |
842 /* Pain because we don't know whether s is nul-terminated. */ | 856 /* Pain because we don't know whether s is nul-terminated. */ |
843 char buf[64]; | 857 char buf[64]; |
844 strncpy (buf, s, MIN (ARRAY_LENGTH (buf) - 1, len)); | 858 len = MIN (ARRAY_LENGTH (buf) - 1, len); |
845 buf[MIN (ARRAY_LENGTH (buf) - 1, len)] = '\0'; | 859 strncpy (buf, s, len); |
| 860 buf[len] = '\0'; |
846 | 861 |
847 char *end; | 862 char *end; |
848 errno = 0; | 863 errno = 0; |
849 unsigned long v = strtoul (buf, &end, base); | 864 unsigned long v = strtoul (buf, &end, base); |
850 if (errno) return false; | 865 if (errno) return false; |
851 if (*end) return false; | 866 if (*end) return false; |
852 *out = v; | 867 *out = v; |
853 return true; | 868 return true; |
854 } | 869 } |
855 | 870 |
856 | 871 |
| 872 /* Global runtime options. */ |
| 873 |
| 874 struct hb_options_t |
| 875 { |
| 876 int initialized : 1; |
| 877 int uniscribe_bug_compatible : 1; |
| 878 }; |
| 879 |
| 880 union hb_options_union_t { |
| 881 int i; |
| 882 hb_options_t opts; |
| 883 }; |
| 884 ASSERT_STATIC (sizeof (int) == sizeof (hb_options_union_t)); |
| 885 |
| 886 HB_INTERNAL void |
| 887 _hb_options_init (void); |
| 888 |
| 889 extern HB_INTERNAL hb_options_union_t _hb_options; |
| 890 |
| 891 static inline hb_options_t |
| 892 hb_options (void) |
| 893 { |
| 894 if (unlikely (!_hb_options.i)) |
| 895 _hb_options_init (); |
| 896 |
| 897 return _hb_options.opts; |
| 898 } |
| 899 |
| 900 |
857 #endif /* HB_PRIVATE_HH */ | 901 #endif /* HB_PRIVATE_HH */ |
OLD | NEW |