| 493 | } |
| 494 | |
| 495 | std::unique_ptr<QPrinter> MapPrinter::makePrinter() const |
| 496 | { |
| 497 | std::unique_ptr<QPrinter> printer; |
| 498 | if (!target) |
| 499 | { |
| 500 | printer = std::make_unique<QPrinter>(QPrinter::HighResolution); |
| 501 | } |
| 502 | else if (isPrinter()) |
| 503 | { |
| 504 | printer = std::make_unique<QPrinter>(*target, QPrinter::HighResolution); |
| 505 | } |
| 506 | else if (options.color_mode == MapPrinterOptions::DeviceCmyk) |
| 507 | { |
| 508 | printer = std::make_unique<AdvancedPdfPrinter>(*target, QPrinter::HighResolution); |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | printer = std::make_unique<QPrinter>(*target, QPrinter::HighResolution); |
| 513 | printer->setOutputFormat(QPrinter::PdfFormat); |
| 514 | } |
| 515 | |
| 516 | if (!printer->isValid()) |
| 517 | { |
| 518 | printer.reset(); |
| 519 | return printer; |
| 520 | } |
| 521 | |
| 522 | // Color can only be changed in (native) properties dialogs. This is the default. |
| 523 | printer->setColorMode(separationsModeSelected() ? QPrinter::GrayScale : QPrinter::Color); |
| 524 | if (printer->outputFormat() == QPrinter::NativeFormat) |
| 525 | { |
| 526 | PlatformPrinterProperties::restore(printer.get(), native_data); |
| 527 | } |
| 528 | |
| 529 | printer->setDocName(::OpenOrienteering::MapPrinter::tr("- Map -")); |
| 530 | printer->setFullPage(true); |
| 531 | if (page_format.page_size == QPageSize::Custom) |
| 532 | { |
| 533 | printer->setPaperSize(page_format.paper_dimensions, QPrinter::Millimeter); |
| 534 | printer->setOrientation(QPrinter::Portrait); |
| 535 | } |
| 536 | else |
| 537 | { |
| 538 | printer->setPageSize(QPageSize{page_format.page_size}); |
| 539 | printer->setOrientation((page_format.orientation == MapPrinterPageFormat::Portrait) ? QPrinter::Portrait : QPrinter::Landscape); |
| 540 | } |
| 541 | printer->setResolution(options.resolution); |
| 542 | |
| 543 | if (page_format.page_size == QPageSize::Custom || !isPrinter()) |
| 544 | { |
| 545 | printer->setPageMargins(0.0, 0.0, 0.0, 0.0, QPrinter::Millimeter); |
| 546 | } |
| 547 | |
| 548 | return printer; |
| 549 | } |
| 550 | |
| 551 | bool MapPrinter::isPrinter() const noexcept |
| 552 | { |
no test coverage detected