fixed crash on bad config-files

svn path=/trunk/kdegraphics/kdvi/; revision=69818
remotes/origin/kdvi-2.1
Stefan Kebekus 26 years ago
parent 1aadd46760
commit e192fd02a8
  1. 26
      dviwin.cpp
  2. 4
      dviwin.h
  3. 14
      glyph.cpp
  4. 12
      kdvi_multipage.cpp

@ -139,9 +139,19 @@ dviWindow::dviWindow( int bdpi, double zoom, const QString & mfm, int mkpk, QWid
Display *DISP = x11Display();
xres = ((double)(DisplayWidth(DISP,(int)DefaultScreen(DISP)) *25.4) /
DisplayWidthMM(DISP,(int)DefaultScreen(DISP)) );
// Just to make sure that we are never dividing by zero.
if ((xres < 10)||(xres > 1000))
xres = 75.0;
// In principle, this method should never be called with illegal
// values for zoom. In principle.
if (zoom < KViewPart::minZoom/1000.0)
zoom = KViewPart::minZoom/1000.0;
if (zoom > KViewPart::maxZoom/1000.0)
zoom = KViewPart::maxZoom/1000.0;
mane.shrinkfactor = currwin.shrinkfactor = (double)basedpi/(xres*zoom);
_zoom = zoom;
PS_interface = new ghostscript_interface(0.0, 0, 0);
is_current_page_drawn = 0;
n_files_left = OPEN_MAX;
@ -459,8 +469,15 @@ int dviWindow::totalPages()
}
void dviWindow::setZoom(double zoom)
double dviWindow::setZoom(double zoom)
{
// In principle, this method should never be called with illegal
// values. In principle.
if (zoom < KViewPart::minZoom/1000.0)
zoom = KViewPart::minZoom/1000.0;
if (zoom > KViewPart::maxZoom/1000.0)
zoom = KViewPart::maxZoom/1000.0;
mane.shrinkfactor = currwin.shrinkfactor = basedpi/(xres*zoom);
_zoom = zoom;
@ -469,6 +486,7 @@ void dviWindow::setZoom(double zoom)
reset_fonts();
changePageSize();
return _zoom;
}
@ -495,9 +513,11 @@ void dviWindow::mousePressEvent ( QMouseEvent * e )
QString locallink = hyperLinkList[i].linkText.mid(1); // Drop the '#' at the beginning
for(int j=0; j<numAnchors; j++) {
if (locallink.compare(AnchorList_String[j]) == 0) {
#ifdef DEBUG_SPECIAL
kdDebug() << "hit: local link to y=" << AnchorList_Vert[j] << endl;
kdDebug() << "hit: local link to sf=" << mane.shrinkfactor << endl;
emit(request_goto_page(AnchorList_Page[j], AnchorList_Vert[j]/mane.shrinkfactor));
#endif
emit(request_goto_page(AnchorList_Page[j], (int)(AnchorList_Vert[j]/mane.shrinkfactor)));
break;
}
}

@ -17,6 +17,8 @@
#include <qintdict.h>
#include <qvector.h>
#include <kviewpart.h>
#include "psgs.h"
#include "dvi_init.h"
@ -97,7 +99,7 @@ public:
public slots:
void setFile(const QString & fname);
void gotoPage(int page);
void setZoom(double zoom);
double setZoom(double zoom);
double zoom() { return _zoom; };
signals:

@ -12,9 +12,11 @@
#include <stdlib.h>
#include <qpainter.h>
#include <qbitmap.h>
#include <qimage.h>
#include <qpainter.h>
#include <kdebug.h>
glyph::~glyph()
{
@ -94,16 +96,22 @@ QPixmap glyph::shrunkCharacter()
// Now shrinking may begin. Produce a QBitmap with the unshrunk
// character.
QBitmap bm(bitmap.bytes_wide*8, (int)bitmap.h, (const uchar *)(bitmap.bits) ,TRUE);
// ... turn it into a Pixmap (highly inefficient, please improve)
SmallChar = new QPixmap(bitmap.w+pre_cols+post_cols, bitmap.h+pre_rows+post_rows);
if (SmallChar == 0)
return 0;
if (SmallChar->isNull()) {
delete SmallChar;
SmallChar = 0;
return 0;
}
QPainter paint(SmallChar);
paint.setBackgroundColor(Qt::white);
paint.setPen( Qt::black );
paint.fillRect(0,0,bitmap.w+pre_cols+post_cols, bitmap.h+pre_rows+post_rows, Qt::white);
paint.drawPixmap(pre_cols, pre_rows, bm);
paint.end();
// Generate an Image and shrink it to the proper size. By the
// documentation of smoothScale, the resulting Image will be
// 8-bit.

@ -21,6 +21,7 @@
#include "print.h"
#include "optiondialog.h"
#include "kdvi_multipage.moc"
#include "kviewpart.h"
#include <config.h>
extern "C"
@ -74,7 +75,7 @@ KDVIMultiPage::KDVIMultiPage(QWidget *parentWidget, const char *widgetName, QObj
window = new dviWindow(300, 1.0, "cx", true, scrollView());
preferencesChanged();
new KAction(i18n("&DVI Options..."), 0, this,
new KAction(i18n("&DVI Options"), 0, this,
SLOT(doSettings()), actionCollection(),
"settings_dvi");
@ -159,10 +160,15 @@ void KDVIMultiPage::goto_page(int page, int y)
double KDVIMultiPage::setZoom(double zoom)
{
window->setZoom(zoom);
if (zoom < KViewPart::minZoom/1000.0)
zoom = KViewPart::minZoom/1000.0;
if (zoom > KViewPart::maxZoom/1000.0)
zoom = KViewPart::maxZoom/1000.0;
double z = window->setZoom(zoom);
scrollView()->resizeContents(window->width(), window->height());
return zoom;
return z;
}

Loading…
Cancel
Save