figurekit 0.6.0__tar.gz → 0.7.0__tar.gz
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.
- {figurekit-0.6.0 → figurekit-0.7.0}/CHANGELOG.md +11 -1
- {figurekit-0.6.0 → figurekit-0.7.0}/PKG-INFO +11 -5
- {figurekit-0.6.0 → figurekit-0.7.0}/README.md +9 -3
- figurekit-0.7.0/notes.md +12 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/pyproject.toml +2 -2
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/__init__.py +2 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/check.py +25 -6
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/export.py +12 -1
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/theme.py +2 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/test_figkit.py +25 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/uv.lock +1 -1
- figurekit-0.6.0/notes.md +0 -21
- {figurekit-0.6.0 → figurekit-0.7.0}/.gitattributes +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/.github/workflows/ci.yml +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/.github/workflows/release.yml +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/.gitignore +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/.pre-commit-config.yaml +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/LICENSE +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/bars-dark.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/bars-dark.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/bars.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/bars.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/card-dark.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/card.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/formula-dark.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/formula-dark.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/formula.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/formula.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/heatmap-dark.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/heatmap-dark.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/heatmap.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/heatmap.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/lines-dark.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/lines-dark.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/lines.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/lines.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/multiples-dark.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/multiples-dark.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/multiples.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/multiples.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/style/lines-dark.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/style/lines-dark.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/style/lines-print.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/style/lines-print.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/style/lines.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/style/lines.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/examples/style/tokens.json +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/readme/before.svg +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/readme/modes.png +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/docs/style-guide.md +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/scripts/build_fonts.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/scripts/check_package.sh +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/scripts/examples.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/scripts/release_notes.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/scripts/smoke.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/access.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/cli.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/fonts/BricolageGrotesque-Regular.ttf +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/fonts/BricolageGrotesque-SemiBold.ttf +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/fonts/JetBrainsMono-Regular.ttf +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/fonts/JetBrainsMono-SemiBold.ttf +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/fonts/OFL-BricolageGrotesque.txt +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/fonts/OFL-JetBrainsMono.txt +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/helpers.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/language.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/manifest.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/preview.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/project.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/py.typed +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/tokens.json +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/src/figkit/tokens.schema.json +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/conftest.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/test_access.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/test_language.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/test_math.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/test_project.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/test_release.py +0 -0
- {figurekit-0.6.0 → figurekit-0.7.0}/tests/test_style.py +0 -0
|
@@ -6,6 +6,15 @@ section of that version.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.7.0] - 2026-11-29
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `PDF` writes a figure as a transparent PDF for papers and print. The fonts are embedded as
|
|
14
|
+
TrueType subsets, so the text stays selectable, and the file is byte-identical between runs.
|
|
15
|
+
`Output("pdf", width=...)` fits a narrower column.
|
|
16
|
+
- `figkit check` checks PDFs too: their pair, file size and page width.
|
|
17
|
+
|
|
9
18
|
## [0.6.0] - 2026-11-28
|
|
10
19
|
|
|
11
20
|
### Added
|
|
@@ -193,7 +202,8 @@ section of that version.
|
|
|
193
202
|
label of a vertical reference line goes on either side.
|
|
194
203
|
- `figkit check` for light/dark pairs, transparency and file sizes.
|
|
195
204
|
|
|
196
|
-
[Unreleased]: https://github.com/BenBotsch/FigureKit/compare/v0.
|
|
205
|
+
[Unreleased]: https://github.com/BenBotsch/FigureKit/compare/v0.7.0...HEAD
|
|
206
|
+
[0.7.0]: https://github.com/BenBotsch/FigureKit/compare/v0.6.0...v0.7.0
|
|
197
207
|
[0.6.0]: https://github.com/BenBotsch/FigureKit/compare/v0.5.1...v0.6.0
|
|
198
208
|
[0.5.1]: https://github.com/BenBotsch/FigureKit/compare/v0.5.0...v0.5.1
|
|
199
209
|
[0.5.0]: https://github.com/BenBotsch/FigureKit/compare/v0.4.0...v0.5.0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: figurekit
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: One figure style for every project: light and dark themes, transparent SVG and
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: One figure style for every project: light and dark themes, transparent SVG, PNG and PDF, Bricolage Grotesque and JetBrains Mono, reproducible files.
|
|
5
5
|
Project-URL: Repository, https://github.com/BenBotsch/FigureKit
|
|
6
6
|
Project-URL: Issues, https://github.com/BenBotsch/FigureKit/issues
|
|
7
7
|
Project-URL: Changelog, https://github.com/BenBotsch/FigureKit/blob/main/CHANGELOG.md
|
|
@@ -43,8 +43,8 @@ Description-Content-Type: text/markdown
|
|
|
43
43
|
</div>
|
|
44
44
|
|
|
45
45
|
A figure is a function of the theme. FigureKit draws it once per theme, such as light and dark,
|
|
46
|
-
and once per language, writes transparent SVG and
|
|
47
|
-
run, and checks them in CI.
|
|
46
|
+
and once per language, writes transparent SVG, PNG and PDF files that are byte-identical on
|
|
47
|
+
every run, and checks them in CI.
|
|
48
48
|
|
|
49
49
|
<table>
|
|
50
50
|
<tr>
|
|
@@ -73,6 +73,8 @@ run, and checks them in CI.
|
|
|
73
73
|
colours; text colours reach WCAG contrast, checked in the tests. Text below 8 pt is an error.
|
|
74
74
|
- **Reproducible.** The same figure gives byte-identical SVGs on Linux and Windows, without date
|
|
75
75
|
or version, so diffs show only real changes.
|
|
76
|
+
- **Print and papers.** `PDF` writes a transparent PDF with the fonts embedded as subsets, so
|
|
77
|
+
the text stays selectable; `Output("pdf", width=3.5)` fits a paper column.
|
|
76
78
|
- **Two languages.** Website figures come without title in every language, German numbers
|
|
77
79
|
included, with a `figures.json` of titles and alt texts.
|
|
78
80
|
- **Checked in CI.** `figkit check` fails on missing theme or language pairs, opaque backgrounds,
|
|
@@ -262,6 +264,10 @@ with figkit.styled(figkit.DARK):
|
|
|
262
264
|
| `WEB` (default) | transparent SVG and PNG on a 6.4 in canvas, the PNG 1600 px wide |
|
|
263
265
|
| `PHOTO` | transparent WebP and PNG, for images and overlays |
|
|
264
266
|
| `CARD` | opaque 1200 x 630 PNG for Open Graph; draw on `CARD_INCHES` |
|
|
267
|
+
| `PDF` | transparent PDF on the 6.4 in canvas, fonts embedded as subsets so the text stays selectable |
|
|
268
|
+
|
|
269
|
+
For a paper column, write `figkit.Output("pdf", width=3.5)` and check it with `--any-width`.
|
|
270
|
+
PDFs are byte-identical between runs, without date or producer.
|
|
265
271
|
|
|
266
272
|
## Figures for a website
|
|
267
273
|
|
|
@@ -414,7 +420,7 @@ $ uv run figkit check --css ../Portfolio/src/styles/tokens.css
|
|
|
414
420
|
| Area | Names |
|
|
415
421
|
| --- | --- |
|
|
416
422
|
| Render | `render`, `page`, `page_entry`, `write_manifest`, `save`, `path_for`, `canvas`, `styled`, `headless` |
|
|
417
|
-
| Outputs | `WEB`, `PHOTO`, `CARD`, `SVG`, `PNG`, `WEB_WIDTH`, `CARD_INCHES`, `RASTER_DPI` |
|
|
423
|
+
| Outputs | `WEB`, `PHOTO`, `CARD`, `PDF`, `SVG`, `PNG`, `WEB_WIDTH`, `CARD_INCHES`, `RASTER_DPI` |
|
|
418
424
|
| Helpers | `title`, `legend_top`, `grid`, `percent`, `category_axis`, `mono`, `mono_ticks`, `value`, `bar_labels`, `reference_line`, `line_labels`, `band`, `error_bars`, `callout`, `small_multiples`, `ramp_cmap`, `ink_on`, `hex_colour` |
|
|
419
425
|
| Languages | `Caption`, `language`, `localize`, `number` |
|
|
420
426
|
| Style | `Theme`, `Typography`, `Style`, `StyleError`, `load_style`, `parse_style`, `DEFAULT`, `LIGHT`, `DARK`, `THEMES`, `TYPE`, `tokens`, `rc`, `register_fonts` |
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
</div>
|
|
16
16
|
|
|
17
17
|
A figure is a function of the theme. FigureKit draws it once per theme, such as light and dark,
|
|
18
|
-
and once per language, writes transparent SVG and
|
|
19
|
-
run, and checks them in CI.
|
|
18
|
+
and once per language, writes transparent SVG, PNG and PDF files that are byte-identical on
|
|
19
|
+
every run, and checks them in CI.
|
|
20
20
|
|
|
21
21
|
<table>
|
|
22
22
|
<tr>
|
|
@@ -45,6 +45,8 @@ run, and checks them in CI.
|
|
|
45
45
|
colours; text colours reach WCAG contrast, checked in the tests. Text below 8 pt is an error.
|
|
46
46
|
- **Reproducible.** The same figure gives byte-identical SVGs on Linux and Windows, without date
|
|
47
47
|
or version, so diffs show only real changes.
|
|
48
|
+
- **Print and papers.** `PDF` writes a transparent PDF with the fonts embedded as subsets, so
|
|
49
|
+
the text stays selectable; `Output("pdf", width=3.5)` fits a paper column.
|
|
48
50
|
- **Two languages.** Website figures come without title in every language, German numbers
|
|
49
51
|
included, with a `figures.json` of titles and alt texts.
|
|
50
52
|
- **Checked in CI.** `figkit check` fails on missing theme or language pairs, opaque backgrounds,
|
|
@@ -234,6 +236,10 @@ with figkit.styled(figkit.DARK):
|
|
|
234
236
|
| `WEB` (default) | transparent SVG and PNG on a 6.4 in canvas, the PNG 1600 px wide |
|
|
235
237
|
| `PHOTO` | transparent WebP and PNG, for images and overlays |
|
|
236
238
|
| `CARD` | opaque 1200 x 630 PNG for Open Graph; draw on `CARD_INCHES` |
|
|
239
|
+
| `PDF` | transparent PDF on the 6.4 in canvas, fonts embedded as subsets so the text stays selectable |
|
|
240
|
+
|
|
241
|
+
For a paper column, write `figkit.Output("pdf", width=3.5)` and check it with `--any-width`.
|
|
242
|
+
PDFs are byte-identical between runs, without date or producer.
|
|
237
243
|
|
|
238
244
|
## Figures for a website
|
|
239
245
|
|
|
@@ -386,7 +392,7 @@ $ uv run figkit check --css ../Portfolio/src/styles/tokens.css
|
|
|
386
392
|
| Area | Names |
|
|
387
393
|
| --- | --- |
|
|
388
394
|
| Render | `render`, `page`, `page_entry`, `write_manifest`, `save`, `path_for`, `canvas`, `styled`, `headless` |
|
|
389
|
-
| Outputs | `WEB`, `PHOTO`, `CARD`, `SVG`, `PNG`, `WEB_WIDTH`, `CARD_INCHES`, `RASTER_DPI` |
|
|
395
|
+
| Outputs | `WEB`, `PHOTO`, `CARD`, `PDF`, `SVG`, `PNG`, `WEB_WIDTH`, `CARD_INCHES`, `RASTER_DPI` |
|
|
390
396
|
| Helpers | `title`, `legend_top`, `grid`, `percent`, `category_axis`, `mono`, `mono_ticks`, `value`, `bar_labels`, `reference_line`, `line_labels`, `band`, `error_bars`, `callout`, `small_multiples`, `ramp_cmap`, `ink_on`, `hex_colour` |
|
|
391
397
|
| Languages | `Caption`, `language`, `localize`, `number` |
|
|
392
398
|
| Style | `Theme`, `Typography`, `Style`, `StyleError`, `load_style`, `parse_style`, `DEFAULT`, `LIGHT`, `DARK`, `THEMES`, `TYPE`, `tokens`, `rc`, `register_fonts` |
|
figurekit-0.7.0/notes.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
```sh
|
|
2
|
+
uv add "figurekit==0.7.0"
|
|
3
|
+
```
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `PDF` writes a figure as a transparent PDF for papers and print. The fonts are embedded as
|
|
8
|
+
TrueType subsets, so the text stays selectable, and the file is byte-identical between runs.
|
|
9
|
+
`Output("pdf", width=...)` fits a narrower column.
|
|
10
|
+
- `figkit check` checks PDFs too: their pair, file size and page width.
|
|
11
|
+
|
|
12
|
+
**Changes:** https://github.com/BenBotsch/FigureKit/compare/v0.6.0...v0.7.0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "figurekit"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "One figure style for every project: light and dark themes, transparent SVG and
|
|
3
|
+
version = "0.7.0"
|
|
4
|
+
description = "One figure style for every project: light and dark themes, transparent SVG, PNG and PDF, Bricolage Grotesque and JetBrains Mono, reproducible files."
|
|
5
5
|
dynamic = ["readme"]
|
|
6
6
|
license = "MIT"
|
|
7
7
|
license-files = ["LICENSE", "src/figkit/fonts/OFL-*.txt"]
|
|
@@ -21,6 +21,7 @@ website, :func:`page` writes the figure without its title per language, ``f1.de.
|
|
|
21
21
|
from figkit.export import (
|
|
22
22
|
CARD,
|
|
23
23
|
CARD_INCHES,
|
|
24
|
+
PDF,
|
|
24
25
|
PHOTO,
|
|
25
26
|
PNG,
|
|
26
27
|
RASTER_DPI,
|
|
@@ -85,6 +86,7 @@ __all__ = [
|
|
|
85
86
|
"DARK",
|
|
86
87
|
"DEFAULT",
|
|
87
88
|
"LIGHT",
|
|
89
|
+
"PDF",
|
|
88
90
|
"PHOTO",
|
|
89
91
|
"PNG",
|
|
90
92
|
"RASTER_DPI",
|
|
@@ -15,14 +15,16 @@ from figkit import manifest
|
|
|
15
15
|
from figkit.export import RASTER_DPI, WEB_WIDTH
|
|
16
16
|
from figkit.theme import DEFAULT, Style
|
|
17
17
|
|
|
18
|
-
FORMATS = (".svg", ".png", ".webp")
|
|
19
|
-
# Bytes. Above these, a chart usually embeds a raster or far too many points.
|
|
20
|
-
|
|
18
|
+
FORMATS = (".svg", ".pdf", ".png", ".webp")
|
|
19
|
+
# Bytes. Above these, a chart usually embeds a raster or far too many points. A PDF carries its
|
|
20
|
+
# font subsets as well.
|
|
21
|
+
BUDGET = {".svg": 150_000, ".pdf": 200_000, ".png": 250_000, ".webp": 250_000}
|
|
21
22
|
# A PNG next to a WebP of the same name is the lossless copy of a photograph, which is larger.
|
|
22
23
|
PHOTO_PNG_BUDGET = 1_000_000
|
|
23
24
|
# The figure background is the first patch matplotlib writes into an SVG.
|
|
24
25
|
_BACKGROUND = re.compile(r'<g id="patch_1">\s*<path[^>]*style="([^"]*)"')
|
|
25
26
|
_SVG_WIDTH = re.compile(r'<svg[^>]* width="([\d.]+)pt"')
|
|
27
|
+
_PDF_BOX = re.compile(rb"/MediaBox \[\s*([\d.-]+)\s+[\d.-]+\s+([\d.-]+)")
|
|
26
28
|
# ``failure-modes.de`` is the German file of ``failure-modes``.
|
|
27
29
|
_LANGUAGE = re.compile(r"^(?P<name>.+)\.(?P<language>[a-z]{2})$")
|
|
28
30
|
_CSS_COLOUR = re.compile(
|
|
@@ -76,9 +78,12 @@ def check(
|
|
|
76
78
|
problems.append(f"{path.name}: {size:,} bytes, budget {budget:,}")
|
|
77
79
|
if _figure_name(path, style) in keep_opaque:
|
|
78
80
|
continue
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
if path.suffix == ".svg":
|
|
82
|
+
found = _svg_problems(path, width)
|
|
83
|
+
elif path.suffix == ".pdf":
|
|
84
|
+
found = _pdf_problems(path, width)
|
|
85
|
+
else:
|
|
86
|
+
found = _raster_problems(path, width)
|
|
82
87
|
problems += [f"{path.name}: {problem}" for problem in found]
|
|
83
88
|
problems += _language_problems(files, style)
|
|
84
89
|
problems += _manifest_problems(directory, names, [t.name for t in style.themes])
|
|
@@ -214,6 +219,20 @@ def _svg_problems(path: Path, width: float | None) -> list[str]:
|
|
|
214
219
|
return problems
|
|
215
220
|
|
|
216
221
|
|
|
222
|
+
def _pdf_problems(path: Path, width: float | None) -> list[str]:
|
|
223
|
+
"""The page of the PDF is as wide as the canvas.
|
|
224
|
+
|
|
225
|
+
Transparency is not checked: a PDF has no background unless the figure draws one.
|
|
226
|
+
"""
|
|
227
|
+
box = _PDF_BOX.search(path.read_bytes())
|
|
228
|
+
if width is None or box is None:
|
|
229
|
+
return []
|
|
230
|
+
points = float(box.group(2)) - float(box.group(1))
|
|
231
|
+
if abs(points - width * 72) > 0.1:
|
|
232
|
+
return [f"{points:g} pt wide, the canvas is {width * 72:g} pt"]
|
|
233
|
+
return []
|
|
234
|
+
|
|
235
|
+
|
|
217
236
|
def _raster_problems(path: Path, width: float | None) -> list[str]:
|
|
218
237
|
with Image.open(path) as image:
|
|
219
238
|
rgba = image.convert("RGBA")
|
|
@@ -43,7 +43,7 @@ class Output:
|
|
|
43
43
|
"""How a figure is written.
|
|
44
44
|
|
|
45
45
|
Attributes:
|
|
46
|
-
format: ``svg``, ``png`` or ``webp``.
|
|
46
|
+
format: ``svg``, ``pdf``, ``png`` or ``webp``.
|
|
47
47
|
transparent: Leave the background empty instead of filling it with the theme surface.
|
|
48
48
|
width: Width of the canvas in inches. With ``tight``, the file is exactly this wide: a
|
|
49
49
|
drawing that sticks out is narrowed until it fits, a smaller one is padded on the
|
|
@@ -70,6 +70,9 @@ RASTER_DPI = 250
|
|
|
70
70
|
SVG = Output("svg", width=WEB_WIDTH)
|
|
71
71
|
PNG = Output("png", width=WEB_WIDTH, dpi=RASTER_DPI)
|
|
72
72
|
WEB = (SVG, PNG)
|
|
73
|
+
# Papers and print: vector graphics with the fonts embedded as subsets, so the text stays
|
|
74
|
+
# selectable. For a narrower column, write Output("pdf", width=...) and check with that width.
|
|
75
|
+
PDF = Output("pdf", width=WEB_WIDTH)
|
|
73
76
|
# Photographs and heatmaps over images: SVG would embed them as a large raster anyway.
|
|
74
77
|
PHOTO = (Output("webp", width=WEB_WIDTH, dpi=RASTER_DPI), PNG)
|
|
75
78
|
# Open Graph and LinkedIn previews are opaque and exactly 1200 x 630 pixels.
|
|
@@ -80,6 +83,7 @@ PAD = 0.15
|
|
|
80
83
|
# Metadata without dates or versions, so that the files change only with their content.
|
|
81
84
|
_SAVE_OPTIONS: dict[str, dict[str, Any]] = {
|
|
82
85
|
"svg": {"metadata": {"Date": None, "Creator": None}},
|
|
86
|
+
"pdf": {"metadata": {"CreationDate": None, "Creator": None, "Producer": None}},
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
|
|
@@ -132,6 +136,13 @@ def save(figure: Figure, path: Path, output: Output) -> Path:
|
|
|
132
136
|
)
|
|
133
137
|
path.write_bytes(_portable_images(svg.getvalue()))
|
|
134
138
|
return path
|
|
139
|
+
if output.format == "pdf":
|
|
140
|
+
pdf = io.BytesIO()
|
|
141
|
+
figure.savefig(
|
|
142
|
+
pdf, format="pdf", transparent=output.transparent, **options, **_SAVE_OPTIONS["pdf"]
|
|
143
|
+
)
|
|
144
|
+
path.write_bytes(pdf.getvalue())
|
|
145
|
+
return path
|
|
135
146
|
buffer = io.BytesIO()
|
|
136
147
|
figure.savefig(buffer, format="png", dpi=dpi, transparent=output.transparent, **options)
|
|
137
148
|
buffer.seek(0)
|
|
@@ -563,6 +563,8 @@ def rc(theme: Theme) -> dict[str, Any]:
|
|
|
563
563
|
"lines.solid_capstyle": "round",
|
|
564
564
|
"patch.linewidth": 0,
|
|
565
565
|
"svg.fonttype": "path",
|
|
566
|
+
# TrueType subsets instead of Type 3 outlines: the text of a PDF stays selectable.
|
|
567
|
+
"pdf.fonttype": 42,
|
|
566
568
|
}
|
|
567
569
|
|
|
568
570
|
|
|
@@ -102,6 +102,31 @@ def test_svg_files_are_reproducible(tmp_path: Path) -> None:
|
|
|
102
102
|
assert a.read_bytes() == b.read_bytes()
|
|
103
103
|
|
|
104
104
|
|
|
105
|
+
def test_pdf_files_are_reproducible_and_embed_their_fonts(tmp_path: Path) -> None:
|
|
106
|
+
first = figkit.render(tmp_path / "a", "example", chart, outputs=(figkit.PDF,))
|
|
107
|
+
second = figkit.render(tmp_path / "b", "example", chart, outputs=(figkit.PDF,))
|
|
108
|
+
|
|
109
|
+
assert [p.name for p in first] == ["example.pdf", "example-dark.pdf"]
|
|
110
|
+
for a, b in zip(first, second, strict=True):
|
|
111
|
+
assert a.read_bytes() == b.read_bytes()
|
|
112
|
+
data = first[0].read_bytes()
|
|
113
|
+
assert b"/CreationDate" not in data
|
|
114
|
+
assert b"/Producer" not in data
|
|
115
|
+
# TrueType subsets keep the text selectable and searchable, unlike Type 3 outlines.
|
|
116
|
+
assert b"/FontFile2" in data
|
|
117
|
+
assert b"BricolageGrotesque" in data
|
|
118
|
+
assert check(tmp_path / "a") == []
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_check_reports_a_pdf_off_the_canvas(tmp_path: Path) -> None:
|
|
122
|
+
column = figkit.Output("pdf", width=3.5)
|
|
123
|
+
figkit.render(tmp_path, "column", lambda theme: chart(theme, 3.0), outputs=(column,))
|
|
124
|
+
|
|
125
|
+
assert any("pt wide, the canvas is 460.8 pt" in p for p in check(tmp_path))
|
|
126
|
+
assert check(tmp_path, width=3.5) == []
|
|
127
|
+
assert check(tmp_path, width=None) == []
|
|
128
|
+
|
|
129
|
+
|
|
105
130
|
def test_embedded_images_do_not_depend_on_the_png_compression(
|
|
106
131
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
107
132
|
) -> None:
|
figurekit-0.6.0/notes.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
```sh
|
|
2
|
-
uv add "figurekit==0.6.0"
|
|
3
|
-
```
|
|
4
|
-
|
|
5
|
-
### Added
|
|
6
|
-
|
|
7
|
-
- `font.math` in the tokens names the fonts of formulas: `italic` for variables and `fallback`
|
|
8
|
-
for characters that the other fonts lack.
|
|
9
|
-
- `render` fails with the character and the figure when a text or formula needs a glyph that no
|
|
10
|
-
font has, before it writes any file. `complete_glyphs` makes the same check for other code.
|
|
11
|
-
- The gallery shows a fitted decay with its formula and the fitted parameters in the subtitle.
|
|
12
|
-
|
|
13
|
-
### Changed
|
|
14
|
-
|
|
15
|
-
- Formulas set variables and Greek letters in DejaVu Sans italic, which comes with matplotlib.
|
|
16
|
-
Before, variables were upright in Bricolage Grotesque and Greek letters came from the serif
|
|
17
|
-
Computer Modern. Figures with formulas change on the next render.
|
|
18
|
-
- `register_fonts` fails if the math italic has no italic face instead of setting variables
|
|
19
|
-
upright.
|
|
20
|
-
|
|
21
|
-
**Changes:** https://github.com/BenBotsch/FigureKit/compare/v0.5.1...v0.6.0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|