Réserver la colonne de la flèche du nord pour que le titre de la cartouche ne la chevauche plus

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Antoine Jacquin
2026-09-27 16:07:00 +02:00
parent b85c29e5f1
commit 3cf5bbce6e
2 changed files with 40 additions and 4 deletions

View File

@ -294,3 +294,25 @@ def test_fit_title_shrinks_then_elides():
text, size = _fit_title(c, long_title, "Helvetica-Bold", 10, 60 * mm, min_size=7.0)
assert size >= 7.0
assert c.stringWidth(text, "Helvetica-Bold", size) <= 60 * mm + 1e-6
def test_cartouche_title_avoids_north_arrow_column():
"""Le titre (et le sous-titre) de la cartouche ne doit jamais empiéter sur
la colonne réservée à la flèche du nord, en paysage comme en portrait."""
from reportlab.pdfgen import canvas as rl_canvas
from reportlab.lib.units import mm
from io import BytesIO
from lidar_pipeline.export_pdf import (
_cartouche_text_max_width, _fit_title, _panel_boxes, layout)
c = rl_canvas.Canvas(BytesIO())
long_title = "Relief orienté - " + ", ".join(f"{1050 + i:04d}_6882" for i in range(6))
for paper, orient, scale in (("A4", "paysage", 2000), ("A4", "portrait", 10000),
("A3", "portrait", 2000)):
lay = layout(paper, orient, scale)
_legend_box, _quality_box, cart_box = _panel_boxes(lay)
x, y, w, h = cart_box
max_w = _cartouche_text_max_width(w, mm)
txt, size = _fit_title(c, long_title, "Helvetica-Bold", 10, max_w)
title_right_mm = x + c.stringWidth(txt, "Helvetica-Bold", size) / mm
arrow_left_mm = (x + w - 8) - 1.8 # bord gauche du triangle de la flèche
assert title_right_mm <= arrow_left_mm, (paper, orient, scale)