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.
Features
This pull request adds 2 new functionalities to the markup object:
true
astextAlign
inMarkupObject:Draw
will cause the text to be justified (aligned both to the left and the right)<par>
that will tell markup to create new paragraphIf you think that passing
true
as an argument that is expected to be a number is bad, a new argument can be added, but I simply wanted to avoid bloating this function with new parameters and it won't cause any problem with compatibility.Details
Long texts aligned to the left are ugly and annoying to read, but long portions of text that are justified are much more pleasing to the eye. This pull request adds such functionality to the markup library.
Passing
true
astextAlign
will cause the markup object to render justified text while preserving all other features of markup. A<par>
tag can be used to signal markup object to create a new paragraph (\n
is considered a "soft" line break), breaking the line (with 1.5x line height gap) and disabling justification on the last line of the paragraph (in non-justified mode the new line with 1.5x gap is still added).\t
is ignored when it's not adding the full 50px spacing while rendering justified textandhalign
argument is ignored as text is always taking up the full space.Everything is made without altering the original markup functionalities so no need to worry about setting the whole world on fire by this commit. Despite rendering justified text is quite expensive compared to non-justified text because each word has to be rendered separately to maintain consistent gaps between words (it makes little-to-no impact while rendering non-justified text because it's getting rendered in the old way), I think it's still a cool functionality to have.
I tired my best to test everything and I think it's working just fine. If there is something that have to be changed or there is some kind issue with text justification/my code, please let me know.
Showcase
Top image - text is left-aligned, bottom image - text is justified
Top image - text is left-aligned, bottom image - text is justified