MCPcopy Create free account
hub / github.com/LUX-Core/lux / savePdf

Method savePdf

src/qt/qcustomplot.cpp:14486–14547  ·  view source on GitHub ↗

! Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale of texts and lines will be derived from the specified \a width and \a height. This means, the output will look like the normal on-screen output of a QCustomPlot widget with the corresponding pixel width and height. If either \a width or \a height is zero, the exported image will have the s

Source from the content-addressed store, hash-verified

14484 \see savePng, saveBmp, saveJpg, saveRastered
14485*/
14486bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle)
14487{
14488 bool success = false;
14489#ifdef QT_NO_PRINTER
14490 Q_UNUSED(fileName)
14491 Q_UNUSED(exportPen)
14492 Q_UNUSED(width)
14493 Q_UNUSED(height)
14494 Q_UNUSED(pdfCreator)
14495 Q_UNUSED(pdfTitle)
14496 qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created.";
14497#else
14498 int newWidth, newHeight;
14499 if (width == 0 || height == 0)
14500 {
14501 newWidth = this->width();
14502 newHeight = this->height();
14503 } else
14504 {
14505 newWidth = width;
14506 newHeight = height;
14507 }
14508
14509 QPrinter printer(QPrinter::ScreenResolution);
14510 printer.setOutputFileName(fileName);
14511 printer.setOutputFormat(QPrinter::PdfFormat);
14512 printer.setColorMode(QPrinter::Color);
14513 printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator);
14514 printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle);
14515 QRect oldViewport = viewport();
14516 setViewport(QRect(0, 0, newWidth, newHeight));
14517#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
14518 printer.setFullPage(true);
14519 printer.setPaperSize(viewport().size(), QPrinter::DevicePixel);
14520#else
14521 QPageLayout pageLayout;
14522 pageLayout.setMode(QPageLayout::FullPageMode);
14523 pageLayout.setOrientation(QPageLayout::Portrait);
14524 pageLayout.setMargins(QMarginsF(0, 0, 0, 0));
14525 pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch));
14526 printer.setPageLayout(pageLayout);
14527#endif
14528 QCPPainter printpainter;
14529 if (printpainter.begin(&printer))
14530 {
14531 printpainter.setMode(QCPPainter::pmVectorized);
14532 printpainter.setMode(QCPPainter::pmNoCaching);
14533 printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic);
14534 printpainter.setWindow(mViewport);
14535 if (mBackgroundBrush.style() != Qt::NoBrush &&
14536 mBackgroundBrush.color() != Qt::white &&
14537 mBackgroundBrush.color() != Qt::transparent &&
14538 mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent
14539 printpainter.fillRect(viewport(), mBackgroundBrush);
14540 draw(&printpainter);
14541 printpainter.end();
14542 success = true;
14543 }

Callers

nothing calls this directly

Calls 8

viewportFunction · 0.85
setModeMethod · 0.80
setMarginsMethod · 0.80
colorMethod · 0.80
alphaMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected