From c920c6fcccc839f2a62a2e23ea6dbac487d48be7 Mon Sep 17 00:00:00 2001 From: Stefan Kebekus Date: Thu, 23 Jun 2005 06:56:13 +0000 Subject: [PATCH] finished with bookmark support svn path=/trunk/KDE/kdegraphics/kdvi/; revision=428113 --- dviRenderer.cpp | 41 ++++++++++++++++++---------------- dviRenderer.h | 5 +++-- dviRenderer_prescan.cpp | 10 +++++---- prebookmark.h | 49 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 prebookmark.h diff --git a/dviRenderer.cpp b/dviRenderer.cpp index ba89a9b24..7942bfa69 100644 --- a/dviRenderer.cpp +++ b/dviRenderer.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -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 stack; + stack.setAutoDelete (false); + + QValueVector::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(); } - bookMarkAnchors.clear(); - bookMarkTitles.clear(); + 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 diff --git a/dviRenderer.h b/dviRenderer.h index 88241e2a9..46ff28810 100644 --- a/dviRenderer.h +++ b/dviRenderer.h @@ -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 prebookmarks; + /** Utility fields used by the embedPostScript method*/ diff --git a/dviRenderer_prescan.cpp b/dviRenderer_prescan.cpp index 38b34f181..ae3bb59b4 100644 --- a/dviRenderer_prescan.cpp +++ b/dviRenderer_prescan.cpp @@ -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; } } diff --git a/prebookmark.h b/prebookmark.h new file mode 100644 index 000000000..a65ce657d --- /dev/null +++ b/prebookmark.h @@ -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 + +/*! \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