-
Notifications
You must be signed in to change notification settings - Fork 264
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
{nb} breaks if text shaping is turned on with certain fonts #1090
Comments
Thank you for the report @catsclaw You are right, those two features are currently incompatible. The reason is that with test shaping, each character is rendered individually in the PDF (with a dedicated As a consequence, this is currently a limitation in Would you be interested to contribute regarding this @catsclaw? (docs improvement and/or implementation) |
The characters will be rendered as a sequence if they are only moving on the x axis by the character length, but if there is any offset (kerning, etc) we need to adjust the text matrix and make individual |
Adding to this issue:
Example: from fpdf import FPDF
text="Lorem ipsum dolor sit amet, {nb} {nb} {nb} {nb} {nb} {nb} consectetur adipiscing elit. {nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}{nb}Mauris sit amet lacus ut ex tincidunt vulputate non nec mauris. Lorem ipsum dolor sit amet, consectetur adipiscing elit."
pdf = FPDF()
pdf.add_page()
pdf.set_font("helvetica", "", 24)
pdf.multi_cell(w=pdf.epw, text=text, align="J", new_x="LEFT")
pdf.output('test_nb.pdf') The problem is the replacement is done directly in the page content after all the rendering is done. |
The underlying problem here is that an otherwise legitimate sequence of text characters is given a special meaning under certain circumstances. This was bound to result in conflicts somewhere down the line. The clean solution would be to use a reserved Unicode character for this purpose, which can't otherwise appear in renderable text. Or am I missing some basic obstacle here? |
Address issue: py-pdf/fpdf2#1090
Just reporting @andersonhc comment there from #71 (comment):
|
Would it be possible in the meantime to (loudly) call this out in the docs for both The underlying cause makes perfect sense in retrospect now that I understand what's happening, but in the moment, man that was a weird problem to chase down. 😅 |
Yes, I think that is a good idea 🙂 |
This fixup has been included in the new release published today: |
The special
{nb}
code fails with some fonts when text shaping is turned on.Minimal code
Please include some minimal Python code reproducing your issue:
Result
![image](https://private-user-images.githubusercontent.com/1660839/296344647-4f0e5cc1-5262-47dc-ac53-675bd152126b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNzc3NjUsIm5iZiI6MTczOTE3NzQ2NSwicGF0aCI6Ii8xNjYwODM5LzI5NjM0NDY0Ny00ZjBlNWNjMS01MjYyLTQ3ZGMtYWM1My02NzViZDE1MjEyNmIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTBUMDg1MTA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZWExMmNkYjVlNjg2ODViNWY2YTNiYzYzZGQyY2MzNTk5MjdkNTUwOGI4NTBiYTJiZjliNTUxYWZhMzI4YmFlZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.dZXup8XCmy5h6U1HC2a6qwd__8VcpIj9H0gcql7vn_4)
Environment
Please provide the following information:
fpdf2
version used: 2.7.7The text was updated successfully, but these errors were encountered: