David PHAM-VAN

Improve Apple orientation handling

@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 - Remove deprecated methods 5 - Remove deprecated methods
6 - Document.save() now returns a Future 6 - Document.save() now returns a Future
7 - Implement pan and zoom on PdfPreview widget 7 - Implement pan and zoom on PdfPreview widget
  8 +- Improve orientation handling
8 9
9 ## 3.7.2 10 ## 3.7.2
10 11
@@ -27,6 +27,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate @@ -27,6 +27,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
27 private var pdfDocument: CGPDFDocument? 27 private var pdfDocument: CGPDFDocument?
28 private var urlObservation: NSKeyValueObservation? 28 private var urlObservation: NSKeyValueObservation?
29 private var jobName: String? 29 private var jobName: String?
  30 + private var orientation: UIPrintInfo.Orientation?
30 31
31 public init(printing: PrintingPlugin, index: Int) { 32 public init(printing: PrintingPlugin, index: Int) {
32 self.printing = printing 33 self.printing = printing
@@ -62,6 +63,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate @@ -62,6 +63,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
62 let printInfo = UIPrintInfo.printInfo() 63 let printInfo = UIPrintInfo.printInfo()
63 printInfo.jobName = jobName! 64 printInfo.jobName = jobName!
64 printInfo.outputType = .general 65 printInfo.outputType = .general
  66 + if orientation != nil {
  67 + printInfo.orientation = orientation!
  68 + orientation = nil
  69 + }
65 controller.printInfo = printInfo 70 controller.printInfo = printInfo
66 controller.printPageRenderer = self 71 controller.printPageRenderer = self
67 controller.present(animated: true, completionHandler: completionHandler) 72 controller.present(animated: true, completionHandler: completionHandler)
@@ -112,6 +117,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate @@ -112,6 +117,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
112 return 117 return
113 } 118 }
114 119
  120 + if size.width > size.height {
  121 + orientation = UIPrintInfo.Orientation.landscape
  122 + }
  123 +
115 jobName = name 124 jobName = name
116 125
117 self.printing.onLayout( 126 self.printing.onLayout(
@@ -80,12 +80,16 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { @@ -80,12 +80,16 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
80 80
81 public func directPrintPdf(name _: String, data _: Data, withPrinter _: String) {} 81 public func directPrintPdf(name _: String, data _: Data, withPrinter _: String) {}
82 82
83 - public func printPdf(name: String, withPageSize _: CGSize, andMargin _: CGRect) { 83 + public func printPdf(name: String, withPageSize size: CGSize, andMargin _: CGRect) {
84 let sharedInfo = NSPrintInfo.shared 84 let sharedInfo = NSPrintInfo.shared
85 let sharedDict = sharedInfo.dictionary() 85 let sharedDict = sharedInfo.dictionary()
86 let printInfoDict = NSMutableDictionary(dictionary: sharedDict) 86 let printInfoDict = NSMutableDictionary(dictionary: sharedDict)
87 let printInfo = NSPrintInfo(dictionary: printInfoDict as! [NSPrintInfo.AttributeKey: Any]) 87 let printInfo = NSPrintInfo(dictionary: printInfoDict as! [NSPrintInfo.AttributeKey: Any])
88 88
  89 + if size.width > size.height {
  90 + printInfo.orientation = NSPrintInfo.PaperOrientation.landscape
  91 + }
  92 +
89 // Print the custom view 93 // Print the custom view
90 printOperation = NSPrintOperation(view: self, printInfo: printInfo) 94 printOperation = NSPrintOperation(view: self, printInfo: printInfo)
91 printOperation!.jobTitle = name 95 printOperation!.jobTitle = name