-
Notifications
You must be signed in to change notification settings - Fork 920
Support Unicode line breaking #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5714a56
to
367b46f
Compare
This is a much needed addition! I'm curious - have you profiled My biggest concern is with the added build dependency required to enable the unicode tries import here: https://github.com/devongovett/linebreak/blob/master/src/linebreaker.coffee#L3 |
i.e. the brfs addition to the webpack config? I'm not too familiar with webpack, but with browserify you can specify transforms needed by a module in the package.json (see here). Webpack didn't seem to support that when I first tried building, so I had to add it to the webpack config here. Is there a better way to do that? As a last resort, I suppose I could publish a prebuilt version to npm but I'd prefer not to as you lose debugging info that way. |
Support Unicode 7.0.0 and make builds much smaller
Just updated the linebreak module to the latest version which adds Unicode 7.0 support, and makes builds much smaller (48KB -> 15KB minified). Also did some benchmarking of the
I think other improvements to the actual line layout algorithm are probably possible, but as for line breaking itself, I'm not sure it can get much faster while remaining correct according to the unicode standard. I did a lot of work on this for PDFKit to try to get it to be as fast as possible, including by implementing a custom data structure to represent the unicode properties as efficiently in terms of file size and lookup performance as possible. As for the build issue, see my previous comment and let me know what you'd prefer. |
I should also note that the benchmarks above were without the cache enabled. 😄 |
Look forward to be able to merge |
Sorry - totally dropped the ball on this one. I'd like to get this merged, but am having trouble running the PR branch. @devongovett are you missing a I'd like to be able to remove the dependency on webpack and/or browserify to build react-canvas but that doesn't have to happen in this PR. |
Just to be clear, it's not just the brfs loader that I'm talking about re: webpack/browserify dependency. It's also that ImageCache relies on webpack's |
Sorry for the delay. Just merged in master and added the |
Thanks @devongovett for updating. Landing in master now. |
Support Unicode line breaking
This adds support for correctly breaking lines of unicode text in languages where there are no spaces between the words, such as CJK languages. It uses the linebreak module, which is an implementation of the Unicode line breaking algorithm. The module is also used by my PDFKit project.
Also adds support for force breaks (e.g. newlines) in the text as well, as a side benefit. 😄
Tested by adding some Chinese text to the timeline demo: