Skip to content

Commit

Permalink
Fix skewX and skewY in SVG parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kayuri committed Oct 16, 2017
1 parent 661c684 commit e3d4498
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions MacawTests/MacawSVGTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ class MacawSVGTests: XCTestCase {
}
}
}

func testSVGTransform() {
let bundle = Bundle(for: type(of: TestUtils()))
let transformReferenceContent = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" ><g><g transform=\"matrix(2.0,1.0,1.0,1.0,0.0,0.0)\" ><rect height=\"5\" x=\"0\" y=\"0\" width=\"150\" fill=\"blue\"/><rect height=\"50\" x=\"0\" y=\"0\" width=\"5\" fill=\"red\"/><rect height=\"50\" x=\"150\" y=\"0\" width=\"5\" fill=\"black\"/><rect height=\"5\" x=\"0\" y=\"50\" width=\"150\" fill=\"black\"/><ellipse cy=\"25\" ry=\"15\" rx=\"40\" cx=\"75\" fill=\"purple\"/></g></g></svg>"
do {
let node = try SVGParser.parse(bundle:bundle, path: "transform")
XCTAssertEqual(SVGSerializer.serialize(node: node), transformReferenceContent)
} catch {
print(error)
}
}

func testSVGEllipse() {
let bundle = Bundle(for: type(of: TestUtils()))
Expand Down
12 changes: 12 additions & 0 deletions MacawTests/svg/transform.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Source/svg/SVGParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,12 @@ open class SVGParser {
}
case "skewX":
if let x = Double(values[0]) {
finalTransform = transform.shear(shx: x, shy: 0)
let v = tan((x * Double.pi) / 180.0)
finalTransform = transform.shear(shx: v, shy: 0)
}
case "skewY":
if let y = Double(values[0]) {
let y = tan((y * Double.pi) / 180.0)
finalTransform = transform.shear(shx: 0, shy: y)
}
case "matrix":
Expand Down

0 comments on commit e3d4498

Please sign in to comment.