42 #include <private/qprintengine_qws_p.h> 46 #include <private/qpaintengine_raster_p.h> 50 #include <QCopChannel> 54 #define MM(n) int((n * 720 + 127) / 254) 55 #define IN(n) int(n * 72) 62 d_func()->initialize();
75 if ( !(
d->pageImage) )
79 delete d->_paintEngine;
81 d->paintEngine()->state =
state;
84 if (!
d->paintEngine()->begin(
d->pageImage))
92 d->writeG3FaxHeader();
103 d->paintEngine()->end();
110 if ( !
d->outputFileName.isEmpty() )
116 QFile file( filename );
118 qDebug(
"Failed to open %s for printer output",
121 file.
write(
d->buffer.data() );
154 d->paintEngine()->drawPixmap(r, pm, sr);
161 d->paintEngine()->drawTextItem(p, ti);
167 d->paintEngine()->updateState(state);
175 int w =
qRound(s.
width()*d_func()->resolution/72.);
178 return QRect(0, 0, w, h);
180 return QRect(0, 0, h, w);
186 if (d_func()->fullPage)
189 return QRect(d_func()->resolution/3, d_func()->resolution/3, r.
width()-2*d_func()->resolution/3, r.
height()-2*d_func()->resolution/3);
196 ++(d_func()->pageNumber);
207 return d_func()->printerState;
214 switch (metricType) {
222 val = d_func()->resolution;
225 val = d_func()->resolution;
244 qWarning(
"QtopiaPrintEngine::metric: Invalid metric command");
257 ret =
d->collateCopies;
279 ret =
d->orientation;
282 ret =
d->outputFileName;
297 ret =
d->paperSource;
300 ret =
d->printerName;
303 ret =
d->printProgram;
322 d->collateCopies = value.
toBool();
338 d->numCopies = value.
toInt();
361 d->resolution = value.
toInt();
370 d_func()->pageImage->fill(
QColor(255, 255, 255).
rgb());
375 d_func()->writeG3FaxPage();
399 buffer.append( (
char)
'I' );
400 buffer.append( (
char)
'I' );
401 buffer.append( (
char)42 );
402 buffer.append( (
char)0 );
405 ifdPatch = buffer.size();
406 buffer.append( (
int)0 );
410 #define TIFF_IFD_NEW_SUB_FILE_TYPE 254 411 #define TIFF_IFD_IMAGE_WIDTH 256 412 #define TIFF_IFD_IMAGE_LENGTH 257 413 #define TIFF_IFD_BITS_PER_SAMPLE 258 414 #define TIFF_IFD_COMPRESSION 259 415 #define TIFF_IFD_PHOTOMETRIC_INTERP 262 416 #define TIFF_IFD_FILL_ORDER 266 417 #define TIFF_IFD_STRIP_OFFSETS 273 418 #define TIFF_IFD_ORIENTATION 274 419 #define TIFF_IFD_SAMPLES_PER_PIXEL 277 420 #define TIFF_IFD_ROWS_PER_STRIP 278 421 #define TIFF_IFD_STRIP_BYTE_COUNTS 279 422 #define TIFF_IFD_X_RESOLUTION 282 423 #define TIFF_IFD_Y_RESOLUTION 283 424 #define TIFF_IFD_PLANAR_CONFIG 284 425 #define TIFF_IFD_T4_OPTIONS 292 426 #define TIFF_IFD_RESOLUTION_UNIT 296 427 #define TIFF_IFD_PAGE_NUMBER 297 428 #define TIFF_IFD_CLEAN_FAX_DATA 327 431 #define TIFF_TYPE_SHORT 3 432 #define TIFF_TYPE_LONG 4 433 #define TIFF_TYPE_RATIONAL 5 436 #define TIFF_SHORT_PAIR(a,b) (((a) & 0xFFFF) | ((b) << 16)) 441 #define TIFF_FAX_WIDTH 1728 449 buffer.patch( ifdPatch, buffer.size() );
453 buffer.append( (
short)19 );
468 int stripBytes = writeG3IFDEntry
482 ifdPatch = buffer.size();
483 buffer.append( (
int)0 );
486 buffer.patch( xres, buffer.size() );
487 buffer.append( (
int)resolution );
488 buffer.append( (
int)1 );
489 buffer.patch( yres, buffer.size() );
490 buffer.append( (
int)resolution );
491 buffer.append( (
int)1 );
494 int start = buffer.size();
495 buffer.patch( stripOffsets, start );
498 int width = pageImage->width();
500 for (
int y = 0; y < pageImage->height(); ++y ) {
501 unsigned char *scan = pageImage->scanLine(y);
502 int prev, pixel, len;
507 uint currentColor =
qRgb(255, 255, 255);
514 if ( *p == currentColor ) {
518 if ( currentColor ==
qRgb(0, 0, 0) )
519 writeG3BlackRun( len );
521 writeG3WhiteRun( len );
528 pixel = ((scan[x >> 3] & (1 << (x & 7))) != 0);
529 if ( pixel != prev ) {
531 writeG3BlackRun( len );
533 writeG3WhiteRun( len );
546 if ( currentColor ==
qRgb(0, 0, 0) )
547 writeG3BlackRun( len );
549 writeG3WhiteRun( len );
551 if ( width < TIFF_FAX_WIDTH )
552 writeG3WhiteRun( TIFF_FAX_WIDTH - width );
556 writeG3BlackRun( len );
557 if ( width < TIFF_FAX_WIDTH ) {
558 writeG3WhiteRun( TIFF_FAX_WIDTH - width );
561 if ( width < TIFF_FAX_WIDTH ) {
562 writeG3WhiteRun( len + ( TIFF_FAX_WIDTH - width ) );
564 writeG3WhiteRun( len );
572 if ( partialBits > 0 ) {
573 buffer.append( (
char)( partialByte << ( 8 - partialBits ) ) );
579 for (
int i = 0; i < 6; i++ )
583 buffer.patch( stripBytes, buffer.size() - start );
587 (
int tag,
int type,
int count,
int value )
589 buffer.append( (
short)tag );
590 buffer.append( (
short)type );
591 buffer.append( count );
592 buffer.append( value );
593 return buffer.size() - 4;
598 partialByte = ( ( partialByte << bits ) | code );
600 while ( partialBits >= 8 ) {
602 buffer.append( (
char)( partialByte >> partialBits ) );
611 } whiteCodes[64 + 27] = {
705 int index = 63 + (len >> 6);
706 writeG3Code( whiteCodes[index].code, whiteCodes[index].bits );
709 writeG3Code( whiteCodes[len].code, whiteCodes[len].bits );
717 } blackCodes[64 + 27] = {
811 int index = 63 + (len >> 6);
812 writeG3Code( blackCodes[index].code, blackCodes[index].bits );
815 writeG3Code( blackCodes[len].code, blackCodes[len].bits );
821 if ( partialBits <= 4 ) {
822 bitToPad = 4 - partialBits;
824 bitToPad = 8 - partialBits + 4;
827 partialByte = ((partialByte << (bitToPad + 12)) | 0x0001);
828 partialBits += bitToPad + 12;
830 while ( partialBits >= 8 ) {
832 buffer.append( (
char)(partialByte >> partialBits ) );
840 _data.append( (
char)(value >> 8) );
841 _data.append( (
char)value );
843 _data.append( (
char)value );
844 _data.append( (
char)(value >> 8) );
851 _data.append( (
char)(value >> 24) );
852 _data.append( (
char)(value >> 16) );
853 _data.append( (
char)(value >> 8) );
854 _data.append( (
char)value );
856 _data.append( (
char)value );
857 _data.append( (
char)(value >> 8) );
858 _data.append( (
char)(value >> 16) );
859 _data.append( (
char)(value >> 24) );
866 _data[posn] = (char)(value >> 24);
867 _data[posn + 1] = (char)(value >> 16);
868 _data[posn + 2] = (char)(value >> 8);
869 _data[posn + 3] = (char)value;
871 _data[posn] = (char)value;
872 _data[posn + 1] = (char)(value >> 8);
873 _data[posn + 2] = (char)(value >> 16);
874 _data[posn + 3] = (char)(value >> 24);
880 while ( ( _data.size() % 4 ) != 0 )
881 _data.append( (
char)0 );
886 #endif // QT_NO_PRINTER static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
The QColor class provides colors based on RGB, HSV or CMYK values.
#define QT_QWS_PRINTER_DEFAULT_DPI
QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size)
#define TIFF_IFD_T4_OPTIONS
Format
The following image formats are available in Qt.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
void updateState(const QPaintEngineState &state)
Reimplement this function to update the state of a paint engine.
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
PaperSize paperSize(QPrinter::PaperSize paperSize)
#define QT_END_NAMESPACE
This macro expands to.
QPrinter::PrinterState printerState() const
Returns the current state of the printer being used by the print engine.
#define TIFF_IFD_PHOTOMETRIC_INTERP
#define TIFF_IFD_X_RESOLUTION
#define TIFF_IFD_COMPRESSION
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QPaintEngineState * state
qreal width() const
Returns the width.
PrinterMode
This enum describes the mode the printer should work in.
The QByteArray class provides an array of bytes.
The QPointF class defines a point in the plane using floating point precision.
qreal height() const
Returns the height.
#define TIFF_IFD_FILL_ORDER
Orientation
This enum type (not to be confused with Orientation) is used to specify each page's orientation...
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
int width() const
Returns the width of the rectangle.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
static bool send(const QString &channel, const QString &msg)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool end()
Reimplement this function to finish painting on the current paint device.
int height() const
Returns the height of the rectangle.
The QString class provides a Unicode character string.
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
#define TIFF_IFD_PLANAR_CONFIG
#define TIFF_IFD_IMAGE_WIDTH
#define TIFF_TYPE_RATIONAL
The QSizeF class defines the size of a two-dimensional object using floating point precision...
#define TIFF_IFD_Y_RESOLUTION
QPaintEngine * paintEngine() const
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Q_CORE_EXPORT void qDebug(const char *,...)
QtopiaPrintEngine(QPrinter::PrinterMode mode)
QFuture< void > map(Sequence &sequence, MapFunction function)
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
QSize size() const
Returns the size of the rectangle.
#define TIFF_IFD_ROWS_PER_STRIP
Q_CORE_EXPORT void qWarning(const char *,...)
#define TIFF_IFD_PAGE_NUMBER
The QImage class provides a hardware-independent image representation that allows direct access to th...
static const char * data(const QByteArray &arr)
#define TIFF_IFD_SAMPLES_PER_PIXEL
bool newPage()
Instructs the print engine to start a new page.
#define TIFF_IFD_NEW_SUB_FILE_TYPE
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
bool begin(QPaintDevice *dev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
#define TIFF_IFD_BITS_PER_SAMPLE
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
#define TIFF_IFD_CLEAN_FAX_DATA
#define TIFF_IFD_ORIENTATION
const char * constData() const
Returns a pointer to the data stored in the byte array.
QPaintEngine * paintEngine()
#define Q_ASSERT_X(cond, where, what)
void drawTextItem(const QPointF &p, const QTextItem &ti)
This function draws the text item textItem at position p.
The QFile class provides an interface for reading from and writing to files.
bool abort()
Instructs the print engine to abort the printing process.
#define TIFF_SHORT_PAIR(a, b)
void patch(int posn, int value)
PaperSize
This enum type specifies what paper size QPrinter should use.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
#define TIFF_IFD_RESOLUTION_UNIT
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
int writeG3IFDEntry(int tag, int type, int count, int value)
ColorMode
This enum type is used to indicate whether QPrinter should print in color or not. ...
The QRect class defines a rectangle in the plane using integer precision.
PageOrder
This enum type is used by QPrinter to tell the application program how to print.
The QPixmap class is an off-screen image representation that can be used as a paint device...
The QPaintEngineState class provides information about the active paint engine's current state...
void writeG3BlackRun(int len)
The QSize class defines the size of a two-dimensional object using integer point precision.
QPaintEngine::Type type() const
Reimplement this function to return the paint engine Type.
The QDataStream class provides serialization of binary data to a QIODevice.
#define TIFF_IFD_STRIP_BYTE_COUNTS
#define TIFF_IFD_IMAGE_LENGTH
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
The QTextItem class provides all the information required to draw text in a custom paint engine...
void writeG3Code(int code, int bits)
QVariant property(PrintEnginePropertyKey key) const
Returns the print engine's property specified by key.
qreal & rheight()
Returns a reference to the height.
virtual void close()
Calls QFile::flush() and closes the file.
qreal & rwidth()
Returns a reference to the width.
void setProperty(PrintEnginePropertyKey key, const QVariant &value)
Sets the print engine's property specified by key to the given value.
Q_DECL_CONSTEXPR int qRound(qreal d)
int metric(QPaintDevice::PaintDeviceMetric metricType) const
Returns the metric for the given id.
void writeG3WhiteRun(int len)
~QtopiaPrintEnginePrivate()
PaperSource
This enum type specifies what paper source QPrinter is to use.
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
#define TIFF_IFD_STRIP_OFFSETS