QPSPrintEnginePrivate Class Reference

#include <qprintengine_ps_p.h>

Inheritance diagram for QPSPrintEnginePrivate:

Inheritance graph
[legend]
Collaboration diagram for QPSPrintEnginePrivate:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 84 of file qprintengine_ps_p.h.

Public Member Functions

 QPSPrintEnginePrivate (QPrinter::PrinterMode m)
 ~QPSPrintEnginePrivate ()
void emitHeader (bool finished)
void emitPages ()
void drawImage (qreal x, qreal y, qreal w, qreal h, const QImage &img, const QImage &mask)
void flushPage (bool last=false)

Public Attributes

int pageCount
bool epsf
QByteArray fontsUsed
QByteArray buffer
bool firstPage
QRect boundingBox
QPrinter::PrinterState printerState
bool hugeDocument
bool headerDone


Constructor & Destructor Documentation

QPSPrintEnginePrivate::QPSPrintEnginePrivate ( QPrinter::PrinterMode  m  ) 

Definition at line 154 of file qprintengine_ps.cpp.

References QSettings::beginGroup(), QPdfBaseEnginePrivate::embedFonts, firstPage, QPdfBaseEnginePrivate::postscript, QVariant::toBool(), QSettings::UserScope, and QSettings::value().

00155     : QPdfBaseEnginePrivate(m),
00156       printerState(QPrinter::Idle), hugeDocument(false), headerDone(false)
00157 {
00158     postscript = true;
00159 
00160     firstPage = true;
00161 
00162 #ifndef QT_NO_SETTINGS
00163     QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
00164     settings.beginGroup(QLatin1String("Qt"));
00165     embedFonts = settings.value(QLatin1String("embedFonts"), true).toBool();
00166 #else
00167     embedFonts = true;
00168 #endif
00169 }

Here is the call graph for this function:

QPSPrintEnginePrivate::~QPSPrintEnginePrivate (  ) 

Definition at line 171 of file qprintengine_ps.cpp.

00172 {
00173 }


Member Function Documentation

void QPSPrintEnginePrivate::emitHeader ( bool  finished  ) 

Definition at line 432 of file qprintengine_ps.cpp.

References QRect::bottom(), boundingBox, QPdfBaseEnginePrivate::collate, QPdfBaseEnginePrivate::copies, QPdfBaseEnginePrivate::creator, QDateTime::currentDateTime(), QString::endsWith(), QPdfBaseEnginePrivate::fullPage, h, header(), headerDone, height, QRect::height(), int, QString::isEmpty(), QRect::isValid(), QPrinter::Landscape, QRect::left(), QPdfBaseEngine::metric(), QPdfBaseEnginePrivate::orientation, QPdfBaseEnginePrivate::outDevice, QPdfBaseEnginePrivate::outputFileName, pageCount, QPdfBaseEnginePrivate::pageRect(), QPdfBaseEnginePrivate::paperRect(), QPdfBaseEnginePrivate::pdev, QPaintDevice::PdmDpiY, QPrinter::Portrait, ps_header, QPaintEnginePrivate::q_ptr, qt_gen_epsf, QT_VERSION_STR, QRect::right(), s, scale(), QRect::setRect(), QPdfBaseEnginePrivate::title, QRect::top(), QDateTime::toString(), QString::toUtf8(), QRect::translate(), w, QRect::width(), width, wrapDSC(), and QIODevice::write().

Referenced by flushPage().

00433 {
00434     QPSPrintEngine *q = static_cast<QPSPrintEngine *>(q_ptr);
00435     QPrinter *printer = static_cast<QPrinter*>(pdev);
00436 
00437     if (creator.isEmpty())
00438         creator = QLatin1String("Qt " QT_VERSION_STR);
00439 
00440     QByteArray header;
00441     QPdf::ByteStream s(&header);
00442     s << "%!PS-Adobe-1.0";
00443 
00444     qreal scale = 72. / ((qreal) q->metric(QPaintDevice::PdmDpiY));
00445     QRect pageRect = this->pageRect();
00446     QRect paperRect = this->paperRect();
00447     int mtop = pageRect.top() - paperRect.top();
00448     int mleft = pageRect.left() - paperRect.left();
00449     int mbottom = paperRect.bottom() - pageRect.bottom();
00450     int mright = paperRect.right() - pageRect.right();
00451     int width = pageRect.width();
00452     int height = pageRect.height();
00453     if (finished && pageCount == 1 && copies == 1 &&
00454         ((fullPage && qt_gen_epsf) || (outputFileName.endsWith(QLatin1String(".eps"))))
00455        ) {
00456         if (!boundingBox.isValid())
00457             boundingBox.setRect(0, 0, width, height);
00458         if (orientation == QPrinter::Landscape) {
00459             if (!fullPage)
00460                 boundingBox.translate(-mleft, -mtop);
00461             s << " EPSF-3.0\n%%BoundingBox: "
00462               << (int)(printer->height() - boundingBox.bottom())*scale // llx
00463               << (int)(printer->width() - boundingBox.right())*scale - 1 // lly
00464               << (int)(printer->height() - boundingBox.top())*scale + 1 // urx
00465               << (int)(printer->width() - boundingBox.left())*scale; // ury
00466         } else {
00467             if (!fullPage)
00468                 boundingBox.translate(mleft, -mtop);
00469             s << " EPSF-3.0\n%%BoundingBox: "
00470               << (int)(boundingBox.left())*scale
00471               << (int)(printer->height() - boundingBox.bottom())*scale - 1
00472               << (int)(boundingBox.right())*scale + 1
00473               << (int)(printer->height() - boundingBox.top())*scale;
00474         }
00475     } else {
00476         int w = width + (fullPage ? 0 : mleft + mright);
00477         int h = height + (fullPage ? 0 : mtop + mbottom);
00478         w = (int)(w*scale);
00479         h = (int)(h*scale);
00480         // set a bounding box according to the DSC
00481         if (orientation == QPrinter::Landscape)
00482             s << "\n%%BoundingBox: 0 0 " << h << w;
00483         else
00484             s << "\n%%BoundingBox: 0 0 " << w << h;
00485     }
00486     s << "\n" << wrapDSC("%%Creator: " + creator.toUtf8());
00487     if (!title.isEmpty())
00488         s << wrapDSC("%%Title: " + title.toUtf8());
00489 #ifndef QT_NO_DATESTRING
00490     s << "%%CreationDate: " << QDateTime::currentDateTime().toString().toUtf8();
00491 #endif
00492     s << "\n%%Orientation: ";
00493     if (orientation == QPrinter::Landscape)
00494         s << "Landscape";
00495     else
00496         s << "Portrait";
00497 
00498     s << "\n%%Pages: (atend)"
00499         "\n%%DocumentFonts: (atend)"
00500         "\n%%EndComments\n"
00501 
00502         "%%BeginProlog\n"
00503         "% Prolog copyright 1994-2006 Trolltech. You may copy this prolog in any way\n"
00504         "% that is directly related to this document. For other use of this prolog,\n"
00505         "% see your licensing agreement for Qt.\n"
00506       << ps_header << "\n";
00507 
00508 
00509     s << "/pageinit {\n";
00510     if (!fullPage) {
00511         if (orientation == QPrinter::Portrait)
00512             s << mleft*scale << mbottom*scale << "translate\n";
00513         else
00514             s << mtop*scale << mleft*scale << "translate\n";
00515     }
00516     if (orientation == QPrinter::Portrait) {
00517         s << "% " << printer->widthMM() << "*" << printer->heightMM()
00518           << "mm (portrait)\n0 " << height*scale
00519           << "translate " << scale << "-" << scale << "scale } def\n";
00520     } else {
00521         s << "% " << printer->heightMM() << "*" << printer->widthMM()
00522           << " mm (landscape)\n 90 rotate " << scale << "-" << scale << "scale } def\n";
00523     }
00524     s << "%%EndProlog\n";
00525 
00526 
00527     s << "%%BeginSetup\n";
00528     if (copies > 1) {
00529         s << "/#copies " << copies << " def\n";
00530         s << "/NumCopies " << copies << " SPD\n";
00531         s << "/Collate " << (collate ? "true" : "false") << " SPD\n";
00532     }
00533     s << "%%EndSetup\n";
00534 
00535     outDevice->write(header);
00536     headerDone = true;
00537 }

Here is the call graph for this function:

void QPSPrintEnginePrivate::emitPages (  ) 

Definition at line 540 of file qprintengine_ps.cpp.

References buffer, QHash< Key, T >::constBegin(), QHash< Key, T >::constEnd(), QPdfBaseEnginePrivate::fonts, hugeDocument, QPdfBaseEnginePrivate::outDevice, and QIODevice::write().

Referenced by flushPage().

00541 {
00542     if (!hugeDocument) {
00543         for (QHash<QFontEngine::FaceId, QFontSubset *>::const_iterator it = fonts.constBegin();
00544              it != fonts.constEnd(); ++it)
00545             outDevice->write((*it)->toType1());
00546     }
00547 
00548     outDevice->write(buffer);
00549 
00550     buffer = QByteArray();
00551     hugeDocument = true;
00552 }

Here is the call graph for this function:

void QPSPrintEnginePrivate::drawImage ( qreal  x,
qreal  y,
qreal  w,
qreal  h,
const QImage img,
const QImage mask 
)

Definition at line 365 of file qprintengine_ps.cpp.

References QImage::allGray(), QPdfBaseEnginePrivate::colorMode, compress(), QImage::copy(), QPdfBaseEnginePrivate::currentPage, QImage::depth(), filters, Qt::gray, QPrinter::GrayScale, QImage::height(), height, QImage::isNull(), mask, ps_r7(), qMin(), QByteArray::size(), size, QImage::width(), and width.

00367 {
00368     if (!w || !h || img.isNull()) return;
00369 
00370     int width  = img.width();
00371     int height = img.height();
00372     qreal scaleX = width/w;
00373     qreal scaleY = height/h;
00374 
00375     bool gray = (colorMode == QPrinter::GrayScale) ||
00376                 img.allGray();
00377     int splitSize = 21830 * (gray ? 3 : 1);
00378     if (width * height > splitSize) { // 65535/3, tolerance for broken printers
00379         int images, subheight;
00380         images = (width * height + splitSize - 1) / splitSize;
00381         subheight = (height + images-1) / images;
00382         while (subheight * width > splitSize) {
00383             images++;
00384             subheight = (height + images-1) / images;
00385         }
00386         int suby = 0;
00387         while(suby < height) {
00388             drawImage(x, y + suby/scaleY, w, qMin(subheight, height-suby)/scaleY,
00389                       img.copy(0, suby, width, qMin(subheight, height-suby)),
00390                       mask.isNull() ? mask : mask.copy(0, suby, width, qMin(subheight, height-suby)));
00391             suby += subheight;
00392         }
00393     } else {
00394         QByteArray out;
00395         int size = 0;
00396         const char *bits;
00397 
00398         if (!mask.isNull()) {
00399             int format;
00400             out = ::compress(mask, true, &format);
00401             size = (width+7)/8*height;
00402             *currentPage << "/mask currentfile/ASCII85Decode filter"
00403                          << filters[format]
00404                          << size << " string readstring\n";
00405             ps_r7(*currentPage, out, out.size());
00406             *currentPage << " pop def\n";
00407         }
00408         if (img.depth() == 1) {
00409             size = (width+7)/8*height;
00410             bits = "1 ";
00411         } else if (gray) {
00412             size = width*height;
00413             bits = "8 ";
00414         } else {
00415             size = width*height*3;
00416             bits = "24 ";
00417         }
00418 
00419         int format;
00420         out = ::compress(img, gray, &format);
00421         *currentPage << "/sl currentfile/ASCII85Decode filter"
00422                      << filters[format]
00423                      << size << " string readstring\n";
00424         ps_r7(*currentPage, out, out.size());
00425         *currentPage << " pop def\n";
00426         *currentPage << width << ' ' << height << "[" << scaleX << " 0 0 " << scaleY << " 0 0]sl "
00427                     << bits << (!mask.isNull() ? "mask " : "false ")
00428                     << x << ' ' << y << " di\n";
00429     }
00430 }

Here is the call graph for this function:

void QPSPrintEnginePrivate::flushPage ( bool  last = false  ) 

Definition at line 561 of file qprintengine_ps.cpp.

References QVector< T >::at(), buffer, QHash< Key, T >::constBegin(), QHash< Key, T >::constEnd(), QVector< T >::contains(), QPdfPage::content(), QPdfBaseEnginePrivate::currentPage, emitHeader(), emitPages(), QPdfPage::fonts, QPdfBaseEnginePrivate::fonts, headerDone, hugeDocument, i, QByteArray::isEmpty(), max_in_memory_size, QByteArray::number(), pageCount, s, and QVector< T >::size().

00562 {
00563     if (!last && currentPage->content().isEmpty())
00564         return;
00565 
00566     QPdf::ByteStream s(&buffer);
00567     s << "%%Page: "
00568       << pageCount << pageCount << "\n"
00569       << "%%BeginPageSetup\n"
00570       << "QI\n";
00571     if (hugeDocument) {
00572         for (QHash<QFontEngine::FaceId, QFontSubset *>::const_iterator it = fonts.constBegin();
00573              it != fonts.constEnd(); ++it) {
00574             if (currentPage->fonts.contains((*it)->object_id)) {
00575                 if ((*it)->downloaded_glyphs == 0) {
00576                     s << (*it)->toType1();
00577                     (*it)->downloaded_glyphs = 0;
00578                 } else {
00579                     s << (*it)->type1AddedGlyphs();
00580                 }
00581             }
00582         }
00583     }
00584     for (int i = 0; i < currentPage->fonts.size(); ++i)
00585         s << "(F" << QByteArray::number(currentPage->fonts.at(i)) << ") T1Setup\n";
00586 
00587     s << "%%EndPageSetup\nq\n"
00588       << currentPage->content()
00589       << "\nQ QP\n";
00590     if (last || hugeDocument || buffer.size() > max_in_memory_size) {
00591 //        qDebug("emiting header at page %d", pageCount);
00592         if (!headerDone)
00593             emitHeader(last);
00594         emitPages();
00595     }
00596     pageCount++;
00597 }

Here is the call graph for this function:


Member Data Documentation

int QPSPrintEnginePrivate::pageCount

Definition at line 94 of file qprintengine_ps_p.h.

Referenced by emitHeader(), and flushPage().

bool QPSPrintEnginePrivate::epsf

Definition at line 95 of file qprintengine_ps_p.h.

QByteArray QPSPrintEnginePrivate::fontsUsed

Definition at line 96 of file qprintengine_ps_p.h.

QByteArray QPSPrintEnginePrivate::buffer

Definition at line 99 of file qprintengine_ps_p.h.

Referenced by emitPages(), and flushPage().

bool QPSPrintEnginePrivate::firstPage

Definition at line 101 of file qprintengine_ps_p.h.

Referenced by QPSPrintEnginePrivate().

QRect QPSPrintEnginePrivate::boundingBox

Definition at line 103 of file qprintengine_ps_p.h.

Referenced by emitHeader().

QPrinter::PrinterState QPSPrintEnginePrivate::printerState

Definition at line 105 of file qprintengine_ps_p.h.

bool QPSPrintEnginePrivate::hugeDocument

Definition at line 106 of file qprintengine_ps_p.h.

Referenced by emitPages(), and flushPage().

bool QPSPrintEnginePrivate::headerDone

Definition at line 107 of file qprintengine_ps_p.h.

Referenced by emitHeader(), and flushPage().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:45:41 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1