2007-04-20 17:17:44 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 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_p.h"
|
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QDebug>
|
2007-07-07 20:35:01 +00:00
|
|
|
|
|
|
|
#include "fontinfo.h"
|
2007-04-20 17:17:44 +00:00
|
|
|
#include "generator.h"
|
2008-05-20 15:20:40 +00:00
|
|
|
#include "utils.h"
|
2007-04-20 17:17:44 +00:00
|
|
|
|
|
|
|
using namespace Okular;
|
|
|
|
|
|
|
|
PixmapGenerationThread::PixmapGenerationThread( Generator *generator )
|
2017-09-05 21:27:18 +00:00
|
|
|
: mGenerator( generator ), mRequest( nullptr ), mCalcBoundingBox( false )
|
2007-04-20 17:17:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:20:40 +00:00
|
|
|
void PixmapGenerationThread::startGeneration( PixmapRequest *request, bool calcBoundingBox )
|
2007-04-20 17:17:44 +00:00
|
|
|
{
|
|
|
|
mRequest = request;
|
2008-05-20 15:20:40 +00:00
|
|
|
mCalcBoundingBox = calcBoundingBox;
|
2007-04-20 17:17:44 +00:00
|
|
|
|
|
|
|
start( QThread::InheritPriority );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PixmapGenerationThread::endGeneration()
|
|
|
|
{
|
2017-09-05 21:27:18 +00:00
|
|
|
mRequest = nullptr;
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PixmapRequest *PixmapGenerationThread::request() const
|
|
|
|
{
|
|
|
|
return mRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage PixmapGenerationThread::image() const
|
|
|
|
{
|
2018-02-01 18:42:37 +00:00
|
|
|
return mRequest ? PixmapRequestPrivate::get(mRequest)->mResultImage : QImage();
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2008-05-20 15:20:40 +00:00
|
|
|
bool PixmapGenerationThread::calcBoundingBox() const
|
|
|
|
{
|
|
|
|
return mCalcBoundingBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
NormalizedRect PixmapGenerationThread::boundingBox() const
|
|
|
|
{
|
|
|
|
return mBoundingBox;
|
|
|
|
}
|
|
|
|
|
2007-04-20 17:17:44 +00:00
|
|
|
void PixmapGenerationThread::run()
|
|
|
|
{
|
|
|
|
if ( mRequest )
|
2008-05-20 15:20:40 +00:00
|
|
|
{
|
2018-02-01 18:42:37 +00:00
|
|
|
PixmapRequestPrivate::get(mRequest)->mResultImage = mGenerator->image( mRequest );
|
|
|
|
|
2008-05-20 15:20:40 +00:00
|
|
|
if ( mCalcBoundingBox )
|
2018-02-01 18:42:37 +00:00
|
|
|
mBoundingBox = Utils::imageBoundingBox( &PixmapRequestPrivate::get(mRequest)->mResultImage );
|
2008-05-20 15:20:40 +00:00
|
|
|
}
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TextPageGenerationThread::TextPageGenerationThread( Generator *generator )
|
2018-02-01 18:42:37 +00:00
|
|
|
: mGenerator( generator ), mTextPage( nullptr )
|
2007-04-20 17:17:44 +00:00
|
|
|
{
|
2018-02-01 18:42:37 +00:00
|
|
|
TextRequestPrivate *treqPriv = TextRequestPrivate::get( &mTextRequest );
|
|
|
|
treqPriv->mPage = nullptr;
|
|
|
|
treqPriv->mShouldAbortExtraction = 0;
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 18:42:37 +00:00
|
|
|
void TextPageGenerationThread::startGeneration()
|
2007-04-20 17:17:44 +00:00
|
|
|
{
|
2018-02-01 18:42:37 +00:00
|
|
|
if ( page() )
|
|
|
|
{
|
|
|
|
start( QThread::InheritPriority );
|
|
|
|
}
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextPageGenerationThread::endGeneration()
|
|
|
|
{
|
2018-02-01 18:42:37 +00:00
|
|
|
TextRequestPrivate *treqPriv = TextRequestPrivate::get( &mTextRequest );
|
|
|
|
treqPriv->mPage = nullptr;
|
|
|
|
treqPriv->mShouldAbortExtraction = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextPageGenerationThread::setPage( Page *page )
|
|
|
|
{
|
|
|
|
TextRequestPrivate *treqPriv = TextRequestPrivate::get( &mTextRequest );
|
|
|
|
treqPriv->mPage = page;
|
|
|
|
treqPriv->mShouldAbortExtraction = 0;
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Page *TextPageGenerationThread::page() const
|
|
|
|
{
|
2018-02-01 18:42:37 +00:00
|
|
|
return mTextRequest.page();
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextPage* TextPageGenerationThread::textPage() const
|
|
|
|
{
|
|
|
|
return mTextPage;
|
|
|
|
}
|
|
|
|
|
2018-02-01 18:42:37 +00:00
|
|
|
void TextPageGenerationThread::abortExtraction()
|
|
|
|
{
|
|
|
|
// If extraction already finished no point in aborting
|
|
|
|
if ( !mTextPage )
|
|
|
|
{
|
|
|
|
TextRequestPrivate *treqPriv = TextRequestPrivate::get( &mTextRequest );
|
|
|
|
treqPriv->mShouldAbortExtraction = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextPageGenerationThread::shouldAbortExtraction() const
|
|
|
|
{
|
|
|
|
return mTextRequest.shouldAbortExtraction();
|
|
|
|
}
|
|
|
|
|
2007-04-20 17:17:44 +00:00
|
|
|
void TextPageGenerationThread::run()
|
|
|
|
{
|
2017-09-05 21:27:18 +00:00
|
|
|
mTextPage = nullptr;
|
2007-04-20 17:17:44 +00:00
|
|
|
|
2018-02-01 18:42:37 +00:00
|
|
|
Q_ASSERT ( page() );
|
|
|
|
|
|
|
|
mTextPage = mGenerator->textPage( &mTextRequest );
|
|
|
|
|
|
|
|
if ( mTextRequest.shouldAbortExtraction() )
|
|
|
|
{
|
|
|
|
delete mTextPage;
|
|
|
|
mTextPage = nullptr;
|
|
|
|
}
|
2007-04-20 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 20:35:01 +00:00
|
|
|
|
|
|
|
FontExtractionThread::FontExtractionThread( Generator *generator, int pages )
|
2007-07-08 21:22:37 +00:00
|
|
|
: mGenerator( generator ), mNumOfPages( pages ), mGoOn( true )
|
2007-07-07 20:35:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontExtractionThread::startExtraction( bool async )
|
|
|
|
{
|
|
|
|
if ( async )
|
|
|
|
{
|
2014-10-01 12:02:01 +00:00
|
|
|
connect(this, &FontExtractionThread::finished, this, &FontExtractionThread::deleteLater);
|
2007-07-07 20:35:01 +00:00
|
|
|
start( QThread::InheritPriority );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
run();
|
2007-07-08 21:22:37 +00:00
|
|
|
deleteLater();
|
2007-07-07 20:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-08 21:22:37 +00:00
|
|
|
void FontExtractionThread::stopExtraction()
|
|
|
|
{
|
|
|
|
mGoOn = false;
|
|
|
|
}
|
|
|
|
|
2007-07-07 20:35:01 +00:00
|
|
|
void FontExtractionThread::run()
|
|
|
|
{
|
2007-12-28 17:06:43 +00:00
|
|
|
for ( int i = -1; i < mNumOfPages && mGoOn; ++i )
|
2007-07-07 20:35:01 +00:00
|
|
|
{
|
|
|
|
FontInfo::List list = mGenerator->fontsForPage( i );
|
|
|
|
foreach ( const FontInfo& fi, list )
|
|
|
|
{
|
|
|
|
emit gotFont( fi );
|
|
|
|
}
|
|
|
|
emit progress( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 22:00:07 +00:00
|
|
|
#include "moc_generator_p.cpp"
|