2008-09-19 09:21:20 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2008 by Tobias Koenig <tokoe@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "generator_fax.h"
|
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPrinter>
|
2008-09-19 09:21:20 +00:00
|
|
|
|
2014-09-18 20:17:10 +00:00
|
|
|
#include <KAboutData>
|
2014-10-08 11:37:04 +00:00
|
|
|
#include <KLocalizedString>
|
2008-09-19 09:21:20 +00:00
|
|
|
|
2011-06-01 08:49:49 +00:00
|
|
|
#include <core/document.h>
|
|
|
|
#include <core/page.h>
|
2008-09-19 09:21:20 +00:00
|
|
|
|
2015-11-28 19:24:41 +00:00
|
|
|
OKULAR_EXPORT_PLUGIN(FaxGenerator, "libokularGenerator_fax.json")
|
2008-09-19 09:21:20 +00:00
|
|
|
|
|
|
|
FaxGenerator::FaxGenerator( QObject *parent, const QVariantList &args )
|
|
|
|
: Generator( parent, args )
|
|
|
|
{
|
|
|
|
setFeature( Threaded );
|
|
|
|
setFeature( PrintNative );
|
|
|
|
setFeature( PrintToFile );
|
|
|
|
}
|
|
|
|
|
|
|
|
FaxGenerator::~FaxGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FaxGenerator::loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector )
|
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
if ( fileName.toLower().endsWith( QLatin1String(".g3") ) )
|
2014-05-11 09:17:49 +00:00
|
|
|
m_type = FaxDocument::G3;
|
2008-09-19 09:21:20 +00:00
|
|
|
else
|
2014-05-11 09:17:49 +00:00
|
|
|
m_type = FaxDocument::G4;
|
2008-09-19 09:21:20 +00:00
|
|
|
|
2014-05-11 09:17:49 +00:00
|
|
|
FaxDocument faxDocument( fileName, m_type );
|
2008-09-19 09:21:20 +00:00
|
|
|
|
|
|
|
if ( !faxDocument.load() )
|
|
|
|
{
|
|
|
|
emit error( i18n( "Unable to load document" ), -1 );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_img = faxDocument.image();
|
|
|
|
|
|
|
|
pagesVector.resize( 1 );
|
|
|
|
|
|
|
|
Okular::Page * page = new Okular::Page( 0, m_img.width(), m_img.height(), Okular::Rotation0 );
|
|
|
|
pagesVector[0] = page;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FaxGenerator::doCloseDocument()
|
|
|
|
{
|
|
|
|
m_img = QImage();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage FaxGenerator::image( Okular::PixmapRequest * request )
|
|
|
|
{
|
|
|
|
// perform a smooth scaled generation
|
|
|
|
int width = request->width();
|
|
|
|
int height = request->height();
|
|
|
|
if ( request->page()->rotation() % 2 == 1 )
|
|
|
|
qSwap( width, height );
|
|
|
|
|
|
|
|
return m_img.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
|
|
|
}
|
|
|
|
|
2014-05-11 09:17:49 +00:00
|
|
|
Okular::DocumentInfo FaxGenerator::generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &keys ) const
|
2008-09-19 09:21:20 +00:00
|
|
|
{
|
2014-05-11 09:17:49 +00:00
|
|
|
Okular::DocumentInfo docInfo;
|
|
|
|
if ( keys.contains( Okular::DocumentInfo::MimeType ) )
|
|
|
|
{
|
|
|
|
if ( m_type == FaxDocument::G3 )
|
2015-10-29 12:37:11 +00:00
|
|
|
docInfo.set( Okular::DocumentInfo::MimeType, QStringLiteral("image/fax-g3") );
|
2014-05-11 09:17:49 +00:00
|
|
|
else
|
2015-10-29 12:37:11 +00:00
|
|
|
docInfo.set( Okular::DocumentInfo::MimeType, QStringLiteral("image/fax-g4") );
|
2014-05-11 09:17:49 +00:00
|
|
|
}
|
|
|
|
return docInfo;
|
2008-09-19 09:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FaxGenerator::print( QPrinter& printer )
|
|
|
|
{
|
|
|
|
QPainter p( &printer );
|
|
|
|
|
|
|
|
QImage image( m_img );
|
|
|
|
|
|
|
|
if ( ( image.width() > printer.width() ) || ( image.height() > printer.height() ) )
|
|
|
|
|
|
|
|
image = image.scaled( printer.width(), printer.height(),
|
|
|
|
Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
|
|
|
|
|
|
|
p.drawImage( 0, 0, image );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "generator_fax.moc"
|
|
|
|
|