Skip to content

Commit

Permalink
Get bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
onmyway133 committed Nov 29, 2016
1 parent 742909c commit fc7494a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class ViewController: UIViewController {

let svgView = document.svg.view
self.view.addSubview(svgView)

print(document.svg.bounds())
}

override func viewDidLayoutSubviews() {
Expand Down
19 changes: 19 additions & 0 deletions Sources/iOS/Document/SVG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,22 @@ public class SVG {
return view
}
}

public extension SVG {

func bounds() -> CGRect {
var rect = CGRect.zero

items.forEach { item in
if let item = item as? ShapeAware {
rect = item.path.bounds.union(rect)
}
}

return rect
}

func layers(size: CGSize) -> [CALayer] {
return []
}
}
5 changes: 4 additions & 1 deletion Sources/iOS/Item/Shape/ShapeAware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public protocol ShapeAware {

public extension ShapeAware {

var layer: CALayer {
func layer(transform: CGAffineTransform) -> CAShapeLayer {
var path = self.path
path.apply(transform)

let layer = CAShapeLayer()
layer.path = path.cgPath

Expand Down

0 comments on commit fc7494a

Please sign in to comment.