summaryrefslogtreecommitdiff
path: root/qt4
diff options
context:
space:
mode:
authorPino Toscano <pino@kde.org>2008-11-30 16:34:57 +0100
committerPino Toscano <pino@kde.org>2008-11-30 16:34:57 +0100
commitb5cd58b5565055fd0c13771461245ddcd80edfcf (patch)
treeb49890399eb2be211951eb7cfaf5837bd066cd07 /qt4
parentee191363e22940ae7b06945e68c4738b17c78348 (diff)
extract the LinkAction "serialization" in an own function, and make it more safe
Diffstat (limited to 'qt4')
-rw-r--r--qt4/src/poppler-private.cc85
1 files changed, 59 insertions, 26 deletions
diff --git a/qt4/src/poppler-private.cc b/qt4/src/poppler-private.cc
index 7b6e2a01..80871e7a 100644
--- a/qt4/src/poppler-private.cc
+++ b/qt4/src/poppler-private.cc
@@ -118,28 +118,14 @@ namespace Poppler {
return ret;
}
- void DocumentData::addTocChildren( QDomDocument * docSyn, QDomNode * parent, GooList * items )
+ void linkActionToTocItem( ::LinkAction * a, DocumentData * doc, QDomElement * e )
{
- int numItems = items->getLength();
- for ( int i = 0; i < numItems; ++i )
- {
- // iterate over every object in 'items'
- OutlineItem * outlineItem = (OutlineItem *)items->get( i );
-
- // 1. create element using outlineItem's title as tagName
- QString name;
- Unicode * uniChar = outlineItem->getTitle();
- int titleLength = outlineItem->getTitleLength();
- name = unicodeToQString(uniChar, titleLength);
- if ( name.isEmpty() )
- continue;
-
- QDomElement item = docSyn->createElement( name );
- parent->appendChild( item );
+ if ( !a || !e )
+ return;
- // 2. find the page the link refers to
- ::LinkAction * a = outlineItem->getAction();
- if ( a && ( a->getKind() == actionGoTo || a->getKind() == actionGoToR ) )
+ switch ( a->getKind() )
+ {
+ case actionGoTo:
{
// page number is contained/referenced in a LinkGoTo
LinkGoTo * g = static_cast< LinkGoTo * >( a );
@@ -153,20 +139,67 @@ namespace Poppler {
QChar *charArray = new QChar[s->getLength()];
for (int i = 0; i < s->getLength(); ++i) charArray[i] = QChar(s->getCString()[i]);
QString aux(charArray, s->getLength());
- item.setAttribute( "DestinationName", aux );
+ e->setAttribute( "DestinationName", aux );
delete[] charArray;
}
else if ( destination && destination->isOk() )
{
- LinkDestinationData ldd(destination, NULL, this);
- item.setAttribute( "Destination", LinkDestination(ldd).toString() );
+ LinkDestinationData ldd(destination, NULL, doc);
+ e->setAttribute( "Destination", LinkDestination(ldd).toString() );
}
- if ( a->getKind() == actionGoToR )
+ break;
+ }
+ case actionGoToR:
+ {
+ // page number is contained/referenced in a LinkGoToR
+ LinkGoToR * g = static_cast< LinkGoToR * >( a );
+ LinkDest * destination = g->getDest();
+ if ( !destination && g->getNamedDest() )
{
- LinkGoToR * g2 = static_cast< LinkGoToR * >( a );
- item.setAttribute( "ExternalFileName", g2->getFileName()->getCString() );
+ // no 'destination' but an internal 'named reference'. we could
+ // get the destination for the page now, but it's VERY time consuming,
+ // so better storing the reference and provide the viewport on demand
+ GooString *s = g->getNamedDest();
+ QChar *charArray = new QChar[s->getLength()];
+ for (int i = 0; i < s->getLength(); ++i) charArray[i] = QChar(s->getCString()[i]);
+ QString aux(charArray, s->getLength());
+ e->setAttribute( "DestinationName", aux );
+ delete[] charArray;
+ }
+ else if ( destination && destination->isOk() )
+ {
+ LinkDestinationData ldd(destination, NULL, doc);
+ e->setAttribute( "Destination", LinkDestination(ldd).toString() );
}
+ e->setAttribute( "ExternalFileName", g->getFileName()->getCString() );
+ break;
}
+ default: ;
+ }
+ }
+
+ void DocumentData::addTocChildren( QDomDocument * docSyn, QDomNode * parent, GooList * items )
+ {
+ int numItems = items->getLength();
+ for ( int i = 0; i < numItems; ++i )
+ {
+ // iterate over every object in 'items'
+ OutlineItem * outlineItem = (OutlineItem *)items->get( i );
+
+ // 1. create element using outlineItem's title as tagName
+ QString name;
+ Unicode * uniChar = outlineItem->getTitle();
+ int titleLength = outlineItem->getTitleLength();
+ name = unicodeToQString(uniChar, titleLength);
+ if ( name.isEmpty() )
+ continue;
+
+ QDomElement item = docSyn->createElement( name );
+ parent->appendChild( item );
+
+ // 2. find the page the link refers to
+ ::LinkAction * a = outlineItem->getAction();
+ linkActionToTocItem( a, this, &item );
item.setAttribute( "Open", QVariant( (bool)outlineItem->isOpen() ).toString() );