Commit c3f76672 authored by Pino Toscano's avatar Pino Toscano

isolate the Poppler -> Okular annotation conversion function in an own file

svn path=/trunk/KDE/kdegraphics/okular/; revision=796451
parent bef0e98f
...@@ -34,6 +34,7 @@ include_directories( ...@@ -34,6 +34,7 @@ include_directories(
set(okularGenerator_poppler_PART_SRCS set(okularGenerator_poppler_PART_SRCS
generator_pdf.cpp generator_pdf.cpp
formfields.cpp formfields.cpp
annots.cpp
) )
kde4_add_plugin(okularGenerator_poppler ${okularGenerator_poppler_PART_SRCS}) kde4_add_plugin(okularGenerator_poppler ${okularGenerator_poppler_PART_SRCS})
......
/***************************************************************************
* Copyright (C) 2008 by Pino Toscano <pino@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 <poppler-annotation.h>
#include <okular/core/annotations.h>
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;
}
...@@ -240,6 +240,8 @@ static QLinkedList<Okular::ObjectRect*> generateLinks( const QList<Poppler::Link ...@@ -240,6 +240,8 @@ static QLinkedList<Okular::ObjectRect*> generateLinks( const QList<Poppler::Link
return links; return links;
} }
extern Okular::Annotation* createAnnotationFromPopplerAnnotation( const Poppler::Annotation *ann, bool * doDelete );
/** NOTES on threading: /** NOTES on threading:
* internal: thread race prevention is done via the 'docLock' mutex. the * internal: thread race prevention is done via the 'docLock' mutex. the
* mutex is needed only because we have the asynchronous thread; else * mutex is needed only because we have the asynchronous thread; else
...@@ -1254,13 +1256,9 @@ void PDFGenerator::addAnnotations( Poppler::Page * popplerPage, Okular::Page * p ...@@ -1254,13 +1256,9 @@ void PDFGenerator::addAnnotations( Poppler::Page * popplerPage, Okular::Page * p
<<", window.summary:"<<a->window.summary <<", window.summary:"<<a->window.summary
<<", window.text:"<<a->window.text; <<", window.text:"<<a->window.text;
kDebug(PDFDebug) << "astario: " << szanno; */ 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 //TODO add annotations after poppler write feather is full suported
QDomDocument doc; bool doDelete = true;
QDomElement root = doc.createElement("root"); Okular::Annotation * newann = createAnnotationFromPopplerAnnotation( a, &doDelete );
doc.appendChild(root);
Poppler::AnnotationUtils::storeAnnotation(a, root, doc);
Okular::Annotation * newann = Okular::AnnotationUtils::createAnnotation(root);
if (newann) if (newann)
{ {
// the Contents field has lines separated by \r // the Contents field has lines separated by \r
...@@ -1271,8 +1269,9 @@ void PDFGenerator::addAnnotations( Poppler::Page * popplerPage, Okular::Page * p ...@@ -1271,8 +1269,9 @@ void PDFGenerator::addAnnotations( Poppler::Page * popplerPage, Okular::Page * p
newann->setFlags( newann->flags() | Okular::Annotation::External ); newann->setFlags( newann->flags() | Okular::Annotation::External );
page->addAnnotation(newann); page->addAnnotation(newann);
} }
if ( doDelete )
delete a;
} }
qDeleteAll(popplerAnnotations);
} }
void PDFGenerator::addTransition( Poppler::Page * pdfPage, Okular::Page * page ) void PDFGenerator::addTransition( Poppler::Page * pdfPage, Okular::Page * page )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment