summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2018-01-10 02:20:14 +0100
committerBehdad Esfahbod <behdad@behdad.org>2018-01-10 02:50:49 +0100
commit71fd6325b6cba2586709022dd33530c61141bf8f (patch)
tree720b3645bf4a6ef63aa9feaefd23c45b2a248d56
parent316a28f8f8a9c459936ce9f2786d4d64a8f4e2c0 (diff)
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
-rw-r--r--src/hb-buffer-serialize.cc38
-rw-r--r--src/hb-buffer.h5
-rw-r--r--util/hb-shape.cc2
-rw-r--r--util/options.cc2
-rw-r--r--util/options.hh2
5 files changed, 38 insertions, 11 deletions
diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc
index ea62e9ff..6a19c43c 100644
--- a/src/hb-buffer-serialize.cc
+++ b/src/hb-buffer-serialize.cc
@@ -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));
-
- *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 (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));
+
+ 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;
diff --git a/src/hb-buffer.h b/src/hb-buffer.h
index a8a4b84e..1341be52 100644
--- a/src/hb-buffer.h
+++ b/src/hb-buffer.h
@@ -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;
/**
diff --git a/util/hb-shape.cc b/util/hb-shape.cc
index dc9f446b..337cd431 100644
--- a/util/hb-shape.cc
+++ b/util/hb-shape.cc
@@ -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)
diff --git a/util/options.cc b/util/options.cc
index 5434b156..dc95b71f 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -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},
diff --git a/util/options.hh b/util/options.hh
index 4f9d85e5..103cd0d7 100644
--- a/util/options.hh
+++ b/util/options.hh
@@ -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;