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

Right-aligned HTML paragraph breaks inline font styling #151

Closed
bgdncz opened this issue May 29, 2021 · 8 comments
Closed

Right-aligned HTML paragraph breaks inline font styling #151

bgdncz opened this issue May 29, 2021 · 8 comments

Comments

@bgdncz
Copy link

bgdncz commented May 29, 2021

Bold/italic/underline text in p tags works for default parameters, but setting align="right" breaks the layout:
Screen Shot 2021-05-29 at 18 07 41

@Lucas-C
Copy link
Member

Lucas-C commented May 29, 2021

Thanks for the report @boghison!

Could you please provide your source code for this test?

@Lucas-C Lucas-C added the bug label May 29, 2021
@bgdncz
Copy link
Author

bgdncz commented May 29, 2021

@Lucas-C I got it from the write_html documentation. I also tried it with the example here by changing the first paragraph to <p align="right"><b>Hello</b> world. <u>I am</u> <i>tired</i>.</p>:
Screen Shot 2021-05-29 at 18 32 59

PS Thank you for your work!

@bgdncz
Copy link
Author

bgdncz commented May 29, 2021

I think it’s because aligned paragraphs get written with multi_cell, so this might be related to #108

@Lucas-C
Copy link
Member

Lucas-C commented May 29, 2021

You're totally right, implementing #108 would help solving this!

I'll try to get back to this other issue in the next weeks.

@Lucas-C
Copy link
Member

Lucas-C commented Jul 15, 2021

Quick update: now pending on #171

@Lucas-C
Copy link
Member

Lucas-C commented Jan 29, 2022

Quick status update: solving this would require rendering the whole <p> block with FPDF.multi_cell().
But how to combine that with parsing of HTML tags like <b> or <u> inside the paragraph?
A solution could be to convert those to Markdown markers, but that's not an elegant solution...

#91 is also closely related

@gmischler
Copy link
Collaborator

The reason for this problem is that the html.py module is currently rather a dirty hack than a correct implementation.

Among other shortcomings, it just copies all the whitespace fromt the HTML data to the output, instead of condensing each run to a single space, which very often results in a very weird layout.
Using multi_cell() to align text is also an extremely quick-and-dirty approach, since as demonstrated above, it will necessarily start a new line each time the character formatting changes. Fixing this part will become a lot easier, once phase 2 of the proposed additions to write() are implemented (see #339).

The HTML parsing, and several other shortcomings, will have to be fixed seperately.

@gmischler
Copy link
Collaborator

I've just checked in #897, which should solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants