mcruft-vectorcraft 0.1.2__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.
- mcruft_vectorcraft-0.1.2/.gitignore +230 -0
- mcruft_vectorcraft-0.1.2/PKG-INFO +10 -0
- mcruft_vectorcraft-0.1.2/pyproject.toml +35 -0
- mcruft_vectorcraft-0.1.2/src/mcruft_vectorcraft/__init__.py +123 -0
- mcruft_vectorcraft-0.1.2/src/mcruft_vectorcraft/__version__.py +24 -0
- mcruft_vectorcraft-0.1.2/tests/test_vectorcraft.py +116 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs/Zensical documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
221
|
+
|
|
222
|
+
# OMC runtime state
|
|
223
|
+
.omc/
|
|
224
|
+
.superpowers/
|
|
225
|
+
|
|
226
|
+
# Generated by hatch-vcs; keep the release helper under lib/.
|
|
227
|
+
packages/*/src/*/__version__.py
|
|
228
|
+
!/lib/
|
|
229
|
+
/lib/*
|
|
230
|
+
!/lib/guard.sh
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mcruft-vectorcraft
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: VectorCraft engine for mcruft
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Requires-Dist: mcruft
|
|
8
|
+
Requires-Dist: pypdf
|
|
9
|
+
Provides-Extra: bundled
|
|
10
|
+
Requires-Dist: mcruft-vectorcraft-bin; extra == 'bundled'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# this_file: packages/mcruft_vectorcraft/pyproject.toml
|
|
2
|
+
[project]
|
|
3
|
+
license = "Apache-2.0"
|
|
4
|
+
name = "mcruft-vectorcraft"
|
|
5
|
+
description = "VectorCraft engine for mcruft"
|
|
6
|
+
dynamic = ["version"]
|
|
7
|
+
requires-python = ">=3.12"
|
|
8
|
+
dependencies = ["mcruft", "pypdf"]
|
|
9
|
+
|
|
10
|
+
[project.optional-dependencies]
|
|
11
|
+
bundled = ["mcruft-vectorcraft-bin"]
|
|
12
|
+
|
|
13
|
+
[project.entry-points."mcruft.engines"]
|
|
14
|
+
vectorcraft = "mcruft_vectorcraft:engine"
|
|
15
|
+
|
|
16
|
+
[tool.uv.sources]
|
|
17
|
+
mcruft = { workspace = true }
|
|
18
|
+
|
|
19
|
+
[build-system]
|
|
20
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
21
|
+
build-backend = "hatchling.build"
|
|
22
|
+
|
|
23
|
+
[tool.hatch.version]
|
|
24
|
+
source = "vcs"
|
|
25
|
+
fallback-version = "0.0.0"
|
|
26
|
+
|
|
27
|
+
[tool.hatch.version.raw-options]
|
|
28
|
+
root = "../.."
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.hooks.vcs]
|
|
31
|
+
version-file = "src/mcruft_vectorcraft/__version__.py"
|
|
32
|
+
|
|
33
|
+
[tool.uv]
|
|
34
|
+
# Rebuild editable installs when git state changes, so hatch-vcs metadata stays current.
|
|
35
|
+
cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true, tags = true } }]
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# this_file: packages/mcruft_vectorcraft/src/mcruft_vectorcraft/__init__.py
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from tempfile import TemporaryDirectory
|
|
5
|
+
|
|
6
|
+
from mcruft.engines.base import Capability
|
|
7
|
+
from mcruft.engines.cli import CliEngine, page_indexes, pixel_scale
|
|
8
|
+
from mcruft.report import Loss, Policy, Report
|
|
9
|
+
from pypdf import PdfReader, PdfWriter
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from .__version__ import __version__ as __version__
|
|
13
|
+
except ImportError:
|
|
14
|
+
from importlib.metadata import version
|
|
15
|
+
|
|
16
|
+
__version__ = version("mcruft-vectorcraft")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
CONVERSIONS = [
|
|
20
|
+
("svg", "pdf", "editable"),
|
|
21
|
+
("svg", "png", "fidelity"),
|
|
22
|
+
("svg", "ai", "editable"),
|
|
23
|
+
("svg", "vectorcraft", "editable"),
|
|
24
|
+
("pdf", "svg", "editable"),
|
|
25
|
+
("pdf", "psd", "fidelity"),
|
|
26
|
+
("vectorcraft", "pdf", "editable"),
|
|
27
|
+
("vectorcraft", "svg", "editable"),
|
|
28
|
+
("vectorcraft", "png", "fidelity"),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class VectorcraftEngine(CliEngine):
|
|
33
|
+
PRODUCT = "vectorcraft"
|
|
34
|
+
MIN_VERSION = "0.16.0"
|
|
35
|
+
|
|
36
|
+
def capabilities(self) -> list[Capability]:
|
|
37
|
+
routes = [("convert", *row) for row in CONVERSIONS]
|
|
38
|
+
routes += [
|
|
39
|
+
("outline_text", src, dst, "fidelity")
|
|
40
|
+
for src in ("pdf", "svg", "vectorcraft", "ai")
|
|
41
|
+
for dst in ("pdf", "svg")
|
|
42
|
+
]
|
|
43
|
+
routes += [("export_pages", src, "pdf", "editable") for src in ("vectorcraft", "svg", "ai")]
|
|
44
|
+
routes += [("export_pages", src, "png", "fidelity") for src in ("vectorcraft", "svg", "ai")]
|
|
45
|
+
routes += [("inspect", ext, ext, "editable") for ext in ("vectorcraft", "ai", "eps")]
|
|
46
|
+
return [Capability(*row, f"{self.PRODUCT}-cli {self.MIN_VERSION}") for row in routes]
|
|
47
|
+
|
|
48
|
+
def inspect(self, path: Path) -> list[tuple[float, float]]:
|
|
49
|
+
path = Path(path)
|
|
50
|
+
if path.suffix.lower() not in (".vectorcraft", ".ai", ".eps"):
|
|
51
|
+
return super().inspect(path)
|
|
52
|
+
info = json.loads(self.call(["info", path]))
|
|
53
|
+
# VectorCraft info uses [x, y, width, height], unlike DesignCraft bounds.
|
|
54
|
+
return [(float(a["rect"][2]), float(a["rect"][3])) for a in info["artboards"]]
|
|
55
|
+
|
|
56
|
+
def run(self, op: str, src: Path, dst: Path, *, policy: Policy, **opts) -> Report:
|
|
57
|
+
src, dst = Path(src), Path(dst)
|
|
58
|
+
self.check_route(op, src, dst, policy)
|
|
59
|
+
report = self.report(op, policy, [dst])
|
|
60
|
+
args = ["convert", src, dst]
|
|
61
|
+
if op == "outline_text":
|
|
62
|
+
args = [
|
|
63
|
+
"run",
|
|
64
|
+
"--in",
|
|
65
|
+
src,
|
|
66
|
+
"--cmd",
|
|
67
|
+
"select.all",
|
|
68
|
+
"--cmd",
|
|
69
|
+
"type.createOutlines",
|
|
70
|
+
"--export",
|
|
71
|
+
dst,
|
|
72
|
+
]
|
|
73
|
+
report.losses.append(
|
|
74
|
+
Loss(
|
|
75
|
+
"layout",
|
|
76
|
+
"re-imported via VectorCraft: links, annotations and forms may be dropped",
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
elif op == "export_pages":
|
|
80
|
+
count = len(json.loads(self.call(["info", src]))["artboards"])
|
|
81
|
+
pages = page_indexes(opts.get("pages"), count)
|
|
82
|
+
if dst.suffix.lower() == ".png":
|
|
83
|
+
report.outputs = []
|
|
84
|
+
for page in pages:
|
|
85
|
+
out = dst.with_name(f"{dst.stem}-{page:04d}.png")
|
|
86
|
+
self.call(
|
|
87
|
+
[
|
|
88
|
+
"convert",
|
|
89
|
+
src,
|
|
90
|
+
out,
|
|
91
|
+
"--artboard",
|
|
92
|
+
str(page),
|
|
93
|
+
"--scale",
|
|
94
|
+
str(pixel_scale(opts.get("dpi", 150))),
|
|
95
|
+
],
|
|
96
|
+
report,
|
|
97
|
+
)
|
|
98
|
+
report.outputs.append(out)
|
|
99
|
+
report.losses.append(Loss("raster", "vector artwork rasterised"))
|
|
100
|
+
return report
|
|
101
|
+
if len(set(pages)) != len(pages):
|
|
102
|
+
# --range drops duplicates; join single-artboard exports to retain them.
|
|
103
|
+
with TemporaryDirectory(dir=dst.parent) as directory, PdfWriter() as writer:
|
|
104
|
+
for index, page in enumerate(pages):
|
|
105
|
+
part = Path(directory) / f"{index}.pdf"
|
|
106
|
+
self.call([*args[:2], part, "--artboard", str(page)], report)
|
|
107
|
+
writer.append(PdfReader(part))
|
|
108
|
+
writer.write(dst)
|
|
109
|
+
return report
|
|
110
|
+
args += (
|
|
111
|
+
["--artboard", str(pages[0])]
|
|
112
|
+
if len(pages) == 1
|
|
113
|
+
else ["--range", ",".join(str(i + 1) for i in pages)]
|
|
114
|
+
)
|
|
115
|
+
elif dst.suffix.lower() == ".png":
|
|
116
|
+
args += ["--scale", str(pixel_scale(opts.get("dpi", 150)))]
|
|
117
|
+
if dst.suffix.lower() in (".png", ".psd"):
|
|
118
|
+
report.losses.append(Loss("raster", "vector artwork rasterised"))
|
|
119
|
+
self.call(args, report)
|
|
120
|
+
return report
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
engine = VectorcraftEngine()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.1.2'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 1, 2)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# this_file: packages/mcruft_vectorcraft/tests/test_vectorcraft.py
|
|
2
|
+
import pytest
|
|
3
|
+
from mcruft import UnsupportedRoute
|
|
4
|
+
from mcruft.engines.cli import run_cli
|
|
5
|
+
from mcruft_vectorcraft import engine
|
|
6
|
+
from PIL import Image
|
|
7
|
+
from pypdf import PdfReader, PdfWriter
|
|
8
|
+
|
|
9
|
+
pytestmark = pytest.mark.skipif(not engine.available(), reason="vectorcraft-cli not installed")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_unknown_route(tmp_path):
|
|
13
|
+
with pytest.raises(UnsupportedRoute):
|
|
14
|
+
engine.run("convert", tmp_path / "in.unknown", tmp_path / "out.unknown", policy="editable")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_declared_routes(tmp_path):
|
|
18
|
+
svg = tmp_path / "input.svg"
|
|
19
|
+
svg.write_text(
|
|
20
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="96pt" height="48pt">'
|
|
21
|
+
'<text x="3" y="24" font-family="Arial" font-size="12">Hello</text></svg>'
|
|
22
|
+
)
|
|
23
|
+
inputs = {"svg": svg}
|
|
24
|
+
for ext in ("pdf", "vectorcraft", "ai", "eps"):
|
|
25
|
+
inputs[ext] = tmp_path / f"input.{ext}"
|
|
26
|
+
run_cli([engine.binary(), "convert", svg, inputs[ext]])
|
|
27
|
+
exercised = set()
|
|
28
|
+
for n, cap in enumerate(engine.capabilities()):
|
|
29
|
+
src = inputs[cap.src]
|
|
30
|
+
dst = tmp_path / f"route-{n}.{cap.dst}"
|
|
31
|
+
if cap.op == "inspect":
|
|
32
|
+
assert engine.inspect(src) == [(96, 48)]
|
|
33
|
+
else:
|
|
34
|
+
report = engine.run(cap.op, src, dst, policy=cap.policy, pages=[0], dpi=144)
|
|
35
|
+
if cap.op == "export_pages" and cap.dst == "png":
|
|
36
|
+
dst = dst.with_name(f"{dst.stem}-0000.png")
|
|
37
|
+
assert report.outputs == [dst]
|
|
38
|
+
assert dst.stat().st_size > 0
|
|
39
|
+
if cap.dst == "pdf":
|
|
40
|
+
assert len(PdfReader(dst).pages) == 1
|
|
41
|
+
assert float(PdfReader(dst).pages[0].mediabox.width) == pytest.approx(96)
|
|
42
|
+
if cap.dst == "png":
|
|
43
|
+
with Image.open(dst) as image:
|
|
44
|
+
assert image.size == (192, 96)
|
|
45
|
+
assert any(loss.kind == "raster" for loss in report.losses)
|
|
46
|
+
if cap.dst == "psd":
|
|
47
|
+
with Image.open(dst) as image:
|
|
48
|
+
assert image.size == (96, 48)
|
|
49
|
+
assert any(loss.kind == "raster" for loss in report.losses)
|
|
50
|
+
if cap.op == "outline_text":
|
|
51
|
+
assert report.losses[0].detail == (
|
|
52
|
+
"re-imported via VectorCraft: links, annotations and forms may be dropped"
|
|
53
|
+
)
|
|
54
|
+
assert b"/FontFile" not in dst.read_bytes()
|
|
55
|
+
if cap.dst == "svg":
|
|
56
|
+
assert "<text" not in dst.read_text()
|
|
57
|
+
elif cap.dst == "svg":
|
|
58
|
+
assert "<text" in dst.read_text()
|
|
59
|
+
exercised.add((cap.op, cap.src, cap.dst, cap.policy))
|
|
60
|
+
assert {
|
|
61
|
+
(c.op, c.src, c.dst, c.policy) for c in engine.capabilities() if c.verified_with
|
|
62
|
+
} <= exercised
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_export_svg_png_page_contract(tmp_path):
|
|
66
|
+
src = tmp_path / "input.svg"
|
|
67
|
+
src.write_text('<svg xmlns="http://www.w3.org/2000/svg" width="96pt" height="48pt"/>')
|
|
68
|
+
report = engine.run(
|
|
69
|
+
"export_pages", src, tmp_path / "page.png", policy="fidelity", pages=[0], dpi=72
|
|
70
|
+
)
|
|
71
|
+
assert report.outputs == [tmp_path / "page-0000.png"]
|
|
72
|
+
with Image.open(report.outputs[0]) as image:
|
|
73
|
+
assert image.size == (96, 48)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_page_order_duplicates_and_warnings(tmp_path):
|
|
77
|
+
pdf = tmp_path / "input.pdf"
|
|
78
|
+
writer = PdfWriter()
|
|
79
|
+
writer.add_blank_page(96, 48)
|
|
80
|
+
writer.add_blank_page(144, 72)
|
|
81
|
+
writer.write(pdf)
|
|
82
|
+
native = tmp_path / "input.vectorcraft"
|
|
83
|
+
run_cli([engine.binary(), "convert", pdf, native])
|
|
84
|
+
for pages, expected in (
|
|
85
|
+
(None, [96, 144]),
|
|
86
|
+
([1], [144]),
|
|
87
|
+
([1, 0], [144, 96]),
|
|
88
|
+
([1, 0, 1], [144, 96, 144]),
|
|
89
|
+
):
|
|
90
|
+
dst = tmp_path / "selected.pdf"
|
|
91
|
+
report = engine.run("export_pages", native, dst, policy="editable", pages=pages)
|
|
92
|
+
assert [float(p.mediabox.width) for p in PdfReader(dst).pages] == expected
|
|
93
|
+
if pages == [1]:
|
|
94
|
+
assert any("Preserve editing" in warning for warning in report.warnings)
|
|
95
|
+
with pytest.raises((ValueError, IndexError)):
|
|
96
|
+
engine.run("export_pages", native, tmp_path / "bad.pdf", policy="editable", pages=[-1])
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_json_warnings_and_cli_failure(tmp_path, monkeypatch):
|
|
100
|
+
from mcruft import EngineFailed
|
|
101
|
+
|
|
102
|
+
binary = tmp_path / "fake-cli"
|
|
103
|
+
binary.write_text(
|
|
104
|
+
'#!/bin/sh\nif [ "$1" = "--version" ]; then echo "0.16.0"; exit; fi\n'
|
|
105
|
+
'echo \'{"warnings":["first"],"result":{"warnings":["second"]}}\'\n'
|
|
106
|
+
'echo \'{"warnings":["third"]}\'\n'
|
|
107
|
+
)
|
|
108
|
+
binary.chmod(0o755)
|
|
109
|
+
monkeypatch.setenv("MCRUFT_VECTORCRAFT_CLI", str(binary))
|
|
110
|
+
report = engine.run(
|
|
111
|
+
"outline_text", tmp_path / "in.svg", tmp_path / "out.svg", policy="fidelity"
|
|
112
|
+
)
|
|
113
|
+
assert report.warnings == ["first", "second", "third"]
|
|
114
|
+
binary.write_text('#!/bin/sh\necho "broken CLI" >&2\nexit 1\n')
|
|
115
|
+
with pytest.raises(EngineFailed, match="broken CLI"):
|
|
116
|
+
engine.run("convert", tmp_path / "in.svg", tmp_path / "out.pdf", policy="editable")
|