David PHAM-VAN

Fix rotated pages display on iOS and macOS

... ... @@ -3,6 +3,7 @@
## 5.0.3
- Fix RichText annotations
- Fix rotated pages display on iOS and macOS
## 5.0.2
... ...
... ... @@ -302,9 +302,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
for pageNum in pages ?? Array(0 ... pageCount - 1) {
guard let page = document.page(at: pageNum + 1) else { continue }
let angle = CGFloat(page.rotationAngle) * CGFloat.pi / -180
let rect = page.getBoxRect(.mediaBox)
let width = Int(rect.width * scale)
let height = Int(rect.height * scale)
let width = Int(abs((cos(angle) * rect.width + sin(angle) * rect.height) * scale))
let height = Int(abs((cos(angle) * rect.height + sin(angle) * rect.width) * scale))
let stride = width * 4
var data = Data(repeating: 0, count: stride * height)
... ... @@ -320,7 +321,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
)
if context != nil {
context!.translateBy(x: CGFloat(width) / 2, y: CGFloat(height) / 2)
context!.scaleBy(x: scale, y: scale)
context!.rotate(by: angle)
context!.translateBy(x: -rect.width / 2, y: -rect.height / 2)
context!.drawPDFPage(page)
}
}
... ...
... ... @@ -249,9 +249,10 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
for pageNum in pages ?? Array(0 ... pageCount - 1) {
guard let page = document.page(at: pageNum + 1) else { continue }
let angle = CGFloat(page.rotationAngle) * CGFloat.pi / -180
let rect = page.getBoxRect(.mediaBox)
let width = Int(rect.width * scale)
let height = Int(rect.height * scale)
let width = Int(abs((cos(angle) * rect.width + sin(angle) * rect.height) * scale))
let height = Int(abs((cos(angle) * rect.height + sin(angle) * rect.width) * scale))
let stride = width * 4
var data = Data(repeating: 0, count: stride * height)
... ... @@ -266,8 +267,12 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
space: rgb,
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
)
if context != nil {
context!.translateBy(x: CGFloat(width) / 2, y: CGFloat(height) / 2)
context!.scaleBy(x: scale, y: scale)
context!.rotate(by: angle)
context!.translateBy(x: -rect.width / 2, y: -rect.height / 2)
context!.drawPDFPage(page)
}
}
... ...