preparation for later implementation of asynchronous DVI rendering

svn path=/trunk/kdegraphics/kdvi/; revision=226132
This commit is contained in:
Stefan Kebekus 2003-05-16 07:17:38 +00:00
parent a067ad0235
commit a5096623c2
5 changed files with 178 additions and 144 deletions

View file

@ -69,8 +69,8 @@ dviWindow::dviWindow(double zoom, QWidget *parent, const char *name )
connect( &clearStatusBarTimer, SIGNAL(timeout()), this, SLOT(clearStatusBar()) );
sourceHyperLinkList.reserve(200);
textLinkList.reserve(250);
currentlyDrawnPage.sourceHyperLinkList.reserve(200);
currentlyDrawnPage.textLinkList.reserve(250);
// initialize the dvi machinery
dviFile = 0;
@ -119,7 +119,7 @@ dviWindow::dviWindow(double zoom, QWidget *parent, const char *name )
HTML_href = NULL;
_postscript = 0;
_showHyperLinks = true;
pixmap = 0;
currentlyDrawnPage.pixmap = 0;
findDialog = 0;
findNextAction = 0;
findPrevAction = 0;
@ -147,6 +147,7 @@ dviWindow::dviWindow(double zoom, QWidget *parent, const char *name )
resize(0,0);
}
dviWindow::~dviWindow()
{
#ifdef DEBUG_DVIWIN
@ -155,8 +156,8 @@ dviWindow::~dviWindow()
if (info)
delete info;
if (pixmap)
delete pixmap;
if (currentlyDrawnPage.pixmap)
delete currentlyDrawnPage.pixmap;
delete PS_interface;
if (dviFile)
delete dviFile;
@ -186,20 +187,22 @@ void dviWindow::showInfo(void)
void dviWindow::selectAll(void)
{
QString selectedText("");
for(unsigned int i = 0; i < textLinkList.size(); i++) {
selectedText += textLinkList[i].linkText;
for(unsigned int i = 0; i < currentlyDrawnPage.textLinkList.size(); i++) {
selectedText += currentlyDrawnPage.textLinkList[i].linkText;
selectedText += "\n";
}
DVIselection.set(0, textLinkList.size()-1, selectedText);
DVIselection.set(0, currentlyDrawnPage.textLinkList.size()-1, selectedText);
update();
}
void dviWindow::copyText(void)
{
QApplication::clipboard()->setSelectionMode(false);
QApplication::clipboard()->setText(DVIselection.selectedText);
}
void dviWindow::setShowPS( bool flag )
{
#ifdef DEBUG_DVIWIN
@ -222,21 +225,6 @@ void dviWindow::setShowHyperLinks( bool flag )
drawPage();
}
#ifdef doof
void dviWindow::setMetafontMode( unsigned int mode )
{
#ifdef DEBUG_DVIWIN
kdDebug(4300) << "dviWindow::setMetafontMode( mode=" << mode << " )" << endl;
#endif
MetafontMode = font_pool->setMetafontMode(mode);
#ifdef DEBUG_DVIWIN
kdDebug(4300) << "dviWindow::setMetafontMode, new MetafontMode is at " << MFResolutions[MetafontMode] << " dpi" << endl;
#endif
shrinkfactor = MFResolutions[MetafontMode]/(xres*_zoom);
font_pool->setDisplayResolution( xres*_zoom );
}
#endif
void dviWindow::setPaper(double width_in_cm, double height_in_cm)
{
@ -258,7 +246,10 @@ void dviWindow::drawPage()
kdDebug(4300) << "dviWindow::drawPage()" << endl;
#endif
#ifdef PERFORMANCE_MEASUREMENT
start:
#endif
shrinkfactor = MFResolutions[font_pool->getMetafontMode()]/(xres*_zoom);
setCursor(arrowCursor);
@ -281,19 +272,19 @@ void dviWindow::drawPage()
resize(0, 0);
return;
}
if ( !pixmap )
if ( !currentlyDrawnPage.pixmap )
return;
if ( !pixmap->paintingActive() ) {
if ( !currentlyDrawnPage.pixmap->paintingActive() ) {
// Reset colors
colorStack.clear();
globalColor = Qt::black;
foreGroundPaint.begin( pixmap );
foreGroundPaint.begin( currentlyDrawnPage.pixmap );
QApplication::setOverrideCursor( waitCursor );
errorMsg = QString::null;
draw_page();
foreGroundPaint.drawRect(0,0,pixmap->width(),pixmap->height());
foreGroundPaint.drawRect(0, 0, currentlyDrawnPage.pixmap->width(), currentlyDrawnPage.pixmap->height());
foreGroundPaint.end();
QApplication::restoreOverrideCursor();
if (errorMsg.isEmpty() != true) {
@ -310,7 +301,7 @@ void dviWindow::drawPage()
// a button "Explain in more detail..." which opens the
// Helpcenter. Thus, we practically re-implement the KMessagebox
// here. Most of the code is stolen from there.
if ((dviFile->sourceSpecialMarker == true) && (sourceHyperLinkList.size() > 0)) {
if ((dviFile->sourceSpecialMarker == true) && (currentlyDrawnPage.sourceHyperLinkList.size() > 0)) {
dviFile->sourceSpecialMarker = false;
// Check if the 'Don't show again' feature was used
KConfig *config = kapp->config();
@ -360,7 +351,18 @@ void dviWindow::drawPage()
}
}
}
update();
// WORK IN PROGRESS
/* repaint();
unsigned int current_page_sav = current_page;
qApp->processEvents();
if (current_page_sav == current_page)
emit contents_changed();
*/
repaint();
// update();
emit contents_changed();
#ifdef PERFORMANCE_MEASUREMENT
@ -408,21 +410,21 @@ void dviWindow::changePageSize()
#ifdef DEBUG_DVIWIN
kdDebug(4300) << "dviWindow::changePageSize()" << endl;
#endif
if ( pixmap && pixmap->paintingActive() )
if ( currentlyDrawnPage.pixmap && currentlyDrawnPage.pixmap->paintingActive() )
return;
if (pixmap)
delete pixmap;
if (currentlyDrawnPage.pixmap)
delete currentlyDrawnPage.pixmap;
unsigned int page_width_in_pixel = (unsigned int)(_zoom*paper_width_in_cm/2.54 * xres + 0.5);
unsigned int page_height_in_pixel = (unsigned int)(_zoom*paper_height_in_cm/2.54 * xres + 0.5);
pixmap = new QPixmap( page_width_in_pixel, page_height_in_pixel );
if (pixmap == 0) {
currentlyDrawnPage.pixmap = new QPixmap( page_width_in_pixel, page_height_in_pixel );
if (currentlyDrawnPage.pixmap == 0) {
kdError(4300) << "dviWindow::changePageSize(), no memory for pixmap, width=" << page_width_in_pixel << ", height=" << page_height_in_pixel << endl;
exit(0);
}
pixmap->fill( white );
currentlyDrawnPage.pixmap->fill( white );
resize( page_width_in_pixel, page_height_in_pixel );
@ -451,9 +453,9 @@ bool dviWindow::setFile(QString fname, QString ref, bool sourceMarker)
delete dviFile;
dviFile = 0;
if (pixmap)
delete pixmap;
pixmap = 0;
if (currentlyDrawnPage.pixmap)
delete currentlyDrawnPage.pixmap;
currentlyDrawnPage.pixmap = 0;
resize(0, 0);
return true;
}
@ -669,7 +671,7 @@ void dviWindow::gotoPage(int new_page, int vflashOffset)
animationCounter = 0;
if (timerIdent != 0)
killTimer(timerIdent);
flashOffset = vflashOffset - pixmap->height()/100; // Heuristic correction. Looks better.
flashOffset = vflashOffset - currentlyDrawnPage.pixmap->height()/100; // Heuristic correction. Looks better.
timerIdent = startTimer(50); // Start the animation. The animation proceeds in 1/10s intervals
}
@ -681,7 +683,7 @@ void dviWindow::timerEvent( QTimerEvent *e )
timerIdent = 0;
animationCounter = 0;
}
repaint(0, flashOffset, pixmap->width(), pixmap->height()/19, false);
repaint(0, flashOffset, currentlyDrawnPage.pixmap->width(), currentlyDrawnPage.pixmap->height()/19, false);
}
int dviWindow::totalPages()
@ -712,24 +714,24 @@ double dviWindow::setZoom(double zoom)
void dviWindow::paintEvent(QPaintEvent *e)
{
if (pixmap) {
bitBlt ( this, e->rect().topLeft(), pixmap, e->rect(), CopyROP);
if (currentlyDrawnPage.pixmap) {
bitBlt ( this, e->rect().topLeft(), currentlyDrawnPage.pixmap, e->rect(), CopyROP);
QPainter p(this);
p.setClipRect(e->rect());
if (animationCounter > 0 && animationCounter < 10) {
int wdt = pixmap->width()/(10-animationCounter);
int hgt = pixmap->height()/((10-animationCounter)*20);
int wdt = currentlyDrawnPage.pixmap->width()/(10-animationCounter);
int hgt = currentlyDrawnPage.pixmap->height()/((10-animationCounter)*20);
p.setPen(QPen(QColor(150,0,0), 3, DashLine));
p.drawRect((pixmap->width()-wdt)/2, flashOffset, wdt, hgt);
p.drawRect((currentlyDrawnPage.pixmap->width()-wdt)/2, flashOffset, wdt, hgt);
}
// Mark selected text.
if (DVIselection.selectedTextStart != -1)
for(unsigned int i = DVIselection.selectedTextStart; (i <= DVIselection.selectedTextEnd)&&(i < textLinkList.size()); i++) {
for(unsigned int i = DVIselection.selectedTextStart; (i <= DVIselection.selectedTextEnd)&&(i < currentlyDrawnPage.textLinkList.size()); i++) {
p.setPen( NoPen );
p.setBrush( white );
p.setRasterOp( Qt::XorROP );
p.drawRect(textLinkList[i].box);
p.drawRect(currentlyDrawnPage.textLinkList[i].box);
}
}
}
@ -744,11 +746,11 @@ void dviWindow::mouseMoveEvent ( QMouseEvent * e )
// If no mouse button pressed
if ( e->state() == 0 ) {
// go through hyperlinks
for(unsigned int i=0; i<hyperLinkList.size(); i++) {
if (hyperLinkList[i].box.contains(e->pos())) {
for(unsigned int i=0; i<currentlyDrawnPage.hyperLinkList.size(); i++) {
if (currentlyDrawnPage.hyperLinkList[i].box.contains(e->pos())) {
clearStatusBarTimer.stop();
setCursor(pointingHandCursor);
QString link = hyperLinkList[i].linkText;
QString link = currentlyDrawnPage.hyperLinkList[i].linkText;
if ( link.startsWith("#") )
link = link.remove(0,1);
emit setStatusBarText( i18n("Link to %1").arg(link) );
@ -760,12 +762,12 @@ void dviWindow::mouseMoveEvent ( QMouseEvent * e )
setCursor(arrowCursor);
// But maybe the cursor hovers over a sourceHyperlink?
for(unsigned int i=0; i<sourceHyperLinkList.size(); i++) {
if (sourceHyperLinkList[i].box.contains(e->pos())) {
for(unsigned int i=0; i<currentlyDrawnPage.sourceHyperLinkList.size(); i++) {
if (currentlyDrawnPage.sourceHyperLinkList[i].box.contains(e->pos())) {
clearStatusBarTimer.stop();
KStringHandler kstr;
QString line = kstr.word(sourceHyperLinkList[i].linkText, "0");
QString file = kstr.word(sourceHyperLinkList[i].linkText, "1:");
QString line = kstr.word(currentlyDrawnPage.sourceHyperLinkList[i].linkText, "0");
QString file = kstr.word(currentlyDrawnPage.sourceHyperLinkList[i].linkText, "1:");
emit setStatusBarText( i18n("Link to line %1 of %2").arg(line).arg(file) );
return;
}
@ -793,8 +795,8 @@ void dviWindow::mouseMoveEvent ( QMouseEvent * e )
Q_INT32 selectedTextStart = -1;
Q_INT32 selectedTextEnd = -1;
for(unsigned int i=0; i<textLinkList.size(); i++)
if ( selectedRectangle.intersects(textLinkList[i].box) ) {
for(unsigned int i=0; i<currentlyDrawnPage.textLinkList.size(); i++)
if ( selectedRectangle.intersects(currentlyDrawnPage.textLinkList[i].box) ) {
if (selectedTextStart == -1)
selectedTextStart = i;
selectedTextEnd = i;
@ -802,8 +804,8 @@ void dviWindow::mouseMoveEvent ( QMouseEvent * e )
QString selectedText("");
if (selectedTextStart != -1)
for(unsigned int i = selectedTextStart; (i <= selectedTextEnd)&&(i < textLinkList.size()); i++) {
selectedText += textLinkList[i].linkText;
for(unsigned int i = selectedTextStart; (i <= selectedTextEnd)&&(i < currentlyDrawnPage.textLinkList.size()); i++) {
selectedText += currentlyDrawnPage.textLinkList[i].linkText;
selectedText += "\n";
}
@ -828,13 +830,13 @@ void dviWindow::mouseMoveEvent ( QMouseEvent * e )
int i=i1;
while(i<i2) {
if (i != -1)
box = box.unite(textLinkList[i].box);
box = box.unite(currentlyDrawnPage.textLinkList[i].box);
i++;
}
for(int i=i3; i<i4; i++)
if (i != -1)
box = box.unite(textLinkList[i].box);
box = box.unite(currentlyDrawnPage.textLinkList[i].box);
DVIselection.set(selectedTextStart, selectedTextEnd, selectedText);
update(box);
}
@ -842,11 +844,13 @@ void dviWindow::mouseMoveEvent ( QMouseEvent * e )
}
}
void dviWindow::mouseReleaseEvent ( QMouseEvent * )
{
selectedRectangle.setRect(0,0,0,0);
}
void dviWindow::mousePressEvent ( QMouseEvent * e )
{
#ifdef DEBUG_SPECIAL
@ -854,14 +858,14 @@ void dviWindow::mousePressEvent ( QMouseEvent * e )
#endif
// Check if the mouse is pressed on a regular hyperlink
if ((e->button() == LeftButton) && (hyperLinkList.size() > 0))
for(int i=0; i<hyperLinkList.size(); i++) {
if (hyperLinkList[i].box.contains(e->pos())) {
if (hyperLinkList[i].linkText[0] == '#' ) {
if ((e->button() == LeftButton) && (currentlyDrawnPage.hyperLinkList.size() > 0))
for(int i=0; i<currentlyDrawnPage.hyperLinkList.size(); i++) {
if (currentlyDrawnPage.hyperLinkList[i].box.contains(e->pos())) {
if (currentlyDrawnPage.hyperLinkList[i].linkText[0] == '#' ) {
#ifdef DEBUG_SPECIAL
kdDebug(4300) << "hit: local link to " << hyperLinkList[i].linkText << endl;
kdDebug(4300) << "hit: local link to " << currentlyDrawnPage.hyperLinkList[i].linkText << endl;
#endif
QString locallink = hyperLinkList[i].linkText.mid(1); // Drop the '#' at the beginning
QString locallink = currentlyDrawnPage.hyperLinkList[i].linkText.mid(1); // Drop the '#' at the beginning
QMap<QString,DVI_Anchor>::Iterator it = anchorList.find(locallink);
if (it != anchorList.end()) {
#ifdef DEBUG_SPECIAL
@ -872,14 +876,14 @@ void dviWindow::mousePressEvent ( QMouseEvent * e )
}
} else {
#ifdef DEBUG_SPECIAL
kdDebug(4300) << "hit: external link to " << hyperLinkList[i].linkText << endl;
kdDebug(4300) << "hit: external link to " << currentlyDrawnPage.hyperLinkList[i].linkText << endl;
#endif
// We could in principle use KIO::Netaccess::run() here, but
// it is perhaps not a very good idea to allow a DVI-file to
// specify arbitrary commands, such as "rm -rvf /". Using
// the kfmclient seems to be MUCH safer.
QUrl DVI_Url(dviFile->filename);
QUrl Link_Url(DVI_Url, hyperLinkList[i].linkText, TRUE );
QUrl Link_Url(DVI_Url, currentlyDrawnPage.hyperLinkList[i].linkText, TRUE );
QStringList args;
args << "openURL";
@ -891,14 +895,14 @@ void dviWindow::mousePressEvent ( QMouseEvent * e )
}
// Check if the mouse is pressed on a source-hyperlink
if ((e->button() == MidButton) && (sourceHyperLinkList.size() > 0))
for(unsigned int i=0; i<sourceHyperLinkList.size(); i++)
if (sourceHyperLinkList[i].box.contains(e->pos())) {
if ((e->button() == MidButton) && (currentlyDrawnPage.sourceHyperLinkList.size() > 0))
for(unsigned int i=0; i<currentlyDrawnPage.sourceHyperLinkList.size(); i++)
if (currentlyDrawnPage.sourceHyperLinkList[i].box.contains(e->pos())) {
#ifdef DEBUG_SPECIAL
kdDebug(4300) << "Source hyperlink to " << sourceHyperLinkList[i].linkText << endl;
kdDebug(4300) << "Source hyperlink to " << currentlyDrawnPage.sourceHyperLinkList[i].linkText << endl;
#endif
QString cp = sourceHyperLinkList[i].linkText;
QString cp = currentlyDrawnPage.sourceHyperLinkList[i].linkText;
int max = cp.length();
int i;
for(i=0; i<max; i++)

View file

@ -4,9 +4,8 @@
// Widget for displaying TeX DVI files.
// Part of KDVI- A previewer for TeX DVI files.
//
// (C) 2001 Stefan Kebekus
// Distributed under the GPL
//
// (C) 2001-2003 Stefan Kebekus. Distributed under the GPL.
#ifndef _dviwin_h_
#define _dviwin_h_
@ -39,10 +38,6 @@ class TeXFontDefinition;
extern const int MFResolutions[];
// If this is defined, KDVI will emitt debugging messages to tell how
// long certain tasks take
class DVI_Hyperlink {
public:
DVI_Hyperlink() {}
@ -101,6 +96,26 @@ struct drawinf {
};
// This class contains everything one needs dviwin needs to know about
// a certain page.
class pageData
{
public:
Q_UINT16 pageNumber;
QPixmap *pixmap;
// List of source-hyperlinks in the current page. This vector is
// generated when the current page is drawn.
QValueVector<DVI_Hyperlink> sourceHyperLinkList;
QValueVector<DVI_Hyperlink> textLinkList; // List of text in the window
QValueVector<DVI_Hyperlink> hyperLinkList; // List of ordinary hyperlinks
};
class dviWindow : public QWidget, bigEndianByteReader
{
Q_OBJECT
@ -128,7 +143,7 @@ public:
bool correctDVI(QString filename);
// for the preview
QPixmap *pix() { return pixmap; };
QPixmap *pix() { return currentlyDrawnPage.pixmap; };
// These should not be public... only for the moment
void mousePressEvent ( QMouseEvent * e );
@ -161,7 +176,7 @@ public:
selection DVIselection;
/** Reference part of the URL which describes the filename. */
QString reference;
QString reference;
QString searchText;
KAction *findNextAction;
@ -245,9 +260,8 @@ private:
*this. */
QTimer clearStatusBarTimer;
// List of source-hyperlinks in the current page. This vector is
// generated when the current page is drawn.
QValueVector<DVI_Hyperlink> sourceHyperLinkList;
pageData currentlyDrawnPage;
// List of source-hyperlinks on all pages. This vector is generated
// when the DVI-file is first loaded, i.e. when draw_part is called
@ -258,9 +272,6 @@ private:
// hyperlink to the (relative) URL given in the string;
QString *source_href;
QValueVector<DVI_Hyperlink> textLinkList; // List of text in the window
QValueVector<DVI_Hyperlink> hyperLinkList; // List of ordinary hyperlinks
// If not NULL, the text currently drawn represents a hyperlink to
// the (relative) URL given in the string;
QString *HTML_href;
@ -319,7 +330,6 @@ private:
double fontPixelPerDVIunit() {return dviFile->cmPerDVIunit * MFResolutions[font_pool->getMetafontMode()]/2.54;};
QPixmap *pixmap;
int ChangesPossible;
unsigned int current_page;

View file

@ -107,10 +107,10 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
dhl.baseline = currinf.data.pxl_v;
dhl.box.setRect(x, y, pix.width(), pix.height());
dhl.linkText = *HTML_href;
hyperLinkList.push_back(dhl);
currentlyDrawnPage.hyperLinkList.push_back(dhl);
} else {
QRect dshunion = hyperLinkList[hyperLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;
hyperLinkList[hyperLinkList.size()-1].box = dshunion;
QRect dshunion = currentlyDrawnPage.hyperLinkList[currentlyDrawnPage.hyperLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;
currentlyDrawnPage.hyperLinkList[currentlyDrawnPage.hyperLinkList.size()-1].box = dshunion;
}
}
@ -128,15 +128,15 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
dhl.linkText = *source_href;
else
dhl.linkText = "";
sourceHyperLinkList.push_back(dhl);
currentlyDrawnPage.sourceHyperLinkList.push_back(dhl);
} else {
QRect dshunion = sourceHyperLinkList[sourceHyperLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;
sourceHyperLinkList[sourceHyperLinkList.size()-1].box = dshunion;
QRect dshunion = currentlyDrawnPage.sourceHyperLinkList[currentlyDrawnPage.sourceHyperLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;
currentlyDrawnPage.sourceHyperLinkList[currentlyDrawnPage.sourceHyperLinkList.size()-1].box = dshunion;
}
}
// Code for DVI -> text functions (e.g. marking of text, full text
// search, etc.). Set up the textLinkList.
// search, etc.). Set up the currentlyDrawnPage.textLinkList.
if (line_boundary_encountered == true) {
// Set up source hyperlinks
DVI_Hyperlink link;
@ -144,50 +144,50 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
link.box.setRect(x, y, pix.width(), pix.height());
link.linkText = "";
textLinkList.push_back(link);
currentlyDrawnPage.textLinkList.push_back(link);
} else { // line boundary encountered
QRect dshunion = textLinkList[textLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;
textLinkList[textLinkList.size()-1].box = dshunion;
QRect dshunion = currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].box = dshunion;
}
switch(ch) {
case 0x0b:
textLinkList[textLinkList.size()-1].linkText += "ff";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "ff";
break;
case 0x0c:
textLinkList[textLinkList.size()-1].linkText += "fi";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "fi";
break;
case 0x0d:
textLinkList[textLinkList.size()-1].linkText += "fl";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "fl";
break;
case 0x0e:
textLinkList[textLinkList.size()-1].linkText += "ffi";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "ffi";
break;
case 0x0f:
textLinkList[textLinkList.size()-1].linkText += "ffl";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "ffl";
break;
case 0x7b:
textLinkList[textLinkList.size()-1].linkText += "-";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "-";
break;
case 0x7c:
textLinkList[textLinkList.size()-1].linkText += "---";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "---";
break;
case 0x7d:
textLinkList[textLinkList.size()-1].linkText += "\"";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "\"";
break;
case 0x7e:
textLinkList[textLinkList.size()-1].linkText += "~";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "~";
break;
case 0x7f:
textLinkList[textLinkList.size()-1].linkText += "@@"; // @@@ check!
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "@@"; // @@@ check!
break;
default:
if ((ch >= 0x21) && (ch <= 0x7a))
textLinkList[textLinkList.size()-1].linkText += QChar(ch);
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += QChar(ch);
else
textLinkList[textLinkList.size()-1].linkText += "?";
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += "?";
break;
}
}
@ -397,8 +397,8 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
((RRtmp >= currinf.fontp->scaled_size_in_DVI_units/6) || (RRtmp <= -4*(currinf.fontp->scaled_size_in_DVI_units/6))) &&
(textLinkList.size() > 0))
textLinkList[textLinkList.size()-1].linkText += ' ';
(currentlyDrawnPage.textLinkList.size() > 0))
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += ' ';
currinf.data.dvi_h += ((long) (RRtmp * current_dimconv));
break;
@ -412,8 +412,8 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
((WWtmp >= currinf.fontp->scaled_size_in_DVI_units/6) || (WWtmp <= -4*(currinf.fontp->scaled_size_in_DVI_units/6))) &&
(textLinkList.size() > 0) )
textLinkList[textLinkList.size()-1].linkText += ' ';
(currentlyDrawnPage.textLinkList.size() > 0) )
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += ' ';
currinf.data.dvi_h += currinf.data.w;
break;
@ -427,8 +427,8 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
((XXtmp >= currinf.fontp->scaled_size_in_DVI_units/6) || (XXtmp <= -4*(currinf.fontp->scaled_size_in_DVI_units/6))) &&
(textLinkList.size() > 0))
textLinkList[textLinkList.size()-1].linkText += ' ';
(currentlyDrawnPage.textLinkList.size() > 0))
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += ' ';
currinf.data.dvi_h += currinf.data.x;
break;
@ -441,11 +441,11 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
(abs(DDtmp) >= 5*(currinf.fontp->scaled_size_in_DVI_units/6)) &&
(textLinkList.size() > 0)) {
(currentlyDrawnPage.textLinkList.size() > 0)) {
word_boundary_encountered = true;
line_boundary_encountered = true;
if (abs(DDtmp) >= 10*(currinf.fontp->scaled_size_in_DVI_units/6))
textLinkList[textLinkList.size()-1].linkText += '\n';
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += '\n';
}
currinf.data.dvi_v += ((long) (DDtmp * current_dimconv))/65536;
currinf.data.pxl_v = int(currinf.data.dvi_v/shrinkfactor);
@ -462,11 +462,11 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
(abs(YYtmp) >= 5*(currinf.fontp->scaled_size_in_DVI_units/6)) &&
(textLinkList.size() > 0)) {
(currentlyDrawnPage.textLinkList.size() > 0)) {
word_boundary_encountered = true;
line_boundary_encountered = true;
if (abs(YYtmp) >= 10*(currinf.fontp->scaled_size_in_DVI_units/6))
textLinkList[textLinkList.size()-1].linkText += '\n';
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += '\n';
}
currinf.data.dvi_v += currinf.data.y/65536;
currinf.data.pxl_v = int(currinf.data.dvi_v/shrinkfactor);
@ -482,11 +482,11 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
(abs(ZZtmp) >= 5*(currinf.fontp->scaled_size_in_DVI_units/6)) &&
(textLinkList.size() > 0)) {
(currentlyDrawnPage.textLinkList.size() > 0)) {
word_boundary_encountered = true;
line_boundary_encountered = true;
if (abs(ZZtmp) >= 10*(currinf.fontp->scaled_size_in_DVI_units/6))
textLinkList[textLinkList.size()-1].linkText += '\n';
currentlyDrawnPage.textLinkList[currentlyDrawnPage.textLinkList.size()-1].linkText += '\n';
}
currinf.data.dvi_v += currinf.data.z/65536;
currinf.data.pxl_v = int(currinf.data.dvi_v/shrinkfactor);
@ -560,14 +560,14 @@ void dviWindow::draw_page(void)
// Reset a couple of variables
HTML_href = 0;
source_href = 0;
hyperLinkList.clear();
currentlyDrawnPage.hyperLinkList.clear();
// Calling resize() here rather than clear() means that the memory
// taken up by the vector is not freed. This is faster than
// constantly allocating/freeing memory.
textLinkList.resize(0);
sourceHyperLinkList.resize(0);
currentlyDrawnPage.textLinkList.resize(0);
currentlyDrawnPage.sourceHyperLinkList.resize(0);
// Check if all the fonts are loaded. If that is not the case, we
// return and do not draw anything. The font_pool will later emit
@ -591,7 +591,7 @@ void dviWindow::draw_page(void)
kdDebug() <<"draw_page" << endl;
#endif
foreGroundPaint.fillRect(pixmap->rect(), PS_interface->getBackgroundColor(current_page) );
foreGroundPaint.fillRect(currentlyDrawnPage.pixmap->rect(), PS_interface->getBackgroundColor(current_page) );
// Render the PostScript background, if there is one.
if (_postscript) {
@ -629,10 +629,10 @@ void dviWindow::draw_page(void)
// one pixel.
int h = (int)(MFResolutions[font_pool->getMetafontMode()]*0.05/(2.54*shrinkfactor) + 0.5);
h = (h < 1) ? 1 : h;
for(unsigned int i=0; i<hyperLinkList.size(); i++) {
int x = hyperLinkList[i].box.left();
int w = hyperLinkList[i].box.width();
int y = hyperLinkList[i].baseline;
for(unsigned int i=0; i<currentlyDrawnPage.hyperLinkList.size(); i++) {
int x = currentlyDrawnPage.hyperLinkList[i].box.left();
int w = currentlyDrawnPage.hyperLinkList[i].box.width();
int y = currentlyDrawnPage.hyperLinkList[i].baseline;
foreGroundPaint.fillRect(x, y, w, h, Qt::blue);
}
}

View file

@ -2,7 +2,7 @@
// Class: dviWindow
// Author: Stefan Kebekus
//
// (C) 2001, Stefan Kebekus.
// (C) 2001-2003, Stefan Kebekus.
//
// Previewer for TeX DVI files.
//
@ -50,7 +50,7 @@ void dviWindow::exportText(void)
return;
if (dviFile->dvi_Data == 0 )
return;
if (pixmap->paintingActive())
if (currentlyDrawnPage.pixmap->paintingActive())
return;
if (KMessageBox::warningContinueCancel( this,
@ -106,8 +106,8 @@ void dviWindow::exportText(void)
draw_page(); // We gracefully ingore any errors (bad dvi-file, etc.) which may occur during draw_page()
foreGroundPaint.end();
for(unsigned int i=0; i<textLinkList.size(); i++)
stream << textLinkList[i].linkText << endl;
for(unsigned int i=0; i<currentlyDrawnPage.textLinkList.size(); i++)
stream << currentlyDrawnPage.textLinkList[i].linkText << endl;
}
// Switch off the progress dialog, etc.

View file

@ -1,9 +1,29 @@
//
// Class: dviWindow
// Author: Stefan Kebekus
//
// (C) 2001-2003, Stefan Kebekus.
//
// Previewer for TeX DVI files.
//
// 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.
//
// Please report bugs or improvements, etc. via the "Report bug"-Menu
// of kdvi.
#include <qapplication.h>
#include <qpainter.h>
@ -90,16 +110,16 @@ void dviWindow::findNextText(void)
// Go trough the text of the current page and search for the
// string.
for(unsigned int i=DVIselection.selectedTextStart+1; i<textLinkList.size(); i++)
if (textLinkList[i].linkText.find(searchText, 0, case_sensitive) >= 0) {
for(unsigned int i=DVIselection.selectedTextStart+1; i<currentlyDrawnPage.textLinkList.size(); i++)
if (currentlyDrawnPage.textLinkList[i].linkText.find(searchText, 0, case_sensitive) >= 0) {
// Restore the previous settings, including the current
// page. Otherwise, the program is "smart enough" not to
// re-render the screen.
_postscript = _postscript_sav;
int j = current_page;
current_page = current_page_sav;
emit(request_goto_page(j, textLinkList[i].box.bottom() ));
DVIselection.set(i, i, textLinkList[i].linkText);
emit(request_goto_page(j, currentlyDrawnPage.textLinkList[i].box.bottom() ));
DVIselection.set(i, i, currentlyDrawnPage.textLinkList[i].linkText);
repaint();
return;
}
@ -217,17 +237,17 @@ void dviWindow::findPrevText(void)
// string.
int i=DVIselection.selectedTextStart-1;
if (i < 0)
i = textLinkList.size()-1;
i = currentlyDrawnPage.textLinkList.size()-1;
while(i >= 0) {
if (textLinkList[i].linkText.find(searchText, 0, case_sensitive) >= 0) {
if (currentlyDrawnPage.textLinkList[i].linkText.find(searchText, 0, case_sensitive) >= 0) {
// Restore the previous settings, including the current
// page. Otherwise, the program is "smart enough" not to
// re-render the screen.
_postscript = _postscript_sav;
int j = current_page;
current_page = current_page_sav;
emit(request_goto_page(j, textLinkList[i].box.bottom() ));
DVIselection.set(i, i, textLinkList[i].linkText);
emit(request_goto_page(j, currentlyDrawnPage.textLinkList[i].box.bottom() ));
DVIselection.set(i, i, currentlyDrawnPage.textLinkList[i].linkText);
repaint();
return;
}