src/gui/painting/qprintengine_ps.cpp
changeset 23 89e065397ea6
parent 18 2f34d5167611
equal deleted inserted replaced
22:79de32ba3296 23:89e065397ea6
   483     if (creator.isEmpty())
   483     if (creator.isEmpty())
   484         creator = QLatin1String("Qt " QT_VERSION_STR);
   484         creator = QLatin1String("Qt " QT_VERSION_STR);
   485 
   485 
   486     QByteArray header;
   486     QByteArray header;
   487     QPdf::ByteStream s(&header);
   487     QPdf::ByteStream s(&header);
   488     s << "%!PS-Adobe-1.0";
       
   489 
   488 
   490     qreal scale = 72. / ((qreal) q->metric(QPaintDevice::PdmDpiY));
   489     qreal scale = 72. / ((qreal) q->metric(QPaintDevice::PdmDpiY));
   491     QRect pageRect = this->pageRect();
   490     QRect pageRect = this->pageRect();
   492     QRect paperRect = this->paperRect();
   491     QRect paperRect = this->paperRect();
   493     int mtop = pageRect.top() - paperRect.top();
   492     int mtop = pageRect.top() - paperRect.top();
   495     int mbottom = paperRect.bottom() - pageRect.bottom();
   494     int mbottom = paperRect.bottom() - pageRect.bottom();
   496     int mright = paperRect.right() - pageRect.right();
   495     int mright = paperRect.right() - pageRect.right();
   497     int width = pageRect.width();
   496     int width = pageRect.width();
   498     int height = pageRect.height();
   497     int height = pageRect.height();
   499     if (finished && pageCount == 1 && copies == 1 &&
   498     if (finished && pageCount == 1 && copies == 1 &&
   500         ((fullPage && qt_gen_epsf) || (outputFileName.endsWith(QLatin1String(".eps"))))
   499         ((fullPage && qt_gen_epsf) || (outputFileName.endsWith(QLatin1String(".eps")))))
   501        ) {
   500     {
       
   501         // According to the EPSF 3.0 spec it is required that the PS
       
   502         // version is PS-Adobe-3.0
       
   503         s << "%!PS-Adobe-3.0";
   502         if (!boundingBox.isValid())
   504         if (!boundingBox.isValid())
   503             boundingBox.setRect(0, 0, width, height);
   505             boundingBox.setRect(0, 0, width, height);
   504         if (orientation == QPrinter::Landscape) {
   506         if (orientation == QPrinter::Landscape) {
   505             if (!fullPage)
   507             if (!fullPage)
   506                 boundingBox.translate(-mleft, -mtop);
   508                 boundingBox.translate(-mleft, -mtop);
   507             s << " EPSF-3.0\n%%BoundingBox: "
   509             s << " EPSF-3.0\n%%BoundingBox: "
   508               << (int)(printer->height() - boundingBox.bottom())*scale // llx
   510               << int((printer->height() - boundingBox.bottom())*scale) // llx
   509               << (int)(printer->width() - boundingBox.right())*scale - 1 // lly
   511               << int((printer->width() - boundingBox.right())*scale - 1) // lly
   510               << (int)(printer->height() - boundingBox.top())*scale + 1 // urx
   512               << int((printer->height() - boundingBox.top())*scale + 1) // urx
   511               << (int)(printer->width() - boundingBox.left())*scale; // ury
   513               << int((printer->width() - boundingBox.left())*scale); // ury
   512         } else {
   514         } else {
   513             if (!fullPage)
   515             if (!fullPage)
   514                 boundingBox.translate(mleft, -mtop);
   516                 boundingBox.translate(mleft, -mtop);
   515             s << " EPSF-3.0\n%%BoundingBox: "
   517             s << " EPSF-3.0\n%%BoundingBox: "
   516               << (int)(boundingBox.left())*scale
   518               << int((boundingBox.left())*scale)
   517               << (int)(printer->height() - boundingBox.bottom())*scale - 1
   519               << int((printer->height() - boundingBox.bottom())*scale - 1)
   518               << (int)(boundingBox.right())*scale + 1
   520               << int((boundingBox.right())*scale + 1)
   519               << (int)(printer->height() - boundingBox.top())*scale;
   521               << int((printer->height() - boundingBox.top())*scale);
   520         }
   522         }
   521     } else {
   523     } else {
       
   524         s << "%!PS-Adobe-1.0";
   522         int w = width + (fullPage ? 0 : mleft + mright);
   525         int w = width + (fullPage ? 0 : mleft + mright);
   523         int h = height + (fullPage ? 0 : mtop + mbottom);
   526         int h = height + (fullPage ? 0 : mtop + mbottom);
   524         w = (int)(w*scale);
   527         w = (int)(w*scale);
   525         h = (int)(h*scale);
   528         h = (int)(h*scale);
   526         // set a bounding box according to the DSC
   529         // set a bounding box according to the DSC