bool QtopiaPrintEngine::begin(QPaintDevice *) { Q_D(QtopiaPrintEngine); Q_ASSERT_X(d->printerState == QPrinter::Idle, "QtopiaPrintEngine", "printer already active"); // Create a new off-screen monochrome image to handle the drawing process. QSize size = paperRect().size(); if ( d->pageImage ) delete d->pageImage; d->pageImage = new QImage( size, QImage::Format_RGB32 ); if ( !(d->pageImage) ) return false; // Recreate the paint engine on the new image. delete d->_paintEngine; d->_paintEngine = 0; d->paintEngine()->state = state; // Begin the paint process on the image. if (!d->paintEngine()->begin(d->pageImage)) return false; // Clear the first page to all-white. clearPage(); // Clear the print buffer and output the image header. d->buffer.clear(); d->writeG3FaxHeader(); // The print engine is currently active. d->printerState = QPrinter::Active; return true; }
QRect QtopiaPrintEngine::pageRect() const { QRect r = paperRect(); if (d_func()->fullPage) return r; // would be nice to get better margins than this. return QRect(d_func()->resolution/3, d_func()->resolution/3, r.width()-2*d_func()->resolution/3, r.height()-2*d_func()->resolution/3); }
QRectF TextPrinter::footerRect(QPaintDevice *device) { QRectF rect = paperRect(device); rect.adjust(mmToInches(leftmargin_) * device->logicalDpiX(), 0, -mmToInches(rightmargin_) * device->logicalDpiX(), -mmToInches(bottommargin_) * device->logicalDpiY()); rect.setTop(rect.bottom() - mmToInches(footersize_) * device->logicalDpiY()); return rect; };
BMessage* PrinterDriver::GetDefaultSettings() { BMessage* msg = new BMessage(); BRect paperRect(0, 0, letter_width, letter_height); BRect printableRect(paperRect); printableRect.InsetBy(10, 10); msg->AddRect("paper_rect", paperRect); msg->AddRect("printable_rect", printableRect); msg->AddInt32("orientation", 0); msg->AddInt32("xres", 300); msg->AddInt32("yres", 300); return msg; }
QRectF TextPrinter::headerRect(QPaintDevice *device) { QRectF rect = paperRect(device); rect.adjust(mmToInches(leftmargin_) * device->logicalDpiX(), mmToInches(topmargin_) * device->logicalDpiY(), -mmToInches(rightmargin_) * device->logicalDpiX(), 0); (headerrule_ / 144.0); rect.setBottom(rect.top() + mmToInches(headersize_) * device->logicalDpiY()); return rect; };
int QtopiaPrintEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const { int val; QRect r = d_func()->fullPage ? paperRect() : pageRect(); switch (metricType) { case QPaintDevice::PdmWidth: val = r.width(); break; case QPaintDevice::PdmHeight: val = r.height(); break; case QPaintDevice::PdmDpiX: val = d_func()->resolution; break; case QPaintDevice::PdmDpiY: val = d_func()->resolution; break; case QPaintDevice::PdmPhysicalDpiX: case QPaintDevice::PdmPhysicalDpiY: val = QT_QWS_PRINTER_DEFAULT_DPI; break; case QPaintDevice::PdmWidthMM: val = qRound(r.width()*25.4/d_func()->resolution); break; case QPaintDevice::PdmHeightMM: val = qRound(r.height()*25.4/d_func()->resolution); break; case QPaintDevice::PdmNumColors: val = 2; break; case QPaintDevice::PdmDepth: val = 1; break; default: qWarning("QtopiaPrintEngine::metric: Invalid metric command"); return 0; } return val; }
QRectF TextPrinter::contentRect(QPaintDevice *device) { // calculate size of content (paper - margins) QRectF rect = paperRect(device); rect.adjust(mmToInches(leftmargin_) * device->logicalDpiX(), mmToInches(topmargin_) * device->logicalDpiY(), -mmToInches(rightmargin_) * device->logicalDpiX(), -mmToInches(bottommargin_) * device->logicalDpiY()); // header if (headersize_ > 0) { rect.adjust(0, mmToInches(headersize_) * device->logicalDpiY(), 0, 0); rect.adjust(0, mmToInches(spacing_) * device->logicalDpiY(), 0, 0); } // footer if (footersize_ > 0) { rect.adjust(0, 0, 0, -mmToInches(footersize_) * device->logicalDpiY()); rect.adjust(0, 0, 0, -mmToInches(spacing_) * device->logicalDpiY()); } return rect; }
QVariant QtopiaPrintEngine::property(PrintEnginePropertyKey key) const { Q_D(const QtopiaPrintEngine); QVariant ret; switch (key) { case PPK_CollateCopies: ret = d->collateCopies; break; case PPK_ColorMode: ret = d->colorMode; break; case PPK_Creator: ret = d->creator; break; case PPK_DocumentName: ret = d->docName; break; case PPK_FullPage: ret = d->fullPage; break; case PPK_CopyCount: // fallthrough case PPK_NumberOfCopies: ret = d->numCopies; break; case PPK_SupportsMultipleCopies: ret = false; break; case PPK_Orientation: ret = d->orientation; break; case PPK_OutputFileName: ret = d->outputFileName; break; case PPK_PageOrder: ret = d->pageOrder; break; case PPK_PageRect: ret = pageRect(); break; case PPK_PaperSize: ret = d->paperSize; break; case PPK_PaperRect: ret = paperRect(); break; case PPK_PaperSource: ret = d->paperSource; break; case PPK_PrinterName: ret = d->printerName; break; case PPK_PrinterProgram: ret = d->printProgram; break; case PPK_Resolution: ret = d->resolution; break; case PPK_SupportedResolutions: ret = QList<QVariant>() << QT_QWS_PRINTER_DEFAULT_DPI; break; default: break; } return ret; }