From bc5189b71fa233481f46259746ce39b846ba00a0 Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:18:07 +0100 Subject: [PATCH] Pleasing black (#1354) --- fpdf/annotations.py | 1 + fpdf/enums.py | 4 ++++ fpdf/fpdf.py | 1 + fpdf/image_datastructures.py | 1 + fpdf/line_break.py | 4 ++-- fpdf/table.py | 1 + scripts/benchmark_borb_vs_fpdf2.py | 2 +- test/fonts/test_wraps_zerowidthspace.py | 18 +++++++++--------- test/test_positioning.py | 14 +++++++------- test/text/test_varied_fragments.py | 2 +- 10 files changed, 28 insertions(+), 20 deletions(-) diff --git a/fpdf/annotations.py b/fpdf/annotations.py index 05114b0ac..849d2533c 100644 --- a/fpdf/annotations.py +++ b/fpdf/annotations.py @@ -84,6 +84,7 @@ def __init__(self, *args, **kwargs): class AnnotationDict(AnnotationMixin): "A PDF annotation that get serialized as an inline <>" + __slots__ = ( # RAM usage optimization "type", "subtype", diff --git a/fpdf/enums.py b/fpdf/enums.py index 500454dbd..4e7279dbc 100644 --- a/fpdf/enums.py +++ b/fpdf/enums.py @@ -149,6 +149,7 @@ def coerce(cls, value): class WrapMode(CoerciveEnum): "Defines how to break and wrap lines in multi-line text." + WORD = intern("WORD") "Wrap by word" @@ -158,6 +159,7 @@ class WrapMode(CoerciveEnum): class CharVPos(CoerciveEnum): "Defines the vertical position of text relative to the line." + SUP = intern("SUP") "Superscript" @@ -493,6 +495,7 @@ def coerce(cls, value): class TextMode(CoerciveIntEnum): "Values described in PDF spec section 'Text Rendering Mode'" + FILL = 0 STROKE = 1 FILL_STROKE = 2 @@ -552,6 +555,7 @@ class YPos(CoerciveEnum): class Angle(CoerciveIntEnum): "Direction values used for mirror transformations specifying the angle of mirror line" + NORTH = 90 EAST = 0 SOUTH = 270 diff --git a/fpdf/fpdf.py b/fpdf/fpdf.py index eec4badc6..7d21993c3 100644 --- a/fpdf/fpdf.py +++ b/fpdf/fpdf.py @@ -221,6 +221,7 @@ def wrapper(self, *args, **kwargs): class FPDF(GraphicsStateMixin, TextRegionMixin): "PDF Generation class" + MARKDOWN_BOLD_MARKER = "**" MARKDOWN_ITALICS_MARKER = "__" MARKDOWN_UNDERLINE_MARKER = "--" diff --git a/fpdf/image_datastructures.py b/fpdf/image_datastructures.py index 49e3dbfc8..ae3954cba 100644 --- a/fpdf/image_datastructures.py +++ b/fpdf/image_datastructures.py @@ -65,6 +65,7 @@ def size_in_document_units(self, w, h, scale=1): class VectorImageInfo(ImageInfo): "Information about a vector image used in the PDF document" + # pass diff --git a/fpdf/line_break.py b/fpdf/line_break.py index b7857985b..ac74d50c6 100644 --- a/fpdf/line_break.py +++ b/fpdf/line_break.py @@ -31,8 +31,8 @@ "\u2006", # | SIX-PER-EM SPACE "\u2008", # | PUNCTUATION SPACE "\u2009", # | THIN SPACE - "\u200A", # | HAIR SPACE - "\u205F", # | MEDIUM MATHEMATICAL SPACE + "\u200a", # | HAIR SPACE + "\u205f", # | MEDIUM MATHEMATICAL SPACE "\u3000", # | IDEOGRAPHIC SPACE "\u0009", # | TAB ] diff --git a/fpdf/table.py b/fpdf/table.py index 0cb3568dd..4a7e44d8f 100644 --- a/fpdf/table.py +++ b/fpdf/table.py @@ -855,6 +855,7 @@ def cell( @dataclass(frozen=True) class Cell: "Internal representation of a table cell" + __slots__ = ( # RAM usage optimization "text", "align", diff --git a/scripts/benchmark_borb_vs_fpdf2.py b/scripts/benchmark_borb_vs_fpdf2.py index 32aa47104..cc709814c 100755 --- a/scripts/benchmark_borb_vs_fpdf2.py +++ b/scripts/benchmark_borb_vs_fpdf2.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 """Speed benchmark: how much time each lib takes to generate a 10 thousands pages PDF with ~180 distinct images? - (disclaimer: the author of this benchmark is fpdf2 current maintainer)""" +(disclaimer: the author of this benchmark is fpdf2 current maintainer)""" # Script used in this article: https://chezsoi.org/lucas/blog/fpdf2-5-2-svg-support-and-borb.html import resource from decimal import Decimal diff --git a/test/fonts/test_wraps_zerowidthspace.py b/test/fonts/test_wraps_zerowidthspace.py index d05f7c15d..17f299148 100644 --- a/test/fonts/test_wraps_zerowidthspace.py +++ b/test/fonts/test_wraps_zerowidthspace.py @@ -15,14 +15,14 @@ def test_wraps_zerowidthspace(tmp_path): pdf.write( 8, "Thai (ideally wouldn't wrap after the space after '1000'): " - + "นโยบาย\u200Bสาธารณะ\u200Bมี\u200Bความ\u200Bสำคัญ\u200Bต่อ\u200B" - + "การ\u200Bสนับสนุน\u200Bการ\u200Bออก\u200Bแบบ\u200Bและ\u200Bการ" - + "\u200Bสร้าง\u200Bชุมชน\u200Bและ\u200Bเมือง\u200Bสุขภาพ\u200Bดี\u200B" - + "และ\u200Bยั่งยืน รายการ\u200Bตรวจ\u200Bสอบนโยบาย\u200Bความ\u200B" - + "ท้าทาย 1,000 เมือง\u200Bสำหรับ\u200Bใช้\u200Bเพื่อ\u200Bประเมิน\u200Bการ" - + "\u200Bมี\u200Bอยู่\u200Bและ\u200Bคุณภาพ\u200Bของ\u200Bนโยบาย\u200Bที่" - + "\u200Bสอด\u200Bคล้อง\u200Bกับ\u200Bหลัก\u200Bฐาน\u200Bและ\u200Bหลัก" - + "\u200Bการ\u200Bสำหรับ\u200Bเมือง\u200Bที่\u200Bมี\u200Bสุขภาพ\u200Bดี" - + "\u200Bและ\u200Bยั่งยืน", + + "นโยบาย\u200bสาธารณะ\u200bมี\u200bความ\u200bสำคัญ\u200bต่อ\u200b" + + "การ\u200bสนับสนุน\u200bการ\u200bออก\u200bแบบ\u200bและ\u200bการ" + + "\u200bสร้าง\u200bชุมชน\u200bและ\u200bเมือง\u200bสุขภาพ\u200bดี\u200b" + + "และ\u200bยั่งยืน รายการ\u200bตรวจ\u200bสอบนโยบาย\u200bความ\u200b" + + "ท้าทาย 1,000 เมือง\u200bสำหรับ\u200bใช้\u200bเพื่อ\u200bประเมิน\u200bการ" + + "\u200bมี\u200bอยู่\u200bและ\u200bคุณภาพ\u200bของ\u200bนโยบาย\u200bที่" + + "\u200bสอด\u200bคล้อง\u200bกับ\u200bหลัก\u200bฐาน\u200bและ\u200bหลัก" + + "\u200bการ\u200bสำหรับ\u200bเมือง\u200bที่\u200bมี\u200bสุขภาพ\u200bดี" + + "\u200bและ\u200bยั่งยืน", ) assert_pdf_equal(pdf, HERE / "thai_wraps_zerowidthspace.pdf", tmp_path) diff --git a/test/test_positioning.py b/test/test_positioning.py index 83bdc85e5..2ef50fd1e 100644 --- a/test/test_positioning.py +++ b/test/test_positioning.py @@ -1,10 +1,10 @@ -""" Tests related to positioning self.x and self.y on the page. - implemented: - * ln() - to be implemented: - * set_x() - * set_y() - * set_xy() +"""Tests related to positioning self.x and self.y on the page. +implemented: +* ln() +to be implemented: +* set_x() +* set_y() +* set_xy() """ from pathlib import Path diff --git a/test/text/test_varied_fragments.py b/test/text/test_varied_fragments.py index 62a6b743f..6fca14eb4 100644 --- a/test/text/test_varied_fragments.py +++ b/test/text/test_varied_fragments.py @@ -1,4 +1,4 @@ -""" Test that _render_styled_text_line() correctly handles sequences of +"""Test that _render_styled_text_line() correctly handles sequences of Fragments with varying font/size/style and other characteristics. """