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:
commit
cdd08b2f08
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user