Showing
11 changed files
with
51 additions
and
44 deletions
| @@ -628,7 +628,7 @@ class Outline extends Anchor { | @@ -628,7 +628,7 @@ class Outline extends Anchor { | ||
| 628 | final root = context.document.outline; | 628 | final root = context.document.outline; |
| 629 | 629 | ||
| 630 | // find the most recently added outline | 630 | // find the most recently added outline |
| 631 | - var actualLevel= -1; | 631 | + var actualLevel = -1; |
| 632 | var candidate = root; | 632 | var candidate = root; |
| 633 | while (candidate.outlines.isNotEmpty) { | 633 | while (candidate.outlines.isNotEmpty) { |
| 634 | candidate = candidate.outlines.last; | 634 | candidate = candidate.outlines.last; |
| 1 | # Changelog | 1 | # Changelog |
| 2 | 2 | ||
| 3 | -## 5.6.7 | 3 | +## 5.7.0 |
| 4 | 4 | ||
| 5 | - Fix imports for Dart 2.15 | 5 | - Fix imports for Dart 2.15 |
| 6 | - Fix print dialog crash on Linux | 6 | - Fix print dialog crash on Linux |
| @@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
| 10 | - Update Google Fonts | 10 | - Update Google Fonts |
| 11 | - Add a default theme initializer | 11 | - Add a default theme initializer |
| 12 | - Use RENDER_MODE_FOR_DISPLAY on Android | 12 | - Use RENDER_MODE_FOR_DISPLAY on Android |
| 13 | +- Enable usage of printer's settings on Windows [Alban Lecuivre] | ||
| 13 | 14 | ||
| 14 | ## 5.6.6 | 15 | ## 5.6.6 |
| 15 | 16 |
| @@ -65,6 +65,7 @@ class PrintingPlugin extends PrintingPlatform { | @@ -65,6 +65,7 @@ class PrintingPlugin extends PrintingPlatform { | ||
| 65 | String name, | 65 | String name, |
| 66 | PdfPageFormat format, | 66 | PdfPageFormat format, |
| 67 | bool dynamicLayout, | 67 | bool dynamicLayout, |
| 68 | + bool usePrinterSettings, | ||
| 68 | ) async { | 69 | ) async { |
| 69 | late Uint8List result; | 70 | late Uint8List result; |
| 70 | try { | 71 | try { |
| @@ -202,7 +202,7 @@ bool print_job::print_pdf(const gchar* name, | @@ -202,7 +202,7 @@ bool print_job::print_pdf(const gchar* name, | ||
| 202 | void print_job::write_job(const uint8_t data[], size_t size) { | 202 | void print_job::write_job(const uint8_t data[], size_t size) { |
| 203 | auto fd = memfd_create("printing", 0); | 203 | auto fd = memfd_create("printing", 0); |
| 204 | size_t offset = 0; | 204 | size_t offset = 0; |
| 205 | - size_t n; | 205 | + ssize_t n; |
| 206 | while ((n = write(fd, data + offset, size - offset)) >= 0 && | 206 | while ((n = write(fd, data + offset, size - offset)) >= 0 && |
| 207 | size - offset > 0) { | 207 | size - offset > 0) { |
| 208 | offset += n; | 208 | offset += n; |
| @@ -249,8 +249,8 @@ void print_job::raster_pdf(const uint8_t data[], | @@ -249,8 +249,8 @@ void print_job::raster_pdf(const uint8_t data[], | ||
| 249 | double scale) { | 249 | double scale) { |
| 250 | FPDF_LIBRARY_CONFIG config; | 250 | FPDF_LIBRARY_CONFIG config; |
| 251 | config.version = 2; | 251 | config.version = 2; |
| 252 | - config.m_pUserFontPaths = NULL; | ||
| 253 | - config.m_pIsolate = NULL; | 252 | + config.m_pUserFontPaths = nullptr; |
| 253 | + config.m_pIsolate = nullptr; | ||
| 254 | config.m_v8EmbedderSlot = 0; | 254 | config.m_v8EmbedderSlot = 0; |
| 255 | FPDF_InitLibraryWithConfig(&config); | 255 | FPDF_InitLibraryWithConfig(&config); |
| 256 | 256 |
| @@ -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.7 | 9 | +version: 5.7.0 |
| 10 | 10 | ||
| 11 | environment: | 11 | environment: |
| 12 | sdk: ">=2.12.0 <3.0.0" | 12 | sdk: ">=2.12.0 <3.0.0" |
| @@ -33,11 +33,12 @@ namespace nfet { | @@ -33,11 +33,12 @@ namespace nfet { | ||
| 33 | const auto pdfDpi = 72; | 33 | const auto pdfDpi = 72; |
| 34 | 34 | ||
| 35 | std::string toUtf8(std::wstring wstr) { | 35 | std::string toUtf8(std::wstring wstr) { |
| 36 | - int cbMultiByte = | ||
| 37 | - WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL); | 36 | + int cbMultiByte = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, |
| 37 | + 0, nullptr, nullptr); | ||
| 38 | LPSTR lpMultiByteStr = (LPSTR)malloc(cbMultiByte); | 38 | LPSTR lpMultiByteStr = (LPSTR)malloc(cbMultiByte); |
| 39 | - cbMultiByte = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, | ||
| 40 | - lpMultiByteStr, cbMultiByte, NULL, NULL); | 39 | + cbMultiByte = |
| 40 | + WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, lpMultiByteStr, | ||
| 41 | + cbMultiByte, nullptr, nullptr); | ||
| 41 | std::string ret = lpMultiByteStr; | 42 | std::string ret = lpMultiByteStr; |
| 42 | free(lpMultiByteStr); | 43 | free(lpMultiByteStr); |
| 43 | return ret; | 44 | return ret; |
| @@ -73,7 +74,7 @@ std::wstring fromUtf8(std::string str) { | @@ -73,7 +74,7 @@ std::wstring fromUtf8(std::string str) { | ||
| 73 | PrintJob::PrintJob(Printing* printing, int index) | 74 | PrintJob::PrintJob(Printing* printing, int index) |
| 74 | : printing{printing}, index{index} {} | 75 | : printing{printing}, index{index} {} |
| 75 | 76 | ||
| 76 | -bool PrintJob::printPdf(std::string name, | 77 | +bool PrintJob::printPdf(const std::string& name, |
| 77 | std::string printer, | 78 | std::string printer, |
| 78 | double width, | 79 | double width, |
| 79 | double height, | 80 | double height, |
| @@ -82,12 +83,13 @@ bool PrintJob::printPdf(std::string name, | @@ -82,12 +83,13 @@ bool PrintJob::printPdf(std::string name, | ||
| 82 | 83 | ||
| 83 | auto dm = static_cast<DEVMODE*>(GlobalAlloc(0, sizeof(DEVMODE))); | 84 | auto dm = static_cast<DEVMODE*>(GlobalAlloc(0, sizeof(DEVMODE))); |
| 84 | 85 | ||
| 85 | - if (usePrinterSettings){ | ||
| 86 | - dm = NULL; // to use default driver config | 86 | + if (usePrinterSettings) { |
| 87 | + dm = nullptr; // to use default driver config | ||
| 87 | } else { | 88 | } else { |
| 88 | ZeroMemory(dm, sizeof(DEVMODE)); | 89 | ZeroMemory(dm, sizeof(DEVMODE)); |
| 89 | dm->dmSize = sizeof(DEVMODE); | 90 | dm->dmSize = sizeof(DEVMODE); |
| 90 | - dm->dmFields = DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH; | 91 | + dm->dmFields = |
| 92 | + DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH; | ||
| 91 | dm->dmPaperSize = 0; | 93 | dm->dmPaperSize = 0; |
| 92 | if (width > height) { | 94 | if (width > height) { |
| 93 | dm->dmOrientation = DMORIENT_LANDSCAPE; | 95 | dm->dmOrientation = DMORIENT_LANDSCAPE; |
| @@ -100,7 +102,6 @@ bool PrintJob::printPdf(std::string name, | @@ -100,7 +102,6 @@ bool PrintJob::printPdf(std::string name, | ||
| 100 | } | 102 | } |
| 101 | } | 103 | } |
| 102 | 104 | ||
| 103 | - | ||
| 104 | if (printer.empty()) { | 105 | if (printer.empty()) { |
| 105 | PRINTDLG pd; | 106 | PRINTDLG pd; |
| 106 | 107 | ||
| @@ -136,7 +137,7 @@ bool PrintJob::printPdf(std::string name, | @@ -136,7 +137,7 @@ bool PrintJob::printPdf(std::string name, | ||
| 136 | hDevNames = pd.hDevNames; | 137 | hDevNames = pd.hDevNames; |
| 137 | 138 | ||
| 138 | } else { | 139 | } else { |
| 139 | - hDC = CreateDC(TEXT("WINSPOOL"), fromUtf8(printer).c_str(), NULL, dm); | 140 | + hDC = CreateDC(TEXT("WINSPOOL"), fromUtf8(printer).c_str(), nullptr, dm); |
| 140 | if (!hDC) { | 141 | if (!hDC) { |
| 141 | return false; | 142 | return false; |
| 142 | } | 143 | } |
| @@ -227,8 +228,8 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | @@ -227,8 +228,8 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | ||
| 227 | 228 | ||
| 228 | FPDF_LIBRARY_CONFIG config; | 229 | FPDF_LIBRARY_CONFIG config; |
| 229 | config.version = 2; | 230 | config.version = 2; |
| 230 | - config.m_pUserFontPaths = NULL; | ||
| 231 | - config.m_pIsolate = NULL; | 231 | + config.m_pUserFontPaths = nullptr; |
| 232 | + config.m_pIsolate = nullptr; | ||
| 232 | config.m_v8EmbedderSlot = 0; | 233 | config.m_v8EmbedderSlot = 0; |
| 233 | FPDF_InitLibraryWithConfig(&config); | 234 | FPDF_InitLibraryWithConfig(&config); |
| 234 | 235 | ||
| @@ -243,7 +244,7 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | @@ -243,7 +244,7 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | ||
| 243 | auto marginTop = GetDeviceCaps(hDC, PHYSICALOFFSETY); | 244 | auto marginTop = GetDeviceCaps(hDC, PHYSICALOFFSETY); |
| 244 | 245 | ||
| 245 | for (auto pageNum = 0; pageNum < pages; pageNum++) { | 246 | for (auto pageNum = 0; pageNum < pages; pageNum++) { |
| 246 | - r = StartPage(hDC); | 247 | + StartPage(hDC); |
| 247 | 248 | ||
| 248 | auto page = FPDF_LoadPage(doc, pageNum); | 249 | auto page = FPDF_LoadPage(doc, pageNum); |
| 249 | if (!page) { | 250 | if (!page) { |
| @@ -266,7 +267,7 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | @@ -266,7 +267,7 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | ||
| 266 | FPDF_CloseDocument(doc); | 267 | FPDF_CloseDocument(doc); |
| 267 | FPDF_DestroyLibrary(); | 268 | FPDF_DestroyLibrary(); |
| 268 | 269 | ||
| 269 | - r = EndDoc(hDC); | 270 | + EndDoc(hDC); |
| 270 | 271 | ||
| 271 | DeleteDC(hDC); | 272 | DeleteDC(hDC); |
| 272 | GlobalFree(hDevNames); | 273 | GlobalFree(hDevNames); |
| @@ -275,9 +276,9 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | @@ -275,9 +276,9 @@ void PrintJob::writeJob(std::vector<uint8_t> data) { | ||
| 275 | printing->onCompleted(this, true, ""); | 276 | printing->onCompleted(this, true, ""); |
| 276 | } | 277 | } |
| 277 | 278 | ||
| 278 | -void PrintJob::cancelJob(std::string error) {} | 279 | +void PrintJob::cancelJob(const std::string& error) {} |
| 279 | 280 | ||
| 280 | -bool PrintJob::sharePdf(std::vector<uint8_t> data, std::string name) { | 281 | +bool PrintJob::sharePdf(std::vector<uint8_t> data, const std::string& name) { |
| 281 | TCHAR lpTempPathBuffer[MAX_PATH]; | 282 | TCHAR lpTempPathBuffer[MAX_PATH]; |
| 282 | 283 | ||
| 283 | auto ret = GetTempPath(MAX_PATH, lpTempPathBuffer); | 284 | auto ret = GetTempPath(MAX_PATH, lpTempPathBuffer); |
| @@ -294,14 +295,14 @@ bool PrintJob::sharePdf(std::vector<uint8_t> data, std::string name) { | @@ -294,14 +295,14 @@ bool PrintJob::sharePdf(std::vector<uint8_t> data, std::string name) { | ||
| 294 | 295 | ||
| 295 | SHELLEXECUTEINFO ShExecInfo; | 296 | SHELLEXECUTEINFO ShExecInfo; |
| 296 | ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); | 297 | ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); |
| 297 | - ShExecInfo.fMask = NULL; | ||
| 298 | - ShExecInfo.hwnd = NULL; | 298 | + ShExecInfo.fMask = 0; |
| 299 | + ShExecInfo.hwnd = nullptr; | ||
| 299 | ShExecInfo.lpVerb = TEXT("open"); | 300 | ShExecInfo.lpVerb = TEXT("open"); |
| 300 | ShExecInfo.lpFile = filename.c_str(); | 301 | ShExecInfo.lpFile = filename.c_str(); |
| 301 | - ShExecInfo.lpParameters = NULL; | ||
| 302 | - ShExecInfo.lpDirectory = NULL; | 302 | + ShExecInfo.lpParameters = nullptr; |
| 303 | + ShExecInfo.lpDirectory = nullptr; | ||
| 303 | ShExecInfo.nShow = SW_SHOWDEFAULT; | 304 | ShExecInfo.nShow = SW_SHOWDEFAULT; |
| 304 | - ShExecInfo.hInstApp = NULL; | 305 | + ShExecInfo.hInstApp = nullptr; |
| 305 | 306 | ||
| 306 | ret = ShellExecuteEx(&ShExecInfo); | 307 | ret = ShellExecuteEx(&ShExecInfo); |
| 307 | 308 | ||
| @@ -315,8 +316,8 @@ void PrintJob::rasterPdf(std::vector<uint8_t> data, | @@ -315,8 +316,8 @@ void PrintJob::rasterPdf(std::vector<uint8_t> data, | ||
| 315 | double scale) { | 316 | double scale) { |
| 316 | FPDF_LIBRARY_CONFIG config; | 317 | FPDF_LIBRARY_CONFIG config; |
| 317 | config.version = 2; | 318 | config.version = 2; |
| 318 | - config.m_pUserFontPaths = NULL; | ||
| 319 | - config.m_pIsolate = NULL; | 319 | + config.m_pUserFontPaths = nullptr; |
| 320 | + config.m_pIsolate = nullptr; | ||
| 320 | config.m_v8EmbedderSlot = 0; | 321 | config.m_v8EmbedderSlot = 0; |
| 321 | FPDF_InitLibraryWithConfig(&config); | 322 | FPDF_InitLibraryWithConfig(&config); |
| 322 | 323 |
| @@ -39,11 +39,11 @@ struct Printer { | @@ -39,11 +39,11 @@ struct Printer { | ||
| 39 | const bool default; | 39 | const bool default; |
| 40 | const bool available; | 40 | const bool available; |
| 41 | 41 | ||
| 42 | - Printer(std::string name, | ||
| 43 | - std::string url, | ||
| 44 | - std::string model, | ||
| 45 | - std::string location, | ||
| 46 | - std::string comment, | 42 | + Printer(const std::string& name, |
| 43 | + const std::string& url, | ||
| 44 | + const std::string& model, | ||
| 45 | + const std::string& location, | ||
| 46 | + const std::string& comment, | ||
| 47 | bool default, | 47 | bool default, |
| 48 | bool available) | 48 | bool available) |
| 49 | : name(name), | 49 | : name(name), |
| @@ -71,7 +71,7 @@ class PrintJob { | @@ -71,7 +71,7 @@ class PrintJob { | ||
| 71 | 71 | ||
| 72 | std::vector<Printer> listPrinters(); | 72 | std::vector<Printer> listPrinters(); |
| 73 | 73 | ||
| 74 | - bool printPdf(std::string name, | 74 | + bool printPdf(const std::string& name, |
| 75 | std::string printer, | 75 | std::string printer, |
| 76 | double width, | 76 | double width, |
| 77 | double height, | 77 | double height, |
| @@ -79,9 +79,9 @@ class PrintJob { | @@ -79,9 +79,9 @@ class PrintJob { | ||
| 79 | 79 | ||
| 80 | void writeJob(std::vector<uint8_t> data); | 80 | void writeJob(std::vector<uint8_t> data); |
| 81 | 81 | ||
| 82 | - void cancelJob(std::string error); | 82 | + void cancelJob(const std::string& error); |
| 83 | 83 | ||
| 84 | - bool sharePdf(std::vector<uint8_t> data, std::string name); | 84 | + bool sharePdf(std::vector<uint8_t> data, const std::string& name); |
| 85 | 85 | ||
| 86 | void pickPrinter(void* result); | 86 | void pickPrinter(void* result); |
| 87 | 87 |
| @@ -44,7 +44,7 @@ void Printing::onPageRasterized(std::vector<uint8_t> data, | @@ -44,7 +44,7 @@ void Printing::onPageRasterized(std::vector<uint8_t> data, | ||
| 44 | }))); | 44 | }))); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | -void Printing::onPageRasterEnd(PrintJob* job, const std::string error) { | 47 | +void Printing::onPageRasterEnd(PrintJob* job, const std::string& error) { |
| 48 | auto map = flutter::EncodableMap{ | 48 | auto map = flutter::EncodableMap{ |
| 49 | {flutter::EncodableValue("job"), flutter::EncodableValue(job->id())}, | 49 | {flutter::EncodableValue("job"), flutter::EncodableValue(job->id())}, |
| 50 | }; | 50 | }; |
| @@ -111,7 +111,9 @@ void Printing::onLayout(PrintJob* job, | @@ -111,7 +111,9 @@ void Printing::onLayout(PrintJob* job, | ||
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | // send completion status to flutter | 113 | // send completion status to flutter |
| 114 | -void Printing::onCompleted(PrintJob* job, bool completed, std::string error) { | 114 | +void Printing::onCompleted(PrintJob* job, |
| 115 | + bool completed, | ||
| 116 | + const std::string& error) { | ||
| 115 | auto map = flutter::EncodableMap{ | 117 | auto map = flutter::EncodableMap{ |
| 116 | {flutter::EncodableValue("job"), flutter::EncodableValue(job->id())}, | 118 | {flutter::EncodableValue("job"), flutter::EncodableValue(job->id())}, |
| 117 | {flutter::EncodableValue("completed"), | 119 | {flutter::EncodableValue("completed"), |
| @@ -40,7 +40,7 @@ class Printing { | @@ -40,7 +40,7 @@ class Printing { | ||
| 40 | int height, | 40 | int height, |
| 41 | PrintJob* job); | 41 | PrintJob* job); |
| 42 | 42 | ||
| 43 | - void onPageRasterEnd(PrintJob* job, const std::string error); | 43 | + void onPageRasterEnd(PrintJob* job, const std::string& error); |
| 44 | 44 | ||
| 45 | void onLayout(PrintJob* job, | 45 | void onLayout(PrintJob* job, |
| 46 | double pageWidth, | 46 | double pageWidth, |
| @@ -52,7 +52,7 @@ class Printing { | @@ -52,7 +52,7 @@ class Printing { | ||
| 52 | 52 | ||
| 53 | void Printing::onCompleted(PrintJob* job, | 53 | void Printing::onCompleted(PrintJob* job, |
| 54 | bool completed, | 54 | bool completed, |
| 55 | - const std::string error); | 55 | + const std::string& error); |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | } // namespace nfet | 58 | } // namespace nfet |
| @@ -79,11 +79,13 @@ class PrintingPlugin : public flutter::Plugin { | @@ -79,11 +79,13 @@ class PrintingPlugin : public flutter::Plugin { | ||
| 79 | auto height = std::get<double>( | 79 | auto height = std::get<double>( |
| 80 | arguments->find(flutter::EncodableValue("height"))->second); | 80 | arguments->find(flutter::EncodableValue("height"))->second); |
| 81 | auto usePrinterSettings = std::get<bool>( | 81 | auto usePrinterSettings = std::get<bool>( |
| 82 | - arguments->find(flutter::EncodableValue("usePrinterSettings"))->second); | 82 | + arguments->find(flutter::EncodableValue("usePrinterSettings")) |
| 83 | + ->second); | ||
| 83 | auto vJob = arguments->find(flutter::EncodableValue("job")); | 84 | auto vJob = arguments->find(flutter::EncodableValue("job")); |
| 84 | auto jobNum = vJob != arguments->end() ? std::get<int>(vJob->second) : -1; | 85 | auto jobNum = vJob != arguments->end() ? std::get<int>(vJob->second) : -1; |
| 85 | auto job = new PrintJob{&printing, jobNum}; | 86 | auto job = new PrintJob{&printing, jobNum}; |
| 86 | - auto res = job->printPdf(name, printer, width, height, usePrinterSettings); | 87 | + auto res = |
| 88 | + job->printPdf(name, printer, width, height, usePrinterSettings); | ||
| 87 | if (!res) { | 89 | if (!res) { |
| 88 | delete job; | 90 | delete job; |
| 89 | } | 91 | } |
-
Please register or login to post a comment