Skip to content

Commit b5a1ba7

Browse files
committed
Fix color encoding
1 parent 502ef1d commit b5a1ba7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

SwiftDraw/XML.Formatter.SVG.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,22 @@ extension XML.Formatter {
296296
case let .keyword(k):
297297
return k.rawValue
298298
case let .rgbi(r, g, b, a):
299-
let aa = String(format: "%.2f", a)
300-
return "rgb(\(r), \(g), \(b), \(aa)"
299+
if a == 1.0 {
300+
return "rgb(\(r), \(g), \(b))"
301+
} else {
302+
let aa = String(format: "%.2f", a)
303+
return "rgba(\(r), \(g), \(b), \(aa))"
304+
}
301305
case let .rgbf(r, g, b, a):
302306
let rr = String(format: "%.0f", r * 100)
303307
let gg = String(format: "%.0f", g * 100)
304308
let bb = String(format: "%.0f", b * 100)
305-
let aa = String(format: "%.2f", a)
306-
return "rgb(\(rr)%, \(gg)%, \(bb)%, \(aa)"
309+
if a == 1.0 {
310+
return "rgb(\(rr)%, \(gg)%, \(bb)%)"
311+
} else {
312+
let aa = String(format: "%.2f", a)
313+
return "rgba(\(rr)%, \(gg)%, \(bb)%, \(aa))"
314+
}
307315
case let .p3(r, g, b):
308316
return "color(display-p3 \(r), \(g), \(b))"
309317
case let .hex(r, g, b):

0 commit comments

Comments
 (0)