2013-02-27 17:06:36 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2012,2013 Google, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
|
* all copies of this software.
|
|
|
|
|
*
|
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
|
* DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
*
|
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
|
*/
|
|
|
|
|
|
2019-06-18 22:26:03 +02:00
|
|
|
|
#include "hb.hh"
|
|
|
|
|
|
|
|
|
|
#ifndef HB_NO_BUFFER_SERIALIZE
|
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
|
#include "hb-buffer.hh"
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
|
2022-06-16 21:50:35 +02:00
|
|
|
|
static const char *_hb_buffer_serialize_formats[] = {
|
2013-02-27 17:06:36 +01:00
|
|
|
|
"text",
|
|
|
|
|
"json",
|
2017-10-15 12:11:08 +02:00
|
|
|
|
nullptr
|
2013-02-27 17:06:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* hb_buffer_serialize_list_formats:
|
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* Returns a list of supported buffer serialization formats.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
|
|
|
|
* Return value: (transfer none):
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* A string array of buffer serialization formats. Should not be freed.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
|
**/
|
2013-02-27 17:06:36 +01:00
|
|
|
|
const char **
|
2018-12-17 19:01:01 +01:00
|
|
|
|
hb_buffer_serialize_list_formats ()
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
2022-06-16 21:50:35 +02:00
|
|
|
|
return _hb_buffer_serialize_formats;
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* hb_buffer_serialize_format_from_string:
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* @str: (array length=len) (element-type uint8_t): a string to parse
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* @len: length of @str, or -1 if string is `NULL` terminated
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* 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.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2018-10-20 16:20:39 +02:00
|
|
|
|
* Return value:
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* The parsed #hb_buffer_serialize_format_t.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
|
**/
|
2013-02-27 17:06:36 +01:00
|
|
|
|
hb_buffer_serialize_format_t
|
|
|
|
|
hb_buffer_serialize_format_from_string (const char *str, int len)
|
|
|
|
|
{
|
|
|
|
|
/* Upper-case it. */
|
2014-07-11 20:54:42 +02:00
|
|
|
|
return (hb_buffer_serialize_format_t) (hb_tag_from_string (str, len) & ~0x20202020u);
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* hb_buffer_serialize_format_to_string:
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* @format: an #hb_buffer_serialize_format_t to convert.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* Converts @format to the string corresponding it, or `NULL` if it is not a valid
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* #hb_buffer_serialize_format_t.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* Return value: (transfer none):
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* A `NULL` terminated string corresponding to @format. Should not be freed.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
|
**/
|
2013-02-27 17:06:36 +01:00
|
|
|
|
const char *
|
|
|
|
|
hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format)
|
|
|
|
|
{
|
2019-05-13 00:33:31 +02:00
|
|
|
|
switch ((unsigned) format)
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
2022-06-16 21:50:35 +02:00
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_TEXT: return _hb_buffer_serialize_formats[0];
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_JSON: return _hb_buffer_serialize_formats[1];
|
2013-02-27 17:06:36 +01:00
|
|
|
|
default:
|
2020-09-18 10:35:05 +02:00
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return nullptr;
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
|
_hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
|
|
|
|
unsigned int *buf_consumed,
|
|
|
|
|
hb_font_t *font,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
2017-10-15 12:11:08 +02:00
|
|
|
|
hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
|
2015-08-18 19:47:02 +02:00
|
|
|
|
hb_glyph_position_t *pos = (flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS) ?
|
2020-09-18 10:35:05 +02:00
|
|
|
|
nullptr : hb_buffer_get_glyph_positions (buffer, nullptr);
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
*buf_consumed = 0;
|
2018-01-10 02:20:14 +01:00
|
|
|
|
hb_position_t x = 0, y = 0;
|
2013-02-27 17:06:36 +01:00
|
|
|
|
for (unsigned int i = start; i < end; i++)
|
|
|
|
|
{
|
|
|
|
|
char b[1024];
|
|
|
|
|
char *p = b;
|
|
|
|
|
|
|
|
|
|
/* In the following code, we know b is large enough that no overflow can happen. */
|
|
|
|
|
|
|
|
|
|
#define APPEND(s) HB_STMT_START { strcpy (p, s); p += strlen (s); } HB_STMT_END
|
|
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
|
*p++ = ',';
|
2020-09-18 11:31:28 +02:00
|
|
|
|
else
|
|
|
|
|
*p++ = '[';
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
*p++ = '{';
|
|
|
|
|
|
|
|
|
|
APPEND ("\"g\":");
|
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES))
|
|
|
|
|
{
|
|
|
|
|
char g[128];
|
|
|
|
|
hb_font_glyph_to_string (font, info[i].codepoint, g, sizeof (g));
|
|
|
|
|
*p++ = '"';
|
2020-10-10 05:13:10 +02:00
|
|
|
|
for (char *q = g; *q; q++)
|
|
|
|
|
{
|
|
|
|
|
if (unlikely (*q == '"' || *q == '\\'))
|
|
|
|
|
*p++ = '\\';
|
|
|
|
|
*p++ = *q;
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
*p++ = '"';
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint));
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) {
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"cl\":%u", info[i].cluster));
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS))
|
|
|
|
|
{
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"dx\":%d,\"dy\":%d",
|
2020-10-10 05:13:10 +02:00
|
|
|
|
x+pos[i].x_offset, y+pos[i].y_offset));
|
2018-01-10 02:20:14 +01:00
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES))
|
2020-09-18 10:35:05 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d",
|
2020-10-10 05:13:10 +02:00
|
|
|
|
pos[i].x_advance, pos[i].y_advance));
|
2016-05-02 14:47:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS)
|
|
|
|
|
{
|
2014-07-20 00:09:09 +02:00
|
|
|
|
if (info[i].mask & HB_GLYPH_FLAG_DEFINED)
|
2020-09-18 10:35:05 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"fl\":%u", info[i].mask & HB_GLYPH_FLAG_DEFINED));
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-24 14:49:55 +02:00
|
|
|
|
if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS)
|
|
|
|
|
{
|
|
|
|
|
hb_glyph_extents_t extents;
|
|
|
|
|
hb_font_get_glyph_extents(font, info[i].codepoint, &extents);
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"xb\":%d,\"yb\":%d",
|
2020-09-18 10:35:05 +02:00
|
|
|
|
extents.x_bearing, extents.y_bearing));
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"w\":%d,\"h\":%d",
|
2020-09-18 10:35:05 +02:00
|
|
|
|
extents.width, extents.height));
|
2015-08-24 14:49:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 17:06:36 +01:00
|
|
|
|
*p++ = '}';
|
2020-09-18 11:31:28 +02:00
|
|
|
|
if (i == end-1)
|
|
|
|
|
*p++ = ']';
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
2013-10-30 18:27:24 +01:00
|
|
|
|
unsigned int l = p - b;
|
|
|
|
|
if (buf_size > l)
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
|
|
|
|
memcpy (buf, b, l);
|
|
|
|
|
buf += l;
|
|
|
|
|
buf_size -= l;
|
|
|
|
|
*buf_consumed += l;
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
} else
|
|
|
|
|
return i - start;
|
2018-01-10 02:20:14 +01:00
|
|
|
|
|
2018-01-11 11:37:12 +01:00
|
|
|
|
if (pos && (flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES))
|
2018-01-10 02:20:14 +01:00
|
|
|
|
{
|
|
|
|
|
x += pos[i].x_advance;
|
|
|
|
|
y += pos[i].y_advance;
|
|
|
|
|
}
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return end - start;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 17:29:40 +02:00
|
|
|
|
static unsigned int
|
|
|
|
|
_hb_buffer_serialize_unicode_json (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
2020-09-21 15:35:05 +02:00
|
|
|
|
unsigned int *buf_consumed,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
2020-09-17 17:29:40 +02:00
|
|
|
|
{
|
2020-09-18 10:35:05 +02:00
|
|
|
|
hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
*buf_consumed = 0;
|
|
|
|
|
for (unsigned int i = start; i < end; i++)
|
|
|
|
|
{
|
|
|
|
|
char b[1024];
|
|
|
|
|
char *p = b;
|
2020-09-21 15:35:05 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
if (i)
|
|
|
|
|
*p++ = ',';
|
2020-09-18 11:31:28 +02:00
|
|
|
|
else
|
|
|
|
|
*p++ = '[';
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-21 15:35:05 +02:00
|
|
|
|
*p++ = '{';
|
|
|
|
|
|
|
|
|
|
APPEND ("\"u\":");
|
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint));
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-21 15:35:05 +02:00
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) {
|
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"cl\":%u", info[i].cluster));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*p++ = '}';
|
|
|
|
|
|
2020-09-18 11:31:28 +02:00
|
|
|
|
if (i == end-1)
|
|
|
|
|
*p++ = ']';
|
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int l = p - b;
|
|
|
|
|
if (buf_size > l)
|
|
|
|
|
{
|
|
|
|
|
memcpy (buf, b, l);
|
|
|
|
|
buf += l;
|
|
|
|
|
buf_size -= l;
|
|
|
|
|
*buf_consumed += l;
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
} else
|
|
|
|
|
return i - start;
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
}
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
return end - start;
|
2020-09-17 17:29:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 17:06:36 +01:00
|
|
|
|
static unsigned int
|
|
|
|
|
_hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
|
|
|
|
unsigned int *buf_consumed,
|
|
|
|
|
hb_font_t *font,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
2017-10-15 12:11:08 +02:00
|
|
|
|
hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
|
2015-08-18 19:47:02 +02:00
|
|
|
|
hb_glyph_position_t *pos = (flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS) ?
|
2020-09-18 10:35:05 +02:00
|
|
|
|
nullptr : hb_buffer_get_glyph_positions (buffer, nullptr);
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
*buf_consumed = 0;
|
2018-01-10 02:20:14 +01:00
|
|
|
|
hb_position_t x = 0, y = 0;
|
2013-02-27 17:06:36 +01:00
|
|
|
|
for (unsigned int i = start; i < end; i++)
|
|
|
|
|
{
|
|
|
|
|
char b[1024];
|
|
|
|
|
char *p = b;
|
|
|
|
|
|
|
|
|
|
/* In the following code, we know b is large enough that no overflow can happen. */
|
|
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
|
*p++ = '|';
|
2020-09-18 11:31:28 +02:00
|
|
|
|
else
|
|
|
|
|
*p++ = '[';
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES))
|
|
|
|
|
{
|
2020-10-10 05:13:10 +02:00
|
|
|
|
/* TODO Escape delimiters we use. */
|
2013-02-27 17:06:36 +01:00
|
|
|
|
hb_font_glyph_to_string (font, info[i].codepoint, p, 128);
|
|
|
|
|
p += strlen (p);
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint));
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) {
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].cluster));
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS))
|
|
|
|
|
{
|
2018-01-10 02:20:14 +01:00
|
|
|
|
if (x+pos[i].x_offset || y+pos[i].y_offset)
|
2020-09-18 10:35:05 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", x+pos[i].x_offset, y+pos[i].y_offset));
|
2018-01-10 02:20:14 +01:00
|
|
|
|
|
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES))
|
|
|
|
|
{
|
2020-09-18 10:35:05 +02:00
|
|
|
|
*p++ = '+';
|
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advance));
|
|
|
|
|
if (pos[i].y_advance)
|
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance));
|
2018-01-10 02:20:14 +01:00
|
|
|
|
}
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 14:47:45 +02:00
|
|
|
|
if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS)
|
|
|
|
|
{
|
2018-12-16 03:00:55 +01:00
|
|
|
|
if (info[i].mask & HB_GLYPH_FLAG_DEFINED)
|
2020-09-18 10:35:05 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "#%X", info[i].mask &HB_GLYPH_FLAG_DEFINED));
|
2016-05-02 14:47:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-24 14:49:55 +02:00
|
|
|
|
if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS)
|
|
|
|
|
{
|
|
|
|
|
hb_glyph_extents_t extents;
|
|
|
|
|
hb_font_get_glyph_extents(font, info[i].codepoint, &extents);
|
2019-05-08 05:54:31 +02:00
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "<%d,%d,%d,%d>", extents.x_bearing, extents.y_bearing, extents.width, extents.height));
|
2015-08-24 14:49:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:31:28 +02:00
|
|
|
|
if (i == end-1) {
|
|
|
|
|
*p++ = ']';
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-30 18:27:24 +01:00
|
|
|
|
unsigned int l = p - b;
|
|
|
|
|
if (buf_size > l)
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
|
|
|
|
memcpy (buf, b, l);
|
|
|
|
|
buf += l;
|
|
|
|
|
buf_size -= l;
|
|
|
|
|
*buf_consumed += l;
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
} else
|
|
|
|
|
return i - start;
|
2018-01-10 02:20:14 +01:00
|
|
|
|
|
2018-01-11 11:37:12 +01:00
|
|
|
|
if (pos && (flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES))
|
2018-01-10 02:20:14 +01:00
|
|
|
|
{
|
|
|
|
|
x += pos[i].x_advance;
|
|
|
|
|
y += pos[i].y_advance;
|
|
|
|
|
}
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return end - start;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
|
_hb_buffer_serialize_unicode_text (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
2020-09-21 15:35:05 +02:00
|
|
|
|
unsigned int *buf_consumed,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
2020-09-17 17:29:40 +02:00
|
|
|
|
{
|
2020-09-18 10:27:27 +02:00
|
|
|
|
hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
|
|
|
|
|
*buf_consumed = 0;
|
|
|
|
|
for (unsigned int i = start; i < end; i++)
|
|
|
|
|
{
|
|
|
|
|
char b[1024];
|
|
|
|
|
char *p = b;
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:27:27 +02:00
|
|
|
|
if (i)
|
|
|
|
|
*p++ = '|';
|
2020-09-18 11:31:28 +02:00
|
|
|
|
else
|
|
|
|
|
*p++ = '<';
|
2020-09-18 10:27:27 +02:00
|
|
|
|
|
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "U+%04X", info[i].codepoint));
|
2020-09-18 11:31:28 +02:00
|
|
|
|
|
2020-09-21 15:35:05 +02:00
|
|
|
|
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) {
|
|
|
|
|
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].cluster));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:31:28 +02:00
|
|
|
|
if (i == end-1)
|
|
|
|
|
*p++ = '>';
|
|
|
|
|
|
2020-09-18 10:27:27 +02:00
|
|
|
|
unsigned int l = p - b;
|
|
|
|
|
if (buf_size > l)
|
|
|
|
|
{
|
|
|
|
|
memcpy (buf, b, l);
|
|
|
|
|
buf += l;
|
|
|
|
|
buf_size -= l;
|
|
|
|
|
*buf_consumed += l;
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
} else
|
|
|
|
|
return i - start;
|
|
|
|
|
}
|
|
|
|
|
return end - start;
|
2020-09-17 17:29:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* hb_buffer_serialize_glyphs:
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* @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.
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* @buf_consumed: (out) (optional): if not `NULL`, will be set to the number of bytes written into @buf.
|
2020-12-30 23:28:27 +01:00
|
|
|
|
* @font: (nullable): the #hb_font_t used to shape this buffer, needed to
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* read glyph names and extents. If `NULL`, an empty font will be used.
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* @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.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* 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]
|
|
|
|
|
* ```
|
2020-12-22 22:52:46 +01:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* - 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,
|
2020-12-22 22:52:46 +01:00
|
|
|
|
* - If #HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS is set, the #hb_glyph_extents_t in the format `<x_bearing,y_bearing,width,height>`
|
2016-01-01 17:38:21 +01:00
|
|
|
|
*
|
|
|
|
|
* ## json
|
2020-09-18 11:24:29 +02:00
|
|
|
|
* 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}]
|
|
|
|
|
* ```
|
2020-12-22 22:52:46 +01:00
|
|
|
|
*
|
2020-09-18 11:24:29 +02:00
|
|
|
|
* 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.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2018-10-20 16:20:39 +02:00
|
|
|
|
* Return value:
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* The number of serialized items.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
|
**/
|
2013-02-27 17:06:36 +01:00
|
|
|
|
unsigned int
|
|
|
|
|
hb_buffer_serialize_glyphs (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
|
|
|
|
unsigned int *buf_consumed,
|
|
|
|
|
hb_font_t *font,
|
|
|
|
|
hb_buffer_serialize_format_t format,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
2020-10-10 01:58:57 +02:00
|
|
|
|
end = hb_clamp (end, start, buffer->len);
|
|
|
|
|
start = hb_min (start, end);
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
2013-02-27 18:02:42 +01:00
|
|
|
|
unsigned int sconsumed;
|
|
|
|
|
if (!buf_consumed)
|
|
|
|
|
buf_consumed = &sconsumed;
|
2013-02-27 17:06:36 +01:00
|
|
|
|
*buf_consumed = 0;
|
2017-03-08 03:13:28 +01:00
|
|
|
|
if (buf_size)
|
|
|
|
|
*buf = '\0';
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
2020-10-15 10:02:04 +02:00
|
|
|
|
buffer->assert_glyphs ();
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
2015-12-18 18:30:18 +01:00
|
|
|
|
if (!buffer->have_positions)
|
|
|
|
|
flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS;
|
|
|
|
|
|
2013-02-27 17:06:36 +01:00
|
|
|
|
if (unlikely (start == end))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!font)
|
|
|
|
|
font = hb_font_get_empty ();
|
|
|
|
|
|
|
|
|
|
switch (format)
|
|
|
|
|
{
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_TEXT:
|
|
|
|
|
return _hb_buffer_serialize_glyphs_text (buffer, start, end,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
buf, buf_size, buf_consumed,
|
|
|
|
|
font, flags);
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_JSON:
|
|
|
|
|
return _hb_buffer_serialize_glyphs_json (buffer, start, end,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
buf, buf_size, buf_consumed,
|
|
|
|
|
font, flags);
|
2013-02-27 17:06:36 +01:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_INVALID:
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:24:29 +02:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* @buf_consumed: (out) (optional): if not `NULL`, will be set to the number of bytes written into @buf.
|
2020-09-18 11:24:29 +02:00
|
|
|
|
* @format: the #hb_buffer_serialize_format_t to use for formatting the output.
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* @flags: the #hb_buffer_serialize_flags_t that control what glyph properties
|
|
|
|
|
* to serialize.
|
2020-09-18 11:24:29 +02:00
|
|
|
|
*
|
|
|
|
|
* 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:
|
|
|
|
|
*
|
|
|
|
|
* ```
|
2020-12-22 22:52:46 +01:00
|
|
|
|
* <U+0651=0|U+0628=1>
|
2020-09-18 11:24:29 +02:00
|
|
|
|
* ```
|
2020-12-22 22:52:46 +01:00
|
|
|
|
*
|
2020-09-18 11:24:29 +02:00
|
|
|
|
* - Glyphs are separated with `|`
|
|
|
|
|
* - Unicode codepoints are expressed as zero-padded four (or more)
|
|
|
|
|
* digit hexadecimal numbers preceded by `U+`
|
2020-09-21 15:35:05 +02:00
|
|
|
|
* - If #HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS is not set, the cluster
|
|
|
|
|
* will be indicated with a `=` then #hb_glyph_info_t.cluster.
|
2020-09-18 11:24:29 +02:00
|
|
|
|
*
|
|
|
|
|
* ## json
|
|
|
|
|
* A machine-readable, structured format.
|
2020-09-21 15:35:05 +02:00
|
|
|
|
* The serialized codepoints will be a list of objects with the following
|
|
|
|
|
* properties:
|
2020-09-21 17:35:40 +02:00
|
|
|
|
* - `u`: the Unicode codepoint as a decimal integer
|
2020-09-21 15:35:05 +02:00
|
|
|
|
* - `cl`: #hb_glyph_info_t.cluster if
|
|
|
|
|
* #HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS is not set.
|
|
|
|
|
*
|
|
|
|
|
* For example:
|
2020-12-22 22:52:46 +01:00
|
|
|
|
*
|
2020-09-18 11:24:29 +02:00
|
|
|
|
* ```
|
2020-09-21 17:35:40 +02:00
|
|
|
|
* [{u:1617,cl:0},{u:1576,cl:1}]
|
2020-09-18 11:24:29 +02:00
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* The number of serialized items.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.7.3
|
|
|
|
|
**/
|
2020-09-17 17:29:40 +02:00
|
|
|
|
unsigned int
|
|
|
|
|
hb_buffer_serialize_unicode (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
|
|
|
|
unsigned int *buf_consumed,
|
2020-09-21 15:35:05 +02:00
|
|
|
|
hb_buffer_serialize_format_t format,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
2020-09-17 17:29:40 +02:00
|
|
|
|
{
|
2020-10-10 01:58:57 +02:00
|
|
|
|
end = hb_clamp (end, start, buffer->len);
|
|
|
|
|
start = hb_min (start, end);
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int sconsumed;
|
|
|
|
|
if (!buf_consumed)
|
|
|
|
|
buf_consumed = &sconsumed;
|
|
|
|
|
*buf_consumed = 0;
|
|
|
|
|
if (buf_size)
|
|
|
|
|
*buf = '\0';
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-10-15 10:02:04 +02:00
|
|
|
|
buffer->assert_unicode ();
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
if (unlikely (start == end))
|
|
|
|
|
return 0;
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
switch (format)
|
|
|
|
|
{
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_TEXT:
|
|
|
|
|
return _hb_buffer_serialize_unicode_text (buffer, start, end,
|
2020-09-21 15:35:05 +02:00
|
|
|
|
buf, buf_size, buf_consumed, flags);
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_JSON:
|
|
|
|
|
return _hb_buffer_serialize_unicode_json (buffer, start, end,
|
2020-09-21 15:35:05 +02:00
|
|
|
|
buf, buf_size, buf_consumed, flags);
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
default:
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_INVALID:
|
|
|
|
|
return 0;
|
2020-09-17 17:29:40 +02:00
|
|
|
|
|
2020-09-18 10:35:05 +02:00
|
|
|
|
}
|
2020-09-17 17:29:40 +02:00
|
|
|
|
}
|
2020-09-25 22:24:41 +02:00
|
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
|
_hb_buffer_serialize_invalid (hb_buffer_t *buffer,
|
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
|
|
|
|
unsigned int *buf_consumed,
|
|
|
|
|
hb_buffer_serialize_format_t format,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
|
|
|
|
{
|
2020-10-10 02:01:32 +02:00
|
|
|
|
assert (!buffer->len);
|
|
|
|
|
|
2020-09-25 22:24:41 +02:00
|
|
|
|
unsigned int sconsumed;
|
|
|
|
|
if (!buf_consumed)
|
|
|
|
|
buf_consumed = &sconsumed;
|
|
|
|
|
if (buf_size < 3)
|
|
|
|
|
return 0;
|
|
|
|
|
if (format == HB_BUFFER_SERIALIZE_FORMAT_JSON) {
|
|
|
|
|
*buf++ = '[';
|
|
|
|
|
*buf++ = ']';
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
} else if (format == HB_BUFFER_SERIALIZE_FORMAT_TEXT) {
|
|
|
|
|
*buf++ = '!';
|
|
|
|
|
*buf++ = '!';
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
}
|
|
|
|
|
*buf_consumed = 2;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 17:29:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* @buf_consumed: (out) (optional): if not `NULL`, will be set to the number of bytes written into @buf.
|
2020-12-30 23:28:27 +01:00
|
|
|
|
* @font: (nullable): the #hb_font_t used to shape this buffer, needed to
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* read glyph names and extents. If `NULL`, an empty font will be used.
|
2020-09-17 17:29:40 +02:00
|
|
|
|
* @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.
|
2020-09-18 10:35:05 +02:00
|
|
|
|
* See the documentation of hb_buffer_serialize_unicode() and
|
|
|
|
|
* hb_buffer_serialize_glyphs() for a description of the output format.
|
2020-09-17 17:29:40 +02:00
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* The number of serialized items.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.7.3
|
|
|
|
|
**/
|
|
|
|
|
unsigned int
|
|
|
|
|
hb_buffer_serialize (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
unsigned int start,
|
|
|
|
|
unsigned int end,
|
|
|
|
|
char *buf,
|
|
|
|
|
unsigned int buf_size,
|
|
|
|
|
unsigned int *buf_consumed,
|
|
|
|
|
hb_font_t *font,
|
|
|
|
|
hb_buffer_serialize_format_t format,
|
|
|
|
|
hb_buffer_serialize_flags_t flags)
|
2020-09-17 17:29:40 +02:00
|
|
|
|
{
|
2020-09-25 22:24:41 +02:00
|
|
|
|
switch (buffer->content_type)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
case HB_BUFFER_CONTENT_TYPE_GLYPHS:
|
2020-10-10 02:02:16 +02:00
|
|
|
|
return hb_buffer_serialize_glyphs (buffer, start, end, buf, buf_size,
|
|
|
|
|
buf_consumed, font, format, flags);
|
2020-09-25 22:24:41 +02:00
|
|
|
|
|
|
|
|
|
case HB_BUFFER_CONTENT_TYPE_UNICODE:
|
2020-10-10 02:02:16 +02:00
|
|
|
|
return hb_buffer_serialize_unicode (buffer, start, end, buf, buf_size,
|
|
|
|
|
buf_consumed, format, flags);
|
2020-09-25 22:24:41 +02:00
|
|
|
|
|
|
|
|
|
case HB_BUFFER_CONTENT_TYPE_INVALID:
|
|
|
|
|
default:
|
2020-10-10 02:02:16 +02:00
|
|
|
|
return _hb_buffer_serialize_invalid (buffer, start, end, buf, buf_size,
|
|
|
|
|
buf_consumed, format, flags);
|
2020-09-25 22:24:41 +02:00
|
|
|
|
}
|
2020-09-17 17:29:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-02 22:32:40 +02:00
|
|
|
|
static bool
|
|
|
|
|
parse_int (const char *pp, const char *end, int32_t *pv)
|
2013-02-27 19:01:02 +01:00
|
|
|
|
{
|
2019-09-02 22:32:40 +02:00
|
|
|
|
int v;
|
|
|
|
|
const char *p = pp;
|
2019-09-03 20:39:47 +02:00
|
|
|
|
if (unlikely (!hb_parse_int (&p, end, &v, true/* whole buffer */)))
|
|
|
|
|
return false;
|
2013-02-28 00:39:37 +01:00
|
|
|
|
|
|
|
|
|
*pv = v;
|
|
|
|
|
return true;
|
2013-02-27 19:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-02 22:32:40 +02:00
|
|
|
|
static bool
|
|
|
|
|
parse_uint (const char *pp, const char *end, uint32_t *pv)
|
2013-02-28 00:39:37 +01:00
|
|
|
|
{
|
2019-09-03 14:30:46 +02:00
|
|
|
|
unsigned int v;
|
|
|
|
|
const char *p = pp;
|
2019-09-03 20:39:47 +02:00
|
|
|
|
if (unlikely (!hb_parse_uint (&p, end, &v, true/* whole buffer */)))
|
|
|
|
|
return false;
|
2013-02-28 00:39:37 +01:00
|
|
|
|
|
|
|
|
|
*pv = v;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 15:19:17 +02:00
|
|
|
|
static bool
|
|
|
|
|
parse_hex (const char *pp, const char *end, uint32_t *pv)
|
|
|
|
|
{
|
|
|
|
|
unsigned int v;
|
|
|
|
|
const char *p = pp;
|
|
|
|
|
if (unlikely (!hb_parse_uint (&p, end, &v, true/* whole buffer */, 16)))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
*pv = v;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 00:39:37 +01:00
|
|
|
|
#include "hb-buffer-deserialize-json.hh"
|
2013-02-27 23:59:28 +01:00
|
|
|
|
#include "hb-buffer-deserialize-text.hh"
|
2013-02-27 19:01:02 +01:00
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* hb_buffer_deserialize_glyphs:
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* @buffer: an #hb_buffer_t buffer.
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* @buf: (array length=buf_len): string to deserialize
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* @buf_len: the size of @buf, or -1 if it is `NULL`-terminated
|
2020-12-30 23:28:27 +01:00
|
|
|
|
* @end_ptr: (out) (optional): output pointer to the character after last
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* consumed one.
|
2020-12-30 23:28:27 +01:00
|
|
|
|
* @font: (nullable): font for getting glyph IDs
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* @format: the #hb_buffer_serialize_format_t of the input @buf
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* Deserializes glyphs @buffer from textual representation in the format
|
|
|
|
|
* produced by hb_buffer_serialize_glyphs().
|
2018-10-20 16:20:39 +02:00
|
|
|
|
*
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* Return value: `true` if @buf is not fully consumed, `false` otherwise.
|
2013-09-06 21:40:22 +02:00
|
|
|
|
*
|
2016-01-01 17:38:21 +01:00
|
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
|
**/
|
2013-02-27 17:06:36 +01:00
|
|
|
|
hb_bool_t
|
|
|
|
|
hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
|
2020-09-18 10:35:05 +02:00
|
|
|
|
const char *buf,
|
|
|
|
|
int buf_len, /* -1 means nul-terminated */
|
|
|
|
|
const char **end_ptr, /* May be NULL */
|
|
|
|
|
hb_font_t *font, /* May be NULL */
|
|
|
|
|
hb_buffer_serialize_format_t format)
|
2013-02-27 17:06:36 +01:00
|
|
|
|
{
|
2013-02-27 23:59:28 +01:00
|
|
|
|
const char *end;
|
|
|
|
|
if (!end_ptr)
|
|
|
|
|
end_ptr = &end;
|
|
|
|
|
*end_ptr = buf;
|
2013-02-27 19:01:02 +01:00
|
|
|
|
|
2020-10-15 10:02:04 +02:00
|
|
|
|
buffer->assert_glyphs ();
|
2013-02-27 19:01:02 +01:00
|
|
|
|
|
2020-09-22 00:50:11 +02:00
|
|
|
|
if (unlikely (hb_object_is_immutable (buffer)))
|
|
|
|
|
{
|
2020-10-10 01:55:21 +02:00
|
|
|
|
if (end_ptr)
|
|
|
|
|
*end_ptr = buf;
|
2020-09-22 00:50:11 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 19:01:02 +01:00
|
|
|
|
if (buf_len == -1)
|
|
|
|
|
buf_len = strlen (buf);
|
|
|
|
|
|
|
|
|
|
if (!buf_len)
|
|
|
|
|
{
|
2013-02-27 23:59:28 +01:00
|
|
|
|
*end_ptr = buf;
|
|
|
|
|
return false;
|
2013-02-27 19:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_GLYPHS);
|
|
|
|
|
|
|
|
|
|
if (!font)
|
|
|
|
|
font = hb_font_get_empty ();
|
|
|
|
|
|
|
|
|
|
switch (format)
|
|
|
|
|
{
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_TEXT:
|
2020-09-18 15:19:17 +02:00
|
|
|
|
return _hb_buffer_deserialize_text (buffer,
|
|
|
|
|
buf, buf_len, end_ptr,
|
|
|
|
|
font);
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* hb_buffer_deserialize_unicode:
|
|
|
|
|
* @buffer: an #hb_buffer_t buffer.
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* @buf: (array length=buf_len): string to deserialize
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* @buf_len: the size of @buf, or -1 if it is `NULL`-terminated
|
2020-12-30 23:28:27 +01:00
|
|
|
|
* @end_ptr: (out) (optional): output pointer to the character after last
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* consumed one.
|
|
|
|
|
* @format: the #hb_buffer_serialize_format_t of the input @buf
|
2020-09-18 15:19:17 +02:00
|
|
|
|
*
|
2020-12-30 22:44:30 +01:00
|
|
|
|
* Deserializes Unicode @buffer from textual representation in the format
|
|
|
|
|
* produced by hb_buffer_serialize_unicode().
|
2020-09-18 15:19:17 +02:00
|
|
|
|
*
|
2022-06-30 08:43:57 +02:00
|
|
|
|
* Return value: `true` if @buf is not fully consumed, `false` otherwise.
|
2020-09-18 15:19:17 +02:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.7.3
|
|
|
|
|
**/
|
|
|
|
|
hb_bool_t
|
|
|
|
|
hb_buffer_deserialize_unicode (hb_buffer_t *buffer,
|
|
|
|
|
const char *buf,
|
|
|
|
|
int buf_len, /* -1 means nul-terminated */
|
|
|
|
|
const char **end_ptr, /* May be NULL */
|
|
|
|
|
hb_buffer_serialize_format_t format)
|
|
|
|
|
{
|
|
|
|
|
const char *end;
|
|
|
|
|
if (!end_ptr)
|
|
|
|
|
end_ptr = &end;
|
|
|
|
|
*end_ptr = buf;
|
|
|
|
|
|
2020-10-15 10:02:04 +02:00
|
|
|
|
buffer->assert_unicode ();
|
2020-09-25 11:06:33 +02:00
|
|
|
|
|
|
|
|
|
if (unlikely (hb_object_is_immutable (buffer)))
|
|
|
|
|
{
|
2020-10-10 01:55:21 +02:00
|
|
|
|
if (end_ptr)
|
|
|
|
|
*end_ptr = buf;
|
2020-09-25 11:06:33 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 15:19:17 +02:00
|
|
|
|
if (buf_len == -1)
|
|
|
|
|
buf_len = strlen (buf);
|
|
|
|
|
|
|
|
|
|
if (!buf_len)
|
|
|
|
|
{
|
|
|
|
|
*end_ptr = buf;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_UNICODE);
|
|
|
|
|
|
|
|
|
|
hb_font_t* font = hb_font_get_empty ();
|
|
|
|
|
|
|
|
|
|
switch (format)
|
|
|
|
|
{
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_TEXT:
|
|
|
|
|
return _hb_buffer_deserialize_text (buffer,
|
|
|
|
|
buf, buf_len, end_ptr,
|
|
|
|
|
font);
|
2013-02-27 19:01:02 +01:00
|
|
|
|
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_JSON:
|
2020-09-18 15:19:17 +02:00
|
|
|
|
return _hb_buffer_deserialize_json (buffer,
|
|
|
|
|
buf, buf_len, end_ptr,
|
|
|
|
|
font);
|
2013-02-27 19:01:02 +01:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
case HB_BUFFER_SERIALIZE_FORMAT_INVALID:
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
2013-02-27 17:06:36 +01:00
|
|
|
|
}
|
2019-06-18 22:26:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|