Add option to buffer serialization to not output glyph advances
When advances are not printed, glyph offsets reflect absolute glyph positions. New API: HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES hb-shape --no-advances
This commit is contained in:
parent
316a28f8f8
commit
71fd6325b6
|
@ -109,6 +109,7 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer,
|
|||
nullptr : hb_buffer_get_glyph_positions (buffer, nullptr);
|
||||
|
||||
*buf_consumed = 0;
|
||||
hb_position_t x = 0, y = 0;
|
||||
for (unsigned int i = start; i < end; i++)
|
||||
{
|
||||
char b[1024];
|
||||
|
@ -146,9 +147,10 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer,
|
|||
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS))
|
||||
{
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"dx\":%d,\"dy\":%d",
|
||||
pos[i].x_offset, pos[i].y_offset));
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d",
|
||||
pos[i].x_advance, pos[i].y_advance));
|
||||
x+pos[i].x_offset, y+pos[i].y_offset));
|
||||
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES))
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d",
|
||||
pos[i].x_advance, pos[i].y_advance));
|
||||
}
|
||||
|
||||
if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS)
|
||||
|
@ -179,6 +181,12 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer,
|
|||
*buf = '\0';
|
||||
} else
|
||||
return i - start;
|
||||
|
||||
if (flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES)
|
||||
{
|
||||
x += pos[i].x_advance;
|
||||
y += pos[i].y_advance;
|
||||
}
|
||||
}
|
||||
|
||||
return end - start;
|
||||
|
@ -199,6 +207,7 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer,
|
|||
nullptr : hb_buffer_get_glyph_positions (buffer, nullptr);
|
||||
|
||||
*buf_consumed = 0;
|
||||
hb_position_t x = 0, y = 0;
|
||||
for (unsigned int i = start; i < end; i++)
|
||||
{
|
||||
char b[1024];
|
||||
|
@ -223,13 +232,16 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer,
|
|||
|
||||
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS))
|
||||
{
|
||||
if (pos[i].x_offset || pos[i].y_offset)
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", pos[i].x_offset, pos[i].y_offset));
|
||||
if (x+pos[i].x_offset || y+pos[i].y_offset)
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", x+pos[i].x_offset, y+pos[i].y_offset));
|
||||
|
||||
*p++ = '+';
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advance));
|
||||
if (pos[i].y_advance)
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance));
|
||||
if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES))
|
||||
{
|
||||
*p++ = '+';
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advance));
|
||||
if (pos[i].y_advance)
|
||||
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance));
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS)
|
||||
|
@ -255,6 +267,12 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer,
|
|||
*buf = '\0';
|
||||
} else
|
||||
return i - start;
|
||||
|
||||
if (flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES)
|
||||
{
|
||||
x += pos[i].x_advance;
|
||||
y += pos[i].y_advance;
|
||||
}
|
||||
}
|
||||
|
||||
return end - start;
|
||||
|
|
|
@ -412,6 +412,8 @@ hb_buffer_normalize_glyphs (hb_buffer_t *buffer);
|
|||
* @HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS: do not serialize glyph position information.
|
||||
* @HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES: do no serialize glyph name.
|
||||
* @HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS: serialize glyph extents.
|
||||
* @HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS: serialize glyph flags. Since: 1.5.0
|
||||
* @HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES: do not serialize glyph advances. Since: 1.8.0
|
||||
*
|
||||
* Flags that control what glyph information are serialized in hb_buffer_serialize_glyphs().
|
||||
*
|
||||
|
@ -423,7 +425,8 @@ typedef enum { /*< flags >*/
|
|||
HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002u,
|
||||
HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u,
|
||||
HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS = 0x00000008u,
|
||||
HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS = 0x00000010u
|
||||
HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS = 0x00000010u,
|
||||
HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES = 0x00000020u
|
||||
} hb_buffer_serialize_flags_t;
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,6 +72,8 @@ struct output_buffer_t
|
|||
flags |= HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS;
|
||||
if (!format.show_positions)
|
||||
flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS;
|
||||
if (!format.show_advances)
|
||||
flags |= HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES;
|
||||
if (format.show_extents)
|
||||
flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS;
|
||||
if (format.show_flags)
|
||||
|
|
|
@ -844,6 +844,8 @@ format_options_t::add_options (option_parser_t *parser)
|
|||
G_OPTION_ARG_NONE, &this->show_glyph_names, "Output glyph indices instead of names", nullptr},
|
||||
{"no-positions", 0, G_OPTION_FLAG_REVERSE,
|
||||
G_OPTION_ARG_NONE, &this->show_positions, "Do not output glyph positions", nullptr},
|
||||
{"no-advances", 0, G_OPTION_FLAG_REVERSE,
|
||||
G_OPTION_ARG_NONE, &this->show_advances, "Do not output glyph advances", nullptr},
|
||||
{"no-clusters", 0, G_OPTION_FLAG_REVERSE,
|
||||
G_OPTION_ARG_NONE, &this->show_clusters, "Do not output cluster indices", nullptr},
|
||||
{"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Output glyph extents", nullptr},
|
||||
|
|
|
@ -584,6 +584,7 @@ struct format_options_t : option_group_t
|
|||
format_options_t (option_parser_t *parser) {
|
||||
show_glyph_names = true;
|
||||
show_positions = true;
|
||||
show_advances = true;
|
||||
show_clusters = true;
|
||||
show_text = false;
|
||||
show_unicode = false;
|
||||
|
@ -628,6 +629,7 @@ struct format_options_t : option_group_t
|
|||
|
||||
hb_bool_t show_glyph_names;
|
||||
hb_bool_t show_positions;
|
||||
hb_bool_t show_advances;
|
||||
hb_bool_t show_clusters;
|
||||
hb_bool_t show_text;
|
||||
hb_bool_t show_unicode;
|
||||
|
|
Loading…
Reference in New Issue