further source code cleanup

svn path=/trunk/kdegraphics/kdvi/; revision=206918
This commit is contained in:
Stefan Kebekus 2003-02-14 21:11:03 +00:00
parent dc729a55bf
commit 3db56840d3
9 changed files with 39 additions and 62 deletions

3
TODO
View file

@ -4,7 +4,6 @@ URGENT / URGENT BUGFIXING
o add tip: kdvi can load compressed files! o add tip: kdvi can load compressed files!
o get rid of useless README.kdvi o get rid of useless README.kdvi
o "neue datei laden" geht nicht mehr
o Proper handling of the base-url o Proper handling of the base-url
o add "tt.dvi.gz" to the list of recent files, not "/tmp/kviews....." o add "tt.dvi.gz" to the list of recent files, not "/tmp/kviews....."
@ -17,7 +16,7 @@ o Support for colored font specials
o Support papersize information given by the dvi-file on a page-by-page o Support papersize information given by the dvi-file on a page-by-page
basis. basis.
o Extra enlargement of characters for improved readability should be switchable. o asynchronous rendering of pages, so that browsing with pg up/down looks faster
NOT SO URGENT NOT SO URGENT

View file

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <qdatastream.h> #include <qdatastream.h>
#include <qfile.h> #include <qfile.h>
#include <qintdict.h>
#include <qstring.h> #include <qstring.h>
#include "bigEndianByteReader.h" #include "bigEndianByteReader.h"
@ -26,7 +27,7 @@ class dvifile : public bigEndianByteReader
Q_UINT8 * dvi_Data; Q_UINT8 * dvi_Data;
QIODevice::Offset size_of_file; QIODevice::Offset size_of_file;
QString errorMsg; QString errorMsg;
/** This flag is set to "true" during the construction of the /** This flag is set to "true" during the construction of the
dvifile, and is never changed afterwards by the dvifile dvifile, and is never changed afterwards by the dvifile
class. It is used in kdvi in conjuction with source-specials: class. It is used in kdvi in conjuction with source-specials:
@ -34,7 +35,8 @@ class dvifile : public bigEndianByteReader
shows an info dialog, and the flag is set to false. That way shows an info dialog, and the flag is set to false. That way
KDVI ensures that the user is only informed once. */ KDVI ensures that the user is only informed once. */
bool sourceSpecialMarker; bool sourceSpecialMarker;
QIntDict<struct font> tn_table;
double cmPerDVIunit; double cmPerDVIunit;

View file

@ -59,8 +59,6 @@ struct WindowRec currwin = {(Window) 0, 3, 0, 0, 0, 0, MAXDIM, 0, MAXDIM, 0};
extern struct WindowRec alt; extern struct WindowRec alt;
struct drawinf currinf; struct drawinf currinf;
QIntDict<font> tn_table;
// The following are really used // The following are really used
unsigned int page_w; unsigned int page_w;
unsigned int page_h; unsigned int page_h;
@ -523,7 +521,7 @@ bool dviWindow::setFile(QString fname, QString ref, bool sourceMarker)
command_pointer = end_pointer = 0; command_pointer = end_pointer = 0;
memset((char *) &currinf.data, 0, sizeof(currinf.data)); memset((char *) &currinf.data, 0, sizeof(currinf.data));
currinf.fonttable = tn_table; currinf.fonttable = dviFile->tn_table;
currinf._virtual = NULL; currinf._virtual = NULL;
draw_part(65536.0*fontPixelPerDVIunit(), false); draw_part(65536.0*fontPixelPerDVIunit(), false);

View file

@ -270,7 +270,7 @@ static void set_rule(int h, int w)
} }
#define xspell_conv(n) spell_conv0(n, current_dimconv) #define xspell_conv(n) ((long) (n * current_dimconv))
void dviWindow::draw_part(double current_dimconv, bool is_vfmacro) void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
{ {
@ -316,7 +316,7 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
b = readUINT32(); b = readUINT32();
b = xspell_conv(b); b = xspell_conv(b);
if (a > 0 && b > 0 && PostScriptOutPutString == NULL) if (a > 0 && b > 0 && PostScriptOutPutString == NULL)
set_rule(pixel_round(xspell_conv(a)), pixel_round(b)); set_rule( ((int) ROUNDUP(xspell_conv(a), shrink_factor * 65536)), ((int) ROUNDUP(b, shrink_factor * 65536)) );
DVI_H += b; DVI_H += b;
break; break;
@ -330,7 +330,7 @@ void dviWindow::draw_part(double current_dimconv, bool is_vfmacro)
a = xspell_conv(a); a = xspell_conv(a);
b = xspell_conv(b); b = xspell_conv(b);
if (a > 0 && b > 0 && PostScriptOutPutString == NULL) if (a > 0 && b > 0 && PostScriptOutPutString == NULL)
set_rule(pixel_round(a), pixel_round(b)); set_rule(((int) ROUNDUP(a, shrink_factor * 65536)), ((int) ROUNDUP(b, shrink_factor * 65536)));
break; break;
case NOP: case NOP:
@ -594,7 +594,7 @@ void dviWindow::draw_page(void)
command_pointer = end_pointer = 0; command_pointer = end_pointer = 0;
memset((char *) &currinf.data, 0, sizeof(currinf.data)); memset((char *) &currinf.data, 0, sizeof(currinf.data));
currinf.fonttable = tn_table; currinf.fonttable = dviFile->tn_table;
currinf._virtual = 0; currinf._virtual = 0;
draw_part(65536.0*fontPixelPerDVIunit(), false); draw_part(65536.0*fontPixelPerDVIunit(), false);
if (HTML_href != 0) { if (HTML_href != 0) {

View file

@ -111,10 +111,10 @@ void fontPool::setEnlargeFonts( bool flag )
} }
class font *fontPool::appendx(const char *fontname, long checksum, Q_INT32 scale, double enlargement, double cmPerDVIunit) class font *fontPool::appendx(const char *fontname, Q_UINT32 checksum, Q_UINT32 scale, double enlargement, double cmPerDVIunit)
{ {
double fsize = enlargement * MFResolutions[getMetafontMode()]; double fsize = enlargement * MFResolutions[getMetafontMode()];
// Reuse font if possible: check if a font with that name and // Reuse font if possible: check if a font with that name and
// natural resolution is already in the fontpool, and use that, if // natural resolution is already in the fontpool, and use that, if
// possible. // possible.
@ -128,12 +128,12 @@ class font *fontPool::appendx(const char *fontname, long checksum, Q_INT32 scale
} }
fontp=fontList.next(); fontp=fontList.next();
} }
// If font doesn't exist yet, we have to generate a new font. // If font doesn't exist yet, we have to generate a new font.
// Calculate the number of pixel per DVI unit // Calculate the number of pixel per DVI unit
double pixelPerDVIunit = cmPerDVIunit * MFResolutions[getMetafontMode()] / 2.54; double pixelPerDVIunit = cmPerDVIunit * MFResolutions[getMetafontMode()] / 2.54;
fontp = new font(fontname, fsize, checksum, scale, pixelPerDVIunit, this, fontp = new font(fontname, fsize, checksum, scale, pixelPerDVIunit, this,
(enlargeFonts == true) ? shrinkFactor/1.1 : shrinkFactor, enlargement, cmPerDVIunit); (enlargeFonts == true) ? shrinkFactor/1.1 : shrinkFactor, enlargement, cmPerDVIunit);
if (fontp == 0) { if (fontp == 0) {
@ -141,7 +141,7 @@ class font *fontPool::appendx(const char *fontname, long checksum, Q_INT32 scale
exit(0); exit(0);
} }
fontList.append(fontp); fontList.append(fontp);
// Now start kpsewhich/MetaFont, etc. if necessary // Now start kpsewhich/MetaFont, etc. if necessary
return fontp; return fontp;
} }

View file

@ -85,7 +85,7 @@ Q_OBJECT
will be called. Since this is done using a concurrently running will be called. Since this is done using a concurrently running
process, there is no guarantee that the loading is already process, there is no guarantee that the loading is already
performed when the method returns. */ performed when the method returns. */
class font *appendx(const char *fontname, long checksum, Q_INT32 scale, double enlargement, double cmPerDVIunit); class font *appendx(const char *fontname, Q_UINT32 checksum, Q_UINT32 scale, double enlargement, double cmPerDVIunit);
/** Prints very basic debugging information about the fonts in the /** Prints very basic debugging information about the fonts in the
pool to the kdDebug output stream. */ pool to the kdDebug output stream. */

6
tips
View file

@ -1,3 +1,9 @@
<tip category="KDVI|General">
<html>
<p>...that KDVI can also load compressed DVI-files?
</html>
</tip>
<tip category="KDVI|General"> <tip category="KDVI|General">
<html> <html>
<p>...that you can mark text with the right mouse button and paste it <p>...that you can mark text with the right mouse button and paste it

27
vf.cpp
View file

@ -89,26 +89,25 @@ void font::read_VF_index(void)
first_font = NULL; first_font = NULL;
while ((cmnd = one(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) { while ((cmnd = one(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
int TeXnumber = num(VF_file, (int) cmnd - FNTDEF1 + 1); int TeXnumber = num(VF_file, (int) cmnd - FNTDEF1 + 1);
long checksum = four(VF_file); Q_UINT32 checksum = four(VF_file);
int scale = four(VF_file); Q_UINT32 scale = four(VF_file);
int design = four(VF_file); Q_UINT32 design = four(VF_file);
int len = one(VF_file) + one(VF_file); /* sequence point in the middle */ Q_UINT16 len = one(VF_file) + one(VF_file); /* sequence point in the middle */
char *fontname = new char[(unsigned) len + 1]; char *fontname = new char[len + 1];
fread(fontname, sizeof(char), len, VF_file); fread(fontname, sizeof(char), len, VF_file);
fontname[len] = '\0'; fontname[len] = '\0';
#ifdef DEBUG_FONTS #ifdef DEBUG_FONTS
kdDebug() << "Virtual font defines subfont \"" << fontname << "\" scale=" << scale << " design=" << design << endl; kdDebug() << "Virtual font defines subfont \"" << fontname << "\" scale=" << scale << " design=" << design << endl;
#endif #endif
// The scaled size is given in units of vfparent->scale * 2 ** -20 // According to Knuth's documentation found in the web source code
// SPELL units, so we convert it into SPELL units by multiplying // of the "vftovp" program (which seems to be the standard
// by vfparent->dimconv. The design size is given in units of 2 // definition of virtual fonts), the "scale" is a fixed point
// -20 pt, so we convert into SPELL units by multiplying by // number which describes extra enlargement that the virtual font
// (pixels_per_inch * 2**16) / (72.27 * 2**20). // imposes. One obtains the enlargement by dividing 2^20.
// @@@@@@@@@@@@@@ CHECK THAT @@@@@@@@@@@@@@@@@@@@@@@ THIS CALL OF appendx PROBABLY HAS A WRONG enlargement. ORIGINAL CODE WAS: double enlargement_factor = double(scale)/(1<<20) * enlargement;
// struct font *newfontp = font_pool->appendx(fontname, checksum, scale, (72.27 * (1<<4)) * dimconv * scale / design, dimconv); struct font *newfontp = font_pool->appendx(fontname, checksum, scale, enlargement_factor, cmPerDVIunit);
struct font *newfontp = font_pool->appendx(fontname, checksum, scale, enlargement, cmPerDVIunit);
// Insert font in dictionary and make sure the dictionary is big // Insert font in dictionary and make sure the dictionary is big
// enough. // enough.

33
xdvi.h
View file

@ -13,31 +13,11 @@
* PAGE_OFFSET in dvi_draw.c. * PAGE_OFFSET in dvi_draw.c.
*/ */
#define pixel_conv(x) ((int) ((x) / (shrink_factor * 65536)))
#define pixel_round(x) ((int) ROUNDUP(x, shrink_factor * 65536))
#define spell_conv0(n, f) ((long) (n * f))
#define BMUNIT Q_UINT32
#ifdef BMBYTE
#define BMUNIT unsigned char
#define BITS_PER_BMUNIT 8
#define BYTES_PER_BMUNIT 1
#else /* !BMBYTE */
#ifdef BMSHORT
#define BMUNIT unsigned short
#define BITS_PER_BMUNIT 16
#define BYTES_PER_BMUNIT 2
#else /* !BMSHORT */
#define BMLONG
#ifdef __alpha
#define BMUNIT unsigned int
#else
#define BMUNIT unsigned long
#endif /* if __alpha */
#define BITS_PER_BMUNIT 32 #define BITS_PER_BMUNIT 32
#define BYTES_PER_BMUNIT 4 #define BYTES_PER_BMUNIT 4
#endif /* !BMSHORT */
#endif /* !BMBYTE */
#define ADD(a, b) ((BMUNIT *) (((char *) a) + b)) #define ADD(a, b) ((BMUNIT *) (((char *) a) + b))
#define SUB(a, b) ((BMUNIT *) (((char *) a) - b)) #define SUB(a, b) ((BMUNIT *) (((char *) a) - b))
@ -51,7 +31,7 @@ extern struct drawinf currinf;
scaled pixel units */ scaled pixel units */
#define DVI_H currinf.data.dvi_h #define DVI_H currinf.data.dvi_h
#define PXL_H pixel_conv(currinf.data.dvi_h) #define PXL_H ((int) ((currinf.data.dvi_h) / (shrink_factor * 65536)))
#define DVI_V currinf.data.dvi_v #define DVI_V currinf.data.dvi_v
#define PXL_V currinf.data.pxl_v #define PXL_V currinf.data.pxl_v
#define WW currinf.data.w #define WW currinf.data.w
@ -60,13 +40,6 @@ extern struct drawinf currinf;
#define ZZ currinf.data.z #define ZZ currinf.data.z
#define ROUNDUP(x,y) (((x)+(y)-1)/(y)) #define ROUNDUP(x,y) (((x)+(y)-1)/(y))
extern QIntDict<struct font> tn_table;
/*
* Command line flags.
*/
extern unsigned long num (FILE *, int); extern unsigned long num (FILE *, int);
extern long snum(FILE *, int); extern long snum(FILE *, int);
extern struct WindowRec mane, currwin; extern struct WindowRec mane, currwin;