Commit 25a41490 authored by Pino Toscano's avatar Pino Toscano

djvu toc:

- add mapping for page id/name/title -> page
- properly get the destination for "named" destinations in toc items
this way we should recognize all the types of destinations in a djvu toc

svn path=/trunk/KDE/kdegraphics/okular/; revision=890963
parent 67438034
......@@ -30,7 +30,7 @@
#include <klocale.h>
#include <ktemporaryfile.h>
static void recurseCreateTOC( QDomDocument &maindoc, const QDomNode &parent, QDomNode &parentDestination )
static void recurseCreateTOC( QDomDocument &maindoc, const QDomNode &parent, QDomNode &parentDestination, KDjVu *djvu )
{
QDomNode n = parent.firstChild();
while( !n.isNull() )
......@@ -47,6 +47,12 @@ static void recurseCreateTOC( QDomDocument &maindoc, const QDomNode &parent, QDo
vp.pageNumber = dest.toInt() - 1;
newel.setAttribute( "Viewport", vp.toString() );
}
else if ( !( dest = el.attribute( "PageName" ) ).isEmpty() )
{
Okular::DocumentViewport vp;
vp.pageNumber = djvu->pageNumber( dest );
newel.setAttribute( "Viewport", vp.toString() );
}
else if ( !( dest = el.attribute( "URL" ) ).isEmpty() )
{
newel.setAttribute( "URL", dest );
......@@ -54,7 +60,7 @@ static void recurseCreateTOC( QDomDocument &maindoc, const QDomNode &parent, QDo
if ( el.hasChildNodes() )
{
recurseCreateTOC( maindoc, n, newel );
recurseCreateTOC( maindoc, n, newel, djvu );
}
n = n.nextSibling();
}
......@@ -182,7 +188,7 @@ const Okular::DocumentSynopsis * DjVuGenerator::generateDocumentSynopsis()
if ( doc )
{
m_docSyn = new Okular::DocumentSynopsis();
recurseCreateTOC( *m_docSyn, *doc, *m_docSyn );
recurseCreateTOC( *m_docSyn, *doc, *m_docSyn, m_djvu );
}
locker.unlock();
......
......@@ -443,6 +443,8 @@ class KDjVu::Private
void readMetaData( int page );
int pageWithName( const QString & name );
ddjvu_context_t *m_djvu_cxt;
ddjvu_document_t *m_djvu_document;
ddjvu_format_t *m_format;
......@@ -455,6 +457,8 @@ class KDjVu::Private
QHash<QString, QVariant> m_metaData;
QDomDocument * m_docBookmarks;
QHash<QString, int> m_pageNamesCache;
bool m_cacheEnabled;
static unsigned int s_formatmask[4];
......@@ -596,6 +600,23 @@ void KDjVu::Private::readMetaData( int page )
}
}
int KDjVu::Private::pageWithName( const QString & name )
{
const QByteArray utfName = name.toUtf8();
const int fileNum = ddjvu_document_get_filenum( m_djvu_document );
ddjvu_fileinfo_t info;
for ( int i = 0; i < fileNum; ++i )
{
if ( DDJVU_JOB_OK != ddjvu_document_get_fileinfo( m_djvu_document, i, &info ) )
continue;
if ( info.type != 'P' )
continue;
if ( ( utfName == info.id ) || ( utfName == info.name ) || ( utfName == info.title ) )
return info.pageno;
}
return -1;
}
KDjVu::KDjVu() : d( new Private )
{
......@@ -719,6 +740,8 @@ void KDjVu::closeFile()
d->mImgCache.clear();
// clearing the old metadata
d->m_metaData.clear();
// cleaing the page names mapping
d->m_pageNamesCache.clear();
// releasing the old document
if ( d->m_djvu_document )
ddjvu_document_release( d->m_djvu_document );
......@@ -1102,3 +1125,16 @@ bool KDjVu::isCacheEnabled() const
{
return d->m_cacheEnabled;
}
int KDjVu::pageNumber( const QString & name ) const
{
if ( !d->m_djvu_document )
return -1;
QHash< QString, int >::iterator it = d->m_pageNamesCache.find( name );
if ( it == d->m_pageNamesCache.end() )
{
it = d->m_pageNamesCache.insert( name, d->pageWithName( name ) );
}
return it.value();
}
......@@ -284,6 +284,11 @@ class KDjVu
*/
bool isCacheEnabled() const;
/**
* Return the page number of the page whose title is \p name.
*/
int pageNumber( const QString & name ) const;
private:
class Private;
Private * const d;
......
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