From e0123f1dc383ad1245c8cc7366a1139c06f261b4 Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Fri, 25 Aug 2023 08:58:05 +0200 Subject: [PATCH] Deprecating txt= arg in favor of text= --- CHANGELOG.md | 3 + docs/Annotations.md | 14 +- docs/CombineWithBorb.md | 2 +- docs/DatabaseStorage.md | 2 +- docs/DocumentOutlineAndTableOfContents.md | 4 +- docs/EmojisSymbolsDingbats.md | 10 +- docs/Encryption.md | 4 +- docs/FAQ.md | 6 +- docs/History.md | 2 +- docs/Images.md | 2 +- docs/Links.md | 12 +- docs/PageBreaks.md | 2 +- docs/PageFormatAndOrientation.md | 12 +- docs/Presentations.md | 30 ++--- docs/TextShaping.md | 2 +- docs/TextStyling.md | 42 +++--- docs/Transformations.md | 16 +-- docs/Unicode.md | 2 +- docs/UsageInWebAPI.md | 12 +- docs/index.md | 2 +- docs/symbol.py | 6 +- docs/zapfdingbats.py | 10 +- fpdf/deprecation.py | 21 +++ fpdf/fpdf.py | 131 ++++++++++--------- fpdf/html.py | 6 +- fpdf/table.py | 2 +- fpdf/template.py | 10 +- test/barcodes/test_barcodes.py | 4 +- test/drawing/test_drawing.py | 2 +- test/encryption/test_encryption.py | 24 ++-- test/errors/test_FPDF_errors.py | 6 +- test/fonts/test_add_font.py | 10 +- test/fonts/test_font_fallback.py | 26 ++-- test/fonts/test_font_remap.py | 12 +- test/fonts/test_set_font.py | 4 +- test/image/image_types/test_insert_images.py | 4 +- test/layout/test_units.py | 2 +- test/metadata/test_display_mode.py | 18 +-- test/metadata/test_info.py | 2 +- test/metadata/test_viewer_preferences.py | 8 +- test/outline/test_outline.py | 6 +- test/outline/test_outline_html.py | 4 +- test/shapes/test_dash_pattern.py | 2 +- test/signing/test_sign.py | 4 +- test/table/test_table_padding.py | 2 +- test/table/test_table_with_image.py | 2 +- test/template/test_flextemplate.py | 4 +- test/test_add_page.py | 10 +- test/test_annotations.py | 24 ++-- test/test_graphics_context.py | 20 +-- test/test_links.py | 36 ++--- test/test_mirror.py | 46 +++---- test/test_positioning.py | 4 +- test/test_recorder.py | 14 +- test/test_skew.py | 28 ++-- test/test_transitions.py | 24 ++-- test/text/test_cell.py | 77 ++++++----- test/text/test_multi_cell.py | 123 +++++++++-------- test/text/test_multi_cell_markdown.py | 16 +-- test/text/test_render_styled.py | 20 +-- test/text/test_text.py | 13 +- test/text/test_text_mode.py | 18 +-- test/text/test_write.py | 71 ++++++---- test/text_shaping/test_text_shaping.py | 44 +++---- 64 files changed, 592 insertions(+), 509 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eb845e30..a28067148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default', ## [2.7.6] - Not released yet This release is the first performed from the [@py-pdf GitHub org](https://github.com/py-pdf), where `fpdf2` migrated. +This release also marks the arrival of two new maintainers: Georg Mischler ([@gmischler](https://github.com/gmischler)) and Anderson Herzogenrath da Costa ([@andersonhc](https://github.com/andersonhc)). ### Added * The new experimental method `text_columns()` allows to render text within a single or multiple columns, including height balancing: [documentation](https://py-pdf.github.io/fpdf2/TextColumns.html) * [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html) now supports heading colors defined as attributes (_e.g._ `

...`) @@ -42,6 +43,8 @@ This change was made for consistency between row-height governed by text or imag * [`FPDF.table()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.table): images no longer overlap with cell borders - _cf._ issue [#892](https://github.com/py-pdf/fpdf2/issues/892) * Encryption of strings containing non-latin characters - _cf._ issue [#933](https://github.com/py-pdf/fpdf2/issues/933) * Handling of fragments with zero-length - _cf._ issue [#902](https://github.com/py-pdf/fpdf2/issues/902) +### Deprecated +* to improve naming consistency, the `txt` parameters of `FPDF.cell()`, `FPDF.multi_cell()`, `FPDF.text()` & `FPDF.write()` have been renamed to `text` ## [2.7.5] - 2023-08-04 ### Added diff --git a/docs/Annotations.md b/docs/Annotations.md index 9568b1d98..c68a7b4c3 100644 --- a/docs/Annotations.md +++ b/docs/Annotations.md @@ -15,7 +15,7 @@ from fpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", size=24) -pdf.text(x=60, y=140, txt="Some text.") +pdf.text(x=60, y=140, text="Some text.") pdf.text_annotation( x=100, y=130, @@ -38,8 +38,8 @@ pdf.set_font("Helvetica", size=24) with pdf.highlight("Highlight comment"): pdf.text(50, 50, "Line 1") pdf.set_y(50) - pdf.multi_cell(w=30, txt="Line 2") -pdf.cell(w=60, txt="Not highlighted", border=1) + pdf.multi_cell(w=30, text="Line 2") +pdf.cell(w=60, text="Not highlighted", border=1) pdf.output("highlighted.pdf") ``` @@ -87,11 +87,11 @@ from fpdf.actions import NamedAction pdf = FPDF() pdf.set_font("Helvetica", size=24) pdf.add_page() -pdf.text(x=80, y=140, txt="First page") +pdf.text(x=80, y=140, text="First page") pdf.add_page() pdf.underline = True for x, y, named_action in ((40, 80, "NextPage"), (120, 80, "PrevPage"), (40, 200, "FirstPage"), (120, 200, "LastPage")): - pdf.text(x=x, y=y, txt=named_action) + pdf.text(x=x, y=y, text=named_action) pdf.add_action( NamedAction(named_action), x=x, @@ -101,7 +101,7 @@ for x, y, named_action in ((40, 80, "NextPage"), (120, 80, "PrevPage"), (40, 200 ) pdf.underline = False pdf.add_page() -pdf.text(x=80, y=140, txt="Last page") +pdf.text(x=80, y=140, text="Last page") pdf.output("named_actions.pdf") ``` @@ -118,7 +118,7 @@ pdf = FPDF() pdf.set_font("Helvetica", size=24) pdf.add_page() x, y, text = 80, 140, "Launch action" -pdf.text(x=x, y=y, txt=text) +pdf.text(x=x, y=y, text=text) pdf.add_action( LaunchAction("another_file_in_same_directory.pdf"), x=x, diff --git a/docs/CombineWithBorb.md b/docs/CombineWithBorb.md index ebb423e4b..bba1c2f87 100644 --- a/docs/CombineWithBorb.md +++ b/docs/CombineWithBorb.md @@ -20,7 +20,7 @@ pdf = FPDF() pdf.set_title('Initiating a borb doc from a FPDF instance') pdf.set_font('helvetica', size=12) pdf.add_page() -pdf.cell(txt="Hello world!") +pdf.cell(text="Hello world!") doc = PDF.loads(BytesIO(pdf.output())) print(doc.get_document_info().get_title()) diff --git a/docs/DatabaseStorage.md b/docs/DatabaseStorage.md index 15bb0a0dc..aec57d696 100644 --- a/docs/DatabaseStorage.md +++ b/docs/DatabaseStorage.md @@ -24,7 +24,7 @@ Base.metadata.create_all(engine) pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", size=24) -pdf.cell(txt="My name is Bobby") +pdf.cell(text="My name is Bobby") new_user = User(name="Bobby", pdf=pdf.output()) Session = sessionmaker(bind=engine) diff --git a/docs/DocumentOutlineAndTableOfContents.md b/docs/DocumentOutlineAndTableOfContents.md index 22792afda..90f3a2af5 100644 --- a/docs/DocumentOutlineAndTableOfContents.md +++ b/docs/DocumentOutlineAndTableOfContents.md @@ -39,9 +39,9 @@ from fpdf import FPDF, HTML2FPDF class CustomHTML2FPDF(HTML2FPDF): def render_toc(self, pdf, outline): - pdf.cell(txt='Table of contents:', new_x="LMARGIN", new_y="NEXT") + pdf.cell(text='Table of contents:', new_x="LMARGIN", new_y="NEXT") for section in outline: - pdf.cell(txt=f'* {section.name} (page {section.page_number})', new_x="LMARGIN", new_y="NEXT") + pdf.cell(text=f'* {section.name} (page {section.page_number})', new_x="LMARGIN", new_y="NEXT") class PDF(FPDF): HTML2FPDF_CLASS = CustomHTML2FPDF diff --git a/docs/EmojisSymbolsDingbats.md b/docs/EmojisSymbolsDingbats.md index 2047b5426..3200e0ce0 100644 --- a/docs/EmojisSymbolsDingbats.md +++ b/docs/EmojisSymbolsDingbats.md @@ -14,7 +14,7 @@ pdf = fpdf.FPDF() pdf.add_font(fname="DejaVuSans.ttf") pdf.set_font("DejaVuSans", size=64) pdf.add_page() -pdf.multi_cell(0, txt="".join([chr(0x1F600 + x) for x in range(68)])) +pdf.multi_cell(0, text="".join([chr(0x1F600 + x) for x in range(68)])) pdf.set_font_size(32) pdf.text(10, 270, "".join([chr(0x1F0A0 + x) for x in range(15)])) pdf.output("fonts_emoji_glyph.pdf") @@ -35,11 +35,11 @@ import fpdf pdf = fpdf.FPDF() pdf.add_page() pdf.set_font("symbol", size=36) -pdf.cell(h=16, txt="\u0022 \u0068 \u0024 \u0065 \u00ce \u00c2, \u0068/\u0065 \u0040 \u00a5", +pdf.cell(h=16, text="\u0022 \u0068 \u0024 \u0065 \u00ce \u00c2, \u0068/\u0065 \u0040 \u00a5", new_x="LMARGIN", new_y="NEXT") -pdf.cell(h=16, txt="\u0044 \u0046 \u0053 \u0057 \u0059 \u0061 \u0062 \u0063", +pdf.cell(h=16, text="\u0044 \u0046 \u0053 \u0057 \u0059 \u0061 \u0062 \u0063", new_x="LMARGIN", new_y="NEXT") -pdf.cell(h=16, txt="\u00a0 \u00a7 \u00a8 \u00a9 \u00aa \u00ab \u00ac \u00ad \u00ae \u00af \u00db \u00dc \u00de", +pdf.cell(h=16, text="\u00a0 \u00a7 \u00a8 \u00a9 \u00aa \u00ab \u00ac \u00ad \u00ae \u00af \u00db \u00dc \u00de", new_x="LMARGIN", new_y="NEXT") pdf.output("symbol.pdf") ``` @@ -61,7 +61,7 @@ import fpdf pdf = fpdf.FPDF() pdf.add_page() pdf.set_font("zapfdingbats", size=36) -pdf.cell(txt="+ 3 8 A r \u00a6 } \u00a8 \u00a9 \u00aa \u00ab ~") +pdf.cell(text="+ 3 8 A r \u00a6 } \u00a8 \u00a9 \u00aa \u00ab ~") pdf.output("zapfdingbat.pdf") ``` diff --git a/docs/Encryption.md b/docs/Encryption.md index 7a159a485..acda434ce 100644 --- a/docs/Encryption.md +++ b/docs/Encryption.md @@ -58,7 +58,7 @@ from fpdf.enums import AccessPermission pdf = FPDF() pdf.add_page() pdf.set_font("helvetica", size=12) -pdf.cell(txt="hello world") +pdf.cell(text="hello world") pdf.set_encryption( owner_password="98765421", @@ -102,7 +102,7 @@ from fpdf.enums import AccessPermission, EncryptionMethod pdf = FPDF() pdf.add_page() pdf.set_font("helvetica", size=12) -pdf.cell(txt="hello world") +pdf.cell(text="hello world") pdf.set_encryption( owner_password="123", diff --git a/docs/FAQ.md b/docs/FAQ.md index 9f8d1e105..74a7a8d1f 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -79,13 +79,13 @@ def get_me_a_pdf(): pdf = FPDF() pdf.add_page() pdf.set_font('Times', 'B', 15) - pdf.cell(w=210, h=9, txt=title, border=0, + pdf.cell(w=210, h=9, text=title, border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) pdf.set_font('Times', 'B', 15) - pdf.cell(w=0, h=6, txt=heading, border=0, + pdf.cell(w=0, h=6, text=heading, border=0, new_x="LMARGIN", new_y="NEXT", align='L', fill=False) pdf.set_font('Times', '', 12) - pdf.multi_cell(w=0, h=5, txt=text) + pdf.multi_cell(w=0, h=5, text=text) response.headers['Content-Type'] = 'application/pdf' return pdf.output() ``` diff --git a/docs/History.md b/docs/History.md index 26303681b..dc0ac29c2 100644 --- a/docs/History.md +++ b/docs/History.md @@ -25,7 +25,7 @@ On 2020, the first PRs were merged from external contributors. At the end of the year, Lucas Cimon ([@Lucas-C](https://github.com/Lucas-C/)) started contributing several improvements, in order to use `fpdf2` for his [Undying Dusk](https://lucas-c.itch.io/undying-dusk) project. [Version **2.1.0** was released](https://github.com/py-pdf/fpdf2/blob/master/CHANGELOG.md#210---2020-12-07) and on 2021/01/10 `fpdf2` was moved to a dedicated `PyFPDF` GitHub organization, and `@Lucas-C` became another maintainer of the project. -On 2023/08/04, `fpdf2` moved to the `py-pdf` organization: . The context for this move can be found there: . On this date, the `PyFPDF` GitHub organization has been **archived**. +On 2023/08/04, `fpdf2` moved to the `py-pdf` organization: . The context for this move can be found there: [discussion #752](https://github.com/py-pdf/fpdf2/discussions/752). On this date, the `PyFPDF` GitHub organization has been **archived**. The same month, Georg Mischler ([@gmischler](https://github.com/gmischler)) and Anderson Herzogenrath da Costa ([@andersonhc](https://github.com/andersonhc)) joined the project as new maintainers. ## Compatibility between PyFPDF & fpdf2 ## diff --git a/docs/Images.md b/docs/Images.md index b6d372d0f..bbe44caa1 100644 --- a/docs/Images.md +++ b/docs/Images.md @@ -219,7 +219,7 @@ from fpdf import FPDF pdf = FPDF() pdf.allow_images_transparency = False pdf.set_font("Helvetica", size=15) -pdf.cell(w=pdf.epw, h=30, txt="Text behind. " * 6) +pdf.cell(w=pdf.epw, h=30, text="Text behind. " * 6) pdf.image("docs/fpdf2-logo.png", x=0) pdf.output("pdf-including-image-without-transparency.pdf") ``` diff --git a/docs/Links.md b/docs/Links.md index 5f56a9ee2..0ff10509d 100644 --- a/docs/Links.md +++ b/docs/Links.md @@ -14,7 +14,7 @@ from fpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font("helvetica", size=24) -pdf.cell(txt="Cell link", border=1, center=True, +pdf.cell(text="Cell link", border=1, center=True, link="https://github.com/py-pdf/fpdf2") pdf.output("hyperlink.pdf") ``` @@ -30,7 +30,7 @@ pdf.set_font("helvetica", size=24) pdf.add_page() pdf.multi_cell( pdf.epw, - txt="**Website:** [fpdf2](https://py-pdf.github.io/fpdf2/) __Go visit it!__", + text="**Website:** [fpdf2](https://py-pdf.github.io/fpdf2/) __Go visit it!__", markdown=True, ) pdf.output("hyperlink.pdf") @@ -55,7 +55,7 @@ pdf.add_page() pdf.set_font("helvetica", size=36) line_height = 10 text = "Text link" -pdf.text(x=0, y=line_height, txt=text) +pdf.text(x=0, y=line_height, text=text) width = pdf.get_string_width(text) pdf.link(x=0, y=0, w=width, h=line_height, link="https://github.com/py-pdf/fpdf2") pdf.output("hyperlink.pdf") @@ -91,10 +91,10 @@ from fpdf import FPDF pdf = FPDF() pdf.set_font("helvetica", size=24) pdf.add_page() -pdf.cell(txt="Welcome on first page!", align="C", center=True) +pdf.cell(text="Welcome on first page!", align="C", center=True) pdf.add_page() link = pdf.add_link(page=1) -pdf.cell(txt="Internal link to first page", border=1, link=link) +pdf.cell(text="Internal link to first page", border=1, link=link) pdf.output("internal_link.pdf") ``` @@ -117,7 +117,7 @@ from fpdf import FPDF pdf = FPDF() pdf.set_font("helvetica", size=24) pdf.add_page() -pdf.cell(txt="Link to other_doc.pdf", border=1, link="other_doc.pdf") +pdf.cell(text="Link to other_doc.pdf", border=1, link="other_doc.pdf") pdf.output("link_to_other_doc.pdf") ``` diff --git a/docs/PageBreaks.md b/docs/PageBreaks.md index 182897f26..c46e0cc9e 100644 --- a/docs/PageBreaks.md +++ b/docs/PageBreaks.md @@ -62,7 +62,7 @@ if dummy.page_break_triggered: # We trigger a page break manually beforehand: pdf.add_page() # We duplicate the section header: - pdf.cell(txt="Appendix C") + pdf.cell(text="Appendix C") # Now performing our rendering for real: pdf.multi_cell(...) ``` \ No newline at end of file diff --git a/docs/PageFormatAndOrientation.md b/docs/PageFormatAndOrientation.md index be065665c..742a5eea7 100644 --- a/docs/PageFormatAndOrientation.md +++ b/docs/PageFormatAndOrientation.md @@ -27,10 +27,10 @@ for i in range(9): if i == 6: pdf.set_page_background('image_path.png') pdf.add_page(format=(210 * (1 - i/10), 297 * (1 - i/10))) - pdf.cell(txt=str(i)) + pdf.cell(text=str(i)) pdf.set_page_background(None) pdf.add_page(same=True) -pdf.cell(txt="9") +pdf.cell(text="9") pdf.output("varying_format.pdf") ``` @@ -51,9 +51,9 @@ pdf = FPDF() pdf.set_display_mode(zoom="default", layout="TWO_COLUMN_LEFT") pdf.set_font("helvetica", size=30) pdf.add_page() -pdf.cell(txt="page 1") +pdf.cell(text="page 1") pdf.add_page() -pdf.cell(txt="page 2") +pdf.cell(text="page 2") pdf.output("two-column.pdf") ``` @@ -74,9 +74,9 @@ pdf.viewer_preferences = ViewerPreferences( ) pdf.set_font("helvetica", size=30) pdf.add_page() -pdf.cell(txt="page 1") +pdf.cell(text="page 1") pdf.add_page() -pdf.cell(txt="page 2") +pdf.cell(text="page 2") pdf.output("viewer-prefs.pdf") ``` diff --git a/docs/Presentations.md b/docs/Presentations.md index 31bf23e0a..b9f918b4c 100644 --- a/docs/Presentations.md +++ b/docs/Presentations.md @@ -16,12 +16,12 @@ from fpdf import FPDF pdf = fpdf.FPDF() pdf.set_font("Helvetica", size=120) pdf.add_page(duration=3) -pdf.cell(txt="Page 1") +pdf.cell(text="Page 1") pdf.page_duration = .5 pdf.add_page() -pdf.cell(txt="Page 2") +pdf.cell(text="Page 2") pdf.add_page() -pdf.cell(txt="Page 3") +pdf.cell(text="Page 3") pdf.output("presentation.pdf") ``` @@ -39,29 +39,29 @@ from fpdf.transitions import * pdf = fpdf.FPDF() pdf.set_font("Helvetica", size=120) pdf.add_page() -pdf.text(x=40, y=150, txt="Page 0") +pdf.text(x=40, y=150, text="Page 0") pdf.add_page(transition=SplitTransition("V", "O")) -pdf.text(x=40, y=150, txt="Page 1") +pdf.text(x=40, y=150, text="Page 1") pdf.add_page(transition=BlindsTransition("H")) -pdf.text(x=40, y=150, txt="Page 2") +pdf.text(x=40, y=150, text="Page 2") pdf.add_page(transition=BoxTransition("I")) -pdf.text(x=40, y=150, txt="Page 3") +pdf.text(x=40, y=150, text="Page 3") pdf.add_page(transition=WipeTransition(90)) -pdf.text(x=40, y=150, txt="Page 4") +pdf.text(x=40, y=150, text="Page 4") pdf.add_page(transition=DissolveTransition()) -pdf.text(x=40, y=150, txt="Page 5") +pdf.text(x=40, y=150, text="Page 5") pdf.add_page(transition=GlitterTransition(315)) -pdf.text(x=40, y=150, txt="Page 6") +pdf.text(x=40, y=150, text="Page 6") pdf.add_page(transition=FlyTransition("H")) -pdf.text(x=40, y=150, txt="Page 7") +pdf.text(x=40, y=150, text="Page 7") pdf.add_page(transition=PushTransition(270)) -pdf.text(x=40, y=150, txt="Page 8") +pdf.text(x=40, y=150, text="Page 8") pdf.add_page(transition=CoverTransition(270)) -pdf.text(x=40, y=150, txt="Page 9") +pdf.text(x=40, y=150, text="Page 9") pdf.add_page(transition=UncoverTransition(270)) -pdf.text(x=40, y=150, txt="Page 10") +pdf.text(x=40, y=150, text="Page 10") pdf.add_page(transition=FadeTransition()) -pdf.text(x=40, y=150, txt="Page 11") +pdf.text(x=40, y=150, text="Page 11") pdf.output("transitions.pdf") ``` diff --git a/docs/TextShaping.md b/docs/TextShaping.md index c8f849b47..1889f83d8 100644 --- a/docs/TextShaping.md +++ b/docs/TextShaping.md @@ -56,7 +56,7 @@ pdf.add_page() pdf.add_font(family="ViaodaLibre", fname=HERE / "ViaodaLibre-Regular.ttf") pdf.set_font("ViaodaLibre", size=40) pdf.set_text_shaping(True) -pdf.cell(txt="final soft stuff") +pdf.cell(text="final soft stuff") pdf.output("Example.pdf") ``` diff --git a/docs/TextStyling.md b/docs/TextStyling.md index b94466901..cdcd2c97b 100644 --- a/docs/TextStyling.md +++ b/docs/TextStyling.md @@ -15,13 +15,13 @@ from fpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=36) -pdf.cell(txt="This") +pdf.cell(text="This") pdf.set_font(style="B") -pdf.cell(txt="is") +pdf.cell(text="is") pdf.set_font(style="I") -pdf.cell(txt="a") +pdf.cell(text="a") pdf.set_font(style="U") -pdf.cell(txt="PDF") +pdf.cell(text="PDF") pdf.output("style.pdf") ``` @@ -37,10 +37,10 @@ pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", "", 8) pdf.set_fill_color(255, 255, 0) -pdf.multi_cell(w=50, txt=LOREM_IPSUM[:100], new_x="LEFT", fill=True) +pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True) pdf.ln() pdf.set_stretching(150) -pdf.multi_cell(w=50, txt=LOREM_IPSUM[:100], new_x="LEFT", fill=True) +pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True) ``` ![](font_stretching.png) @@ -59,10 +59,10 @@ pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", "", 8) pdf.set_fill_color(255, 255, 0) -pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True) +pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True) pdf.ln() pdf.set_char_spacing(10) -pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True) +pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True) ``` ![](char_spacing.png) @@ -106,25 +106,25 @@ The example shows the most common use cases: pdf = fpdf.FPDF() pdf.add_page() pdf.set_font("Helvetica", "", 20) - pdf.write(txt="2") + pdf.write(text="2") pdf.char_vpos = "SUP" - pdf.write(txt="56") + pdf.write(text="56") pdf.char_vpos = "LINE" - pdf.write(txt=" more line text") + pdf.write(text=" more line text") pdf.char_vpos = "SUB" - pdf.write(txt="(idx)") + pdf.write(text="(idx)") pdf.char_vpos = "LINE" - pdf.write(txt=" end") + pdf.write(text=" end") pdf.ln() - pdf.write(txt="1234 + ") + pdf.write(text="1234 + ") pdf.char_vpos = "NOM" - pdf.write(txt="5") + pdf.write(text="5") pdf.char_vpos = "LINE" - pdf.write(txt="/") + pdf.write(text="/") pdf.char_vpos = "DENOM" - pdf.write(txt="16") + pdf.write(text="16") pdf.char_vpos = "LINE" - pdf.write(txt=" + 987 = x") + pdf.write(text=" + 987 = x") ``` ![](char_vpos.png) @@ -151,13 +151,13 @@ pdf.add_page() pdf.set_font("Helvetica", size=100) with pdf.local_context(text_mode="STROKE", line_width=2): - pdf.cell(txt="Hello world") + pdf.cell(text="Hello world") # Outside the local context, text_mode & line_width are reverted # back to their original default values pdf.ln() with pdf.local_context(text_mode="CLIP"): - pdf.cell(txt="CLIP text mode") + pdf.cell(text="CLIP text mode") for r in range(0, 250, 2): # drawing concentric circles pdf.circle(x=130-r/2, y=70-r/2, r=r) @@ -187,7 +187,7 @@ from fpdf import FPDF pdf = fpdf.FPDF() pdf.add_page() pdf.set_font("Times", size=60) -pdf.cell(txt="**Lorem** __Ipsum__ --dolor--", markdown=True) +pdf.cell(text="**Lorem** __Ipsum__ --dolor--", markdown=True) pdf.output("markdown-styled.pdf") ``` diff --git a/docs/Transformations.md b/docs/Transformations.md index 065706b87..70dc413a9 100644 --- a/docs/Transformations.md +++ b/docs/Transformations.md @@ -25,13 +25,13 @@ pdf.output("rotations.pdf") ```python with pdf.skew(ax=0, ay=10): - pdf.cell(txt="text skewed on the y-axis") + pdf.cell(text="text skewed on the y-axis") ``` ![](y_axis_skewed_text.png) ```python with pdf.skew(ax=10, ay=0): - pdf.cell(txt="text skewed on the x-axis") + pdf.cell(text="text skewed on the x-axis") ``` ![](x_axis_skewed_text.png) @@ -52,28 +52,28 @@ The `mirror` context-manager applies a mirror transformation to all objects inse ```python x, y = 100, 100 -pdf.text(x, y, txt="mirror this text") +pdf.text(x, y, text="mirror this text") with pdf.mirror((x, y), "EAST"): pdf.set_text_color(r=255, g=128, b=0) - pdf.text(x, y, txt="mirror this text") + pdf.text(x, y, text="mirror this text") ``` ![](horizontal_mirror.png) ```python -pdf.text(x, y, txt="mirror this text") +pdf.text(x, y, text="mirror this text") with pdf.mirror((x, y), "NORTH"): pdf.set_text_color(r=255, g=128, b=0) - pdf.text(x, y, txt="mirror this text") + pdf.text(x, y, text="mirror this text") ``` ![](vertical_mirror.png) ```python prev_x, prev_y = pdf.x, pdf.y -pdf.multi_cell(w=50, txt=LOREM_IPSUM) +pdf.multi_cell(w=50, text=LOREM_IPSUM) with pdf.mirror((pdf.x, pdf.y), "NORTHEAST"): # Reset cursor to mirror original multi-cell pdf.x = prev_x pdf.y = prev_y - pdf.multi_cell(w=50, txt=LOREM_IPSUM, fill=True) + pdf.multi_cell(w=50, text=LOREM_IPSUM, fill=True) ``` ![](diagonal_mirror.png) \ No newline at end of file diff --git a/docs/Unicode.md b/docs/Unicode.md index 9d3594c0b..6b18ac868 100644 --- a/docs/Unicode.md +++ b/docs/Unicode.md @@ -171,7 +171,7 @@ pdf.add_font(fname="Roboto.ttf") pdf.add_font(fname="TwitterEmoji.ttf") pdf.set_font("Roboto", size=15) pdf.set_fallback_fonts(["TwitterEmoji"]) -pdf.write(txt="text with an emoji 🌭") +pdf.write(text="text with an emoji 🌭") pdf.output("text_with_emoji.pdf") ``` diff --git a/docs/UsageInWebAPI.md b/docs/UsageInWebAPI.md index 84a1a46ff..e7232bdca 100644 --- a/docs/UsageInWebAPI.md +++ b/docs/UsageInWebAPI.md @@ -21,7 +21,7 @@ def report(request): pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", size=24) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") return HttpResponse(bytes(pdf.output()), content_type="application/pdf") ``` @@ -42,7 +42,7 @@ def hello_world(): pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", size=24) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") response = make_response(pdf.output()) response.headers["Content-Type"] = "application/pdf" return response @@ -60,7 +60,7 @@ def handler(event, context): pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", size=24) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") return { 'statusCode': 200, 'headers': { @@ -131,7 +131,7 @@ def gen_pdf(): pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", size=24) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") return bytes(pdf.output()) # Embed PDF to display it: @@ -180,8 +180,8 @@ async def create_pdf(request: Request): pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", size=24) - pdf.cell(txt="hello world") - # pdf.cell(txt=data["content"]) # Using the contents of the JSON object to write into the PDF file + pdf.cell(text="hello world") + # pdf.cell(text=data["content"]) # Using the contents of the JSON object to write into the PDF file # Use str(data["content"]) if the content is non-string type diff --git a/docs/index.md b/docs/index.md index 4016c2a4e..6ce5678dc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -13,7 +13,7 @@ from fpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font('helvetica', size=12) -pdf.cell(txt="hello world") +pdf.cell(text="hello world") pdf.output("hello_world.pdf") ``` diff --git a/docs/symbol.py b/docs/symbol.py index ee5842de0..e3298457f 100755 --- a/docs/symbol.py +++ b/docs/symbol.py @@ -12,11 +12,11 @@ pdf.add_page() pdf.set_font("helvetica", size=30) pdf.y = 10 - pdf.cell(w=pdf.epw, txt="Symbol font", align="C") + pdf.cell(w=pdf.epw, text="Symbol font", align="C") pdf.x = pdf.l_margin = 10 + (col % 3) * 65 pdf.y = 30 pdf.set_font("helvetica", size=30) - pdf.cell(txt=f"\\u00{hex(n)[2:]} = ") + pdf.cell(text=f"\\u00{hex(n)[2:]} = ") pdf.set_font("symbol", size=30) - pdf.cell(txt=chr(n), ln=1) + pdf.cell(text=chr(n), ln=1) pdf.output("symbol.pdf") diff --git a/docs/zapfdingbats.py b/docs/zapfdingbats.py index 480e0e4fd..48c4b901e 100755 --- a/docs/zapfdingbats.py +++ b/docs/zapfdingbats.py @@ -6,7 +6,7 @@ pdf = FPDF() pdf.add_page() pdf.set_font("helvetica", size=30) -pdf.cell(w=pdf.epw, txt="ZapfDingbats", align="C") +pdf.cell(w=pdf.epw, text="ZapfDingbats", align="C") pdf.set_margin(0) for i, char in enumerate( "!\"#$%&'()*+,-./" @@ -21,9 +21,9 @@ pdf.x = pdf.l_margin = 10 + (i // 24) * 50 pdf.y = 30 pdf.set_font("helvetica", size=30) - pdf.cell(txt=char + " = ") + pdf.cell(text=char + " = ") pdf.set_font("zapfdingbats", size=30) - pdf.cell(txt=char, new_x="LMARGIN", new_y="NEXT") + pdf.cell(text=char, new_x="LMARGIN", new_y="NEXT") for i, n in enumerate(chain(range(0x80, 0x8E), range(0xA1, 0xF0), range(0xF1, 0xFF))): if i % 26 == 0: col = i // 26 @@ -32,7 +32,7 @@ pdf.x = pdf.l_margin = 10 + (col % 3) * 65 pdf.y = 10 pdf.set_font("helvetica", size=30) - pdf.cell(txt=f"\\u00{hex(n)[2:]} = ") + pdf.cell(text=f"\\u00{hex(n)[2:]} = ") pdf.set_font("zapfdingbats", size=30) - pdf.cell(txt=chr(n), new_x="LMARGIN", new_y="NEXT") + pdf.cell(text=chr(n), new_x="LMARGIN", new_y="NEXT") pdf.output("zapfdingbats.pdf") diff --git a/fpdf/deprecation.py b/fpdf/deprecation.py index 3c020dc7f..92aaea22e 100644 --- a/fpdf/deprecation.py +++ b/fpdf/deprecation.py @@ -7,12 +7,33 @@ """ import contextlib +from functools import wraps import inspect import os.path import warnings from types import ModuleType +def support_deprecated_txt_arg(fn): + """Decorator converting `txt=` arguments into `text=` arguments""" + + @wraps(fn) + def wrapper(self, *args, **kwargs): + txt_value = kwargs.pop("txt", None) + if txt_value is not None: + if "text" in kwargs: + raise ValueError("Both txt= & text= arguments cannot be provided") + kwargs["text"] = txt_value + warnings.warn( + 'The parameter "txt" has been renamed to "text" in 2.7.6', + DeprecationWarning, + stacklevel=get_stack_level(), + ) + return fn(self, *args, **kwargs) + + return wrapper + + class WarnOnDeprecatedModuleAttributes(ModuleType): def __call__(self): raise TypeError( diff --git a/fpdf/fpdf.py b/fpdf/fpdf.py index 836f19165..1ecbce418 100644 --- a/fpdf/fpdf.py +++ b/fpdf/fpdf.py @@ -47,7 +47,11 @@ class Image: PDFEmbeddedFile, DEFAULT_ANNOT_FLAGS, ) -from .deprecation import get_stack_level, WarnOnDeprecatedModuleAttributes +from .deprecation import ( + support_deprecated_txt_arg, + get_stack_level, + WarnOnDeprecatedModuleAttributes, +) from .encryption import StandardSecurityHandler from .enums import ( AccessPermission, @@ -2387,7 +2391,8 @@ def ink_annotation( return annotation @check_page - def text(self, x, y, txt=""): + @support_deprecated_txt_arg + def text(self, x, y, text=""): """ Prints a character string. The origin is on the left of the first character, on the baseline. This method allows placing a string precisely on the page, @@ -2396,18 +2401,19 @@ def text(self, x, y, txt=""): Args: x (float): abscissa of the origin y (float): ordinate of the origin - txt (str): string to print + text (str): string to print + txt (str): [**DEPRECATED since v2.7.6**] string to print """ if not self.font_family: raise FPDFException("No font set, you need to call set_font() beforehand") - txt = self.normalize_text(txt) + text = self.normalize_text(text) sl = [f"BT {x * self.k:.2f} {(self.h - y) * self.k:.2f} Td"] if self.text_mode != TextMode.FILL: sl.append(f" {self.text_mode} Tr {self.line_width:.2f} w") - sl.append(f"{self.current_font.encode_text(txt)} ET") - if (self.underline and txt != "") or self._record_text_quad_points: - w = self.get_string_width(txt, normalized=True, markdown=False) - if self.underline and txt != "": + sl.append(f"{self.current_font.encode_text(text)} ET") + if (self.underline and text != "") or self._record_text_quad_points: + w = self.get_string_width(text, normalized=True, markdown=False) + if self.underline and text != "": sl.append(self._do_underline(x, y, w)) if self._record_text_quad_points: h = self.font_size @@ -2677,11 +2683,12 @@ def accept_page_break(self): return self.auto_page_break @check_page + @support_deprecated_txt_arg def cell( self, w=None, h=None, - txt="", + text="", border=0, ln="DEPRECATED", align=Align.L, @@ -2707,7 +2714,7 @@ def cell( If 0, the cell extends up to the right margin. h (float): Cell height. Default value: None, meaning an height equal to the current font size. - txt (str): String to print. Default value: empty string. + text (str): String to print. Default value: empty string. border: Indicates if borders must be drawn around the cell. The value can be either a number (`0`: no border ; `1`: frame) or a string containing some or all of the following characters @@ -2726,6 +2733,7 @@ def cell( center (bool): center the cell horizontally on the page. markdown (bool): enable minimal markdown-like markup to render part of text as bold / italics / underlined. Default to False. + txt (str): [**DEPRECATED since v2.7.6**] String to print. Default value: empty string. Returns: a boolean indicating if page break was triggered """ @@ -2734,7 +2742,7 @@ def cell( if isinstance(w, str) or isinstance(h, str): raise ValueError( "Parameter 'w' and 'h' must be numbers, not strings." - " You can omit them by passing string content with txt=" + " You can omit them by passing string content with text=" ) if isinstance(border, int) and border not in (0, 1): warnings.warn( @@ -2774,8 +2782,8 @@ def cell( stacklevel=get_stack_level(), ) # Font styles preloading must be performed before any call to FPDF.get_string_width: - txt = self.normalize_text(txt) - styled_txt_frags = self._preload_font_styles(txt, markdown) + text = self.normalize_text(text) + styled_txt_frags = self._preload_font_styles(text, markdown) return self._render_styled_text_line( TextLine( styled_txt_frags, @@ -3106,7 +3114,7 @@ def _add_quad_points(self, x, y, w, h): ] ) - def _preload_font_styles(self, txt, markdown): + def _preload_font_styles(self, text, markdown): """ When Markdown styling is enabled, we require secondary fonts to ender text in bold & italics. @@ -3115,12 +3123,12 @@ def _preload_font_styles(self, txt, markdown): so we return the resulting `styled_txt_frags` tuple to avoid repeating this processing later on. """ - if not txt: + if not text: return tuple() if not markdown: - return self._parse_chars(txt) + return self._parse_chars(text) prev_font_style = self.font_style - styled_txt_frags = tuple(self._markdown_parse(txt)) + styled_txt_frags = tuple(self._markdown_parse(text)) page = self.page # We set the current to page to zero so that # set_font() does not produce any text object on the stream buffer: @@ -3138,14 +3146,14 @@ def _preload_font_styles(self, txt, markdown): self.page = page return styled_txt_frags - def _parse_chars(self, txt): + def _parse_chars(self, text): "Check if the font has all the necessary glyphs. If a glyph from a fallback font is used, break into fragments" fragments = [] txt_frag = [] if not self.is_ttf_font or not self._fallback_font_ids: - return tuple([Fragment(txt, self._get_current_graphics_state(), self.k)]) + return tuple([Fragment(text, self._get_current_graphics_state(), self.k)]) font_glyphs = self.current_font.cmap - for char in txt: + for char in text: if char == "\n" or ord(char) in font_glyphs: txt_frag.append(char) else: @@ -3195,7 +3203,7 @@ def get_fallback_font(self, char, style=""): return None return fonts_with_char[0] - def _markdown_parse(self, txt): + def _markdown_parse(self, text): "Split some text into fragments based on styling: **bold**, __italics__, --underlined--" txt_frag, in_bold, in_italics, in_underline = ( [], @@ -3220,32 +3228,32 @@ def frag(): else: font_glyphs = [] - while txt: - is_marker = txt[:2] in ( + while text: + is_marker = text[:2] in ( self.MARKDOWN_BOLD_MARKER, self.MARKDOWN_ITALICS_MARKER, self.MARKDOWN_UNDERLINE_MARKER, ) - half_marker = txt[0] + half_marker = text[0] # Check that previous & next characters are not identical to the marker: if ( is_marker - and (len(txt_frag) < 1 or txt_frag[-1] != half_marker) - and (len(txt) < 3 or txt[2] != half_marker) + and (not txt_frag or txt_frag[-1] != half_marker) + and (len(text) < 3 or text[2] != half_marker) ): if txt_frag: yield frag() - if txt[:2] == self.MARKDOWN_BOLD_MARKER: + if text[:2] == self.MARKDOWN_BOLD_MARKER: in_bold = not in_bold - if txt[:2] == self.MARKDOWN_ITALICS_MARKER: + if text[:2] == self.MARKDOWN_ITALICS_MARKER: in_italics = not in_italics - if txt[:2] == self.MARKDOWN_UNDERLINE_MARKER: + if text[:2] == self.MARKDOWN_UNDERLINE_MARKER: in_underline = not in_underline - txt = txt[2:] + text = text[2:] continue - is_link = self.MARKDOWN_LINK_REGEX.match(txt) + is_link = self.MARKDOWN_LINK_REGEX.match(text) if is_link: - link_text, link_dest, txt = is_link.groups() + link_text, link_dest, text = is_link.groups() if txt_frag: yield frag() gstate = self._get_current_graphics_state() @@ -3259,19 +3267,19 @@ def frag(): pass yield Fragment(list(link_text), gstate, self.k, link=link_dest) continue - if self.is_ttf_font and txt[0] != "\n" and not ord(txt[0]) in font_glyphs: + if self.is_ttf_font and text[0] != "\n" and not ord(text[0]) in font_glyphs: style = ("B" if in_bold else "") + ("I" if in_italics else "") - fallback_font = self.get_fallback_font(txt[0], style) + fallback_font = self.get_fallback_font(text[0], style) if fallback_font: if txt_frag: yield frag() gstate = self._get_current_graphics_state() gstate["font_family"] = fallback_font - yield Fragment(txt[0], gstate, self.k) - txt = txt[1:] + yield Fragment(text[0], gstate, self.k) + text = text[1:] continue - txt_frag.append(txt[0]) - txt = txt[1:] + txt_frag.append(text[0]) + text = text[1:] if txt_frag: yield frag() @@ -3337,11 +3345,12 @@ def _disable_writing(self): del self._out @check_page + @support_deprecated_txt_arg def multi_cell( self, w, h=None, - txt="", + text="", border=0, align=Align.J, fill=False, @@ -3370,7 +3379,7 @@ def multi_cell( Args: w (float): cell width. If 0, they extend up to the right margin of the page. h (float): height of a single line of text. Default value: None, meaning to use the current font size. - txt (str): string to print. + text (str): string to print. border: Indicates if borders must be drawn around the cell. The value can be either a number (`0`: no border ; `1`: frame) or a string containing some or all of the following characters @@ -3400,6 +3409,7 @@ def multi_cell( Can be useful when combined with `output`. output (fpdf.enums.MethodReturnValue): defines what this method returns. If several enum values are joined, the result will be a tuple. + txt (str): [**DEPRECATED since v2.7.6**] string to print. center (bool): center the cell horizontally on the page. padding (float or Sequence): padding to apply around the text. Default value: 0. When one value is specified, it applies the same padding to all four sides. @@ -3411,7 +3421,6 @@ def multi_cell( Center overrides values for horizontal padding - Using `new_x=XPos.RIGHT, new_y=XPos.TOP, maximum height=pdf.font_size` is useful to build tables with multiline text in cells. @@ -3435,7 +3444,7 @@ def multi_cell( return self.multi_cell( w=w, h=h, - txt=txt, + text=text, border=border, align=align, fill=fill, @@ -3458,7 +3467,7 @@ def multi_cell( if isinstance(w, str) or isinstance(h, str): raise ValueError( "Parameter 'w' and 'h' must be numbers, not strings." - " You can omit them by passing string content with txt=" + " You can omit them by passing string content with text=" ) new_x = XPos.coerce(new_x) new_y = YPos.coerce(new_y) @@ -3522,8 +3531,8 @@ def multi_cell( ) # Calculate text length - txt = self.normalize_text(txt) - normalized_string = txt.replace("\r", "") + text = self.normalize_text(text) + normalized_string = text.replace("\r", "") styled_text_fragments = self._preload_font_styles(normalized_string, markdown) prev_font_style, prev_underline = self.font_style, self.underline @@ -3667,10 +3676,11 @@ def multi_cell( return return_value @check_page + @support_deprecated_txt_arg def write( self, h: float = None, - txt: str = "", + text: str = "", link: str = "", print_sh: bool = False, wrapmode: WrapMode = WrapMode.WORD, @@ -3684,13 +3694,14 @@ def write( Args: h (float): line height. Default value: None, meaning to use the current font size. - txt (str): text content + text (str): text content link (str): optional link to add on the text, internal (identifier returned by `FPDF.add_link`) or external URL. print_sh (bool): Treat a soft-hyphen (\\u00ad) as a normal printable character, instead of a line breaking opportunity. Default value: False wrapmode (fpdf.enums.WrapMode): "WORD" for word based line wrapping (default), "CHAR" for character based line wrapping. + txt (str): [**DEPRECATED since v2.7.6**] text content """ wrapmode = WrapMode.coerce(wrapmode) if not self.font_family: @@ -3698,13 +3709,13 @@ def write( if isinstance(h, str): raise ValueError( "Parameter 'h' must be a number, not a string." - " You can omit it by passing string content with txt=" + " You can omit it by passing string content with text=" ) if h is None: h = self.font_size page_break_triggered = False - normalized_string = self.normalize_text(txt).replace("\r", "") + normalized_string = self.normalize_text(text).replace("\r", "") styled_text_fragments = self._preload_font_styles(normalized_string, False) text_lines = [] @@ -4239,20 +4250,20 @@ def set_xy(self, x, y): self.set_y(y) self.set_x(x) - def normalize_text(self, txt): + def normalize_text(self, text): """Check that text input is in the correct format/encoding""" # - for TTF unicode fonts: unicode object (utf8 encoding) # - for built-in fonts: string instances (encoding: latin-1, cp1252) if not self.is_ttf_font and self.core_fonts_encoding: try: - return txt.encode(self.core_fonts_encoding).decode("latin-1") + return text.encode(self.core_fonts_encoding).decode("latin-1") except UnicodeEncodeError as error: raise FPDFUnicodeEncodingException( text_index=error.start, - character=txt[error.start], + character=text[error.start], font_name=self.font_family + self.font_style, ) from error - return txt + return text def sign_pkcs12( self, @@ -4447,7 +4458,7 @@ def _out(self, s): self.pages[self.page].contents += s + b"\n" @check_page - def interleaved2of5(self, txt, x, y, w=1, h=10): + def interleaved2of5(self, text, x, y, w=1, h=10): """Barcode I2of5 (numeric), adds a 0 if odd length""" narrow = w / 3 wide = w @@ -4469,7 +4480,7 @@ def interleaved2of5(self, txt, x, y, w=1, h=10): } # The caller should do this, or we can't rotate the thing. # self.set_fill_color(0) - code = txt + code = text # add leading zero if code-length is odd if len(code) % 2 != 0: code = f"0{code}" @@ -4503,10 +4514,10 @@ def interleaved2of5(self, txt, x, y, w=1, h=10): x += line_width @check_page - def code39(self, txt, x, y, w=1.5, h=5): + def code39(self, text, x, y, w=1.5, h=5): """Barcode 3of9""" dim = {"w": w, "n": w / 3} - if not txt.startswith("*") or not txt.endswith("*"): + if not text.startswith("*") or not text.endswith("*"): warnings.warn( ( "Code 39 input must start and end with a '*' character to be valid." @@ -4562,7 +4573,7 @@ def code39(self, txt, x, y, w=1.5, h=5): } # The caller should do this, or we can't rotate the thing. # self.set_fill_color(0) - for c in txt.upper(): + for c in text.upper(): if c not in chars: raise RuntimeError(f'Invalid char "{c}" for Code39') for i, d in enumerate(chars[c]): @@ -4766,7 +4777,7 @@ def start_section(self, name, level=0, strict=True): pdf.multi_cell( w=pdf.epw, h=pdf.font_size, - txt=name, + text=name, new_x=XPos.LMARGIN, new_y=YPos.NEXT, ) @@ -4779,7 +4790,7 @@ def start_section(self, name, level=0, strict=True): self.multi_cell( w=self.epw, h=self.font_size, - txt=name, + text=name, new_x=XPos.LMARGIN, new_y=YPos.NEXT, ) diff --git a/fpdf/html.py b/fpdf/html.py index 0c6903e27..e6d42ad0a 100644 --- a/fpdf/html.py +++ b/fpdf/html.py @@ -777,11 +777,11 @@ def set_text_color(self, r=None, g=0, b=0): self.pdf.set_text_color(r, g, b) self.pdf.page = prev_page - def put_link(self, txt): + def put_link(self, text): # Put a hyperlink self.set_text_color(0, 0, 255) self.set_style("u", True) - self._write_paragraph(txt, link=self.href) + self._write_paragraph(text, link=self.href) self.set_style("u", False) self.set_text_color(*self.font_color) @@ -796,7 +796,7 @@ def render_toc(self, pdf, outline): pdf.multi_cell( w=pdf.epw, h=pdf.font_size, - txt=text, + text=text, new_x=XPos.LMARGIN, new_y=YPos.NEXT, link=link, diff --git a/fpdf/table.py b/fpdf/table.py index a388bbe27..b74feb5d1 100644 --- a/fpdf/table.py +++ b/fpdf/table.py @@ -503,7 +503,7 @@ def _render_table_cell( page_break_text, cell_height = self._fpdf.multi_cell( w=col_width, h=row_height, - txt=cell.text, + text=cell.text, max_line_height=self._line_height, border=0, align=text_align, diff --git a/fpdf/template.py b/fpdf/template.py index a30487f85..f9c00fc91 100644 --- a/fpdf/template.py +++ b/fpdf/template.py @@ -286,7 +286,7 @@ def split_multicell(self, text, element_name): return self.splitting_pdf.multi_cell( w=element["x2"] - element["x1"], h=element["y2"] - element["y1"], - txt=str(text), + text=str(text), align=element.get("align", ""), dry_run=True, output="LINES", @@ -340,21 +340,21 @@ def _text( pdf.set_xy(x1, y1) width, height = x2 - x1, y2 - y1 if multiline is None: # write without wrapping/trimming (default) - pdf.cell(w=width, h=height, txt=text, border=0, align=align, fill=fill) + pdf.cell(w=width, h=height, text=text, border=0, align=align, fill=fill) elif multiline: # automatic word - warp pdf.multi_cell( - w=width, h=height, txt=text, border=0, align=align, fill=fill + w=width, h=height, text=text, border=0, align=align, fill=fill ) else: # trim to fit exactly the space defined text = pdf.multi_cell( w=width, h=height, - txt=text, + text=text, align=align, dry_run=True, output="LINES", )[0] - pdf.cell(w=width, h=height, txt=text, border=0, align=align, fill=fill) + pdf.cell(w=width, h=height, text=text, border=0, align=align, fill=fill) def _line( self, diff --git a/test/barcodes/test_barcodes.py b/test/barcodes/test_barcodes.py index 69babe62e..eb38fea08 100644 --- a/test/barcodes/test_barcodes.py +++ b/test/barcodes/test_barcodes.py @@ -11,7 +11,7 @@ def test_code39(tmp_path): pdf.add_page() pdf.code39("*fpdf2*", x=30, y=50, w=4, h=20) pdf.set_font("courier", "B", size=36) - pdf.text(x=70, y=80, txt="*fpdf2*") + pdf.text(x=70, y=80, text="*fpdf2*") assert_pdf_equal(pdf, HERE / "barcodes_code39.pdf", tmp_path) @@ -20,5 +20,5 @@ def test_interleaved2of5(tmp_path): pdf.add_page() pdf.interleaved2of5("1337", x=65, y=50, w=4, h=20) pdf.set_font("courier", "B", size=36) - pdf.text(x=80, y=80, txt="1337") + pdf.text(x=80, y=80, text="1337") assert_pdf_equal(pdf, HERE / "barcodes_interleaved2of5.pdf", tmp_path) diff --git a/test/drawing/test_drawing.py b/test/drawing/test_drawing.py index 8be2a4fdf..57d92ba6e 100644 --- a/test/drawing/test_drawing.py +++ b/test/drawing/test_drawing.py @@ -997,7 +997,7 @@ def test_blending_images(tmp_path): pdf.image(HERE / "../image/png_test_suite/f04n2c08.png", y=70 * i, h=64) with pdf.local_context(blend_mode=blend_mode): pdf.image(HERE / "../image/png_test_suite/pp0n6a08.png", y=70 * i, h=64) - pdf.text(x=0, y=70 * i + 10, txt=str(blend_mode)) + pdf.text(x=0, y=70 * i + 10, text=str(blend_mode)) assert_pdf_equal(pdf, HERE / "generated_pdf/blending_images.pdf", tmp_path) diff --git a/test/encryption/test_encryption.py b/test/encryption/test_encryption.py index 6ebc3862a..da6d9f745 100644 --- a/test/encryption/test_encryption.py +++ b/test/encryption/test_encryption.py @@ -49,7 +49,7 @@ def test_encryption_rc4(tmp_path): pdf.set_subject("string to be encrypted") pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.set_encryption(owner_password="fpdf2", permissions=AccessPermission.all()) assert_pdf_equal(pdf, HERE / "encryption_rc4.pdf", tmp_path) @@ -60,7 +60,7 @@ def test_encryption_rc4_permissions(tmp_path): pdf.set_subject("string to be encrypted") pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.set_encryption( owner_password="fpdf2", permissions=AccessPermission.PRINT_LOW_RES | AccessPermission.PRINT_HIGH_RES, @@ -79,7 +79,7 @@ def custom_file_id(): pdf.set_subject("string to be encrypted") pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.set_encryption( owner_password="fpdf2", encryption_method=EncryptionMethod.NO_ENCRYPTION, @@ -105,7 +105,7 @@ def custom_file_id(): pdf.set_subject("string to be encrypted") pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.set_encryption( owner_password="fpdf2", user_password="654321", @@ -129,7 +129,7 @@ def fixed_iv(size): pdf.set_subject("string to be encrypted") pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.set_encryption( owner_password="fpdf2", encryption_method=EncryptionMethod.AES_128, @@ -149,7 +149,7 @@ def custom_file_id(): pdf.file_id = custom_file_id pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.set_encryption( owner_password="fpdf2", encrypt_metadata=True, @@ -179,9 +179,9 @@ def test_encrypt_font(tmp_path): "Lorem ipsum dolor, **consectetur adipiscing** elit," " eiusmod __tempor incididunt__ ut labore et dolore --magna aliqua--." ) - pdf.multi_cell(w=pdf.epw, txt=text, markdown=True) + pdf.multi_cell(w=pdf.epw, text=text, markdown=True) pdf.ln() - pdf.multi_cell(w=pdf.epw, txt=text, markdown=True, align="L") + pdf.multi_cell(w=pdf.epw, text=text, markdown=True, align="L") pdf.set_encryption(owner_password="fpdf2") assert_pdf_equal(pdf, HERE / "encrypt_fonts.pdf", tmp_path) @@ -190,7 +190,7 @@ def test_encryption_with_hyperlink(tmp_path): # issue 672 pdf = FPDF() pdf.add_page() pdf.set_font("helvetica") - pdf.cell(txt="hyperlink", link="https://github.com/py-pdf/fpdf2") + pdf.cell(text="hyperlink", link="https://github.com/py-pdf/fpdf2") pdf.set_encryption(owner_password="fpdf2") assert_pdf_equal(pdf, HERE / "encryption_with_hyperlink.pdf", tmp_path) @@ -220,7 +220,7 @@ def fixed_iv(size): pdf.set_subject("string to be encrypted") pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.text(50, 50, "Some text") pdf.ink_annotation( [(40, 50), (70, 25), (100, 50), (70, 75), (40, 50)], @@ -251,7 +251,7 @@ def fixed_iv(size): pdf.set_subject("string to be encrypted") pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.cell(txt="hello world") + pdf.cell(text="hello world") pdf.set_encryption( owner_password="fpdf2", user_password="1" * 1000, @@ -305,7 +305,7 @@ def test_encryption_unicode(tmp_path): pdf.set_font("Garuda", size=12) pdf.start_section("ทดสอบภาษาไทย") pdf.cell( - txt="สวัสดี ทดสอบภาษาไทย กีกี้ กาก้า ก๋า อ้า อ้ำ ฤาษี ทุ่มทุน อุ้งอุ๋ง น้ำใจ ฯลฯ ญาญ่า ฐาน ฎีกา ฏฒัฯนณ ภัทร์ สิทธิ์" + text="สวัสดี ทดสอบภาษาไทย กีกี้ กาก้า ก๋า อ้า อ้ำ ฤาษี ทุ่มทุน อุ้งอุ๋ง น้ำใจ ฯลฯ ญาญ่า ฐาน ฎีกา ฏฒัฯนณ ภัทร์ สิทธิ์" ) pdf.set_encryption(owner_password="fpdf2") assert_pdf_equal(pdf, HERE / "encryption_unicode.pdf", tmp_path) diff --git a/test/errors/test_FPDF_errors.py b/test/errors/test_FPDF_errors.py index adf8f7301..d78778a4d 100644 --- a/test/errors/test_FPDF_errors.py +++ b/test/errors/test_FPDF_errors.py @@ -23,7 +23,7 @@ def test_encoding_exception(): pdf.add_page() pdf.set_font("Helvetica", size=15) with pytest.raises(FPDFUnicodeEncodingException) as error: - pdf.cell(txt="Joséō") + pdf.cell(text="Joséō") # This should through an error since Helvetica is a latin-1 encoder and the ō is out of range. msg = ( 'Character "ō" at index 4 in text is outside the range of characters supported by the font ' @@ -90,7 +90,7 @@ def test_adding_content_after_closing(): pdf = fpdf.FPDF() pdf.set_font("helvetica", size=24) pdf.add_page() - pdf.cell(w=pdf.epw, txt="Hello fpdf2!", align="C") + pdf.cell(w=pdf.epw, text="Hello fpdf2!", align="C") pdf.output() with pytest.raises(FPDFException) as error: pdf.add_page() @@ -99,7 +99,7 @@ def test_adding_content_after_closing(): == "A page cannot be added on a closed document, after calling output()" ) with pytest.raises(FPDFException) as error: - pdf.cell(w=pdf.epw, txt="Hello again!", align="C") + pdf.cell(w=pdf.epw, text="Hello again!", align="C") assert ( str(error.value) == "Content cannot be added on a finalized document, after calling output()" diff --git a/test/fonts/test_add_font.py b/test/fonts/test_add_font.py index a1442952f..85fac953f 100644 --- a/test/fonts/test_add_font.py +++ b/test/fonts/test_add_font.py @@ -88,7 +88,7 @@ def test_add_font_with_str_fname_ok(tmp_path): pdf.add_font(fname=font_file_path) pdf.set_font("Roboto-Regular", size=64) pdf.add_page() - pdf.cell(txt="Hello World!") + pdf.cell(text="Hello World!") assert_pdf_equal(pdf, HERE / "add_font_unicode.pdf", tmp_path) for r in record: @@ -118,7 +118,7 @@ def test_render_en_dash(tmp_path): # issue-166 pdf.add_font(fname=HERE / "Roboto-Regular.ttf") pdf.set_font("Roboto-Regular", size=120) pdf.add_page() - pdf.cell(w=pdf.epw, txt="–") # U+2013 + pdf.cell(w=pdf.epw, text="–") # U+2013 assert_pdf_equal(pdf, HERE / "render_en_dash.pdf", tmp_path) @@ -137,9 +137,9 @@ def test_add_font_otf(tmp_path): "Lorem ipsum dolor, **consectetur adipiscing** elit," " eiusmod __tempor incididunt__ ut labore et dolore --magna aliqua--." ) - pdf.multi_cell(w=pdf.epw, txt=text, markdown=True) + pdf.multi_cell(w=pdf.epw, text=text, markdown=True) pdf.ln() - pdf.multi_cell(w=pdf.epw, txt=text, markdown=True, align="L") + pdf.multi_cell(w=pdf.epw, text=text, markdown=True, align="L") assert_pdf_equal(pdf, HERE / "fonts_otf.pdf", tmp_path) @@ -154,6 +154,6 @@ def test_font_missing_glyphs(caplog): pdf.add_page() pdf.add_font(family="Roboto", fname=HERE / "Roboto-Regular.ttf") pdf.set_font("Roboto") - pdf.cell(txt="Test 𝕥𝕖𝕤𝕥 🆃🅴🆂🆃 😲") + pdf.cell(text="Test 𝕥𝕖𝕤𝕥 🆃🅴🆂🆃 😲") pdf.output(devnull) assert "Roboto is missing the following glyphs: 𝕥, 𝕖, 𝕤, 🆃, 🅴, 🆂, 😲" in caplog.text diff --git a/test/fonts/test_font_fallback.py b/test/fonts/test_font_fallback.py index 432a385e9..1d83b2303 100644 --- a/test/fonts/test_font_fallback.py +++ b/test/fonts/test_font_fallback.py @@ -19,11 +19,11 @@ def test_fallback_font(tmp_path): pdf.add_font(family="Roboto", style="B", fname=HERE / "Roboto-Bold.ttf") pdf.add_font(family="DejaVuSans", fname=HERE / "DejaVuSans.ttf") pdf.set_font("Roboto", size=15) - pdf.write(txt="WITHOUT FALLBACK FONT:\n") + pdf.write(text="WITHOUT FALLBACK FONT:\n") write_strings(pdf) pdf.ln(10) - pdf.write(txt="WITH FALLBACK FONT:\n") + pdf.write(text="WITH FALLBACK FONT:\n") pdf.set_fallback_fonts(["DejaVuSans"]) write_strings(pdf) @@ -35,21 +35,21 @@ def test_fallback_font(tmp_path): def write_strings(pdf): - pdf.write(txt="write() 😄 😁 😆 😅 ✌") + pdf.write(text="write() 😄 😁 😆 😅 ✌") pdf.ln() pdf.cell( - txt="cell() without markdown 😄 😁**bold** 😆 😅 ✌", + text="cell() without markdown 😄 😁**bold** 😆 😅 ✌", new_x=XPos.LMARGIN, new_y=YPos.NEXT, ) pdf.cell( - txt="cell() with markdown 😄 😁**bold** 😆 😅 ✌", + text="cell() with markdown 😄 😁**bold** 😆 😅 ✌", markdown=True, new_x=XPos.LMARGIN, new_y=YPos.NEXT, ) pdf.multi_cell( - txt="multi_cell() 😄 😁 😆 😅 ✌", + text="multi_cell() 😄 😁 😆 😅 ✌", w=50, new_x=XPos.LMARGIN, new_y=YPos.NEXT, @@ -79,7 +79,7 @@ def test_fallback_font_ignore_style(tmp_path): pdf.set_fallback_fonts(["DejaVuSans"], exact_match=True) pdf.cell( - txt="cell() with markdown + exact_match=True: **[😄 😁]** 😆 😅 ✌", + text="cell() with markdown + exact_match=True: **[😄 😁]** 😆 😅 ✌", markdown=True, new_x=XPos.LMARGIN, new_y=YPos.NEXT, @@ -88,7 +88,7 @@ def test_fallback_font_ignore_style(tmp_path): pdf.set_fallback_fonts(["DejaVuSans"], exact_match=False) pdf.cell( - txt="cell() with markdown + exact_match=False: **[😄 😁]** 😆 😅 ✌", + text="cell() with markdown + exact_match=False: **[😄 😁]** 😆 😅 ✌", markdown=True, new_x=XPos.LMARGIN, new_y=YPos.NEXT, @@ -97,7 +97,7 @@ def test_fallback_font_ignore_style(tmp_path): pdf.add_font(family="DejaVuSans", style="B", fname=HERE / "DejaVuSans-Bold.ttf") pdf.cell( - txt="cell() with markdown + matching font style: **[😄 😁]** 😆 😅 ✌", + text="cell() with markdown + matching font style: **[😄 😁]** 😆 😅 ✌", markdown=True, new_x=XPos.LMARGIN, new_y=YPos.NEXT, @@ -111,7 +111,7 @@ def test_fallback_font_ignore_style(tmp_path): family="DejaVuSans", style="IB", fname=HERE / "DejaVuSans-BoldOblique.ttf" ) pdf.cell( - txt="cell() with markdown + bold-italics: __{**[😄 😁]** 😆 😅}__ ✌", + text="cell() with markdown + bold-italics: __{**[😄 😁]** 😆 😅}__ ✌", markdown=True, new_x=XPos.LMARGIN, new_y=YPos.NEXT, @@ -158,14 +158,14 @@ def get_fallback_font(self, char, style=""): pdf.set_fallback_fonts(["DejaVuSans", "TwitterEmoji", "Waree"]) pdf.set_font("Quicksand", size=20) pdf.cell( - txt=text, + text=text, new_x=XPos.LMARGIN, new_y=YPos.NEXT, ) pdf.ln() pdf.set_font("Roboto", size=20) pdf.cell( - txt=text, + text=text, new_x=XPos.LMARGIN, new_y=YPos.NEXT, ) @@ -201,6 +201,6 @@ def test_glyph_not_on_any_font(caplog): pdf.add_font(family="DejaVuSans", fname=HERE / "DejaVuSans.ttf") pdf.set_font("Roboto") pdf.set_fallback_fonts(["DejaVuSans"]) - pdf.cell(txt="Test 𝕥𝕖𝕤𝕥 🆃🅴🆂🆃 😲") + pdf.cell(text="Test 𝕥𝕖𝕤𝕥 🆃🅴🆂🆃 😲") pdf.output(devnull) assert "Roboto is missing the following glyphs: 🆃, 🅴, 🆂" in caplog.text diff --git a/test/fonts/test_font_remap.py b/test/fonts/test_font_remap.py index c594bf422..94676191d 100644 --- a/test/fonts/test_font_remap.py +++ b/test/fonts/test_font_remap.py @@ -14,7 +14,7 @@ def test_emoji_glyph(tmp_path): pdf.set_font("DejaVuSans", size=64) pdf.add_page() - pdf.multi_cell(0, txt="".join([chr(0x1F600 + x) for x in range(68)])) + pdf.multi_cell(0, text="".join([chr(0x1F600 + x) for x in range(68)])) pdf.set_font_size(32) pdf.text(10, 270, "".join([chr(0x1F0A0 + x) for x in range(15)])) @@ -29,10 +29,10 @@ def test_nb_replace(tmp_path): pdf.add_page() pdf.set_font("DejaVuSans", size=64) - pdf.cell(txt="{nb}") + pdf.cell(text="{nb}") pdf.set_font("helvetica") - pdf.cell(txt="{nb}") + pdf.cell(text="{nb}") assert_pdf_equal(pdf, HERE / "fonts_remap_nb.pdf", tmp_path) @@ -45,10 +45,10 @@ def test_two_mappings(tmp_path): pdf.add_page() pdf.set_font("DejaVuSans", size=64) - pdf.cell(txt="ABCDEF") + pdf.cell(text="ABCDEF") pdf.set_font("DroidSansFallback") - pdf.cell(txt="DEFGHI") + pdf.cell(text="DEFGHI") assert_pdf_equal(pdf, HERE / "fonts_two_mappings.pdf", tmp_path) @@ -58,5 +58,5 @@ def test_thai_text(tmp_path): pdf.add_font(fname=HERE / "Waree.ttf") pdf.set_font("Waree") pdf.add_page() - pdf.write(txt="สวัสดีชาวโลก ทดสอบฟอนต์, Hello world font test.") + pdf.write(text="สวัสดีชาวโลก ทดสอบฟอนต์, Hello world font test.") assert_pdf_equal(pdf, HERE / "thai_text.pdf", tmp_path) diff --git a/test/fonts/test_set_font.py b/test/fonts/test_set_font.py index b91d0a769..8c78735f7 100644 --- a/test/fonts/test_set_font.py +++ b/test/fonts/test_set_font.py @@ -60,9 +60,9 @@ def test_issue_66(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("Times", "B", 14) - pdf.cell(txt="ABC") + pdf.cell(text="ABC") pdf.set_font("Times", size=10) - pdf.cell(txt="DEF") + pdf.cell(text="DEF") # Setting the font to an already used one used to remove the text! pdf.set_font("Times", "B", 14) assert_pdf_equal(pdf, HERE / "fonts_issue_66.pdf", tmp_path) diff --git a/test/image/image_types/test_insert_images.py b/test/image/image_types/test_insert_images.py index be4b1ed6c..bc197a60d 100644 --- a/test/image/image_types/test_insert_images.py +++ b/test/image/image_types/test_insert_images.py @@ -86,7 +86,7 @@ def test_insert_png_alpha(tmp_path): pdf.compress = False pdf.add_page() pdf.set_font("Helvetica", size=30) - pdf.cell(w=pdf.epw, h=30, txt="BEHIND") + pdf.cell(w=pdf.epw, h=30, text="BEHIND") pdf.image( HERE / "../png_images/ba2b2b6e72ca0e4683bb640e2d5572f8.png", x=25, y=0, h=40 ) @@ -98,7 +98,7 @@ def test_insert_png_disallow_transparency(tmp_path): pdf.allow_images_transparency = False pdf.add_page() pdf.set_font("Helvetica", size=30) - pdf.cell(w=pdf.epw, h=30, txt="BEHIND") + pdf.cell(w=pdf.epw, h=30, text="BEHIND") pdf.image( HERE / "../png_images/ba2b2b6e72ca0e4683bb640e2d5572f8.png", x=25, y=0, h=40 ) diff --git a/test/layout/test_units.py b/test/layout/test_units.py index ee3b0bb49..a17183d96 100644 --- a/test/layout/test_units.py +++ b/test/layout/test_units.py @@ -12,7 +12,7 @@ def add_cell_page(pdf, cell_text): """Add a page with with some text to the PDF""" pdf.set_font("Helvetica") pdf.add_page() - pdf.cell(w=10, h=10, txt=str(cell_text)) + pdf.cell(w=10, h=10, text=str(cell_text)) def test_unit_default(tmp_path): diff --git a/test/metadata/test_display_mode.py b/test/metadata/test_display_mode.py index 041dc6d64..2aab602a1 100644 --- a/test/metadata/test_display_mode.py +++ b/test/metadata/test_display_mode.py @@ -21,7 +21,7 @@ def test_setting_all_zoom(zoom, tmp_path): w=72, h=0, border=1, - txt="hello world", + text="hello world", new_x="LMARGIN", new_y="NEXT", ) @@ -41,9 +41,9 @@ def test_page_layout(page_layout, tmp_path): pdf.set_display_mode(zoom="default", layout=page_layout) pdf.set_font("helvetica", size=30) pdf.add_page() - pdf.cell(txt="page 1") + pdf.cell(text="page 1") pdf.add_page() - pdf.cell(txt="page 2") + pdf.cell(text="page 2") assert_pdf_equal(pdf, HERE / f"page-layout-{page_layout}.pdf", tmp_path) @@ -53,9 +53,9 @@ def test_layout_aliases(layout_alias, tmp_path): pdf.set_display_mode(zoom="default", layout=layout_alias) pdf.set_font("helvetica", size=30) pdf.add_page() - pdf.cell(txt="page 1") + pdf.cell(text="page 1") pdf.add_page() - pdf.cell(txt="page 2") + pdf.cell(text="page 2") assert_pdf_equal(pdf, HERE / f"layout-alias-{layout_alias}.pdf", tmp_path) @@ -65,9 +65,9 @@ def test_page_mode(page_mode, tmp_path): pdf.page_mode = page_mode pdf.set_font("helvetica", size=30) pdf.add_page() - pdf.cell(txt="page 1") + pdf.cell(text="page 1") pdf.add_page() - pdf.cell(txt="page 2") + pdf.cell(text="page 2") assert_pdf_equal(pdf, HERE / f"page-mode-{page_mode}.pdf", tmp_path) @@ -76,9 +76,9 @@ def test_page_mode_zoom_numeric(tmp_path): pdf.set_display_mode(zoom=25) pdf.set_font("helvetica", size=30) pdf.add_page() - pdf.cell(txt="page 1") + pdf.cell(text="page 1") pdf.add_page() - pdf.cell(txt="page 2") + pdf.cell(text="page 2") assert_pdf_equal( pdf, HERE / f"page-mode-zoom_numeric.pdf", diff --git a/test/metadata/test_info.py b/test/metadata/test_info.py index 8a34eb131..5e493c200 100644 --- a/test/metadata/test_info.py +++ b/test/metadata/test_info.py @@ -38,7 +38,7 @@ def document_operations(doc): doc.add_page() doc.set_font("helvetica", size=12) - doc.cell(w=72, h=0, border=1, txt="hello world", fill=False, link="") + doc.cell(w=72, h=0, border=1, text="hello world", fill=False, link="") def test_put_info_all(tmp_path): diff --git a/test/metadata/test_viewer_preferences.py b/test/metadata/test_viewer_preferences.py index f5190c096..a81a25419 100644 --- a/test/metadata/test_viewer_preferences.py +++ b/test/metadata/test_viewer_preferences.py @@ -14,9 +14,9 @@ def test_default_viewer_preferences(tmp_path): pdf.viewer_preferences = ViewerPreferences() pdf.set_font("helvetica", size=30) pdf.add_page() - pdf.cell(txt="page 1") + pdf.cell(text="page 1") pdf.add_page() - pdf.cell(txt="page 2") + pdf.cell(text="page 2") assert_pdf_equal(pdf, HERE / "default_viewer_preferences.pdf", tmp_path) @@ -33,9 +33,9 @@ def test_custom_viewer_preferences(tmp_path): ) pdf.set_font("helvetica", size=30) pdf.add_page() - pdf.cell(txt="page 1") + pdf.cell(text="page 1") pdf.add_page() - pdf.cell(txt="page 2") + pdf.cell(text="page 2") assert_pdf_equal(pdf, HERE / "custom_viewer_preferences.pdf", tmp_path) diff --git a/test/outline/test_outline.py b/test/outline/test_outline.py index c2779b22f..c8e4249fd 100644 --- a/test/outline/test_outline.py +++ b/test/outline/test_outline.py @@ -80,7 +80,7 @@ def p(pdf, text, **kwargs): pdf.multi_cell( w=pdf.epw, h=pdf.font_size, - txt=text, + text=text, new_x="LMARGIN", new_y="NEXT", **kwargs, @@ -178,7 +178,7 @@ def render_toc(self, outline): self.set_font(style="", size=12) for section in outline: self.ln() - self.cell(txt=section.name) + self.cell(text=section.name) def footer(self): self.set_y(-15) @@ -192,7 +192,7 @@ def footer(self): for i in range(1, 80): pdf.set_font(style="B") pdf.start_section(f"Section {i}") - pdf.cell(txt=f"Section {i}") + pdf.cell(text=f"Section {i}") pdf.ln() assert_pdf_equal(pdf, HERE / "toc_with_nb_and_footer.pdf", tmp_path) diff --git a/test/outline/test_outline_html.py b/test/outline/test_outline_html.py index 66e3e343e..acccdbc7e 100644 --- a/test/outline/test_outline_html.py +++ b/test/outline/test_outline_html.py @@ -242,10 +242,10 @@ def test_html_toc_with_h1_as_2nd_heading(tmp_path): # issue 239 class CustomHTML2FPDF(HTML2FPDF): def render_toc(self, pdf, outline): - pdf.cell(txt="Table of contents:", new_x="LMARGIN", new_y="NEXT") + pdf.cell(text="Table of contents:", new_x="LMARGIN", new_y="NEXT") for section in outline: pdf.cell( - txt=f"* {section.name} (page {section.page_number})", + text=f"* {section.name} (page {section.page_number})", new_x="LMARGIN", new_y="NEXT", ) diff --git a/test/shapes/test_dash_pattern.py b/test/shapes/test_dash_pattern.py index e13ab05bb..6439faba2 100644 --- a/test/shapes/test_dash_pattern.py +++ b/test/shapes/test_dash_pattern.py @@ -19,7 +19,7 @@ def draw_stuff(x, y): pdf.rect(x, y, 50, 50) pdf.ellipse(x, y, 50, 50) pdf.set_xy(x, y + 55) - pdf.cell(w=50, h=5, txt="cell", border=1) + pdf.cell(w=50, h=5, text="cell", border=1) # solid line draw_stuff(20, 20) diff --git a/test/signing/test_sign.py b/test/signing/test_sign.py index 322ff75be..71b160fcb 100644 --- a/test/signing/test_sign.py +++ b/test/signing/test_sign.py @@ -24,14 +24,14 @@ def test_sign_pkcs12_with_link(tmp_path): pdf.set_creation_date(EPOCH) pdf.set_font("Helvetica", size=30) pdf.add_page() - pdf.text(x=80, y=50, txt="Page 1/2") + pdf.text(x=80, y=50, text="Page 1/2") pdf.add_page() pdf.set_xy(80, 50) pdf.sign_pkcs12(HERE / "certs.p12", password=b"1234") pdf.cell( w=50, h=20, - txt="URL link", + text="URL link", border=1, align="C", link="https://github.com/py-pdf/fpdf2", diff --git a/test/table/test_table_padding.py b/test/table/test_table_padding.py index 90d0f093d..7efd87840 100644 --- a/test/table/test_table_padding.py +++ b/test/table/test_table_padding.py @@ -540,7 +540,7 @@ def box(x, y, borders): ) draw_box_borders(pdf, x - 20, y - 20, x + 50, y + 30, border=borders) pdf.set_xy(x, y) - pdf.cell(txt=borders) + pdf.cell(text=borders) box(40, 40, "L") box(140, 40, "R") diff --git a/test/table/test_table_with_image.py b/test/table/test_table_with_image.py index 4f9d5400f..a43ee248e 100644 --- a/test/table/test_table_with_image.py +++ b/test/table/test_table_with_image.py @@ -169,7 +169,7 @@ def test_table_with_links(tmp_path): pdf.set_font("Times", size=16) pdf.add_page() pdf.y = 100 - pdf.cell(txt="Page 1", center=True) + pdf.cell(text="Page 1", center=True) pdf.add_page() with pdf.table() as table: for i, data_row in enumerate(TABLE_DATA): diff --git a/test/template/test_flextemplate.py b/test/template/test_flextemplate.py index 5a4624167..fb9c66c3c 100644 --- a/test/template/test_flextemplate.py +++ b/test/template/test_flextemplate.py @@ -489,7 +489,7 @@ def test_flextemplate_leak(tmp_path): # issue #570 pdf = FPDF() pdf.add_page() pdf.set_font("helvetica", "", 10) - pdf.cell(txt="before", new_x="LEFT", new_y="NEXT") + pdf.cell(text="before", new_x="LEFT", new_y="NEXT") tmpldata = [ { "name": "template", @@ -506,5 +506,5 @@ def test_flextemplate_leak(tmp_path): # issue #570 templ = FlexTemplate(pdf, elements=tmpldata) templ.render(offsetx=pdf.x, offsety=pdf.y) pdf.ln() - pdf.cell(txt="after", new_x="LEFT", new_y="NEXT") + pdf.cell(text="after", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "flextemplate_leak.pdf", tmp_path) diff --git a/test/test_add_page.py b/test/test_add_page.py index 88fa3ba7a..03d9a1097 100644 --- a/test/test_add_page.py +++ b/test/test_add_page.py @@ -13,9 +13,9 @@ def test_add_page_format(tmp_path): pdf.set_font("Helvetica") for i in range(9): pdf.add_page(format=(210 * (1 - i / 10), 297 * (1 - i / 10))) - pdf.cell(w=10, h=10, txt=str(i)) + pdf.cell(w=10, h=10, text=str(i)) pdf.add_page(same=True) - pdf.cell(w=10, h=10, txt="9") + pdf.cell(w=10, h=10, text="9") assert_pdf_equal(pdf, HERE / "add_page_format.pdf", tmp_path) @@ -23,12 +23,12 @@ def test_add_page_duration(tmp_path): pdf = fpdf.FPDF() pdf.set_font("Helvetica", size=120) pdf.add_page(duration=3) - pdf.cell(txt="Page 1") + pdf.cell(text="Page 1") pdf.page_duration = 0.5 pdf.add_page() - pdf.cell(txt="Page 2") + pdf.cell(text="Page 2") pdf.add_page() - pdf.cell(txt="Page 3") + pdf.cell(text="Page 3") assert_pdf_equal(pdf, HERE / "add_page_duration.pdf", tmp_path) diff --git a/test/test_annotations.py b/test/test_annotations.py index ca2110377..c57694076 100644 --- a/test/test_annotations.py +++ b/test/test_annotations.py @@ -25,7 +25,7 @@ def test_text_annotation(tmp_path): ) for i, flags in enumerate((("PRINT",), all_visible_flags)): for j, flag in enumerate(flags): - pdf.text(x=15 + 50 * i, y=10 + 5 * j, txt=flag) + pdf.text(x=15 + 50 * i, y=10 + 5 * j, text=flag) for j, name in enumerate( (None,) + tuple(AnnotationName.__members__.keys()) @@ -45,7 +45,7 @@ def test_named_actions(tmp_path): pdf = FPDF() pdf.set_font("Helvetica", size=24) pdf.add_page() - pdf.text(x=80, y=140, txt="First page") + pdf.text(x=80, y=140, text="First page") pdf.add_page() pdf.underline = True for x, y, named_action in ( @@ -54,7 +54,7 @@ def test_named_actions(tmp_path): (40, 200, "FirstPage"), (120, 200, "LastPage"), ): - pdf.text(x=x, y=y, txt=named_action) + pdf.text(x=x, y=y, text=named_action) pdf.add_action( NamedAction(named_action), x=x, @@ -64,7 +64,7 @@ def test_named_actions(tmp_path): ) pdf.underline = False pdf.add_page() - pdf.text(x=80, y=140, txt="Last page") + pdf.text(x=80, y=140, text="Last page") assert_pdf_equal(pdf, HERE / "named_actions.pdf", tmp_path) @@ -73,7 +73,7 @@ def test_goto_action(tmp_path): pdf.set_font("Helvetica", size=24) pdf.add_page() x, y, text = 80, 140, "GoTo action" - pdf.text(x=x, y=y, txt=text) + pdf.text(x=x, y=y, text=text) pdf.add_action( GoToAction(dest=DestinationXYZ(page=2, top=pdf.h_pt)), x=x, @@ -82,7 +82,7 @@ def test_goto_action(tmp_path): h=pdf.font_size, ) pdf.add_page() - pdf.text(x=80, y=140, txt="Page 2") + pdf.text(x=80, y=140, text="Page 2") assert_pdf_equal(pdf, HERE / "goto_action.pdf", tmp_path) @@ -91,7 +91,7 @@ def test_goto_remote_action(tmp_path): pdf.set_font("Helvetica", size=24) pdf.add_page() x, y, text = 80, 140, "GoTo-Remote action" - pdf.text(x=x, y=y, txt=text) + pdf.text(x=x, y=y, text=text) dest = DestinationXYZ(page=1, top=pdf.h_pt) pdf.add_action( GoToRemoteAction("goto_action.pdf", dest=dest), @@ -108,7 +108,7 @@ def test_launch_action(tmp_path): pdf.set_font("Helvetica", size=24) pdf.add_page() x, y, text = 80, 140, "Launch action" - pdf.text(x=x, y=y, txt=text) + pdf.text(x=x, y=y, text=text) pdf.add_action( LaunchAction(file="goto_action.pdf"), x=x, @@ -126,8 +126,8 @@ def test_highlighted(tmp_path): with pdf.highlight("Highlight comment", type="Squiggly", modification_time=EPOCH): pdf.text(50, 50, "Line 1") pdf.set_y(50) - pdf.multi_cell(w=30, txt="Line 2") - pdf.cell(w=60, txt="Not highlighted", border=1) + pdf.multi_cell(w=30, text="Line 2") + pdf.cell(w=60, text="Not highlighted", border=1) assert_pdf_equal(pdf, HERE / "highlighted.pdf", tmp_path) @@ -135,10 +135,10 @@ def test_highlighted_over_page_break(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("helvetica", size=24) - pdf.write(txt=LOREM_IPSUM) + pdf.write(text=LOREM_IPSUM) pdf.ln() with pdf.highlight("Comment", title="Freddy Mercury", modification_time=EPOCH): - pdf.write(txt=LOREM_IPSUM) + pdf.write(text=LOREM_IPSUM) assert_pdf_equal(pdf, HERE / "highlighted_over_page_break.pdf", tmp_path) diff --git a/test/test_graphics_context.py b/test/test_graphics_context.py index 4797d294b..8bc3f88b5 100644 --- a/test/test_graphics_context.py +++ b/test/test_graphics_context.py @@ -15,19 +15,19 @@ def test_graphics_context(tmp_path): pdf.set_text_color(0x00, 0xFF, 0x00) pdf.set_fill_color(0xFF, 0x88, 0xFF) pdf.set_y(20) - pdf.cell(txt="outer 01", new_x="LMARGIN", new_y="NEXT", fill=True) + pdf.cell(text="outer 01", new_x="LMARGIN", new_y="NEXT", fill=True) with pdf.local_context(): pdf.set_font("courier", "BIU", 30) pdf.set_text_color(0xFF, 0x00, 0x00) pdf.set_fill_color(0xFF, 0xFF, 0x00) - pdf.cell(txt="inner 01", new_x="LMARGIN", new_y="NEXT", fill=True) + pdf.cell(text="inner 01", new_x="LMARGIN", new_y="NEXT", fill=True) pdf.set_x(70) with pdf.rotation(30, pdf.get_x(), pdf.get_y()): pdf.set_fill_color(0x00, 0xFF, 0x00) - pdf.cell(txt="inner 02", new_x="LMARGIN", new_y="NEXT", fill=True) + pdf.cell(text="inner 02", new_x="LMARGIN", new_y="NEXT", fill=True) pdf.set_stretching(150) - pdf.cell(txt="inner 03", new_x="LMARGIN", new_y="NEXT", fill=True) - pdf.cell(txt="outer 02", new_x="LMARGIN", new_y="NEXT", fill=True) + pdf.cell(text="inner 03", new_x="LMARGIN", new_y="NEXT", fill=True) + pdf.cell(text="outer 02", new_x="LMARGIN", new_y="NEXT", fill=True) assert_pdf_equal(pdf, HERE / "graphics_context.pdf", tmp_path) @@ -324,9 +324,9 @@ def test_local_context_init(tmp_path): with pdf.local_context( font_family="Courier", font_style="B", font_size=24, text_color=(255, 128, 0) ): - pdf.cell(txt="Local context") + pdf.cell(text="Local context") pdf.ln() - pdf.cell(txt="Back to base") + pdf.cell(text="Back to base") assert_pdf_equal(pdf, HERE / "local_context_init.pdf", tmp_path) @@ -355,14 +355,14 @@ def test_local_context_inherited_shared_props(tmp_path): pdf.set_fill_color(255, 128, 0) pdf.set_line_width(2) pdf.set_dash_pattern(dash=0.5, gap=9.5, phase=3.25) - pdf.write(txt="normal") + pdf.write(text="normal") with pdf.local_context( fill_opacity=0.5, char_vpos="SUP" ): # => triggers creation of a local GraphicsStyle pdf.rect(x=60, y=60, w=60, h=60, style="DF") - pdf.write(txt="sup") + pdf.write(text="sup") pdf.rect(x=60, y=150, w=60, h=60, style="DF") - pdf.write(txt="normal") + pdf.write(text="normal") assert_pdf_equal(pdf, HERE / "local_context_inherited_shared_props.pdf", tmp_path) diff --git a/test/test_links.py b/test/test_links.py index 39d6a776b..afbe9865e 100644 --- a/test/test_links.py +++ b/test/test_links.py @@ -15,7 +15,7 @@ def test_hyperlinks(tmp_path): pdf.y = 50 pdf.cell( - txt="Link from FPDF.cell()", + text="Link from FPDF.cell()", center=True, link="https://github.com/py-pdf/fpdf2", ) @@ -25,7 +25,7 @@ def test_hyperlinks(tmp_path): text = "Link set over an arbitrary area with FPDF.link()" x, y = 20, 150 - pdf.text(x=x, y=y, txt=text) + pdf.text(x=x, y=y, text=text) width = pdf.get_string_width(text) pdf.link( x=x, @@ -48,7 +48,7 @@ def test_link_alt_text(tmp_path): pdf.add_page() pdf.set_font("helvetica", size=24) text = "py-pdf/fpdf2" - pdf.text(x=80, y=150, txt=text) + pdf.text(x=80, y=150, text=text) width = pdf.get_string_width(text) line_height = 10 pdf.link( @@ -72,7 +72,7 @@ def test_link_with_zoom_and_shift(tmp_path): pdf.cell( w=140, h=10, - txt="Link to 2nd page zoomed & shifted", + text="Link to 2nd page zoomed & shifted", border=1, align="C", link=link, @@ -80,7 +80,7 @@ def test_link_with_zoom_and_shift(tmp_path): pdf.add_page() pdf.multi_cell( pdf.epw, - txt="Lorem ipsum dolor sit amet, consectetur adipiscing elit," + text="Lorem ipsum dolor sit amet, consectetur adipiscing elit," " sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." " Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." " Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." @@ -103,7 +103,7 @@ def test_link_border(tmp_path): height = 10 x, y = 50, 150 - pdf.text(x=x, y=y, txt=text) + pdf.text(x=x, y=y, text=text) pdf.link( x=x, y=y - height, @@ -157,7 +157,7 @@ def test_inserting_link_with_no_page_number(): pdf.add_page() pdf.set_font("helvetica", size=12) with pytest.raises(ValueError): - pdf.cell(txt="Page 1", link=link) + pdf.cell(text="Page 1", link=link) def test_later_call_to_set_link(tmp_path): # v2.6.1 bug spotted in discussion 729 @@ -166,11 +166,11 @@ def test_later_call_to_set_link(tmp_path): # v2.6.1 bug spotted in discussion 7 pdf.add_page() # page 1 link_to_section1 = pdf.add_link() - pdf.cell(txt="Section 1", link=link_to_section1) + pdf.cell(text="Section 1", link=link_to_section1) pdf.add_page() # page 2 pdf.set_link(link_to_section1, page=pdf.page) - pdf.cell(txt="Section 1: Bla bla bla") + pdf.cell(text="Section 1: Bla bla bla") assert_pdf_equal(pdf, HERE / "later_call_to_set_link.pdf", tmp_path) @@ -182,7 +182,7 @@ def test_link_to_other_document(tmp_path): pdf.set_xy(80, 50) pdf.cell( - txt="Link defined with FPDF.cell", + text="Link defined with FPDF.cell", border=1, align="C", link="links.pdf", @@ -191,7 +191,7 @@ def test_link_to_other_document(tmp_path): pdf.set_y(100) pdf.multi_cell( w=pdf.epw, - txt="Link defined with FPDF.multi_cell", + text="Link defined with FPDF.multi_cell", border=1, align="C", link="links.pdf", @@ -200,7 +200,7 @@ def test_link_to_other_document(tmp_path): pdf.set_y(150) pdf.multi_cell( w=pdf.epw, - txt="Link defined with FPDF.multi_cell and markdown=True: [links.pdf](links.pdf)", + text="Link defined with FPDF.multi_cell and markdown=True: [links.pdf](links.pdf)", border=1, align="C", markdown=True, @@ -210,7 +210,7 @@ def test_link_to_other_document(tmp_path): pdf.write_html('Link defined with FPDF.write_html') text = "Link defined with FPDF.link" - pdf.text(x=80, y=250, txt=text) + pdf.text(x=80, y=250, text=text) width = pdf.get_string_width(text) pdf.link( x=80, @@ -229,13 +229,13 @@ def test_internal_links(tmp_path): pdf.add_page() pdf.y = 100 - pdf.cell(txt="Page 1", center=True) + pdf.cell(text="Page 1", center=True) pdf.add_page() pdf.set_xy(80, 50) pdf.cell( - txt="Link defined with FPDF.cell", + text="Link defined with FPDF.cell", border=1, align="C", link=pdf.add_link(page=1), @@ -244,7 +244,7 @@ def test_internal_links(tmp_path): pdf.set_y(100) pdf.multi_cell( w=pdf.epw, - txt="Link defined with FPDF.multi_cell", + text="Link defined with FPDF.multi_cell", border=1, align="C", link=pdf.add_link(page=1), @@ -253,7 +253,7 @@ def test_internal_links(tmp_path): pdf.set_y(150) pdf.multi_cell( w=pdf.epw, - txt="Link defined with FPDF.multi_cell and markdown=True: [page 1](1)", + text="Link defined with FPDF.multi_cell and markdown=True: [page 1](1)", border=1, align="C", markdown=True, @@ -263,7 +263,7 @@ def test_internal_links(tmp_path): pdf.write_html('Link defined with FPDF.write_html') text = "Link defined with FPDF.link" - pdf.text(x=80, y=250, txt=text) + pdf.text(x=80, y=250, text=text) width = pdf.get_string_width(text) pdf.link( x=80, diff --git a/test/test_mirror.py b/test/test_mirror.py index ad7f47c4b..71580ac6d 100644 --- a/test/test_mirror.py +++ b/test/test_mirror.py @@ -75,10 +75,10 @@ def test_mirror_with_angle_as_number(tmp_path): pdf.set_font("helvetica", size=50) pdf.add_page() x, y = 50, 50 - pdf.text(x, y, txt="mirror this text") + pdf.text(x, y, text="mirror this text") with pdf.mirror((x, y), 180): pdf.set_text_color(r=255, g=128, b=0) - pdf.text(x, y, txt="mirror this text") + pdf.text(x, y, text="mirror this text") assert_pdf_equal(pdf, HERE / "mirror_with_angle_as_number.pdf", tmp_path) @@ -87,19 +87,19 @@ def test_mirror_text(tmp_path): pdf.add_page() pdf.set_font("helvetica", size=12) - pdf.text(pdf.epw / 2, pdf.epw / 2, txt="mirror this text") + pdf.text(pdf.epw / 2, pdf.epw / 2, text="mirror this text") with pdf.mirror((pdf.epw / 2, pdf.eph / 2.5), "EAST"): - pdf.text(pdf.epw / 2, pdf.eph / 2, txt="mirrored text E/W") + pdf.text(pdf.epw / 2, pdf.eph / 2, text="mirrored text E/W") with pdf.mirror((pdf.epw / 2.5, pdf.eph / 2), "NORTH"): - pdf.text(pdf.epw / 2, pdf.eph / 2, txt="mirrored text N/S") + pdf.text(pdf.epw / 2, pdf.eph / 2, text="mirrored text N/S") with pdf.mirror((pdf.epw / 1.5, pdf.eph / 1.5), "NORTHWEST"): - pdf.text(pdf.epw / 2, pdf.eph / 2, txt="mirrored text NW/SE") + pdf.text(pdf.epw / 2, pdf.eph / 2, text="mirrored text NW/SE") with pdf.mirror((pdf.epw / 2.5, pdf.eph / 2.5), "NORTHEAST"): - pdf.text(pdf.epw / 2, pdf.eph / 2, txt="mirrored text NE/SW") + pdf.text(pdf.epw / 2, pdf.eph / 2, text="mirrored text NE/SW") assert_pdf_equal(pdf, HERE / "mirror_text.pdf", tmp_path) @@ -110,34 +110,34 @@ def test_mirror_cell(tmp_path): pdf.set_font("helvetica", size=12) pdf.set_fill_color(255, 255, 0) - pdf.cell(txt="cell to be mirrored repeatedly") + pdf.cell(text="cell to be mirrored repeatedly") pdf.x = pdf.l_margin with pdf.mirror((pdf.epw / 2, 0), "NORTH"): draw_mirror_line(pdf, (pdf.epw / 2, 0), "NORTH") - pdf.cell(txt="cell mirrored", fill=True) - pdf.cell(txt="cell mirrored", fill=True) - pdf.cell(txt="cell mirrored", fill=True) + pdf.cell(text="cell mirrored", fill=True) + pdf.cell(text="cell mirrored", fill=True) + pdf.cell(text="cell mirrored", fill=True) pdf.ln(40) - pdf.cell(txt="cell text 1") + pdf.cell(text="cell text 1") pdf.x = pdf.l_margin with pdf.mirror((pdf.epw / 2, pdf.eph / 4), "EAST"): draw_mirror_line(pdf, (pdf.epw / 2, pdf.eph / 4), "EAST") - pdf.cell(txt="cell text 1", fill=True) + pdf.cell(text="cell text 1", fill=True) pdf.ln(40) - pdf.cell(txt="cell text 2") + pdf.cell(text="cell text 2") pdf.x = pdf.l_margin with pdf.mirror((pdf.epw / 2, 0), "SOUTHWEST"): draw_mirror_line(pdf, (pdf.epw / 2, 0), "SOUTHWEST") - pdf.cell(txt="cell text 2", fill=True) + pdf.cell(text="cell text 2", fill=True) pdf.ln(40) - pdf.cell(txt="cell text 3") + pdf.cell(text="cell text 3") pdf.x = pdf.l_margin with pdf.mirror((pdf.epw / 2, pdf.eph / 4), "NORTHEAST"): draw_mirror_line(pdf, (pdf.epw / 2, pdf.eph / 4), "NORTHEAST") - pdf.cell(txt="cell text 3", fill=True, border=1) + pdf.cell(text="cell text 3", fill=True, border=1) pdf.ln(40) assert_pdf_equal(pdf, HERE / "mirror_cell.pdf", tmp_path) @@ -149,32 +149,32 @@ def test_mirror_multi_cell(tmp_path): pdf.set_font("helvetica", size=12) pdf.set_fill_color(255, 255, 0) - pdf.multi_cell(w=50, txt=LOREM_IPSUM[:200]) + pdf.multi_cell(w=50, text=LOREM_IPSUM[:200]) pdf.x = pdf.l_margin pdf.y = pdf.t_margin with pdf.mirror((pdf.epw / 2, pdf.eph / 4), "NORTHEAST"): draw_mirror_line(pdf, (pdf.epw / 2, pdf.eph / 4), "NORTHEAST") - pdf.multi_cell(w=50, txt=LOREM_IPSUM[:200], fill=True) + pdf.multi_cell(w=50, text=LOREM_IPSUM[:200], fill=True) pdf.ln(20) prev_y = pdf.y - pdf.multi_cell(w=100, txt=LOREM_IPSUM[:200]) + pdf.multi_cell(w=100, text=LOREM_IPSUM[:200]) pdf.x = pdf.l_margin pdf.y = prev_y with pdf.mirror((0, pdf.eph / 2), "EAST"): draw_mirror_line(pdf, (0, pdf.eph / 2), "EAST") - pdf.multi_cell(w=100, txt=LOREM_IPSUM[:200], fill=True) + pdf.multi_cell(w=100, text=LOREM_IPSUM[:200], fill=True) pdf.ln(150) prev_y = pdf.y - pdf.multi_cell(w=120, txt=LOREM_IPSUM[:120]) + pdf.multi_cell(w=120, text=LOREM_IPSUM[:120]) pdf.x = pdf.l_margin pdf.y = prev_y with pdf.mirror((pdf.epw / 2, pdf.eph), "SOUTH"): draw_mirror_line(pdf, (pdf.epw / 2, pdf.eph), "SOUTH") - pdf.multi_cell(w=120, txt=LOREM_IPSUM[:120], fill=True, border=1) + pdf.multi_cell(w=120, text=LOREM_IPSUM[:120], fill=True, border=1) assert_pdf_equal(pdf, HERE / "mirror_multi_cell.pdf", tmp_path) diff --git a/test/test_positioning.py b/test/test_positioning.py index 95ad794f9..55f8f0700 100644 --- a/test/test_positioning.py +++ b/test/test_positioning.py @@ -76,7 +76,7 @@ def test_ln_by_lasth(): # ln() uses self._lasth after writing some text. pdf.set_font("helvetica", size=16) pdf.x += 20 - pdf.cell(txt="something") + pdf.cell(text="something") h = pdf.font_size # last *used* font height, no cell height given prev_y = pdf.y pdf.ln(h) @@ -102,7 +102,7 @@ def test_ln_by_lasth(): # cell(h=x) should set _lasth to that h = 20 pdf.x += 33 - pdf.cell(h=h, txt="something") + pdf.cell(h=h, text="something") prev_y = pdf.y pdf.ln() assert math.isclose( diff --git a/test/test_recorder.py b/test/test_recorder.py index 3adecbb7e..65a677e2a 100644 --- a/test/test_recorder.py +++ b/test/test_recorder.py @@ -12,7 +12,7 @@ def init_pdf(): pdf.set_creation_date(EPOCH) pdf.set_font("helvetica", size=24) pdf.add_page() - pdf.cell(w=pdf.epw, h=10, txt="Hello fpdf2!", align="C") + pdf.cell(w=pdf.epw, h=10, text="Hello fpdf2!", align="C") return pdf @@ -22,7 +22,7 @@ def test_recorder_rewind_ok(tmp_path): expected = recorder.output() # close the document as a side-effect recorder.rewind() # in order to un-close the document recorder.add_page() - recorder.cell(w=recorder.epw, h=10, txt="Hello again!", align="C") + recorder.cell(w=recorder.epw, h=10, text="Hello again!", align="C") recorder.rewind() assert_pdf_equal(recorder, expected, tmp_path) @@ -33,7 +33,7 @@ def test_recorder_rewind_twice_ok(tmp_path): expected = recorder.output() # close the document as a side-effect recorder.rewind() # in order to un-close the document recorder.add_page() - recorder.cell(w=recorder.epw, h=10, txt="Hello again!", align="C") + recorder.cell(w=recorder.epw, h=10, text="Hello again!", align="C") recorder.rewind() assert_pdf_equal(recorder, expected, tmp_path) @@ -41,7 +41,7 @@ def test_recorder_rewind_twice_ok(tmp_path): def test_recorder_replay_ok(tmp_path): recorder = FPDFRecorder(init_pdf()) recorder.add_page() - recorder.cell(w=recorder.epw, h=10, txt="Hello again!", align="C") + recorder.cell(w=recorder.epw, h=10, text="Hello again!", align="C") expected = recorder.output() recorder.rewind() recorder.replay() @@ -58,7 +58,7 @@ def test_recorder_preserve_pages_count(): pdf.set_y(250) assert pdf.pages_count == 1 with pdf.offset_rendering() as recorder: - pdf.multi_cell(txt=LOREM_IPSUM, w=pdf.epw) + pdf.multi_cell(text=LOREM_IPSUM, w=pdf.epw) assert pdf.pages_count == 2 assert recorder.page_break_triggered assert pdf.pages_count == 1 @@ -69,11 +69,11 @@ def test_recorder_with_ttf_font(tmp_path): pdf.add_font(fname=str(HERE / "fonts" / "Roboto-Regular.ttf")) pdf.set_font("Roboto-Regular", size=64) pdf.add_page() - pdf.cell(txt="Hello!", align="C") + pdf.cell(text="Hello!", align="C") recorder = FPDFRecorder(pdf) expected = recorder.output() # close the document as a side-effect recorder.rewind() # in order to un-close the document recorder.add_page() - recorder.cell(w=recorder.epw, h=10, txt="Hello again!", align="C") + recorder.cell(w=recorder.epw, h=10, text="Hello again!", align="C") recorder.rewind() assert_pdf_equal(recorder, expected, tmp_path) diff --git a/test/test_skew.py b/test/test_skew.py index 84424d1d8..10eaaee15 100644 --- a/test/test_skew.py +++ b/test/test_skew.py @@ -29,16 +29,16 @@ def test_skew_text(tmp_path): doc.add_page() doc.set_font("helvetica", size=12) with doc.skew(0, 20, 20, 20): - doc.text(20, 20, txt="text skewed on the y-axis") + doc.text(20, 20, text="text skewed on the y-axis") with doc.skew(0, -20, 20, 60): - doc.text(20, 60, txt="text skewed on the y-axis (negative)") - doc.text(20, 100, txt="text skewed on the y-axis (negative) - line 2") + doc.text(20, 60, text="text skewed on the y-axis (negative)") + doc.text(20, 100, text="text skewed on the y-axis (negative) - line 2") with doc.skew(20, 0, 20, 140): - doc.text(20, 140, txt="text skewed on the x-axis") + doc.text(20, 140, text="text skewed on the x-axis") with doc.skew(-20, 0, 20, 180): - doc.text(20, 180, txt="text skewed on the x-axis (negative)") + doc.text(20, 180, text="text skewed on the x-axis (negative)") with doc.skew(89, 0, 20, 220): - doc.text(20, 220, txt="some extreme skewing") + doc.text(20, 220, text="some extreme skewing") assert_pdf_equal(doc, HERE / "skew_text.pdf", tmp_path) @@ -48,19 +48,19 @@ def test_cell_skew_text(tmp_path): doc.set_font("helvetica", size=12) doc.ln(40) with doc.skew(0, 20): - doc.cell(txt="text skewed on the y-axis") + doc.cell(text="text skewed on the y-axis") doc.ln(40) with doc.skew(0, -20): - doc.cell(txt="text skewed on the y-axis (negative)") + doc.cell(text="text skewed on the y-axis (negative)") doc.ln(40) with doc.skew(20, 0): - doc.cell(txt="text skewed on the x-axis") + doc.cell(text="text skewed on the x-axis") doc.ln(40) with doc.skew(-20, 0): - doc.cell(txt="text skewed on the x-axis (negative)") + doc.cell(text="text skewed on the x-axis (negative)") doc.ln(40) with doc.skew(89, 0): - doc.cell(txt="some extreme skewing") + doc.cell(text="some extreme skewing") doc.ln(40) assert_pdf_equal(doc, HERE / "cell_skew_text.pdf", tmp_path) @@ -72,11 +72,11 @@ def test_multi_cell_skew_text(tmp_path): pdf.set_font("Helvetica", "", 8) pdf.set_fill_color(255, 255, 0) with pdf.skew(20, 0): - pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], fill=True) + pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], fill=True) pdf.ln(60) with pdf.skew(0, 20): - pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], fill=True) + pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], fill=True) pdf.ln(60) with pdf.skew(20, 20): - pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], fill=True) + pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], fill=True) assert_pdf_equal(pdf, HERE / "multi_cell_skew_text.pdf", tmp_path) diff --git a/test/test_transitions.py b/test/test_transitions.py index 257d31a96..8be76f126 100644 --- a/test/test_transitions.py +++ b/test/test_transitions.py @@ -25,29 +25,29 @@ def test_transitions(tmp_path): pdf = FPDF() pdf.set_font("Helvetica", size=120) pdf.add_page() - pdf.text(x=40, y=150, txt="Page 0") + pdf.text(x=40, y=150, text="Page 0") pdf.add_page(transition=SplitTransition("V", "O")) - pdf.text(x=40, y=150, txt="Page 1") + pdf.text(x=40, y=150, text="Page 1") pdf.add_page(transition=BlindsTransition("H")) - pdf.text(x=40, y=150, txt="Page 2") + pdf.text(x=40, y=150, text="Page 2") pdf.add_page(transition=BoxTransition("I")) - pdf.text(x=40, y=150, txt="Page 3") + pdf.text(x=40, y=150, text="Page 3") pdf.add_page(transition=WipeTransition(90)) - pdf.text(x=40, y=150, txt="Page 4") + pdf.text(x=40, y=150, text="Page 4") pdf.add_page(transition=DissolveTransition()) - pdf.text(x=40, y=150, txt="Page 5") + pdf.text(x=40, y=150, text="Page 5") pdf.add_page(transition=GlitterTransition(315)) - pdf.text(x=40, y=150, txt="Page 6") + pdf.text(x=40, y=150, text="Page 6") pdf.add_page(transition=FlyTransition("H")) - pdf.text(x=40, y=150, txt="Page 7") + pdf.text(x=40, y=150, text="Page 7") pdf.add_page(transition=PushTransition(270)) - pdf.text(x=40, y=150, txt="Page 8") + pdf.text(x=40, y=150, text="Page 8") pdf.add_page(transition=CoverTransition(270)) - pdf.text(x=40, y=150, txt="Page 9") + pdf.text(x=40, y=150, text="Page 9") pdf.add_page(transition=UncoverTransition(270)) - pdf.text(x=40, y=150, txt="Page 10") + pdf.text(x=40, y=150, text="Page 10") pdf.add_page(transition=FadeTransition()) - pdf.text(x=40, y=150, txt="Page 11") + pdf.text(x=40, y=150, text="Page 11") assert_pdf_equal(pdf, HERE / "transitions.pdf", tmp_path) diff --git a/test/text/test_cell.py b/test/text/test_cell.py index 26061d0d1..3d69b18f8 100644 --- a/test/text/test_cell.py +++ b/test/text/test_cell.py @@ -41,7 +41,7 @@ def test_ln_positioning_and_page_breaking_for_cell(tmp_path): border=1, new_x="LEFT", new_y="NEXT", - txt=text[i * 100 : i * 100 + 99], + text=text[i * 100 : i * 100 + 99], ) assert_pdf_equal( @@ -53,10 +53,10 @@ def test_cell_ln_0(tmp_path): doc = FPDF() doc.add_page() doc.set_font("helvetica", size=TEXT_SIZE) - doc.cell(w=45, h=LINE_HEIGHT, border=1, txt="Lorem") - doc.cell(w=45, h=LINE_HEIGHT, border=1, txt="ipsum") - doc.cell(w=45, h=LINE_HEIGHT, border=1, txt="Ut") - doc.cell(w=45, h=LINE_HEIGHT, border=1, txt="nostrud") + doc.cell(w=45, h=LINE_HEIGHT, border=1, text="Lorem") + doc.cell(w=45, h=LINE_HEIGHT, border=1, text="ipsum") + doc.cell(w=45, h=LINE_HEIGHT, border=1, text="Ut") + doc.cell(w=45, h=LINE_HEIGHT, border=1, text="nostrud") assert_pdf_equal(doc, HERE / "ln_0.pdf", tmp_path) @@ -69,19 +69,19 @@ def test_cell_ln_1(tmp_path): doc.add_page() doc.set_font("helvetica", size=TEXT_SIZE) with pytest.warns(DeprecationWarning) as record: - doc.cell(w=100, h=LINE_HEIGHT, border=1, txt="Lorem ipsum", ln=1) + doc.cell(w=100, h=LINE_HEIGHT, border=1, text="Lorem ipsum", ln=1) assert len(record) == 1 assert record[0].filename == __file__ - doc.cell(w=100, h=LINE_HEIGHT, border=1, txt="Ut nostrud irure") + doc.cell(w=100, h=LINE_HEIGHT, border=1, text="Ut nostrud irure") assert_pdf_equal(doc, HERE / "ln_1.pdf", tmp_path) doc = FPDF() doc.add_page() doc.set_font("helvetica", size=TEXT_SIZE) - doc.cell(w=100, h=LINE_HEIGHT, border=1, txt="Lorem ipsum") + doc.cell(w=100, h=LINE_HEIGHT, border=1, text="Lorem ipsum") doc.ln() - doc.cell(w=100, h=LINE_HEIGHT, border=1, txt="Ut nostrud irure") + doc.cell(w=100, h=LINE_HEIGHT, border=1, text="Ut nostrud irure") assert_pdf_equal(doc, HERE / "ln_1.pdf", tmp_path) @@ -120,7 +120,7 @@ def test_cell_without_font_set(): pdf = FPDF() pdf.add_page() with pytest.raises(FPDFException) as error: - pdf.cell(txt="Hello World!") + pdf.cell(text="Hello World!") expected_msg = "No font set, you need to call set_font() beforehand" assert str(error.value) == expected_msg @@ -129,9 +129,9 @@ def test_cell_without_w_nor_h(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=16) - pdf.cell(txt="Lorem ipsum", border=1) + pdf.cell(text="Lorem ipsum", border=1) pdf.set_font_size(80) - pdf.cell(txt="Lorem ipsum", border=1) + pdf.cell(text="Lorem ipsum", border=1) assert_pdf_equal(pdf, HERE / "cell_without_w_nor_h.pdf", tmp_path) @@ -151,7 +151,7 @@ def test_cell_centering(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=60) - pdf.cell(txt="Lorem ipsum", border=1, center=True) + pdf.cell(text="Lorem ipsum", border=1, center=True) assert_pdf_equal(pdf, HERE / "cell_centering.pdf", tmp_path) @@ -159,7 +159,7 @@ def test_cell_centering_and_align_x(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=16) - pdf.cell(txt="Lorem ipsum", border=1, center=True, align="X") + pdf.cell(text="Lorem ipsum", border=1, center=True, align="X") pdf.set_draw_color(r=0, g=255, b=0) pdf.line(pdf.w / 2, 0, pdf.w / 2, pdf.h) assert_pdf_equal(pdf, HERE / "cell_centering_and_align_x.pdf", tmp_path) @@ -169,7 +169,7 @@ def test_cell_markdown(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=60) - pdf.cell(txt="**Lorem** __Ipsum__ --dolor--", markdown=True) + pdf.cell(text="**Lorem** __Ipsum__ --dolor--", markdown=True) assert_pdf_equal(pdf, HERE / "cell_markdown.pdf", tmp_path) @@ -180,7 +180,7 @@ def test_cell_markdown_with_ttf_fonts(tmp_path): pdf.add_font("Roboto", "B", FONTS_DIR / "Roboto-Bold.ttf") pdf.add_font("Roboto", "I", FONTS_DIR / "Roboto-Italic.ttf") pdf.set_font("Roboto", size=60) - pdf.cell(txt="**Lorem** __Ipsum__ --dolor--", markdown=True) + pdf.cell(text="**Lorem** __Ipsum__ --dolor--", markdown=True) assert_pdf_equal(pdf, HERE / "cell_markdown_with_ttf_fonts.pdf", tmp_path) @@ -190,7 +190,7 @@ def test_cell_markdown_missing_ttf_font(): pdf.add_font(fname=FONTS_DIR / "Roboto-Regular.ttf") pdf.set_font("Roboto-Regular", size=60) with pytest.raises(FPDFException) as error: - pdf.cell(txt="**Lorem Ipsum**", markdown=True) + pdf.cell(text="**Lorem Ipsum**", markdown=True) expected_msg = "Undefined font: roboto-regularB - Use built-in fonts or FPDF.add_font() beforehand" assert str(error.value) == expected_msg @@ -199,12 +199,12 @@ def test_cell_markdown_bleeding(tmp_path): # issue 241 pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=60) - pdf.cell(txt="--Lorem Ipsum dolor--", markdown=True, new_x="LMARGIN", new_y="NEXT") - pdf.cell(txt="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT") - pdf.cell(txt="**Lorem Ipsum dolor**", markdown=True, new_x="LMARGIN", new_y="NEXT") - pdf.cell(txt="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT") - pdf.cell(txt="__Lorem Ipsum dolor__", markdown=True, new_x="LMARGIN", new_y="NEXT") - pdf.cell(txt="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT") + pdf.cell(text="--Lorem Ipsum dolor--", markdown=True, new_x="LMARGIN", new_y="NEXT") + pdf.cell(text="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT") + pdf.cell(text="**Lorem Ipsum dolor**", markdown=True, new_x="LMARGIN", new_y="NEXT") + pdf.cell(text="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT") + pdf.cell(text="__Lorem Ipsum dolor__", markdown=True, new_x="LMARGIN", new_y="NEXT") + pdf.cell(text="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT") assert_pdf_equal(pdf, HERE / "cell_markdown_bleeding.pdf", tmp_path) @@ -274,15 +274,15 @@ def test_cell_curfont_leak(tmp_path): # issue #475 pdf.add_font("Roboto", style="B", fname=FONTS_DIR / "Roboto-Bold.ttf") with pdf.local_context(): pdf.set_font("Roboto", "B", 10) - pdf.cell(txt="ABCDEFGH", new_x="LEFT", new_y="NEXT") + pdf.cell(text="ABCDEFGH", new_x="LEFT", new_y="NEXT") pdf.set_font("Roboto", "", 10) - pdf.cell(txt="IJKLMNOP", new_x="LEFT", new_y="NEXT") + pdf.cell(text="IJKLMNOP", new_x="LEFT", new_y="NEXT") with pdf.local_context(): pdf.set_font("Roboto", "B", 10) - pdf.cell(txt="QRSTUVW", new_x="LEFT", new_y="NEXT") + pdf.cell(text="QRSTUVW", new_x="LEFT", new_y="NEXT") pdf.set_font("Roboto", "", 10) - pdf.cell(txt="XYZ012abc,-", new_x="LEFT", new_y="NEXT") - pdf.cell(txt="3,7E-05", new_x="LEFT", new_y="NEXT") + pdf.cell(text="XYZ012abc,-", new_x="LEFT", new_y="NEXT") + pdf.cell(text="3,7E-05", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "cell_curfont_leak.pdf", tmp_path) @@ -292,22 +292,33 @@ def test_cell_lasth(tmp_path): # issue #601 pdf.add_page() pdf.set_font("helvetica", size=18) pdf.set_fill_color(255, 255, 0) - pdf.cell(w=100, txt="Hello world", fill=True) + pdf.cell(w=100, text="Hello world", fill=True) pdf.ln() assert pdf._lasth == 6.35, f"pdf._lasth ({pdf._lasth}) != 5.35" pdf.set_fill_color(255, 0, 255) - pdf.cell(w=100, txt="Hello world", h=50, fill=True) + pdf.cell(w=100, text="Hello world", h=50, fill=True) pdf.ln() assert pdf._lasth == 50, f"pdf._lasth ({pdf._lasth}) != 50 after cell(h=50)" pdf.set_fill_color(0, 255, 255) - pdf.cell(w=100, txt="Hello world", fill=True) - pdf.cell(w=100, txt="") + pdf.cell(w=100, text="Hello world", fill=True) + pdf.cell(w=100, text="") pdf.ln() assert pdf._lasth == 6.35, f"pdf._lasth ({pdf._lasth}) != 5.35 after empty cell" - pdf.cell(w=100, txt="Hello world", border=True) + pdf.cell(w=100, text="Hello world", border=True) assert_pdf_equal(pdf, HERE / "cell_lasth.pdf", tmp_path) +def test_cell_deprecated_txt_arg(): + pdf = FPDF() + pdf.add_page() + pdf.set_font("Helvetica", size=TEXT_SIZE) + with pytest.warns( + DeprecationWarning, match='The parameter "txt" has been renamed to "text"' + ): + # pylint: disable=unexpected-keyword-arg + pdf.cell(txt="Lorem ipsum Ut nostrud irure") + + @ensure_exec_time_below(seconds=22) @ensure_rss_memory_below(mib=1) def test_cell_speed_with_long_text(): # issue #907 diff --git a/test/text/test_multi_cell.py b/test/text/test_multi_cell.py index 316f7ad6f..d1124a300 100644 --- a/test/text/test_multi_cell.py +++ b/test/text/test_multi_cell.py @@ -25,7 +25,7 @@ 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) + pdf.multi_cell(text="Hello world!", w=pdf.epw) assert str(error.value) == "No font set, you need to call set_font() beforehand" @@ -38,7 +38,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=144, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[:29], + text=LOREM_IPSUM[:29], new_x="RIGHT", new_y="NEXT", ) @@ -46,7 +46,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=180, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[29:60], + text=LOREM_IPSUM[29:60], new_x="LEFT", new_y="NEXT", ) @@ -54,7 +54,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=144, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[60:90], + text=LOREM_IPSUM[60:90], new_x="LMARGIN", new_y="NEXT", ) @@ -62,7 +62,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=72 * 5, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[0:30], + text=LOREM_IPSUM[0:30], new_x="LMARGIN", new_y="NEXT", ) @@ -70,7 +70,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=72 * 5, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[31:60], + text=LOREM_IPSUM[31:60], new_x="LMARGIN", new_y="NEXT", ) @@ -78,7 +78,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=72 * 5, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[61:90], + text=LOREM_IPSUM[61:90], new_x="LMARGIN", new_y="NEXT", ) @@ -86,7 +86,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=72 * 5, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[91:120], + text=LOREM_IPSUM[91:120], new_x="LMARGIN", new_y="NEXT", ) @@ -96,7 +96,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=144, h=LINE_HEIGHT, border=1, - txt=LOREM_IPSUM[30:90], + text=LOREM_IPSUM[30:90], new_x="LEFT", new_y="NEXT", ) @@ -104,7 +104,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=72 * 2, h=LINE_HEIGHT, border=1, - txt="Lorem ipsum", + text="Lorem ipsum", new_x="LEFT", new_y="NEXT", ) @@ -112,7 +112,7 @@ def test_ln_positioning_and_page_breaking_for_multicell(tmp_path): w=72 * 2, h=LINE_HEIGHT, border=1, - txt="Lorem ipsum", + text="Lorem ipsum", new_x="LEFT", new_y="NEXT", ) @@ -127,10 +127,10 @@ def test_multi_cell_border_thickness(tmp_path): doc.add_page() doc.set_font("helvetica", size=TEXT_SIZE) doc.set_line_width(3) - doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, txt="Lorem") - doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, txt="ipsum") - doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, txt="Ut") - doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, txt="nostrud") + doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="Lorem") + doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="ipsum") + doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="Ut") + doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="nostrud") assert_pdf_equal(doc, HERE / "multi_cell_border_thickness.pdf", tmp_path) @@ -142,11 +142,11 @@ def test_multi_cell_ln_1(tmp_path): w=100, h=LINE_HEIGHT, border=1, - txt="Lorem ipsum", + text="Lorem ipsum", new_x="LMARGIN", new_y="NEXT", ) - doc.multi_cell(w=100, h=LINE_HEIGHT, border=1, txt="Ut nostrud irure") + doc.multi_cell(w=100, h=LINE_HEIGHT, border=1, text="Ut nostrud irure") assert_pdf_equal(doc, HERE / "multi_cell_ln_1.pdf", tmp_path) @@ -155,14 +155,14 @@ def test_multi_cell_ln_3(tmp_path): doc.add_page() doc.set_font("helvetica", size=TEXT_SIZE) doc.multi_cell( - w=45, h=LINE_HEIGHT, border=1, txt="Lorem", new_x="RIGHT", new_y="TOP" + w=45, h=LINE_HEIGHT, border=1, text="Lorem", new_x="RIGHT", new_y="TOP" ) doc.multi_cell( - w=45, h=LINE_HEIGHT, border=1, txt="ipsum", new_x="RIGHT", new_y="TOP" + w=45, h=LINE_HEIGHT, border=1, text="ipsum", new_x="RIGHT", new_y="TOP" ) - doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, txt="Ut", new_x="RIGHT", new_y="TOP") + doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="Ut", new_x="RIGHT", new_y="TOP") doc.multi_cell( - w=45, h=LINE_HEIGHT, border=1, txt="nostrud", new_x="RIGHT", new_y="TOP" + w=45, h=LINE_HEIGHT, border=1, text="nostrud", new_x="RIGHT", new_y="TOP" ) assert_pdf_equal(doc, HERE / "multi_cell_ln_3.pdf", tmp_path) @@ -231,9 +231,9 @@ def test_multi_cell_table_with_max_line_height(tmp_path): # issue 589 " Tip: If you love spicy dishes, add a bit of our Red Silk Chili" " (not included) with the gaozis" ) - pdf.multi_cell(w=120, h=50, txt=text, max_line_height=6, border=True) + pdf.multi_cell(w=120, h=50, text=text, max_line_height=6, border=True) pdf.ln() - pdf.multi_cell(w=120, h=18, txt=text, max_line_height=6, border=True) + pdf.multi_cell(w=120, h=18, text=text, max_line_height=6, border=True) assert_pdf_equal(pdf, HERE / "multi_cell_table_with_max_line_height.pdf", tmp_path) @@ -243,7 +243,7 @@ def test_multi_cell_justified_with_unicode_font(tmp_path): # issue 118 pdf.add_font(fname=FONTS_DIR / "DejaVuSans.ttf") pdf.set_font("DejaVuSans", size=14) text = 'Justified line containing "()" that is long enough to trigger wrapping and a line jump' - pdf.multi_cell(w=0, h=8, txt=text, new_x="LMARGIN", new_y="NEXT") + pdf.multi_cell(w=0, h=8, text=text, new_x="LMARGIN", new_y="NEXT") assert_pdf_equal(pdf, HERE / "multi_cell_justified_with_unicode_font.pdf", tmp_path) @@ -260,7 +260,9 @@ def test_multi_cell_split_only(): # discussion 314 with pytest.warns( DeprecationWarning, match='The parameter "split_only" is deprecated.' ) as record: - assert pdf.multi_cell(w=0, h=LINE_HEIGHT, txt=text, split_only=True) == expected + assert ( + pdf.multi_cell(w=0, h=LINE_HEIGHT, text=text, split_only=True) == expected + ) assert len(record) == 1 assert record[0].filename == __file__ @@ -270,10 +272,10 @@ def test_multi_cell_with_empty_contents(tmp_path): # issue 349 pdf.add_page() pdf.set_font("helvetica", size=10) for i in range(1, 5): - pdf.multi_cell(20, new_x="RIGHT", new_y="TOP", txt=str(i)) + pdf.multi_cell(20, new_x="RIGHT", new_y="TOP", text=str(i)) pdf.ln(10) for i in range(1, 5): - pdf.multi_cell(20, new_x="RIGHT", new_y="TOP", txt=str(i) if i > 2 else "") + pdf.multi_cell(20, new_x="RIGHT", new_y="TOP", text=str(i) if i > 2 else "") assert_pdf_equal(pdf, HERE / "multi_cell_with_empty_contents.pdf", tmp_path) @@ -318,7 +320,7 @@ def test_multi_cell_j_paragraphs(tmp_path): # issue 364 J’ai appelé les bourreaux pour, en périssant, mordre la crosse de leurs fusils. J’ai appelé les fléaux, pour m’étouffer avec le sable, le sang. Le malheur a été mon dieu. Je me suis allongé dans la boue. Je me suis séché à l’air du crime. Et j’ai joué de bons tours à la folie.""" - pdf.multi_cell(w=0, h=None, txt=text, align="J") + pdf.multi_cell(w=0, h=None, text=text, align="J") assert_pdf_equal(pdf, HERE / "multi_cell_j_paragraphs.pdf", tmp_path) @@ -329,16 +331,16 @@ def test_multi_cell_font_leakage(tmp_path): # Issue #359 pdf.add_font("Roboto", style="B", fname=FONTS_DIR / "Roboto-Bold.ttf") pdf.set_font("Roboto", "", 12) - pdf.multi_cell(0, txt="xyz **abcde**", markdown=True) + pdf.multi_cell(0, text="xyz **abcde**", markdown=True) pdf.ln() pdf.set_font("Roboto", "", 12) - pdf.multi_cell(0, txt="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + pdf.multi_cell(0, text="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") pdf.ln() pdf.ln() - pdf.multi_cell(0, txt="xyz **abcde** ", markdown=True) + pdf.multi_cell(0, text="xyz **abcde** ", markdown=True) pdf.ln() pdf.set_font("Roboto", "", 12) - pdf.multi_cell(0, txt="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + pdf.multi_cell(0, text="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") assert_pdf_equal(pdf, HERE / "multi_cell_font_leakage.pdf", tmp_path) @@ -346,19 +348,19 @@ def test_multi_cell_with_zero_horizontal_space(): # issue #389 pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", "", 10) - pdf.multi_cell(w=0, h=5, txt="test") + pdf.multi_cell(w=0, h=5, text="test") with pytest.raises(FPDFException): - pdf.multi_cell(w=0, h=5, txt="test") + pdf.multi_cell(w=0, h=5, text="test") def test_multi_cell_with_limited_horizontal_space(): # issue #389 pdf = FPDF() pdf.add_page() pdf.set_font("Helvetica", "", 10) - pdf.multi_cell(w=pdf.epw - 2 * pdf.c_margin - 1, h=5, txt="test") + pdf.multi_cell(w=pdf.epw - 2 * pdf.c_margin - 1, h=5, text="test") assert pdf.x == pdf.l_margin + pdf.epw - 2 * pdf.c_margin - 1 with pytest.raises(FPDFException): - pdf.multi_cell(w=0, h=5, txt="test") + pdf.multi_cell(w=0, h=5, text="test") def test_multi_cell_trailing_nl(tmp_path): # issue #455 @@ -368,11 +370,11 @@ def test_multi_cell_trailing_nl(tmp_path): # issue #455 pdf.set_font("Times", size=16) lines = ["Hello\n", "Sweet\n", "World\n"] for line in lines: - pdf.multi_cell(200, txt=line) - pdf.cell(txt="end_mmc") + pdf.multi_cell(200, text=line) + pdf.cell(text="end_mmc") pdf.ln(50) - pdf.multi_cell(200, txt="".join(lines)) - pdf.cell(txt="end_mc") + pdf.multi_cell(200, text="".join(lines)) + pdf.cell(text="end_mc") assert_pdf_equal(pdf, HERE / "multi_cell_trailing_nl.pdf", tmp_path) @@ -382,20 +384,20 @@ def test_multi_cell_font_stretching(tmp_path): # issue #478 # built-in font pdf.set_font("Helvetica", "", 8) pdf.set_fill_color(255, 255, 0) - pdf.multi_cell(w=50, txt=LOREM_IPSUM[:100], new_x="LEFT", fill=True) + pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True) pdf.ln() pdf.set_stretching(150) - pdf.multi_cell(w=50, txt=LOREM_IPSUM[:100], new_x="LEFT", fill=True) + pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True) pdf.ln() # unicode font pdf.set_stretching(100) pdf.add_font(fname=FONTS_DIR / "DroidSansFallback.ttf") pdf.set_font("DroidSansFallback", size=8) pdf.set_fill_color(255, 255, 0) - pdf.multi_cell(w=50, txt=LOREM_IPSUM[:100], new_x="LEFT", fill=True) + pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True) pdf.ln() pdf.set_stretching(150) - pdf.multi_cell(w=50, txt=LOREM_IPSUM[:100], new_x="LEFT", fill=True) + pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True) assert_pdf_equal(pdf, HERE / "multi_cell_font_stretching.pdf", tmp_path) @@ -405,20 +407,20 @@ def test_multi_cell_char_spacing(tmp_path): # issue #489 # built-in font pdf.set_font("Helvetica", "", 8) pdf.set_fill_color(255, 255, 0) - pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True) + pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True) pdf.ln() pdf.set_char_spacing(10) - pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True) + pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True) pdf.ln() # unicode font pdf.set_char_spacing(0) pdf.add_font(fname=FONTS_DIR / "DroidSansFallback.ttf") pdf.set_font("DroidSansFallback", size=8) pdf.set_fill_color(255, 255, 0) - pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True) + pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True) pdf.ln() pdf.set_char_spacing(10) - pdf.multi_cell(w=150, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True) + pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True) assert_pdf_equal(pdf, HERE / "multi_cell_char_spacing.pdf", tmp_path) @@ -427,17 +429,17 @@ def test_multi_cell_char_wrap(tmp_path): # issue #649 pdf.add_page() pdf.set_font("Helvetica", "", 10) pdf.set_fill_color(255, 255, 0) - pdf.multi_cell(w=50, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True) + pdf.multi_cell(w=50, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True) pdf.ln() pdf.multi_cell( - w=50, txt=LOREM_IPSUM[:200], new_x="LEFT", fill=True, wrapmode="CHAR" + w=50, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True, wrapmode="CHAR" ) pdf.ln() pdf.set_font("Courier", "", 10) txt = " " + "abcdefghijklmnopqrstuvwxyz" * 3 - pdf.multi_cell(w=50, txt=txt, new_x="LEFT", fill=True, align="L") + pdf.multi_cell(w=50, text=txt, new_x="LEFT", fill=True, align="L") pdf.ln() - pdf.multi_cell(w=50, txt=txt, new_x="LEFT", fill=True, align="L", wrapmode="CHAR") + pdf.multi_cell(w=50, text=txt, new_x="LEFT", fill=True, align="L", wrapmode="CHAR") assert_pdf_equal(pdf, HERE / "multi_cell_char_wrap.pdf", tmp_path) @@ -445,7 +447,7 @@ def test_multi_cell_centering(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=16) - pdf.multi_cell(w=120, txt=LOREM_IPSUM, border=1, center=True) + pdf.multi_cell(w=120, text=LOREM_IPSUM, border=1, center=True) assert_pdf_equal(pdf, HERE / "multi_cell_centering.pdf", tmp_path) @@ -454,7 +456,7 @@ def test_multi_cell_align_x(tmp_path): pdf.add_page() pdf.set_font("Times", size=16) pdf.set_x(140) - pdf.multi_cell(w=120, txt=LOREM_IPSUM, border=1, align="X") + pdf.multi_cell(w=120, text=LOREM_IPSUM, border=1, align="X") pdf.set_draw_color(r=0, g=255, b=0) pdf.line(140, 0, 140, pdf.h) assert_pdf_equal(pdf, HERE / "multi_cell_align_x.pdf", tmp_path) @@ -464,7 +466,18 @@ def test_multi_cell_centering_and_align_x(tmp_path): pdf = FPDF() pdf.add_page() pdf.set_font("Times", size=16) - pdf.multi_cell(w=120, txt=LOREM_IPSUM, border=1, center=True, align="X") + pdf.multi_cell(w=120, text=LOREM_IPSUM, border=1, center=True, align="X") pdf.set_draw_color(r=0, g=255, b=0) pdf.line(pdf.w / 2, 0, pdf.w / 2, pdf.h) assert_pdf_equal(pdf, HERE / "multi_cell_centering_and_align_x.pdf", tmp_path) + + +def test_multi_cell_deprecated_txt_arg(): + pdf = FPDF() + pdf.add_page() + pdf.set_font("Helvetica", size=TEXT_SIZE) + with pytest.warns( + DeprecationWarning, match='The parameter "txt" has been renamed to "text"' + ): + # pylint: disable=unexpected-keyword-arg + pdf.multi_cell(w=0, txt="Lorem ipsum Ut nostrud irure") diff --git a/test/text/test_multi_cell_markdown.py b/test/text/test_multi_cell_markdown.py index 5044a7705..d042dd2e2 100644 --- a/test/text/test_multi_cell_markdown.py +++ b/test/text/test_multi_cell_markdown.py @@ -18,10 +18,10 @@ def test_multi_cell_markdown(tmp_path): " sed do eiusmod __tempor incididunt__ ut labore et dolore --magna aliqua--." ) pdf.multi_cell( - w=pdf.epw, txt=text, markdown=True + w=pdf.epw, text=text, markdown=True ) # This is tricky to get working well pdf.ln() - pdf.multi_cell(w=pdf.epw, txt=text, markdown=True, align="L") + pdf.multi_cell(w=pdf.epw, text=text, markdown=True, align="L") assert_pdf_equal(pdf, HERE / "multi_cell_markdown.pdf", tmp_path) @@ -37,10 +37,10 @@ def test_multi_cell_markdown_with_ttf_fonts(tmp_path): " eiusmod __tempor incididunt__ ut labore et dolore --magna aliqua--." ) pdf.multi_cell( - w=pdf.epw, txt=text, markdown=True + w=pdf.epw, text=text, markdown=True ) # This is tricky to get working well pdf.ln() - pdf.multi_cell(w=pdf.epw, txt=text, markdown=True, align="L") + pdf.multi_cell(w=pdf.epw, text=text, markdown=True, align="L") assert_pdf_equal(pdf, HERE / "multi_cell_markdown_with_ttf_fonts.pdf", tmp_path) @@ -50,7 +50,7 @@ def test_multi_cell_markdown_missing_ttf_font(): pdf.add_font(fname=FONTS_DIR / "Roboto-Regular.ttf") pdf.set_font("Roboto-Regular", size=60) with pytest.raises(fpdf.FPDFException) as error: - pdf.multi_cell(w=pdf.epw, txt="**Lorem Ipsum**", markdown=True) + pdf.multi_cell(w=pdf.epw, text="**Lorem Ipsum**", markdown=True) expected_msg = "Undefined font: roboto-regularB - Use built-in fonts or FPDF.add_font() beforehand" assert str(error.value) == expected_msg @@ -61,7 +61,7 @@ def test_multi_cell_markdown_with_fill_color(tmp_path): # issue 348 pdf.set_font("Times", size=10) pdf.set_fill_color(255, 0, 0) pdf.multi_cell( - 50, markdown=True, txt="aa bb cc **dd ee dd ee dd ee dd ee dd ee dd ee**" + 50, markdown=True, text="aa bb cc **dd ee dd ee dd ee dd ee dd ee dd ee**" ) assert_pdf_equal(pdf, HERE / "multi_cell_markdown_with_fill_color.pdf", tmp_path) @@ -76,7 +76,7 @@ def test_multi_cell_markdown_justified(tmp_path): # issue 327 190, markdown=True, align="J", - txt=( + text=( "Lorem **ipsum** dolor sit amet, **consectetur** adipiscing elit, " "sed do eiusmod tempor incididunt ut labore et dolore magna " "aliqua. Ut enim ad minim veniam, __quis__ nostrud exercitation " @@ -98,7 +98,7 @@ def test_multi_cell_markdown_link(tmp_path): pdf.add_page() pdf.multi_cell( pdf.epw, - txt="**Start** [One Page Dungeon Context](https://www.dungeoncontest.com/) __End__", + text="**Start** [One Page Dungeon Context](https://www.dungeoncontest.com/) __End__", markdown=True, ) assert_pdf_equal(pdf, HERE / "multi_cell_markdown_link.pdf", tmp_path) diff --git a/test/text/test_render_styled.py b/test/text/test_render_styled.py index 58b2daf5e..20444be9f 100644 --- a/test/text/test_render_styled.py +++ b/test/text/test_render_styled.py @@ -134,7 +134,7 @@ def test_cell_newpos(tmp_path): newy = item[3] doc.cell( twidth, - txt=s, + text=s, border=1, align=align, new_x=newx, @@ -177,7 +177,7 @@ def test_cell_newpos_stretched(tmp_path): newy = item[3] doc.cell( twidth, - txt=s, + text=s, border=1, align=align, new_x=newx, @@ -220,7 +220,7 @@ def test_cell_newpos_charspaced(tmp_path): newy = item[3] doc.cell( twidth, - txt=s, + text=s, border=1, align=align, new_x=newx, @@ -264,7 +264,7 @@ def test_cell_newpos_combined(tmp_path): newy = item[3] doc.cell( twidth, - txt=s, + text=s, border=1, align=align, new_x=newx, @@ -305,7 +305,7 @@ def test_multi_cell_newpos(tmp_path): newy = item[3] doc.multi_cell( twidth, - txt=s + " xxxxxxxxxxxxxxx", # force auto break + text=s + " xxxxxxxxxxxxxxx", # force auto break border=1, align=align, new_x=newx, @@ -347,7 +347,7 @@ def test_multi_cell_newpos_stretched(tmp_path): newy = item[3] doc.multi_cell( twidth, - txt=s + " xxxxxxxxxxxxxxx", # force auto break + text=s + " xxxxxxxxxxxxxxx", # force auto break border=1, align=align, new_x=newx, @@ -388,7 +388,7 @@ def test_multi_cell_newpos_charspaced(tmp_path): newy = item[3] doc.multi_cell( twidth, - txt=s + " xxxxxxxxxxxx", # force auto break + text=s + " xxxxxxxxxxxx", # force auto break border=1, align=align, new_x=newx, @@ -430,7 +430,7 @@ def test_multi_cell_newpos_combined(tmp_path): newy = item[3] doc.multi_cell( twidth, - txt=s + " xxxxxxxxxxxx", # force auto break + text=s + " xxxxxxxxxxxx", # force auto break border=1, align=align, new_x=newx, @@ -495,7 +495,7 @@ def test_cell_lnpos(tmp_path): with pytest.warns(DeprecationWarning) as record: doc.cell( twidth, - txt=s, + text=s, border=1, align=align, ln=ln, @@ -539,7 +539,7 @@ def test_multi_cell_ln_newpos(tmp_path): with pytest.warns(DeprecationWarning) as record: doc.multi_cell( twidth, - txt=s + " xxxxxxxxxxxxxxxxxxxx", # force auto break + text=s + " xxxxxxxxxxxxxxxxxxxx", # force auto break border=1, align=align, ln=ln, diff --git a/test/text/test_text.py b/test/text/test_text.py index 98d02a60b..5d4a5c9df 100644 --- a/test/text/test_text.py +++ b/test/text/test_text.py @@ -95,7 +95,7 @@ def test_text_no_font_set(): pdf = FPDF() pdf.add_page() with pytest.raises(FPDFException) as error: - pdf.text(20, 20, txt="Hello World!") + pdf.text(20, 20, text="Hello World!") expected_msg = "No font set, you need to call set_font() beforehand" assert str(error.value) == expected_msg @@ -114,3 +114,14 @@ def test_text_badinput(): pdf.text(20, 20, (1, 2, 3)) with pytest.raises(AttributeError): pdf.text(20, 20, None) + + +def test_text_deprecated_txt_arg(): + pdf = FPDF() + pdf.add_page() + pdf.set_font("Helvetica", size=10) + with pytest.warns( + DeprecationWarning, match='The parameter "txt" has been renamed to "text"' + ): + # pylint: disable=unexpected-keyword-arg + pdf.text(20, 20, txt="Lorem ipsum Ut nostrud irure") diff --git a/test/text/test_text_mode.py b/test/text/test_text_mode.py index c18c5d3ee..ab8270ab3 100644 --- a/test/text/test_text_mode.py +++ b/test/text/test_text_mode.py @@ -15,21 +15,21 @@ def test_text_modes(tmp_path): pdf.add_page() pdf.set_font("Helvetica", size=80) with pdf.local_context(fill_color=(255, 128, 0)): - pdf.cell(txt="FILL default") + pdf.cell(text="FILL default") with pdf.local_context(text_color=(0, 128, 255)): - pdf.cell(txt=" text mode") + pdf.cell(text=" text mode") pdf.ln() with pdf.local_context(text_mode=TextMode.STROKE, line_width=2): - pdf.cell(txt="STROKE text mode") + pdf.cell(text="STROKE text mode") pdf.ln() pdf.text_mode = TextMode.FILL_STROKE pdf.line_width = 4 pdf.set_draw_color(255, 0, 255) - pdf.cell(txt="FILL_STROKE text mode") + pdf.cell(text="FILL_STROKE text mode") pdf.ln() with pdf.local_context(): pdf.text_mode = "INVISIBLE" # testing TextMode.coerce - pdf.cell(txt="INVISIBLE text mode") + pdf.cell(text="INVISIBLE text mode") assert_pdf_equal(pdf, HERE / "text_modes.pdf", tmp_path) @@ -39,24 +39,24 @@ def test_clip_text_modes(tmp_path): pdf.set_font("Helvetica", size=80) pdf.line_width = 1 with pdf.local_context(text_mode=TextMode.FILL_CLIP, text_color=(0, 255, 255)): - pdf.cell(txt="FILL_CLIP text mode") + pdf.cell(text="FILL_CLIP text mode") for r in range(0, 200, 2): pdf.circle(x=110 - r / 2, y=22 - r / 2, r=r) pdf.ln() with pdf.local_context(text_mode=TextMode.STROKE_CLIP): - pdf.cell(txt="STROKE_CLIP text mode") + pdf.cell(text="STROKE_CLIP text mode") for r in range(0, 200, 2): pdf.circle(x=110 - r / 2, y=50 - r / 2, r=r) pdf.ln() with pdf.local_context( text_mode=TextMode.FILL_STROKE_CLIP, text_color=(0, 255, 255) ): - pdf.cell(txt="FILL_STROKE_CLIP text mode") + pdf.cell(text="FILL_STROKE_CLIP text mode") for r in range(0, 200, 2): pdf.circle(x=110 - r / 2, y=78 - r / 2, r=r) pdf.ln() with pdf.local_context(text_mode=TextMode.CLIP): - pdf.cell(txt="CLIP text mode") + pdf.cell(text="CLIP text mode") for r in range(0, 200, 2): pdf.circle(x=110 - r / 2, y=106 - r / 2, r=r) pdf.ln() diff --git a/test/text/test_write.py b/test/text/test_write.py index 1ee6cc58d..fed93b455 100644 --- a/test/text/test_write.py +++ b/test/text/test_write.py @@ -1,5 +1,7 @@ from pathlib import Path +import pytest + from fpdf import FPDF from test.conftest import assert_pdf_equal, LOREM_IPSUM @@ -12,8 +14,8 @@ def test_write_page_break(tmp_path): doc.add_page() doc.set_font("helvetica", size=24) doc.y = 20 - doc.write(txt=LOREM_IPSUM) - doc.write(txt=LOREM_IPSUM) + doc.write(text=LOREM_IPSUM) + doc.write(text=LOREM_IPSUM) assert_pdf_equal(doc, HERE / "write_page_break.pdf", tmp_path) @@ -30,19 +32,19 @@ def test_write_soft_hyphen(tmp_path): doc.add_page() doc.set_font("helvetica", size=24) doc.y = 20 - doc.write(txt=s) + doc.write(text=s) doc.set_font("helvetica", size=24, style="B") - doc.write(txt=s) + doc.write(text=s) doc.set_font("helvetica", size=24, style="I") - doc.write(txt=s) + doc.write(text=s) doc.set_font("helvetica", size=24) - doc.write(txt=s) + doc.write(text=s) doc.set_font("helvetica", size=24, style="B") - doc.write(txt=s) + doc.write(text=s) doc.set_font("helvetica", size=24, style="I") - doc.write(txt=s) + doc.write(text=s) doc.set_font("helvetica", size=24) - doc.write(txt=s) + doc.write(text=s) assert_pdf_equal(doc, HERE / "write_soft_hyphen.pdf", tmp_path) @@ -53,8 +55,8 @@ def test_write_trailing_nl(tmp_path): # issue #455 pdf.set_font("Times", size=16) lines = ["Hello\n", "Sweet\n", "World\n"] for line in lines: - pdf.write(txt=line) - pdf.write(txt="end_mmc") + pdf.write(text=line) + pdf.write(text="end_mmc") assert_pdf_equal(pdf, HERE / "write_trailing_nl.pdf", tmp_path) @@ -65,22 +67,22 @@ def test_write_font_stretching(tmp_path): # issue #478 # built-in font pdf.set_font("Helvetica", "", 8) pdf.set_right_margin(pdf.w - right_boundary) - pdf.write(txt=LOREM_IPSUM[:100]) + pdf.write(text=LOREM_IPSUM[:100]) pdf.ln() pdf.ln() pdf.set_stretching(150) - pdf.write(txt=LOREM_IPSUM[:100]) + pdf.write(text=LOREM_IPSUM[:100]) pdf.ln() pdf.ln() # unicode font pdf.set_stretching(100) pdf.add_font(fname=FONTS_DIR / "DroidSansFallback.ttf") pdf.set_font("DroidSansFallback", "", 8) - pdf.write(txt=LOREM_IPSUM[:100]) + pdf.write(text=LOREM_IPSUM[:100]) pdf.ln() pdf.ln() pdf.set_stretching(150) - pdf.write(txt=LOREM_IPSUM[:100]) + pdf.write(text=LOREM_IPSUM[:100]) # for reference, in lieu of a colored background pdf.line(pdf.l_margin, 10, pdf.l_margin, 100) pdf.line(right_boundary, 10, right_boundary, 100) @@ -93,26 +95,26 @@ def test_write_superscript(tmp_path): pdf.set_font("Helvetica", "", 20) def write_this(): - pdf.write(txt="2") + pdf.write(text="2") pdf.char_vpos = "SUP" - pdf.write(txt="56") + pdf.write(text="56") pdf.char_vpos = "LINE" - pdf.write(txt=" more line text") + pdf.write(text=" more line text") pdf.char_vpos = "SUB" - pdf.write(txt="(idx)") + pdf.write(text="(idx)") pdf.char_vpos = "LINE" - pdf.write(txt=" end") + pdf.write(text=" end") pdf.ln() pdf.ln() - pdf.write(txt="1234 + ") + pdf.write(text="1234 + ") pdf.char_vpos = "NOM" - pdf.write(txt="5") + pdf.write(text="5") pdf.char_vpos = "LINE" - pdf.write(txt="/") + pdf.write(text="/") pdf.char_vpos = "DENOM" - pdf.write(txt="16") + pdf.write(text="16") pdf.char_vpos = "LINE" - pdf.write(txt=" + 987 = x") + pdf.write(text=" + 987 = x") pdf.ln() pdf.ln() pdf.ln() @@ -142,18 +144,18 @@ def test_write_char_wrap(tmp_path): # issue #649 pdf.add_page() pdf.set_right_margin(pdf.w - right_boundary) pdf.set_font("Helvetica", "", 10) - pdf.write(txt=LOREM_IPSUM[:200]) + pdf.write(text=LOREM_IPSUM[:200]) pdf.ln() pdf.ln() - pdf.write(txt=LOREM_IPSUM[:200], wrapmode="CHAR") + pdf.write(text=LOREM_IPSUM[:200], wrapmode="CHAR") pdf.ln() pdf.ln() pdf.set_font("Courier", "", 10) txt = " " + "abcdefghijklmnopqrstuvwxyz" * 3 - pdf.write(txt=txt) + pdf.write(text=txt) pdf.ln() pdf.ln() - pdf.write(txt=txt, wrapmode="CHAR") + pdf.write(text=txt, wrapmode="CHAR") pdf.line(pdf.l_margin, 10, pdf.l_margin, 130) pdf.line(right_boundary, 10, right_boundary, 130) assert_pdf_equal(pdf, HERE / "write_char_wrap.pdf", tmp_path) @@ -179,3 +181,14 @@ def test_write_empty(): assert ( pdf.x == x and pdf.y == y ), f"write('') has changed pdf.x ({pdf.x} from {x}) or pdf.x ({pdf.y} from {y})" + + +def test_write_deprecated_txt_arg(): + pdf = FPDF() + pdf.add_page() + pdf.set_font("Helvetica", size=10) + with pytest.warns( + DeprecationWarning, match='The parameter "txt" has been renamed to "text"' + ): + # pylint: disable=unexpected-keyword-arg + pdf.write(txt="Lorem ipsum Ut nostrud irure") diff --git a/test/text_shaping/test_text_shaping.py b/test/text_shaping/test_text_shaping.py index 44ffc7884..871a85781 100644 --- a/test/text_shaping/test_text_shaping.py +++ b/test/text_shaping/test_text_shaping.py @@ -14,10 +14,10 @@ def test_indi_text(tmp_path): pdf.add_font(family="Mangal", fname=HERE / "Mangal 400.ttf") pdf.set_font("Mangal", size=40) pdf.set_text_shaping(False) - pdf.cell(txt="इण्टरनेट पर हिन्दी के साधन", new_x="LEFT", new_y="NEXT") + pdf.cell(text="इण्टरनेट पर हिन्दी के साधन", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping(True) - pdf.cell(txt="इण्टरनेट पर हिन्दी के साधन", new_x="LEFT", new_y="NEXT") + pdf.cell(text="इण्टरनेट पर हिन्दी के साधन", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "shaping_hindi.pdf", tmp_path) @@ -31,11 +31,11 @@ def test_mixed_text_shaping(tmp_path): ) pdf.set_font("KFGQPC", size=36) pdf.set_text_shaping(True) - pdf.write(txt="مثال على اللغة العربية. محاذاة لليمين.") + pdf.write(text="مثال على اللغة العربية. محاذاة لليمين.") pdf.add_font(family="Mangal", fname=HERE / "Mangal 400.ttf") pdf.set_font("Mangal", size=40) # With preceding whitespace - pdf.write(txt=" इण्टरनेट पर हिन्दी के साधन") + pdf.write(text=" इण्टरनेट पर हिन्दी के साधन") assert_pdf_equal(pdf, HERE / "text_mixed_text_shaping.pdf", tmp_path) @@ -46,10 +46,10 @@ def test_text_replacement(tmp_path): pdf.add_font(family="FiraCode", fname=HERE / "FiraCode-Regular.ttf") pdf.set_font("FiraCode", size=40) pdf.set_text_shaping(False) - pdf.cell(txt="http://www 3 >= 2 != 1", new_x="LEFT", new_y="NEXT") + pdf.cell(text="http://www 3 >= 2 != 1", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping(True) - pdf.cell(txt="http://www 3 >= 2 != 1", new_x="LEFT", new_y="NEXT") + pdf.cell(text="http://www 3 >= 2 != 1", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "text_replacement.pdf", tmp_path) @@ -61,10 +61,10 @@ def test_kerning(tmp_path): pdf.add_font(family="Dumbledor3Thin", fname=HERE / "Dumbledor3Thin.ttf") pdf.set_font("Dumbledor3Thin", size=40) pdf.set_text_shaping(False) - pdf.cell(txt="Ты То Тф Та Тт Ти", new_x="LEFT", new_y="NEXT") + pdf.cell(text="Ты То Тф Та Тт Ти", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping(True) - pdf.cell(txt="Ты То Тф Та Тт Ти", new_x="LEFT", new_y="NEXT") + pdf.cell(text="Ты То Тф Та Тт Ти", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "kerning.pdf", tmp_path) @@ -76,10 +76,10 @@ def test_hebrew_diacritics(tmp_path): pdf.add_font(family="SBL_Hbrw", fname=HERE / "SBL_Hbrw.ttf") pdf.set_font("SBL_Hbrw", size=40) pdf.set_text_shaping(False) - pdf.cell(txt="בּ", new_x="LEFT", new_y="NEXT") + pdf.cell(text="בּ", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping(True) - pdf.cell(txt="בּ", new_x="LEFT", new_y="NEXT") + pdf.cell(text="בּ", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "hebrew_diacritics.pdf", tmp_path) @@ -90,10 +90,10 @@ def test_ligatures(tmp_path): pdf.add_font(family="ViaodaLibre", fname=HERE / "ViaodaLibre-Regular.ttf") pdf.set_font("ViaodaLibre", size=40) pdf.set_text_shaping(False) - pdf.cell(txt="final soft stuff", new_x="LEFT", new_y="NEXT") + pdf.cell(text="final soft stuff", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping(True) - pdf.cell(txt="final soft stuff", new_x="LEFT", new_y="NEXT") + pdf.cell(text="final soft stuff", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "ligatures.pdf", tmp_path) @@ -107,10 +107,10 @@ def test_arabic_right_to_left(tmp_path): ) pdf.set_font("KFGQPC", size=36) pdf.set_text_shaping(False) - pdf.cell(txt="مثال على اللغة العربية. محاذاة لليمين.", new_x="LEFT", new_y="NEXT") + pdf.cell(text="مثال على اللغة العربية. محاذاة لليمين.", new_x="LEFT", new_y="NEXT") pdf.ln(36) pdf.set_text_shaping(True) - pdf.cell(txt="مثال على اللغة العربية. محاذاة لليمين.", new_x="LEFT", new_y="NEXT") + pdf.cell(text="مثال على اللغة العربية. محاذاة لليمين.", new_x="LEFT", new_y="NEXT") assert_pdf_equal(pdf, HERE / "arabic.pdf", tmp_path) @@ -128,10 +128,10 @@ def test_multi_cell_markdown_with_shaping(tmp_path): " eiusmod __tempor incididunt__ ut labore et dolore --magna aliqua--." ) pdf.multi_cell( - w=pdf.epw, txt=text, markdown=True + w=pdf.epw, text=text, markdown=True ) # This is tricky to get working well pdf.ln() - pdf.multi_cell(w=pdf.epw, txt=text, markdown=True, align="L") + pdf.multi_cell(w=pdf.epw, text=text, markdown=True, align="L") assert_pdf_equal(pdf, HERE / "multi_cell_markdown_with_styling.pdf", tmp_path) @@ -141,18 +141,18 @@ def test_features(tmp_path): pdf.add_font(family="ViaodaLibre", fname=HERE / "ViaodaLibre-Regular.ttf") pdf.set_font("ViaodaLibre", size=40) pdf.set_text_shaping(use_shaping_engine=True) - pdf.cell(txt="final soft stuff", new_x="LEFT", new_y="NEXT") + pdf.cell(text="final soft stuff", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping(use_shaping_engine=True, features={"liga": False}) - pdf.cell(txt="final soft stuff", new_x="LEFT", new_y="NEXT") + pdf.cell(text="final soft stuff", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping(use_shaping_engine=True, features={"kern": False}) - pdf.cell(txt="final soft stuff", new_x="LEFT", new_y="NEXT") + pdf.cell(text="final soft stuff", new_x="LEFT", new_y="NEXT") pdf.ln() pdf.set_text_shaping( use_shaping_engine=True, direction="rtl", script="Latn", language="en-us" ) - pdf.cell(txt="final soft stuff", new_x="LEFT", new_y="NEXT") + pdf.cell(text="final soft stuff", new_x="LEFT", new_y="NEXT") pdf.ln() assert_pdf_equal(pdf, HERE / "features.pdf", tmp_path) @@ -164,7 +164,7 @@ def test_text_with_parentheses(tmp_path): pdf.add_font(family="SBL_Hbrw", fname=HERE / "SBL_Hbrw.ttf") pdf.set_font("SBL_Hbrw", size=30) pdf.set_text_shaping(30) - pdf.cell(txt="אנגלית (באנגלית: English) ה", new_x="LEFT", new_y="NEXT") + pdf.cell(text="אנגלית (באנגלית: English) ה", new_x="LEFT", new_y="NEXT") pdf.ln() - pdf.cell(txt="אנגלית (באנגלית: English) ", new_y="NEXT") + pdf.cell(text="אנגלית (באנגלית: English) ", new_y="NEXT") assert_pdf_equal(pdf, HERE / "text_with_parentheses.pdf", tmp_path)