mcruft-vectorcraft 0.1.2__py3-none-any.whl
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.
|
@@ -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,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,6 @@
|
|
|
1
|
+
mcruft_vectorcraft/__init__.py,sha256=ZWtqXZOfGT58rU2RYSYEMzQ79lmZUyKveFW3EcWlPaQ,4856
|
|
2
|
+
mcruft_vectorcraft/__version__.py,sha256=Q6ScJXlkBsUI-cazSvpYPMyIVUB-Vd0R3pq3_rM1wmI,520
|
|
3
|
+
mcruft_vectorcraft-0.1.2.dist-info/METADATA,sha256=MrxKPV8leS83zGsZkUpHYjcy0xVTsY6DRG2vcTx8UYo,281
|
|
4
|
+
mcruft_vectorcraft-0.1.2.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
5
|
+
mcruft_vectorcraft-0.1.2.dist-info/entry_points.txt,sha256=dCGXwDiqvyrmjVZ1RyZxbi7OaPNSxeWVBUNMmBYz0D4,57
|
|
6
|
+
mcruft_vectorcraft-0.1.2.dist-info/RECORD,,
|