where = appearances.getOrDefault(r.anchor(), List.of());
+ b.append(TD_OPEN).append(where.isEmpty() ? "—" : String.join(", ", where)).append(TD_CLOSE);
+ }
+ b.append("| ").append(pageRef(r.anchor())).append(TD_TR_CLOSE);
+ }
+ b.append(TBODY_TABLE_CLOSE);
+ }
+
+ /**
+ * Ou apparait chaque adversaire : ancre de sa fiche ({@code enemy-}) -> scenes
+ * (renvois) qui le citent, dans la scene elle-meme ou dans l'une de ses pieces.
+ */
+ static Map> enemyAppearances(Structure st) {
+ Map> sceneIdsByEnemy = new LinkedHashMap<>();
+ Map byId = new LinkedHashMap<>();
+ for (SceneJpaEntity sc : scenesInOrder(st)) {
+ byId.put(sc.getId(), sc);
+ List ids = new ArrayList<>();
+ if (sc.getEnemyIds() != null) ids.addAll(sc.getEnemyIds());
+ if (sc.getRooms() != null) {
+ for (Room r : sc.getRooms()) if (r.getEnemyIds() != null) ids.addAll(r.getEnemyIds());
+ }
+ for (String id : ids) {
+ if (notBlank(id)) sceneIdsByEnemy.computeIfAbsent("enemy-" + id.trim(), k -> new LinkedHashSet<>()).add(sc.getId());
+ }
+ }
+ Map> out = new LinkedHashMap<>();
+ sceneIdsByEnemy.forEach((enemyAnchor, sceneIds) -> {
+ List refs = new ArrayList<>();
+ for (Long sid : sceneIds) {
+ String anchor = "scene-" + sid;
+ refs.add(xref(anchor, byId.get(sid).getName()) + " " + pageRef(anchor));
+ }
+ out.put(enemyAnchor, refs);
+ });
+ return out;
+ }
+
+ /** Toutes les scenes dans l'ordre du livret (arcs, chapitres, scenes). */
+ private static List scenesInOrder(Structure st) {
+ List out = new ArrayList<>();
+ for (ArcJpaEntity arc : st.arcs) {
+ for (ChapterJpaEntity ch : st.chaptersByArc.getOrDefault(arc.getId(), List.of())) {
+ out.addAll(st.scenesByChapter.getOrDefault(ch.getId(), List.of()));
+ }
+ }
+ return out;
+ }
+}
diff --git a/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportOptions.java b/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportOptions.java
index 2aa8516..53038bf 100644
--- a/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportOptions.java
+++ b/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportOptions.java
@@ -17,8 +17,12 @@ import java.util.Set;
public record PdfExportOptions(boolean gmContent, PageFormat format, boolean printFriendly,
Set sections, LoreScope loreScope) {
- /** Parties du livret qu'on peut inclure ou non. */
- public enum Section { NARRATIVE, QUESTS, NPCS, ENEMIES, TABLES, LORE }
+ /**
+ * Parties du livret qu'on peut inclure ou non. APPENDIX = annexes MJ (revelations et
+ * indices, index PNJ et adversaires ; jamais en version joueurs) ; MAPS = cartes en
+ * pleine page paysage (les scenes y renvoient au lieu de les afficher en petit).
+ */
+ public enum Section { NARRATIVE, QUESTS, NPCS, ENEMIES, TABLES, LORE, APPENDIX, MAPS }
/** Pages de lore exportées : toutes, ou seulement celles liées au contenu de la campagne. */
public enum LoreScope { ALL, LINKED }
@@ -28,12 +32,13 @@ public record PdfExportOptions(boolean gmContent, PageFormat format, boolean pri
* A5 : marges et corps réduits pour garder une ligne lisible sur une page étroite.
*/
public enum PageFormat {
- A4("A4", 21.0, 2.2, 1.7, 2.0, 10.0, 12.5),
- A5("A5", 14.8, 1.7, 1.3, 1.6, 9.0, 7.0),
- LETTER("letter", 21.59, 2.2, 1.8, 2.0, 10.0, 12.0);
+ A4("A4", 21.0, 29.7, 2.2, 1.7, 2.0, 10.0, 12.5),
+ A5("A5", 14.8, 21.0, 1.7, 1.3, 1.6, 9.0, 7.0),
+ LETTER("letter", 21.59, 27.94, 2.2, 1.8, 2.0, 10.0, 12.0);
final String cssSize;
final double widthCm;
+ final double heightCm;
final double marginTopCm;
final double marginSideCm;
final double marginBottomCm;
@@ -41,10 +46,11 @@ public record PdfExportOptions(boolean gmContent, PageFormat format, boolean pri
/** Hauteur max de l'illustration de couverture : la couverture tient sur une page. */
final double coverArtMaxCm;
- PageFormat(String cssSize, double widthCm, double marginTopCm, double marginSideCm,
+ PageFormat(String cssSize, double widthCm, double heightCm, double marginTopCm, double marginSideCm,
double marginBottomCm, double bodyPt, double coverArtMaxCm) {
this.cssSize = cssSize;
this.widthCm = widthCm;
+ this.heightCm = heightCm;
this.marginTopCm = marginTopCm;
this.marginSideCm = marginSideCm;
this.marginBottomCm = marginBottomCm;
@@ -52,6 +58,11 @@ public record PdfExportOptions(boolean gmContent, PageFormat format, boolean pri
this.coverArtMaxCm = coverArtMaxCm;
}
+ /** Largeur d'une page tournée en paysage (= hauteur en portrait). */
+ double landscapeWidthCm() {
+ return heightCm;
+ }
+
/** Largeur utile (page moins les deux marges latérales). */
double contentWidthCm() {
return widthCm - 2 * marginSideCm;
diff --git a/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportService.java b/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportService.java
index b5defdc..8fa2844 100644
--- a/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportService.java
+++ b/core/src/main/java/com/loremind/infrastructure/transfer/pdf/PdfExportService.java
@@ -178,11 +178,13 @@ public class PdfExportService {
* Contexte de rendu : les sections ecrivent leur corps et alimentent les signets,
* le sommaire et les compteurs (repris ensuite sur la couverture).
*/
- private static final class Ctx {
+ static final class Ctx {
final PdfExportOptions opt;
/** Version MJ : les contenus reserves au MJ (secrets, consequences, combats...) sont rendus. */
final boolean gm;
final StringBuilder body = new StringBuilder();
+ /** Cartes rendues en annexe (par scene), ou null si l'annexe Cartes n'est pas demandee. */
+ Map> maps;
final StringBuilder bookmarks = new StringBuilder();
final List toc = new ArrayList<>();
int scenes;
@@ -226,33 +228,60 @@ public class PdfExportService {
// et le sommaire sont assembles ensuite en tete de document.
Structure st = structureLoader.load(campaign);
Ctx ctx = new Ctx(opt);
+ // Cartes encodees d'abord : les scenes y renvoient au lieu de les afficher en petit.
+ if (opt.includes(Section.MAPS)) ctx.maps = PdfAppendices.collectMaps(st, imageEncoder);
+ List npcRows = opt.includes(Section.NPCS) ? npcEntries(campaign) : List.of();
+ List enemyRows = opt.includes(Section.ENEMIES) ? enemyEntries(campaign) : List.of();
introduction(ctx, campaign, pub, st);
if (opt.includes(Section.NARRATIVE)) narrative(ctx, st);
if (opt.includes(Section.QUESTS)) {
ctx.quests = st.quests.size();
quests(ctx, st);
}
- if (opt.includes(Section.NPCS)) {
- personas(ctx, "part-npcs", "Personnages non-joueurs (PNJ)", npcEntries(campaign), npcTemplate, false);
- }
- if (opt.includes(Section.ENEMIES)) {
- personas(ctx, "part-enemies", "Bestiaire", enemyEntries(campaign), enemyTemplate, true);
- }
+ personas(ctx, "part-npcs", "Personnages non-joueurs (PNJ)", npcRows, npcTemplate, false);
+ personas(ctx, "part-enemies", "Bestiaire", enemyRows, enemyTemplate, true);
if (opt.includes(Section.TABLES)) randomTables(ctx, campaign);
if (opt.includes(Section.LORE)) lore(ctx, campaign, st);
+ if (opt.includes(Section.APPENDIX) && ctx.gm) appendix(ctx, st, npcRows, enemyRows);
+ if (ctx.maps != null) PdfAppendices.mapsPart(ctx, ctx.maps);
StringBuilder full = new StringBuilder();
cover(full, ctx, campaign, pub);
creditsPage(full, campaign, pub);
full.append(tocHtml(ctx.toc));
full.append(ctx.body);
+ String body = resolveRefs(full.toString());
return "\n"
+ "\n"
+ documentInfo(campaign, pub)
+ "\n"
+ "" + ctx.bookmarks + "\n"
- + "" + full + "";
+ + "" + body + " |