diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0773a806..393481f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -102,7 +102,7 @@ jobs: - "3.11" - "3.10" - "3.9" - - "3.8" +# - "3.8" # - "3.7" steps: - name: Install wkhtmltopdf diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 841d0d7e..5383d0c7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -28,6 +28,14 @@ are used for versioning (schema follows below): 0.3.4 to 0.4). - All backwards incompatible changes are mentioned in this document. +0.17.13 +------- +2024-10-30 + +- Upgrade `Pillow` related code to work with `Pillow`>=9.1.0 (tested with + 10.x and 11.x). +- Drop EOL Python 3.8 support. + 0.17.12 ------- 2024-09-10 diff --git a/examples/requirements/common.txt b/examples/requirements/common.txt index 80e57225..d157b3e9 100644 --- a/examples/requirements/common.txt +++ b/examples/requirements/common.txt @@ -137,7 +137,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -254,7 +254,7 @@ webencodings==0.5.1 # tinycss2 xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in yarl==1.11.1 # via aiohttp diff --git a/examples/requirements/dev.txt b/examples/requirements/dev.txt index d729b135..536b30ae 100644 --- a/examples/requirements/dev.txt +++ b/examples/requirements/dev.txt @@ -238,7 +238,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -445,7 +445,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_2_2.txt b/examples/requirements/django_2_2.txt index 3258a3aa..7176a242 100644 --- a/examples/requirements/django_2_2.txt +++ b/examples/requirements/django_2_2.txt @@ -206,7 +206,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -393,7 +393,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_2_2_and_flask.txt b/examples/requirements/django_2_2_and_flask.txt index e93d5223..982767cb 100644 --- a/examples/requirements/django_2_2_and_flask.txt +++ b/examples/requirements/django_2_2_and_flask.txt @@ -238,7 +238,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -440,7 +440,7 @@ wtforms==3.1.2 # via flask-admin xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_3_2.txt b/examples/requirements/django_3_2.txt index c46eb946..a74effda 100644 --- a/examples/requirements/django_3_2.txt +++ b/examples/requirements/django_3_2.txt @@ -211,7 +211,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -399,7 +399,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_3_2_and_flask.txt b/examples/requirements/django_3_2_and_flask.txt index 3917cc2f..3f32610a 100644 --- a/examples/requirements/django_3_2_and_flask.txt +++ b/examples/requirements/django_3_2_and_flask.txt @@ -243,7 +243,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -446,7 +446,7 @@ wtforms==3.1.2 # via flask-admin xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_4_0.txt b/examples/requirements/django_4_0.txt index de3a6af9..d9b4558d 100644 --- a/examples/requirements/django_4_0.txt +++ b/examples/requirements/django_4_0.txt @@ -211,7 +211,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -399,7 +399,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_4_0_and_flask.txt b/examples/requirements/django_4_0_and_flask.txt index 8047250f..c17d2038 100644 --- a/examples/requirements/django_4_0_and_flask.txt +++ b/examples/requirements/django_4_0_and_flask.txt @@ -243,7 +243,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -446,7 +446,7 @@ wtforms==3.1.2 # via flask-admin xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_4_1.txt b/examples/requirements/django_4_1.txt index 10448c4c..d3af8f1e 100644 --- a/examples/requirements/django_4_1.txt +++ b/examples/requirements/django_4_1.txt @@ -211,7 +211,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -399,7 +399,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_4_1_and_flask.txt b/examples/requirements/django_4_1_and_flask.txt index b9e54a45..563bdb0f 100644 --- a/examples/requirements/django_4_1_and_flask.txt +++ b/examples/requirements/django_4_1_and_flask.txt @@ -243,7 +243,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -446,7 +446,7 @@ wtforms==3.1.2 # via flask-admin xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_4_2.txt b/examples/requirements/django_4_2.txt index 2579086d..ff32b890 100644 --- a/examples/requirements/django_4_2.txt +++ b/examples/requirements/django_4_2.txt @@ -211,7 +211,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -397,7 +397,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/django_4_2_and_flask.txt b/examples/requirements/django_4_2_and_flask.txt index fbe7e9cb..01dac77f 100644 --- a/examples/requirements/django_4_2_and_flask.txt +++ b/examples/requirements/django_4_2_and_flask.txt @@ -243,7 +243,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -444,7 +444,7 @@ wtforms==3.1.2 # via flask-admin xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/docs.txt b/examples/requirements/docs.txt index 8259bfd7..6d7d9af8 100644 --- a/examples/requirements/docs.txt +++ b/examples/requirements/docs.txt @@ -225,7 +225,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -450,7 +450,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/flask.txt b/examples/requirements/flask.txt index 4c393b77..567c7b72 100644 --- a/examples/requirements/flask.txt +++ b/examples/requirements/flask.txt @@ -212,7 +212,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -396,7 +396,7 @@ wtforms==3.1.2 # via flask-admin xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/ml.txt b/examples/requirements/ml.txt index f6c0e72f..47e8e3b8 100644 --- a/examples/requirements/ml.txt +++ b/examples/requirements/ml.txt @@ -255,7 +255,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -473,7 +473,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/examples/requirements/testing.txt b/examples/requirements/testing.txt index e1424283..a513c8a4 100644 --- a/examples/requirements/testing.txt +++ b/examples/requirements/testing.txt @@ -211,7 +211,7 @@ pdf2image==1.17.0 # via -r examples/requirements/common.in pdfkit==1.0.0 # via -r examples/requirements/common.in -pillow==9.5.0 +pillow==11.0.0 # via # pdf2image # python-pptx @@ -399,7 +399,7 @@ werkzeug==3.0.4 # via moto xlsxwriter==3.2.0 # via python-pptx -xml2epub==2.6.5 +xml2epub==2.6.6 # via -r examples/requirements/common.in xmltodict==0.13.0 # via moto diff --git a/setup.py b/setup.py index de7ddb44..392b6686 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def clean_readme(text: str) -> str: return text -version = "0.17.12" +version = "0.17.13" try: readme = open(os.path.join(os.path.dirname(__file__), "README.rst")).read() @@ -108,8 +108,8 @@ def clean_readme(text: str) -> str: long_description_content_type="text/x-rst", classifiers=[ "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", + # "Programming Language :: Python :: 3.7", + # "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", diff --git a/src/faker_file/__init__.py b/src/faker_file/__init__.py index 85bd6d28..b46720c7 100644 --- a/src/faker_file/__init__.py +++ b/src/faker_file/__init__.py @@ -1,5 +1,5 @@ __title__ = "faker_file" -__version__ = "0.17.12" +__version__ = "0.17.13" __author__ = "Artur Barseghyan " __copyright__ = "2022-2024 Artur Barseghyan" __license__ = "MIT" diff --git a/src/faker_file/contrib/pdf_file/pil_snippets.py b/src/faker_file/contrib/pdf_file/pil_snippets.py index 0c109e15..481ee725 100644 --- a/src/faker_file/contrib/pdf_file/pil_snippets.py +++ b/src/faker_file/contrib/pdf_file/pil_snippets.py @@ -267,9 +267,18 @@ def add_paragraph( y_text = position[1] # LOGGER.debug(f"position: {position}") for counter, line in enumerate(lines): - text_width, text_height = generator.draw.textsize( - line, font=font, spacing=generator.spacing + # text_width, text_height = generator.draw.textsize( + # line, font=font, spacing=generator.spacing + # ) + text_bbox = generator.draw.textbbox( + (position[0], y_text), + line, + font=font, + spacing=generator.spacing, ) + # text_width = text_bbox[2] - text_bbox[0] + text_height = text_bbox[3] - text_bbox[1] + if y_text + text_height > generator.page_height: generator.save_and_start_new_page() y_text = 0 @@ -369,7 +378,11 @@ def add_heading( font=font, ) - text_width, text_height = generator.draw.textsize(_content, font=font) + # text_width, text_height = generator.draw.textsize(_content, font=font) + text_bbox = generator.draw.textbbox((position[0], y), _content, font=font) + # text_width = text_bbox[2] - text_bbox[0] + text_height = text_bbox[3] - text_bbox[1] + y += text_height # If you want to keep track of the last position to place another @@ -450,7 +463,11 @@ def draw_table_cell(document, cell_content, position, cell_size, font): ) # Draw text in the rectangle - text_width, text_height = document.textsize(cell_content, font=font) + # text_width, text_height = document.textsize(cell_content, font=font) + text_bbox = document.textbbox((0, 0), cell_content, font=font) + text_width = text_bbox[2] - text_bbox[0] + text_height = text_bbox[3] - text_bbox[1] + text_position = ( x + (width - text_width) // 2, y + (height - text_height) // 2, diff --git a/src/faker_file/providers/image/pil_generator.py b/src/faker_file/providers/image/pil_generator.py index 7658c422..95231d3c 100644 --- a/src/faker_file/providers/image/pil_generator.py +++ b/src/faker_file/providers/image/pil_generator.py @@ -180,7 +180,8 @@ def find_max_fit_for_single_line_text( low, high = 0, len(text) while low < high: mid = (high + low) // 2 - text_width, _ = draw.textsize(text[:mid], font=font) + # text_width, _ = draw.textsize(text[:mid], font=font) + text_width = draw.textlength(text[:mid], font=font) if text_width > max_width: high = mid @@ -288,9 +289,19 @@ def generate( y_text = 0 for counter, line in enumerate(lines): - text_width, text_height = self.draw.textsize( - line, font=font, spacing=self.spacing + # text_width, text_height = self.draw.textsize( + # line, font=font, spacing=self.spacing + # ) + # Updated to use textbbox for text width and height + text_bbox = self.draw.textbbox( + (0, y_text), + line, + font=font, + spacing=self.spacing, ) + # text_width = text_bbox[2] - text_bbox[0] + text_height = text_bbox[3] - text_bbox[1] + if y_text + text_height > self.page_height: self.save_and_start_new_page() y_text = 0 diff --git a/src/faker_file/providers/pdf_file/generators/pil_generator.py b/src/faker_file/providers/pdf_file/generators/pil_generator.py index 3f73d354..452a3921 100644 --- a/src/faker_file/providers/pdf_file/generators/pil_generator.py +++ b/src/faker_file/providers/pdf_file/generators/pil_generator.py @@ -97,7 +97,8 @@ def find_max_fit_for_single_line_text( low, high = 0, len(text) while low < high: mid = (high + low) // 2 - text_width, _ = draw.textsize(text[:mid], font=font) + # text_width, _ = draw.textsize(text[:mid], font=font) + text_width = draw.textlength(text[:mid], font=font) if text_width > max_width: high = mid @@ -189,9 +190,18 @@ def generate( y_text = 0 for counter, line in enumerate(lines): - text_width, text_height = self.draw.textsize( - line, font=font, spacing=self.spacing + # text_width, text_height = self.draw.textsize( + # line, font=font, spacing=self.spacing + # ) + text_bbox = self.draw.textbbox( + (0, y_text), + line, + font=font, + spacing=self.spacing, ) + # text_width = text_bbox[2] - text_bbox[0] + text_height = text_bbox[3] - text_bbox[1] + # if counter % max_lines_per_page == 0: if y_text + text_height > self.page_height: self.save_and_start_new_page()