fix(translators): ameliorer le respect des formats de fichiers pour Excel, PowerPoint et PDF
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m33s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m33s
- Excel: elargissement intelligent des colonnes pour le texte etendu et alignement RTL des cellules - PowerPoint: retour a la ligne et auto-fit anti-debordement, colonnes de tableaux en RTL - PDF: protection multi-colonnes pour eviter les chevauchements et formatage hebreu - Tests: validation de non-regression pour tous les formats
This commit is contained in:
@@ -169,7 +169,19 @@ def _shape_rtl_multiline(
|
||||
shaped_lines = []
|
||||
for l in lines:
|
||||
try:
|
||||
shaped_lines.append(get_display(arabic_reshaper.reshape(l)))
|
||||
# Arabic/Persian/Urdu script requires cursive contextual shaping (arabic_reshaper) + bidi display
|
||||
# Hebrew script only requires bidi display (get_display)
|
||||
has_arabic = any(
|
||||
"\u0600" <= ch <= "\u06FF"
|
||||
or "\u0750" <= ch <= "\u077F"
|
||||
or "\uFB50" <= ch <= "\uFDFF"
|
||||
or "\uFE70" <= ch <= "\uFEFF"
|
||||
for ch in l
|
||||
)
|
||||
if has_arabic:
|
||||
shaped_lines.append(get_display(arabic_reshaper.reshape(l)))
|
||||
else:
|
||||
shaped_lines.append(get_display(l))
|
||||
except Exception:
|
||||
shaped_lines.append(l)
|
||||
shaped_result.append("\n".join(shaped_lines))
|
||||
@@ -1103,10 +1115,9 @@ class PDFTranslator:
|
||||
if not assigned:
|
||||
columns.append([block])
|
||||
|
||||
# For each column, set next_block_y by y-order within that column.
|
||||
# A block whose expanded bbox would touch the next column-mate's
|
||||
# y0 will be capped to that y0 - 2 (small visual gap).
|
||||
for column in columns:
|
||||
# For each column, set next_block_y by y-order within that column,
|
||||
# and set next_block_x to prevent expanding across adjacent columns.
|
||||
for c_idx, column in enumerate(columns):
|
||||
column.sort(key=lambda b: b["bbox"][1])
|
||||
for i, block in enumerate(column):
|
||||
if i + 1 < len(column):
|
||||
@@ -1114,6 +1125,18 @@ class PDFTranslator:
|
||||
else:
|
||||
block["_next_block_y"] = page_bottom
|
||||
|
||||
# Multi-column protection: find adjacent column to the right
|
||||
# with overlapping vertical bounds
|
||||
next_col_x0 = page_rect.x1 - margin
|
||||
b_y0, b_y1 = block["bbox"][1], block["bbox"][3]
|
||||
for other_col in columns[c_idx + 1:]:
|
||||
for other_b in other_col:
|
||||
if other_b["bbox"][1] < b_y1 and other_b["bbox"][3] > b_y0:
|
||||
cand_x0 = other_b["bbox"][0] - 4.0
|
||||
if block["bbox"][2] < cand_x0 < next_col_x0:
|
||||
next_col_x0 = cand_x0
|
||||
block["_next_block_x"] = next_col_x0
|
||||
|
||||
def _write_translated_block(
|
||||
self,
|
||||
page,
|
||||
@@ -1177,10 +1200,9 @@ class PDFTranslator:
|
||||
page_rect = page.rect
|
||||
margin = 18
|
||||
|
||||
# Track B3.6: try a wider bbox that respects the page margin.
|
||||
# For headings, also allow horizontal expansion because long
|
||||
# translated titles often don't fit in the original width.
|
||||
max_x1 = page_rect.x1 - margin
|
||||
# Track B3.6: try a wider bbox that respects the page margin and adjacent columns.
|
||||
next_block_x = block.get("_next_block_x", page_rect.x1 - margin)
|
||||
max_x1 = max(original_rect.x1, min(page_rect.x1 - margin, next_block_x))
|
||||
expanded_h = fitz.Rect(
|
||||
max(original_rect.x0, page_rect.x0 + margin),
|
||||
original_rect.y0,
|
||||
|
||||
Reference in New Issue
Block a user