finished with bookmark support

svn path=/trunk/KDE/kdegraphics/kdvi/; revision=428113
This commit is contained in:
Stefan Kebekus 2005-06-23 06:56:13 +00:00
parent 64cdf121f2
commit c920c6fccc
4 changed files with 82 additions and 27 deletions

View file

@ -21,6 +21,7 @@
#include <qmessagebox.h>
#include <qpaintdevice.h>
#include <qpainter.h>
#include <qptrstack.h>
#include <qurl.h>
#include <qvbox.h>
@ -337,8 +338,7 @@ void dviRenderer::embedPostScript(void)
preScanTimer.start();
#endif
dviFile->numberOfExternalPSFiles = 0;
bookMarkTitles.clear();
bookMarkAnchors.clear();
prebookmarks.clear();
for(current_page=0; current_page < dviFile->total_pages; current_page++) {
PostScriptOutPutString = new QString();
@ -524,8 +524,7 @@ bool dviRenderer::setFile(const QString &fname)
#endif
dviFile->numberOfExternalPSFiles = 0;
Q_UINT16 currPageSav = current_page;
bookMarkAnchors.clear();
bookMarkTitles.clear();
prebookmarks.clear();
for(current_page=0; current_page < dviFile->total_pages; current_page++) {
PostScriptOutPutString = new QString();
@ -549,24 +548,28 @@ bool dviRenderer::setFile(const QString &fname)
// Generate the list of bookmarks
kdError() << "========================================================" << endl;
kdError() << "bookMarkTitles.size() " << bookMarkTitles.size() << endl;
if (bookMarkTitles.size() != bookMarkAnchors.size())
kdError(4330) << "dviRenderer::setFile(..): Internal corruption in bookmark structures. Disregarding all bookmarks." << endl;
else
for(unsigned int i=0; i<bookMarkTitles.size(); i++) {
Anchor anc = findAnchor(bookMarkAnchors[i]);
if (anc.isValid()) {
Bookmark *bmk = new Bookmark(bookMarkTitles[i], anc);
bookmarks.append(bmk);
} else
kdError() << bookMarkTitles[i] << " has an invalicd anchor" << endl;
}
bookMarkAnchors.clear();
bookMarkTitles.clear();
kdError() << "========================================================" << endl;
QPtrStack<Bookmark> stack;
stack.setAutoDelete (false);
QValueVector<PreBookmark>::iterator it;
for( it = prebookmarks.begin(); it != prebookmarks.end(); ++it ) {
kdError() << (*it).title << " has an count " << (*it).noOfChildren << endl;
Bookmark *bmk = new Bookmark((*it).title, findAnchor((*it).anchorName));
if (stack.isEmpty())
bookmarks.append(bmk);
else {
stack.top()->subordinateBookmarks.append(bmk);
stack.remove();
}
for(int i=0; i<(*it).noOfChildren; i++)
stack.push(bmk);
}
prebookmarks.clear();
#ifdef PERFORMANCE_MEASUREMENT
kdDebug(4300) << "Time required for prescan phase: " << preScanTimer.restart() << "ms" << endl;
#endif

View file

@ -27,6 +27,7 @@
#include "fontpool.h"
#include "infodialog.h"
#include "pageSize.h"
#include "prebookmark.h"
#include "psgs.h"
#include "renderedDocumentPage.h"
@ -190,8 +191,8 @@ private:
void prescan_setChar(unsigned int ch);
/* */
QStringList bookMarkTitles;
QStringList bookMarkAnchors;
QValueVector<PreBookmark> prebookmarks;
/** Utility fields used by the embedPostScript method*/

View file

@ -339,10 +339,12 @@ void dviRenderer::prescan_ParsePSSpecial(QString cp)
l.setLength_in_inch(currinf.data.dvi_v/(resolutionInDPI*shrinkfactor));
anchorList[anchorName] = Anchor(current_page+1, l);
}
if (cp.contains("/Dest") && cp.contains("/Title")) { // The PostScript code defines a bookmark
bookMarkAnchors += cp.section('(', 1, 1).section(')', 0, 0);
bookMarkTitles += cp.section('(', 2, 2).section(')', 0, 0);
}
// The PostScript code defines a bookmark
if (cp.contains("/Dest") && cp.contains("/Title"))
prebookmarks.append(PreBookmark(cp.section('(', 2, 2).section(')', 0, 0),
cp.section('(', 1, 1).section(')', 0, 0),
cp.section('-', 1, 1).section(' ', 0, 0).toUInt()
));
return;
}
}

49
prebookmark.h Normal file
View file

@ -0,0 +1,49 @@
/***************************************************************************
* Copyright (C) 2005 by Stefan Kebekus *
* kebekus@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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _PREBOOKMARK_H_
#define _PREBOOKMARK_H_
#include <qstring.h>
/*! \brief Bookmark representation
This class presents a bookmark in a format that is used internally by
the DVI prescan routines.
*/
class PreBookmark
{
public:
PreBookmark(QString t, QString a, Q_UINT16 n) {title=t; anchorName=a; noOfChildren=n;}
PreBookmark() {title=QString::null; anchorName=QString::null; noOfChildren=0;}
// Title of the bookmark
QString title;
// Name of the anchor
QString anchorName;
// Number of subordinate bookmarks
Q_UINT16 noOfChildren;
};
#endif