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

@ -366,6 +366,15 @@ def _fit_title(c, text, font, size, max_width, min_size=7.0):
return text, size
_ARROW_COLUMN_MM = 16.0 # largeur (mm) réservée à la flèche du nord + son "N", coin haut droit
def _cartouche_text_max_width(w, mm):
"""Largeur (pt) disponible pour le titre/sous-titre de la cartouche, hors
colonne réservée à la flèche du nord (coin haut droit du bloc, même ligne)."""
return max(0.0, w - _ARROW_COLUMN_MM) * mm
def _draw_hatch(c, x, y, w, h, mm, step=3.0):
"""Hachures grises sur fond blanc (maille sans donnée), comme sur la carte."""
from reportlab.lib.colors import Color, white
@ -561,12 +570,17 @@ def _draw_cartouche(c, box, lay, bbox, cx, cy, title, now, mm):
"""Titre, échelle graphique et numérique, nord, date, source."""
from reportlab.lib.colors import black, white
x, y, w, h = box
txt, title_size = _fit_title(c, _pdf_text(title), "Helvetica-Bold", 10, w * mm)
# Titre et sous-titre partagent la ligne du haut avec la flèche du nord
# (coin haut droit) : largeur bornée pour ne jamais la chevaucher.
max_w_head = _cartouche_text_max_width(w, mm)
txt, title_size = _fit_title(c, _pdf_text(title), "Helvetica-Bold", 10, max_w_head)
c.setFillColor(black); c.setFont("Helvetica-Bold", title_size)
c.drawString(x * mm, (y + h - 5) * mm, txt)
c.setFont("Helvetica", 7)
c.drawString(x * mm, (y + h - 9) * mm,
_pdf_text(f"Échelle 1:{_fmt_int(lay.scale)} - {lay.paper} {lay.orient} - {lay.dpi} dpi"))
subtitle, subtitle_size = _fit_title(
c, _pdf_text(f"Échelle 1:{_fmt_int(lay.scale)} - {lay.paper} {lay.orient} - {lay.dpi} dpi"),
"Helvetica", 7, max_w_head, min_size=6.0)
c.setFont("Helvetica", subtitle_size)
c.drawString(x * mm, (y + h - 9) * mm, subtitle)
# Échelle graphique : longueur ronde ≤ 40 % de la largeur du bloc
max_m = w * 0.4 / 1000 * lay.scale
length = max((s for s in _SCALEBAR_STEPS if s <= max_m), default=_SCALEBAR_STEPS[0])