Spaces:
Sleeping
Sleeping
[docs] Bundle Inter + Fraunces locally — offline PDF generation
Browse filesDocument PDFs no longer fetch Google Fonts at render time (no internet
dependency, and generation dropped ~22s -> ~0.8s):
- agent/tools/templates/fonts/: bundled static Latin TTFs (Inter 400/600/700,
Fraunces 600/700, ~280KB, committed).
- _head.html: local @font-face; non-Latin scripts (Arabic/CJK/Devanagari/
Cyrillic) fall back to the system Noto fonts (also offline).
- doc_generator passes base_url=templates dir so the @font-face urls resolve.
Verified: no font warnings; English + Arabic documents render offline as valid PDFs.
Co-authored-by: Codex <noreply@openai.com>
- agent/tools/doc_generator.py +3 -1
- agent/tools/templates/_head.html +11 -4
- agent/tools/templates/fonts/Fraunces-600.ttf +0 -0
- agent/tools/templates/fonts/Fraunces-700.ttf +0 -0
- agent/tools/templates/fonts/Inter-400.ttf +0 -0
- agent/tools/templates/fonts/Inter-600.ttf +0 -0
- agent/tools/templates/fonts/Inter-700.ttf +0 -0
agent/tools/doc_generator.py
CHANGED
|
@@ -116,7 +116,9 @@ def _new_docx(title: str, subtitle: str) -> Document:
|
|
| 116 |
|
| 117 |
|
| 118 |
def _pdf_from_html(body_html: str, path: Path):
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
# -- per-document content ---------------------------------------------------
|
|
|
|
| 116 |
|
| 117 |
|
| 118 |
def _pdf_from_html(body_html: str, path: Path):
|
| 119 |
+
# base_url = the templates dir so @font-face url('fonts/...') resolves locally.
|
| 120 |
+
html_doc = f"<!DOCTYPE html><html><head>{_HEAD}</head><body>{_BRAND}{body_html}</body></html>"
|
| 121 |
+
HTML(string=html_doc, base_url=str(TEMPLATES)).write_pdf(str(path))
|
| 122 |
|
| 123 |
|
| 124 |
# -- per-document content ---------------------------------------------------
|
agent/tools/templates/_head.html
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
<meta charset="utf-8" />
|
| 2 |
<style>
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
@page {
|
| 5 |
size: A4; margin: 24mm 20mm 20mm;
|
| 6 |
@bottom-center {
|
|
@@ -15,7 +21,8 @@
|
|
| 15 |
--text: #1A1A1A; --muted: #6B7280; --line: #E7E2D8; --tint: #E5EFEA;
|
| 16 |
}
|
| 17 |
* { box-sizing: border-box; }
|
| 18 |
-
body { font-family: "Inter", "
|
|
|
|
| 19 |
font-size: 11.5pt; line-height: 1.65; }
|
| 20 |
|
| 21 |
/* Branded masthead */
|
|
@@ -26,8 +33,8 @@
|
|
| 26 |
color: var(--primary-deep); letter-spacing: -.01em; }
|
| 27 |
.brand .tag { margin-left: auto; font-size: 8.5pt; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
|
| 28 |
|
| 29 |
-
h1, h2, h3, h4 { font-family: "Fraunces", Georgia, "Times New Roman", serif;
|
| 30 |
-
margin: 0 0 4px; line-height: 1.2; }
|
| 31 |
h1 { font-size: 23pt; }
|
| 32 |
h2 { font-size: 14pt; margin-top: 20px; padding-bottom: 3px; border-bottom: 1px solid var(--line); }
|
| 33 |
.sub { color: var(--muted); font-size: 10pt; margin: 0 0 18px; letter-spacing: .02em; }
|
|
|
|
| 1 |
<meta charset="utf-8" />
|
| 2 |
<style>
|
| 3 |
+
/* Bundled locally (no internet). Non-Latin scripts fall back to system Noto. */
|
| 4 |
+
@font-face { font-family: "Inter"; font-weight: 400; src: url("fonts/Inter-400.ttf"); }
|
| 5 |
+
@font-face { font-family: "Inter"; font-weight: 500; src: url("fonts/Inter-600.ttf"); }
|
| 6 |
+
@font-face { font-family: "Inter"; font-weight: 600; src: url("fonts/Inter-600.ttf"); }
|
| 7 |
+
@font-face { font-family: "Inter"; font-weight: 700; src: url("fonts/Inter-700.ttf"); }
|
| 8 |
+
@font-face { font-family: "Fraunces"; font-weight: 600; src: url("fonts/Fraunces-600.ttf"); }
|
| 9 |
+
@font-face { font-family: "Fraunces"; font-weight: 700; src: url("fonts/Fraunces-700.ttf"); }
|
| 10 |
@page {
|
| 11 |
size: A4; margin: 24mm 20mm 20mm;
|
| 12 |
@bottom-center {
|
|
|
|
| 21 |
--text: #1A1A1A; --muted: #6B7280; --line: #E7E2D8; --tint: #E5EFEA;
|
| 22 |
}
|
| 23 |
* { box-sizing: border-box; }
|
| 24 |
+
body { font-family: "Inter", "Noto Sans", "Noto Sans Arabic", "Noto Sans CJK SC",
|
| 25 |
+
"Noto Sans Devanagari", "DejaVu Sans", sans-serif; color: var(--text);
|
| 26 |
font-size: 11.5pt; line-height: 1.65; }
|
| 27 |
|
| 28 |
/* Branded masthead */
|
|
|
|
| 33 |
color: var(--primary-deep); letter-spacing: -.01em; }
|
| 34 |
.brand .tag { margin-left: auto; font-size: 8.5pt; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
|
| 35 |
|
| 36 |
+
h1, h2, h3, h4 { font-family: "Fraunces", "Noto Serif", Georgia, "Times New Roman", serif;
|
| 37 |
+
color: var(--primary-deep); margin: 0 0 4px; line-height: 1.2; }
|
| 38 |
h1 { font-size: 23pt; }
|
| 39 |
h2 { font-size: 14pt; margin-top: 20px; padding-bottom: 3px; border-bottom: 1px solid var(--line); }
|
| 40 |
.sub { color: var(--muted); font-size: 10pt; margin: 0 0 18px; letter-spacing: .02em; }
|
agent/tools/templates/fonts/Fraunces-600.ttf
ADDED
|
Binary file (37.2 kB). View file
|
|
|
agent/tools/templates/fonts/Fraunces-700.ttf
ADDED
|
Binary file (37.1 kB). View file
|
|
|
agent/tools/templates/fonts/Inter-400.ttf
ADDED
|
Binary file (68 kB). View file
|
|
|
agent/tools/templates/fonts/Inter-600.ttf
ADDED
|
Binary file (68.1 kB). View file
|
|
|
agent/tools/templates/fonts/Inter-700.ttf
ADDED
|
Binary file (68 kB). View file
|
|
|