-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from f3dm76/task/svgViewBox
Fix #87: Support <svg> viewBox attribute
- Loading branch information
Showing
13 changed files
with
315 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" ><defs><clipPath id="clipPath1"><rect height="400" x="100" y="50" width="400" /></clipPath></defs><g clip-path="url(#clipPath1)" transform="matrix(0.444444444444444,0.0,0.0,0.444444444444444,-5.55555555555554,-22.2222222222222)" ><g><g><ellipse cy="80" ry="50" rx="100" cx="200" fill="yellow" stroke="purple" stroke-width="2.0"/></g></g></svg> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
public enum Align { | ||
case min | ||
case mid | ||
case max | ||
open class Align { | ||
|
||
public static let min: Align = Align() | ||
public static let mid: Align = MidAlign() | ||
public static let max: Align = MaxAlign() | ||
|
||
open func align(outer: Double, inner: Double) -> Double { | ||
return 0 | ||
} | ||
|
||
open func align(size: Double) -> Double { | ||
return align(outer: size, inner: 0) | ||
} | ||
|
||
} | ||
|
||
private class MidAlign : Align { | ||
|
||
override func align(outer: Double, inner: Double) -> Double { | ||
return (outer - inner) / 2 | ||
} | ||
} | ||
|
||
private class MaxAlign : Align { | ||
|
||
override func align(outer: Double, inner: Double) -> Double { | ||
return outer - inner | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,64 @@ | ||
public enum AspectRatio { | ||
case none | ||
case meet | ||
case slice | ||
open class AspectRatio { | ||
|
||
public static let none: AspectRatio = NoneAspectRatio() | ||
public static let meet: AspectRatio = MeetAspectRatio() | ||
public static let slice: AspectRatio = SliceAspectRatio() | ||
|
||
open func fit(rect: Rect, into rectToFitIn: Rect) -> Size { | ||
return Size(w: 0, h: 0) | ||
} | ||
|
||
open func fit(size: Size, into rectToFitIn: Rect) -> Size { | ||
return fit(rect: Rect(x: 0, y: 0, w: size.w, h: size.h), into: rectToFitIn) | ||
} | ||
|
||
open func fit(size: Size, into sizeToFitIn: Size) -> Size { | ||
return fit(size: size, into: Rect(x: 0, y: 0, w: sizeToFitIn.w, h: sizeToFitIn.h)) | ||
} | ||
|
||
} | ||
|
||
private class NoneAspectRatio : AspectRatio { | ||
|
||
override func fit(rect: Rect, into rectToFitIn: Rect) -> Size { | ||
return Size(w: rectToFitIn.w, h: rectToFitIn.h) | ||
} | ||
} | ||
|
||
private class MeetAspectRatio : AspectRatio { | ||
|
||
override func fit(rect: Rect, into rectToFitIn: Rect) -> Size { | ||
let widthRatio = rectToFitIn.w / rect.w | ||
let heightRatio = rectToFitIn.h / rect.h | ||
|
||
var newWidth = rectToFitIn.w | ||
var newHeight = rectToFitIn.h | ||
|
||
if heightRatio < widthRatio { | ||
newWidth = rect.w * heightRatio | ||
} | ||
else { | ||
newHeight = rect.h * widthRatio | ||
} | ||
return Size(w: newWidth, h: newHeight) | ||
} | ||
} | ||
|
||
private class SliceAspectRatio : AspectRatio { | ||
|
||
override func fit(rect: Rect, into rectToFitIn: Rect) -> Size { | ||
let widthRatio = rectToFitIn.w / rect.w | ||
let heightRatio = rectToFitIn.h / rect.h | ||
|
||
var newWidth = rectToFitIn.w | ||
var newHeight = rectToFitIn.h | ||
|
||
if heightRatio > widthRatio { | ||
newWidth = rect.w * heightRatio | ||
} | ||
else { | ||
newHeight = rect.h * widthRatio | ||
} | ||
return Size(w: newWidth, h: newHeight) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.