predictygraph 0.2.5__tar.gz → 0.3.1__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.
- predictygraph-0.3.1/LICENSE +73 -0
- predictygraph-0.3.1/NOTICE +11 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/PKG-INFO +9 -4
- {predictygraph-0.2.5 → predictygraph-0.3.1}/README.md +7 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/pyproject.toml +32 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/__init__.py +46 -19
- predictygraph-0.3.1/src/predictygraph/__main__.py +7 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/anim.py +14 -13
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/cli.py +9 -8
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/default.css +2 -2
- predictygraph-0.3.1/src/predictygraph/fonts/licenses/Bitstream-Vera.txt +15 -0
- predictygraph-0.3.1/src/predictygraph/fonts/licenses/OFL-1.1.txt +43 -0
- predictygraph-0.3.1/src/predictygraph/fonts/licenses/README.md +5 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts.py +28 -22
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/ir.py +5 -3
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/layout.py +40 -22
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/model.py +7 -6
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/parser.py +157 -26
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/render/__init__.py +5 -4
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/render/apng.py +37 -9
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/render/svg.py +20 -11
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/route.py +98 -38
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/safe.py +3 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/scene.py +271 -93
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/style.py +45 -15
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/styleutil.py +5 -6
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/text.py +3 -3
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/theme.py +17 -10
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/catppuccin-frappe.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/catppuccin-latte.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/catppuccin-macchiato.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/catppuccin-mocha.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/default.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/dracula.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/github-light.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/gruvbox-dark.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/hami.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/nord.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/solarized-dark.toml +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/themes/solarized-light.toml +2 -2
- predictygraph-0.3.1/src/predictygraph/themes/trunkline.toml +47 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_annotations.py +6 -3
- predictygraph-0.3.1/tests/test_blocks.py +63 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_diagonal.py +2 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_fixes.py +4 -3
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_hardening.py +4 -4
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_predictygraph.py +14 -13
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_routing.py +3 -2
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_scene.py +9 -8
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_stack.py +25 -18
- {predictygraph-0.2.5 → predictygraph-0.3.1}/tests/test_targets.py +4 -4
- predictygraph-0.3.1/tests/test_trunkline.py +49 -0
- predictygraph-0.2.5/src/predictygraph/__main__.py +0 -7
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/Carlito-Bold.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/Carlito-Regular.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/DejaVuSans-Bold.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/DejaVuSans.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/LiberationMono-Bold.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/LiberationMono-Regular.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/LiberationSans-Bold.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/LiberationSans-Regular.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/LiberationSerif-Bold.ttf +0 -0
- {predictygraph-0.2.5 → predictygraph-0.3.1}/src/predictygraph/fonts/LiberationSerif-Regular.ttf +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright [yyyy] [name of copyright owner]
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
predictygraph
|
|
2
|
+
Copyright 2026 Reza Jelveh
|
|
3
|
+
|
|
4
|
+
Originally created by Reza Jelveh.
|
|
5
|
+
https://github.com/predictygraph/predictygraph
|
|
6
|
+
|
|
7
|
+
This product is licensed under the Apache License, Version 2.0.
|
|
8
|
+
Redistributions and derivative works must keep this NOTICE file.
|
|
9
|
+
|
|
10
|
+
The name "predictygraph" and its mascot logo are not licensed under
|
|
11
|
+
the Apache License. Forks must use a different name and logo.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: predictygraph
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Predictable graphs: a readable, CSS-styled diagram DSL with per-group layouts, rendered to SVG/APNG
|
|
5
5
|
Author-Email: Reza Jelveh <git@jelveh.me>
|
|
6
|
-
License:
|
|
6
|
+
License: Apache-2.0
|
|
7
7
|
Requires-Python: >=3.11
|
|
8
8
|
Requires-Dist: tinycss2>=1.5.1
|
|
9
9
|
Requires-Dist: typer>=0.26.8
|
|
@@ -13,9 +13,9 @@ Requires-Dist: cairosvg>=2.7; extra == "apng"
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
|
|
15
15
|
<!--
|
|
16
|
-
SPDX-FileCopyrightText: 2026
|
|
16
|
+
SPDX-FileCopyrightText: 2026 Reza Jelveh
|
|
17
17
|
|
|
18
|
-
SPDX-License-Identifier:
|
|
18
|
+
SPDX-License-Identifier: Apache-2.0
|
|
19
19
|
-->
|
|
20
20
|
|
|
21
21
|
# predictygraph
|
|
@@ -24,6 +24,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
24
24
|
plain-CSS styling, and static or animated SVG/APNG output (no browser).
|
|
25
25
|
Spec: [docs/SPEC.md](docs/SPEC.md). Docs: [predictygraph.github.io](https://predictygraph.github.io/).
|
|
26
26
|
Editor support: [tree-sitter-pdg](https://github.com/predictygraph/tree-sitter-pdg).
|
|
27
|
+
In the browser: [predictygraph-js](https://github.com/predictygraph/predictygraph-js).
|
|
27
28
|
Rendered examples and the gallery: [predictygraph.github.io](https://predictygraph.github.io/). This repo keeps
|
|
28
29
|
only `.pdg` sources; images live in the docs repo (git-lfs).
|
|
29
30
|
|
|
@@ -83,3 +84,7 @@ and hosts.
|
|
|
83
84
|
predictygraph keeps what we love from both (diagrams as readable text) and adds what we
|
|
84
85
|
missed: per-group layouts, plain-CSS styling, and deterministic static SVG with no
|
|
85
86
|
browser in the loop.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Apache-2.0, see [LICENSE](LICENSE). Forks must keep [NOTICE](NOTICE). Bundled fonts keep their own licences in [fonts/licenses](src/predictygraph/fonts/licenses).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
SPDX-FileCopyrightText: 2026
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Reza Jelveh
|
|
3
3
|
|
|
4
|
-
SPDX-License-Identifier:
|
|
4
|
+
SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
-->
|
|
6
6
|
|
|
7
7
|
# predictygraph
|
|
@@ -10,6 +10,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
10
10
|
plain-CSS styling, and static or animated SVG/APNG output (no browser).
|
|
11
11
|
Spec: [docs/SPEC.md](docs/SPEC.md). Docs: [predictygraph.github.io](https://predictygraph.github.io/).
|
|
12
12
|
Editor support: [tree-sitter-pdg](https://github.com/predictygraph/tree-sitter-pdg).
|
|
13
|
+
In the browser: [predictygraph-js](https://github.com/predictygraph/predictygraph-js).
|
|
13
14
|
Rendered examples and the gallery: [predictygraph.github.io](https://predictygraph.github.io/). This repo keeps
|
|
14
15
|
only `.pdg` sources; images live in the docs repo (git-lfs).
|
|
15
16
|
|
|
@@ -69,3 +70,7 @@ and hosts.
|
|
|
69
70
|
predictygraph keeps what we love from both (diagrams as readable text) and adds what we
|
|
70
71
|
missed: per-group layouts, plain-CSS styling, and deterministic static SVG with no
|
|
71
72
|
browser in the loop.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
Apache-2.0, see [LICENSE](LICENSE). Forks must keep [NOTICE](NOTICE). Bundled fonts keep their own licences in [fonts/licenses](src/predictygraph/fonts/licenses).
|
|
@@ -12,10 +12,10 @@ dependencies = [
|
|
|
12
12
|
]
|
|
13
13
|
requires-python = ">=3.11"
|
|
14
14
|
readme = "README.md"
|
|
15
|
-
version = "0.
|
|
15
|
+
version = "0.3.1"
|
|
16
16
|
|
|
17
17
|
[project.license]
|
|
18
|
-
text = "
|
|
18
|
+
text = "Apache-2.0"
|
|
19
19
|
|
|
20
20
|
[project.optional-dependencies]
|
|
21
21
|
apng = [
|
|
@@ -40,6 +40,36 @@ testpaths = [
|
|
|
40
40
|
"tests",
|
|
41
41
|
]
|
|
42
42
|
|
|
43
|
+
[tool.ruff]
|
|
44
|
+
line-length = 140
|
|
45
|
+
target-version = "py311"
|
|
46
|
+
|
|
47
|
+
[tool.ruff.lint]
|
|
48
|
+
select = [
|
|
49
|
+
"F",
|
|
50
|
+
"E",
|
|
51
|
+
"W",
|
|
52
|
+
"I",
|
|
53
|
+
"UP",
|
|
54
|
+
"B",
|
|
55
|
+
"SIM",
|
|
56
|
+
]
|
|
57
|
+
ignore = [
|
|
58
|
+
"E501",
|
|
59
|
+
"B007",
|
|
60
|
+
"B008",
|
|
61
|
+
"B019",
|
|
62
|
+
"B023",
|
|
63
|
+
"B039",
|
|
64
|
+
"B905",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint.isort]
|
|
68
|
+
split-on-trailing-comma = false
|
|
69
|
+
|
|
70
|
+
[tool.ruff.format]
|
|
71
|
+
skip-magic-trailing-comma = true
|
|
72
|
+
|
|
43
73
|
[dependency-groups]
|
|
44
74
|
dev = [
|
|
45
75
|
"pytest>=9.1.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2026
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Reza Jelveh
|
|
2
2
|
#
|
|
3
|
-
# SPDX-License-Identifier:
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
"""Predictygraph: readable diagram DSL -> Scene IR -> SVG / APNG.
|
|
6
6
|
|
|
@@ -15,6 +15,7 @@ Pipeline (mirrors slidr):
|
|
|
15
15
|
Labels are measured with the fonts of the render *target* (see fonts.py): the platform
|
|
16
16
|
or viewer the SVG is made for. Showing it somewhere else can make labels overflow.
|
|
17
17
|
"""
|
|
18
|
+
|
|
18
19
|
from __future__ import annotations
|
|
19
20
|
|
|
20
21
|
from pathlib import Path
|
|
@@ -24,15 +25,28 @@ from .ir import Scene
|
|
|
24
25
|
from .layout import layout
|
|
25
26
|
from .parser import PdgSyntaxError, parse, parse_file
|
|
26
27
|
from .render import write_apng, write_svg
|
|
27
|
-
from .route import Router
|
|
28
|
+
from .route import Router, bump, straighten
|
|
28
29
|
from .scene import SceneBuilder
|
|
29
30
|
from .style import apply_styles
|
|
30
31
|
from .text import use_target
|
|
31
32
|
from .theme import ThemeError, list_themes, theme_css
|
|
32
33
|
|
|
33
|
-
__all__ = [
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
__all__ = [
|
|
35
|
+
"render",
|
|
36
|
+
"render_file",
|
|
37
|
+
"build_scene",
|
|
38
|
+
"scene_from_file",
|
|
39
|
+
"parse",
|
|
40
|
+
"parse_file",
|
|
41
|
+
"write_svg",
|
|
42
|
+
"write_apng",
|
|
43
|
+
"Scene",
|
|
44
|
+
"PdgSyntaxError",
|
|
45
|
+
"ThemeError",
|
|
46
|
+
"FontWarning",
|
|
47
|
+
"TARGETS",
|
|
48
|
+
"list_themes",
|
|
49
|
+
]
|
|
36
50
|
|
|
37
51
|
MAX_PASSES = 4
|
|
38
52
|
|
|
@@ -59,21 +73,20 @@ def _layout_and_route(doc) -> Router:
|
|
|
59
73
|
"""Lay out, route; if a channel between two ranks is too narrow for its lanes,
|
|
60
74
|
widen exactly that gap and lay out again."""
|
|
61
75
|
router = None
|
|
62
|
-
for _ in range(MAX_PASSES):
|
|
76
|
+
for _ in range(MAX_PASSES * 2):
|
|
63
77
|
layout(doc)
|
|
64
78
|
router = Router(doc).route()
|
|
65
79
|
if not router.needs:
|
|
66
|
-
|
|
80
|
+
if not straighten(doc, router):
|
|
81
|
+
break
|
|
82
|
+
continue
|
|
67
83
|
for (gid, rank), need in router.needs.items():
|
|
68
84
|
g = doc.root if gid == doc.root.id else doc.items[gid]
|
|
69
|
-
|
|
70
|
-
extra[rank] = extra.get(rank, 0.0) + need
|
|
71
|
-
g.extra_gap = extra
|
|
85
|
+
bump(g, "extra_gap", rank, need)
|
|
72
86
|
return router
|
|
73
87
|
|
|
74
88
|
|
|
75
|
-
def build_scene(doc, extra_css: list[str] | None = None, theme: str | None = None,
|
|
76
|
-
target: str | None = None) -> Scene:
|
|
89
|
+
def build_scene(doc, extra_css: list[str] | None = None, theme: str | None = None, target: str | None = None) -> Scene:
|
|
77
90
|
"""Style, then iterate layout -> route -> scene until edges clear the group titles
|
|
78
91
|
(a crossed title that cannot slide asks for a wider group)."""
|
|
79
92
|
target = resolve_target(doc, target)
|
|
@@ -92,17 +105,31 @@ def build_scene(doc, extra_css: list[str] | None = None, theme: str | None = Non
|
|
|
92
105
|
return scene
|
|
93
106
|
|
|
94
107
|
|
|
95
|
-
def scene_from_file(
|
|
96
|
-
|
|
108
|
+
def scene_from_file(
|
|
109
|
+
path: str | Path, extra_css: list[str] | None = None, theme: str | None = None, allow_outside: bool = False, target: str | None = None
|
|
110
|
+
) -> Scene:
|
|
97
111
|
return build_scene(parse_file(path, allow_outside), extra_css, theme, target)
|
|
98
112
|
|
|
99
113
|
|
|
100
|
-
def render(
|
|
101
|
-
|
|
114
|
+
def render(
|
|
115
|
+
text: str,
|
|
116
|
+
base_dir: str = ".",
|
|
117
|
+
extra_css: list[str] | None = None,
|
|
118
|
+
theme: str | None = None,
|
|
119
|
+
t: float | None = None,
|
|
120
|
+
allow_outside: bool = False,
|
|
121
|
+
target: str | None = None,
|
|
122
|
+
) -> str:
|
|
102
123
|
"""SVG text. t=None: animated (SMIL) SVG; t=seconds: static frame at that time."""
|
|
103
124
|
return write_svg(build_scene(parse(text, base_dir, allow_outside), extra_css, theme, target), t)
|
|
104
125
|
|
|
105
126
|
|
|
106
|
-
def render_file(
|
|
107
|
-
|
|
127
|
+
def render_file(
|
|
128
|
+
path: str | Path,
|
|
129
|
+
extra_css: list[str] | None = None,
|
|
130
|
+
theme: str | None = None,
|
|
131
|
+
t: float | None = None,
|
|
132
|
+
allow_outside: bool = False,
|
|
133
|
+
target: str | None = None,
|
|
134
|
+
) -> str:
|
|
108
135
|
return write_svg(scene_from_file(path, extra_css, theme, allow_outside, target), t)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2026
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Reza Jelveh
|
|
2
2
|
#
|
|
3
|
-
# SPDX-License-Identifier:
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
"""Animation tracks: format-independent keyframe descriptions.
|
|
6
6
|
|
|
@@ -9,6 +9,7 @@ attached to a Scene IR element. The first keyframe always equals the static valu
|
|
|
9
9
|
writers that cannot animate (PDF, PNG, ODP) just use it. Writers that can animate
|
|
10
10
|
(SVG via SMIL) emit the track; frame writers (APNG) sample it with ``Track.at(t)``.
|
|
11
11
|
"""
|
|
12
|
+
|
|
12
13
|
from __future__ import annotations
|
|
13
14
|
|
|
14
15
|
import math
|
|
@@ -16,7 +17,7 @@ import re
|
|
|
16
17
|
|
|
17
18
|
from .safe import NUM, numbers
|
|
18
19
|
|
|
19
|
-
FLOW_MODES = ("forward", "reverse", "both", "auto")
|
|
20
|
+
FLOW_MODES = ("forward", "reverse", "both", "auto", "draw")
|
|
20
21
|
BORDER_MODES = ("march", "pulse", "glow")
|
|
21
22
|
|
|
22
23
|
|
|
@@ -57,7 +58,7 @@ class Track:
|
|
|
57
58
|
f = ph - i
|
|
58
59
|
return vs[i] + (vs[i + 1] - vs[i]) * f
|
|
59
60
|
|
|
60
|
-
def shifted(self, delta: float) ->
|
|
61
|
+
def shifted(self, delta: float) -> Track:
|
|
61
62
|
return Track(self.attr, [v + delta for v in self.values], self.dur)
|
|
62
63
|
|
|
63
64
|
|
|
@@ -67,15 +68,19 @@ def flow_tracks(dash: str, dur: float, reverse: bool) -> list[Track]:
|
|
|
67
68
|
return [Track("stroke-dashoffset", [0.0, L] if reverse else [L, 0.0], dur)]
|
|
68
69
|
|
|
69
70
|
|
|
71
|
+
def draw_tracks(length: float, dur: float) -> list[Track]:
|
|
72
|
+
"""Trace: hold drawn, erase from the start, redraw from the start (dasharray "L L").
|
|
73
|
+
Offsets 0 and -2L are the same picture, so the loop is seamless and t=0 is complete."""
|
|
74
|
+
return [Track("stroke-dashoffset", [0.0, 0.0, -length, -2 * length], dur)]
|
|
75
|
+
|
|
76
|
+
|
|
70
77
|
def border_tracks(mode: str, sw: float, dash: str | None, dur: float) -> list[Track]:
|
|
71
78
|
if mode == "march":
|
|
72
79
|
return [Track("stroke-dashoffset", [dash_len(dash) or 10.0, 0.0], dur)]
|
|
73
80
|
if mode == "pulse":
|
|
74
|
-
return [Track("stroke-opacity", [1.0, 0.35, 1.0], dur),
|
|
75
|
-
Track("stroke-width", [sw, sw * 2.2, sw], dur)]
|
|
81
|
+
return [Track("stroke-opacity", [1.0, 0.35, 1.0], dur), Track("stroke-width", [sw, sw * 2.2, sw], dur)]
|
|
76
82
|
if mode == "glow": # applied to a halo copy behind the shape
|
|
77
|
-
return [Track("stroke-width", [sw, sw + 10, sw + 10], dur),
|
|
78
|
-
Track("stroke-opacity", [0.7, 0.0, 0.0], dur)]
|
|
83
|
+
return [Track("stroke-width", [sw, sw + 10, sw + 10], dur), Track("stroke-opacity", [0.7, 0.0, 0.0], dur)]
|
|
79
84
|
return []
|
|
80
85
|
|
|
81
86
|
|
|
@@ -83,9 +88,5 @@ def loop_length(durations: list[float], cap: float = 12.0) -> float:
|
|
|
83
88
|
"""Shortest time after which every track is back at its start (LCM on a 10 ms grid)."""
|
|
84
89
|
if not durations:
|
|
85
90
|
return 1.0
|
|
86
|
-
|
|
87
|
-
for d in durations:
|
|
88
|
-
c = max(1, round(d * 100))
|
|
89
|
-
l = l * c // math.gcd(l, c)
|
|
90
|
-
lcm = l / 100
|
|
91
|
+
lcm = math.lcm(*(max(1, round(d * 100)) for d in durations)) / 100
|
|
91
92
|
return lcm if lcm <= cap else min(max(durations), cap)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2026
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Reza Jelveh
|
|
2
2
|
#
|
|
3
|
-
# SPDX-License-Identifier:
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
"""predictygraph CLI: .pdg -> Scene IR -> .svg (animated or static) or .png (APNG)."""
|
|
6
|
+
|
|
6
7
|
from __future__ import annotations
|
|
7
8
|
|
|
8
9
|
import warnings
|
|
@@ -21,10 +22,11 @@ def main(
|
|
|
21
22
|
out: Path | None = typer.Option(None, "-o", "--out", help="Output .svg or .png (default: <src>.svg)"),
|
|
22
23
|
css: list[Path] = typer.Option([], "--css", help="Extra stylesheet(s), applied after the file's own"),
|
|
23
24
|
theme: str | None = typer.Option(None, "--theme", help="Theme name or .toml path (overrides graph theme=)"),
|
|
24
|
-
target: str | None = typer.Option(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
target: str | None = typer.Option(
|
|
26
|
+
None,
|
|
27
|
+
"--target",
|
|
28
|
+
help="Where the SVG will be shown: web, linux, macos, windows or host (overrides graph target=). Labels are measured with that platform's fonts",
|
|
29
|
+
),
|
|
28
30
|
themes: bool = typer.Option(False, "--list-themes", help="List bundled themes and exit"),
|
|
29
31
|
check: bool = typer.Option(False, "--check", help="Parse, lay out and route only; report errors"),
|
|
30
32
|
static: bool = typer.Option(False, "--static", help="SVG without animation (first frame)"),
|
|
@@ -34,8 +36,7 @@ def main(
|
|
|
34
36
|
scale: float = typer.Option(2.0, "--scale", help="PNG pixel scale"),
|
|
35
37
|
width: int | None = typer.Option(None, "--width", help="PNG width in pixels (overrides --scale)"),
|
|
36
38
|
colors: int | None = typer.Option(None, "--colors", help="PNG palette size, 2-256 (smaller files)"),
|
|
37
|
-
allow_outside: bool = typer.Option(False, "--allow-outside",
|
|
38
|
-
help="Let image= and css \"...\" read files outside the input's directory"),
|
|
39
|
+
allow_outside: bool = typer.Option(False, "--allow-outside", help='Let image= and css "..." read files outside the input\'s directory'),
|
|
39
40
|
) -> None:
|
|
40
41
|
if themes:
|
|
41
42
|
typer.echo("\n".join(list_themes()))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* SPDX-FileCopyrightText: 2026
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Reza Jelveh
|
|
3
3
|
*
|
|
4
|
-
* SPDX-License-Identifier:
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*
|
|
6
6
|
* Base layer. Cascade: default.css < theme < css in the .pdg file < --css.
|
|
7
7
|
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is a trademark of Bitstream, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of the fonts accompanying this license ("Fonts") and associated documentation files (the "Font Software"), to reproduce and distribute the Font Software, including without limitation the rights to use, copy, merge, publish, distribute, and/or sell copies of the Font Software, and to permit persons to whom the Font Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright and trademark notices and this permission notice shall be included in all copies of one or more of the Font Software typefaces.
|
|
6
|
+
|
|
7
|
+
The Font Software may be modified, altered, or added to, and in particular the designs of glyphs or characters in the Fonts may be modified and additional glyphs or characters may be added to the Fonts, only if the fonts are renamed to names not containing either the words "Bitstream" or the word "Vera".
|
|
8
|
+
|
|
9
|
+
This License becomes null and void to the extent applicable to Fonts or Font Software that has been modified and is distributed under the "Bitstream Vera" names.
|
|
10
|
+
|
|
11
|
+
The Font Software may be sold as part of a larger software package but no copy of one or more of the Font Software typefaces may be sold by itself.
|
|
12
|
+
|
|
13
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
14
|
+
|
|
15
|
+
Except as contained in this notice, the names of Gnome, the Gnome Foundation, and Bitstream Inc., shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from the Gnome Foundation or Bitstream Inc., respectively. For further information, contact: fonts at gnome dot org.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
SIL OPEN FONT LICENSE
|
|
2
|
+
|
|
3
|
+
Version 1.1 - 26 February 2007
|
|
4
|
+
|
|
5
|
+
PREAMBLE
|
|
6
|
+
|
|
7
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
|
8
|
+
|
|
9
|
+
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
|
10
|
+
|
|
11
|
+
DEFINITIONS
|
|
12
|
+
|
|
13
|
+
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
|
14
|
+
|
|
15
|
+
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
|
|
16
|
+
|
|
17
|
+
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
|
18
|
+
|
|
19
|
+
"Modified Version" refers to any derivative made by adding to, deleting, or substituting — in part or in whole — any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
|
20
|
+
|
|
21
|
+
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
|
22
|
+
|
|
23
|
+
PERMISSION & CONDITIONS
|
|
24
|
+
|
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
|
26
|
+
|
|
27
|
+
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
|
28
|
+
|
|
29
|
+
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
|
30
|
+
|
|
31
|
+
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
|
32
|
+
|
|
33
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
|
34
|
+
|
|
35
|
+
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
|
36
|
+
|
|
37
|
+
TERMINATION
|
|
38
|
+
|
|
39
|
+
This license becomes null and void if any of the above conditions are not met.
|
|
40
|
+
|
|
41
|
+
DISCLAIMER
|
|
42
|
+
|
|
43
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Metric-only subsets (no outlines) of free fonts, used to measure label widths.
|
|
2
|
+
|
|
3
|
+
- DejaVuSans*.ttf: Copyright 2003 Bitstream, Inc.; 2006 Tavmjong Bah. Bitstream-Vera.txt
|
|
4
|
+
- LiberationSans/Serif/Mono-*.ttf: Copyright 2010 Google Corporation; 2012 Red Hat, Inc. OFL-1.1.txt
|
|
5
|
+
- Carlito-*.ttf: Copyright 2010-2013 tyPoland Lukasz Dziedzic. OFL-1.1.txt
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2026
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Reza Jelveh
|
|
2
2
|
#
|
|
3
|
-
# SPDX-License-Identifier:
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
"""Pick the font file used to measure a label, for a given render target.
|
|
6
6
|
|
|
@@ -16,6 +16,7 @@ Bundled metric fonts (no outlines, widths and kerning only) stand in for common
|
|
|
16
16
|
including proprietary ones with identical widths (Liberation Sans = Arial/Helvetica,
|
|
17
17
|
Liberation Serif = Times New Roman, Carlito = Calibri).
|
|
18
18
|
"""
|
|
19
|
+
|
|
19
20
|
from __future__ import annotations
|
|
20
21
|
|
|
21
22
|
import functools
|
|
@@ -36,31 +37,34 @@ METRIC = {
|
|
|
36
37
|
}
|
|
37
38
|
# Proprietary or common fonts with identical advance widths to a bundled one.
|
|
38
39
|
ALIASES = {
|
|
39
|
-
"arial": "liberation sans",
|
|
40
|
+
"arial": "liberation sans",
|
|
41
|
+
"helvetica": "liberation sans",
|
|
42
|
+
"helvetica neue": "liberation sans",
|
|
40
43
|
"arimo": "liberation sans",
|
|
41
|
-
"times new roman": "liberation serif",
|
|
42
|
-
"
|
|
44
|
+
"times new roman": "liberation serif",
|
|
45
|
+
"times": "liberation serif",
|
|
46
|
+
"tinos": "liberation serif",
|
|
47
|
+
"courier new": "liberation mono",
|
|
48
|
+
"courier": "liberation mono",
|
|
49
|
+
"cousine": "liberation mono",
|
|
43
50
|
"calibri": "carlito",
|
|
44
|
-
"bitstream vera sans": "dejavu sans",
|
|
51
|
+
"bitstream vera sans": "dejavu sans",
|
|
52
|
+
"verdana": "dejavu sans",
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
# Fonts each platform ships, and what the generic CSS families resolve to there.
|
|
48
56
|
PLATFORMS = {
|
|
49
57
|
"linux": {
|
|
50
58
|
"has": {"dejavu sans", "liberation sans", "liberation serif", "liberation mono", "carlito"},
|
|
51
|
-
"generic": {"sans-serif": "dejavu sans", "serif": "liberation serif", "monospace": "liberation mono",
|
|
52
|
-
"system-ui": "dejavu sans"},
|
|
59
|
+
"generic": {"sans-serif": "dejavu sans", "serif": "liberation serif", "monospace": "liberation mono", "system-ui": "dejavu sans"},
|
|
53
60
|
},
|
|
54
61
|
"macos": {
|
|
55
|
-
"has": {"helvetica", "helvetica neue", "arial", "times", "times new roman", "courier", "courier new",
|
|
56
|
-
|
|
57
|
-
"generic": {"sans-serif": "helvetica", "serif": "times", "monospace": "courier",
|
|
58
|
-
"system-ui": "helvetica neue"},
|
|
62
|
+
"has": {"helvetica", "helvetica neue", "arial", "times", "times new roman", "courier", "courier new", "verdana"},
|
|
63
|
+
"generic": {"sans-serif": "helvetica", "serif": "times", "monospace": "courier", "system-ui": "helvetica neue"},
|
|
59
64
|
},
|
|
60
65
|
"windows": {
|
|
61
66
|
"has": {"arial", "times new roman", "courier new", "calibri", "verdana"},
|
|
62
|
-
"generic": {"sans-serif": "arial", "serif": "times new roman", "monospace": "courier new",
|
|
63
|
-
"system-ui": "arial"},
|
|
67
|
+
"generic": {"sans-serif": "arial", "serif": "times new roman", "monospace": "courier new", "system-ui": "arial"},
|
|
64
68
|
},
|
|
65
69
|
}
|
|
66
70
|
TARGETS = ("host", "web", *PLATFORMS)
|
|
@@ -79,9 +83,9 @@ def families(css: str) -> list[str]:
|
|
|
79
83
|
|
|
80
84
|
@dataclass(frozen=True)
|
|
81
85
|
class FontChoice:
|
|
82
|
-
path: str | None
|
|
83
|
-
family: str
|
|
84
|
-
exact: bool
|
|
86
|
+
path: str | None # file to measure with; None = Pillow's built-in default
|
|
87
|
+
family: str # the family the viewer is expected to draw with
|
|
88
|
+
exact: bool # True if widths are known to match that family
|
|
85
89
|
|
|
86
90
|
|
|
87
91
|
def bundled(family: str, bold: bool) -> str | None:
|
|
@@ -98,8 +102,9 @@ def fontconfig(family: str, bold: bool) -> tuple[str | None, str | None]:
|
|
|
98
102
|
"""(file, resolved family) from fc-match, or (None, None) without fontconfig."""
|
|
99
103
|
pattern = family + (":bold" if bold else "")
|
|
100
104
|
try:
|
|
101
|
-
out = subprocess.run(
|
|
102
|
-
|
|
105
|
+
out = subprocess.run(
|
|
106
|
+
["fc-match", "-f", "%{file}\t%{family[0]}", "--", pattern], capture_output=True, text=True, timeout=5, check=False
|
|
107
|
+
).stdout.strip()
|
|
103
108
|
except (OSError, subprocess.SubprocessError):
|
|
104
109
|
return None, None
|
|
105
110
|
path, _, fam = out.partition("\t")
|
|
@@ -142,11 +147,12 @@ class FontResolver:
|
|
|
142
147
|
path, got = fontconfig(fam, bold)
|
|
143
148
|
if path and got == fam:
|
|
144
149
|
return FontChoice(path, fam, True)
|
|
145
|
-
if
|
|
150
|
+
if b := bundled(fam, bold):
|
|
146
151
|
return FontChoice(b, fam, True)
|
|
147
152
|
path, got = fontconfig(fams[0], bold)
|
|
148
|
-
self.warn(
|
|
149
|
-
|
|
153
|
+
self.warn(
|
|
154
|
+
f"font {fams[0]!r} is not installed; measuring with {got or 'a default font'} instead. Set a target (e.g. --target web) or install the font"
|
|
155
|
+
)
|
|
150
156
|
return FontChoice(path, got or fams[0], False)
|
|
151
157
|
|
|
152
158
|
@functools.lru_cache(maxsize=256)
|