How to get advance distance of shaped text in Skia?

Skip to first unread message

Chenguang Wang

May 2, 2023, 4:36:41 PMMay 2
to skia-discuss

I am trying to figure out how to render text like "👨🏿hi" (U+1F468, U+1F3FF, 'h', 'i') correctly. Since this case involves mixing fonts, I need to figure out the advance distance of the emoji.

SkFont::measureText() does not work for multi-codepoint graphemes, because it simply sums up the advance distance of each code point; the skin color emoji modifier has its own advance distance, which should be ignored.

SkTextBlob::bounds() is the conservative bounding box, which is still larger than the actual advance width.

I *think* if using HarfBuzz directly this could be achieved by calling hb_buffer_get_glyph_positions() and summing the advance of each cluster. Wondering if it's possible to obtain the data from skia directly.


Ben Wagner

May 2, 2023, 4:57:24 PMMay 2
The drawing part of Skia mostly works in terms of glyphs, not code
points. For something like this you would need to first shape your
code points into positioned glyphs. Skia has SkShaper which in turn
uses HarfBuzz or CoreText to do the actual shaping.
> --
> You received this message because you are subscribed to the Google Groups "skia-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> To view this discussion on the web visit

Chenguang Wang

May 3, 2023, 8:43:11 AMMay 3
to skia-discuss
Thanks for the reply.

Yes, I have already ran grapheme segmentation and can distinguish the three graphemes here. I am able to shape the string with two SkShaper::shape() calls, one for '👨🏿' with my emoji font, and one for 'hi' with my text font. The missing part is figuring out the relative position of these two blobs.
Reply all
Reply to author
0 new messages