[hb-view] Add --show-extents

This commit is contained in:
Behdad Esfahbod 2023-01-24 11:22:55 -07:00
parent 72e13fff65
commit 20fcf5c5b8
2 changed files with 26 additions and 1 deletions

View File

@ -168,7 +168,8 @@ view_cairo_t::render (const font_options_t *font_opts)
cairo_translate (cr, -vert * leading, +horiz * leading); cairo_translate (cr, -vert * leading, +horiz * leading);
if (annotate) { if (annotate)
{
cairo_save (cr); cairo_save (cr);
/* Draw actual glyph origins */ /* Draw actual glyph origins */
@ -183,6 +184,28 @@ view_cairo_t::render (const font_options_t *font_opts)
cairo_restore (cr); cairo_restore (cr);
} }
if (show_extents)
{
cairo_save (cr);
/* Draw actual glyph origins */
cairo_set_source_rgba (cr, .5, .5, .5, 1.);
cairo_set_line_width (cr, 2);
for (unsigned i = 0; i < l.num_glyphs; i++)
{
hb_glyph_extents_t hb_extents;
hb_font_get_glyph_extents (font, l.glyphs[i].index, &hb_extents);
double x1 = scalbn ((double) hb_extents.x_bearing, - (int) subpixel_bits);
double y1 = -scalbn ((double) hb_extents.y_bearing, - (int) subpixel_bits);
double width = scalbn ((double) hb_extents.width, - (int) subpixel_bits);
double height = -scalbn ((double) hb_extents.height, - (int) subpixel_bits);
cairo_rectangle (cr, l.glyphs[i].x + x1, l.glyphs[i].y + y1, width, height);
}
cairo_stroke (cr);
cairo_restore (cr);
}
if (l.num_clusters) if (l.num_clusters)
cairo_show_text_glyphs (cr, cairo_show_text_glyphs (cr,

View File

@ -57,6 +57,7 @@ struct view_options_t
struct margin_t { struct margin_t {
double t, r, b, l; double t, r, b, l;
} margin = {DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN}; } margin = {DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN};
hb_bool_t show_extents = false;
}; };
@ -116,6 +117,7 @@ view_options_t::add_options (option_parser_t *parser)
{"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &this->line_space, "Set space between lines (default: 0)", "units"}, {"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &this->line_space, "Set space between lines (default: 0)", "units"},
{"font-extents", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_extents, "Set font ascent/descent/line-gap (default: auto)","one to three numbers"}, {"font-extents", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_extents, "Set font ascent/descent/line-gap (default: auto)","one to three numbers"},
{"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: " G_STRINGIFY(DEFAULT_MARGIN) ")","one to four numbers"}, {"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: " G_STRINGIFY(DEFAULT_MARGIN) ")","one to four numbers"},
{"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Draw glyph extents", nullptr},
{nullptr} {nullptr}
}; };
parser->add_group (entries, parser->add_group (entries,