Skip to content

Commit

Permalink
Ensuring set_font() is called before multi_cell() (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Jun 19, 2023
1 parent b55bb9d commit 4357991
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fpdf/fpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2751,8 +2751,6 @@ def _render_styled_text_line(
Returns: a boolean indicating if page break was triggered
"""
if not self.font_family:
raise FPDFException("No font set, you need to call set_font() beforehand")
if isinstance(border, int) and border not in (0, 1):
warnings.warn(
'Integer values for "border" parameter other than 1 are currently ignored'
Expand Down Expand Up @@ -2884,6 +2882,7 @@ def _render_styled_text_line(
sl.append(f"/F{frag.font.i} {frag.font_size_pt:.2f} Tf")
lift = frag.lift
if lift != 0.0:
# Use text rise operator:
sl.append(f"{lift:.2f} Ts")
if (
frag.text_mode != TextMode.FILL
Expand Down Expand Up @@ -3348,6 +3347,8 @@ def multi_cell(
output=MethodReturnValue.LINES if split_only else output,
center=center,
)
if not self.font_family:
raise FPDFException("No font set, you need to call set_font() beforehand")
wrapmode = WrapMode.coerce(wrapmode)
if isinstance(w, str) or isinstance(h, str):
raise ValueError(
Expand Down
8 changes: 8 additions & 0 deletions test/text/test_multi_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
)


def test_multi_cell_without_any_font_set():
pdf = FPDF()
pdf.add_page()
with pytest.raises(FPDFException) as error:
pdf.multi_cell(txt="Hello world!", w=pdf.epw)
assert str(error.value) == "No font set, you need to call set_font() beforehand"


def test_ln_positioning_and_page_breaking_for_multicell(tmp_path):
doc = FPDF(format="letter", unit="pt")
doc.add_page()
Expand Down

0 comments on commit 4357991

Please sign in to comment.