/** * hb_buffer_serialize_list_formats: * * Returns a list of supported buffer serialization formats. * * Return value: (transfer none): * A string array of buffer serialization formats. Should not be freed. * * Since: 0.9.7
**/ constchar **
hb_buffer_serialize_list_formats ()
{ return _hb_buffer_serialize_formats;
}
/** * hb_buffer_serialize_format_from_string: * @str: (array length=len) (element-type uint8_t): a string to parse * @len: length of @str, or -1 if string is `NULL` terminated * * Parses a string into an #hb_buffer_serialize_format_t. Does not check if * @str is a valid buffer serialization format, use * hb_buffer_serialize_list_formats() to get the list of supported formats. * * Return value: * The parsed #hb_buffer_serialize_format_t. * * Since: 0.9.7
**/
hb_buffer_serialize_format_t
hb_buffer_serialize_format_from_string (constchar *str, int len)
{ /* Upper-case it. */ return (hb_buffer_serialize_format_t) (hb_tag_from_string (str, len) & ~0x20202020u);
}
/** * hb_buffer_serialize_format_to_string: * @format: an #hb_buffer_serialize_format_t to convert. * * Converts @format to the string corresponding it, or `NULL` if it is not a valid * #hb_buffer_serialize_format_t. * * Return value: (transfer none): * A `NULL` terminated string corresponding to @format. Should not be freed. * * Since: 0.9.7
**/ constchar *
hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format)
{ switch ((unsigned) format)
{ case HB_BUFFER_SERIALIZE_FORMAT_TEXT: return _hb_buffer_serialize_formats[0]; case HB_BUFFER_SERIALIZE_FORMAT_JSON: return _hb_buffer_serialize_formats[1]; default: case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return nullptr;
}
}
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) {
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].cluster));
}
if (i == end-1)
*p++ = '>';
unsignedint l = p - b; if (buf_size > l)
{
hb_memcpy (buf, b, l);
buf += l;
buf_size -= l;
*buf_consumed += l;
*buf = '\0';
} else return i - start;
} return end - start;
}
/** * hb_buffer_serialize_glyphs: * @buffer: an #hb_buffer_t buffer. * @start: the first item in @buffer to serialize. * @end: the last item in @buffer to serialize. * @buf: (out) (array length=buf_size) (element-type uint8_t): output string to * write serialized buffer into. * @buf_size: the size of @buf. * @buf_consumed: (out) (optional): if not `NULL`, will be set to the number of bytes written into @buf. * @font: (nullable): the #hb_font_t used to shape this buffer, needed to * read glyph names and extents. If `NULL`, an empty font will be used. * @format: the #hb_buffer_serialize_format_t to use for formatting the output. * @flags: the #hb_buffer_serialize_flags_t that control what glyph properties * to serialize. * * Serializes @buffer into a textual representation of its glyph content, * useful for showing the contents of the buffer, for example during debugging. * There are currently two supported serialization formats: * * ## text * A human-readable, plain text format. * The serialized glyphs will look something like: * * ``` * [uni0651=0@518,0+0|uni0628=0+1897] * ``` * * - The serialized glyphs are delimited with `[` and `]`. * - Glyphs are separated with `|` * - Each glyph starts with glyph name, or glyph index if * #HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES flag is set. Then, * - If #HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS is not set, `=` then #hb_glyph_info_t.cluster. * - If #HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS is not set, the #hb_glyph_position_t in the format: * - If both #hb_glyph_position_t.x_offset and #hb_glyph_position_t.y_offset are not 0, `@x_offset,y_offset`. Then, * - `+x_advance`, then `,y_advance` if #hb_glyph_position_t.y_advance is not 0. Then, * - If #HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS is set, the #hb_glyph_extents_t in the format `<x_bearing,y_bearing,width,height>` * * ## json * A machine-readable, structured format. * The serialized glyphs will look something like: * * ``` * [{"g":"uni0651","cl":0,"dx":518,"dy":0,"ax":0,"ay":0}, * {"g":"uni0628","cl":0,"dx":0,"dy":0,"ax":1897,"ay":0}] * ``` * * Each glyph is a JSON object, with the following properties: * - `g`: the glyph name or glyph index if * #HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES flag is set. * - `cl`: #hb_glyph_info_t.cluster if * #HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS is not set. * - `dx`,`dy`,`ax`,`ay`: #hb_glyph_position_t.x_offset, #hb_glyph_position_t.y_offset, * #hb_glyph_position_t.x_advance and #hb_glyph_position_t.y_advance * respectively, if #HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS is not set. * - `xb`,`yb`,`w`,`h`: #hb_glyph_extents_t.x_bearing, #hb_glyph_extents_t.y_bearing, * #hb_glyph_extents_t.width and #hb_glyph_extents_t.height respectively if * #HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS is set. * * Return value: * The number of serialized items. * * Since: 0.9.7
**/ unsignedint
hb_buffer_serialize_glyphs (hb_buffer_t *buffer, unsignedint start, unsignedint end, char *buf, unsignedint buf_size, unsignedint *buf_consumed,
hb_font_t *font,
hb_buffer_serialize_format_t format,
hb_buffer_serialize_flags_t flags)
{
end = hb_clamp (end, start, buffer->len);
start = hb_min (start, end);
unsignedint sconsumed; if (!buf_consumed)
buf_consumed = &sconsumed;
*buf_consumed = 0; if (buf_size)
*buf = '\0';
buffer->assert_glyphs ();
if (!buffer->have_positions)
flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS;
default: case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return 0;
}
}
/** * hb_buffer_serialize_unicode: * @buffer: an #hb_buffer_t buffer. * @start: the first item in @buffer to serialize. * @end: the last item in @buffer to serialize. * @buf: (out) (array length=buf_size) (element-type uint8_t): output string to * write serialized buffer into. * @buf_size: the size of @buf. * @buf_consumed: (out) (optional): if not `NULL`, will be set to the number of bytes written into @buf. * @format: the #hb_buffer_serialize_format_t to use for formatting the output. * @flags: the #hb_buffer_serialize_flags_t that control what glyph properties * to serialize. * * Serializes @buffer into a textual representation of its content, * when the buffer contains Unicode codepoints (i.e., before shaping). This is * useful for showing the contents of the buffer, for example during debugging. * There are currently two supported serialization formats: * * ## text * A human-readable, plain text format. * The serialized codepoints will look something like: * * ``` * <U+0651=0|U+0628=1> * ``` * * - Glyphs are separated with `|` * - Unicode codepoints are expressed as zero-padded four (or more) * digit hexadecimal numbers preceded by `U+` * - If #HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS is not set, the cluster * will be indicated with a `=` then #hb_glyph_info_t.cluster. * * ## json * A machine-readable, structured format. * The serialized codepoints will be a list of objects with the following * properties: * - `u`: the Unicode codepoint as a decimal integer * - `cl`: #hb_glyph_info_t.cluster if * #HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS is not set. * * For example: * * ``` * [{u:1617,cl:0},{u:1576,cl:1}] * ``` * * Return value: * The number of serialized items. * * Since: 2.7.3
**/ unsignedint
hb_buffer_serialize_unicode (hb_buffer_t *buffer, unsignedint start, unsignedint end, char *buf, unsignedint buf_size, unsignedint *buf_consumed,
hb_buffer_serialize_format_t format,
hb_buffer_serialize_flags_t flags)
{
end = hb_clamp (end, start, buffer->len);
start = hb_min (start, end);
unsignedint sconsumed; if (!buf_consumed)
buf_consumed = &sconsumed;
*buf_consumed = 0; if (buf_size)
*buf = '\0';
/** * hb_buffer_serialize: * @buffer: an #hb_buffer_t buffer. * @start: the first item in @buffer to serialize. * @end: the last item in @buffer to serialize. * @buf: (out) (array length=buf_size) (element-type uint8_t): output string to * write serialized buffer into. * @buf_size: the size of @buf. * @buf_consumed: (out) (optional): if not `NULL`, will be set to the number of bytes written into @buf. * @font: (nullable): the #hb_font_t used to shape this buffer, needed to * read glyph names and extents. If `NULL`, an empty font will be used. * @format: the #hb_buffer_serialize_format_t to use for formatting the output. * @flags: the #hb_buffer_serialize_flags_t that control what glyph properties * to serialize. * * Serializes @buffer into a textual representation of its content, whether * Unicode codepoints or glyph identifiers and positioning information. This is * useful for showing the contents of the buffer, for example during debugging. * See the documentation of hb_buffer_serialize_unicode() and * hb_buffer_serialize_glyphs() for a description of the output format. * * Return value: * The number of serialized items. * * Since: 2.7.3
**/ unsignedint
hb_buffer_serialize (hb_buffer_t *buffer, unsignedint start, unsignedint end, char *buf, unsignedint buf_size, unsignedint *buf_consumed,
hb_font_t *font,
hb_buffer_serialize_format_t format,
hb_buffer_serialize_flags_t flags)
{ switch (buffer->content_type)
{
case HB_BUFFER_CONTENT_TYPE_GLYPHS: return hb_buffer_serialize_glyphs (buffer, start, end, buf, buf_size,
buf_consumed, font, format, flags);
case HB_BUFFER_CONTENT_TYPE_UNICODE: return hb_buffer_serialize_unicode (buffer, start, end, buf, buf_size,
buf_consumed, format, flags);
case HB_BUFFER_CONTENT_TYPE_INVALID: default: return _hb_buffer_serialize_invalid (buffer, start, end, buf, buf_size,
buf_consumed, format, flags);
}
}
/** * hb_buffer_deserialize_glyphs: * @buffer: an #hb_buffer_t buffer. * @buf: (array length=buf_len): string to deserialize * @buf_len: the size of @buf, or -1 if it is `NULL`-terminated * @end_ptr: (out) (optional): output pointer to the character after last * consumed one. * @font: (nullable): font for getting glyph IDs * @format: the #hb_buffer_serialize_format_t of the input @buf * * Deserializes glyphs @buffer from textual representation in the format * produced by hb_buffer_serialize_glyphs(). * * Return value: `true` if parse was successful, `false` if an error * occurred. * * Since: 0.9.7
**/
hb_bool_t
hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, constchar *buf, int buf_len, /* -1 means nul-terminated */ constchar **end_ptr, /* May be NULL */
hb_font_t *font, /* May be NULL */
hb_buffer_serialize_format_t format)
{ constchar *end; if (!end_ptr)
end_ptr = &end;
*end_ptr = buf;
buffer->assert_glyphs ();
if (unlikely (hb_object_is_immutable (buffer)))
{ if (end_ptr)
*end_ptr = buf; returnfalse;
}
case HB_BUFFER_SERIALIZE_FORMAT_JSON: return _hb_buffer_deserialize_json (buffer,
buf, buf_len, end_ptr,
font);
default: case HB_BUFFER_SERIALIZE_FORMAT_INVALID: returnfalse;
}
}
/** * hb_buffer_deserialize_unicode: * @buffer: an #hb_buffer_t buffer. * @buf: (array length=buf_len): string to deserialize * @buf_len: the size of @buf, or -1 if it is `NULL`-terminated * @end_ptr: (out) (optional): output pointer to the character after last * consumed one. * @format: the #hb_buffer_serialize_format_t of the input @buf * * Deserializes Unicode @buffer from textual representation in the format * produced by hb_buffer_serialize_unicode(). * * Return value: `true` if parse was successful, `false` if an error * occurred. * * Since: 2.7.3
**/
hb_bool_t
hb_buffer_deserialize_unicode (hb_buffer_t *buffer, constchar *buf, int buf_len, /* -1 means nul-terminated */ constchar **end_ptr, /* May be NULL */
hb_buffer_serialize_format_t format)
{ constchar *end; if (!end_ptr)
end_ptr = &end;
*end_ptr = buf;
buffer->assert_unicode ();
if (unlikely (hb_object_is_immutable (buffer)))
{ if (end_ptr)
*end_ptr = buf; returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.