Sorts : relevé à partir des règles réparé, objets écartés, écoles remises en ordre
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 2m18s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 2m49s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 3m10s
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 2m18s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 2m49s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 3m10s
Presque tous les sorts proposés étaient écartés : la description reprise du livre commençait par une ligne trop courte (« 1 Action ») pour servir de passage cité. Relevé de sorts - Le passage cité prend le début de la description sur plusieurs lignes quand la première est trop courte. - La ligne de niveau placée au-dessus du nom (« TIER 2 ») ouvre la description du sort au lieu de finir celle du précédent ; le niveau y est lu avant celui du modèle. - Un objet magique n'est pas un sort : texte qui s'ouvre sur une rareté, « nom » qui n'est qu'un niveau, consigne au modèle ; les sections d'équipement ne sont plus cochées d'office. - Le modèle est relancé quand des titres de sorts restent sans réponse. - L'école se lit aussi dans un titre traduit ; la traduction des titres garde « › ». Lecture du PDF - Un grand titre dessiné après le texte qu'il coiffe est remis à sa place : les sorts d'une école n'étaient plus rangés sous le titre de l'école précédente. - Des lignes de blocs différents ne forment une rangée de tableau que si leurs cellules se touchent presque ou si une rangée voisine est alignée ; deux intertitres à la même hauteur ne sont pas une rangée.
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.infrastructure.pdf_layout import (
|
||||
CELL_SEPARATOR, LayoutBlock, LayoutLine, place_lines, reading_order, split_cells, without_overprints,
|
||||
CELL_SEPARATOR, LayoutBlock, LayoutLine, hoist_titles, place_lines, reading_order, split_cells,
|
||||
without_overprints,
|
||||
)
|
||||
|
||||
WIDTH, HEIGHT = 600.0, 800.0
|
||||
@@ -105,9 +106,31 @@ def test_cells_of_a_row_spread_over_several_blocks_are_gathered():
|
||||
block(40, 400, 120, 410, line(40, 400, 120, "Wooden Buckler")),
|
||||
block(300, 400, 320, 410, line(300, 400, 320, "+2")),
|
||||
block(500, 400, 540, 410, line(500, 400, 540, "5 gp")),
|
||||
block(40, 415, 120, 425, line(40, 415, 120, "Iron Shield")),
|
||||
block(300, 415, 320, 425, line(300, 415, 320, "+3")),
|
||||
block(500, 415, 540, 425, line(500, 415, 540, "20 gp")),
|
||||
]
|
||||
placed = place_lines(blocks, WIDTH, HEIGHT)
|
||||
assert placed[-1].text == "Wooden Buckler | +2 | 5 gp" and placed[-1].cells == 3
|
||||
assert [p.text for p in placed[-2:]] == ["Wooden Buckler | +2 | 5 gp", "Iron Shield | +3 | 20 gp"]
|
||||
assert placed[-1].cells == 3
|
||||
|
||||
|
||||
def test_two_lone_labels_at_the_same_height_are_not_a_table_row():
|
||||
"""Double colonne de sorts : « CANTRIP » ouvre un sort à gauche, « TIER 4 » un autre à droite."""
|
||||
blocks = [
|
||||
paragraph(40, 100, 560, 300),
|
||||
block(40, 400, 80, 408, line(40, 400, 80, "CANTRIP", 8.0)),
|
||||
block(40, 410, 260, 450, line(40, 410, 260, "Rebuke : la cible subit 1d8 dégâts radiants,"),
|
||||
line(40, 422, 260, "et ne peut plus attaquer ce tour.")),
|
||||
block(300, 400, 335, 408, line(300, 400, 335, "TIER 4", 8.0)),
|
||||
block(300, 410, 540, 450, line(300, 410, 540, "Shield of Justice : vos attaquants sont aveuglés"),
|
||||
line(300, 422, 540, "jusqu'à la fin de leur prochain tour.")),
|
||||
block(40, 520, 80, 528, line(40, 520, 80, "TIER 1", 8.0)),
|
||||
block(300, 520, 335, 528, line(300, 520, 335, "TIER 6", 8.0)),
|
||||
]
|
||||
read = [p.text for p in place_lines(blocks, WIDTH, HEIGHT)]
|
||||
assert "CANTRIP" in read and "TIER 4" in read and "TIER 1" in read and "TIER 6" in read
|
||||
assert not any(" | " in text for text in read)
|
||||
|
||||
|
||||
def test_lines_of_a_paragraph_are_never_pulled_into_a_neighbouring_row():
|
||||
@@ -118,6 +141,8 @@ def test_lines_of_a_paragraph_are_never_pulled_into_a_neighbouring_row():
|
||||
paragraph(40, 100, 560, 300),
|
||||
block(40, 395, 120, 405, line(40, 395, 120, "Wooden Buckler")),
|
||||
block(200, 395, 220, 405, line(200, 395, 220, "+2")),
|
||||
block(40, 410, 120, 420, line(40, 410, 120, "Iron Shield")),
|
||||
block(200, 410, 220, 420, line(200, 410, 220, "+3")),
|
||||
sidebar,
|
||||
]
|
||||
placed = place_lines(blocks, WIDTH, HEIGHT)
|
||||
@@ -146,6 +171,77 @@ def test_lines_at_the_top_and_bottom_of_the_page_are_flagged():
|
||||
assert [p.edge for p in place_lines(blocks, WIDTH, HEIGHT)] == [True, False, True]
|
||||
|
||||
|
||||
# --- grands titres dessinés après leur texte ---------------------------------------------------
|
||||
|
||||
def _spell(x0: float, y0: float, name: str) -> LayoutBlock:
|
||||
return block(x0, y0, x0 + 160, y0 + 60, LayoutLine(x0, y0, x0 + 160, y0 + 12, name, 12.0),
|
||||
line(x0, y0 + 14, x0 + 160, "Portée 8. Dégâts 2d12, puis la cible est entravée jusqu'à la fin."))
|
||||
|
||||
|
||||
def _big_title(x0: float, y0: float, text: str) -> LayoutBlock:
|
||||
return block(x0, y0, x0 + 150, y0 + 30, LayoutLine(x0, y0, x0 + 150, y0 + 30, text, 25.0))
|
||||
|
||||
|
||||
def test_a_big_title_drawn_after_the_text_it_heads_is_put_back_above_it():
|
||||
"""Double page d'un livre de sorts : chaque moitié a deux colonnes de sorts sous son titre,
|
||||
mais le PDF trace les sorts d'abord, le titre de l'école ensuite."""
|
||||
width, height = 840.0, 600.0
|
||||
radiant = [_spell(30, 80, "Rebuke"), _spell(30, 200, "Heal"), _spell(220, 80, "Vengeance")]
|
||||
necrotic = [block(450, 100, 475, 110, line(450, 100, 475, "CANTRIP", 7.5)),
|
||||
_spell(450, 115, "Entice"), _spell(640, 115, "Vigor Mortis")]
|
||||
radiant_title, necrotic_title = _big_title(150, 30, "Radiant Spells"), _big_title(570, 60, "Necrotic Spells")
|
||||
redeem = _spell(80, 520, "Redeem")
|
||||
drawn = [*radiant, radiant_title, redeem, *necrotic, necrotic_title]
|
||||
ordered = hoist_titles(drawn, width, height)
|
||||
assert ordered == [radiant_title, *radiant, redeem, necrotic_title, *necrotic]
|
||||
# Par place_lines, le texte suit : le titre de l'école précède ses sorts.
|
||||
read = [placed.text for placed in place_lines(drawn, width, height)]
|
||||
assert read.index("Radiant Spells") < read.index("Rebuke") < read.index("Redeem")
|
||||
assert read.index("Redeem") < read.index("Necrotic Spells") < read.index("CANTRIP") < read.index("Entice")
|
||||
|
||||
|
||||
def test_a_label_brushing_the_bottom_of_a_big_title_is_still_below_it():
|
||||
"""La boîte d'un titre de 25 points descend sous ses lettres : l'étiquette « CANTRIP » du
|
||||
premier sort la frôle, sans être au-dessus du titre."""
|
||||
title = _big_title(150, 30, "Radiant Spells") # boîte de 30 à 60
|
||||
label = block(30, 57, 60, 66, line(30, 57, 60, "CANTRIP", 7.5))
|
||||
spell = _spell(30, 70, "Rebuke")
|
||||
assert hoist_titles([label, spell, title], 840.0, 600.0) == [title, label, spell]
|
||||
|
||||
|
||||
def test_two_subheadings_at_the_same_height_in_two_columns_are_not_a_table_row():
|
||||
left = block(30, 200, 190, 212, LayoutLine(30, 200, 190, 212, "Heal | 1 Action", 12.0, 2))
|
||||
right = block(220, 200, 380, 212, LayoutLine(220, 200, 380, 212, "Sacrifice | 1 Action", 12.0, 2))
|
||||
texts_ = [paragraph(30, 216, 190, 260), paragraph(220, 216, 380, 260)]
|
||||
read = [placed.text for placed in place_lines([left, texts_[0], right, texts_[1]], 840.0, 600.0)]
|
||||
assert "Heal | 1 Action" in read and "Sacrifice | 1 Action" in read
|
||||
# Des cellules à la taille du texte courant restent une rangée.
|
||||
cells = [block(30, 300, 80, 310, line(30, 300, 80, "Épée")), block(110, 300, 160, 310, line(110, 300, 160, "1d8")),
|
||||
block(30, 314, 80, 324, line(30, 314, 80, "Dague")), block(110, 314, 160, 324, line(110, 314, 160, "1d4"))]
|
||||
assert "Épée | 1d8" in [placed.text for placed in place_lines([*texts_, *cells], 840.0, 600.0)]
|
||||
|
||||
|
||||
def test_a_title_already_in_place_or_heading_another_column_does_not_move():
|
||||
# Page simple, deux colonnes : le titre en tête de la seconde ne passe pas devant la première.
|
||||
first = [paragraph(40, 60, 280, 300), paragraph(40, 320, 280, 560)]
|
||||
title = _big_title(320, 60, "Magie")
|
||||
second = [paragraph(320, 100, 560, 300)]
|
||||
drawn = [*first, title, *second]
|
||||
assert hoist_titles(drawn, WIDTH, HEIGHT) == drawn
|
||||
# Un titre placé plus bas que ce qui le précède reste où il est.
|
||||
lower = [paragraph(40, 60, 560, 200), _big_title(40, 240, "Combat"), paragraph(40, 290, 560, 400)]
|
||||
assert hoist_titles(lower, WIDTH, HEIGHT) == lower
|
||||
|
||||
|
||||
def test_a_title_does_not_climb_over_a_block_that_spans_the_page():
|
||||
banner = paragraph(40, 200, 560, 240) # barre la page, sous le titre
|
||||
below = paragraph(40, 260, 280, 400)
|
||||
title = _big_title(40, 150, "Rituels")
|
||||
drawn = [paragraph(40, 60, 560, 120), banner, below, title]
|
||||
# Le titre remonte devant le bloc qu'il coiffe, pas au-delà de la bande qui barre la page.
|
||||
assert hoist_titles(drawn, WIDTH, HEIGHT) == [drawn[0], banner, title, below]
|
||||
|
||||
|
||||
def test_a_title_drawn_twice_at_the_same_place_is_read_once():
|
||||
title = line(50, 100, 120, "Notes", 18.0)
|
||||
twice = block(50, 100, 300, 140, title, LayoutLine(50.2, 100.1, 120.1, 118.0, "Notes", 18.0),
|
||||
|
||||
Reference in New Issue
Block a user