1
1
/*
2
2
* Copyright 2012, 2013 Thomas Schöps
3
- * Copyright 2012-2018 Kai Pastor
3
+ * Copyright 2012-2020 Kai Pastor
4
4
*
5
5
* This file is part of OpenOrienteering.
6
6
*
@@ -391,6 +391,12 @@ const QPrinterInfo* MapPrinter::imageTarget()
391
391
return &image_target;
392
392
}
393
393
394
+ const QPrinterInfo* MapPrinter::kmzTarget ()
395
+ {
396
+ static QPrinterInfo kmz_target; // TODO: set name and features?
397
+ return &kmz_target;
398
+ }
399
+
394
400
395
401
// QPageSize (::key(), ::name()) made this list mostly obsolete.
396
402
// But we keep it in v0.9 for loading maps where we used names
@@ -454,14 +460,17 @@ void MapPrinter::setTarget(const QPrinterInfo* new_target)
454
460
target = new_target;
455
461
else if (new_target == imageTarget ())
456
462
target = new_target;
463
+ else if (new_target == kmzTarget ())
464
+ target = new_target;
457
465
else
458
466
{
459
467
// We don't own this target, so we need to make a copy.
460
468
target_copy = *new_target;
461
469
target = &target_copy;
462
470
}
463
471
464
- if (old_target == imageTarget () || new_target == imageTarget ())
472
+ if (old_target == imageTarget () || new_target == imageTarget ()
473
+ || old_target == kmzTarget () || new_target == kmzTarget ())
465
474
{
466
475
// No page margins. Will emit pageFormatChanged( ).
467
476
setCustomPageSize (page_format.page_rect .size ());
@@ -536,7 +545,8 @@ bool MapPrinter::isPrinter() const
536
545
{
537
546
bool is_printer = target
538
547
&& target != imageTarget ()
539
- && target != pdfTarget ();
548
+ && target != pdfTarget ()
549
+ && target != kmzTarget ();
540
550
return is_printer;
541
551
}
542
552
@@ -547,7 +557,7 @@ void MapPrinter::setPrintArea(const QRectF& area)
547
557
{
548
558
print_area = area;
549
559
550
- if (target == imageTarget () && print_area.size () != page_format.paper_dimensions )
560
+ if (( target == imageTarget () || target == kmzTarget () ) && print_area.size () != page_format.paper_dimensions )
551
561
setCustomPageSize (print_area.size () * scale_adjustment);
552
562
553
563
updatePageBreaks ();
@@ -627,7 +637,7 @@ void MapPrinter::setOverlap(qreal h_overlap, qreal v_overlap)
627
637
628
638
void MapPrinter::updatePaperDimensions ()
629
639
{
630
- if (target == imageTarget () && page_format.page_size == QPageSize::Custom)
640
+ if (( target == imageTarget () || target == kmzTarget () ) && page_format.page_size == QPageSize::Custom)
631
641
{
632
642
// No margins, no need to query QPrinter.
633
643
page_format.page_rect = QRectF (QPointF (0.0 , 0.0 ), page_format.paper_dimensions );
@@ -639,7 +649,7 @@ void MapPrinter::updatePaperDimensions()
639
649
640
650
QPrinter* printer = target ? new QPrinter (*target, QPrinter::HighResolution)
641
651
: new QPrinter (QPrinter::HighResolution);
642
- if (!printer->isValid () || target == imageTarget () || target == pdfTarget ())
652
+ if (!printer->isValid () || target == imageTarget () || target == kmzTarget () || target == pdfTarget ())
643
653
printer->setOutputFormat (QPrinter::PdfFormat);
644
654
645
655
if (page_format.page_size == QPageSize::Custom)
@@ -657,7 +667,7 @@ void MapPrinter::updatePaperDimensions()
657
667
page_format.page_rect = printer->paperRect (QPrinter::Millimeter);
658
668
page_format.paper_dimensions = page_format.page_rect .size ();
659
669
660
- if ( target != imageTarget () && target != pdfTarget () &&
670
+ if ( target != imageTarget () && target != kmzTarget () && target != pdfTarget () &&
661
671
page_format.page_size != QPageSize::Custom )
662
672
{
663
673
page_format.page_rect = printer->pageRect (QPrinter::Millimeter);
@@ -896,7 +906,7 @@ void MapPrinter::takePrinterSettings(const QPrinter* printer)
896
906
if (!printer) return ;
897
907
898
908
MapPrinterPageFormat f (*printer);
899
- if (target == pdfTarget () || target == imageTarget ())
909
+ if (target == pdfTarget () || target == imageTarget () || target == kmzTarget () )
900
910
{
901
911
f.page_rect = QRectF (QPointF (0.0 , 0.0 ), f.paper_dimensions );
902
912
}
@@ -921,6 +931,20 @@ void MapPrinter::takePrinterSettings(const QPrinter* printer)
921
931
922
932
923
933
void MapPrinter::drawPage (QPainter* device_painter, const QRectF& page_extent, QImage* page_buffer) const
934
+ {
935
+ // Determine transformation and clipping for page extent and region
936
+ const qreal units_per_mm = options.resolution / 25.4 ;
937
+ // Translate for top left page margin
938
+ auto transform = QTransform::fromScale (units_per_mm, units_per_mm);
939
+ transform.translate (page_format.page_rect .left (), page_format.page_rect .top ());
940
+ // Convert native map scale to print scale
941
+ transform.scale (scale_adjustment, scale_adjustment);
942
+ // Translate and clip for margins and print area
943
+ transform.translate (-page_extent.left (), -page_extent.top ());
944
+ drawPage (device_painter, page_extent, transform, page_buffer);
945
+ }
946
+
947
+ void MapPrinter::drawPage (QPainter* device_painter, const QRectF& page_extent, const QTransform& page_extent_transform, QImage* page_buffer) const
924
948
{
925
949
// Logical units per mm
926
950
const qreal units_per_mm = options.resolution / 25.4 ;
@@ -930,18 +954,6 @@ void MapPrinter::drawPage(QPainter* device_painter, const QRectF& page_extent, Q
930
954
| QPainter::Antialiasing
931
955
| QPainter::SmoothPixmapTransform;
932
956
933
- // Determine transformation and clipping for page extent and region
934
- const auto page_extent_transform = [this , units_per_mm, page_extent]() {
935
- // Translate for top left page margin
936
- auto transform = QTransform::fromScale (units_per_mm, units_per_mm);
937
- transform.translate (page_format.page_rect .left (), page_format.page_rect .top ());
938
- // Convert native map scale to print scale
939
- transform.scale (scale_adjustment, scale_adjustment);
940
- // Translate and clip for margins and print area
941
- transform.translate (-page_extent.left (), -page_extent.top ());
942
- return transform;
943
- }();
944
-
945
957
const auto page_region_used = page_extent.intersected (print_area);
946
958
947
959
@@ -964,7 +976,7 @@ void MapPrinter::drawPage(QPainter* device_painter, const QRectF& page_extent, Q
964
976
* When the target is an image, use the temporary image to enforce the given
965
977
* resolution.
966
978
*/
967
- const bool use_buffer_for_map = rasterModeSelected () || target == imageTarget () || engineWillRasterize ();
979
+ const bool use_buffer_for_map = rasterModeSelected () || target == imageTarget () || target == kmzTarget () || engineWillRasterize ();
968
980
bool use_page_buffer = use_buffer_for_map;
969
981
970
982
auto first_front_template = map.getFirstFrontTemplate ();
@@ -1232,7 +1244,7 @@ void MapPrinter::drawSeparationPages(QPrinter* printer, QPainter* device_painter
1232
1244
1233
1245
// Translate and clip for margins and print area
1234
1246
device_painter->translate (-page_extent.left (), -page_extent.top ());
1235
- device_painter->setClipRect (page_extent.intersected (print_area), Qt::ReplaceClip);
1247
+ device_painter->setClipRect (page_extent.intersected (print_area). adjusted (- 10 , 10 , 10 , 10 ) , Qt::ReplaceClip);
1236
1248
1237
1249
bool need_new_page = false ;
1238
1250
for (int i = map.getNumColors () - 1 ; i >= 0 ; --i)
0 commit comments