1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#!/usr/bin/env python3
import os
import sys
import json
import xml.etree.ElementTree as ET
from copy import deepcopy
INPUT = sys.argv[1] if len(sys.argv) > 1 else "org.projecttick.ProjTLauncher.svg"
OUT_DIR = ".icon/assets"
os.makedirs(OUT_DIR, exist_ok=True)
tree = ET.parse(INPUT)
root = tree.getroot()
# SVG namespace fix (çünkü XML eğlenceli)
ns = {"svg": "http://www.w3.org/2000/svg"}
def strip_ns(tag):
return tag.split("}")[-1]
layers = []
# 1. group-based extraction
groups = [el for el in root if strip_ns(el.tag) == "g"]
if not groups:
# fallback: top-level shapes
groups = [el for el in root if strip_ns(el.tag) != "defs"]
for idx, g in enumerate(groups):
name = g.attrib.get("id", f"layer{idx}")
new_svg = ET.Element(root.tag, root.attrib)
new_svg.append(deepcopy(g))
out_path = os.path.join(OUT_DIR, f"{name}.svg")
ET.ElementTree(new_svg).write(out_path)
layers.append({
"image-name": f"assets/{name}.svg",
"name": name,
"position": {
"scale": 1.0,
"translation-in-points": [0, 0]
}
})
# JSON oluştur
icon_json = {
"color-space-for-untagged-svg-colors": "display-p3",
"groups": [
{
"layers": layers,
"shadow": {
"kind": "neutral",
"opacity": 0.5
},
"translucency": {
"enabled": False,
"value": 0.5
}
}
],
"supported-platforms": {
"squares": ["macOS"]
}
}
with open(".icon/icon.json", "w") as f:
json.dump(icon_json, f, indent=2)
print(f"{len(layers)} layer extracted -> .icon/assets/")
|