summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2015-08-24 13:49:55 +0100
committerBehdad Esfahbod <behdad@behdad.org>2015-08-24 13:49:55 +0100
commitfdd1770e006ca2d2973c049177ceda87a575e07f (patch)
treea47fdc0074ead709d79fd5ebcc2b7ff297f2e4b2
parent2cee5b68a07b99214ef9428fe5d03e7b378a558f (diff)
downloadharfbuzz-fdd1770e006ca2d2973c049177ceda87a575e07f.tar.gz
Add API/cmdline to show glyph extents when serializing buffer
New API: HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS hb-shape now accepts --show-extents. Patch from Simon Cozens.
-rw-r--r--src/hb-buffer-serialize.cc17
-rw-r--r--src/hb-buffer.h3
-rw-r--r--util/hb-shape.cc2
-rw-r--r--util/options.cc1
-rw-r--r--util/options.hh2
5 files changed, 24 insertions, 1 deletions
diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc
index 8a22224a..81f75aec 100644
--- a/src/hb-buffer-serialize.cc
+++ b/src/hb-buffer-serialize.cc
@@ -145,6 +145,16 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer,
pos[i].x_advance, pos[i].y_advance);
}
+ if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS)
+ {
+ hb_glyph_extents_t extents;
+ hb_font_get_glyph_extents(font, info[i].codepoint, &extents);
+ p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"xb\":%d,\"yb\":%d",
+ extents.x_bearing, extents.y_bearing));
+ p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"w\":%d,\"h\":%d",
+ extents.width, extents.height));
+ }
+
*p++ = '}';
unsigned int l = p - b;
@@ -210,6 +220,13 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer,
p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance));
}
+ if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS)
+ {
+ hb_glyph_extents_t extents;
+ hb_font_get_glyph_extents(font, info[i].codepoint, &extents);
+ p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "<%d,%d,%d,%d>", extents.x_bearing, extents.y_bearing, extents.width, extents.height));
+ }
+
unsigned int l = p - b;
if (buf_size > l)
{
diff --git a/src/hb-buffer.h b/src/hb-buffer.h
index 4b285bbb..1cfe13c0 100644
--- a/src/hb-buffer.h
+++ b/src/hb-buffer.h
@@ -323,7 +323,8 @@ typedef enum { /*< flags >*/
HB_BUFFER_SERIALIZE_FLAG_DEFAULT = 0x00000000u,
HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001u,
HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002u,
- HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u
+ HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u,
+ HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS = 0x00000008u
} hb_buffer_serialize_flags_t;
typedef enum {
diff --git a/util/hb-shape.cc b/util/hb-shape.cc
index f38f3879..3bd2184d 100644
--- a/util/hb-shape.cc
+++ b/util/hb-shape.cc
@@ -70,6 +70,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_extents)
+ flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS;
format_flags = (hb_buffer_serialize_flags_t) flags;
}
void new_line (void)
diff --git a/util/options.cc b/util/options.cc
index 0821a17b..0005f5c6 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -706,6 +706,7 @@ format_options_t::add_options (option_parser_t *parser)
G_OPTION_ARG_NONE, &this->show_positions, "Do not output glyph positions", NULL},
{"no-clusters", 0, G_OPTION_FLAG_REVERSE,
G_OPTION_ARG_NONE, &this->show_clusters, "Do not output cluster indices", NULL},
+ {"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Output glyph extents", NULL},
{NULL}
};
parser->add_group (entries,
diff --git a/util/options.hh b/util/options.hh
index 6eb6c04c..f1ec8cfd 100644
--- a/util/options.hh
+++ b/util/options.hh
@@ -410,6 +410,7 @@ struct format_options_t : option_group_t
show_text = false;
show_unicode = false;
show_line_num = false;
+ show_extents = false;
add_options (parser);
}
@@ -450,6 +451,7 @@ struct format_options_t : option_group_t
hb_bool_t show_text;
hb_bool_t show_unicode;
hb_bool_t show_line_num;
+ hb_bool_t show_extents;
};