Committed by
David PHAM-VAN
Output image sized to cropBox instead of mediaBox
Showing
2 changed files
with
8 additions
and
3 deletions
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | - Refactor html imports | 5 | - Refactor html imports |
6 | - Implement PdfActionBarTheme for actions bar and add method scrollToPage [Aleksei] | 6 | - Implement PdfActionBarTheme for actions bar and add method scrollToPage [Aleksei] |
7 | - Update cursors in zoom mode for web [Aleksei] | 7 | - Update cursors in zoom mode for web [Aleksei] |
8 | +- Output image sized to cropBox instead of mediaBox (iOS) [garrettApproachableGeek] | ||
8 | 9 | ||
9 | ## 5.11.1 | 10 | ## 5.11.1 |
10 | 11 |
@@ -350,8 +350,11 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | @@ -350,8 +350,11 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | ||
350 | guard let page = document.page(at: pageNum + 1) else { continue } | 350 | guard let page = document.page(at: pageNum + 1) else { continue } |
351 | let angle = CGFloat(page.rotationAngle) * CGFloat.pi / -180 | 351 | let angle = CGFloat(page.rotationAngle) * CGFloat.pi / -180 |
352 | let rect = page.getBoxRect(.mediaBox) | 352 | let rect = page.getBoxRect(.mediaBox) |
353 | - let width = Int(abs((cos(angle) * rect.width + sin(angle) * rect.height) * scale)) | ||
354 | - let height = Int(abs((cos(angle) * rect.height + sin(angle) * rect.width) * scale)) | 353 | + let rectCrop = page.getBoxRect(.cropBox) |
354 | + let diffHeight = rectCrop.height - rect.height | ||
355 | + let diffWidth = rectCrop.width - rect.width | ||
356 | + let width = Int(abs((cos(angle) * rectCrop.width + sin(angle) * rectCrop.height) * scale)) | ||
357 | + let height = Int(abs((cos(angle) * rectCrop.height + sin(angle) * rectCrop.width) * scale)) | ||
355 | let stride = width * 4 | 358 | let stride = width * 4 |
356 | var data = Data(repeating: 0, count: stride * height) | 359 | var data = Data(repeating: 0, count: stride * height) |
357 | 360 | ||
@@ -371,7 +374,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | @@ -371,7 +374,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | ||
371 | context!.translateBy(x: CGFloat(width) / 2, y: CGFloat(height) / 2) | 374 | context!.translateBy(x: CGFloat(width) / 2, y: CGFloat(height) / 2) |
372 | context!.scaleBy(x: scale, y: scale) | 375 | context!.scaleBy(x: scale, y: scale) |
373 | context!.rotate(by: angle) | 376 | context!.rotate(by: angle) |
374 | - context!.translateBy(x: -rect.width / 2, y: -rect.height / 2) | 377 | + context!.translateBy(x: -rectCrop.width / 2, y: -rectCrop.height / 2) |
378 | + context!.translateBy(x: diffWidth, y: diffHeight) | ||
375 | context!.drawPDFPage(page) | 379 | context!.drawPDFPage(page) |
376 | } | 380 | } |
377 | } | 381 | } |
-
Please register or login to post a comment