Skip to content

Commit

Permalink
Fix HTML rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Sep 4, 2024
1 parent be0ca31 commit ca7527b
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 122 deletions.
10 changes: 5 additions & 5 deletions docs/TextColumns.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ cols = pdf.text_columns()
with cols:
cols.write(text=LOREM_IPSUM[:400])
with cols.paragraph(
text_align="J",
top_margin=pdf.font_size,
bottom_margin=pdf.font_size
) as par:
par.write(text=LOREM_IPSUM[:400])
text_align="J",
top_margin=pdf.font_size,
bottom_margin=pdf.font_size
) as paragraph:
paragraph.write(text=LOREM_IPSUM[:400])
cols.write(text=LOREM_IPSUM[:400])
```
![Single Text Column](tcols-single.png)
Expand Down
223 changes: 106 additions & 117 deletions fpdf/html.py

Large diffs are not rendered by default.

Binary file modified test/html/html_features.pdf
Binary file not shown.
Binary file added test/html/html_font_tag.pdf
Binary file not shown.
Binary file modified test/html/html_table_with_bgcolor.pdf
Binary file not shown.
Binary file modified test/html/html_table_with_font_tags_used_to_set_text_color.pdf
Binary file not shown.
27 changes: 27 additions & 0 deletions test/html/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,3 +1161,30 @@ def footer(self):
pdf.add_page()
pdf.write_html("<p>Main content</p>")
assert_pdf_equal(pdf, HERE / "html_footer_with_call_to_write_html_ok.pdf", tmp_path)


def test_html_font_tag(tmp_path):
pdf = FPDF()
pdf.add_page()
pdf.write_html(
'<font size="36">Large text in Times 1<p>Large text in Times 2</p></font>',
)
pdf.write_html("<br><hr><br>")
pdf.write_html(
"""Text in Times 1
<font face="helvetica">
Text in Helvetica 1
<font size="36">
Large text in Helvetica 2
<font face="times">
Large text in Times 2
<p>Large text in Times 3</p>
</font>
Large text in Helvetica 3
<p>Large text in Helvetica 4</p>
</font>
Text in Helvetica 5
</font>
Text in Times 4""",
)
assert_pdf_equal(pdf, HERE / "html_font_tag.pdf", tmp_path)
Binary file added test/text_region/paragraph_emphasis.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions test/text_region/test_text_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,23 @@ def test_tcols_break_top_margin(tmp_path): # regression test for #1214
) as par:
par.write(text=LOREM_IPSUM)
assert_pdf_equal(pdf, HERE / "tcols_break_top_margin.pdf", tmp_path)


def test_paragraph_emphasis(tmp_path):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=32)
column = pdf.text_columns()
# Paragraph 1:
par = column.paragraph()
par.write(text="Un.")
column.end_paragraph()
# Paragraph 2:
pdf.set_font(style="B")
par = column.paragraph()
par.write(text="Deux.")
pdf.set_font(style="I")
par.write(text="Trois.")
column.end_paragraph()
column.render()
assert_pdf_equal(pdf, HERE / "paragraph_emphasis.pdf", tmp_path)

0 comments on commit ca7527b

Please sign in to comment.