1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-11-13 05:07:24 +03:00

Fix #378: Gradient color in rgb() format is not being parsed

This commit is contained in:
Alisa Mylnikova 2018-05-30 12:48:04 +07:00
parent e5dbc44ff4
commit 793d91ce32
4 changed files with 61 additions and 41 deletions

View File

@ -400,6 +400,12 @@
5B1AE2DD20B6A669007EECCB /* coords-transformattr-05-f-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = 5B1AE22F20B6A669007EECCB /* coords-transformattr-05-f-manual.reference */; };
5B1AE2DE20B6A669007EECCB /* painting-control-03-f-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = 5B1AE23020B6A669007EECCB /* painting-control-03-f-manual.svg */; };
5B1AE2DF20B6A669007EECCB /* coords-trans-07-t-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = 5B1AE23120B6A669007EECCB /* coords-trans-07-t-manual.reference */; };
5B2D971720BE70D0008E2586 /* pservers-grad-01-b-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = 5B2D971120BE70CF008E2586 /* pservers-grad-01-b-manual.svg */; };
5B2D971820BE70D0008E2586 /* pservers-grad-07-b-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = 5B2D971220BE70CF008E2586 /* pservers-grad-07-b-manual.reference */; };
5B2D971920BE70D0008E2586 /* pservers-grad-01-b-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = 5B2D971320BE70CF008E2586 /* pservers-grad-01-b-manual.reference */; };
5B2D971A20BE70D0008E2586 /* pservers-grad-07-b-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = 5B2D971420BE70CF008E2586 /* pservers-grad-07-b-manual.svg */; };
5B2D971B20BE70D0008E2586 /* pservers-grad-02-b-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = 5B2D971520BE70D0008E2586 /* pservers-grad-02-b-manual.reference */; };
5B2D971C20BE70D0008E2586 /* pservers-grad-02-b-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = 5B2D971620BE70D0008E2586 /* pservers-grad-02-b-manual.svg */; };
5B6E192120AC58F900454E7E /* AlphaEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6E190F20AC58F700454E7E /* AlphaEffect.swift */; };
5B6E192220AC58F900454E7E /* AlphaEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6E190F20AC58F700454E7E /* AlphaEffect.swift */; };
5B6E192320AC58F900454E7E /* OffsetEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6E191020AC58F700454E7E /* OffsetEffect.swift */; };
@ -806,6 +812,12 @@
5B1AE22F20B6A669007EECCB /* coords-transformattr-05-f-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "coords-transformattr-05-f-manual.reference"; sourceTree = "<group>"; };
5B1AE23020B6A669007EECCB /* painting-control-03-f-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "painting-control-03-f-manual.svg"; sourceTree = "<group>"; };
5B1AE23120B6A669007EECCB /* coords-trans-07-t-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "coords-trans-07-t-manual.reference"; sourceTree = "<group>"; };
5B2D971120BE70CF008E2586 /* pservers-grad-01-b-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "pservers-grad-01-b-manual.svg"; path = "../../../MacawTests/w3cSVGTests/pservers-grad-01-b-manual.svg"; sourceTree = "<group>"; };
5B2D971220BE70CF008E2586 /* pservers-grad-07-b-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "pservers-grad-07-b-manual.reference"; path = "../../../MacawTests/w3cSVGTests/pservers-grad-07-b-manual.reference"; sourceTree = "<group>"; };
5B2D971320BE70CF008E2586 /* pservers-grad-01-b-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "pservers-grad-01-b-manual.reference"; path = "../../../MacawTests/w3cSVGTests/pservers-grad-01-b-manual.reference"; sourceTree = "<group>"; };
5B2D971420BE70CF008E2586 /* pservers-grad-07-b-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "pservers-grad-07-b-manual.svg"; path = "../../../MacawTests/w3cSVGTests/pservers-grad-07-b-manual.svg"; sourceTree = "<group>"; };
5B2D971520BE70D0008E2586 /* pservers-grad-02-b-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "pservers-grad-02-b-manual.reference"; path = "../../../MacawTests/w3cSVGTests/pservers-grad-02-b-manual.reference"; sourceTree = "<group>"; };
5B2D971620BE70D0008E2586 /* pservers-grad-02-b-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "pservers-grad-02-b-manual.svg"; path = "../../../MacawTests/w3cSVGTests/pservers-grad-02-b-manual.svg"; sourceTree = "<group>"; };
5B6E190F20AC58F700454E7E /* AlphaEffect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlphaEffect.swift; sourceTree = "<group>"; };
5B6E191020AC58F700454E7E /* OffsetEffect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OffsetEffect.swift; sourceTree = "<group>"; };
5B6E191120AC58F700454E7E /* GaussianBlur.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GaussianBlur.swift; sourceTree = "<group>"; };
@ -1395,6 +1407,12 @@
5BFEF5D420BC1C1E008DAC11 /* paths-data-18-f-manual.svg */,
5B1AE1D720B6A669007EECCB /* paths-data-19-f-manual.reference */,
5B1AE21A20B6A669007EECCB /* paths-data-19-f-manual.svg */,
5B2D971320BE70CF008E2586 /* pservers-grad-01-b-manual.reference */,
5B2D971120BE70CF008E2586 /* pservers-grad-01-b-manual.svg */,
5B2D971520BE70D0008E2586 /* pservers-grad-02-b-manual.reference */,
5B2D971620BE70D0008E2586 /* pservers-grad-02-b-manual.svg */,
5B2D971220BE70CF008E2586 /* pservers-grad-07-b-manual.reference */,
5B2D971420BE70CF008E2586 /* pservers-grad-07-b-manual.svg */,
5B1AE1F020B6A669007EECCB /* pservers-grad-stops-01-f-manual.reference */,
5B1AE1EB20B6A669007EECCB /* pservers-grad-stops-01-f-manual.svg */,
5B1AE1A220B6A669007EECCB /* render-elems-01-t-manual.reference */,
@ -1720,6 +1738,7 @@
5B1AE27020B6A669007EECCB /* shapes-line-01-t-manual.svg in Resources */,
5B1AE2BD20B6A669007EECCB /* paths-data-09-t-manual.reference in Resources */,
C43B06671F99EE7300787A35 /* cubicRelative.svg in Resources */,
5B2D971920BE70D0008E2586 /* pservers-grad-01-b-manual.reference in Resources */,
5BAE204A208E163D006BF277 /* roundRect.reference in Resources */,
5BAE203E208E163D006BF277 /* circle.reference in Resources */,
C410148E1F834D290022EE44 /* style.svg in Resources */,
@ -1788,6 +1807,7 @@
5B1AE24920B6A669007EECCB /* painting-control-06-f-manual.svg in Resources */,
5B1AE2B320B6A669007EECCB /* coords-trans-04-t-manual.reference in Resources */,
5BAE2038208E163D006BF277 /* polyline.reference in Resources */,
5B2D971A20BE70D0008E2586 /* pservers-grad-07-b-manual.svg in Resources */,
5B1AE28020B6A669007EECCB /* coords-transformattr-03-f-manual.svg in Resources */,
C43B06661F99EE7300787A35 /* cubicAbsolute.svg in Resources */,
5B1AE26A20B6A669007EECCB /* painting-control-06-f-manual.reference in Resources */,
@ -1801,10 +1821,12 @@
5B1AE23B20B6A669007EECCB /* struct-use-12-f-manual.reference in Resources */,
5B1AE29F20B6A669007EECCB /* painting-stroke-09-t-manual.svg in Resources */,
5B1AE27D20B6A669007EECCB /* shapes-polygon-03-t-manual.svg in Resources */,
5B2D971720BE70D0008E2586 /* pservers-grad-01-b-manual.svg in Resources */,
5B1AE26020B6A669007EECCB /* shapes-polygon-02-t-manual.reference in Resources */,
5B1AE2AA20B6A669007EECCB /* struct-frag-03-t-manual.svg in Resources */,
5B1AE24720B6A669007EECCB /* painting-stroke-01-t-manual.reference in Resources */,
5B1AE29B20B6A669007EECCB /* shapes-line-01-t-manual.reference in Resources */,
5B2D971C20BE70D0008E2586 /* pservers-grad-02-b-manual.svg in Resources */,
5B1AE29820B6A669007EECCB /* paths-data-08-t-manual.svg in Resources */,
5B1AE25D20B6A669007EECCB /* shapes-polyline-02-t-manual.reference in Resources */,
57CAB1351D7832E000FD8E47 /* roundRect.svg in Resources */,
@ -1829,6 +1851,7 @@
5B1AE28420B6A669007EECCB /* shapes-polyline-01-t-manual.reference in Resources */,
5B1AE2C320B6A669007EECCB /* text-fonts-02-t-manual.reference in Resources */,
5B1AE2CC20B6A669007EECCB /* text-fonts-01-t-manual.reference in Resources */,
5B2D971820BE70D0008E2586 /* pservers-grad-07-b-manual.reference in Resources */,
5B1AE2D220B6A669007EECCB /* struct-group-01-t-manual.svg in Resources */,
5B1AE2B520B6A669007EECCB /* coords-trans-09-t-manual.reference in Resources */,
57CAB1321D7832E000FD8E47 /* polygon.svg in Resources */,
@ -1847,6 +1870,7 @@
5B1AE27A20B6A669007EECCB /* coords-transformattr-01-f-manual.reference in Resources */,
5B1AE24C20B6A669007EECCB /* metadata-example-01-t-manual.reference in Resources */,
5B1AE29720B6A669007EECCB /* render-elems-01-t-manual.svg in Resources */,
5B2D971B20BE70D0008E2586 /* pservers-grad-02-b-manual.reference in Resources */,
5B1AE26220B6A669007EECCB /* coords-transformattr-02-f-manual.svg in Resources */,
5B1AE28F20B6A669007EECCB /* shapes-polyline-02-t-manual.svg in Resources */,
5B1AE24420B6A669007EECCB /* shapes-rect-05-f-manual.reference in Resources */,

View File

@ -12,11 +12,6 @@ class MacawSVGTests: XCTestCase {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testCreate() {
createJSON("painting-stroke-07-t-manual")
createJSON("shapes-polyline-02-t-manual")
}
func validate(node: Node, referenceFile: String) {
let bundle = Bundle(for: type(of: TestUtils()))
@ -553,4 +548,16 @@ class MacawSVGTests: XCTestCase {
func testPathsData10() {
validateJSON("paths-data-10-t-manual")
}
func testPserversGrad01() {
validateJSON("pservers-grad-01-b-manual")
}
func testPserversGrad02() {
validateJSON("pservers-grad-02-b-manual")
}
func testPserversGrad07() {
validateJSON("pservers-grad-07-b-manual")
}
}

View File

@ -10,8 +10,8 @@ There are 521 SVG tests in total. 212 files uses features that are not covered b
* [switch/object](https://www.w3.org/TR/SVG11/backward.html) (7)
The rest 309 tests can be split into following categories:
* 28.4% passed (88)
* 20% not yet covered (62)
* 29.4% passed (91)
* 19% not yet covered (59)
* 14% filters (43)
* 7.8% images (24)
* 2.6% markers (8)

View File

@ -543,8 +543,7 @@ open class SVGParser {
return styleAttributes
}
fileprivate func createColor(_ hexString: String, opacity: Double = 1) -> Color {
let opacity = min(max(opacity, 0), 1)
fileprivate func createColorFromHex(_ hexString: String, opacity: Double = 1) -> Color {
var cleanedHexString = hexString
if hexString.hasPrefix("#") {
cleanedHexString = hexString.replacingOccurrences(of: "#", with: "")
@ -563,43 +562,44 @@ open class SVGParser {
return Color.rgba(r: Int(red), g: Int(green), b: Int(blue), a: opacity)
}
fileprivate func createColor(_ colorString: String, opacity: Double = 1) -> Color? {
if colorString == "none" || colorString == "transparent" {
return .none
}
let opacity = min(max(opacity, 0), 1)
if let defaultColor = SVGConstants.colorList[colorString] {
let color = Color(val: defaultColor)
return opacity != 1 ? color.with(a: opacity) : color
}
if colorString.hasPrefix("rgb") {
let color = parseRGBNotation(colorString: colorString)
return opacity != 1 ? color.with(a: opacity) : color
}
return createColorFromHex(colorString, opacity: opacity)
}
fileprivate func getFillColor(_ styleParts: [String: String], groupStyle: [String: String] = [:]) -> Fill? {
guard var fillColor = styleParts["fill"] else {
return Color.black
}
if fillColor == "none" || fillColor == "transparent" {
return .none
if let colorId = parseIdFromUrl(fillColor) {
return defFills[colorId]
}
if fillColor == "currentColor", let currentColor = groupStyle["color"] {
fillColor = currentColor
}
var opacity: Double = 1
var hasFillOpacity = false
if let fillOpacity = styleParts["fill-opacity"] {
opacity = Double(fillOpacity.replacingOccurrences(of: " ", with: "")) ?? 1
hasFillOpacity = true
}
if let defaultColor = SVGConstants.colorList[fillColor] {
let color = Color(val: defaultColor)
return hasFillOpacity ? color.with(a: opacity) : color
}
if fillColor.hasPrefix("rgb") {
let color = parseRGBNotation(colorString: fillColor)
return hasFillOpacity ? color.with(a: opacity) : color
} else if let colorId = parseIdFromUrl(fillColor) {
return defFills[colorId]
} else {
return createColor(fillColor.replacingOccurrences(of: " ", with: ""), opacity: opacity)
}
return createColor(fillColor.replacingOccurrences(of: " ", with: ""), opacity: opacity)
}
fileprivate func getStroke(_ styleParts: [String: String], groupStyle: [String: String] = [:]) -> Stroke? {
guard var strokeColor = styleParts["stroke"] else {
return .none
}
if strokeColor == "none" {
return .none
}
if strokeColor == "currentColor", let currentColor = groupStyle["color"] {
strokeColor = currentColor
}
@ -609,12 +609,7 @@ open class SVGParser {
opacity = min(max(opacity, 0), 1)
}
var fill: Fill?
if let defaultColor = SVGConstants.colorList[strokeColor] {
let color = Color(val: defaultColor)
fill = color.with(a: opacity)
} else if strokeColor.hasPrefix("rgb") {
fill = parseRGBNotation(colorString: strokeColor)
} else if let colorId = parseIdFromUrl(strokeColor) {
if let colorId = parseIdFromUrl(strokeColor) {
fill = defFills[colorId]
} else {
fill = createColor(strokeColor.replacingOccurrences(of: " ", with: ""), opacity: opacity)
@ -1233,7 +1228,6 @@ open class SVGParser {
guard let element = stop.element else {
return .none
}
guard let offset = getDoubleValueFromPercentage(element, attribute: "offset") else {
return .none
}
@ -1247,12 +1241,7 @@ open class SVGParser {
if stopColor == "currentColor", let currentColor = groupStyle["color"] {
stopColor = currentColor
}
if let defaultColor = SVGConstants.colorList[stopColor] {
color = Color(val: defaultColor).with(a: opacity)
} else {
color = createColor(stopColor.replacingOccurrences(of: " ", with: ""), opacity: opacity)
}
color = createColor(stopColor.replacingOccurrences(of: " ", with: ""), opacity: opacity)!
}
return Stop(offset: offset, color: color)