1 /*************************************************************************** 2 qgslayoutexporter.h 3 ------------------- 4 begin : October 2017 5 copyright : (C) 2017 by Nyall Dawson 6 email : nyall dot dawson at gmail dot com 7 ***************************************************************************/ 8 /*************************************************************************** 9 * * 10 * This program is free software; you can redistribute it and/or modify * 11 * it under the terms of the GNU General Public License as published by * 12 * the Free Software Foundation; either version 2 of the License, or * 13 * (at your option) any later version. * 14 * * 15 ***************************************************************************/ 16 #ifndef QGSLAYOUTEXPORTER_H 17 #define QGSLAYOUTEXPORTER_H 18 19 #include "qgis_core.h" 20 #include "qgsmargins.h" 21 #include "qgslayoutrendercontext.h" 22 #include "qgslayoutreportcontext.h" 23 #include "qgslayoutitem.h" 24 #include <QPointer> 25 #include <QSize> 26 #include <QRectF> 27 #include <QVector> 28 #include <functional> 29 30 #ifndef QT_NO_PRINTER 31 #include <QPrinter> 32 33 class QgsLayout; 34 class QPainter; 35 class QgsLayoutItemMap; 36 class QgsAbstractLayoutIterator; 37 class QgsFeedback; 38 class QgsLabelingResults; 39 40 /** 41 * \ingroup core 42 * \class QgsLayoutExporter 43 * \brief Handles rendering and exports of layouts to various formats. 44 * \since QGIS 3.0 45 */ 46 class CORE_EXPORT QgsLayoutExporter 47 { 48 49 public: 50 51 //! Contains details of a page being exported by the class 52 struct PageExportDetails 53 { 54 //! Target folder 55 QString directory; 56 57 //! Base part of filename (i.e. file name without extension or '.') 58 QString baseName; 59 60 //! File suffix/extension (without the leading '.') 61 QString extension; 62 63 //! Page number, where 0 = first page. 64 int page = 0; 65 }; 66 67 /** 68 * Constructor for QgsLayoutExporter, for the specified \a layout. 69 */ 70 QgsLayoutExporter( QgsLayout *layout ); 71 72 virtual ~QgsLayoutExporter(); 73 74 /** 75 * Returns the layout linked to this exporter. 76 */ 77 QgsLayout *layout() const; 78 79 /** 80 * Renders a full page to a destination \a painter. 81 * 82 * The \a page argument specifies the page number to render. Page numbers 83 * are 0 based, such that the first page in a layout is page 0. 84 * 85 * \see renderRegion() 86 */ 87 void renderPage( QPainter *painter, int page ) const; 88 89 /** 90 * Renders a full page to an image. 91 * 92 * The \a page argument specifies the page number to render. Page numbers 93 * are 0 based, such that the first page in a layout is page 0. 94 * 95 * The optional \a imageSize parameter can specify the target image size, in pixels. 96 * It is the caller's responsibility to ensure that the ratio of the target image size 97 * matches the ratio of the corresponding layout page size. 98 * 99 * The \a dpi parameter is an optional dpi override. Set to -1 to use the default layout print 100 * resolution. This parameter has no effect if \a imageSize is specified. 101 * 102 * Returns the rendered image, or a null QImage if the image does not fit into available memory. 103 * 104 * \see renderPage() 105 * \see renderRegionToImage() 106 */ 107 QImage renderPageToImage( int page, QSize imageSize = QSize(), double dpi = -1 ) const; 108 109 /** 110 * Renders a \a region from the layout to a \a painter. This method can be used 111 * to render sections of pages rather than full pages. 112 * 113 * \see renderPage() 114 * \see renderRegionToImage() 115 */ 116 void renderRegion( QPainter *painter, const QRectF ®ion ) const; 117 118 /** 119 * Renders a \a region of the layout to an image. This method can be used to render 120 * sections of pages rather than full pages. 121 * 122 * The optional \a imageSize parameter can specify the target image size, in pixels. 123 * It is the caller's responsibility to ensure that the ratio of the target image size 124 * matches the ratio of the specified region of the layout. 125 * 126 * The \a dpi parameter is an optional dpi override. Set to -1 to use the default layout print 127 * resolution. This parameter has no effect if \a imageSize is specified. 128 * 129 * Returns the rendered image, or a null QImage if the image does not fit into available memory. 130 * 131 * \see renderRegion() 132 * \see renderPageToImage() 133 */ 134 QImage renderRegionToImage( const QRectF ®ion, QSize imageSize = QSize(), double dpi = -1 ) const; 135 136 137 //! Result codes for exporting layouts 138 enum ExportResult 139 { 140 Success, //!< Export was successful 141 Canceled, //!< Export was canceled 142 MemoryError, //!< Unable to allocate memory required to export 143 FileError, //!< Could not write to destination file, likely due to a lock held by another application 144 PrintError, //!< Could not start printing to destination device 145 SvgLayerError, //!< Could not create layered SVG file 146 IteratorError, //!< Error iterating over layout 147 }; 148 149 //! Contains settings relating to exporting layouts to raster images 150 struct ImageExportSettings 151 { 152 //! Constructor for ImageExportSettings ImageExportSettingsImageExportSettings153 ImageExportSettings() 154 : flags( QgsLayoutRenderContext::FlagAntialiasing | QgsLayoutRenderContext::FlagUseAdvancedEffects ) 155 {} 156 157 //! Resolution to export layout at. If dpi <= 0 the default layout dpi will be used. 158 double dpi = -1; 159 160 /** 161 * Manual size in pixels for output image. If imageSize is not 162 * set then it will be automatically calculated based on the 163 * output dpi and layout size. 164 * 165 * If cropToContents is TRUE then imageSize has no effect. 166 * 167 * Be careful when specifying manual sizes if pages in the layout 168 * have differing sizes! It's likely not going to give a reasonable 169 * output in this case, and the automatic dpi-based image size should be 170 * used instead. 171 */ 172 QSize imageSize; 173 174 /** 175 * Set to TRUE if image should be cropped so only parts of the layout 176 * containing items are exported. 177 */ 178 bool cropToContents = false; 179 180 /** 181 * Crop to content margins, in pixels. These margins will be added 182 * to the bounds of the exported layout if cropToContents is TRUE. 183 */ 184 QgsMargins cropMargins; 185 186 /** 187 * List of specific pages to export, or an empty list to 188 * export all pages. 189 * 190 * Page numbers are 0 index based, so the first page in the 191 * layout corresponds to page 0. 192 */ 193 QList< int > pages; 194 195 /** 196 * Set to TRUE to generate an external world file alongside 197 * exported images. 198 */ 199 bool generateWorldFile = false; 200 201 /** 202 * Indicates whether image export should include metadata generated 203 * from the layout's project's metadata. 204 * 205 * \since QGIS 3.2 206 */ 207 bool exportMetadata = true; 208 209 210 /** 211 * Layout context flags, which control how the export will be created. 212 */ 213 QgsLayoutRenderContext::Flags flags = QgsLayoutRenderContext::Flags(); 214 215 /** 216 * A list of predefined scales to use with the layout. This is used 217 * for maps which are set to the predefined atlas scaling mode. 218 * \since QGIS 3.10 219 */ 220 QVector<qreal> predefinedMapScales; 221 222 }; 223 224 /** 225 * Exports the layout to the \a filePath, using the specified export \a settings. 226 * 227 * If the layout is a multi-page layout, then filenames for each page will automatically 228 * be generated by appending "_1", "_2", etc to the image file's base name. 229 * 230 * Returns a result code indicating whether the export was successful or an 231 * error was encountered. If an error code is returned, errorFile() can be called 232 * to determine the filename for the export which encountered the error. 233 */ 234 ExportResult exportToImage( const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings ); 235 236 237 /** 238 * Exports a layout \a iterator to raster images, with the specified export \a settings. 239 * 240 * The \a baseFilePath argument gives a base file path, which is modified by the 241 * iterator to obtain file paths for each iterator feature. 242 * 243 * Returns a result code indicating whether the export was successful or an 244 * error was encountered. If an error was obtained then \a error will be set 245 * to the error description. 246 */ 247 static ExportResult exportToImage( QgsAbstractLayoutIterator *iterator, const QString &baseFilePath, 248 const QString &extension, const QgsLayoutExporter::ImageExportSettings &settings, 249 QString &error SIP_OUT, QgsFeedback *feedback = nullptr ); 250 251 252 //! Contains settings relating to exporting layouts to PDF 253 struct PdfExportSettings 254 { 255 //! Constructor for PdfExportSettings PdfExportSettingsPdfExportSettings256 PdfExportSettings() 257 : flags( QgsLayoutRenderContext::FlagAntialiasing | QgsLayoutRenderContext::FlagUseAdvancedEffects ) 258 {} 259 260 //! Resolution to export layout at. If dpi <= 0 the default layout dpi will be used. 261 double dpi = -1; 262 263 /** 264 * Set to TRUE to force whole layout to be rasterized while exporting. 265 * 266 * This option is mutually exclusive with forceVectorOutput. 267 */ 268 bool rasterizeWholeImage = false; 269 270 /** 271 * Set to TRUE to force vector object exports, even when the resultant appearance will differ 272 * from the layout. If FALSE, some items may be rasterized in order to maintain their 273 * correct appearance in the output. 274 * 275 * This option is mutually exclusive with rasterizeWholeImage. 276 */ 277 bool forceVectorOutput = false; 278 279 /** 280 * Indicates whether PDF export should append georeference data 281 * 282 * \since QGIS 3.10 283 */ 284 bool appendGeoreference = true; 285 286 /** 287 * Indicates whether PDF export should include metadata generated 288 * from the layout's project's metadata. 289 * 290 * \since QGIS 3.2 291 */ 292 bool exportMetadata = true; 293 294 /** 295 * Layout context flags, which control how the export will be created. 296 */ 297 QgsLayoutRenderContext::Flags flags = QgsLayoutRenderContext::Flags(); 298 299 /** 300 * Text rendering format, which controls how text should be rendered in the export (e.g. 301 * as paths or real text objects). 302 * 303 * \since QGIS 3.4.3 304 */ 305 Qgis::TextRenderFormat textRenderFormat = Qgis::TextRenderFormat::AlwaysOutlines; 306 307 /** 308 * Indicates whether vector geometries should be simplified to avoid redundant extraneous detail, 309 * such as vertices which are not visible at the specified dpi of the output. 310 * 311 * \since QGIS 3.10 312 */ 313 bool simplifyGeometries = true; 314 315 /** 316 * TRUE if GeoPDF files should be created, instead of normal PDF files. 317 * 318 * Whilst GeoPDF files can include some desirable properties like the ability to interactively 319 * query map features, they also can result in lower-quality output files, or forced rasterization 320 * of layers. 321 * 322 * \note Requires builds based on GDAL 3.0 or greater. 323 * 324 * \since QGIS 3.10 325 */ 326 bool writeGeoPdf = false; 327 328 /** 329 * TRUE if individual layers from the layout should be rendered to separate PDF files. 330 * 331 * This option allows for separation of logic layout layers to individual PDF files. For instance, 332 * if this option is TRUE, then a separate PDF file will be created per layer per map item in the 333 * layout. Additionally, separate PDF files may be created for other complex layout items, resulting 334 * in a set of PDF files which contain logical atomic components of the layout. 335 * 336 * This option is designed to allow the PDF files to be composited back together in an external 337 * application (e.g. Adobe Illustrator) as a non-QGIS, post-production step. 338 * 339 * \since QGIS 3.14 340 */ 341 bool exportLayersAsSeperateFiles = false; // TODO QGIS 4 fix typo //#spellok 342 343 /** 344 * TRUE if ISO3200 extension format georeferencing should be used. 345 * 346 * This is a recommended setting which results in Geospatial PDF files compatible 347 * with the built-in Acrobat geospatial tools. 348 * 349 * If PdfExportSettings::writeGeoPdf is FALSE than this option has no effect. 350 */ 351 bool useIso32000ExtensionFormatGeoreferencing = true; 352 353 /** 354 * TRUE if OGC "best practice" format georeferencing should be used. 355 * 356 * \warning This results in GeoPDF files compatible with the TerraGo suite of tools, but 357 * can break compatibility with the built-in Acrobat geospatial tools (yes, GeoPDF 358 * format is a mess!). 359 * 360 * If PdfExportSettings::writeGeoPdf is FALSE than this option has no effect. 361 */ 362 bool useOgcBestPracticeFormatGeoreferencing = false; 363 364 /** 365 * TRUE if feature vector information (such as attributes) should be exported during GeoPDF exports. 366 * 367 * If PdfExportSettings::writeGeoPdf is FALSE than this option has no effect. 368 */ 369 bool includeGeoPdfFeatures = true; 370 371 /** 372 * Optional list of map themes to export as GeoPDF layer groups. 373 * 374 * If set, map item's which are not assigned a specific map theme will iterate through all listed 375 * themes and a GeoPDF layer group will be created for each. 376 * 377 * If PdfExportSettings::writeGeoPdf is FALSE than this option has no effect. 378 */ 379 QStringList exportThemes; 380 381 /** 382 * A list of predefined scales to use with the layout. This is used 383 * for maps which are set to the predefined atlas scaling mode. 384 * \since QGIS 3.10 385 */ 386 QVector<qreal> predefinedMapScales; 387 388 }; 389 390 /** 391 * Exports the layout as a PDF to the \a filePath, using the specified export \a settings. 392 * 393 * Returns a result code indicating whether the export was successful or an 394 * error was encountered. 395 */ 396 ExportResult exportToPdf( const QString &filePath, const QgsLayoutExporter::PdfExportSettings &settings ); 397 398 /** 399 * Exports a layout \a iterator to a single PDF file, with the specified export \a settings. 400 * 401 * The \a fileName argument gives the destination file name for the output PDF. 402 * 403 * Returns a result code indicating whether the export was successful or an 404 * error was encountered. If an error was obtained then \a error will be set 405 * to the error description. 406 * 407 * \see exportToPdfs() 408 */ 409 static ExportResult exportToPdf( QgsAbstractLayoutIterator *iterator, const QString &fileName, 410 const QgsLayoutExporter::PdfExportSettings &settings, 411 QString &error SIP_OUT, QgsFeedback *feedback = nullptr ); 412 413 /** 414 * Exports a layout \a iterator to multiple PDF files, with the specified export \a settings. 415 * 416 * The \a baseFilePath argument gives a base file path, which is modified by the 417 * iterator to obtain file paths for each iterator feature. 418 * 419 * Returns a result code indicating whether the export was successful or an 420 * error was encountered. If an error was obtained then \a error will be set 421 * to the error description. 422 * 423 * \see exportToPdf() 424 */ 425 static ExportResult exportToPdfs( QgsAbstractLayoutIterator *iterator, const QString &baseFilePath, 426 const QgsLayoutExporter::PdfExportSettings &settings, 427 QString &error SIP_OUT, QgsFeedback *feedback = nullptr ); 428 429 430 //! Contains settings relating to printing layouts 431 struct PrintExportSettings 432 { 433 //! Constructor for PrintExportSettings PrintExportSettingsPrintExportSettings434 PrintExportSettings() 435 : flags( QgsLayoutRenderContext::FlagAntialiasing | QgsLayoutRenderContext::FlagUseAdvancedEffects ) 436 {} 437 438 //! Resolution to export layout at. If dpi <= 0 the default layout dpi will be used. 439 double dpi = -1; 440 441 /** 442 * Set to TRUE to force whole layout to be rasterized while exporting. 443 * 444 * This option is mutually exclusive with forceVectorOutput. 445 */ 446 bool rasterizeWholeImage = false; 447 448 /** 449 * Layout context flags, which control how the export will be created. 450 */ 451 QgsLayoutRenderContext::Flags flags = QgsLayoutRenderContext::Flags(); 452 453 /** 454 * A list of predefined scales to use with the layout. This is used 455 * for maps which are set to the predefined atlas scaling mode. 456 * \since QGIS 3.10 457 */ 458 QVector<qreal> predefinedMapScales; 459 460 }; 461 462 /** 463 * Prints the layout to a \a printer, using the specified export \a settings. 464 * 465 * Returns a result code indicating whether the export was successful or an 466 * error was encountered. 467 */ 468 ExportResult print( QPrinter &printer, const QgsLayoutExporter::PrintExportSettings &settings ); 469 470 /** 471 * Exports a layout \a iterator to a \a printer, with the specified export \a settings. 472 * 473 * Returns a result code indicating whether the export was successful or an 474 * error was encountered. If an error was obtained then \a error will be set 475 * to the error description. 476 */ 477 static ExportResult print( QgsAbstractLayoutIterator *iterator, QPrinter &printer, 478 const QgsLayoutExporter::PrintExportSettings &settings, 479 QString &error SIP_OUT, QgsFeedback *feedback = nullptr ); 480 481 482 //! Contains settings relating to exporting layouts to SVG 483 struct SvgExportSettings 484 { 485 //! Constructor for SvgExportSettings SvgExportSettingsSvgExportSettings486 SvgExportSettings() 487 : flags( QgsLayoutRenderContext::FlagAntialiasing | QgsLayoutRenderContext::FlagUseAdvancedEffects ) 488 {} 489 490 //! Resolution to export layout at. If dpi <= 0 the default layout dpi will be used. 491 double dpi = -1; 492 493 /** 494 * Set to TRUE to force vector object exports, even when the resultant appearance will differ 495 * from the layout. If FALSE, some items may be rasterized in order to maintain their 496 * correct appearance in the output. 497 * 498 * This option is mutually exclusive with rasterizeWholeImage. 499 */ 500 bool forceVectorOutput = false; 501 502 /** 503 * Set to TRUE if image should be cropped so only parts of the layout 504 * containing items are exported. 505 */ 506 bool cropToContents = false; 507 508 /** 509 * Crop to content margins, in layout units. These margins will be added 510 * to the bounds of the exported layout if cropToContents is TRUE. 511 */ 512 QgsMargins cropMargins; 513 514 /** 515 * Set to TRUE to export as a layered SVG file. 516 * Note that this option is considered experimental, and the generated 517 * SVG may differ from the expected appearance of the layout. 518 */ 519 bool exportAsLayers = false; 520 521 /** 522 * Set to TRUE to export labels to separate layers (grouped by map layer) 523 * in layered SVG exports. 524 * 525 * This option is only used if exportAsLayers is TRUE. 526 * 527 * \since QGIS 3.10 528 */ 529 bool exportLabelsToSeparateLayers = true; 530 531 /** 532 * Indicates whether SVG export should include RDF metadata generated 533 * from the layout's project's metadata. 534 * 535 * \since QGIS 3.2 536 */ 537 bool exportMetadata = true; 538 539 /** 540 * Layout context flags, which control how the export will be created. 541 */ 542 QgsLayoutRenderContext::Flags flags = QgsLayoutRenderContext::Flags(); 543 544 /** 545 * Text rendering format, which controls how text should be rendered in the export (e.g. 546 * as paths or real text objects). 547 * 548 * \since QGIS 3.4.3 549 */ 550 Qgis::TextRenderFormat textRenderFormat = Qgis::TextRenderFormat::AlwaysOutlines; 551 552 /** 553 * Indicates whether vector geometries should be simplified to avoid redundant extraneous detail, 554 * such as vertices which are not visible at the specified dpi of the output. 555 * 556 * \since QGIS 3.10 557 */ 558 bool simplifyGeometries = true; 559 560 /** 561 * A list of predefined scales to use with the layout. This is used 562 * for maps which are set to the predefined atlas scaling mode. 563 * \since QGIS 3.10 564 */ 565 QVector<qreal> predefinedMapScales; 566 }; 567 568 /** 569 * Exports the layout as an SVG to the \a filePath, using the specified export \a settings. 570 * 571 * Returns a result code indicating whether the export was successful or an 572 * error was encountered. 573 */ 574 ExportResult exportToSvg( const QString &filePath, const QgsLayoutExporter::SvgExportSettings &settings ); 575 576 /** 577 * Exports a layout \a iterator to SVG files, with the specified export \a settings. 578 * 579 * The \a baseFilePath argument gives a base file path, which is modified by the 580 * iterator to obtain file paths for each iterator feature. 581 * 582 * Returns a result code indicating whether the export was successful or an 583 * error was encountered. If an error was obtained then \a error will be set 584 * to the error description. 585 */ 586 static ExportResult exportToSvg( QgsAbstractLayoutIterator *iterator, const QString &baseFilePath, 587 const QgsLayoutExporter::SvgExportSettings &settings, 588 QString &error SIP_OUT, QgsFeedback *feedback = nullptr ); 589 590 591 /** 592 * Returns the file name corresponding to the last error encountered during 593 * an export. 594 */ errorFile()595 QString errorFile() const { return mErrorFileName; } 596 597 /** 598 * Returns the labeling results for all map items included in the export. Map keys are the item UUIDs (see QgsLayoutItem::uuid()). 599 * 600 * Ownership of the results remains with the layout exporter. 601 * 602 * \since QGIS 3.20 603 */ 604 QMap< QString, QgsLabelingResults * > labelingResults(); 605 606 #ifndef SIP_RUN 607 608 /** 609 * Takes the labeling results for all map items included in the export. Map keys are the item UUIDs (see QgsLayoutItem::uuid()). 610 * 611 * Ownership of the results is transferred to the caller. 612 * 613 * \note Not available in Python bindings 614 * 615 * \since QGIS 3.20 616 */ 617 QMap< QString, QgsLabelingResults * > takeLabelingResults(); 618 #endif 619 620 /** 621 * Georeferences a \a file (image of PDF) exported from the layout. 622 * 623 * The \a referenceMap argument specifies a map item to use for georeferencing. If left as NULLPTR, the 624 * default layout QgsLayout::referenceMap() will be used. 625 * 626 * The \a exportRegion argument can be set to a valid rectangle to indicate that only part of the layout was 627 * exported. 628 * 629 * Similarly, the \a dpi can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. 630 * 631 * The function will return TRUE if the output was successfully georeferenced. 632 * 633 * \see computeWorldFileParameters() 634 */ 635 bool georeferenceOutput( const QString &file, QgsLayoutItemMap *referenceMap = nullptr, 636 const QRectF &exportRegion = QRectF(), double dpi = -1 ) const; 637 638 /** 639 * Compute world file parameters. Assumes the whole page containing the reference map item 640 * will be exported. 641 * 642 * The \a dpi argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. 643 */ 644 void computeWorldFileParameters( double &a, double &b, double &c, double &d, double &e, double &f, double dpi = -1 ) const; 645 646 /** 647 * Computes the world file parameters for a specified \a region of the layout. 648 * 649 * The \a dpi argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. 650 */ 651 void computeWorldFileParameters( const QRectF ®ion, double &a, double &b, double &c, double &d, double &e, double &f, double dpi = -1 ) const; 652 653 /** 654 * Returns TRUE if the specified \a layout contains visible items which have settings 655 * that require rasterization of the entire export layout in order to reproduce the desired 656 * appearance. 657 * 658 * \see containsAdvancedEffects() 659 * \since QGIS 3.20 660 */ 661 static bool requiresRasterization( const QgsLayout *layout ); 662 663 /** 664 * Returns TRUE if the specified \a layout contains visible items which have settings 665 * such as opacity which will prevent these individual items from being exported as vector artwork. 666 * 667 * \see requiresRasterization() 668 * \since QGIS 3.20 669 */ 670 static bool containsAdvancedEffects( const QgsLayout *layout ); 671 672 protected: 673 674 /** 675 * Generates the file name for a page during export. 676 * 677 * Subclasses can override this method to customize page file naming. 678 */ 679 virtual QString generateFileName( const PageExportDetails &details ) const; 680 681 private: 682 683 QPointer< QgsLayout > mLayout; 684 685 void captureLabelingResults(); 686 QMap< QString, QgsLabelingResults * > mLabelingResults; 687 688 mutable QString mErrorFileName; 689 690 QImage createImage( const ImageExportSettings &settings, int page, QRectF &bounds, bool &skipPage ) const; 691 692 /** 693 * Returns the page number of the first page to be exported from the layout, skipping any pages 694 * which have been excluded from export. 695 */ 696 static int firstPageToBeExported( QgsLayout *layout ); 697 698 /** 699 * Saves an image to a file, possibly using format specific options (e.g. LZW compression for tiff) 700 */ 701 static bool saveImage( const QImage &image, const QString &imageFilename, const QString &imageFormat, QgsProject *projectForMetadata ); 702 703 /** 704 * Computes a GDAL style geotransform for georeferencing a layout. 705 * 706 * The \a referenceMap argument specifies a map item to use for georeferencing. If left as NULLPTR, the 707 * default layout QgsLayout::referenceMap() will be used. 708 * 709 * The \a exportRegion argument can be set to a valid rectangle to indicate that only part of the layout was 710 * exported. 711 * 712 * Similarly, the \a dpi can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. 713 * 714 * \see georeferenceOutput() 715 */ 716 std::unique_ptr<double[]> computeGeoTransform( const QgsLayoutItemMap *referenceMap = nullptr, const QRectF &exportRegion = QRectF(), double dpi = -1 ) const; 717 718 //! Write a world file 719 void writeWorldFile( const QString &fileName, double a, double b, double c, double d, double e, double f ) const; 720 721 /** 722 * Prepare a \a printer for printing a layout as a PDF, to the destination \a filePath. 723 */ 724 static void preparePrintAsPdf( QgsLayout *layout, QPrinter &printer, const QString &filePath ); 725 726 static void preparePrint( QgsLayout *layout, QPrinter &printer, bool setFirstPageSize = false ); 727 728 /** 729 * Convenience function that prepares the printer and prints. 730 */ 731 ExportResult print( QPrinter &printer ); 732 733 /** 734 * Print on a preconfigured printer 735 * \param printer QPrinter destination 736 * \param painter QPainter source 737 * \param startNewPage set to TRUE to begin the print on a new page 738 * \param dpi set to a value > 0 to manually override the layout's default dpi 739 * \param rasterize set to TRUE to force print as a raster image 740 */ 741 ExportResult printPrivate( QPrinter &printer, QPainter &painter, bool startNewPage = false, double dpi = -1, bool rasterize = false ); 742 743 static void updatePrinterPageSize( QgsLayout *layout, QPrinter &printer, int page ); 744 745 ExportResult renderToLayeredSvg( const SvgExportSettings &settings, double width, double height, int page, const QRectF &bounds, 746 const QString &filename, unsigned int svgLayerId, const QString &layerName, 747 QDomDocument &svg, QDomNode &svgDocRoot, bool includeMetadata ) const; 748 749 void appendMetadataToSvg( QDomDocument &svg ) const; 750 751 bool georeferenceOutputPrivate( const QString &file, QgsLayoutItemMap *referenceMap = nullptr, 752 const QRectF &exportRegion = QRectF(), double dpi = -1, bool includeGeoreference = true, bool includeMetadata = false ) const; 753 754 ExportResult handleLayeredExport( const QList<QGraphicsItem *> &items, const std::function<QgsLayoutExporter::ExportResult( unsigned int layerId, const QgsLayoutItem::ExportLayerDetail &layerDetails )> &exportFunc ); 755 756 static QgsVectorSimplifyMethod createExportSimplifyMethod(); 757 friend class TestQgsLayout; 758 friend class TestQgsLayoutExporter; 759 760 }; 761 762 #endif // ! QT_NO_PRINTER 763 764 #endif //QGSLAYOUTEXPORTER_H 765 766 767 768