Skip to content
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

Add text justification to markup #2145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

danx91
Copy link
Contributor

@danx91 danx91 commented Nov 4, 2024

Features

This pull request adds 2 new functionalities to the markup object:

  • Passing true as textAlign in MarkupObject:Draw will cause the text to be justified (aligned both to the left and the right)
  • Added new tag <par> that will tell markup to create new paragraph

If 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 as textAlign 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 text and halign 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

Lorem Ipsum
Top image - text is left-aligned, bottom image - text is justified

Text text
Top image - text is left-aligned, bottom image - text is justified

@danx91
Copy link
Contributor Author

danx91 commented Nov 4, 2024

Just noticed that I made a little mistake with halign argument. fixed in 9f85409

@robotboy655 robotboy655 added the Addition The pull request adds new functionality. label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Addition The pull request adds new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants