diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-02-18 19:21:49 -0600 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-03-10 13:10:30 -0500 |
commit | 0913404c2d447b00cb8e0b8c03b89c5403b4193c (patch) | |
tree | b4fece717efc1b883319af6df4dc9df703241d3b | |
parent | 60c4f9d5f967faa3ffac8f72de3b943d69c3310d (diff) | |
download | pango-0913404c2d447b00cb8e0b8c03b89c5403b4193c.tar.gz |
wip: Apply italic correction
This is a work-in-progress attempt to implement Italic
correction between runs of different slant.
-rw-r--r-- | pango/pango-layout.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c index e45fb69f..665a7a92 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -6330,6 +6330,41 @@ adjust_line_letter_spacing (PangoLayoutLine *line, } static void +apply_italic_correction (PangoLayoutLine *line, + ParaBreakState *state) +{ +#if HB_VERSION_ATLEAST (3, 0, 0) + for (GSList *l = line->runs; l; l = l->next) + { + PangoLayoutRun *run = l->data; + PangoLayoutRun *next_run = l->next ? l->next->data : NULL; + hb_font_t *font, *next_font; + float slant, next_slant; + hb_font_extents_t extents; + hb_position_t height; + hb_position_t pos; + + if (!next_run) + break; + + font = pango_font_get_hb_font (run->item->analysis.font); + next_font = pango_font_get_hb_font (next_run->item->analysis.font); + + slant = hb_style_get_value (font, HB_STYLE_TAG_SLANT_RATIO); + next_slant = hb_style_get_value (next_font, HB_STYLE_TAG_SLANT_RATIO); + + if (next_slant > slant) + continue; + + hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &extents); + height = extents.ascender - extents.descender; + pos = extents.ascender - height / 2; + pad_glyphstring_right (run->glyphs, state, (slant - next_slant) * pos); + } +#endif +} + +static void justify_clusters (PangoLayoutLine *line, ParaBreakState *state) { @@ -6822,6 +6857,10 @@ pango_layout_line_postprocess (PangoLayoutLine *line, DEBUG ("after letter spacing", line, state); + apply_italic_correction (line, state); + + DEBUG ("after italic correction", line, state); + /* Distribute extra space between words if justifying and line was wrapped */ if (line->layout->justify && (wrapped || ellipsized || line->layout->justify_last_line)) { |