summaryrefslogtreecommitdiff
path: root/pango/shape.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-09-01 01:35:01 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-09-01 01:35:01 -0400
commit54b0d3fd39f841ba8ebc9efa153bd23c9efb2c4c (patch)
treefb8eb200b43f79c385b9e5eabc0f825373cc8914 /pango/shape.c
parent923284062075fd2fe1b061d256f91aec2912b1ab (diff)
downloadpango-54b0d3fd39f841ba8ebc9efa153bd23c9efb2c4c.tar.gz
shape: Mark color glyphs in glyphstrings
GTK needs this information to decide how to render the glyphs, so provide it.
Diffstat (limited to 'pango/shape.c')
-rw-r--r--pango/shape.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/pango/shape.c b/pango/shape.c
index 62c0f025..30131dd5 100644
--- a/pango/shape.c
+++ b/pango/shape.c
@@ -30,6 +30,8 @@
#include "pango-font-private.h"
+#include <hb-ot.h>
+
/* {{{ Harfbuzz shaping */
/* {{{{ Buffer handling */
@@ -335,6 +337,45 @@ find_text_transform (const PangoAnalysis *analysis)
return PANGO_TEXT_TRANSFORM_NONE;
}
+static gboolean
+glyph_has_color (hb_font_t *font,
+ hb_codepoint_t glyph)
+{
+ hb_face_t *face;
+ hb_blob_t *blob;
+
+ face = hb_font_get_face (font);
+
+ if (hb_ot_color_glyph_get_layers (face, glyph, 0, NULL, NULL) > 0)
+ return TRUE;
+
+ if (hb_ot_color_has_png (face))
+ {
+ blob = hb_ot_color_glyph_reference_png (font, glyph);
+ if (blob)
+ {
+ guint length = hb_blob_get_length (blob);
+ hb_blob_destroy (blob);
+ if (length > 0)
+ return TRUE;
+ }
+ }
+
+ if (hb_ot_color_has_svg (face))
+ {
+ blob = hb_ot_color_glyph_reference_svg (face, glyph);
+ if (blob)
+ {
+ guint length = hb_blob_get_length (blob);
+ hb_blob_destroy (blob);
+ if (length > 0)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/* }}}} */
static void
@@ -495,11 +536,13 @@ pango_hb_shape (const char *item_text,
pango_glyph_string_set_size (glyphs, num_glyphs);
infos = glyphs->glyphs;
last_cluster = -1;
+
for (i = 0; i < num_glyphs; i++)
{
infos[i].glyph = hb_glyph->codepoint;
glyphs->log_clusters[i] = hb_glyph->cluster - item_offset;
infos[i].attr.is_cluster_start = glyphs->log_clusters[i] != last_cluster;
+ infos[i].attr.is_color = glyph_has_color (hb_font, hb_glyph->codepoint);
hb_glyph++;
last_cluster = glyphs->log_clusters[i];
}