Add support for printing of TIFF documents

svn path=/trunk/playground/graphics/okular/; revision=605625
remotes/origin/KDE/4.0
Tobias Koenig 20 years ago
parent 07167f1e24
commit 6c53e576b6
  1. 2
      generators/tiff/CMakeLists.txt
  2. 45
      generators/tiff/generator_tiff.cpp
  3. 2
      generators/tiff/generator_tiff.h

@ -14,7 +14,7 @@ kde4_automoc(${okularGenerator_tiff_SRCS})
kde4_add_plugin(okularGenerator_tiff WITH_PREFIX ${okularGenerator_tiff_SRCS})
target_link_libraries(okularGenerator_tiff okularcore ${TIFF_LIBRARIES} ${KDE4_KDEUI_LIBS} )
target_link_libraries(okularGenerator_tiff okularcore ${TIFF_LIBRARIES} ${KDE4_KDEUI_LIBS} ${KDE4_KDEPRINT_LIBS} )
install(TARGETS okularGenerator_tiff DESTINATION ${PLUGIN_INSTALL_DIR})

@ -11,9 +11,11 @@
#include <qfile.h>
#include <qimage.h>
#include <qlist.h>
#include <qpainter.h>
#include <qthread.h>
#include <kglobal.h>
#include <klocale.h>
#include <kprinter.h>
#include "core/page.h"
#include "generator_tiff.h"
@ -330,5 +332,48 @@ void TIFFGenerator::loadPages( QVector<Okular::Page*> & pagesVector, int rotatio
}
}
bool TIFFGenerator::print( KPrinter& printer )
{
uint32 width = 0;
uint32 height = 0;
tdir_t dirs = TIFFNumberOfDirectories( d->tiff );
QPainter p( &printer );
for ( tdir_t i = 0; i < dirs; ++i )
{
if ( !TIFFSetDirectory( d->tiff, i ) )
continue;
if ( TIFFGetField( d->tiff, TIFFTAG_IMAGEWIDTH, &width ) != 1 ||
TIFFGetField( d->tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 )
continue;
QImage image( width, height, QImage::Format_RGB32 );
uint32 * data = (uint32 *)image.bits();
// read data
if ( TIFFReadRGBAImageOriented( d->tiff, width, height, data, ORIENTATION_TOPLEFT ) != 0 )
{
// an image read by ReadRGBAImage is ABGR, we need ARGB, so swap red and blue
uint32 size = width * height;
for ( uint32 i = 0; i < size; ++i )
{
uint32 red = ( data[i] & 0x00FF0000 ) >> 16;
uint32 blue = ( data[i] & 0x000000FF ) << 16;
data[i] = ( data[i] & 0xFF00FF00 ) + red + blue;
}
}
if ( i != 0 )
printer.newPage();
p.drawImage( 0, 0, image );
}
return true;
}
#include "generator_tiff.moc"

@ -31,6 +31,8 @@ class TIFFGenerator : public Okular::Generator
bool supportsRotation() const { return true; };
bool print( KPrinter& printer );
private slots:
void slotThreadFinished();

Loading…
Cancel
Save