memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.07k stars 767 forks source link

Fixes the issue that line gap may ruin the text layout. #563

Closed olliwang closed 4 years ago

olliwang commented 4 years ago

iOS uses the Hiragino Sans font as the default Japanese font. However, this font abuses the line gap property like many fonts.

Back to the Hiragino font. The font family always sets line gap to 500 no matter what while the font height (ascent - descent) is only 1000. Which causes the spaces between lines are super big.

Screen Shot 2020-02-28 at 5 31 10 PM

As mentioned here https://stackoverflow.com/questions/5414730/custom-installed-font-not-displayed-correctly-in-uilabel, Apple ignores the line gap property since iOS 7, and a workaround to fix this issue is to add the line gap to the ascent and we'll be fine to ignore the line gap property. Now the result looks much normal.

Screen Shot 2020-02-28 at 5 30 27 PM

This change doesn't affect the alignment, either.

linegap

memononen commented 4 years ago

How will this affect how western multiline text is rendered? i.e. the nanovg demo.

olliwang commented 4 years ago

This doesn't affect western multiline at all.

Screen Shot 2020-02-28 at 6 09 22 PM

PS. In my previous PR of fixing font size, the font size now matches what you saw on other native apps. The font used by the demo was affected by this because the font sizes were set to a value bigger than they actually were. I'm still fixing the font sizes and will submit another PR later.

olliwang commented 4 years ago

Just submitted a PR to fix demo's font size. #564

The result looks exactly the same with or without this PR's changes of fixing the line gap issue.

BEFORE:

Screen Shot 2020-02-28 at 6 22 05 PM

AFTER:

Screen Shot 2020-02-28 at 6 31 23 PM
memononen commented 4 years ago

Thanks for the fix!

olliwang commented 4 years ago

Thanks for the quick merging. Cheers! 🥂