Showing
3 changed files
with
14 additions
and
4 deletions
@@ -302,9 +302,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | @@ -302,9 +302,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | ||
302 | 302 | ||
303 | for pageNum in pages ?? Array(0 ... pageCount - 1) { | 303 | for pageNum in pages ?? Array(0 ... pageCount - 1) { |
304 | guard let page = document.page(at: pageNum + 1) else { continue } | 304 | guard let page = document.page(at: pageNum + 1) else { continue } |
305 | + let angle = CGFloat(page.rotationAngle) * CGFloat.pi / -180 | ||
305 | let rect = page.getBoxRect(.mediaBox) | 306 | let rect = page.getBoxRect(.mediaBox) |
306 | - let width = Int(rect.width * scale) | ||
307 | - let height = Int(rect.height * scale) | 307 | + let width = Int(abs((cos(angle) * rect.width + sin(angle) * rect.height) * scale)) |
308 | + let height = Int(abs((cos(angle) * rect.height + sin(angle) * rect.width) * scale)) | ||
308 | let stride = width * 4 | 309 | let stride = width * 4 |
309 | var data = Data(repeating: 0, count: stride * height) | 310 | var data = Data(repeating: 0, count: stride * height) |
310 | 311 | ||
@@ -320,7 +321,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | @@ -320,7 +321,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | ||
320 | bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | 321 | bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue |
321 | ) | 322 | ) |
322 | if context != nil { | 323 | if context != nil { |
324 | + context!.translateBy(x: CGFloat(width) / 2, y: CGFloat(height) / 2) | ||
323 | context!.scaleBy(x: scale, y: scale) | 325 | context!.scaleBy(x: scale, y: scale) |
326 | + context!.rotate(by: angle) | ||
327 | + context!.translateBy(x: -rect.width / 2, y: -rect.height / 2) | ||
324 | context!.drawPDFPage(page) | 328 | context!.drawPDFPage(page) |
325 | } | 329 | } |
326 | } | 330 | } |
@@ -249,9 +249,10 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { | @@ -249,9 +249,10 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { | ||
249 | 249 | ||
250 | for pageNum in pages ?? Array(0 ... pageCount - 1) { | 250 | for pageNum in pages ?? Array(0 ... pageCount - 1) { |
251 | guard let page = document.page(at: pageNum + 1) else { continue } | 251 | guard let page = document.page(at: pageNum + 1) else { continue } |
252 | + let angle = CGFloat(page.rotationAngle) * CGFloat.pi / -180 | ||
252 | let rect = page.getBoxRect(.mediaBox) | 253 | let rect = page.getBoxRect(.mediaBox) |
253 | - let width = Int(rect.width * scale) | ||
254 | - let height = Int(rect.height * scale) | 254 | + let width = Int(abs((cos(angle) * rect.width + sin(angle) * rect.height) * scale)) |
255 | + let height = Int(abs((cos(angle) * rect.height + sin(angle) * rect.width) * scale)) | ||
255 | let stride = width * 4 | 256 | let stride = width * 4 |
256 | var data = Data(repeating: 0, count: stride * height) | 257 | var data = Data(repeating: 0, count: stride * height) |
257 | 258 | ||
@@ -266,8 +267,12 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { | @@ -266,8 +267,12 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { | ||
266 | space: rgb, | 267 | space: rgb, |
267 | bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | 268 | bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue |
268 | ) | 269 | ) |
270 | + | ||
269 | if context != nil { | 271 | if context != nil { |
272 | + context!.translateBy(x: CGFloat(width) / 2, y: CGFloat(height) / 2) | ||
270 | context!.scaleBy(x: scale, y: scale) | 273 | context!.scaleBy(x: scale, y: scale) |
274 | + context!.rotate(by: angle) | ||
275 | + context!.translateBy(x: -rect.width / 2, y: -rect.height / 2) | ||
271 | context!.drawPDFPage(page) | 276 | context!.drawPDFPage(page) |
272 | } | 277 | } |
273 | } | 278 | } |
-
Please register or login to post a comment