fix: stabilize RTL PDF wrapping and list markers
Tests / test (3.10) (push) Successful in 1m55s
Tests / test (3.11) (push) Successful in 16s
Tests / test (3.12) (push) Successful in 14s
Tests / test (3.13) (push) Successful in 20s
Tests / test (3.9) (push) Failing after 13s

This commit is contained in:
Meghdad committed 2026-06-30 17:37:36 +03:30
1 parent 86a54faf6a
commit aac8ac2df3
2 files changed
+252 -10

No files matched your search

+52
View File
@@ -3,11 +3,14 @@ import unittest
from pathlib import Path
from chatgpt_pdf_converter import (
FontConfig,
PdfOptions,
build_styles,
content_aware_column_widths,
convert_markdown_file,
detect_direction,
inline_markup,
list_flowable,
parse_markdown,
reshape_plain_text,
)
@@ -62,6 +65,24 @@ print("hello")
self.assertNotIn("<b>", markup)
self.assertLess(markup.index("L=2"), markup.index("ﺎﺑ"))
def test_rtl_wrapped_markup_keeps_lines_in_reading_order(self):
styles = build_styles(
FontConfig("Helvetica", "Helvetica-Bold", "Courier", None),
14,
"rtl",
)
text = (
"به نظر می‌رسد این یک پروفایل **۱۶ عامل شخصیت کتل (16PF)** "
"به زبان فارسی باشد. می‌توانم نمره‌های عامل‌های اصلی را از برگه بخوانم:"
)
markup = inline_markup(text, "rtl", styles["Body"], 270)
lines = markup.split("<br/>")
self.assertGreater(len(lines), 1)
self.assertIn("ﻞﯾﺎﻓﻭﺮﭘ", lines[0])
self.assertIn("ﻢﻧﺍﻮﺨﺑ", lines[-1])
def test_content_aware_table_widths_prioritize_long_source_column(self):
rows = [
["نام", "نوع", "اندازه", "ابعاد", "منبع"],
@@ -82,6 +103,37 @@ print("hello")
self.assertGreater(widths[2], 45)
self.assertAlmostEqual(sum(widths), 480, delta=0.1)
def test_rtl_list_markers_use_fixed_right_column(self):
styles = build_styles(
FontConfig("Helvetica", "Helvetica-Bold", "Courier", None),
14,
"rtl",
)
table = list_flowable(
[
("-", "احتمالا در موقعیت‌های پراسترس آرام می‌مانید."),
("-", "L=2 به آدم‌ها حسن‌نیت می‌دهید."),
],
styles,
"rtl",
480,
)
self.assertEqual(table._cellvalues[0][-1].getPlainText(), "-")
self.assertEqual(table._cellvalues[1][-1].getPlainText(), "-")
self.assertAlmostEqual(sum(table._argW), 480, delta=0.1)
def test_ltr_list_markers_use_fixed_left_column(self):
styles = build_styles(
FontConfig("Helvetica", "Helvetica-Bold", "Courier", None),
14,
"ltr",
)
table = list_flowable([("-", "First item")], styles, "ltr", 480)
self.assertEqual(table._cellvalues[0][0].getPlainText(), "-")
self.assertAlmostEqual(sum(table._argW), 480, delta=0.1)
def test_generates_pdf(self):
with tempfile.TemporaryDirectory() as tmpdir:
tmp = Path(tmpdir)