| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright © 2012,2013 Google, Inc. | 2 * Copyright © 2012,2013 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 static const char *serialize_formats[] = { | 30 static const char *serialize_formats[] = { |
| 31 "text", | 31 "text", |
| 32 "json", | 32 "json", |
| 33 NULL | 33 NULL |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * hb_buffer_serialize_list_formats: | 37 * hb_buffer_serialize_list_formats: |
| 38 * | 38 * |
| 39 * | 39 * Returns a list of supported buffer serialization formats. |
| 40 * | 40 * |
| 41 * Return value: (transfer none): | 41 * Return value: (transfer none): |
| 42 * A string array of buffer serialization formats. Should not be freed. |
| 42 * | 43 * |
| 43 * Since: 0.9.2 | 44 * Since: 0.9.7 |
| 44 **/ | 45 **/ |
| 45 const char ** | 46 const char ** |
| 46 hb_buffer_serialize_list_formats (void) | 47 hb_buffer_serialize_list_formats (void) |
| 47 { | 48 { |
| 48 return serialize_formats; | 49 return serialize_formats; |
| 49 } | 50 } |
| 50 | 51 |
| 51 /** | 52 /** |
| 52 * hb_buffer_serialize_format_from_string: | 53 * hb_buffer_serialize_format_from_string: |
| 53 * @str: | 54 * @str: (array length=len) (element-type uint8_t): a string to parse |
| 54 * @len: | 55 * @len: length of @str, or -1 if string is %NULL terminated |
| 55 * | 56 * |
| 56 * | 57 * Parses a string into an #hb_buffer_serialize_format_t. Does not check if |
| 58 * @str is a valid buffer serialization format, use |
| 59 * hb_buffer_serialize_list_formats() to get the list of supported formats. |
| 57 * | 60 * |
| 58 * Return value: | 61 * Return value: |
| 62 * The parsed #hb_buffer_serialize_format_t. |
| 59 * | 63 * |
| 60 * Since: 0.9.2 | 64 * Since: 0.9.7 |
| 61 **/ | 65 **/ |
| 62 hb_buffer_serialize_format_t | 66 hb_buffer_serialize_format_t |
| 63 hb_buffer_serialize_format_from_string (const char *str, int len) | 67 hb_buffer_serialize_format_from_string (const char *str, int len) |
| 64 { | 68 { |
| 65 /* Upper-case it. */ | 69 /* Upper-case it. */ |
| 66 return (hb_buffer_serialize_format_t) (hb_tag_from_string (str, len) & ~0x2020
2020u); | 70 return (hb_buffer_serialize_format_t) (hb_tag_from_string (str, len) & ~0x2020
2020u); |
| 67 } | 71 } |
| 68 | 72 |
| 69 /** | 73 /** |
| 70 * hb_buffer_serialize_format_to_string: | 74 * hb_buffer_serialize_format_to_string: |
| 71 * @format: | 75 * @format: an #hb_buffer_serialize_format_t to convert. |
| 72 * | 76 * |
| 73 * | 77 * Converts @format to the string corresponding it, or %NULL if it is not a vali
d |
| 78 * #hb_buffer_serialize_format_t. |
| 74 * | 79 * |
| 75 * Return value: | 80 * Return value: (transfer none): |
| 81 * A %NULL terminated string corresponding to @format. Should not be freed. |
| 76 * | 82 * |
| 77 * Since: 0.9.2 | 83 * Since: 0.9.7 |
| 78 **/ | 84 **/ |
| 79 const char * | 85 const char * |
| 80 hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format) | 86 hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format) |
| 81 { | 87 { |
| 82 switch (format) | 88 switch (format) |
| 83 { | 89 { |
| 84 case HB_BUFFER_SERIALIZE_FORMAT_TEXT: return serialize_formats[0]; | 90 case HB_BUFFER_SERIALIZE_FORMAT_TEXT: return serialize_formats[0]; |
| 85 case HB_BUFFER_SERIALIZE_FORMAT_JSON: return serialize_formats[1]; | 91 case HB_BUFFER_SERIALIZE_FORMAT_JSON: return serialize_formats[1]; |
| 86 default: | 92 default: |
| 87 case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return NULL; | 93 case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return NULL; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 buf_size -= l; | 241 buf_size -= l; |
| 236 *buf_consumed += l; | 242 *buf_consumed += l; |
| 237 *buf = '\0'; | 243 *buf = '\0'; |
| 238 } else | 244 } else |
| 239 return i - start; | 245 return i - start; |
| 240 } | 246 } |
| 241 | 247 |
| 242 return end - start; | 248 return end - start; |
| 243 } | 249 } |
| 244 | 250 |
| 245 /* Returns number of items, starting at start, that were serialized. */ | |
| 246 /** | 251 /** |
| 247 * hb_buffer_serialize_glyphs: | 252 * hb_buffer_serialize_glyphs: |
| 248 * @buffer: a buffer. | 253 * @buffer: an #hb_buffer_t buffer. |
| 249 * @start: | 254 * @start: the first item in @buffer to serialize. |
| 250 * @end: | 255 * @end: the last item in @buffer to serialize. |
| 251 * @buf: (array length=buf_size): | 256 * @buf: (out) (array length=buf_size) (element-type uint8_t): output string to |
| 252 * @buf_size: | 257 * write serialized buffer into. |
| 253 * @buf_consumed: (out): | 258 * @buf_size: the size of @buf. |
| 254 * @font: | 259 * @buf_consumed: (out) (allow-none): if not %NULL, will be set to the number of
byes written into @buf. |
| 255 * @format: | 260 * @font: (allow-none): the #hb_font_t used to shape this buffer, needed to |
| 256 * @flags: | 261 * read glyph names and extents. If %NULL, and empty font will be used. |
| 262 * @format: the #hb_buffer_serialize_format_t to use for formatting the output. |
| 263 * @flags: the #hb_buffer_serialize_flags_t that control what glyph properties |
| 264 * to serialize. |
| 257 * | 265 * |
| 258 * | 266 * Serializes @buffer into a textual representation of its glyph content, |
| 267 * useful for showing the contents of the buffer, for example during debugging. |
| 268 * There are currently two supported serialization formats: |
| 269 * |
| 270 * ## text |
| 271 * A human-readable, plain text format. |
| 272 * The serialized glyphs will look something like: |
| 273 * |
| 274 * ``` |
| 275 * [uni0651=0@518,0+0|uni0628=0+1897] |
| 276 * ``` |
| 277 * - The serialized glyphs are delimited with `[` and `]`. |
| 278 * - Glyphs are separated with `|` |
| 279 * - Each glyph starts with glyph name, or glyph index if |
| 280 * #HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES flag is set. Then, |
| 281 * - If #HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS is not set, `=` then #hb_glyph_i
nfo_t.cluster. |
| 282 * - If #HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS is not set, the #hb_glyph_posit
ion_t in the format: |
| 283 * - If both #hb_glyph_position_t.x_offset and #hb_glyph_position_t.y_offset
are not 0, `@x_offset,y_offset`. Then, |
| 284 * - `+x_advance`, then `,y_advance` if #hb_glyph_position_t.y_advance is no
t 0. Then, |
| 285 * - If #HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS is set, the |
| 286 * #hb_glyph_extents_t in the format |
| 287 * `<x_bearing,y_bearing,width,height>` |
| 288 * |
| 289 * ## json |
| 290 * TODO. |
| 259 * | 291 * |
| 260 * Return value: | 292 * Return value: |
| 293 * The number of serialized items. |
| 261 * | 294 * |
| 262 * Since: 0.9.2 | 295 * Since: 0.9.7 |
| 263 **/ | 296 **/ |
| 264 unsigned int | 297 unsigned int |
| 265 hb_buffer_serialize_glyphs (hb_buffer_t *buffer, | 298 hb_buffer_serialize_glyphs (hb_buffer_t *buffer, |
| 266 unsigned int start, | 299 unsigned int start, |
| 267 unsigned int end, | 300 unsigned int end, |
| 268 char *buf, | 301 char *buf, |
| 269 unsigned int buf_size, | 302 unsigned int buf_size, |
| 270 » » » unsigned int *buf_consumed, /* May be NULL */ | 303 » » » unsigned int *buf_consumed, |
| 271 » » » hb_font_t *font, /* May be NULL */ | 304 » » » hb_font_t *font, |
| 272 hb_buffer_serialize_format_t format, | 305 hb_buffer_serialize_format_t format, |
| 273 hb_buffer_serialize_flags_t flags) | 306 hb_buffer_serialize_flags_t flags) |
| 274 { | 307 { |
| 275 assert (start <= end && end <= buffer->len); | 308 assert (start <= end && end <= buffer->len); |
| 276 | 309 |
| 277 unsigned int sconsumed; | 310 unsigned int sconsumed; |
| 278 if (!buf_consumed) | 311 if (!buf_consumed) |
| 279 buf_consumed = &sconsumed; | 312 buf_consumed = &sconsumed; |
| 280 *buf_consumed = 0; | 313 *buf_consumed = 0; |
| 281 | 314 |
| 282 assert ((!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALI
D) || | 315 assert ((!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALI
D) || |
| 283 buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS); | 316 buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS); |
| 284 | 317 |
| 318 if (!buffer->have_positions) |
| 319 flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS; |
| 320 |
| 285 if (unlikely (start == end)) | 321 if (unlikely (start == end)) |
| 286 return 0; | 322 return 0; |
| 287 | 323 |
| 288 if (!font) | 324 if (!font) |
| 289 font = hb_font_get_empty (); | 325 font = hb_font_get_empty (); |
| 290 | 326 |
| 291 switch (format) | 327 switch (format) |
| 292 { | 328 { |
| 293 case HB_BUFFER_SERIALIZE_FORMAT_TEXT: | 329 case HB_BUFFER_SERIALIZE_FORMAT_TEXT: |
| 294 return _hb_buffer_serialize_glyphs_text (buffer, start, end, | 330 return _hb_buffer_serialize_glyphs_text (buffer, start, end, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 384 |
| 349 *pv = v; | 385 *pv = v; |
| 350 return true; | 386 return true; |
| 351 } | 387 } |
| 352 | 388 |
| 353 #include "hb-buffer-deserialize-json.hh" | 389 #include "hb-buffer-deserialize-json.hh" |
| 354 #include "hb-buffer-deserialize-text.hh" | 390 #include "hb-buffer-deserialize-text.hh" |
| 355 | 391 |
| 356 /** | 392 /** |
| 357 * hb_buffer_deserialize_glyphs: | 393 * hb_buffer_deserialize_glyphs: |
| 358 * @buffer: a buffer. | 394 * @buffer: an #hb_buffer_t buffer. |
| 359 * @buf: (array length=buf_len): | 395 * @buf: (array length=buf_len): |
| 360 * @buf_len: | 396 * @buf_len: |
| 361 * @end_ptr: (out): | 397 * @end_ptr: (out): |
| 362 * @font: | 398 * @font: |
| 363 * @format: | 399 * @format: |
| 364 * | 400 * |
| 365 * | 401 * |
| 366 * | 402 * |
| 367 * Return value: | 403 * Return value: |
| 368 * | 404 * |
| 369 * Since: 0.9.2 | 405 * Since: 0.9.7 |
| 370 **/ | 406 **/ |
| 371 hb_bool_t | 407 hb_bool_t |
| 372 hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, | 408 hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, |
| 373 const char *buf, | 409 const char *buf, |
| 374 int buf_len, /* -1 means nul-terminated */ | 410 int buf_len, /* -1 means nul-terminated */ |
| 375 const char **end_ptr, /* May be NULL */ | 411 const char **end_ptr, /* May be NULL */ |
| 376 hb_font_t *font, /* May be NULL */ | 412 hb_font_t *font, /* May be NULL */ |
| 377 hb_buffer_serialize_format_t format) | 413 hb_buffer_serialize_format_t format) |
| 378 { | 414 { |
| 379 const char *end; | 415 const char *end; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 409 return _hb_buffer_deserialize_glyphs_json (buffer, | 445 return _hb_buffer_deserialize_glyphs_json (buffer, |
| 410 buf, buf_len, end_ptr, | 446 buf, buf_len, end_ptr, |
| 411 font); | 447 font); |
| 412 | 448 |
| 413 default: | 449 default: |
| 414 case HB_BUFFER_SERIALIZE_FORMAT_INVALID: | 450 case HB_BUFFER_SERIALIZE_FORMAT_INVALID: |
| 415 return false; | 451 return false; |
| 416 | 452 |
| 417 } | 453 } |
| 418 } | 454 } |
| OLD | NEW |