Move the call to fontLocate in the pixmap rendering thread

- Initialize the kpsewhich QProcess in the fontLocate() method
- Remove the usage of fontProgressDialog and use the warning
  signal to notify the user on the status of font generation.
- The change makes it "easier", in future, to kill the font
  generation when the user opens a new document. Right now it
  is not possible to stop the generation.

Reviewed by: Albert Astal Cid, Fabio d'Urso
(and thanks for the hints!)
This commit is contained in:
Luigi Toscano 2014-05-11 00:17:46 +02:00
parent 6ce1cd49bd
commit ae555519c5
4 changed files with 33 additions and 39 deletions

View file

@ -66,7 +66,8 @@ dviRenderer::dviRenderer(bool useFontHinting)
number_of_elements_in_path(0),
currentlyDrawnPage(0),
m_eventLoop(0),
foreGroundPainter(0)
foreGroundPainter(0),
fontpoolLocateFontsDone(false)
{
#ifdef DEBUG_DVIRENDERER
//kDebug(kvs::dvi) << "dviRenderer( parent=" << par << " )";
@ -141,6 +142,17 @@ void dviRenderer::drawPage(RenderedDocumentPagePixmap* page)
return;
}
/* locateFonts() is here just once (if it has not been executed
not been executed yet), so that it is possible to easily intercept
the cancel signal (because for example the user tries to open
another document); it would not have been possible (or more
complicated) in case it was still in the document loading section.
*/
if ( !fontpoolLocateFontsDone ) {
font_pool.locateFonts();
fontpoolLocateFontsDone = true;
}
double resolution = page->resolution;
if (resolution != resolutionInDPI)
@ -493,9 +505,6 @@ bool dviRenderer::setFile(const QString &fname, const KUrl &base)
if (dviFile->page_offset.isEmpty() == true)
return false;
// Locate fonts.
font_pool.locateFonts();
// We should pre-scan the document now (to extract embedded,
// PostScript, Hyperlinks, ets).

View file

@ -324,6 +324,9 @@ private:
QEventLoop* m_eventLoop;
QPainter* foreGroundPainter;
// was the locateFonts method of font pool executed?
bool fontpoolLocateFontsDone;
};
#endif

View file

@ -34,14 +34,6 @@ bool fontPoolTimerFlag;
#endif
fontPool::fontPool(bool useFontHinting)
: progress("fontgen", // Chapter in the documentation for help.
i18n("Okular is currently generating bitmap fonts..."),
i18n("Aborts the font generation. Do not do this."),
i18n("Okular is currently generating bitmap fonts which are needed to display your document. "
"For this, Okular uses a number of external programs, such as MetaFont. You can find "
"the output of these programs later in the document info dialog."),
i18n("Okular is generating fonts. Please wait."),
0)
{
#ifdef DEBUG_FONTPOOL
kDebug(kvs::dvi) << "fontPool::fontPool() called";
@ -63,12 +55,6 @@ fontPool::fontPool(bool useFontHinting)
FreeType_could_be_loaded = true;
#endif
// If PK fonts are generated, the kpsewhich command will re-route
// the output of MetaFont into its stderr. Here we make sure this
// output is intercepted and parsed.
connect(&kpsewhich_, SIGNAL(readyReadStandardError()),
this, SLOT(mf_output_receiver()));
// Check if the QT library supports the alpha channel of
// QImages. Experiments show that --depending of the configuration
// of QT at compile and runtime or the availability of the XFt
@ -271,7 +257,12 @@ void fontPool::locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFo
if (numFontsInJob == 0)
return;
progress.setTotalSteps(numFontsInJob, &kpsewhich_);
// If PK fonts are generated, the kpsewhich command will re-route
// the output of MetaFont into its stderr. Here we make sure this
// output is intercepted and parsed.
kpsewhich_ = new QProcess();
connect(kpsewhich_, SIGNAL(readyReadStandardError()),
this, SLOT(mf_output_receiver()));
// Now run... kpsewhich. In case of error, kick up a fuss.
// This string is not going to be quoted, as it might be were it
@ -284,9 +275,9 @@ void fontPool::locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFo
i18n("<p>Okular relies on the <b>kpsewhich</b> program to locate font files "
"on your hard disk and to generate PK fonts, if necessary.</p>");
kpsewhich_.start(kpsewhich_exe, kpsewhich_args,
kpsewhich_->start(kpsewhich_exe, kpsewhich_args,
QIODevice::ReadOnly|QIODevice::Text);
if (!kpsewhich_.waitForStarted()) {
if (!kpsewhich_->waitForStarted()) {
QApplication::restoreOverrideCursor();
emit error(i18n("There were problems running 'kpsewhich'. As a result, "
"some font files could not be located, and your document might be unreadable.\n"
@ -296,23 +287,18 @@ void fontPool::locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFo
// This makes sure the we don't try to run kpsewhich again
markFontsAsLocated();
delete kpsewhich_;
return;
}
// We wait here while the external program runs concurrently.
// Every 200ms we call processEvents() to keep the GUI updated.
// This is important, e.g. for the progress dialog that is
// shown when PK fonts are generated by MetaFont.
while(!kpsewhich_.waitForFinished(200))
qApp->processEvents();
progress.hide();
kpsewhich_->waitForFinished();
// Handle fatal errors.
int const kpsewhich_exit_code = kpsewhich_.exitCode();
int const kpsewhich_exit_code = kpsewhich_->exitCode();
if (kpsewhich_exit_code < 0) {
emit warning(i18n("The font generation by 'kpsewhich' was aborted (exit code %1, error %2). As a "
"result, some font files could not be located, and your document might be unreadable.",
kpsewhich_exit_code, kpsewhich_.errorString()), -1);
kpsewhich_exit_code, kpsewhich_->errorString()), -1);
// This makes sure the we don't try to run kpsewhich again
if (makePK == false)
@ -321,7 +307,7 @@ void fontPool::locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFo
// Create a list with all filenames found by the kpsewhich program.
const QStringList fileNameList =
QString(kpsewhich_.readAll()).split('\n', QString::SkipEmptyParts);
QString(kpsewhich_->readAll()).split('\n', QString::SkipEmptyParts);
// Now associate the file names found with the fonts
QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
@ -357,6 +343,7 @@ void fontPool::locateFonts(bool makePK, bool locateTFMonly, bool *virtualFontsFo
}
} // of if (fontp->filename.isEmpty() == true)
}
delete kpsewhich_;
}
@ -457,7 +444,7 @@ void fontPool::release_fonts()
void fontPool::mf_output_receiver()
{
const QString output_data =
QString::fromLocal8Bit(kpsewhich_.readAllStandardError());
QString::fromLocal8Bit(kpsewhich_->readAllStandardError());
kpsewhichOutput.append(output_data);
MetafontOutput.append(output_data);
@ -487,8 +474,7 @@ void fontPool::mf_output_receiver()
int secondblank = startLine.lastIndexOf(' ',lastblank-1);
QString dpi = startLine.mid(secondblank+1,lastblank-secondblank-1);
progress.show();
progress.increaseNumSteps( i18n("Currently generating %1 at %2 dpi", fontName, dpi) );
emit warning( i18n("Currently generating %1 at %2 dpi", fontName, dpi), -1 );
}
MetafontOutput = MetafontOutput.remove(0,numleft+1);
}

View file

@ -9,7 +9,6 @@
#include "fontEncodingPool.h"
#include "fontMap.h"
#include "fontprogress.h"
#include "TeXFontDefinition.h"
#include <QList>
@ -194,11 +193,8 @@ private:
// setExtraSearchPath(...) method
QString extraSearchPath;
// FontProgress; the progress dialog used when generating fonts.
fontProgressDialog progress;
// The handle on the external process.
QProcess kpsewhich_;
QProcess *kpsewhich_;
private slots:
// This slot is called when MetaFont is run via the kpsewhich program.