@nomad-e/bluma-cli 0.26.3 → 2026.27.0-darwin-arm64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +189 -70
- package/README.md +2 -162
- package/THIRD-PARTY-NOTICES.txt +46201 -0
- package/bin/bluma-core +0 -0
- package/package.json +24 -124
- package/third-party/option-ext/.cargo_vcs_info.json +6 -0
- package/third-party/option-ext/Cargo.toml +22 -0
- package/third-party/option-ext/LICENSE.txt +373 -0
- package/third-party/option-ext/README.md +67 -0
- package/third-party/option-ext/src/impl.rs +20 -0
- package/third-party/option-ext/src/lib.rs +71 -0
- package/assets/bg.png +0 -0
- package/assets/bg1.png +0 -0
- package/assets/bluma.png +0 -0
- package/assets/image.png +0 -0
- package/dist/assets/bg.png +0 -0
- package/dist/assets/bg1.png +0 -0
- package/dist/assets/bluma.png +0 -0
- package/dist/assets/image.png +0 -0
- package/dist/config/native_tools.json +0 -1151
- package/dist/config/plan_mode_instructions.md +0 -218
- package/dist/config/skills/factorai-sh/SKILL.md +0 -98
- package/dist/config/skills/git-commit/LICENSE.txt +0 -18
- package/dist/config/skills/git-commit/SKILL.md +0 -300
- package/dist/config/skills/git-commit/references/REFERENCE.md +0 -253
- package/dist/config/skills/git-commit/scripts/validate_commit_msg.py +0 -163
- package/dist/config/skills/git-pr/LICENSE.txt +0 -18
- package/dist/config/skills/git-pr/SKILL.md +0 -293
- package/dist/config/skills/git-pr/references/REFERENCE.md +0 -256
- package/dist/config/skills/git-pr/scripts/validate_commits.py +0 -120
- package/dist/config/skills/git-release/LICENSE.txt +0 -18
- package/dist/config/skills/git-release/SKILL.md +0 -408
- package/dist/config/skills/pdf/LICENSE.txt +0 -26
- package/dist/config/skills/pdf/SKILL.md +0 -736
- package/dist/config/skills/pdf/references/DOCUMENT_TYPES.md +0 -59
- package/dist/config/skills/pdf/references/FORMS.md +0 -69
- package/dist/config/skills/pdf/references/REFERENCE.md +0 -52
- package/dist/config/skills/pdf/scripts/__pycache__/create_report.cpython-312.pyc +0 -0
- package/dist/config/skills/pdf/scripts/create_report.py +0 -936
- package/dist/config/skills/pdf/scripts/merge_pdfs.py +0 -48
- package/dist/config/skills/skill-creator/LICENSE.txt +0 -26
- package/dist/config/skills/skill-creator/SKILL.md +0 -229
- package/dist/config/skills/xlsx/LICENSE.txt +0 -18
- package/dist/config/skills/xlsx/SKILL.md +0 -340
- package/dist/config/skills/xlsx/references/REFERENCE.md +0 -337
- package/dist/config/skills/xlsx/scripts/office/__init__.py +0 -2
- package/dist/config/skills/xlsx/scripts/office/pack.py +0 -58
- package/dist/config/skills/xlsx/scripts/office/soffice.py +0 -180
- package/dist/config/skills/xlsx/scripts/office/unpack.py +0 -63
- package/dist/config/skills/xlsx/scripts/office/validate.py +0 -122
- package/dist/config/skills/xlsx/scripts/recalc.py +0 -152
- package/dist/main.js +0 -47932
- package/dist/native/bluma-clipboard.linux-x64-gnu.node +0 -0
- package/dist/native/index.d.ts +0 -38
- package/dist/native/index.js +0 -319
- package/dist/native/package.json +0 -38
- package/dist/scaffold/.eslintrc.json +0 -3
- package/dist/scaffold/app/globals.css +0 -46
- package/dist/scaffold/app/layout.tsx +0 -19
- package/dist/scaffold/app/page.tsx +0 -124
- package/dist/scaffold/components/ui/README.md +0 -12
- package/dist/scaffold/components/ui/accordion.jsx +0 -42
- package/dist/scaffold/components/ui/alert-dialog.jsx +0 -80
- package/dist/scaffold/components/ui/alert.jsx +0 -33
- package/dist/scaffold/components/ui/aspect-ratio.jsx +0 -5
- package/dist/scaffold/components/ui/avatar.jsx +0 -28
- package/dist/scaffold/components/ui/badge.jsx +0 -24
- package/dist/scaffold/components/ui/breadcrumb.jsx +0 -72
- package/dist/scaffold/components/ui/button.jsx +0 -40
- package/dist/scaffold/components/ui/calendar.jsx +0 -56
- package/dist/scaffold/components/ui/card.jsx +0 -38
- package/dist/scaffold/components/ui/carousel.jsx +0 -168
- package/dist/scaffold/components/ui/chart.jsx +0 -76
- package/dist/scaffold/components/ui/checkbox.jsx +0 -22
- package/dist/scaffold/components/ui/collapsible.jsx +0 -7
- package/dist/scaffold/components/ui/command.jsx +0 -100
- package/dist/scaffold/components/ui/context-menu.jsx +0 -137
- package/dist/scaffold/components/ui/dialog.jsx +0 -72
- package/dist/scaffold/components/ui/drawer.jsx +0 -68
- package/dist/scaffold/components/ui/dropdown-menu.jsx +0 -143
- package/dist/scaffold/components/ui/form.jsx +0 -88
- package/dist/scaffold/components/ui/hover-card.jsx +0 -22
- package/dist/scaffold/components/ui/input-otp.jsx +0 -49
- package/dist/scaffold/components/ui/input.jsx +0 -19
- package/dist/scaffold/components/ui/label.jsx +0 -15
- package/dist/scaffold/components/ui/menubar.jsx +0 -161
- package/dist/scaffold/components/ui/navigation-menu.jsx +0 -95
- package/dist/scaffold/components/ui/pagination.jsx +0 -77
- package/dist/scaffold/components/ui/popover.jsx +0 -25
- package/dist/scaffold/components/ui/progress.jsx +0 -19
- package/dist/scaffold/components/ui/radio-group.jsx +0 -29
- package/dist/scaffold/components/ui/resizable.jsx +0 -27
- package/dist/scaffold/components/ui/scroll-area.jsx +0 -31
- package/dist/scaffold/components/ui/select.jsx +0 -117
- package/dist/scaffold/components/ui/separator.jsx +0 -22
- package/dist/scaffold/components/ui/sheet.jsx +0 -81
- package/dist/scaffold/components/ui/skeleton.jsx +0 -7
- package/dist/scaffold/components/ui/slider.jsx +0 -19
- package/dist/scaffold/components/ui/sonner.jsx +0 -22
- package/dist/scaffold/components/ui/switch.jsx +0 -23
- package/dist/scaffold/components/ui/table.jsx +0 -61
- package/dist/scaffold/components/ui/tabs.jsx +0 -43
- package/dist/scaffold/components/ui/textarea.jsx +0 -18
- package/dist/scaffold/components/ui/toast.jsx +0 -85
- package/dist/scaffold/components/ui/toaster.jsx +0 -33
- package/dist/scaffold/components/ui/toggle-group.jsx +0 -41
- package/dist/scaffold/components/ui/toggle.jsx +0 -30
- package/dist/scaffold/components/ui/tooltip.jsx +0 -22
- package/dist/scaffold/hooks/use-toast.ts +0 -101
- package/dist/scaffold/lib/utils.ts +0 -6
- package/dist/scaffold/next.config.js +0 -5
- package/dist/scaffold/next.config.mjs +0 -15
- package/dist/scaffold/next.config.ts +0 -19
- package/dist/scaffold/package.json +0 -70
- package/dist/scaffold/postcss.config.js +0 -6
- package/dist/scaffold/tailwind.config.ts +0 -57
- package/dist/scaffold/tsconfig.json +0 -20
|
@@ -1,936 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Professional PDF Report Generator — BluMa Template
|
|
4
|
-
|
|
5
|
-
Usage:
|
|
6
|
-
Demo (sample content):
|
|
7
|
-
python create_report.py [--title TITLE] [--subtitle SUBTITLE] [--output FILE]
|
|
8
|
-
|
|
9
|
-
Production (your content, same visual system):
|
|
10
|
-
python create_report.py --from-json report.json --output .bluma/artifacts/relatorio.pdf
|
|
11
|
-
|
|
12
|
-
JSON schema (UTF-8 file):
|
|
13
|
-
{
|
|
14
|
-
"document_type": "technical",
|
|
15
|
-
"title": "Relatório",
|
|
16
|
-
"subtitle": "Subtítulo opcional",
|
|
17
|
-
"author": "Equipe / Cliente (opcional)",
|
|
18
|
-
"letterhead": {
|
|
19
|
-
"organization": "Empresa",
|
|
20
|
-
"address_lines": ["Morada"],
|
|
21
|
-
"logo_path": ".bluma/artifacts/logo.png"
|
|
22
|
-
},
|
|
23
|
-
"layout": { "include_toc": true, "page_break_per_section": false },
|
|
24
|
-
"sections": [
|
|
25
|
-
{
|
|
26
|
-
"num": 1,
|
|
27
|
-
"title": "Introdução",
|
|
28
|
-
"blocks": [
|
|
29
|
-
{ "type": "paragraph", "text": "Texto com quebras\\nlinha." },
|
|
30
|
-
{ "type": "callout", "title": "Destaque", "text": "...", "variant": "info" },
|
|
31
|
-
{ "type": "bullets", "items": ["Item A", "Item B"] },
|
|
32
|
-
{ "type": "table", "headers": ["Col1", "Col2"], "rows": [["a", "b"]], "col_widths": null }
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
variant for callout: "info" | "warning" | "plain_language" | "technical_note"
|
|
39
|
-
Top-level audience: "technical" | "mixed" | "general"
|
|
40
|
-
Text in JSON is escaped for XML/HTML safety; use plain text, not ReportLab tags.
|
|
41
|
-
|
|
42
|
-
Editorial guidance for agents (structure, copy, restraint): see pdf/SKILL.md
|
|
43
|
-
section "JSON quality — make the PDF look designed".
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
from __future__ import annotations
|
|
47
|
-
|
|
48
|
-
import argparse
|
|
49
|
-
import json
|
|
50
|
-
import sys
|
|
51
|
-
from datetime import date
|
|
52
|
-
from pathlib import Path
|
|
53
|
-
from typing import Any
|
|
54
|
-
from xml.sax.saxutils import escape
|
|
55
|
-
|
|
56
|
-
MIN_PYTHON = (3, 10)
|
|
57
|
-
if sys.version_info < MIN_PYTHON:
|
|
58
|
-
print(
|
|
59
|
-
f"Error: Python {'.'.join(map(str, MIN_PYTHON))}+ is required "
|
|
60
|
-
f"(found {'.'.join(map(str, sys.version_info[:3]))})",
|
|
61
|
-
file=sys.stderr,
|
|
62
|
-
)
|
|
63
|
-
sys.exit(1)
|
|
64
|
-
|
|
65
|
-
try:
|
|
66
|
-
from reportlab.lib.pagesizes import A4
|
|
67
|
-
from reportlab.lib.units import cm
|
|
68
|
-
except ImportError:
|
|
69
|
-
print(
|
|
70
|
-
"Error: reportlab is required. Install with: pip install reportlab",
|
|
71
|
-
file=sys.stderr,
|
|
72
|
-
)
|
|
73
|
-
sys.exit(1)
|
|
74
|
-
from reportlab.lib.colors import HexColor
|
|
75
|
-
from reportlab.lib.styles import ParagraphStyle
|
|
76
|
-
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY
|
|
77
|
-
from reportlab.platypus import (
|
|
78
|
-
SimpleDocTemplate,
|
|
79
|
-
Paragraph,
|
|
80
|
-
Spacer,
|
|
81
|
-
PageBreak,
|
|
82
|
-
Table,
|
|
83
|
-
TableStyle,
|
|
84
|
-
HRFlowable,
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
# ── Color Palette ──────────────────────────────────────────────
|
|
89
|
-
|
|
90
|
-
COLORS = {
|
|
91
|
-
"primary": HexColor("#0F172A"), # slate-900 — mais editorial que navy genérico
|
|
92
|
-
"secondary": HexColor("#334155"), # slate-700
|
|
93
|
-
"accent": HexColor("#C2410C"), # laranja queimado — menos “banner de site”
|
|
94
|
-
"muted": HexColor("#64748B"),
|
|
95
|
-
"text": HexColor("#1E293B"),
|
|
96
|
-
"text_light": HexColor("#64748B"),
|
|
97
|
-
"bg_light": HexColor("#F1F5F9"),
|
|
98
|
-
"bg_accent": HexColor("#E0F2FE"),
|
|
99
|
-
"border": HexColor("#CBD5E1"),
|
|
100
|
-
"white": HexColor("#FFFFFF"),
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
# ── Typography ─────────────────────────────────────────────────
|
|
104
|
-
|
|
105
|
-
FONT = "Helvetica"
|
|
106
|
-
FONT_B = "Helvetica-Bold"
|
|
107
|
-
FONT_I = "Helvetica-Oblique"
|
|
108
|
-
|
|
109
|
-
PAGE_W, PAGE_H = A4
|
|
110
|
-
M = 2.5 * cm
|
|
111
|
-
CW = PAGE_W - 2 * M
|
|
112
|
-
|
|
113
|
-
S = {
|
|
114
|
-
"title": ParagraphStyle(
|
|
115
|
-
"T",
|
|
116
|
-
fontName=FONT_B,
|
|
117
|
-
fontSize=26,
|
|
118
|
-
leading=31,
|
|
119
|
-
textColor=COLORS["primary"],
|
|
120
|
-
alignment=TA_CENTER,
|
|
121
|
-
spaceAfter=8,
|
|
122
|
-
),
|
|
123
|
-
"subtitle": ParagraphStyle(
|
|
124
|
-
"ST",
|
|
125
|
-
fontName=FONT,
|
|
126
|
-
fontSize=13,
|
|
127
|
-
leading=17,
|
|
128
|
-
textColor=COLORS["secondary"],
|
|
129
|
-
alignment=TA_CENTER,
|
|
130
|
-
spaceAfter=6,
|
|
131
|
-
),
|
|
132
|
-
"h1": ParagraphStyle(
|
|
133
|
-
"H1",
|
|
134
|
-
fontName=FONT_B,
|
|
135
|
-
fontSize=18,
|
|
136
|
-
leading=24,
|
|
137
|
-
textColor=COLORS["primary"],
|
|
138
|
-
spaceBefore=22,
|
|
139
|
-
spaceAfter=10,
|
|
140
|
-
),
|
|
141
|
-
# Cabeçalho de capítulo (sem spaceBefore — evita “buraco” dentro da tabela)
|
|
142
|
-
"h1_sec": ParagraphStyle(
|
|
143
|
-
"H1Sec",
|
|
144
|
-
fontName=FONT_B,
|
|
145
|
-
fontSize=17,
|
|
146
|
-
leading=22,
|
|
147
|
-
textColor=COLORS["primary"],
|
|
148
|
-
spaceBefore=0,
|
|
149
|
-
spaceAfter=0,
|
|
150
|
-
),
|
|
151
|
-
"h2": ParagraphStyle(
|
|
152
|
-
"H2",
|
|
153
|
-
fontName=FONT_B,
|
|
154
|
-
fontSize=13,
|
|
155
|
-
leading=18,
|
|
156
|
-
textColor=COLORS["secondary"],
|
|
157
|
-
spaceBefore=16,
|
|
158
|
-
spaceAfter=6,
|
|
159
|
-
),
|
|
160
|
-
"body": ParagraphStyle(
|
|
161
|
-
"B",
|
|
162
|
-
fontName=FONT,
|
|
163
|
-
fontSize=10.5,
|
|
164
|
-
leading=15,
|
|
165
|
-
textColor=COLORS["text"],
|
|
166
|
-
alignment=TA_JUSTIFY,
|
|
167
|
-
spaceBefore=2,
|
|
168
|
-
spaceAfter=8,
|
|
169
|
-
),
|
|
170
|
-
"bullet": ParagraphStyle(
|
|
171
|
-
"BL",
|
|
172
|
-
fontName=FONT,
|
|
173
|
-
fontSize=10.5,
|
|
174
|
-
leading=15,
|
|
175
|
-
textColor=COLORS["text"],
|
|
176
|
-
leftIndent=18,
|
|
177
|
-
bulletIndent=8,
|
|
178
|
-
spaceBefore=1,
|
|
179
|
-
spaceAfter=3,
|
|
180
|
-
),
|
|
181
|
-
"meta": ParagraphStyle(
|
|
182
|
-
"M",
|
|
183
|
-
fontName=FONT,
|
|
184
|
-
fontSize=10,
|
|
185
|
-
textColor=COLORS["text_light"],
|
|
186
|
-
alignment=TA_CENTER,
|
|
187
|
-
spaceAfter=4,
|
|
188
|
-
),
|
|
189
|
-
"date": ParagraphStyle(
|
|
190
|
-
"D",
|
|
191
|
-
fontName=FONT,
|
|
192
|
-
fontSize=9.5,
|
|
193
|
-
textColor=COLORS["muted"],
|
|
194
|
-
alignment=TA_CENTER,
|
|
195
|
-
),
|
|
196
|
-
"toc": ParagraphStyle(
|
|
197
|
-
"TOC",
|
|
198
|
-
fontName=FONT,
|
|
199
|
-
fontSize=10.5,
|
|
200
|
-
leading=18,
|
|
201
|
-
textColor=COLORS["text"],
|
|
202
|
-
),
|
|
203
|
-
"toc_b": ParagraphStyle(
|
|
204
|
-
"TOCB",
|
|
205
|
-
fontName=FONT_B,
|
|
206
|
-
fontSize=10.5,
|
|
207
|
-
leading=18,
|
|
208
|
-
textColor=COLORS["primary"],
|
|
209
|
-
),
|
|
210
|
-
"cell": ParagraphStyle(
|
|
211
|
-
"Cell",
|
|
212
|
-
fontName=FONT,
|
|
213
|
-
fontSize=8.5,
|
|
214
|
-
leading=11,
|
|
215
|
-
textColor=COLORS["text"],
|
|
216
|
-
alignment=TA_JUSTIFY,
|
|
217
|
-
),
|
|
218
|
-
"letterhead_org": ParagraphStyle(
|
|
219
|
-
"LHOrg",
|
|
220
|
-
fontName=FONT_B,
|
|
221
|
-
fontSize=11,
|
|
222
|
-
leading=14,
|
|
223
|
-
textColor=COLORS["primary"],
|
|
224
|
-
alignment=TA_CENTER,
|
|
225
|
-
spaceAfter=2,
|
|
226
|
-
),
|
|
227
|
-
"letterhead_meta": ParagraphStyle(
|
|
228
|
-
"LHMeta",
|
|
229
|
-
fontName=FONT,
|
|
230
|
-
fontSize=8.5,
|
|
231
|
-
leading=11,
|
|
232
|
-
textColor=COLORS["muted"],
|
|
233
|
-
alignment=TA_CENTER,
|
|
234
|
-
spaceAfter=2,
|
|
235
|
-
),
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
def _resolve_layout(data: dict[str, Any]) -> dict[str, Any]:
|
|
240
|
-
"""Merge document_type presets with explicit layout / letterhead overrides."""
|
|
241
|
-
doc_type = str(data.get("document_type") or "executive_report").strip().lower()
|
|
242
|
-
layout = dict(data.get("layout") or {})
|
|
243
|
-
letterhead = dict(data.get("letterhead") or {})
|
|
244
|
-
|
|
245
|
-
presets: dict[str, dict[str, Any]] = {
|
|
246
|
-
"executive_report": {
|
|
247
|
-
"include_toc": True,
|
|
248
|
-
"page_break_per_section": True,
|
|
249
|
-
"cover_style": "corporate",
|
|
250
|
-
"use_letterhead_band": False,
|
|
251
|
-
},
|
|
252
|
-
"technical": {
|
|
253
|
-
"include_toc": True,
|
|
254
|
-
"page_break_per_section": False,
|
|
255
|
-
"cover_style": "minimal",
|
|
256
|
-
"use_letterhead_band": False,
|
|
257
|
-
},
|
|
258
|
-
"letterhead": {
|
|
259
|
-
"include_toc": True,
|
|
260
|
-
"page_break_per_section": False,
|
|
261
|
-
"cover_style": "letterhead",
|
|
262
|
-
"use_letterhead_band": True,
|
|
263
|
-
},
|
|
264
|
-
"memo": {
|
|
265
|
-
"include_toc": False,
|
|
266
|
-
"page_break_per_section": False,
|
|
267
|
-
"cover_style": "minimal",
|
|
268
|
-
"use_letterhead_band": False,
|
|
269
|
-
},
|
|
270
|
-
"article": {
|
|
271
|
-
"include_toc": False,
|
|
272
|
-
"page_break_per_section": False,
|
|
273
|
-
"cover_style": "minimal",
|
|
274
|
-
"use_letterhead_band": False,
|
|
275
|
-
},
|
|
276
|
-
}
|
|
277
|
-
base = dict(presets.get(doc_type, presets["executive_report"]))
|
|
278
|
-
for key in ("include_toc", "page_break_per_section", "cover_style", "use_letterhead_band"):
|
|
279
|
-
if key in layout:
|
|
280
|
-
base[key] = layout[key]
|
|
281
|
-
audience = str(data.get("audience") or layout.get("audience") or "technical").strip().lower()
|
|
282
|
-
if audience not in ("technical", "mixed", "general"):
|
|
283
|
-
audience = "mixed" if audience in ("lay", "public", "mixed_audience") else "technical"
|
|
284
|
-
base["document_type"] = doc_type
|
|
285
|
-
base["letterhead"] = letterhead
|
|
286
|
-
base["audience"] = audience
|
|
287
|
-
return base
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
def _section_char_count(sec: dict[str, Any]) -> int:
|
|
291
|
-
total = len(str(sec.get("title") or ""))
|
|
292
|
-
for block in sec.get("blocks") or []:
|
|
293
|
-
if not isinstance(block, dict):
|
|
294
|
-
continue
|
|
295
|
-
btype = block.get("type")
|
|
296
|
-
if btype == "paragraph":
|
|
297
|
-
total += len(str(block.get("text") or ""))
|
|
298
|
-
elif btype == "bullets":
|
|
299
|
-
total += sum(len(str(x)) for x in (block.get("items") or []))
|
|
300
|
-
elif btype == "table":
|
|
301
|
-
total += 120 * len(block.get("rows") or [])
|
|
302
|
-
elif btype == "callout":
|
|
303
|
-
total += len(str(block.get("text") or ""))
|
|
304
|
-
return total
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
def _should_page_break_before_section(
|
|
308
|
-
sec: dict[str, Any], *, page_per_section: bool, index: int
|
|
309
|
-
) -> bool:
|
|
310
|
-
if index == 0 or not page_per_section:
|
|
311
|
-
return False
|
|
312
|
-
# Evita páginas quase vazias: só quebra se a secção anterior tinha conteúdo denso
|
|
313
|
-
return _section_char_count(sec) >= 280 or len(sec.get("blocks") or []) >= 3
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
def _ptext(s: str) -> str:
|
|
317
|
-
"""Plain text → safe Paragraph markup (preserva quebras como <br/>)."""
|
|
318
|
-
if s is None:
|
|
319
|
-
return ""
|
|
320
|
-
return escape(str(s)).replace("\n", "<br/>")
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
def _cover_title_paragraph(title: str) -> Paragraph:
|
|
324
|
-
"""Título da capa: tamanho adaptável + quebra em duas linhas equilibradas."""
|
|
325
|
-
raw = (title or "").strip()
|
|
326
|
-
if not raw:
|
|
327
|
-
return Paragraph("", S["title"])
|
|
328
|
-
if "\n" in raw:
|
|
329
|
-
return Paragraph(_ptext(raw), S["title"])
|
|
330
|
-
n = len(raw)
|
|
331
|
-
if n > 56:
|
|
332
|
-
fs, ld = 17, 21
|
|
333
|
-
elif n > 42:
|
|
334
|
-
fs, ld = 20, 25
|
|
335
|
-
else:
|
|
336
|
-
fs, ld = 26, 31
|
|
337
|
-
sty = ParagraphStyle(
|
|
338
|
-
"TCoverDyn",
|
|
339
|
-
fontName=FONT_B,
|
|
340
|
-
fontSize=fs,
|
|
341
|
-
leading=ld,
|
|
342
|
-
textColor=COLORS["primary"],
|
|
343
|
-
alignment=TA_CENTER,
|
|
344
|
-
spaceAfter=8,
|
|
345
|
-
)
|
|
346
|
-
# Duas linhas com comprimento o mais equilibrado possível (evita órfãos)
|
|
347
|
-
if n > 28 and " " in raw:
|
|
348
|
-
words = raw.split()
|
|
349
|
-
if len(words) >= 2:
|
|
350
|
-
best_cut, best_diff = 1, 10**9
|
|
351
|
-
for cut in range(1, len(words)):
|
|
352
|
-
a = len(" ".join(words[:cut]))
|
|
353
|
-
b = len(" ".join(words[cut:]))
|
|
354
|
-
diff = abs(a - b)
|
|
355
|
-
if diff < best_diff:
|
|
356
|
-
best_diff = diff
|
|
357
|
-
best_cut = cut
|
|
358
|
-
last_w = words[best_cut]
|
|
359
|
-
if best_cut > 1 and len(words[best_cut:]) == 1 and len(last_w) <= 10:
|
|
360
|
-
best_cut -= 1
|
|
361
|
-
if 1 <= best_cut < len(words):
|
|
362
|
-
line1 = " ".join(words[:best_cut])
|
|
363
|
-
line2 = " ".join(words[best_cut:])
|
|
364
|
-
markup = _ptext(line1) + "<br/>" + _ptext(line2)
|
|
365
|
-
return Paragraph(markup, sty)
|
|
366
|
-
return Paragraph(_ptext(raw), sty)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
def _normalize_col_widths(
|
|
370
|
-
widths: list[float] | None, ncols: int
|
|
371
|
-
) -> list[float]:
|
|
372
|
-
if not widths or len(widths) != ncols:
|
|
373
|
-
return [CW / ncols] * ncols
|
|
374
|
-
s = sum(float(w) for w in widths)
|
|
375
|
-
if s <= 0:
|
|
376
|
-
return [CW / ncols] * ncols
|
|
377
|
-
scale = CW / s
|
|
378
|
-
return [float(w) * scale for w in widths]
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
# ── Cover (story + canvas) ─────────────────────────────────────
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
def _letterhead_block_story(story: list, letterhead: dict[str, Any]) -> None:
|
|
385
|
-
org = str(letterhead.get("organization") or "").strip()
|
|
386
|
-
if org:
|
|
387
|
-
story.append(Paragraph(_ptext(org), S["letterhead_org"]))
|
|
388
|
-
for key in ("department", "tagline"):
|
|
389
|
-
line = str(letterhead.get(key) or "").strip()
|
|
390
|
-
if line:
|
|
391
|
-
story.append(Paragraph(_ptext(line), S["letterhead_meta"]))
|
|
392
|
-
for line in letterhead.get("address_lines") or []:
|
|
393
|
-
if str(line).strip():
|
|
394
|
-
story.append(Paragraph(_ptext(str(line)), S["letterhead_meta"]))
|
|
395
|
-
contact = str(letterhead.get("contact") or "").strip()
|
|
396
|
-
if contact:
|
|
397
|
-
story.append(Paragraph(_ptext(contact), S["letterhead_meta"]))
|
|
398
|
-
logo_path = letterhead.get("logo_path")
|
|
399
|
-
if logo_path and Path(str(logo_path)).is_file():
|
|
400
|
-
try:
|
|
401
|
-
from reportlab.platypus import Image
|
|
402
|
-
|
|
403
|
-
story.append(Spacer(1, 0.3 * cm))
|
|
404
|
-
img = Image(str(logo_path), width=3.2 * cm, height=1.2 * cm, kind="proportional")
|
|
405
|
-
img.hAlign = "CENTER"
|
|
406
|
-
story.append(img)
|
|
407
|
-
except Exception:
|
|
408
|
-
pass
|
|
409
|
-
story.append(Spacer(1, 0.6 * cm))
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
def cover_story(
|
|
413
|
-
story: list,
|
|
414
|
-
title: str,
|
|
415
|
-
subtitle: str | None,
|
|
416
|
-
author: str | None,
|
|
417
|
-
*,
|
|
418
|
-
cover_style: str = "corporate",
|
|
419
|
-
letterhead: dict[str, Any] | None = None,
|
|
420
|
-
) -> None:
|
|
421
|
-
lh = letterhead or {}
|
|
422
|
-
if cover_style == "letterhead" and lh:
|
|
423
|
-
story.append(Spacer(1, 1.2 * cm))
|
|
424
|
-
_letterhead_block_story(story, lh)
|
|
425
|
-
story.append(Spacer(1, 2.2 * cm))
|
|
426
|
-
elif cover_style == "minimal":
|
|
427
|
-
story.append(Spacer(1, 4.5 * cm))
|
|
428
|
-
else:
|
|
429
|
-
story.append(Spacer(1, 5.5 * cm))
|
|
430
|
-
story.append(_cover_title_paragraph(title))
|
|
431
|
-
if subtitle:
|
|
432
|
-
story.append(Paragraph(_ptext(subtitle), S["subtitle"]))
|
|
433
|
-
story.append(Spacer(1, 0.4 * cm))
|
|
434
|
-
story.append(
|
|
435
|
-
HRFlowable(
|
|
436
|
-
width="32%",
|
|
437
|
-
thickness=1.5,
|
|
438
|
-
color=COLORS["accent"],
|
|
439
|
-
spaceAfter=22,
|
|
440
|
-
spaceBefore=6,
|
|
441
|
-
)
|
|
442
|
-
)
|
|
443
|
-
story.append(Spacer(1, 2.8 * cm))
|
|
444
|
-
if author:
|
|
445
|
-
story.append(Paragraph(_ptext(author), S["meta"]))
|
|
446
|
-
story.append(Paragraph(_ptext(date.today().strftime("%d %B %Y")), S["date"]))
|
|
447
|
-
story.append(PageBreak())
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
def draw_cover_canvas(canvas_obj, doc) -> None:
|
|
451
|
-
"""Barra lateral de marca + filete superior — só na capa (texto segue no fluxo)."""
|
|
452
|
-
canvas_obj.saveState()
|
|
453
|
-
canvas_obj.setFillColor(COLORS["primary"])
|
|
454
|
-
canvas_obj.rect(0, 0, 0.55 * cm, PAGE_H, fill=1, stroke=0)
|
|
455
|
-
canvas_obj.setStrokeColor(COLORS["accent"])
|
|
456
|
-
canvas_obj.setLineWidth(2.5)
|
|
457
|
-
canvas_obj.line(M, PAGE_H - M, PAGE_W - M, PAGE_H - M)
|
|
458
|
-
canvas_obj.restoreState()
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
# ── TOC & body ─────────────────────────────────────────────────
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
def toc(story: list, sections: list[dict[str, Any]]) -> None:
|
|
465
|
-
"""Sumário limpo — sem linhas horizontais a atravessar a página inteira."""
|
|
466
|
-
story.append(Paragraph("Sumário", S["h1"]))
|
|
467
|
-
story.append(Spacer(1, 0.35 * cm))
|
|
468
|
-
for sec in sections:
|
|
469
|
-
style = S["toc_b"] if sec.get("level", 1) == 1 else S["toc"]
|
|
470
|
-
indent = "" if sec.get("level", 1) == 1 else " "
|
|
471
|
-
num = sec.get("num", "")
|
|
472
|
-
title = sec["title"]
|
|
473
|
-
if sec.get("level", 1) == 1 and num != "":
|
|
474
|
-
left = f"{indent}{num}. {title}"
|
|
475
|
-
else:
|
|
476
|
-
left = f"{indent}{title}"
|
|
477
|
-
row = Table(
|
|
478
|
-
[[Paragraph(left, style)]],
|
|
479
|
-
colWidths=[CW],
|
|
480
|
-
)
|
|
481
|
-
row.setStyle(
|
|
482
|
-
TableStyle(
|
|
483
|
-
[
|
|
484
|
-
("VALIGN", (0, 0), (-1, -1), "MIDDLE"),
|
|
485
|
-
("TOPPADDING", (0, 0), (-1, -1), 3),
|
|
486
|
-
("BOTTOMPADDING", (0, 0), (-1, -1), 3),
|
|
487
|
-
("LEFTPADDING", (0, 0), (-1, -1), 0),
|
|
488
|
-
]
|
|
489
|
-
)
|
|
490
|
-
)
|
|
491
|
-
story.append(row)
|
|
492
|
-
story.append(PageBreak())
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
def section(story: list, num: int | str, title: str) -> None:
|
|
496
|
-
header = Table(
|
|
497
|
-
[
|
|
498
|
-
[
|
|
499
|
-
Paragraph(
|
|
500
|
-
f"{num}.",
|
|
501
|
-
ParagraphStyle(
|
|
502
|
-
"SN",
|
|
503
|
-
fontName=FONT_B,
|
|
504
|
-
fontSize=18,
|
|
505
|
-
textColor=COLORS["accent"],
|
|
506
|
-
),
|
|
507
|
-
),
|
|
508
|
-
Paragraph(_ptext(title), S["h1_sec"]),
|
|
509
|
-
]
|
|
510
|
-
],
|
|
511
|
-
colWidths=[32, CW - 32],
|
|
512
|
-
)
|
|
513
|
-
header.setStyle(
|
|
514
|
-
TableStyle(
|
|
515
|
-
[
|
|
516
|
-
("VALIGN", (0, 0), (-1, -1), "TOP"),
|
|
517
|
-
("TOPPADDING", (0, 0), (-1, -1), 0),
|
|
518
|
-
("BOTTOMPADDING", (0, 0), (-1, -1), 0),
|
|
519
|
-
]
|
|
520
|
-
)
|
|
521
|
-
)
|
|
522
|
-
story.append(header)
|
|
523
|
-
story.append(
|
|
524
|
-
HRFlowable(
|
|
525
|
-
width="100%",
|
|
526
|
-
thickness=0.75,
|
|
527
|
-
color=COLORS["border"],
|
|
528
|
-
spaceAfter=12,
|
|
529
|
-
)
|
|
530
|
-
)
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
def callout(story: list, title: str, text: str, box_type: str = "info") -> None:
|
|
534
|
-
allowed = ("info", "warning", "plain_language", "technical_note")
|
|
535
|
-
box_type = box_type if box_type in allowed else "info"
|
|
536
|
-
if box_type == "plain_language":
|
|
537
|
-
bg = COLORS["bg_light"]
|
|
538
|
-
border = COLORS["secondary"]
|
|
539
|
-
label = "Em linguagem simples"
|
|
540
|
-
elif box_type == "technical_note":
|
|
541
|
-
bg = HexColor("#F8FAFC")
|
|
542
|
-
border = COLORS["primary"]
|
|
543
|
-
label = "Nota técnica"
|
|
544
|
-
elif box_type == "warning":
|
|
545
|
-
bg = COLORS["bg_light"]
|
|
546
|
-
border = COLORS["accent"]
|
|
547
|
-
label = "Atenção"
|
|
548
|
-
else:
|
|
549
|
-
bg = COLORS["bg_accent"]
|
|
550
|
-
border = COLORS["secondary"]
|
|
551
|
-
label = "Informação"
|
|
552
|
-
content = [
|
|
553
|
-
[
|
|
554
|
-
Paragraph(
|
|
555
|
-
f"<b>{_ptext(label)} — {_ptext(title)}</b>",
|
|
556
|
-
ParagraphStyle(
|
|
557
|
-
"CT",
|
|
558
|
-
fontName=FONT_B,
|
|
559
|
-
fontSize=9.5,
|
|
560
|
-
textColor=COLORS["primary"],
|
|
561
|
-
spaceAfter=4,
|
|
562
|
-
),
|
|
563
|
-
)
|
|
564
|
-
],
|
|
565
|
-
[
|
|
566
|
-
Paragraph(
|
|
567
|
-
_ptext(text),
|
|
568
|
-
ParagraphStyle(
|
|
569
|
-
"CB",
|
|
570
|
-
fontName=FONT,
|
|
571
|
-
fontSize=9.5,
|
|
572
|
-
leading=14,
|
|
573
|
-
textColor=COLORS["text"],
|
|
574
|
-
),
|
|
575
|
-
)
|
|
576
|
-
],
|
|
577
|
-
]
|
|
578
|
-
t = Table(content, colWidths=[CW - 20])
|
|
579
|
-
t.setStyle(
|
|
580
|
-
TableStyle(
|
|
581
|
-
[
|
|
582
|
-
("BACKGROUND", (0, 0), (-1, -1), bg),
|
|
583
|
-
("BOX", (0, 0), (-1, -1), 0.85, border),
|
|
584
|
-
("LEFTPADDING", (0, 0), (-1, -1), 12),
|
|
585
|
-
("RIGHTPADDING", (0, 0), (-1, -1), 12),
|
|
586
|
-
("TOPPADDING", (0, 0), (0, 0), 9),
|
|
587
|
-
("BOTTOMPADDING", (-1, -1), (-1, -1), 9),
|
|
588
|
-
]
|
|
589
|
-
)
|
|
590
|
-
)
|
|
591
|
-
story.append(Spacer(1, 6))
|
|
592
|
-
story.append(t)
|
|
593
|
-
story.append(Spacer(1, 6))
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
def _cell_paragraph(text: str, *, header: bool = False) -> Paragraph:
|
|
597
|
-
raw = str(text or "")
|
|
598
|
-
if len(raw) > 120 or "\n" in raw:
|
|
599
|
-
sty = ParagraphStyle(
|
|
600
|
-
"CellLong",
|
|
601
|
-
fontName=FONT_B if header else FONT,
|
|
602
|
-
fontSize=9 if header else 8.5,
|
|
603
|
-
leading=11 if header else 10,
|
|
604
|
-
textColor=COLORS["white"] if header else COLORS["text"],
|
|
605
|
-
)
|
|
606
|
-
return Paragraph(_ptext(raw), sty)
|
|
607
|
-
return Paragraph(_ptext(raw), S["cell"] if not header else ParagraphStyle(
|
|
608
|
-
"CellH", parent=S["cell"], fontName=FONT_B, textColor=COLORS["white"], fontSize=9
|
|
609
|
-
))
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
def pro_table(
|
|
613
|
-
story: list,
|
|
614
|
-
headers: list[str],
|
|
615
|
-
rows: list[list[str]],
|
|
616
|
-
col_widths: list[float] | None = None,
|
|
617
|
-
) -> None:
|
|
618
|
-
data = [[_cell_paragraph(h, header=True) for h in headers]]
|
|
619
|
-
data += [[_cell_paragraph(c) for c in row] for row in rows]
|
|
620
|
-
col_widths = _normalize_col_widths(col_widths, len(headers))
|
|
621
|
-
t = Table(data, colWidths=col_widths, repeatRows=1)
|
|
622
|
-
t.setStyle(
|
|
623
|
-
TableStyle(
|
|
624
|
-
[
|
|
625
|
-
("BACKGROUND", (0, 0), (-1, 0), COLORS["primary"]),
|
|
626
|
-
("TEXTCOLOR", (0, 0), (-1, 0), COLORS["white"]),
|
|
627
|
-
("FONTNAME", (0, 0), (-1, 0), FONT_B),
|
|
628
|
-
("FONTSIZE", (0, 0), (-1, 0), 9.5),
|
|
629
|
-
("BOTTOMPADDING", (0, 0), (-1, 0), 9),
|
|
630
|
-
("TOPPADDING", (0, 0), (-1, 0), 9),
|
|
631
|
-
("FONTNAME", (0, 1), (-1, -1), FONT),
|
|
632
|
-
("FONTSIZE", (0, 1), (-1, -1), 9),
|
|
633
|
-
("TEXTCOLOR", (0, 1), (-1, -1), COLORS["text"]),
|
|
634
|
-
("TOPPADDING", (0, 1), (-1, -1), 6),
|
|
635
|
-
("BOTTOMPADDING", (0, 1), (-1, -1), 6),
|
|
636
|
-
*[
|
|
637
|
-
("BACKGROUND", (0, i), (-1, i), COLORS["bg_light"])
|
|
638
|
-
for i in range(1, len(data), 2)
|
|
639
|
-
],
|
|
640
|
-
("LINEBELOW", (0, 0), (-1, 0), 1, COLORS["accent"]),
|
|
641
|
-
("LINEBELOW", (0, 1), (-1, -2), 0.25, COLORS["border"]),
|
|
642
|
-
("LINEBELOW", (0, -1), (-1, -1), 0.75, COLORS["secondary"]),
|
|
643
|
-
("ALIGN", (0, 0), (-1, -1), "LEFT"),
|
|
644
|
-
("VALIGN", (0, 0), (-1, -1), "MIDDLE"),
|
|
645
|
-
("LEFTPADDING", (0, 0), (-1, -1), 9),
|
|
646
|
-
("RIGHTPADDING", (0, 0), (-1, -1), 9),
|
|
647
|
-
]
|
|
648
|
-
)
|
|
649
|
-
)
|
|
650
|
-
story.append(Spacer(1, 4))
|
|
651
|
-
story.append(t)
|
|
652
|
-
story.append(Spacer(1, 10))
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
def _draw_letterhead_band(canvas_obj, letterhead: dict[str, Any]) -> None:
|
|
656
|
-
org = str(letterhead.get("organization") or "").strip()[:80]
|
|
657
|
-
if not org:
|
|
658
|
-
return
|
|
659
|
-
canvas_obj.saveState()
|
|
660
|
-
y = PAGE_H - 1.15 * cm
|
|
661
|
-
canvas_obj.setFont(FONT_B, 9)
|
|
662
|
-
canvas_obj.setFillColor(COLORS["primary"])
|
|
663
|
-
canvas_obj.drawString(M, y, org)
|
|
664
|
-
dept = str(letterhead.get("department") or "").strip()[:60]
|
|
665
|
-
if dept:
|
|
666
|
-
canvas_obj.setFont(FONT, 7.5)
|
|
667
|
-
canvas_obj.setFillColor(COLORS["muted"])
|
|
668
|
-
canvas_obj.drawRightString(PAGE_W - M, y, dept)
|
|
669
|
-
canvas_obj.setStrokeColor(COLORS["border"])
|
|
670
|
-
canvas_obj.setLineWidth(0.5)
|
|
671
|
-
canvas_obj.line(M, y - 5, PAGE_W - M, y - 5)
|
|
672
|
-
canvas_obj.restoreState()
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
def header_footer(canvas_obj, doc, *, letterhead: dict[str, Any] | None = None) -> None:
|
|
676
|
-
if letterhead and getattr(doc, "_bluma_letterhead", False):
|
|
677
|
-
_draw_letterhead_band(canvas_obj, letterhead)
|
|
678
|
-
canvas_obj.saveState()
|
|
679
|
-
y_h = PAGE_H - (1.75 * cm if getattr(doc, "_bluma_letterhead", False) else 1.35 * cm)
|
|
680
|
-
canvas_obj.setStrokeColor(COLORS["border"])
|
|
681
|
-
canvas_obj.setLineWidth(0.6)
|
|
682
|
-
canvas_obj.line(M, y_h, PAGE_W - M, y_h)
|
|
683
|
-
canvas_obj.setFont(FONT, 8)
|
|
684
|
-
canvas_obj.setFillColor(COLORS["text_light"])
|
|
685
|
-
title = (doc.title or "")[:90]
|
|
686
|
-
canvas_obj.drawString(M, y_h + 3, title)
|
|
687
|
-
|
|
688
|
-
y_f = 1.05 * cm
|
|
689
|
-
canvas_obj.setStrokeColor(COLORS["border"])
|
|
690
|
-
canvas_obj.setLineWidth(0.35)
|
|
691
|
-
canvas_obj.line(M, y_f + 10, PAGE_W - M, y_f + 10)
|
|
692
|
-
canvas_obj.setFont(FONT, 8)
|
|
693
|
-
canvas_obj.setFillColor(COLORS["muted"])
|
|
694
|
-
canvas_obj.drawCentredString(PAGE_W / 2, y_f, f"Página {doc.page}")
|
|
695
|
-
canvas_obj.restoreState()
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
def on_first_page(canvas_obj, doc) -> None:
|
|
699
|
-
draw_cover_canvas(canvas_obj, doc)
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
def on_later_pages(canvas_obj, doc) -> None:
|
|
703
|
-
lh = getattr(doc, "_bluma_letterhead_data", None) or {}
|
|
704
|
-
header_footer(canvas_obj, doc, letterhead=lh)
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
# ── JSON-driven build ──────────────────────────────────────────
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
def build_from_json(data: dict[str, Any], output_path: str) -> None:
|
|
711
|
-
title = data.get("title") or "Relatório"
|
|
712
|
-
subtitle = data.get("subtitle")
|
|
713
|
-
author = data.get("author")
|
|
714
|
-
layout = _resolve_layout(data)
|
|
715
|
-
letterhead = layout.get("letterhead") or {}
|
|
716
|
-
|
|
717
|
-
page_per_section = layout.get("page_break_per_section", False)
|
|
718
|
-
if "page_break_per_section" in data and data["page_break_per_section"] is not None:
|
|
719
|
-
page_per_section = bool(data["page_break_per_section"])
|
|
720
|
-
if not isinstance(page_per_section, bool):
|
|
721
|
-
page_per_section = bool(page_per_section)
|
|
722
|
-
|
|
723
|
-
sections = data.get("sections") or []
|
|
724
|
-
if not isinstance(sections, list):
|
|
725
|
-
raise ValueError('"sections" must be a list')
|
|
726
|
-
|
|
727
|
-
include_toc = layout.get("include_toc", True)
|
|
728
|
-
if len(sections) < 2:
|
|
729
|
-
include_toc = False
|
|
730
|
-
|
|
731
|
-
toc_rows: list[dict[str, Any]] = []
|
|
732
|
-
for i, sec in enumerate(sections, start=1):
|
|
733
|
-
if not isinstance(sec, dict):
|
|
734
|
-
continue
|
|
735
|
-
num = sec.get("num", i)
|
|
736
|
-
toc_rows.append({"num": num, "title": sec.get("title", f"Seção {i}"), "level": 1})
|
|
737
|
-
|
|
738
|
-
doc = SimpleDocTemplate(
|
|
739
|
-
output_path,
|
|
740
|
-
pagesize=A4,
|
|
741
|
-
leftMargin=M,
|
|
742
|
-
rightMargin=M,
|
|
743
|
-
topMargin=M + (0.4 * cm if layout.get("use_letterhead_band") else 0),
|
|
744
|
-
bottomMargin=M,
|
|
745
|
-
title=title,
|
|
746
|
-
author=str(author or letterhead.get("organization") or "BluMa"),
|
|
747
|
-
)
|
|
748
|
-
doc._bluma_letterhead = bool(layout.get("use_letterhead_band") and letterhead) # type: ignore[attr-defined]
|
|
749
|
-
doc._bluma_letterhead_data = letterhead # type: ignore[attr-defined]
|
|
750
|
-
|
|
751
|
-
story: list = []
|
|
752
|
-
cover_story(
|
|
753
|
-
story,
|
|
754
|
-
title,
|
|
755
|
-
subtitle,
|
|
756
|
-
author,
|
|
757
|
-
cover_style=str(layout.get("cover_style") or "corporate"),
|
|
758
|
-
letterhead=letterhead,
|
|
759
|
-
)
|
|
760
|
-
if include_toc and toc_rows:
|
|
761
|
-
toc(story, toc_rows)
|
|
762
|
-
|
|
763
|
-
audience = str(layout.get("audience") or "technical")
|
|
764
|
-
if audience == "mixed":
|
|
765
|
-
story.append(
|
|
766
|
-
Paragraph(
|
|
767
|
-
_ptext(
|
|
768
|
-
"Este documento apresenta dados com rigor técnico e, em cada secção, "
|
|
769
|
-
"resumos em linguagem acessível para leitores sem formação especializada na área."
|
|
770
|
-
),
|
|
771
|
-
S["body"],
|
|
772
|
-
)
|
|
773
|
-
)
|
|
774
|
-
story.append(Spacer(1, 10))
|
|
775
|
-
|
|
776
|
-
for idx, sec in enumerate(sections):
|
|
777
|
-
if not isinstance(sec, dict):
|
|
778
|
-
continue
|
|
779
|
-
num = sec.get("num", 0)
|
|
780
|
-
sec_title = sec.get("title", "")
|
|
781
|
-
if _should_page_break_before_section(
|
|
782
|
-
sec, page_per_section=page_per_section, index=idx
|
|
783
|
-
):
|
|
784
|
-
story.append(PageBreak())
|
|
785
|
-
|
|
786
|
-
blocks = [b for b in (sec.get("blocks") or []) if isinstance(b, dict)]
|
|
787
|
-
section(story, num, sec_title)
|
|
788
|
-
for block in blocks:
|
|
789
|
-
btype = block.get("type")
|
|
790
|
-
if btype == "paragraph":
|
|
791
|
-
story.append(Paragraph(_ptext(block.get("text", "")), S["body"]))
|
|
792
|
-
elif btype == "h2":
|
|
793
|
-
story.append(Paragraph(_ptext(block.get("text", "")), S["h2"]))
|
|
794
|
-
elif btype == "callout":
|
|
795
|
-
callout(
|
|
796
|
-
story,
|
|
797
|
-
block.get("title", ""),
|
|
798
|
-
block.get("text", ""),
|
|
799
|
-
block.get("variant", "info"),
|
|
800
|
-
)
|
|
801
|
-
elif btype == "bullets":
|
|
802
|
-
for item in block.get("items") or []:
|
|
803
|
-
story.append(Paragraph(f"• {_ptext(item)}", S["bullet"]))
|
|
804
|
-
elif btype == "table":
|
|
805
|
-
headers = block.get("headers") or []
|
|
806
|
-
rows = block.get("rows") or []
|
|
807
|
-
cw = block.get("col_widths")
|
|
808
|
-
pro_table(story, list(headers), [list(r) for r in rows], cw)
|
|
809
|
-
elif btype == "spacer":
|
|
810
|
-
story.append(Spacer(1, float(block.get("pt", 12))))
|
|
811
|
-
|
|
812
|
-
story.append(Spacer(1, 14))
|
|
813
|
-
|
|
814
|
-
doc.build(story, onFirstPage=on_first_page, onLaterPages=on_later_pages)
|
|
815
|
-
print(f"Report generated: {output_path}", file=sys.stderr)
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
def demo_report(args: argparse.Namespace) -> None:
|
|
819
|
-
doc = SimpleDocTemplate(
|
|
820
|
-
args.output,
|
|
821
|
-
pagesize=A4,
|
|
822
|
-
leftMargin=M,
|
|
823
|
-
rightMargin=M,
|
|
824
|
-
topMargin=M,
|
|
825
|
-
bottomMargin=M,
|
|
826
|
-
title=args.title,
|
|
827
|
-
author="BluMa",
|
|
828
|
-
)
|
|
829
|
-
|
|
830
|
-
story: list = []
|
|
831
|
-
cover_story(story, args.title, args.subtitle, "Gerado por BluMa")
|
|
832
|
-
|
|
833
|
-
toc(
|
|
834
|
-
story,
|
|
835
|
-
[
|
|
836
|
-
{"num": 1, "title": "Introdução", "level": 1, "page": ""},
|
|
837
|
-
{"num": 2, "title": "Achados", "level": 1, "page": ""},
|
|
838
|
-
{"num": 3, "title": "Conclusão", "level": 1, "page": ""},
|
|
839
|
-
],
|
|
840
|
-
)
|
|
841
|
-
|
|
842
|
-
section(story, 1, "Introdução")
|
|
843
|
-
story.append(
|
|
844
|
-
Paragraph(
|
|
845
|
-
_ptext(
|
|
846
|
-
"Este modelo define tipografia, margens, tabelas e caixas de destaque "
|
|
847
|
-
"para que o PDF pareça um relatório corporativo, não um print de terminal."
|
|
848
|
-
),
|
|
849
|
-
S["body"],
|
|
850
|
-
)
|
|
851
|
-
)
|
|
852
|
-
story.append(
|
|
853
|
-
Paragraph(
|
|
854
|
-
_ptext(
|
|
855
|
-
"Paleta slate + laranja queimado, hierarquia clara e espaço em branco "
|
|
856
|
-
"intencional reduzem a sensação de documento “gerado por script”."
|
|
857
|
-
),
|
|
858
|
-
S["body"],
|
|
859
|
-
)
|
|
860
|
-
)
|
|
861
|
-
callout(
|
|
862
|
-
story,
|
|
863
|
-
"Leitura rápida",
|
|
864
|
-
"Use o modo --from-json para manter este visual com o seu conteúdo, "
|
|
865
|
-
"sem reimplementar estilos no improviso.",
|
|
866
|
-
"info",
|
|
867
|
-
)
|
|
868
|
-
|
|
869
|
-
story.append(PageBreak())
|
|
870
|
-
section(story, 2, "Achados")
|
|
871
|
-
story.append(Paragraph(_ptext("Resumo numérico:"), S["body"]))
|
|
872
|
-
pro_table(
|
|
873
|
-
story,
|
|
874
|
-
["Métrica", "Q1 2026", "Q2 2026", "Var."],
|
|
875
|
-
[
|
|
876
|
-
["Receita", "R$ 1,2M", "R$ 1,5M", "+25%"],
|
|
877
|
-
["Usuários ativos", "45.000", "58.000", "+29%"],
|
|
878
|
-
["Retenção", "82%", "87%", "+5pp"],
|
|
879
|
-
],
|
|
880
|
-
)
|
|
881
|
-
story.append(Paragraph(_ptext("Destaques:"), S["body"]))
|
|
882
|
-
for item in [
|
|
883
|
-
"Crescimento acima da meta em onboarding",
|
|
884
|
-
"Retenção estável em todas as coortes",
|
|
885
|
-
"NPS em faixa “excelente”",
|
|
886
|
-
]:
|
|
887
|
-
story.append(Paragraph(f"• {_ptext(item)}", S["bullet"]))
|
|
888
|
-
callout(
|
|
889
|
-
story,
|
|
890
|
-
"Metodologia",
|
|
891
|
-
"Comparativos homólogos, ajustados por sazonalidade quando aplicável.",
|
|
892
|
-
"warning",
|
|
893
|
-
)
|
|
894
|
-
|
|
895
|
-
story.append(PageBreak())
|
|
896
|
-
section(story, 3, "Conclusão")
|
|
897
|
-
story.append(
|
|
898
|
-
Paragraph(
|
|
899
|
-
_ptext(
|
|
900
|
-
"Recomenda-se manter as iniciativas em curso e acompanhar CAC com "
|
|
901
|
-
"corte mensal nos canais de aquisição."
|
|
902
|
-
),
|
|
903
|
-
S["body"],
|
|
904
|
-
)
|
|
905
|
-
)
|
|
906
|
-
|
|
907
|
-
doc.build(story, onFirstPage=on_first_page, onLaterPages=on_later_pages)
|
|
908
|
-
print(f"Report generated: {args.output}", file=sys.stderr)
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
def main() -> None:
|
|
912
|
-
parser = argparse.ArgumentParser(description="Generate professional PDF report (BluMa)")
|
|
913
|
-
parser.add_argument("--title", default="Relatório")
|
|
914
|
-
parser.add_argument("--subtitle", default="Documento executivo")
|
|
915
|
-
parser.add_argument("--output", default="report.pdf")
|
|
916
|
-
parser.add_argument(
|
|
917
|
-
"--from-json",
|
|
918
|
-
dest="from_json",
|
|
919
|
-
metavar="FILE",
|
|
920
|
-
help="Build from structured JSON (recommended for real deliverables)",
|
|
921
|
-
)
|
|
922
|
-
args = parser.parse_args()
|
|
923
|
-
|
|
924
|
-
if args.from_json:
|
|
925
|
-
path = Path(args.from_json)
|
|
926
|
-
if not path.is_file():
|
|
927
|
-
print(f"File not found: {path}", file=sys.stderr)
|
|
928
|
-
sys.exit(1)
|
|
929
|
-
data = json.loads(path.read_text(encoding="utf-8"))
|
|
930
|
-
build_from_json(data, args.output)
|
|
931
|
-
else:
|
|
932
|
-
demo_report(args)
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
if __name__ == "__main__":
|
|
936
|
-
main()
|