source code cleanup: removed static variables

svn path=/trunk/kdegraphics/kdvi/; revision=207903
This commit is contained in:
Stefan Kebekus 2003-02-19 12:54:27 +00:00
parent 159fbe04e7
commit c43d971690
6 changed files with 92 additions and 123 deletions

View file

@ -57,12 +57,7 @@
struct WindowRec mane = {(Window) 0, 3, 0, 0, 0, 0, MAXDIM, 0, MAXDIM, 0};
struct WindowRec currwin = {(Window) 0, 3, 0, 0, 0, 0, MAXDIM, 0, MAXDIM, 0};
extern struct WindowRec alt;
struct drawinf currinf;
// The following are really used
unsigned int page_w;
unsigned int page_h;
// end of "really used"
QPainter foreGroundPaint; // QPainter used for text
@ -124,8 +119,8 @@ dviWindow::dviWindow(double zoom, int mkpk, QWidget *parent, const char *name )
zoom = ZoomLimits::MaxZoom/1000.0;
_zoom = zoom;
paper_width = 21.0; // set A4 paper as default
paper_height = 27.9;
paper_width_in_cm = 21.0; // set A4 paper as default
paper_height_in_cm = 27.9;
PostScriptOutPutString = NULL;
HTML_href = NULL;
@ -257,22 +252,17 @@ void dviWindow::setMetafontMode( unsigned int mode )
basedpi = MFResolutions[MetafontMode];
mane.shrinkfactor = currwin.shrinkfactor = basedpi/(xres*_zoom);
font_pool->setShrinkFactor(currwin.shrinkfactor);
setPaper( paper_width, paper_height);
}
void dviWindow::setPaper(double w, double h)
void dviWindow::setPaper(double width_in_cm, double height_in_cm)
{
#ifdef DEBUG_DVIWIN
kdDebug(4300) << "dviWindow::setPaper( w=" << w << ", h=" << h << " )" << endl;
kdDebug(4300) << "dviWindow::setPaper( width_in_cm=" << width_in_cm << ", height_in_cm=" << height_in_cm << " )" << endl;
#endif
paper_width = w;
paper_height = h;
unshrunk_page_w = int( w * basedpi/2.54 + 0.5 );
unshrunk_page_h = int( h * basedpi/2.54 + 0.5 );
page_w = (int)(unshrunk_page_w / mane.shrinkfactor + 0.5) + 2;
page_h = (int)(unshrunk_page_h / mane.shrinkfactor + 0.5) + 2;
paper_width_in_cm = width_in_cm;
paper_height_in_cm = height_in_cm;
changePageSize();
}
@ -421,17 +411,20 @@ void dviWindow::changePageSize()
if (pixmap)
delete pixmap;
pixmap = new QPixmap( (int)page_w, (int)page_h );
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) {
kdError(4300) << "dviWindow::changePageSize(), no memory for pixmap, page_w=" << (int)page_w << ", page_h =" << (int)page_h << endl;
kdError(4300) << "dviWindow::changePageSize(), no memory for pixmap, width=" << page_width_in_pixel << ", height=" << page_height_in_pixel << endl;
exit(0);
}
pixmap->fill( white );
resize( page_w, page_h );
resize( page_width_in_pixel, page_height_in_pixel );
currwin.win = mane.win = pixmap->handle();
PS_interface->setSize( basedpi/mane.shrinkfactor, page_w, page_h );
PS_interface->setSize( basedpi/mane.shrinkfactor, page_width_in_pixel, page_height_in_pixel );
drawPage();
}
@ -506,9 +499,6 @@ bool dviWindow::setFile(QString fname, QString ref, bool sourceMarker)
if (info != 0)
info->setDVIData(dviFile);
page_w = (int)(unshrunk_page_w / mane.shrinkfactor + 0.5) + 2;
page_h = (int)(unshrunk_page_h / mane.shrinkfactor + 0.5) + 2;
// Extract PostScript from the DVI file, and store the PostScript
// specials in PostScriptDirectory, and the headers in the
// PostScriptHeaderString.
@ -680,9 +670,6 @@ double dviWindow::setZoom(double zoom)
mane.shrinkfactor = currwin.shrinkfactor = basedpi/(xres*zoom);
_zoom = zoom;
page_w = (int)(unshrunk_page_w / mane.shrinkfactor + 0.5) + 2;
page_h = (int)(unshrunk_page_h / mane.shrinkfactor + 0.5) + 2;
font_pool->setShrinkFactor(currwin.shrinkfactor);
changePageSize();
return _zoom;

View file

@ -83,6 +83,19 @@ struct framedata {
};
/* this information is saved when using virtual fonts */
typedef void (dviWindow::*set_char_proc)(unsigned int, unsigned int);
struct drawinf {
struct framedata data;
struct font *fontp;
set_char_proc set_char_p;
QIntDict<struct font> fonttable;
struct font *_virtual;
};
class dviWindow : public QWidget, bigEndianByteReader
{
Q_OBJECT
@ -137,8 +150,8 @@ public:
class fontPool *font_pool;
double xres; // horizontal resolution of the display device in dots per inch.
double paper_width; // paper width in centimeters
double paper_height; // paper height in centimeters
double paper_width_in_cm; // paper width in centimeters
double paper_height_in_cm; // paper height in centimeters
selection DVIselection;
@ -264,11 +277,6 @@ private:
QPoint firstSelectedPoint;
QRect selectedRectangle;
/** These fields contain information about the geometry of the
page. */
unsigned int unshrunk_page_w; // basedpi * width(in inch)
unsigned int unshrunk_page_h; // basedpi * height(in inch)
infoDialog *info;
/** If PostScriptOutPutFile is non-zero, then no rendering takes
@ -307,6 +315,8 @@ private:
/** Indicates if the current page is already drawn (=1) or not
(=0). */
char is_current_page_drawn;
// Zoom factor. 1.0 means "100%"
double _zoom;
/** Used to run and to show the progress of dvips and friends. */
@ -316,6 +326,8 @@ private:
QString export_fileName;
QString export_tmpFileName;
QString export_errorString;
struct drawinf currinf;
};
@ -339,20 +351,7 @@ struct WindowRec {
typedef void (dviWindow::*set_char_proc)(unsigned int, unsigned int);
#include "font.h"
/* this information is saved when using virtual fonts */
struct drawinf {
struct framedata data;
struct font *fontp;
set_char_proc set_char_p;
QIntDict<struct font> fonttable;
struct font *_virtual;
};
#undef Unsorted
#endif

View file

@ -82,11 +82,11 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
if (g == NULL)
return;
long dvi_h_sav = DVI_H;
long dvi_h_sav = currinf.data.dvi_h;
if (PostScriptOutPutString == NULL) {
QPixmap pix = currinf.fontp->characterPixmap(ch);
int x = PXL_H - g->x2 - currwin.base_x;
int y = PXL_V - g->y2 - currwin.base_y;
int x = ((int) ((currinf.data.dvi_h) / (currwin.shrinkfactor * 65536))) - g->x2 - currwin.base_x;
int y = currinf.data.pxl_v - g->y2 - currwin.base_y;
// Draw the character.
foreGroundPaint.drawPixmap(x, y, pix);
@ -99,7 +99,7 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
if (line_boundary_encountered == true) {
// Set up hyperlink
DVI_Hyperlink dhl;
dhl.baseline = PXL_V;
dhl.baseline = currinf.data.pxl_v;
dhl.box.setRect(x, y, pix.width(), pix.height());
dhl.linkText = *HTML_href;
hyperLinkList.push_back(dhl);
@ -117,7 +117,7 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
if (line_boundary_encountered == true) {
// Set up source hyperlinks
DVI_Hyperlink dhl;
dhl.baseline = PXL_V;
dhl.baseline = currinf.data.pxl_v;
dhl.box.setRect(x, y, pix.width(), pix.height());
if (source_href != NULL)
dhl.linkText = *source_href;
@ -135,7 +135,7 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
if (line_boundary_encountered == true) {
// Set up source hyperlinks
DVI_Hyperlink link;
link.baseline = PXL_V;
link.baseline = currinf.data.pxl_v;
link.box.setRect(x, y, pix.width(), pix.height());
link.linkText = "";
@ -188,9 +188,9 @@ void dviWindow::set_char(unsigned int cmd, unsigned int ch)
}
if (cmd == PUT1)
DVI_H = dvi_h_sav;
currinf.data.dvi_h = dvi_h_sav;
else
DVI_H += g->dvi_adv;
currinf.data.dvi_h += g->dvi_adv;
word_boundary_encountered = false;
line_boundary_encountered = false;
@ -215,13 +215,13 @@ void dviWindow::set_vf_char(unsigned int cmd, unsigned int ch)
return;
}
long dvi_h_sav = DVI_H;
long dvi_h_sav = currinf.data.dvi_h;
if (PostScriptOutPutString == NULL) {
struct drawinf oldinfo = currinf;
WW = 0;
XX = 0;
YY = 0;
ZZ = 0;
currinf.data.w = 0;
currinf.data.x = 0;
currinf.data.y = 0;
currinf.data.z = 0;
currinf.fonttable = currinf.fontp->vf_table;
currinf._virtual = currinf.fontp;
@ -235,9 +235,9 @@ void dviWindow::set_vf_char(unsigned int cmd, unsigned int ch)
currinf = oldinfo;
}
if (cmd == PUT1)
DVI_H = dvi_h_sav;
currinf.data.dvi_h = dvi_h_sav;
else
DVI_H += m->dvi_adv;
currinf.data.dvi_h += m->dvi_adv;
}
@ -258,24 +258,13 @@ void dviWindow::set_no_char(unsigned int cmd, unsigned int ch)
errorMsg = i18n("The DVI code set a character of unknown font");
return;
/* NOTREACHED */
}
/** Set rule. Arguments are coordinates of lower left corner. */
static void set_rule(int h, int w)
{
foreGroundPaint.fillRect( PXL_H - -currwin.base_x, PXL_V - h + 1 -currwin.base_y, w?w:1, h?h:1, Qt::black );
}
#define xspell_conv(n) ((long) (n * current_dimconv))
void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
{
#ifdef DEBUG_RENDER
kdDebug() << "draw_part" << endl;
kdDebug(4300) << "draw_part" << endl;
#endif
Q_INT32 RRtmp=0, WWtmp=0, XXtmp=0, YYtmp=0, ZZtmp=0;
@ -314,10 +303,14 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
0x80000000. We don't want any SIGFPE here. */
a = readUINT32();
b = readUINT32();
b = xspell_conv(b);
if (a > 0 && b > 0 && PostScriptOutPutString == NULL)
set_rule( ((int) ROUNDUP(xspell_conv(a), currwin.shrinkfactor * 65536)), ((int) ROUNDUP(b, currwin.shrinkfactor * 65536)) );
DVI_H += b;
b = ((long) (b * current_dimconv));
if (a > 0 && b > 0 && PostScriptOutPutString == NULL) {
int h = ((int) ROUNDUP(((long) (a * current_dimconv)), currwin.shrinkfactor * 65536));
int w = ((int) ROUNDUP(b, currwin.shrinkfactor * 65536));
foreGroundPaint.fillRect( ((int) ((currinf.data.dvi_h) / (currwin.shrinkfactor * 65536))) - -currwin.base_x,
currinf.data.pxl_v - h + 1 -currwin.base_y, w?w:1, h?h:1, Qt::black );
}
currinf.data.dvi_h += b;
break;
case PUTRULE:
@ -327,10 +320,14 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
}
a = readUINT32();
b = readUINT32();
a = xspell_conv(a);
b = xspell_conv(b);
if (a > 0 && b > 0 && PostScriptOutPutString == NULL)
set_rule(((int) ROUNDUP(a, currwin.shrinkfactor * 65536)), ((int) ROUNDUP(b, currwin.shrinkfactor * 65536)));
a = ((long) (a * current_dimconv));
b = ((long) (b * current_dimconv));
if (a > 0 && b > 0 && PostScriptOutPutString == NULL) {
int h = ((int) ROUNDUP(a, currwin.shrinkfactor * 65536));
int w = ((int) ROUNDUP(b, currwin.shrinkfactor * 65536));
foreGroundPaint.fillRect( ((int) ((currinf.data.dvi_h) / (currwin.shrinkfactor * 65536))) - -currwin.base_x,
currinf.data.pxl_v - h + 1 -currwin.base_y, w?w:1, h?h:1, Qt::black );
}
break;
case NOP:
@ -342,10 +339,10 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
line_boundary_encountered = true;
}
command_pointer += 11 * 4;
DVI_H = basedpi << 16; // Reminder: DVI-coordinates start at (1",1") from top of page
DVI_V = basedpi;
PXL_V = int(DVI_V/currwin.shrinkfactor);
WW = XX = YY = ZZ = 0;
currinf.data.dvi_h = basedpi << 16; // Reminder: DVI-coordinates start at (1",1") from top of page
currinf.data.dvi_v = basedpi;
currinf.data.pxl_v = int(currinf.data.dvi_v/currwin.shrinkfactor);
currinf.data.w = currinf.data.x = currinf.data.y = currinf.data.z = 0;
break;
case EOP:
@ -397,7 +394,7 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
((RRtmp >= currinf.fontp->scaled_size/6) || (RRtmp <= -4*(currinf.fontp->scaled_size/6))) &&
(textLinkList.size() > 0))
textLinkList[textLinkList.size()-1].linkText += ' ';
DVI_H += xspell_conv(RRtmp);
currinf.data.dvi_h += ((long) (RRtmp * current_dimconv));
break;
case W1:
@ -405,14 +402,14 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
case W3:
case W4:
WWtmp = readINT(ch - W0);
WW = xspell_conv(WWtmp);
currinf.data.w = ((long) (WWtmp * current_dimconv));
case W0:
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
((WWtmp >= currinf.fontp->scaled_size/6) || (WWtmp <= -4*(currinf.fontp->scaled_size/6))) &&
(textLinkList.size() > 0) )
textLinkList[textLinkList.size()-1].linkText += ' ';
DVI_H += WW;
currinf.data.dvi_h += currinf.data.w;
break;
case X1:
@ -420,14 +417,14 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
case X3:
case X4:
XXtmp = readINT(ch - X0);
XX = xspell_conv(XXtmp);
currinf.data.x = ((long) (XXtmp * current_dimconv));
case X0:
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
((XXtmp >= currinf.fontp->scaled_size/6) || (XXtmp <= -4*(currinf.fontp->scaled_size/6))) &&
(textLinkList.size() > 0))
textLinkList[textLinkList.size()-1].linkText += ' ';
DVI_H += XX;
currinf.data.dvi_h += currinf.data.x;
break;
case DOWN1:
@ -445,8 +442,8 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if (abs(DDtmp) >= 10*(currinf.fontp->scaled_size/6))
textLinkList[textLinkList.size()-1].linkText += '\n';
}
DVI_V += xspell_conv(DDtmp)/65536;
PXL_V = int(DVI_V/currwin.shrinkfactor);
currinf.data.dvi_v += ((long) (DDtmp * current_dimconv))/65536;
currinf.data.pxl_v = int(currinf.data.dvi_v/currwin.shrinkfactor);
}
break;
@ -455,7 +452,7 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
case Y3:
case Y4:
YYtmp = readINT(ch - Y0);
YY = xspell_conv(YYtmp);
currinf.data.y = ((long) (YYtmp * current_dimconv));
case Y0:
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
@ -466,8 +463,8 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if (abs(YYtmp) >= 10*(currinf.fontp->scaled_size/6))
textLinkList[textLinkList.size()-1].linkText += '\n';
}
DVI_V += YY/65536;
PXL_V = int(DVI_V/currwin.shrinkfactor);
currinf.data.dvi_v += currinf.data.y/65536;
currinf.data.pxl_v = int(currinf.data.dvi_v/currwin.shrinkfactor);
break;
case Z1:
@ -475,7 +472,7 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
case Z3:
case Z4:
ZZtmp = readINT(ch - Z0);
ZZ = xspell_conv(ZZtmp);
currinf.data.z = ((long) (ZZtmp * current_dimconv));
case Z0:
if ((is_vfmacro == false) &&
(currinf.fontp != 0) &&
@ -486,8 +483,8 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
if (abs(ZZtmp) >= 10*(currinf.fontp->scaled_size/6))
textLinkList[textLinkList.size()-1].linkText += '\n';
}
DVI_V += ZZ/65536;
PXL_V = int(DVI_V/currwin.shrinkfactor);
currinf.data.dvi_v += currinf.data.z/65536;
currinf.data.pxl_v = int(currinf.data.dvi_v/currwin.shrinkfactor);
break;
case FNT1:
@ -552,7 +549,6 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
} /* end for */
}
#undef xspell_conv
void dviWindow::draw_page(void)
{

View file

@ -205,13 +205,13 @@ double KDVIMultiPage::setZoom(double zoom)
double KDVIMultiPage::zoomForHeight(int height)
{
return (double)(height-1)/(window->xres*(window->paper_height/2.54));
return (double)(height-1)/(window->xres*(window->paper_height_in_cm/2.54));
}
double KDVIMultiPage::zoomForWidth(int width)
{
return (double)(width-1)/(window->xres*(window->paper_width/2.54));
return (double)(width-1)/(window->xres*(window->paper_width_in_cm/2.54));
}

View file

@ -30,7 +30,7 @@ void dviWindow::html_anchor_special(QString cp)
kdDebug(4300) << "page " << current_page << endl;
#endif
anchorList[cp] = DVI_Anchor(current_page, DVI_V);
anchorList[cp] = DVI_Anchor(current_page, currinf.data.dvi_v);
}
}
@ -95,7 +95,7 @@ void dviWindow::source_special(QString cp)
break;
Q_UINT32 sourceLineNumber = cp.left(j).toUInt();
QString sourceFileName = QFileInfo(cp.mid(j).stripWhiteSpace()).absFilePath();
DVI_SourceFileAnchor sfa(sourceFileName, sourceLineNumber, current_page, DVI_V);
DVI_SourceFileAnchor sfa(sourceFileName, sourceLineNumber, current_page, currinf.data.dvi_v);
sourceHyperLinkAnchors.push_back(sfa);
}
}
@ -189,8 +189,8 @@ void dviWindow::epsf_special(QString cp)
if (PostScriptOutPutString) {
if (QFile::exists(EPSfilename)) {
double PS_H = (DVI_H*300.0)/(65536*basedpi)-300;
double PS_V = (DVI_V*300.0)/basedpi - 300;
double PS_H = (currinf.data.dvi_h*300.0)/(65536*basedpi)-300;
double PS_V = (currinf.data.dvi_v*300.0)/basedpi - 300;
PostScriptOutPutString->append( QString(" %1 %2 moveto\n").arg(PS_H).arg(PS_V) );
PostScriptOutPutString->append( "@beginspecial " );
PostScriptOutPutString->append( QString(" %1 @llx").arg(llx) );
@ -226,7 +226,7 @@ void dviWindow::epsf_special(QString cp)
bbox_width *= 0.1 * 65536.0*fontPixelPerDVIunit() / currwin.shrinkfactor;
bbox_height *= 0.1 * 65536.0*fontPixelPerDVIunit() / currwin.shrinkfactor;
QRect bbox(PXL_H - currwin.base_x, PXL_V - currwin.base_y - (int)bbox_height, (int)bbox_width, (int)bbox_height);
QRect bbox(((int) ((currinf.data.dvi_h) / (currwin.shrinkfactor * 65536))) - currwin.base_x, currinf.data.pxl_v - currwin.base_y - (int)bbox_height, (int)bbox_width, (int)bbox_height);
foreGroundPaint.save();
if (QFile::exists(EPSfilename))
foreGroundPaint.setBrush(Qt::lightGray);
@ -265,8 +265,8 @@ void dviWindow::quote_special(QString cp)
#endif
if (currwin.win == mane.win && PostScriptOutPutString) {
double PS_H = (DVI_H*300.0)/(65536*basedpi)-300;
double PS_V = (DVI_V*300.0)/basedpi - 300;
double PS_H = (currinf.data.dvi_h*300.0)/(65536*basedpi)-300;
double PS_V = (currinf.data.dvi_v*300.0)/basedpi - 300;
PostScriptOutPutString->append( QString(" %1 %2 moveto\n").arg(PS_H).arg(PS_V) );
PostScriptOutPutString->append( " @beginspecial @setspecial \n" );
PostScriptOutPutString->append( cp );
@ -281,8 +281,8 @@ void dviWindow::ps_special(QString cp)
#endif
if (currwin.win == mane.win && PostScriptOutPutString) {
double PS_H = (DVI_H*300.0)/(65536*basedpi)-300;
double PS_V = (DVI_V*300.0)/basedpi - 300;
double PS_H = (currinf.data.dvi_h*300.0)/(65536*basedpi)-300;
double PS_V = (currinf.data.dvi_v*300.0)/basedpi - 300;
if (cp.find("ps::[begin]", 0, false) == 0) {
PostScriptOutPutString->append( QString(" %1 %2 moveto\n").arg(PS_H).arg(PS_V) );

13
xdvi.h
View file

@ -5,19 +5,6 @@
* Written by Eric C. Cooper, CMU
*/
extern struct drawinf currinf;
/* entries below with the characters 'dvi' in them are actually stored in
scaled pixel units */
#define DVI_H currinf.data.dvi_h
#define PXL_H ((int) ((currinf.data.dvi_h) / (currwin.shrinkfactor * 65536)))
#define DVI_V currinf.data.dvi_v
#define PXL_V currinf.data.pxl_v
#define WW currinf.data.w
#define XX currinf.data.x
#define YY currinf.data.y
#define ZZ currinf.data.z
#define ROUNDUP(x,y) (((x)+(y)-1)/(y))
extern unsigned long num (FILE *, int);