[pango/fix-small-caps-line-height: 48/48] Fix line height with emulated small caps
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/fix-small-caps-line-height: 48/48] Fix line height with emulated small caps
- Date: Sun, 19 Dec 2021 15:41:02 +0000 (UTC)
commit 704662e39856e308ef1683be607d62db0b738708
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 10 12:49:45 2021 -0500
Fix line height with emulated small caps
When we change font scale for emulating small caps,
keep the original font around in the analysis, and use
it for calculating the run height.
Fixes: #622
pango/itemize.c | 17 +++++++++++++----
pango/pango-item.c | 6 ++++++
pango/pango-item.h | 4 ++--
pango/pango-layout.c | 27 +++++++++++++++++++--------
4 files changed, 40 insertions(+), 14 deletions(-)
---
diff --git a/pango/itemize.c b/pango/itemize.c
index 6c07e4c2..6380c12f 100644
--- a/pango/itemize.c
+++ b/pango/itemize.c
@@ -1045,7 +1045,8 @@ collect_font_scale (PangoContext *context,
GList **stack,
PangoItem *item,
PangoItem *prev,
- double *scale)
+ double *scale,
+ gboolean *is_small_caps)
{
gboolean retval = FALSE;
GList *l;
@@ -1123,11 +1124,14 @@ collect_font_scale (PangoContext *context,
}
*scale = 1.0;
+ *is_small_caps = TRUE;
for (l = *stack; l; l = l->next)
{
ScaleItem *entry = l->data;
*scale *= entry->scale;
+ if (((PangoAttrInt *)entry->attr)->value != PANGO_FONT_SCALE_SMALL_CAPS)
+ *is_small_caps = FALSE;
retval = TRUE;
}
@@ -1152,11 +1156,15 @@ collect_font_scale (PangoContext *context,
static void
apply_scale_to_item (PangoContext *context,
PangoItem *item,
- double scale)
+ double scale,
+ gboolean is_small_caps)
{
PangoFontDescription *desc;
double size;
+ if (is_small_caps)
+ pango_analysis_set_size_font (&item->analysis, item->analysis.font);
+
desc = pango_font_describe (item->analysis.font);
size = scale * pango_font_description_get_size (desc);
@@ -1182,9 +1190,10 @@ apply_font_scale (PangoContext *context,
{
PangoItem *item = l->data;
double scale;
+ gboolean is_small_caps;
- if (collect_font_scale (context, &stack, item, prev, &scale))
- apply_scale_to_item (context, item, scale);
+ if (collect_font_scale (context, &stack, item, prev, &scale, &is_small_caps))
+ apply_scale_to_item (context, item, scale, is_small_caps);
prev = item;
}
diff --git a/pango/pango-item.c b/pango/pango-item.c
index d7291a08..c599241f 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -68,6 +68,9 @@ pango_item_copy (PangoItem *item)
((PangoItemPrivate *)result)->char_offset = ((PangoItemPrivate *)item)->char_offset;
result->analysis = item->analysis;
+ if (result->analysis.lang_engine)
+ g_object_ref (result->analysis.lang_engine);
+
if (result->analysis.font)
g_object_ref (result->analysis.font);
@@ -102,6 +105,9 @@ pango_item_free (PangoItem *item)
g_slist_free (item->analysis.extra_attrs);
}
+ if (item->analysis.lang_engine)
+ g_object_unref (item->analysis.lang_engine);
+
if (item->analysis.font)
g_object_unref (item->analysis.font);
diff --git a/pango/pango-item.h b/pango/pango-item.h
index 8122be19..f0eebc01 100644
--- a/pango/pango-item.h
+++ b/pango/pango-item.h
@@ -61,8 +61,8 @@ typedef struct _PangoItem PangoItem;
/**
* PangoAnalysis:
- * @shape_engine: unused
- * @lang_engine: unused
+ * @shape_engine: unused, reserved
+ * @lang_engine: unused, reserved
* @font: the font for this segment.
* @level: the bidirectional level for this segment.
* @gravity: the glyph orientation for this segment (A `PangoGravity`).
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 3f11d5b0..24a1a88b 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -5518,10 +5518,7 @@ pango_layout_get_empty_extents_and_height_at_index (PangoLayout *layout,
free_font_desc = TRUE;
}
- pango_attr_iterator_get_font (&iter,
- font_desc,
- NULL,
- NULL);
+ pango_attr_iterator_get_font (&iter, font_desc, NULL, NULL);
attr = pango_attr_iterator_get (&iter, PANGO_ATTR_LINE_HEIGHT);
if (attr)
@@ -5689,11 +5686,25 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
if (height)
{
- if (!metrics)
- metrics = pango_font_get_metrics (run->item->analysis.font,
- run->item->analysis.language);
+ if (pango_analysis_get_size_font (&run->item->analysis))
+ {
+ PangoFontMetrics *height_metrics;
+
+ height_metrics = pango_font_get_metrics (pango_analysis_get_size_font (&run->item->analysis),
+ run->item->analysis.language);
+
+ *height = pango_font_metrics_get_height (height_metrics);
- *height = pango_font_metrics_get_height (metrics);
+ pango_font_metrics_unref (height_metrics);
+ }
+ else
+ {
+ if (!metrics)
+ metrics = pango_font_get_metrics (run->item->analysis.font,
+ run->item->analysis.language);
+
+ *height = pango_font_metrics_get_height (metrics);
+ }
}
y_offset = run->y_offset;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]