[pango/fix-cluster-accounting: 2/4] wip: glyph item: get more info
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/fix-cluster-accounting: 2/4] wip: glyph item: get more info
- Date: Thu, 11 Nov 2021 04:48:22 +0000 (UTC)
commit 9ae51bf8ee1e8c225221aea7e57b256a77208219
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Nov 10 23:45:00 2021 -0500
wip: glyph item: get more info
This needs to be made properly private.
pango/pango-glyph-item.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
pango/pango-glyph-item.h | 5 +++++
2 files changed, 53 insertions(+)
---
diff --git a/pango/pango-glyph-item.c b/pango/pango-glyph-item.c
index 7eb1737d..93645d34 100644
--- a/pango/pango-glyph-item.c
+++ b/pango/pango-glyph-item.c
@@ -860,3 +860,51 @@ pango_glyph_item_get_logical_widths (PangoGlyphItem *glyph_item,
}
}
}
+
+void
+pango_glyph_item_get_logical_widths_and_clusters (PangoGlyphItem *glyph_item,
+ const char *text,
+ int *logical_widths,
+ int *clusters)
+{
+ PangoGlyphItemIter iter;
+ gboolean has_cluster;
+ int dir;
+
+ dir = glyph_item->item->analysis.level % 2 == 0 ? +1 : -1;
+ for (has_cluster = pango_glyph_item_iter_init_start (&iter, glyph_item, text);
+ has_cluster;
+ has_cluster = pango_glyph_item_iter_next_cluster (&iter))
+ {
+ int glyph_index, char_index, num_chars, cluster_width = 0, char_width;
+
+ for (glyph_index = iter.start_glyph;
+ glyph_index != iter.end_glyph;
+ glyph_index += dir)
+ {
+ cluster_width += glyph_item->glyphs->glyphs[glyph_index].geometry.width;
+ }
+
+ num_chars = iter.end_char - iter.start_char;
+ if (num_chars == 1)
+ {
+ logical_widths[char_index] = cluster_width;
+ clusters[char_index] = 0;
+ }
+ else if (num_chars > 0) /* pedantic */
+ {
+ char_width = cluster_width / num_chars;
+
+ for (char_index = iter.start_char;
+ char_index < iter.end_char;
+ char_index++)
+ {
+ logical_widths[char_index] = char_width;
+ clusters[char_index] = char_index - iter.start_char + 1;
+ }
+
+ /* add any residues to the first char */
+ logical_widths[iter.start_char] += cluster_width - (char_width * num_chars);
+ }
+ }
+}
diff --git a/pango/pango-glyph-item.h b/pango/pango-glyph-item.h
index fd8951d2..fc18ca02 100644
--- a/pango/pango-glyph-item.h
+++ b/pango/pango-glyph-item.h
@@ -85,6 +85,11 @@ void pango_glyph_item_get_logical_widths (PangoGlyphItem *glyph_item,
const char *text,
int *logical_widths);
+void pango_glyph_item_get_logical_widths_and_clusters (PangoGlyphItem *glyph_item,
+ const char *text,
+ int *logical_widths,
+ int *clusters);
+
/**
* PangoGlyphItemIter:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]