#include "qplatformdefs.h"
#include <private/qprintengine_ps_p.h>
#include <private/qpainter_p.h>
#include <private/qfontengine_p.h>
#include <private/qpaintengine_p.h>
#include <private/qpdf_p.h>
#include "qprinter.h"
#include "qpainter.h"
#include "qapplication.h"
#include "qpixmap.h"
#include "qimage.h"
#include "qdatetime.h"
#include "qstring.h"
#include "qbytearray.h"
#include "qhash.h"
#include "qbuffer.h"
#include "qsettings.h"
#include "qmap.h"
#include "qbitmap.h"
#include "qregion.h"
#include "qimagewriter.h"
#include <private/qunicodetables_p.h>
#include <private/qpainterpath_p.h>
#include <qdebug.h>
#include <private/qdrawhelper_p.h>
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include <QDebug>
Include dependency graph for qprintengine_ps.cpp:

Go to the source code of this file.
Enumerations | |
| enum | format |
Functions | |
| void | qt_generate_epsf (bool b) |
| static QByteArray | wrapDSC (const QByteArray &str) |
| static void | ps_r7 (QPdf::ByteStream &stream, const char *s, int l) |
| static QByteArray | runlengthEncode (const QByteArray &input) |
| static QByteArray | compress (const QImage &img, bool gray, int *format) |
| static void | ignoreSigPipe (bool b) |
Variables | |
| static bool | qt_gen_epsf = false |
| static const char *const | ps_header |
| static const char *const | filters [3] |
| static const int | max_in_memory_size = 32000000 |
| enum format |
| static QByteArray compress | ( | const QImage & | img, | |
| bool | gray, | |||
| int * | format | |||
| ) | [static] |
Definition at line 274 of file qprintengine_ps.cpp.
References QPdf::ascii85Encode(), b, buffer, QByteArray::data(), DCT, QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_MonoLSB, height, i, image, QColor::qBlue(), QColor::qGray(), QColor::qGreen(), QColor::qRed(), QColor::QRgb(), Raw, QByteArray::resize(), rgb, Runlength, runlengthEncode(), s, QImageWriter::setQuality(), size, QImageWriter::supportedImageFormats(), width, QImageWriter::write(), x, x80, and y.
Referenced by QPSPrintEnginePrivate::drawImage(), and QPdfEnginePrivate::writeCompressed().
00275 { 00276 // we can't use premultiplied here 00277 QImage image = img; 00278 00279 if (image.format() == QImage::Format_ARGB32_Premultiplied) 00280 image = image.convertToFormat(QImage::Format_ARGB32); 00281 00282 QByteArray pixelData; 00283 int depth = image.depth(); 00284 00285 if (depth != 1 && !gray && QImageWriter::supportedImageFormats().contains("jpeg")) { 00286 QBuffer buffer(&pixelData); 00287 QImageWriter writer(&buffer, "jpeg"); 00288 writer.setQuality(94); 00289 writer.write(img); 00290 *format = DCT; 00291 } else { 00292 int width = image.width(); 00293 int height = image.height(); 00294 int size = width*height; 00295 00296 if (depth == 1) 00297 size = (width+7)/8*height; 00298 else if (!gray) 00299 size = size*3; 00300 00301 pixelData.resize(size); 00302 uchar *pixel = (uchar *)pixelData.data(); 00303 int i = 0; 00304 if (depth == 1) { 00305 QImage::Format format = image.format(); 00306 memset(pixel, 0xff, size); 00307 for(int y=0; y < height; y++) { 00308 const uchar * s = image.scanLine(y); 00309 for(int x=0; x < width; x++) { 00310 // need to copy bit for bit... 00311 bool b = (format == QImage::Format_MonoLSB) ? 00312 (*(s + (x >> 3)) >> (x & 7)) & 1 : 00313 (*(s + (x >> 3)) << (x & 7)) & 0x80 ; 00314 if (b) 00315 pixel[i >> 3] ^= (0x80 >> (i & 7)); 00316 i++; 00317 } 00318 // we need to align to 8 bit here 00319 i = (i+7) & 0xffffff8; 00320 } 00321 } else if (depth == 8) { 00322 for(int y=0; y < height; y++) { 00323 const uchar * s = image.scanLine(y); 00324 for(int x=0; x < width; x++) { 00325 QRgb rgb = image.color(s[x]); 00326 if (gray) { 00327 pixel[i] = (unsigned char) qGray(rgb); 00328 i++; 00329 } else { 00330 pixel[i] = (unsigned char) qRed(rgb); 00331 pixel[i+1] = (unsigned char) qGreen(rgb); 00332 pixel[i+2] = (unsigned char) qBlue(rgb); 00333 i += 3; 00334 } 00335 } 00336 } 00337 } else { 00338 for(int y=0; y < height; y++) { 00339 QRgb * s = (QRgb*)(image.scanLine(y)); 00340 for(int x=0; x < width; x++) { 00341 QRgb rgb = (*s++); 00342 if (gray) { 00343 pixel[i] = (unsigned char) qGray(rgb); 00344 i++; 00345 } else { 00346 pixel[i] = (unsigned char) qRed(rgb); 00347 pixel[i+1] = (unsigned char) qGreen(rgb); 00348 pixel[i+2] = (unsigned char) qBlue(rgb); 00349 i += 3; 00350 } 00351 } 00352 } 00353 } 00354 *format = Raw; 00355 if (depth == 1) { 00356 pixelData = runlengthEncode(pixelData); 00357 *format = Runlength; 00358 } 00359 } 00360 QByteArray outarr = QPdf::ascii85Encode(pixelData); 00361 return outarr; 00362 }
Here is the call graph for this function:

| static void ignoreSigPipe | ( | bool | b | ) | [static] |
Definition at line 612 of file qprintengine_ps.cpp.
References qWarning().
Referenced by QPSPrintEngine::end(), and QPSPrintEngine::newPage().
00613 { 00614 #ifndef QT_NO_LPR 00615 static struct sigaction *users_sigpipe_handler = 0; 00616 00617 if (b) { 00618 if (users_sigpipe_handler != 0) 00619 return; // already ignoring sigpipe 00620 00621 users_sigpipe_handler = new struct sigaction; 00622 struct sigaction tmp_sigpipe_handler; 00623 tmp_sigpipe_handler.sa_handler = SIG_IGN; 00624 sigemptyset(&tmp_sigpipe_handler.sa_mask); 00625 tmp_sigpipe_handler.sa_flags = 0; 00626 00627 if (sigaction(SIGPIPE, &tmp_sigpipe_handler, users_sigpipe_handler) == -1) { 00628 delete users_sigpipe_handler; 00629 users_sigpipe_handler = 0; 00630 } 00631 } 00632 else { 00633 if (users_sigpipe_handler == 0) 00634 return; // not ignoring sigpipe 00635 00636 if (sigaction(SIGPIPE, users_sigpipe_handler, 0) == -1) 00637 qWarning("QPSPrintEngine: Could not restore SIGPIPE handler"); 00638 00639 delete users_sigpipe_handler; 00640 users_sigpipe_handler = 0; 00641 } 00642 #else 00643 Q_UNUSED(b); 00644 #endif 00645 }
Here is the call graph for this function:

| static void ps_r7 | ( | QPdf::ByteStream & | stream, | |
| const char * | s, | |||
| int | l | |||
| ) | [static] |
Definition at line 177 of file qprintengine_ps.cpp.
References i, and QTest::stream.
Referenced by QPSPrintEnginePrivate::drawImage().
00178 { 00179 int i = 0; 00180 uchar line[84]; 00181 int col = 0; 00182 00183 while(i < l) { 00184 line[col++] = s[i++]; 00185 if (i < l - 1 && col >= 76) { 00186 line[col++] = '\n'; 00187 line[col++] = '\0'; 00188 stream << (const char *)line; 00189 col = 0; 00190 } 00191 } 00192 if (col > 0) { 00193 while((col&3) != 0) 00194 line[col++] = '%'; // use a comment as padding 00195 line[col++] = '\n'; 00196 line[col++] = '\0'; 00197 stream << (const char *)line; 00198 } 00199 }
| void qt_generate_epsf | ( | bool | b | ) |
Definition at line 62 of file qprintengine_ps.cpp.
References qt_gen_epsf.
00063 { 00064 qt_gen_epsf = b; 00065 }
| static QByteArray runlengthEncode | ( | const QByteArray & | input | ) | [static] |
Definition at line 201 of file qprintengine_ps.cpp.
References QByteArray::append(), QByteArray::constData(), data, QTextStream::flush(), i, QByteArray::length(), QByteArray::size(), size, and start.
Referenced by compress().
00202 { 00203 if (!input.length()) 00204 return input; 00205 00206 const char *data = input.constData(); 00207 00208 QByteArray out; 00209 int start = 0; 00210 char last = *data; 00211 00212 enum State { 00213 Undef, 00214 Equal, 00215 Diff 00216 }; 00217 State state = Undef; 00218 00219 int i = 1; 00220 int written = 0; 00221 while (1) { 00222 bool flush = (i == input.size()); 00223 if (!flush) { 00224 switch(state) { 00225 case Undef: 00226 state = (last == data[i]) ? Equal : Diff; 00227 break; 00228 case Equal: 00229 if (data[i] != last) 00230 flush = true; 00231 break; 00232 case Diff: 00233 if (data[i] == last) { 00234 --i; 00235 flush = true; 00236 } 00237 } 00238 } 00239 if (flush || i - start == 128) { 00240 int size = i - start; 00241 if (state == Equal) { 00242 out.append((char)(uchar)(257-size)); 00243 out.append(last); 00244 written += size; 00245 } else { 00246 out.append((char)(uchar)size-1); 00247 while (start < i) 00248 out.append(data[start++]); 00249 written += size; 00250 } 00251 state = Undef; 00252 start = i; 00253 if (i == input.size()) 00254 break; 00255 } 00256 last = data[i]; 00257 ++i; 00258 }; 00259 out.append((char)(uchar)128); 00260 return out; 00261 }
Here is the call graph for this function:

| static QByteArray wrapDSC | ( | const QByteArray & | str | ) | [static] |
Definition at line 133 of file qprintengine_ps.cpp.
References QByteArray::left(), QByteArray::length(), QByteArray::mid(), and QByteArray::simplified().
Referenced by QPSPrintEnginePrivate::emitHeader(), and QPSPrintEngine::end().
00134 { 00135 QByteArray dsc = str.simplified(); 00136 const int wrapAt = 254; 00137 QByteArray wrapped; 00138 if (dsc.length() < wrapAt) 00139 wrapped = dsc; 00140 else { 00141 wrapped = dsc.left(wrapAt); 00142 QByteArray tmp = dsc.mid(wrapAt); 00143 while (tmp.length() > wrapAt-3) { 00144 wrapped += "\n%%+" + tmp.left(wrapAt-3); 00145 tmp = tmp.mid(wrapAt-3); 00146 } 00147 wrapped += "\n%%+" + tmp; 00148 } 00149 return wrapped + "\n"; 00150 }
Here is the call graph for this function:

const char* const filters[3] [static] |
Initial value:
{
" ",
"/RunLengthDecode filter ",
"/DCTDecode filter "
}
Definition at line 268 of file qprintengine_ps.cpp.
const int max_in_memory_size = 32000000 [static] |
Definition at line 558 of file qprintengine_ps.cpp.
Referenced by QPSPrintEnginePrivate::flushPage().
const char* const ps_header [static] |
Definition at line 67 of file qprintengine_ps.cpp.
Referenced by QPSPrintEnginePrivate::emitHeader().
bool qt_gen_epsf = false [static] |
Definition at line 60 of file qprintengine_ps.cpp.
Referenced by QPSPrintEnginePrivate::emitHeader(), and qt_generate_epsf().
1.5.1