[pango/italic-correction] wip: Apply italic correction
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/italic-correction] wip: Apply italic correction
- Date: Sat, 19 Feb 2022 01:22:27 +0000 (UTC)
commit 390c6cdb5eebe7f21625f9590a184f14ab57cd70
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 18 19:21:49 2022 -0600
wip: Apply italic correction
This is a work-in-progress attempt to implement Italic
correction between runs of different slant.
pango/pango-layout.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 6e4bb357..5933bd13 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -6330,6 +6330,44 @@ adjust_line_letter_spacing (PangoLayoutLine *line,
line->runs = g_slist_reverse (line->runs);
}
+static void
+apply_italic_correction (PangoLayoutLine *line,
+ ParaBreakState *state)
+{
+ GSList *l;
+
+ if (atoi (g_getenv ("ITALC") ? : "0") == 0)
+ return;
+
+ for (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);
+ }
+}
+
static void
justify_clusters (PangoLayoutLine *line,
ParaBreakState *state)
@@ -6823,6 +6861,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))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]