David PHAM-VAN

Fix Windows initial page format

1 # Changelog 1 # Changelog
2 2
  3 +## 5.6.4
  4 +
  5 +- Fix Windows initial page format
  6 +
3 ## 5.6.3 7 ## 5.6.3
4 8
5 - Fix Windows string encoding 9 - Fix Windows string encoding
@@ -6,7 +6,7 @@ description: > @@ -6,7 +6,7 @@ description: >
6 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing 6 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
7 repository: https://github.com/DavBfr/dart_pdf 7 repository: https://github.com/DavBfr/dart_pdf
8 issue_tracker: https://github.com/DavBfr/dart_pdf/issues 8 issue_tracker: https://github.com/DavBfr/dart_pdf/issues
9 -version: 5.6.3 9 +version: 5.6.4
10 10
11 environment: 11 environment:
12 sdk: ">=2.12.0 <3.0.0" 12 sdk: ">=2.12.0 <3.0.0"
@@ -73,15 +73,29 @@ std::wstring fromUtf8(std::string str) { @@ -73,15 +73,29 @@ std::wstring fromUtf8(std::string str) {
73 PrintJob::PrintJob(Printing* printing, int index) 73 PrintJob::PrintJob(Printing* printing, int index)
74 : printing{printing}, index{index} {} 74 : printing{printing}, index{index} {}
75 75
76 -bool PrintJob::printPdf(std::string name, std::string printer) { 76 +bool PrintJob::printPdf(std::string name,
  77 + std::string printer,
  78 + double width,
  79 + double height) {
77 documentName = name; 80 documentName = name;
78 81
  82 + auto dm = static_cast<DEVMODE*>(GlobalAlloc(0, sizeof(DEVMODE)));
  83 + ZeroMemory(dm, sizeof(DEVMODE));
  84 + dm->dmSize = sizeof(DEVMODE);
  85 + dm->dmFields = DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH;
  86 + dm->dmPaperSize = 0;
  87 + if (width > height) {
  88 + dm->dmOrientation = DMORIENT_LANDSCAPE;
  89 + dm->dmPaperWidth = static_cast<short>(round(height * 254 / 72));
  90 + dm->dmPaperLength = static_cast<short>(round(width * 254 / 72));
  91 + } else {
  92 + dm->dmOrientation = DMORIENT_PORTRAIT;
  93 + dm->dmPaperWidth = static_cast<short>(round(width * 254 / 72));
  94 + dm->dmPaperLength = static_cast<short>(round(height * 254 / 72));
  95 + }
  96 +
79 if (printer.empty()) { 97 if (printer.empty()) {
80 PRINTDLG pd; 98 PRINTDLG pd;
81 - DEVMODE* dm = static_cast<DEVMODE*>(GlobalAlloc(0, sizeof(DEVMODE)));  
82 - ZeroMemory(dm, sizeof(DEVMODE));  
83 - dm->dmFields = DM_ORIENTATION;  
84 - dm->dmOrientation = 2;  
85 99
86 // Initialize PRINTDLG 100 // Initialize PRINTDLG
87 ZeroMemory(&pd, sizeof(pd)); 101 ZeroMemory(&pd, sizeof(pd));
@@ -115,11 +129,11 @@ bool PrintJob::printPdf(std::string name, std::string printer) { @@ -115,11 +129,11 @@ bool PrintJob::printPdf(std::string name, std::string printer) {
115 hDevNames = pd.hDevNames; 129 hDevNames = pd.hDevNames;
116 130
117 } else { 131 } else {
118 - hDC = CreateDC(TEXT("WINSPOOL"), fromUtf8(printer).c_str(), NULL, NULL); 132 + hDC = CreateDC(TEXT("WINSPOOL"), fromUtf8(printer).c_str(), NULL, dm);
119 if (!hDC) { 133 if (!hDC) {
120 return false; 134 return false;
121 } 135 }
122 - hDevMode = nullptr; 136 + hDevMode = dm;
123 hDevNames = nullptr; 137 hDevNames = nullptr;
124 } 138 }
125 139
@@ -71,7 +71,10 @@ class PrintJob { @@ -71,7 +71,10 @@ class PrintJob {
71 71
72 std::vector<Printer> listPrinters(); 72 std::vector<Printer> listPrinters();
73 73
74 - bool printPdf(std::string name, std::string printer); 74 + bool printPdf(std::string name,
  75 + std::string printer,
  76 + double width,
  77 + double height);
75 78
76 void writeJob(std::vector<uint8_t> data); 79 void writeJob(std::vector<uint8_t> data);
77 80
@@ -74,10 +74,14 @@ class PrintingPlugin : public flutter::Plugin { @@ -74,10 +74,14 @@ class PrintingPlugin : public flutter::Plugin {
74 auto printer = vPrinter != arguments->end() 74 auto printer = vPrinter != arguments->end()
75 ? std::get<std::string>(vPrinter->second) 75 ? std::get<std::string>(vPrinter->second)
76 : std::string{}; 76 : std::string{};
  77 + auto width = std::get<double>(
  78 + arguments->find(flutter::EncodableValue("width"))->second);
  79 + auto height = std::get<double>(
  80 + arguments->find(flutter::EncodableValue("height"))->second);
77 auto vJob = arguments->find(flutter::EncodableValue("job")); 81 auto vJob = arguments->find(flutter::EncodableValue("job"));
78 auto jobNum = vJob != arguments->end() ? std::get<int>(vJob->second) : -1; 82 auto jobNum = vJob != arguments->end() ? std::get<int>(vJob->second) : -1;
79 auto job = new PrintJob{&printing, jobNum}; 83 auto job = new PrintJob{&printing, jobNum};
80 - auto res = job->printPdf(name, printer); 84 + auto res = job->printPdf(name, printer, width, height);
81 if (!res) { 85 if (!res) {
82 delete job; 86 delete job;
83 } 87 }