Skip to content

CJK character wrapping in lovrFontGetLines and lovrFontGetVertices - #1000

Open
jamesthomasgriffin wants to merge 11 commits into
bjornbytes:devfrom
jamesthomasgriffin:cjk_wrapping
Open

CJK character wrapping in lovrFontGetLines and lovrFontGetVertices#1000
jamesthomasgriffin wants to merge 11 commits into
bjornbytes:devfrom
jamesthomasgriffin:cjk_wrapping

Conversation

@jamesthomasgriffin

Copy link
Copy Markdown
Contributor

Resolves #989

Summary

Adds CJK-aware line wrapping (break at character boundaries for CJK text, suppressed at certain punctuation) without requiring a full shaping library.

Changes

  • new logic adding word breaks around CJK characters
  • this logic needs to know the previous codepoint, in the getLines code the variable previous was being set to 0 to avoid kerning across linebreaks. This was interfering with the CJK logic so a new variable suppressKerning now does the job instead.
  • suppressKerning logic also ported to lovrFontGetVertices, because it was not easy to see that they were logically the same.
  • this also includes a fix for inconsistency between getLines and getVertices where it comes to the wrap parameter, one used wrap > 0 and the other wrap >= 0; I changed both to wrap > 0.

@bjornbytes

Copy link
Copy Markdown
Owner

I'm a little worried about implementing more advanced line breaking by hand because it creates a precedent for implementing more and more of UAX14. In a way, it's nice that the line wrapping algorithm is extremely bad right now, because LÖVR isn't making a promise about its text layout capabilities that it can't keep.

For example, now it seems reasonable to request that LÖVR handle line breaking around hyphens and emdashes properly, whereas before this change it felt somewhat out of scope. But if that gets added, then it would probably make sense to handle all the funny kinds of dashes, spaces, punctuation marks, currency, etc. At some point, it just makes sense to switch to the text shaping library, since it can do a better job.

However, maybe there is a way to explicitly draw the line and say that LÖVR handles some subset X of the full text shaping features, but nothing more than that. Maybe that line can be drawn somewhere beyond where it is today, but not in a place that creates extra expectations? I'm not too familiar with the landscape here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support text wrapping for CJK characters

2 participants