1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-11-11 01:42:35 +03:00

Merge pull request #317 from f3dm76/task/sliceContentAlign

Apply align for slice content mode
This commit is contained in:
Yuri Strot 2018-04-23 15:07:01 +07:00 committed by GitHub
commit cdd08b2f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -15,8 +15,8 @@ open class SVGParser {
var svgSize: Size?
var viewBox: Rect?
var scalingMode: AspectRatio?
var xAligningMode: Align?
var yAligningMode: Align?
var xAligningMode: Align = .mid
var yAligningMode: Align = .mid
}
/// Parse an SVG file identified by the specified bundle, name and file extension.
@ -139,8 +139,8 @@ open class SVGParser {
if scalingMode === AspectRatio.slice {
// setup new clipping to slice extra bits
let newSize = AspectRatio.meet.fit(size: svgSize, into: viewBox)
let newX = viewBox.x + viewBox.w / 2 - newSize.w / 2
let newY = viewBox.y + viewBox.h / 2 - newSize.h / 2
let newX = viewBox.x + params.xAligningMode.align(outer: viewBox.w, inner: newSize.w)
let newY = viewBox.y + params.yAligningMode.align(outer: viewBox.h, inner: newSize.h)
node.clip = Rect(x: newX, y: newY, w: newSize.w, h: newSize.h)
}

View File

@ -11,10 +11,10 @@ open class SvgContentLayout: ContentLayout {
public let xAligningMode: Align
public let yAligningMode: Align
public init(scalingMode: AspectRatio, xAligningMode: Align? = Align.min, yAligningMode: Align? = Align.min) {
public init(scalingMode: AspectRatio, xAligningMode: Align = Align.min, yAligningMode: Align = Align.min) {
self.scalingMode = scalingMode
self.xAligningMode = xAligningMode ?? Align.min
self.yAligningMode = yAligningMode ?? Align.min
self.xAligningMode = xAligningMode
self.yAligningMode = yAligningMode
}
public static var standard: ContentLayout {