David PHAM-VAN

Fix Windows initial page format

# Changelog
## 5.6.4
- Fix Windows initial page format
## 5.6.3
- Fix Windows string encoding
... ...
... ... @@ -6,7 +6,7 @@ description: >
homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 5.6.3
version: 5.6.4
environment:
sdk: ">=2.12.0 <3.0.0"
... ...
... ... @@ -73,15 +73,29 @@ std::wstring fromUtf8(std::string str) {
PrintJob::PrintJob(Printing* printing, int index)
: printing{printing}, index{index} {}
bool PrintJob::printPdf(std::string name, std::string printer) {
bool PrintJob::printPdf(std::string name,
std::string printer,
double width,
double height) {
documentName = name;
auto dm = static_cast<DEVMODE*>(GlobalAlloc(0, sizeof(DEVMODE)));
ZeroMemory(dm, sizeof(DEVMODE));
dm->dmSize = sizeof(DEVMODE);
dm->dmFields = DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH;
dm->dmPaperSize = 0;
if (width > height) {
dm->dmOrientation = DMORIENT_LANDSCAPE;
dm->dmPaperWidth = static_cast<short>(round(height * 254 / 72));
dm->dmPaperLength = static_cast<short>(round(width * 254 / 72));
} else {
dm->dmOrientation = DMORIENT_PORTRAIT;
dm->dmPaperWidth = static_cast<short>(round(width * 254 / 72));
dm->dmPaperLength = static_cast<short>(round(height * 254 / 72));
}
if (printer.empty()) {
PRINTDLG pd;
DEVMODE* dm = static_cast<DEVMODE*>(GlobalAlloc(0, sizeof(DEVMODE)));
ZeroMemory(dm, sizeof(DEVMODE));
dm->dmFields = DM_ORIENTATION;
dm->dmOrientation = 2;
// Initialize PRINTDLG
ZeroMemory(&pd, sizeof(pd));
... ... @@ -115,11 +129,11 @@ bool PrintJob::printPdf(std::string name, std::string printer) {
hDevNames = pd.hDevNames;
} else {
hDC = CreateDC(TEXT("WINSPOOL"), fromUtf8(printer).c_str(), NULL, NULL);
hDC = CreateDC(TEXT("WINSPOOL"), fromUtf8(printer).c_str(), NULL, dm);
if (!hDC) {
return false;
}
hDevMode = nullptr;
hDevMode = dm;
hDevNames = nullptr;
}
... ...
... ... @@ -71,7 +71,10 @@ class PrintJob {
std::vector<Printer> listPrinters();
bool printPdf(std::string name, std::string printer);
bool printPdf(std::string name,
std::string printer,
double width,
double height);
void writeJob(std::vector<uint8_t> data);
... ...
... ... @@ -74,10 +74,14 @@ class PrintingPlugin : public flutter::Plugin {
auto printer = vPrinter != arguments->end()
? std::get<std::string>(vPrinter->second)
: std::string{};
auto width = std::get<double>(
arguments->find(flutter::EncodableValue("width"))->second);
auto height = std::get<double>(
arguments->find(flutter::EncodableValue("height"))->second);
auto vJob = arguments->find(flutter::EncodableValue("job"));
auto jobNum = vJob != arguments->end() ? std::get<int>(vJob->second) : -1;
auto job = new PrintJob{&printing, jobNum};
auto res = job->printPdf(name, printer);
auto res = job->printPdf(name, printer, width, height);
if (!res) {
delete job;
}
... ...