Skip to content

Commit a13c3ae

Browse files
authored
Merge pull request #20 from rcancro/main
[PATCH] [Bug] update makeTransformation to consider svgs where width
2 parents d803751 + ecd3be1 commit a13c3ae

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Samples/dash.svg

Lines changed: 3 additions & 0 deletions
Loading

SwiftDraw/Renderer.SFSymbol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ extension SFSymbolRenderer {
266266

267267
static func makeTransformation(from source: LayerTree.Rect,
268268
to destination: LayerTree.Rect) -> LayerTree.Transform.Matrix {
269-
let scale = destination.height / source.height
269+
let scale = min(destination.width / source.width, destination.height / source.height)
270270
let scaleMidX = source.midX * scale
271271
let scaleMidY = source.midY * scale
272272
let tx = destination.midX - scaleMidX

SwiftDrawTests/Renderer.SFSymbolTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ final class RendererSFSymbolTests: XCTestCase {
5454
template.black.contents.paths.isEmpty
5555
)
5656
}
57+
58+
func testWidthGreaterThanHeightSymbol() throws {
59+
// This svg has a width of 24, but a height of 4. When scaling in SFSymbolRenderer makeTransformation
60+
// the height was being used to create scale causing the width to be 440 instead of 108.
61+
let url = try Bundle.test.url(forResource: "dash.svg")
62+
let template = try SFSymbolTemplate.parse(
63+
SFSymbolRenderer.render(fileURL: url)
64+
)
65+
66+
XCTAssertTrue(
67+
template.regular.bounds.size.width == 108.0
68+
)
69+
XCTAssertTrue(
70+
template.regular.bounds.size.height == 70.0
71+
)
72+
73+
}
5774

5875
#if canImport(CoreGraphics)
5976
func testStrokeSymbol() throws {

0 commit comments

Comments
 (0)