| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright © 2009 Red Hat, Inc. | 2 * Copyright © 2009 Red Hat, Inc. |
| 3 * Copyright © 2012 Google, Inc. | 3 * Copyright © 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 20 matching lines...) Expand all Loading... |
| 31 #include "hb-shaper-private.hh" | 31 #include "hb-shaper-private.hh" |
| 32 #include "hb-shape-plan-private.hh" | 32 #include "hb-shape-plan-private.hh" |
| 33 #include "hb-buffer-private.hh" | 33 #include "hb-buffer-private.hh" |
| 34 #include "hb-font-private.hh" | 34 #include "hb-font-private.hh" |
| 35 | 35 |
| 36 | 36 |
| 37 static void | 37 static void |
| 38 parse_space (const char **pp, const char *end) | 38 parse_space (const char **pp, const char *end) |
| 39 { | 39 { |
| 40 char c; | 40 char c; |
| 41 #define ISSPACE(c) ((c)==' '||(c)=='\f'||(c)=='\n'||(c)=='\r'||(c)=='\t'||(c)=='
\v') | |
| 42 while (*pp < end && (c = **pp, ISSPACE (c))) | 41 while (*pp < end && (c = **pp, ISSPACE (c))) |
| 43 (*pp)++; | 42 (*pp)++; |
| 44 #undef ISSPACE | |
| 45 } | 43 } |
| 46 | 44 |
| 47 static hb_bool_t | 45 static hb_bool_t |
| 48 parse_char (const char **pp, const char *end, char c) | 46 parse_char (const char **pp, const char *end, char c) |
| 49 { | 47 { |
| 50 parse_space (pp, end); | 48 parse_space (pp, end); |
| 51 | 49 |
| 52 if (*pp == end || **pp != c) | 50 if (*pp == end || **pp != c) |
| 53 return false; | 51 return false; |
| 54 | 52 |
| 55 (*pp)++; | 53 (*pp)++; |
| 56 return true; | 54 return true; |
| 57 } | 55 } |
| 58 | 56 |
| 59 static hb_bool_t | 57 static hb_bool_t |
| 60 parse_uint (const char **pp, const char *end, unsigned int *pv) | 58 parse_uint (const char **pp, const char *end, unsigned int *pv) |
| 61 { | 59 { |
| 62 char buf[32]; | 60 char buf[32]; |
| 63 strncpy (buf, *pp, end - *pp); | 61 unsigned int len = MIN (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp)); |
| 64 buf[ARRAY_LENGTH (buf) - 1] = '\0'; | 62 strncpy (buf, *pp, len); |
| 63 buf[len] = '\0'; |
| 65 | 64 |
| 66 char *p = buf; | 65 char *p = buf; |
| 67 char *pend = p; | 66 char *pend = p; |
| 68 unsigned int v; | 67 unsigned int v; |
| 69 | 68 |
| 69 /* Intentionally use strtol instead of strtoul, such that |
| 70 * -1 turns into "big number"... */ |
| 71 errno = 0; |
| 70 v = strtol (p, &pend, 0); | 72 v = strtol (p, &pend, 0); |
| 71 | 73 if (errno || p == pend) |
| 72 if (p == pend) | |
| 73 return false; | 74 return false; |
| 74 | 75 |
| 75 *pv = v; | 76 *pv = v; |
| 76 *pp += pend - p; | 77 *pp += pend - p; |
| 77 return true; | 78 return true; |
| 78 } | 79 } |
| 79 | 80 |
| 80 static hb_bool_t | 81 static hb_bool_t |
| 81 parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feat
ure) | 82 parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feat
ure) |
| 82 { | 83 { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 196 } |
| 196 assert (len < ARRAY_LENGTH (s)); | 197 assert (len < ARRAY_LENGTH (s)); |
| 197 len = MIN (len, size - 1); | 198 len = MIN (len, size - 1); |
| 198 memcpy (buf, s, len); | 199 memcpy (buf, s, len); |
| 199 s[len] = '\0'; | 200 s[len] = '\0'; |
| 200 } | 201 } |
| 201 | 202 |
| 202 | 203 |
| 203 static const char **static_shaper_list; | 204 static const char **static_shaper_list; |
| 204 | 205 |
| 205 static | 206 static inline |
| 206 void free_static_shaper_list (void) | 207 void free_static_shaper_list (void) |
| 207 { | 208 { |
| 208 free (static_shaper_list); | 209 free (static_shaper_list); |
| 209 } | 210 } |
| 210 | 211 |
| 211 const char ** | 212 const char ** |
| 212 hb_shape_list_shapers (void) | 213 hb_shape_list_shapers (void) |
| 213 { | 214 { |
| 214 retry: | 215 retry: |
| 215 const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_l
ist); | 216 const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_l
ist); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 hb_buffer_t *buffer, | 249 hb_buffer_t *buffer, |
| 249 const hb_feature_t *features, | 250 const hb_feature_t *features, |
| 250 unsigned int num_features, | 251 unsigned int num_features, |
| 251 const char * const *shaper_list) | 252 const char * const *shaper_list) |
| 252 { | 253 { |
| 253 if (unlikely (!buffer->len)) | 254 if (unlikely (!buffer->len)) |
| 254 return true; | 255 return true; |
| 255 | 256 |
| 256 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE); | 257 assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE); |
| 257 | 258 |
| 258 buffer->guess_segment_properties (); | |
| 259 | |
| 260 hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer
->props, features, num_features, shaper_list); | 259 hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer
->props, features, num_features, shaper_list); |
| 261 hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num
_features); | 260 hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num
_features); |
| 262 hb_shape_plan_destroy (shape_plan); | 261 hb_shape_plan_destroy (shape_plan); |
| 263 | 262 |
| 264 if (res) | 263 if (res) |
| 265 buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; | 264 buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; |
| 266 return res; | 265 return res; |
| 267 } | 266 } |
| 268 | 267 |
| 269 void | 268 void |
| 270 hb_shape (hb_font_t *font, | 269 hb_shape (hb_font_t *font, |
| 271 hb_buffer_t *buffer, | 270 hb_buffer_t *buffer, |
| 272 const hb_feature_t *features, | 271 const hb_feature_t *features, |
| 273 unsigned int num_features) | 272 unsigned int num_features) |
| 274 { | 273 { |
| 275 hb_shape_full (font, buffer, features, num_features, NULL); | 274 hb_shape_full (font, buffer, features, num_features, NULL); |
| 276 } | 275 } |
| OLD | NEW |