[pango/line-height-attribute: 2/2] layout: Handle line-height attributes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/line-height-attribute: 2/2] layout: Handle line-height attributes
- Date: Sat, 7 Aug 2021 18:34:22 +0000 (UTC)
commit d5d38f62fe4d1e1749a62e0ad7c88a063d9cd7e2
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 7 10:39:32 2021 -0400
layout: Handle line-height attributes
Modify the height and vertical origin of logical
extents according to the line height attributes.
We currently apply half the leading above and
half below the content (i.e., lines are vertically
centered in their modified height).
pango/pango-layout.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 326999c6..d23ce5a6 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -68,6 +68,7 @@
#include "pango-impl-utils.h"
#include "pango-glyph-item.h"
#include <string.h>
+#include <math.h>
#include "pango-layout-private.h"
#include "pango-attributes-private.h"
@@ -97,6 +98,8 @@ struct _ItemProperties
gboolean shape_set;
PangoRectangle *shape_ink_rect;
PangoRectangle *shape_logical_rect;
+ double line_height;
+ int absolute_line_height;
};
typedef struct _PangoLayoutLinePrivate PangoLayoutLinePrivate;
@@ -4189,6 +4192,8 @@ affects_itemization (PangoAttribute *attr,
case PANGO_ATTR_LETTER_SPACING:
case PANGO_ATTR_SHAPE:
case PANGO_ATTR_RISE:
+ case PANGO_ATTR_LINE_HEIGHT:
+ case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
return TRUE;
default:
return FALSE;
@@ -5144,9 +5149,20 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
if (!metrics)
metrics = pango_font_get_metrics (run->item->analysis.font,
run->item->analysis.language);
+
*height = pango_font_metrics_get_height (metrics);
}
+ if (properties.absolute_line_height != 0 || properties.line_height != 0.0)
+ {
+ int line_height, leading;
+
+ line_height = MAX (properties.absolute_line_height, ceilf (properties.line_height *
run_logical->height));
+ leading = line_height - run_logical->height;
+ run_logical->y -= leading / 2;
+ run_logical->height += leading;
+ }
+
if (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_CENTERED_BASELINE)
{
gboolean is_hinted = (run_logical->y & run_logical->height & (PANGO_SCALE - 1)) == 0;
@@ -6020,6 +6036,8 @@ pango_layout_get_item_properties (PangoItem *item,
properties->shape_set = FALSE;
properties->shape_ink_rect = NULL;
properties->shape_logical_rect = NULL;
+ properties->line_height = 0.0;
+ properties->absolute_line_height = 0;
while (tmp_list)
{
@@ -6083,6 +6101,14 @@ pango_layout_get_item_properties (PangoItem *item,
properties->shape_ink_rect = &((PangoAttrShape *)attr)->ink_rect;
break;
+ case PANGO_ATTR_LINE_HEIGHT:
+ properties->line_height = ((PangoAttrFloat *)attr)->value;
+ break;
+
+ case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
+ properties->absolute_line_height = ((PangoAttrInt *)attr)->value;
+ break;
+
default:
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]