46 svgDoc = QDomDocument()
47 svgBaseElement = svgDoc.createElement(
"svg")
48 svgBaseElement.setAttribute(
49 "xmlns:osb",
"http://www.openswatchbook.org/uri/2009/osb")
50 svgBaseElement.setAttribute(
51 "xmlns:svg",
"http://www.w3.org/2000/svg")
52 svgBaseElement.setAttribute(
53 "xmlns:dc",
"http://purl.org/dc/elements/1.1/")
54 svgBaseElement.setAttribute(
55 "xmlns:cc",
"http://creativecommons.org/ns#")
56 svgBaseElement.setAttribute(
57 "xmlns:rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#")
58 svgDefs = svgDoc.createElement(
"defs")
59 svgSwatches = svgDoc.createElement(
"g")
60 svgSwatches.setAttribute(
"id",
"Swatches")
62 svgMeta = svgDoc.createElement(
"metadata")
63 svgBaseElement.appendChild(svgMeta)
64 rdf = svgDoc.createElement(
"rdf:RDF")
65 ccwork = svgDoc.createElement(
"cc:Work")
66 dctitle = svgDoc.createElement(
"dc:title")
67 dcdescription = svgDoc.createElement(
"dc:description")
68 dctitle.appendChild(svgDoc.createTextNode(self.
paletteName))
69 dcdescription.appendChild(svgDoc.createTextNode(
71 ccwork.appendChild(dctitle)
72 ccwork.appendChild(dcdescription)
73 rdf.appendChild(ccwork)
74 svgMeta.appendChild(rdf)
80 for groupName
in groupNames:
82 groupTitle = svgDoc.createElement(
"text")
83 groupTitle.setAttribute(
"x", str(Column * 20))
84 groupTitle.setAttribute(
"y", str(Row * 20 + 15))
85 groupTitle.appendChild(svgDoc.createTextNode(groupName))
86 svgSwatches.appendChild(groupTitle)
89 for i
in range(slotCount):
92 swatchName =
"{i}-{name}".format(i=i, name=entry.name())
93 swatchName = swatchName.replace(
" ",
"-")
94 swatchName = swatchName.replace(
"(",
"-")
95 swatchName = swatchName.replace(
")",
"-")
97 swatchMain = svgDoc.createElement(
"linearGradient")
98 swatchMain.setAttribute(
"osb:paint",
"solid")
99 swatchMain.setAttribute(
"id", swatchName)
100 swatchSub = svgDoc.createElement(
"stop")
102 color = entry.color()
103 iccColor =
"icc-color(" + color.colorProfile()
104 for c
in range(len(color.componentsOrdered()) - 1):
105 iccColor =
"{col},{c}".format(
106 col=iccColor, c=color.componentsOrdered()[c])
107 iccColor = iccColor +
")"
108 if color.colorProfile()
not in iccProfileList:
109 iccProfileList.append(color.colorProfile())
111 color.setColorSpace(
"RGBA",
"U8",
"sRGB built-in")
112 red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0)
113 green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0)
114 blue = max(min(int(color.componentsOrdered()[2] * 255), 255), 0)
115 hexcode =
"#{red:02x}{green:02x}{blue:02x}".format(
116 red=red, green=green, blue=blue)
118 swatchSub.setAttribute(
120 "stop-color: {hex} {color};stop-opacity:1;".format(
121 hex=hexcode, color=iccColor))
123 swatchSub.setAttribute(
125 "stop-color: #000000;stop-opacity:0;")
127 swatchMain.appendChild(swatchSub)
128 svgDefs.appendChild(swatchMain)
129 svgSingleSwatch = svgDoc.createElement(
"rect")
130 svgSingleSwatch.setAttribute(
"x", str(Column * 20))
131 svgSingleSwatch.setAttribute(
"y", str(Row * 20))
132 svgSingleSwatch.setAttribute(
"width", str(20))
133 svgSingleSwatch.setAttribute(
"height", str(20))
134 svgSingleSwatch.setAttribute(
"fill",
"url(#%s)" % swatchName)
135 svgSingleSwatch.setAttribute(
"id",
"swatch %s" % swatchName)
136 if entry.spotColor()
is True:
137 svgSingleSwatch.setAttribute(
"rx", str(10))
138 svgSingleSwatch.setAttribute(
"ry", str(10))
139 svgSwatches.appendChild(svgSingleSwatch)
146 for profile
in iccProfileList:
147 svgProfileDesc = svgDoc.createElement(
"color-profile")
148 svgProfileDesc.setAttribute(
"name", profile)
153 svgProfileDesc.setAttribute(
"rendering-intent",
"perceptual")
154 svgDefs.appendChild(svgProfileDesc)
155 svgBaseElement.appendChild(svgDefs)
156 svgBaseElement.appendChild(svgSwatches)
157 svgBaseElement.setAttribute(
159 "0 0 {cols} {row}".format(
162 svgDoc.appendChild(svgBaseElement)
163 svgFile.write(svgDoc.toString())