diff --git a/generators/poppler/CMakeLists.txt b/generators/poppler/CMakeLists.txt index 80dbde79745dda9a24763fd678156b9b25c5ca6f..8bc1b0e542a68b73e9db3512786c75a9437a568d 100644 --- a/generators/poppler/CMakeLists.txt +++ b/generators/poppler/CMakeLists.txt @@ -34,6 +34,7 @@ include_directories( set(okularGenerator_poppler_PART_SRCS generator_pdf.cpp formfields.cpp + annots.cpp ) kde4_add_plugin(okularGenerator_poppler ${okularGenerator_poppler_PART_SRCS}) diff --git a/generators/poppler/annots.cpp b/generators/poppler/annots.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ffed7cbd17eb056f68d78cd78d33529d89bbcee6 --- /dev/null +++ b/generators/poppler/annots.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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 + +#include + +Okular::Annotation* createAnnotationFromPopplerAnnotation( const Poppler::Annotation *ann, bool *doDelete ) +{ + Okular::Annotation *annotation = 0; + *doDelete = true; + switch ( ann->subType() ) + { + default: + { + // this is uber ugly but i don't know a better way to do it without introducing a poppler::annotation dependency on core + QDomDocument doc; + QDomElement root = doc.createElement( "root" ); + doc.appendChild( root ); + Poppler::AnnotationUtils::storeAnnotation( ann, root, doc ); + annotation = Okular::AnnotationUtils::createAnnotation( root ); + return annotation; + } + } + if ( annotation ) + { + annotation->setAuthor( ann->author() ); + annotation->setContents( ann->contents() ); + annotation->setUniqueName( ann->uniqueName() ); + annotation->setModificationDate( ann->modificationDate() ); + annotation->setCreationDate( ann->creationDate() ); + annotation->setFlags( ann->flags() ); + annotation->setBoundingRectangle( Okular::NormalizedRect::fromQRectF( ann->boundary() ) ); + // TODO clone style + // TODO clone window + // TODO clone revisions + } + return annotation; +} diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index d8fdd808015e9bfe64a024359c8adb2cc7eea62b..b3e27d26549c3a8631e85090e287bce0fda594ca 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -240,6 +240,8 @@ static QLinkedList generateLinks( const QListwindow.summary <<", window.text:"<window.text; kDebug(PDFDebug) << "astario: " << szanno; */ - // this is uber ugly but i don't know a better way to do it without introducing a poppler::annotation dependency on core //TODO add annotations after poppler write feather is full suported - QDomDocument doc; - QDomElement root = doc.createElement("root"); - doc.appendChild(root); - Poppler::AnnotationUtils::storeAnnotation(a, root, doc); - Okular::Annotation * newann = Okular::AnnotationUtils::createAnnotation(root); + bool doDelete = true; + Okular::Annotation * newann = createAnnotationFromPopplerAnnotation( a, &doDelete ); if (newann) { // the Contents field has lines separated by \r @@ -1271,8 +1269,9 @@ void PDFGenerator::addAnnotations( Poppler::Page * popplerPage, Okular::Page * p newann->setFlags( newann->flags() | Okular::Annotation::External ); page->addAnnotation(newann); } + if ( doDelete ) + delete a; } - qDeleteAll(popplerAnnotations); } void PDFGenerator::addTransition( Poppler::Page * pdfPage, Okular::Page * page )