예제 #1
0
void TextDocumentGeneratorPrivate::generateTitleInfos()
{
    QStack< QPair<int,QDomNode> > parentNodeStack;

    QDomNode parentNode = mDocumentSynopsis;

    parentNodeStack.push( qMakePair( 0, parentNode ) );

    for ( int i = 0; i < mTitlePositions.count(); ++i ) {
        const TitlePosition &position = mTitlePositions[ i ];

        Okular::DocumentViewport viewport = TextDocumentUtils::calculateViewport( mDocument, position.block );

        QDomElement item = mDocumentSynopsis.createElement( position.title );
        item.setAttribute( QStringLiteral("Viewport"), viewport.toString() );

        int headingLevel = position.level;

        // we need a parent, which has to be at a higher heading level than this heading level
        // so we just work through the stack
        while ( ! parentNodeStack.isEmpty() ) {
            int parentLevel = parentNodeStack.top().first;
            if ( parentLevel < headingLevel ) {
                // this is OK as a parent
                parentNode = parentNodeStack.top().second;
                break;
            } else {
                // we'll need to be further into the stack
                parentNodeStack.pop();
            }
        }
        parentNode.appendChild( item );
        parentNodeStack.push( qMakePair( headingLevel, QDomNode(item) ) );
    }
}
예제 #2
0
static void recurseCreateTOC( QDomDocument &maindoc, const QDomNode &parent, QDomNode &parentDestination, KDjVu *djvu )
{
    QDomNode n = parent.firstChild();
    while( !n.isNull() )
    {
        QDomElement el = n.toElement();

        QDomElement newel = maindoc.createElement( el.attribute( "title" ) );
        parentDestination.appendChild( newel );

        QString dest;
        if ( !( dest = el.attribute( "PageNumber" ) ).isEmpty() )
        {
            Okular::DocumentViewport vp;
            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 );
        }

        if ( el.hasChildNodes() )
        {
            recurseCreateTOC( maindoc, n, newel, djvu );
        }
        n = n.nextSibling();
    }
}
예제 #3
0
 OkularBookmarkAction( const Okular::DocumentViewport& vp, const KBookmark& bk, KBookmarkOwner* owner, QObject *parent )
     : KBookmarkAction( bk, owner, parent )
 {
     if ( vp.isValid() )
         setText( QString::number( vp.pageNumber + 1 ) + QStringLiteral(" - ") + text() );
     setProperty("pageNumber", vp.pageNumber + 1);
     setProperty("htmlRef", bk.url().fragment(QUrl::FullyDecoded));
 }
예제 #4
0
const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
{
    if ( m_docSynopsis )
        return m_docSynopsis;

    m_docSynopsis = new Okular::DocumentSynopsis();

    userMutex()->lock();

    QVector<PreBookmark> prebookmarks = m_dviRenderer->getPrebookmarks();

    userMutex()->unlock();

    if ( prebookmarks.isEmpty() ) 
        return m_docSynopsis;

    QStack<QDomElement> stack;

    QVector<PreBookmark>::ConstIterator it = prebookmarks.constBegin();
    QVector<PreBookmark>::ConstIterator itEnd = prebookmarks.constEnd();
    for( ; it != itEnd; ++it ) 
    {
        QDomElement domel = m_docSynopsis->createElement( (*it).title );
        Anchor a = m_dviRenderer->findAnchor((*it).anchorName);
        if ( a.isValid() )
        {
            Okular::DocumentViewport vp;
 
            const Okular::Page *p = document()->page( a.page - 1 );

            fillViewportFromAnchor( vp, a, (int)p->width(), (int)p->height() );
            domel.setAttribute( "Viewport", vp.toString() );
        }
        if ( stack.isEmpty() )
            m_docSynopsis->appendChild( domel );
        else 
        {
            stack.top().appendChild( domel );
            stack.pop();
        }
        for ( int i = 0; i < (*it).noOfChildren; ++i )
            stack.push( domel );
    }

    return m_docSynopsis;
}
예제 #5
0
 OkularBookmarkAction( const Okular::DocumentViewport& vp, const KBookmark& bk, KBookmarkOwner* owner, QObject *parent )
     : KBookmarkAction( bk, owner, parent )
 {
     if ( vp.isValid() )
         setText( QString::number( vp.pageNumber + 1 ) + " - " + text() );
     setProperty("pageNumber", vp.pageNumber + 1);
     setProperty("htmlRef", bk.url().htmlRef());
 }