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
Text justification #188
base: main
Are you sure you want to change the base?
Text justification #188
Conversation
I was thinking about similar approach. However, there is one significant problem. Rendering multiple text spans in a single line. In such case, we need to proportionally distribute available space across all spans available in the line. Therefore, the justification flag does not belong to the TextStyle class, rather to the Text element. It is just another use case along with aligning to the left/center/right. .Text(text =>
{
text.Justify();
// content
text.Span("This is example text. ").Bold();
text.Span(" Different text in the same line.").FontColor(Colors.Red.Medium);
// content
}); |
Yes, you are 100% correct with the approach i implemented, its only possible to render a single chunk of text with one format (not mixed font weights/ bold etc.). |
I gave it another try and actually got it to work. Code: .Text(text =>
{
text.AlignJustify();
// content
text.Span("This is example text. ").Bold();
text.Span(Placeholders.LoremIpsum());
text.Span(" Different text in the same line.").FontColor(Colors.Red.Medium);
text.Line("Last line should not be justified.");
}); However i did not manage to implement this without significant changes in the @MarcinZiabek |
As far as I remember: I am trying to reuse existing components as much as I can. Back then, I decided that the
I am not sure if this is the easiest approach. It was just my idea back then that has worked 😁 |
I think that mentioned corner cases are already handled in the existing implementation:
This should be applied in both the measuring and drawing process. The concept is simple but introduces even more corner cases, e.g. with float rounding when measuring text.
In my opinion, the current text implementation is quite difficult to introduce the concept of text justification, especially in a performant way. In the nearest future, I would like to introduce the text shaping capability. It changes text into a set of font glyphs (e.g. in the Arabic language, multiple characters can become one glyph). As a result of this operation, each glyph gets its position and size. This could be a great opportunity to divide glyphs by whitespaces and just add proper spaces wherever needed.
I am very impressed that you have been able to go so far! Something to be proud of! To be honest, text-rendering capabilities are something that still makes me question the usefulness of QuestPDF. Text justification, font fallback, and text shaping are only the beginning. We also have:
Each of the mentioned features is manageable. Combining them all makes the domain difficult 😁 |
That is correct, however:
Sorry if i am missing something, but i didnt see any handling of this in the current code.
That sounds great, justificiation should be a lot easier to implement then 👍.
That sounds complex 😅 I looked into a document of how text justification is handled in asian languages and must say it was quite overwhelming. |
I would like to once again thank you for your commitment and help! I will do my best to analyse your changes and contact whenever something is not clear. I am afraid however, that this needs to wait a while. A lot is going on in my personal life, very positive yet time-consuming events. I hope that you understand 😁 |
No worries, personal life should always be the priority 😊. |
Depending on priorities, I will either rework the text rendering algorithm first or investigate your implementation and include it in one of the future releases 😁 Text rendering is crucial for library stability and therefore I tend to be extra careful. |
I'd welcome an update on this. My requirements really need text justification. Thanks. |
Looking forward to this update! Awesome job guys! |
Hey guys, any updates on this? |
in #405, Marcin mentioned they are hoping to include this in the January update |
Is there any way of justify text? |
I also need to address the full-Justify Text. |
This PR implements text justification.
Should close #159 #25.
Showcase of the result rendered with the added test
JustifiedText
:.