-
Notifications
You must be signed in to change notification settings - Fork 254
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
Feature request: allow horizontal centering in TextStyle #1282
Comments
@allcontributors please add @Benoite142 for ideas |
I've put up a pull request to add @Benoite142! 🎉 |
Hi @Lucas-C , I am new to this project and would like to contribute for this feature request. Based on my understanding, here are the required changes fpdf/fonts.py (allow to accept Align values in l_margin
fonts/fpdf.py
Please suggest any other changes required or not (I am not counting the test cases here, just the changes required to introduce the feature) |
Yes, this looks like a good start! You will also find more information about There is one thing I would suggest:
|
Hi @Lucas-C , When writing test, something like this
When I passed the value of Align.C, it gave an error like so
I looked into it and realized that the start_section has this code here.
to check if any page break will be triggered and this takes in Should I also update the |
No, I think the best would be to pass Your test looks good. |
Hi @Lucas-C, Just one issue, I could not find a way to calculate or get the width of the text in section, as shown here
Is it stored in any variable, or is there any way to calculate it ? |
I further looked into the
How should I move forward with the same ? |
I am really surprised by this, as we have unit tests ensuring that it works properly:
Could you provide a an autonomous code snippet demonstrating a bug? For reference:
|
Hi @Lucas-C, Here is a script I have written to write down some text (and center it horizontally using
As per my understanding, this script should create a pdf with text "Multi cell center text" horizontally center of the page. However, the pdf created looks like this. If this is the expected behaviour, then probably I have some misunderstanding of the If this is not the expected behaviour, we would need to resolve this first to make the horizontal centering feature work. |
Hi @visheshdvivedi , Multi cell will create a cell and render your text inside it. You are specifying your cell width is 200, so your text is centered inside this cell. If you set a cell border it will be easier to see it:
Set the border and do try increasing If you want a cell to cover the whole page width, respecting the borders, you can use:
|
I agree with @andersonhc detailed answer 🙂👍 This should prove that
|
Hi @Lucas-C, I understood that
And based on my understanding, we need a way to center text without the need to specify any width (being able to center text for variable sizes of text without the need to specify custom width for each of them) So I just wanted to know how can we achieve that ? |
By passing
Earlier I wrote:
But on second thought, it may be better to pass |
Hi @Lucas-C, Thanks for your support, I am clear with the functionality now. Here is my final take.
So now for the final implementation (based on the requirements of the above issue), I will pass the value of Please share your views or confirmation so that I raise the pull request. |
Yes, this seems like a great plan 👍
Awesome, good job! You can go on an open a Pull Request 🙂 |
Proposed solution
.l_margin
in TextStyle.l_margin
is used in FPDF._use_title_style(), if it isAlign.C
, then horizontally align the textThe PR implementing this should include unit tests using
FPDF.start_section()
Discussed in #1280
Originally posted by Benoite142 October 10, 2024:
The text was updated successfully, but these errors were encountered: