Create base text wrapper & SVG implementation #489
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This change adds a new family of classes designed to wrap text to a maximum width. The base
TextWrapper
class can theoretically be used to wrap text in any context, respecting Unicode grapheme cluster boundaries and (when possible) Unicode line break opportunities. It takes a "measurement provider" as an argument, and will use that provider to measure text widths. TheSVGTextWrapper
is some light glue to connect an SVG-based measurement provider to the baseTextWrapper
, though it will likely have a few additional features in the future. For example, I anticipate that it will have a method to return a single SVG node containing several lines of wrapped text.Reason for Changes
This is a step toward implementing say & think bubbles.
Test Coverage
None, currently. We could potentially test the wrapping algorithm by mocking a measurement provider, but we'd need a DOM (or a simulated DOM) to test the SVG version.
Known issues
Due to a limitation in the
grapheme-breaker
library I'm using, it's currently possible for a skin tone modifier to become separated from its associated emoji due to a line break. For more information, see: