void QPpdPrintDevice::loadPageSizes() const { m_pageSizes.clear(); m_printableMargins.clear(); ppd_option_t *pageSizes = ppdFindOption(m_ppd, "PageSize"); if (pageSizes) { for (int i = 0; i < pageSizes->num_choices; ++i) { const ppd_size_t *ppdSize = ppdPageSize(m_ppd, pageSizes->choices[i].choice); if (ppdSize) { // Returned size is in points QString key = QString::fromUtf8(ppdSize->name); QSize size = QSize(qRound(ppdSize->width), qRound(ppdSize->length)); QString name = QString::fromUtf8(pageSizes->choices[i].text); if (!size.isEmpty()) { QPageSize ps = createPageSize(key, size, name); if (ps.isValid()) { m_pageSizes.append(ps); m_printableMargins.insert(key, QMarginsF(ppdSize->left, ppdSize->length - ppdSize->top, ppdSize->width - ppdSize->right, ppdSize->bottom)); } } } } m_havePageSizes = true; } }
QPageSize::PageSizeId KReportPageSize::defaultSize() { QPrinterInfo printerInfo = QPrinterInfo::defaultPrinter(); QPageSize size = printerInfo.defaultPageSize(); if (size.isValid()) { return size.id(); } return QPageSize::A4; }
void QPageLayout::setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins) { if (!pageSize.isValid()) return; d.detach(); d->m_pageSize = pageSize; d->m_fullSize = d->fullSizeUnits(d->m_units); d->setDefaultMargins(minMargins); }
QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) const { if (!pageSize.isValid()) return QPageSize(); if (!m_havePageSizes) loadPageSizes(); // First try match on name and id for case where printer defines same size twice with different names // e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both // map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid if (pageSize.id() != QPageSize::Custom) { foreach (const QPageSize &ps, m_pageSizes) { if (ps.id() == pageSize.id() && ps.name() == pageSize.name()) return ps; } }
void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) { Q_D(QPdfPrintEngine); switch (int(key)) { // The following keys are properties or derived values and so cannot be set case PPK_PageRect: break; case PPK_PaperRect: break; case PPK_PaperSources: break; case PPK_SupportsMultipleCopies: break; case PPK_SupportedResolutions: break; // The following keys are settings that are unsupported by the PDF PrintEngine case PPK_CustomBase: break; // The following keys are properties and settings that are supported by the PDF PrintEngine case PPK_CollateCopies: d->collate = value.toBool(); break; case PPK_ColorMode: d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale); break; case PPK_Creator: d->creator = value.toString(); break; case PPK_DocumentName: d->title = value.toString(); break; case PPK_FullPage: if (value.toBool()) d->m_pageLayout.setMode(QPageLayout::FullPageMode); else d->m_pageLayout.setMode(QPageLayout::StandardMode); break; case PPK_CopyCount: // fallthrough case PPK_NumberOfCopies: d->copies = value.toInt(); break; case PPK_Orientation: d->m_pageLayout.setOrientation(QPageLayout::Orientation(value.toInt())); break; case PPK_OutputFileName: d->outputFileName = value.toString(); break; case PPK_PageOrder: d->pageOrder = QPrinter::PageOrder(value.toInt()); break; case PPK_PageSize: { QPageSize pageSize = QPageSize(QPageSize::PageSizeId(value.toInt())); if (pageSize.isValid()) d->m_pageLayout.setPageSize(pageSize); break; } case PPK_PaperName: { QString name = value.toString(); for (int i = 0; i <= QPageSize::LastPageSize; ++i) { QPageSize pageSize = QPageSize(QPageSize::PageSizeId(i)); if (name == pageSize.name()) { d->m_pageLayout.setPageSize(pageSize); break; } } break; } case PPK_WindowsPageSize: d->m_pageLayout.setPageSize(QPageSize(QPageSize::id(value.toInt()))); break; case PPK_PaperSource: d->paperSource = QPrinter::PaperSource(value.toInt()); break; case PPK_PrinterName: d->printerName = value.toString(); break; case PPK_PrinterProgram: d->printProgram = value.toString(); break; case PPK_Resolution: d->resolution = value.toInt(); break; case PPK_SelectionOption: d->selectionOption = value.toString(); break; case PPK_FontEmbedding: d->embedFonts = value.toBool(); break; case PPK_Duplex: d->duplex = static_cast<QPrint::DuplexMode>(value.toInt()); break; case PPK_CustomPaperSize: d->m_pageLayout.setPageSize(QPageSize(value.toSizeF(), QPageSize::Point)); break; case PPK_PageMargins: { QList<QVariant> margins(value.toList()); Q_ASSERT(margins.size() == 4); d->m_pageLayout.setUnits(QPageLayout::Point); d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(), margins.at(2).toReal(), margins.at(3).toReal())); break; } case PPK_QPageSize: { QPageSize pageSize = value.value<QPageSize>(); if (pageSize.isValid()) d->m_pageLayout.setPageSize(pageSize); break; } case PPK_QPageMargins: { QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >(); d->m_pageLayout.setUnits(pair.second); d->m_pageLayout.setMargins(pair.first); break; } case PPK_QPageLayout: { QPageLayout pageLayout = value.value<QPageLayout>(); if (pageLayout.isValid()) d->m_pageLayout = pageLayout; break; } // No default so that compiler will complain if new keys added and not handled in this engine } }
bool QPageLayoutPrivate::isValid() const { return m_pageSize.isValid(); }