From 096121badbbc19d77a46015339de968817dc5c4f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 10 Feb 2022 19:27:33 -0600 Subject: [PATCH] [util] Implement --sub-font Internally creates a font at 2x and creates a sub-font from it... --- util/font-options.hh | 11 +++++++++++ util/helper-cairo-user.hh | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/util/font-options.hh b/util/font-options.hh index 36e0430d1..62ced8e7a 100644 --- a/util/font-options.hh +++ b/util/font-options.hh @@ -53,6 +53,7 @@ struct font_options_t : face_options_t void post_parse (GError **error); + hb_bool_t sub_font = false; hb_variation_t *variations = nullptr; unsigned int num_variations = 0; int x_ppem = 0; @@ -140,6 +141,14 @@ font_options_t::post_parse (GError **error) #ifdef HAVE_FREETYPE hb_ft_font_set_load_flags (font, ft_load_flags); #endif + + if (sub_font) + { + hb_font_t *old_font = font; + font = hb_font_create_sub_font (old_font); + hb_font_set_scale (old_font, scale_x * 2, scale_y * 2); + hb_font_destroy (old_font); + } } @@ -271,6 +280,8 @@ font_options_t::add_options (option_parser_t *parser) {"font-slant", 0, 0, G_OPTION_ARG_DOUBLE, &this->slant, "Set synthetic slant (default: 0)", "slant ratio; eg. 0.2"}, {"font-funcs", 0, 0, G_OPTION_ARG_STRING, &this->font_funcs, text, "impl"}, + {"sub-font", 0, G_OPTION_FLAG_HIDDEN, + G_OPTION_ARG_NONE, &this->sub_font, "Create a sub-font (default: false)", "boolean"}, {"ft-load-flags", 0, 0, G_OPTION_ARG_INT, &this->ft_load_flags, "Set FreeType load-flags (default: 2)", "integer"}, {nullptr} }; diff --git a/util/helper-cairo-user.hh b/util/helper-cairo-user.hh index 62137134c..8c1f9f222 100644 --- a/util/helper-cairo-user.hh +++ b/util/helper-cairo-user.hh @@ -113,17 +113,7 @@ render_glyph (cairo_scaled_font_t *scaled_font, hb_font_get_scale (font, &x_scale, &y_scale); cairo_scale (cr, +1./x_scale, -1./y_scale); -#if 0 - // Test sub-font scaling... - // TODO: Turn this into a util-wide feature... - hb_font_t *font2 = hb_font_create_sub_font (font); - signed x, y; - hb_font_get_scale (font, &x, &y); - hb_font_set_scale (font2, x/2, y/2); - hb_font_get_glyph_shape (font2, glyph, get_cairo_draw_funcs (), cr); -#else hb_font_get_glyph_shape (font, glyph, get_cairo_draw_funcs (), cr); -#endif cairo_fill (cr); return CAIRO_STATUS_SUCCESS;