[pango/baseline-handling: 2/2] layout: Handle baselines
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/baseline-handling: 2/2] layout: Handle baselines
- Date: Tue, 15 Feb 2022 23:41:28 +0000 (UTC)
commit 7f5a6ad538a672e73c96e933b8b4fb41cecc2f9c
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Feb 14 18:41:29 2022 -0600
layout: Handle baselines
During post-processing for lines, take into
account the baselines for each run, and shift
them vertically to align them on the dominant
baseline.
pango/pango-layout.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 9167883c..00938f96 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -85,6 +85,7 @@
#include <locale.h>
#include <hb-ot.h>
+#include <hb-glib.h>
#include "pango-layout-private.h"
#include "pango-attributes-private.h"
@@ -6694,6 +6695,10 @@ apply_baseline_shift (PangoLayoutLine *line,
{
int y_offset = 0;
PangoItem *prev = NULL;
+ hb_ot_layout_baseline_tag_t baseline_tag = 0;
+ hb_position_t baseline;
+ hb_position_t run_baseline;
+ hb_position_t baseline_adjustment;
for (GSList *l = line->runs; l; l = l->next)
{
@@ -6701,16 +6706,55 @@ apply_baseline_shift (PangoLayoutLine *line,
PangoItem *item = run->item;
int start_x_offset, end_x_offset;
int start_y_offset, end_y_offset;
+ hb_font_t *hb_font;
+ hb_script_t script;
+ hb_language_t language;
+ hb_direction_t direction = HB_DIRECTION_LTR; /* FIXME */
+ hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT];
+ hb_tag_t lang_tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
+ unsigned int script_count = HB_OT_MAX_TAGS_PER_SCRIPT;
+ unsigned int lang_count = HB_OT_MAX_TAGS_PER_LANGUAGE;
+
+ hb_font = pango_font_get_hb_font (item->analysis.font);
+
+ script = hb_glib_script_to_script (item->analysis.script);
+ language = hb_language_from_string (pango_language_to_string (item->analysis.language), -1);
+ hb_ot_tags_from_script_and_language (script, language,
+ &script_count, script_tags,
+ &lang_count, lang_tags);
+
+ if (baseline_tag == 0)
+ {
+ baseline_tag = hb_ot_layout_get_baseline_tag_for_script (script);
+ hb_ot_layout_get_baseline_with_fallback (hb_font,
+ baseline_tag,
+ direction,
+ script_tags[script_count - 1],
+ lang_tags[lang_count - 1],
+ &run_baseline);
+ baseline = run_baseline;
+ }
+ else
+ {
+ hb_ot_layout_get_baseline_with_fallback (hb_font,
+ baseline_tag,
+ direction,
+ script_tags[script_count - 1],
+ lang_tags[lang_count - 1],
+ &run_baseline);
+ }
collect_baseline_shift (state, item, prev, &start_x_offset, &start_y_offset, &end_x_offset,
&end_y_offset);
- y_offset += start_y_offset;
+ baseline_adjustment = baseline - run_baseline;
+
+ y_offset += start_y_offset + baseline_adjustment;
run->y_offset = y_offset;
run->start_x_offset = start_x_offset;
run->end_x_offset = end_x_offset;
- y_offset += end_y_offset;
+ y_offset += end_y_offset - baseline_adjustment;
prev = item;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]