Conversation
added 2 commits
September 12, 2024 11:21
…m number of lines for auto font size
thijmenjk
marked this pull request as draft
September 13, 2024 13:05
thijmenjk
marked this pull request as ready for review
September 13, 2024 13:18
thijmenjk
pushed a commit
to thijmenjk/QuestPDF
that referenced
this pull request
Sep 16, 2024
Mirror of QuestPDF#997 Related work items: #141420
|
I have similar issues and think this would help a lot. |
|
This is a very useful feature |
Open
Member
|
Thank you for sharing this improvement and the thorough investigation 😄 As the first step, I would like to investigate the ScaleToFit API to ensure it works properly in all use cases. This effort is tracked here: #1220. As the next step, I will look over your pull request and check if it fits on the future roadmap. Please feel free to share your perspective with me. It is a perfect time for brainstorming. |
|
This is a very useful feature, and I really need it. Has it been integrated yet? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hello QuestPDF team,
First of all, thank you for developing such an amazing library! We've been using QuestPDF in our projects, and it has been great for our document generation needs.
We have a use case where we need text to dynamically adjust its font size to fit within a given container. Additionally, we require control over the maximum number of lines the text can span and the exact font sizes that can be used. Because of this we implemented some changes that we would like to share with this PR.
Why Not
ScaleToFit?Initially, we tried using the
ScaleToFitfeature, but we encountered some limitations:ScaleToFitdoesn't allow us to specify the maximum number of lines the text can occupy, which is required for our use case.ScaleToFitsometimes doesn't work as expected, leading to text overflow or inadequate scaling (see example below).To overcome these challenges, we've implemented an
AutoFontSizefeature for theTextBlockelement.Feature Highlights:
Usage Examples:
We've added two extension methods to the
TextBlockDescriptorandITextDescriptorinterfaces:Using a Font Size Range:
Using Specific Font Sizes:
Examples:
In the attached example, we compare the
ScaleToFitandAutoFontSizefeatures under various container sizes and font families. You'll notice thatAutoFontSizeprovides better control over the text layout, especially in small containers and when limiting the number of lines.example.pdf
Code Details
Challenges
For our use case, baseline alignment is important. Especially when varying fonts, sometimes the baseline becomes misaligned. We tried using the
BaselineOffsetto adjust for such shifts but did not manage to get a working prototype, since the text seems to be unresponsive to any changes to this offset. Finding a solution for solving the baseline alignment is still future work. A workaround is setting theLineHeightto different values per font. Currently, we use0.8in the example.Conclusion
If there is a way to achieve our use case with the existing QuestPDF functionality, we would be excited to learn about it. We have explored the latest release but couldn't find a solution that meets all our requirements. We think this feature enhances the flexibility of text rendering in QuestPDF and could benefit other users with similar requirements.
Thank you for considering this pull request. We're happy to make any adjustments if needed. Also, if our use case can be done with existing QuestPDF functionality, that would be even better, but we did not find a way as of the latest release.