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

ln() does nothing at the beginning of a new file #937

Closed
gmischler opened this issue Sep 30, 2023 · 3 comments · Fixed by #940
Closed

ln() does nothing at the beginning of a new file #937

gmischler opened this issue Sep 30, 2023 · 3 comments · Fixed by #940
Labels

Comments

@gmischler
Copy link
Collaborator

Error details
ln() moves self.y either by its "h" argument or by self._lasth.
At the beginning of a file, _lasth is 0, so

Minimal code

from fpdf import FPDF
pdf = FPDF()
print(pdf.y)
pdf.ln()
print(pdf.y)

Expected result:

10
14.23333

Actual result:

10
10

Since we have a default font size of 12 points, I would expect self.y to get moved by that much in this situation.
I tried to fix that in #897, but then noticed that quite a few of our tests start with an ineffective ln() (usually within a loop where it later does have an effect). I didn't want to change all those otherwise unrelated tests (under shapes), so I'm bringing it up here.

The fix would be to simply use self.font_size if the other two values (the parameter "h" or self._lasth) are None and 0.

@gmischler gmischler added the bug label Sep 30, 2023
@Lucas-C
Copy link
Member

Lucas-C commented Oct 2, 2023

The fix would be to simply use self.font_size if the other two values (the parameter "h" or self._lasth) are None and 0.

I agree that this should be fixed.

However wouldn't it be better to simply initialize self._lasth to self.font_size?

@gmischler
Copy link
Collaborator Author

However wouldn't it be better to simply initialize self._lasth to self.font_size?

pdf = FPDF()
pdf.set_font("helvetica", size=36)
pdf.ln()

By how much would pdf.y move down in that case?
I think we really need to use the current value of pdf.font_size.

@Lucas-C
Copy link
Member

Lucas-C commented Oct 3, 2023

I think we really need to use the current value of pdf.font_size.

Alright!

And let's use your sample in a unit test 🙂

gmischler added a commit to gmischler/fpdf2 that referenced this issue Oct 3, 2023
gmischler added a commit that referenced this issue Oct 3, 2023
* ln() before text uses font_htight, fixes #937

* more test files

* eliminate pylint implicit-str-concat warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants