diff --git a/CHANGELOG.md b/CHANGELOG.md index f9e5a5a95..fda90ac23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default', ### Fixed - [`FPDF.table()`](https://pyfpdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.table): the `colspan` setting has been fixed - [documentation](https://pyfpdf.github.io/fpdf2/Tables.html#column-span) - [`FPDF.image()`](https://pyfpdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.image): allowing images path starting with `data` to be passed as input +- the initial text color is preserved when using `FPDF.write_html()` - _cf._ [issue #846](https://github.com/PyFPDF/fpdf2/issues/846) ### Deprecated - the `center` optional parameter of [`FPDF.cell()`](https://pyfpdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.cell) is **no more** deprecated, as it allows for horizontal positioning, which is different from text alignment control with `align="C"` diff --git a/fpdf/html.py b/fpdf/html.py index 0e6ea2765..db678cb32 100644 --- a/fpdf/html.py +++ b/fpdf/html.py @@ -238,7 +238,7 @@ def __init__( self.bullet = [] self.font_size = pdf.font_size_pt self.set_font(pdf.font_family or "times", size=self.font_size) - self.font_color = 0, 0, 0 # initialize font color, r,g,b format + self.font_color = tuple((255 * v for v in pdf.text_color.colors)) self.heading_level = None self.heading_sizes = dict(**DEFAULT_HEADING_SIZES) self.heading_above = 0.2 # extra space above heading, relative to font size diff --git a/test/html/html_preserve_initial_text_color.pdf b/test/html/html_preserve_initial_text_color.pdf new file mode 100644 index 000000000..49c907349 Binary files /dev/null and b/test/html/html_preserve_initial_text_color.pdf differ diff --git a/test/html/test_html.py b/test/html/test_html.py index 637cf87c1..040aa83dc 100644 --- a/test/html/test_html.py +++ b/test/html/test_html.py @@ -449,3 +449,12 @@ def test_html_custom_pre_code_font(tmp_path): # issue 770 pdf.add_page() pdf.write_html(" Cześć! ", pre_code_font="DejaVuSansMono") assert_pdf_equal(pdf, HERE / "html_custom_pre_code_font.pdf", tmp_path) + + +def test_html_preserve_initial_text_color(tmp_path): # issue 846 + pdf = FPDF() + pdf.add_page() + pdf.set_text_color(200, 50, 50) + pdf.set_font(family="Helvetica", size=13) + pdf.write_html("one two three") + assert_pdf_equal(pdf, HERE / "html_preserve_initial_text_color.pdf", tmp_path)