HumbleUI / Skija

Java bindings for Skia
Apache License 2.0
501 stars 34 forks source link

Bottom of emoji and text misaligned on linux #18

Open luojinrong opened 2 years ago

luojinrong commented 2 years ago

When I draw text with emoji together on Paragraph,I find bottom alignment of emoji and text is fine on mac,but not on linux.

on mac:

image

on linux:

image

I would like to know what is causing this and how to make it behave the same on linux as it does on mac.

ps. I use the same font(AppleColorEmoji.ttc on mac) on both two system.

tonsky commented 2 years ago

Might it be that hieroglyph is using different font and different offset from baseline?

luojinrong commented 2 years ago

Might it be that hieroglyph is using different font and different offset from baseline?

But I use the same font file, how can this happen?

tonsky commented 2 years ago

Good question! Technically, fonts can provide different metrics (baseline, ascend, descend) for diffrent OSes.

From https://www.maxkohler.com/posts/2022-02-19-fixing-vertical-metrics/

For his­tor­i­cal rea­sons, ver­ti­cal met­rics are stored in three dif­fer­ent places (called hhea, OS/2 typo and OS/2 win), and dif­fer­ent ren­der­ing en­gines get their in­for­ma­tion from dif­fer­ent ones. Apple de­vices gen­er­ally use hhea, Windows uses ei­ther OS/2 typo or OS/2 win, and old ver­sions of MS Office use OS/2 win ex­clu­sively. If the num­bers in these ta­bles aren’t the same, you can end up in a sit­u­a­tion where type ren­ders dif­fer­ently in dif­fer­ent browsers, de­sign tools, or op­er­at­ing sys­tems.

I wonder if that’s the case here. You can try using something like this https://github.com/source-foundry/font-line to print the metrics (but be sure to figure out which exact font is used for rendering first)

luojinrong commented 2 years ago

Thank you for helping me find this article. Although I modified ascent and percent in OS/2 according to the method in the article, it still doesn't work.

However, I found the each emoji has a offsetY argument in the TTX file, and realized the alignment by modifying this. 😄