From 20fcf5c5b8c2c068dc4956b3100d4d9b150c2a41 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 24 Jan 2023 11:22:55 -0700 Subject: [PATCH] [hb-view] Add --show-extents --- util/view-cairo.hh | 25 ++++++++++++++++++++++++- util/view-options.hh | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/util/view-cairo.hh b/util/view-cairo.hh index fbd5e5d9b..cdce2a1f7 100644 --- a/util/view-cairo.hh +++ b/util/view-cairo.hh @@ -168,7 +168,8 @@ view_cairo_t::render (const font_options_t *font_opts) cairo_translate (cr, -vert * leading, +horiz * leading); - if (annotate) { + if (annotate) + { cairo_save (cr); /* Draw actual glyph origins */ @@ -183,6 +184,28 @@ view_cairo_t::render (const font_options_t *font_opts) 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) cairo_show_text_glyphs (cr, diff --git a/util/view-options.hh b/util/view-options.hh index 731c133a2..2cb7cd234 100644 --- a/util/view-options.hh +++ b/util/view-options.hh @@ -57,6 +57,7 @@ struct view_options_t struct margin_t { double t, r, b, l; } 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"}, {"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"}, + {"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Draw glyph extents", nullptr}, {nullptr} }; parser->add_group (entries,