Skip to content

Commit 6b176b5

Browse files
authored
Merge pull request #29 from swhitty/flip-CGImage
Flip CGImage
2 parents 4801ee7 + 36f530c commit 6b176b5

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Samples.bundle/base64.svg

Lines changed: 7 additions & 0 deletions
Loading

Samples.bundle/shapes.svg

Lines changed: 2 additions & 0 deletions
Loading

SwiftDraw/Renderer.CGText.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,11 @@ public final class CGTextRenderer: Renderer {
557557
}
558558

559559
func draw(image: LayerTree.Image) {
560+
lines.append("ctx.saveGState()")
561+
lines.append("ctx.translateBy(x: 0, y: image.height)")
562+
lines.append("ctx.scaleBy(x: 1, y: -1)")
560563
lines.append("ctx.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height)")
564+
lines.append("ctx.restoreGState()")
561565
}
562566

563567
func draw(linear gradient: LayerTree.Gradient, from start: String, to end: String) {

SwiftDraw/Renderer.CoreGraphics.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ final class CGTransformingPattern: Equatable {
7777
}
7878

7979
struct CGProvider: RendererTypeProvider {
80+
8081
typealias Types = CGTypes
8182

8283
func createFloat(from float: LayerTree.Float) -> CGFloat {
@@ -412,8 +413,12 @@ struct CGRenderer: Renderer {
412413
}
413414

414415
func draw(image: CGImage) {
415-
let rect = CGRect(x: 0, y: 0, width: image.width, height: image.height)
416-
ctx.draw(image, in: rect)
416+
let rect = CGRect(x: 0, y: 0, width: image.width, height: image.height)
417+
pushState()
418+
translate(tx: 0, ty: rect.height)
419+
scale(sx: 1, sy: -1)
420+
ctx.draw(image, in: rect)
421+
popState()
417422
}
418423

419424
func draw(linear gradient: CGGradient, from start: CGPoint, to end: CGPoint) {

0 commit comments

Comments
 (0)