diff --git a/cmake/modules/FindPoppler.cmake b/cmake/modules/FindPoppler.cmake index 6e421d9..c35e79e 100644 --- a/cmake/modules/FindPoppler.cmake +++ b/cmake/modules/FindPoppler.cmake @@ -116,6 +116,15 @@ int main() } " HAVE_POPPLER_0_22) +check_cxx_source_compiles(" +#include +int main() +{ + Poppler::Document::RenderHint hint = Poppler::Document::OverprintPreview; + return 0; +} +" HAVE_POPPLER_0_22_CMYK) + set(CMAKE_REQUIRED_INCLUDES) set(CMAKE_REQUIRED_LIBRARIES) if (HAVE_POPPLER_0_22) diff --git a/conf/dlgaccessibilitybase.ui b/conf/dlgaccessibilitybase.ui index 9e76a75..e69f1e1 100644 --- a/conf/dlgaccessibilitybase.ui +++ b/conf/dlgaccessibilitybase.ui @@ -37,6 +37,13 @@ + + + Simulate &Overprint + + + + true diff --git a/conf/okular_core.kcfg b/conf/okular_core.kcfg index 054b5c1..6cbcb7c 100644 --- a/conf/okular_core.kcfg +++ b/conf/okular_core.kcfg @@ -47,6 +47,9 @@ false + + false + Inverted diff --git a/core/document.cpp b/core/document.cpp index 372af56..5cbd498 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1802,6 +1802,10 @@ QVariant DocumentPrivate::documentMetaData( const QString &key, const QVariant & } return color; } + else if ( key == QLatin1String( "OverprintPreview" ) ) + { + return SettingsCore::overprintPreview(); + } else if ( key == QLatin1String( "TextAntialias" ) ) { switch ( SettingsCore::textAntialias() ) diff --git a/generators/poppler/annots.cpp b/generators/poppler/annots.cpp index b7fb9f7..c7a8921 100644 --- a/generators/poppler/annots.cpp +++ b/generators/poppler/annots.cpp @@ -91,7 +91,9 @@ void PopplerAnnotationProxy::notifyAddition( Okular::Annotation *okl_ann, int pa QDomElement dom_ann = doc.createElement( "root" ); Okular::AnnotationUtils::storeAnnotation( okl_ann, dom_ann, doc ); +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker ml(mutex); +#endif // Create poppler annotation Poppler::Annotation *ppl_ann = Poppler::AnnotationUtils::createAnnotation( dom_ann ); @@ -144,7 +146,9 @@ void PopplerAnnotationProxy::notifyModification( const Okular::Annotation *okl_a if ( !ppl_ann ) // Ignore non-native annotations return; +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker ml(mutex); +#endif if ( okl_ann->flags() & Okular::Annotation::BeingMoved ) { @@ -254,7 +258,9 @@ void PopplerAnnotationProxy::notifyRemoval( Okular::Annotation *okl_ann, int pag if ( !ppl_ann ) // Ignore non-native annotations return; +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker ml(mutex); +#endif Poppler::Page *ppl_page = ppl_doc->page( page ); ppl_page->removeAnnotation( ppl_ann ); // Also destroys ppl_ann diff --git a/generators/poppler/config-okular-poppler.h.cmake b/generators/poppler/config-okular-poppler.h.cmake index 2ce6a4a..f0cd2f4 100644 --- a/generators/poppler/config-okular-poppler.h.cmake +++ b/generators/poppler/config-okular-poppler.h.cmake @@ -9,3 +9,6 @@ /* Defined if we have the 0.22 version of the Poppler library */ #cmakedefine HAVE_POPPLER_0_22 1 + +/* Defined if we have the 0.22 version of the Poppler library with overprint */ +#cmakedefine HAVE_POPPLER_0_22_CMYK 1 diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 7f8d1e7..f338a90 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -584,12 +584,16 @@ bool PDFGenerator::init(QVector & pagesVector, const QString &wal bool PDFGenerator::doCloseDocument() { // remove internal objects +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif delete annotProxy; annotProxy = 0; delete pdfdoc; pdfdoc = 0; +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif docInfoDirty = true; docSynopsisDirty = true; docSyn.clear(); @@ -674,7 +678,9 @@ const Okular::DocumentInfo * PDFGenerator::generateDocumentInfo() { if ( docInfoDirty ) { +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif docInfo.set( Okular::DocumentInfo::MimeType, "application/pdf" ); @@ -721,7 +727,9 @@ const Okular::DocumentInfo * PDFGenerator::generateDocumentInfo() docInfo.set( Okular::DocumentInfo::Pages, i18n("Unknown") ); } +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif // if pdfdoc is valid then we cached good info -> don't cache them again if ( pdfdoc ) @@ -738,9 +746,13 @@ const Okular::DocumentSynopsis * PDFGenerator::generateDocumentSynopsis() if ( !pdfdoc ) return NULL; +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif QDomDocument *toc = pdfdoc->toc(); +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif if ( !toc ) return NULL; @@ -819,9 +831,13 @@ Okular::FontInfo::List PDFGenerator::fontsForPage( int page ) return list; QList fonts; +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif pdfdoc->scanForFonts( 1, &fonts ); +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif foreach (const Poppler::FontInfo &font, fonts) { @@ -848,13 +864,17 @@ const QList *PDFGenerator::embeddedFiles() const { if (docEmbeddedFilesDirty) { +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif const QList &popplerFiles = pdfdoc->embeddedFiles(); foreach(Poppler::EmbeddedFile* pef, popplerFiles) { docEmbeddedFiles.append(new PDFEmbeddedFile(pef)); } +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif docEmbeddedFilesDirty = false; } @@ -908,7 +928,9 @@ QImage PDFGenerator::image( Okular::PixmapRequest * request ) bool genObjectRects = !rectsGenerated.at( page->number() ); // 0. LOCK [waits for the thread end] +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif // 1. Set OutputDev parameters and Generate contents // note: thread safety is set on 'false' for the GUI (this) thread @@ -946,7 +968,9 @@ QImage PDFGenerator::image( Okular::PixmapRequest * request ) } // 3. UNLOCK [re-enables shared access] +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif delete p; @@ -1039,9 +1063,13 @@ Okular::TextPage* PDFGenerator::textPage( Okular::Page *page ) Poppler::Page *pp = pdfdoc->page( page->number() ); if (pp) { +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif textList = pp->textList(); +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif QSizeF s = pp->pageSizeF(); pageWidth = s.width(); @@ -1082,7 +1110,9 @@ bool PDFGenerator::print( QPrinter& printer ) printer.newPage(); const int page = pageList.at( i ) - 1; +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif Poppler::Page *pp = pdfdoc->page( page ); if (pp) { @@ -1090,7 +1120,9 @@ bool PDFGenerator::print( QPrinter& printer ) painter.drawImage( painter.window(), img, QRectF(0, 0, img.width(), img.height()) ); delete pp; } +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif } painter.end(); return true; @@ -1162,10 +1194,14 @@ bool PDFGenerator::print( QPrinter& printer ) psConverter->setPSOptions(psConverter->psOptions() | Poppler::PSConverter::HideAnnotations ); #endif +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif if (psConverter->convert()) { +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif delete psConverter; tf.close(); int ret = Okular::FilePrinter::printFile( printer, tempfilename, @@ -1182,7 +1218,9 @@ bool PDFGenerator::print( QPrinter& printer ) { lastPrintError = FileConversionPrintError; delete psConverter; +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif } tf.close(); @@ -1195,7 +1233,9 @@ QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) { if ( key == "StartFullScreen" ) { +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker ml(userMutex()); +#endif // asking for the 'start in fullscreen mode' (pdf property) if ( pdfdoc->pageMode() == Poppler::Document::FullScreen ) return true; @@ -1215,9 +1255,13 @@ QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) { // asking for the page related to a 'named link destination'. the // option is the link name. @see addSynopsisChildren. +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif Poppler::LinkDestination *ld = pdfdoc->linkDestination( optionString ); +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif if ( ld ) { fillViewportFromLinkDestination( viewport, *ld ); @@ -1229,26 +1273,36 @@ QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) } else if ( key == "DocumentTitle" ) { +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif QString title = pdfdoc->info( "Title" ); +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif return title; } else if ( key == "OpenTOC" ) { +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker ml(userMutex()); +#endif if ( pdfdoc->pageMode() == Poppler::Document::UseOutlines ) return true; } else if ( key == "DocumentScripts" && option.toString() == "JavaScript" ) { +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker ml(userMutex()); +#endif return pdfdoc->scripts(); } else if ( key == "HasUnsupportedXfaForm" ) { #ifdef HAVE_POPPLER_0_22 +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker ml(userMutex()); +#endif return pdfdoc->formType() == Poppler::Document::XfaForm; #else return false; @@ -1270,9 +1324,13 @@ bool PDFGenerator::reparseConfig() // over the page rendered on 'standard' white background. if ( color != pdfdoc->paperColor() ) { +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif pdfdoc->setPaperColor(color); +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif somethingchanged = true; } bool aaChanged = setDocumentRenderHints(); @@ -1302,6 +1360,9 @@ bool PDFGenerator::setDocumentRenderHints() #ifdef HAVE_POPPLER_0_12_1 SET_HINT("TextHinting", false, Poppler::Document::TextHinting) #endif +#ifdef HAVE_POPPLER_0_22_CMYK + SET_HINT("OverprintPreview", false, Poppler::Document::OverprintPreview) +#endif #undef SET_HINT return changed; } @@ -1328,13 +1389,17 @@ bool PDFGenerator::exportTo( const QString &fileName, const Okular::ExportFormat for ( int i = 0; i < num; ++i ) { QString text; +#ifndef POPPLER_QT4_THREADSAFE userMutex()->lock(); +#endif Poppler::Page *pp = pdfdoc->page(i); if (pp) { text = pp->text(QRect()).normalized(QString::NormalizationForm_KC); } +#ifndef POPPLER_QT4_THREADSAFE userMutex()->unlock(); +#endif ts << text; delete pp; } @@ -1848,7 +1913,9 @@ bool PDFGenerator::supportsOption( SaveOption option ) const { // Saving files with /Encrypt is not supported before Poppler 0.22 #ifndef HAVE_POPPLER_0_22 +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker locker( userMutex() ); +#endif return pdfdoc->isEncrypted() ? false : true; #else return true; @@ -1867,7 +1934,9 @@ bool PDFGenerator::save( const QString &fileName, SaveOptions options, QString * if ( options & SaveChanges ) pdfConv->setPDFOptions( pdfConv->pdfOptions() | Poppler::PDFConverter::WithChanges ); +#ifndef POPPLER_QT4_THREADSAFE QMutexLocker locker( userMutex() ); +#endif bool success = pdfConv->convert(); #ifdef HAVE_POPPLER_0_12_1 if (!success)