-
Notifications
You must be signed in to change notification settings - Fork 262
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
write_html() ignores font changes #1220
Comments
Thank you for the bug report @gmischler 👍 Given that I probably caused this regression, I will have a look at this myself during the week. |
While investigating this issue, I was surprised by the behaviour of the following code snippets: pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=32)
with pdf.text_columns() as cols:
with cols.paragraph() as par:
par.write(text="Un.")
pdf.font_style = "B"
with cols.paragraph() as par:
par.write(text="Deux.")
pdf.font_style = "I"
par.write(text="Trois.")
print(cols._paragraphs[0]._text_fragments[0].graphics_state["font_style"]) # ""
print(cols._paragraphs[1]._text_fragments[0].graphics_state["font_style"]) # "B"
print(cols._paragraphs[1]._text_fragments[1].graphics_state["font_style"]) # "I"
pdf.output("paragraph_emphasis.pdf") Why the PDF produced by this code does not contain any emphasis (bold/italics)? |
That's an interesting observation. pdf.font_style = ""
pdf.cell(text="Eins.")
pdf.font_style = "B"
pdf.cell(text="Zwei.")
pdf.font_style = "I"
pdf.cell(text="Drei.") Apparently hardly anyone uses All of that isn't directly related to our HTML font settings issue here, but should of course also be fixed. |
You are right. I opened this issue with a proposal to change that: #1223 I still think there is something fishy with how the GraphicsStates of TextFragments are handled... |
I opened PR #1246 to fix this problem. Would you like to review it @gmischler? |
Error details
When
write_html()
encounters eg. a<font face="helvetica">
, then it will process that but the changed font will not necessarily be reflected in the output.Minimal code
The "html_features" test shows the problem, where the "hello helvetica" line is now actually rendered in Times.
It seems that this has happened in #1207. In my comments there I had tried to point out the reasons why the graphics state context switches had previously been done the way they were, but apparently I didn't make their purpose sufficiently clear. I also didn't notice at the time that the font handling got broken.
The text was updated successfully, but these errors were encountered: