mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-17 23:11:48 +00:00
added some warning dialogs; minor bugfixing and enhancements
svn path=/trunk/kdegraphics/kdvi/; revision=90982
This commit is contained in:
parent
c7fad7c239
commit
eef7ca340c
113
dvi_init.cpp
113
dvi_init.cpp
|
@ -110,79 +110,6 @@ static long last_page_offset;
|
|||
|
||||
|
||||
|
||||
/** MAGSTEPVALUE - If the given magnification is close to a \magstep
|
||||
or a \magstephalf, then return twice the number of
|
||||
\magsteps. Otherwise return NOMAGSTP. */
|
||||
|
||||
#define NOMAGSTP (-29999)
|
||||
#define NOBUILD 29999
|
||||
#define MAGSTEP_MAX 40
|
||||
|
||||
static int magstep(int n, int bdpi)
|
||||
{
|
||||
double t;
|
||||
int step;
|
||||
int neg = 0;
|
||||
|
||||
if (n < 0) {
|
||||
neg = 1;
|
||||
n = -n;
|
||||
}
|
||||
|
||||
if (n & 1) {
|
||||
n &= ~1;
|
||||
t = 1.095445115;
|
||||
}
|
||||
else
|
||||
t = 1.0;
|
||||
|
||||
while (n > 8) {
|
||||
n -= 8;
|
||||
t = t * 2.0736;
|
||||
}
|
||||
|
||||
while (n > 0) {
|
||||
n -= 2;
|
||||
t = t * 1.2;
|
||||
}
|
||||
|
||||
/* Unnecessary casts to shut up stupid compilers. */
|
||||
step = (int)(0.5 + (neg ? bdpi / t : bdpi * t));
|
||||
return step;
|
||||
}
|
||||
|
||||
static unsigned kpse_magstep_fix(unsigned dpi, unsigned bdpi, int *m_ret)
|
||||
{
|
||||
int m;
|
||||
int mdpi = -1;
|
||||
unsigned real_dpi = 0;
|
||||
int sign = dpi < bdpi ? -1 : 1; /* negative or positive magsteps? */
|
||||
|
||||
for (m = 0; !real_dpi && m < MAGSTEP_MAX; m++) { /* don't go forever */
|
||||
mdpi = magstep (m * sign, bdpi);
|
||||
if (abs(mdpi - (int) dpi) <= 1) /* if this magstep matches, quit */
|
||||
real_dpi = mdpi;
|
||||
else
|
||||
if ((mdpi - (int) dpi) * sign > 0) /* if gone too far, quit */
|
||||
real_dpi = dpi;
|
||||
}
|
||||
|
||||
// If requested, return the encoded magstep (the loop went one too
|
||||
// far). More unnecessary casts.
|
||||
if (m_ret)
|
||||
*m_ret = real_dpi == (unsigned)(mdpi ? (m - 1) * sign : 0);
|
||||
|
||||
// Always return the true dpi found.
|
||||
return real_dpi ? real_dpi : dpi;
|
||||
}
|
||||
|
||||
static int magstepvalue(float *mag)
|
||||
{
|
||||
int m_ret;
|
||||
unsigned dpi_ret = kpse_magstep_fix ((unsigned) *mag, (unsigned) pixels_per_inch, &m_ret);
|
||||
*mag = (float) dpi_ret; /* MAG is actually a dpi. */
|
||||
return m_ret ? m_ret : NOMAGSTP;
|
||||
}
|
||||
|
||||
|
||||
/** define_font reads the rest of the fntdef command and then reads in
|
||||
|
@ -191,10 +118,6 @@ static int magstepvalue(float *mag)
|
|||
|
||||
font *define_font(FILE *file, unsigned int cmnd, font *vfparent, QIntDict<struct font> *TeXNumberTable, class fontPool *font_pool)
|
||||
{
|
||||
struct font *fontp;
|
||||
int magstepval;
|
||||
int size;
|
||||
|
||||
int TeXnumber = num(file, (int) cmnd - FNTDEF1 + 1);
|
||||
long checksum = four(file);
|
||||
int scale = four(file);
|
||||
|
@ -204,40 +127,18 @@ font *define_font(FILE *file, unsigned int cmnd, font *vfparent, QIntDict<struct
|
|||
Fread(fontname, sizeof(char), len, file);
|
||||
fontname[len] = '\0';
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUG_FONTS
|
||||
kdDebug() << "Define font \"" << fontname << "\" scale=" << scale << " design=" << design << endl;
|
||||
#endif
|
||||
|
||||
// The calculation here is some sort of black magic which I do not
|
||||
// understand. Anyone with time, could you figure out what's going
|
||||
// on here? -- Stefan Kebekus
|
||||
float fsize;
|
||||
double scale_dimconv;
|
||||
if (vfparent == NULL) {
|
||||
fsize = 0.001 * scale / design * magnification * pixels_per_inch;
|
||||
scale_dimconv = dimconv;
|
||||
} else {
|
||||
/* The scaled size is given in units of vfparent->scale * 2 ** -20
|
||||
SPELL units, so we convert it into SPELL units by multiplying
|
||||
by vfparent->dimconv. The design size is given in units of 2 **
|
||||
-20 pt, so we convert into SPELL units by multiplying by
|
||||
(pixels_per_inch * 2**16) / (72.27 * 2**20). */
|
||||
|
||||
fsize = (72.27 * (1<<4)) * vfparent->dimconv * scale / design;
|
||||
scale_dimconv = vfparent->dimconv;
|
||||
}
|
||||
magstepval = magstepvalue(&fsize);
|
||||
size = (int)(fsize + 0.5);
|
||||
|
||||
fontp = font_pool->appendx(fontname, fsize, checksum, magstepval, scale * scale_dimconv / (1<<20));
|
||||
// struct font *fontp = font_pool->appendx(fontname, fsize, checksum, scale * scale_dimconv / (1<<20));
|
||||
struct font *fontp = font_pool->appendx(fontname, checksum, scale, design, vfparent);
|
||||
|
||||
// Insert font in dictionary and make sure the dictionary is big
|
||||
// enough.
|
||||
if (TeXNumberTable->size()-2 <= TeXNumberTable->count())
|
||||
// Not quite optimal. The size of the dict. should be a prime. I
|
||||
// don't care
|
||||
// Not quite optimal. The size of the dictionary should be a
|
||||
// prime. I don't care
|
||||
TeXNumberTable->resize(TeXNumberTable->size()*2);
|
||||
TeXNumberTable->insert(TeXnumber, fontp);
|
||||
return fontp;
|
||||
|
@ -341,7 +242,7 @@ void dvifile::read_postamble(void)
|
|||
|
||||
void dvifile::prepare_pages()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIFILE
|
||||
kdDebug() << "prepare_pages" << endl;
|
||||
#endif
|
||||
|
||||
|
@ -360,7 +261,7 @@ void dvifile::prepare_pages()
|
|||
|
||||
dvifile::dvifile(QString fname, fontPool *pool)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIFILE
|
||||
kdDebug() << "init_dvi_file: " << fname << endl;
|
||||
#endif
|
||||
|
||||
|
@ -391,7 +292,7 @@ dvifile::dvifile(QString fname, fontPool *pool)
|
|||
|
||||
dvifile::~dvifile()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIFILE
|
||||
kdDebug() << "destroy dvi-file" << endl;
|
||||
#endif
|
||||
|
||||
|
|
68
dviwin.cpp
68
dviwin.cpp
|
@ -57,7 +57,7 @@ jmp_buf dvi_env; /* mechanism to communicate dvi file errors */
|
|||
QIntDict<font> tn_table;
|
||||
|
||||
|
||||
int _pixels_per_inch;
|
||||
int _pixels_per_inch; //@@@
|
||||
_Xconst char *_paper;
|
||||
|
||||
|
||||
|
@ -84,7 +84,7 @@ QPainter foreGroundPaint; // QPainter used for text
|
|||
dviWindow::dviWindow(double zoom, int mkpk, QWidget *parent, const char *name )
|
||||
: QWidget( parent, name )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIWIN
|
||||
kdDebug(4300) << "dviWindow" << endl;
|
||||
#endif
|
||||
|
||||
|
@ -96,7 +96,7 @@ dviWindow::dviWindow(double zoom, int mkpk, QWidget *parent, const char *name )
|
|||
// initialize the dvi machinery
|
||||
|
||||
dviFile = 0;
|
||||
info = 0;
|
||||
|
||||
progress = new fontProgressDialog(this);
|
||||
if (progress == NULL) {
|
||||
kdError(4300) << "Could not allocate memory for the font progress dialog." << endl;
|
||||
|
@ -108,14 +108,24 @@ dviWindow::dviWindow(double zoom, int mkpk, QWidget *parent, const char *name )
|
|||
kdError(4300) << "Could not allocate memory for the font pool." << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
qApp->connect(font_pool, SIGNAL(MFOutput(QString)), progress, SLOT(outputReceiver(QString)));
|
||||
qApp->connect(font_pool, SIGNAL(fonts_have_been_loaded()), progress, SLOT(hideDialog()));
|
||||
qApp->connect(font_pool, SIGNAL(MFOutput(const QString)), progress, SLOT(outputReceiver(const QString)));
|
||||
qApp->connect(font_pool, SIGNAL(hide_progress_dialog()), progress, SLOT(hideDialog()));
|
||||
qApp->connect(font_pool, SIGNAL(fonts_have_been_loaded()), this, SLOT(drawPage()));
|
||||
qApp->connect(font_pool, SIGNAL(totalFontsInJob(int)), progress, SLOT(setTotalSteps(int)));
|
||||
|
||||
qApp->connect(font_pool, SIGNAL(show_progress(void)), progress, SLOT(show(void)));
|
||||
qApp->connect(progress, SIGNAL(finished(void)), font_pool, SLOT(abortGeneration(void)));
|
||||
|
||||
info = new infoDialog(this);
|
||||
if (info == 0) {
|
||||
// The info dialog is not vital. Therefore we don't abort if
|
||||
// something goes wrong here.
|
||||
kdError(4300) << "Could not allocate memory for the info dialog." << endl;
|
||||
} else {
|
||||
qApp->connect(font_pool, SIGNAL(MFOutput(const QString)), info, SLOT(outputReceiver(const QString)));
|
||||
qApp->connect(font_pool, SIGNAL(fonts_info(class fontPool *)), info, SLOT(setFontInfo(class fontPool *)));
|
||||
}
|
||||
|
||||
|
||||
setMakePK( mkpk );
|
||||
setMetafontMode( DefaultMFMode ); // that also sets the basedpi
|
||||
unshrunk_paper_w = int( 21.0 * basedpi/2.54 + 0.5 ); // set A4 paper as default
|
||||
|
@ -149,11 +159,12 @@ dviWindow::dviWindow(double zoom, int mkpk, QWidget *parent, const char *name )
|
|||
PS_interface = new ghostscript_interface(0.0, 0, 0);
|
||||
is_current_page_drawn = 0;
|
||||
resize(0,0);
|
||||
//@@@ setMouseTracking(true);
|
||||
}
|
||||
|
||||
dviWindow::~dviWindow()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIWIN
|
||||
kdDebug(4300) << "~dviWindow" << endl;
|
||||
#endif
|
||||
|
||||
|
@ -171,17 +182,9 @@ dviWindow::~dviWindow()
|
|||
|
||||
void dviWindow::showInfo(void)
|
||||
{
|
||||
if (info == 0) {
|
||||
info = new infoDialog(this);
|
||||
if (info == 0) {
|
||||
// The info dialog is not vital. Therefore we don't abort if
|
||||
// something goes wrong here.
|
||||
kdError(4300) << "Could not allocate memory for the info dialog." << endl;
|
||||
return;
|
||||
}
|
||||
qApp->connect(font_pool, SIGNAL(MFOutput(QString)), info, SLOT(outputReceiver(QString)));
|
||||
qApp->connect(font_pool, SIGNAL(fonts_info(class fontPool *)), info, SLOT(setFontInfo(class fontPool *)));
|
||||
}
|
||||
if (info == 0)
|
||||
return;
|
||||
|
||||
info->setDVIData(dviFile);
|
||||
// Call check_if_fonts_are_loaded() to make sure that the fonts_info
|
||||
// is emitted. That way, the infoDialog will know about the fonts
|
||||
|
@ -193,7 +196,7 @@ void dviWindow::showInfo(void)
|
|||
|
||||
void dviWindow::setShowPS( int flag )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIWIN
|
||||
kdDebug(4300) << "setShowPS" << endl;
|
||||
#endif
|
||||
|
||||
|
@ -227,8 +230,8 @@ void dviWindow::setMetafontMode( unsigned int mode )
|
|||
|
||||
MetafontMode = font_pool->setMetafontMode(mode);
|
||||
basedpi = MFResolutions[MetafontMode];
|
||||
_pixels_per_inch = MFResolutions[MetafontMode];
|
||||
#ifdef DEBUG
|
||||
_pixels_per_inch = MFResolutions[MetafontMode]; //@@@
|
||||
#ifdef DEBUG_DVIWIN
|
||||
kdDebug(4300) << "basedpi " << basedpi << endl;
|
||||
#endif
|
||||
}
|
||||
|
@ -236,7 +239,7 @@ void dviWindow::setMetafontMode( unsigned int mode )
|
|||
|
||||
void dviWindow::setPaper(double w, double h)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIWIN
|
||||
kdDebug(4300) << "setPaper" << endl;
|
||||
#endif
|
||||
|
||||
|
@ -255,7 +258,7 @@ void dviWindow::setPaper(double w, double h)
|
|||
|
||||
void dviWindow::drawPage()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_DVIWIN
|
||||
kdDebug(4300) << "drawPage" << endl;
|
||||
#endif
|
||||
|
||||
|
@ -486,6 +489,23 @@ void dviWindow::paintEvent(QPaintEvent *)
|
|||
}
|
||||
}
|
||||
|
||||
void dviWindow::mouseMoveEvent ( QMouseEvent * e )
|
||||
{
|
||||
/*
|
||||
//@@@ setMouseTracking(true);
|
||||
//@@@ kdDebug(4300) << "mouse event" << endl;
|
||||
|
||||
for(int i=0; i<num_of_used_hyperlinks; i++) {
|
||||
if (hyperLinkList[i].box.contains(e->pos())) {
|
||||
setCursor(pointingHandCursor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setCursor(arrowCursor);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void dviWindow::mousePressEvent ( QMouseEvent * e )
|
||||
{
|
||||
#ifdef DEBUG_SPECIAL
|
||||
|
|
5
dviwin.h
5
dviwin.h
|
@ -26,10 +26,10 @@
|
|||
class infoDialog;
|
||||
class fontProgressDialog;
|
||||
|
||||
// max. number of hyperlinks per page. This should late be replaced by
|
||||
// max. number of hyperlinks per page. This should later be replaced by
|
||||
// a dynamic allocation scheme.
|
||||
#define MAX_HYPERLINKS 200
|
||||
// max. number of anchors per document. This should late be replaced by
|
||||
// max. number of anchors per document. This should later be replaced by
|
||||
// a dynamic allocation scheme.
|
||||
#define MAX_ANCHORS 300
|
||||
|
||||
|
@ -74,6 +74,7 @@ public:
|
|||
|
||||
// These should not be public... only for the moment
|
||||
void mousePressEvent ( QMouseEvent * e );
|
||||
void mouseMoveEvent ( QMouseEvent * e );
|
||||
void read_postamble(void);
|
||||
void draw_part(struct frame *minframe, double current_dimconv);
|
||||
void set_vf_char(unsigned int cmd, unsigned int ch);
|
||||
|
|
3
font.cpp
3
font.cpp
|
@ -63,7 +63,7 @@ void font::fontNameReceiver(QString fname)
|
|||
}
|
||||
|
||||
|
||||
font::font(char *nfontname, float nfsize, long chk, int mag, double dconv, class fontPool *pool)
|
||||
font::font(char *nfontname, float nfsize, long chk, double dconv, class fontPool *pool)
|
||||
{
|
||||
#ifdef DEBUG_FONT
|
||||
kdDebug() << "constructing font " << nfontname << " at " << (int) (nfsize + 0.5) << " dpi" << endl;
|
||||
|
@ -73,7 +73,6 @@ font::font(char *nfontname, float nfsize, long chk, int mag, double dconv, class
|
|||
fontname = nfontname;
|
||||
fsize = nfsize;
|
||||
checksum = chk;
|
||||
magstepval = mag;
|
||||
flags = font::FONT_IN_USE;
|
||||
file = NULL;
|
||||
filename = "";
|
||||
|
|
5
font.h
5
font.h
|
@ -58,7 +58,7 @@ public:
|
|||
};
|
||||
|
||||
|
||||
font(char *nfontname, float nfsize, long chk, int mag, double dconv, class fontPool *pool);
|
||||
font(char *nfontname, float nfsize, long chk, double dconv, class fontPool *pool);
|
||||
~font();
|
||||
glyph *glyphptr(unsigned int ch);
|
||||
void mark_as_used(void);
|
||||
|
@ -80,7 +80,6 @@ public:
|
|||
font *first_font; // used by (loaded) virtual fonts, list of fonts used by this vf
|
||||
|
||||
private:
|
||||
int magstepval; // magstep number * two, or NOMAGSTP
|
||||
long checksum; // checksum
|
||||
|
||||
// Functions related to virtual fonts
|
||||
|
@ -94,7 +93,7 @@ private:
|
|||
void read_PK_index(void);
|
||||
|
||||
public slots:
|
||||
void fontNameReceiver(QString);
|
||||
void fontNameReceiver(QString);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
196
fontpool.cpp
196
fontpool.cpp
|
@ -3,14 +3,19 @@
|
|||
// (C) 2001 Stefan Kebekus
|
||||
// Distributed under the GPL
|
||||
|
||||
#include <kconfig.h>
|
||||
#include <kdebug.h>
|
||||
#include <kinstance.h>
|
||||
#include <klocale.h>
|
||||
#include <kprocess.h>
|
||||
#include <qapplication.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "font.h"
|
||||
#include "fontpool.h"
|
||||
#include "kdvi.h"
|
||||
#include "xdvi.h"
|
||||
|
||||
// List of permissible MetaFontModes which are supported by kdvi.
|
||||
|
||||
|
@ -49,30 +54,51 @@ void fontPool::setMakePK(int flag)
|
|||
// If we enable font generation, we look for fonts which have not
|
||||
// yet been loaded, mark them as "not yet looked up" and try once
|
||||
// more.
|
||||
struct font *fontp;
|
||||
for (fontp=fontList.first(); fontp != 0; fontp=fontList.next() )
|
||||
struct font *fontp = fontp=fontList.first();
|
||||
while(fontp != 0 ) {
|
||||
if (fontp->filename.isEmpty() )
|
||||
fontp->flags &= ~font::FONT_KPSE_NAME;
|
||||
fontp=fontList.next();
|
||||
}
|
||||
check_if_fonts_are_loaded();
|
||||
}
|
||||
|
||||
|
||||
class font *fontPool::appendx(char *fontname, float fsize, long checksum, int magstepval, double dconv)
|
||||
class font *fontPool::appendx(char *fontname, long checksum, int scale, int design, font *vfparent)
|
||||
{
|
||||
class font *fontp;
|
||||
// The calculation here is some sort of black magic which I do not
|
||||
// understand. Anyone with time, could you figure out what's going
|
||||
// on here? -- Stefan Kebekus
|
||||
float fsize;
|
||||
double scale_dimconv;
|
||||
if (vfparent == NULL) {
|
||||
fsize = 0.001 * scale / design * magnification * MFResolutions[MetafontMode];
|
||||
scale_dimconv = dimconv;
|
||||
} else {
|
||||
/* The scaled size is given in units of vfparent->scale * 2 ** -20
|
||||
SPELL units, so we convert it into SPELL units by multiplying
|
||||
by vfparent->dimconv. The design size is given in units of 2 **
|
||||
-20 pt, so we convert into SPELL units by multiplying by
|
||||
(pixels_per_inch * 2**16) / (72.27 * 2**20). */
|
||||
|
||||
fsize = (72.27 * (1<<4)) * vfparent->dimconv * scale / design;
|
||||
scale_dimconv = vfparent->dimconv;
|
||||
}
|
||||
|
||||
// reuse font if possible
|
||||
for ( fontp=fontList.first(); fontp != 0; fontp=fontList.next() ) {
|
||||
class font *fontp = fontList.first();
|
||||
while( fontp != 0 ) {
|
||||
if (strcmp(fontname, fontp->fontname) == 0 && (int (fsize+0.5)) == (int)(fontp->fsize + 0.5)) {
|
||||
// if font is already in the list
|
||||
fontp->mark_as_used();
|
||||
free(fontname);
|
||||
return fontp;
|
||||
}
|
||||
fontp=fontList.next();
|
||||
}
|
||||
|
||||
// if font doesn't exist yet
|
||||
fontp = new font(fontname, fsize, checksum, magstepval, dconv, this);
|
||||
fontp = new font(fontname, fsize, checksum, scale*scale_dimconv/(1<<20), this);
|
||||
if (fontp == 0) {
|
||||
kdError(4300) << i18n("Could not allocate memory for a font structure!") << endl;
|
||||
exit(0);
|
||||
|
@ -87,7 +113,6 @@ class font *fontPool::appendx(char *fontname, float fsize, long checksum, int ma
|
|||
|
||||
QString fontPool::status(void)
|
||||
{
|
||||
struct font *fontp;
|
||||
QString text;
|
||||
QStringList tmp;
|
||||
|
||||
|
@ -96,7 +121,9 @@ QString fontPool::status(void)
|
|||
|
||||
text.append("<table WIDTH=\"100%\" NOSAVE >");
|
||||
text.append("<tr><td><b>Name</b></td> <td><b>DPI</b></td> <td><b>Type</b></td> <td><b>Filename</b></td></tr>");
|
||||
for ( fontp=fontList.first(); fontp != 0; fontp=fontList.next() ) {
|
||||
|
||||
struct font *fontp = fontList.first();
|
||||
while ( fontp != 0 ) {
|
||||
QString type;
|
||||
|
||||
if (fontp->flags & font::FONT_VIRTUAL)
|
||||
|
@ -105,7 +132,8 @@ QString fontPool::status(void)
|
|||
type = i18n("regular");
|
||||
|
||||
tmp << QString ("<tr><td>%1</td> <td>%2</td> <td>%3</td> <td>%4</td></tr>").arg(fontp->fontname).arg((int)(fontp->fsize+0.5)).arg(type).arg(fontp->filename);
|
||||
}
|
||||
fontp=fontList.next();
|
||||
}
|
||||
|
||||
tmp.sort();
|
||||
text.append(tmp.join("\n"));
|
||||
|
@ -118,14 +146,12 @@ QString fontPool::status(void)
|
|||
|
||||
char fontPool::check_if_fonts_are_loaded(unsigned char pass)
|
||||
{
|
||||
struct font *fontp;
|
||||
|
||||
#ifdef DEBUG_FONTPOOL
|
||||
kdDebug(4300) << "Check if fonts have been looked for..." << endl;
|
||||
#endif
|
||||
|
||||
// Check if kpsewhich is still running. In that case there certainly
|
||||
// not all fonts have been properly looked up.
|
||||
// Check if kpsewhich is still running. In that case certainly not
|
||||
// all fonts have been properly looked up.
|
||||
if (proc != 0) {
|
||||
#ifdef DEBUG_FONTPOOL
|
||||
kdDebug(4300) << "... no, kpsewhich is still running." << endl;
|
||||
|
@ -135,9 +161,13 @@ char fontPool::check_if_fonts_are_loaded(unsigned char pass)
|
|||
}
|
||||
|
||||
// Is there a font whose name we did not try to find out yet?
|
||||
for (fontp=fontList.first(); fontp != 0; fontp=fontList.next() )
|
||||
struct font *fontp = fontList.first();
|
||||
while( fontp != 0 ) {
|
||||
if ((fontp->flags & font::FONT_KPSE_NAME) == 0)
|
||||
break;
|
||||
fontp=fontList.next();
|
||||
}
|
||||
|
||||
if (fontp == 0) {
|
||||
#ifdef DEBUG_FONTPOOL
|
||||
kdDebug(4300) << "... yes, all fonts are there, or could not be found." << endl;
|
||||
|
@ -150,8 +180,8 @@ char fontPool::check_if_fonts_are_loaded(unsigned char pass)
|
|||
// as to avoid core dumps.
|
||||
if (MetafontMode >= NumberOfMFModes) {
|
||||
kdError(4300) << "fontPool::appendx called with bad MetafontMode " << MetafontMode
|
||||
<< " which is more than the allowed value of " << NumberOfMFModes-1 << endl;
|
||||
kdError(4300) << "setting mode to " << MFModes[DefaultMFMode] << " at "
|
||||
<< " which is more than the allowed value of " << NumberOfMFModes-1 << endl
|
||||
<< "setting mode to " << MFModes[DefaultMFMode] << " at "
|
||||
<< MFResolutions[DefaultMFMode] << "dpi" << endl;
|
||||
MetafontMode = DefaultMFMode;
|
||||
}
|
||||
|
@ -184,7 +214,9 @@ char fontPool::check_if_fonts_are_loaded(unsigned char pass)
|
|||
else
|
||||
*proc << "--mktex pk";
|
||||
int numFontsInJob = 0;
|
||||
for (fontp=fontList.first(); fontp != 0; fontp=fontList.next() )
|
||||
|
||||
fontp = fontList.first();;
|
||||
while ( fontp != 0 ) {
|
||||
if ((fontp->flags & font::FONT_KPSE_NAME) == 0) {
|
||||
numFontsInJob++;
|
||||
*proc << QString("%1.%2pk").arg(fontp->fontname).arg((int)(fontp->fsize + 0.5));
|
||||
|
@ -198,12 +230,19 @@ char fontPool::check_if_fonts_are_loaded(unsigned char pass)
|
|||
if (pass != 0)
|
||||
fontp->flags |= font::FONT_KPSE_NAME;
|
||||
}
|
||||
fontp=fontList.next();
|
||||
}
|
||||
|
||||
if (pass != 0)
|
||||
emit(totalFontsInJob(numFontsInJob));
|
||||
|
||||
kpsewhichOutput = "";
|
||||
proc->start(KProcess::NotifyOnExit, KProcess::All);
|
||||
|
||||
MetafontOutput = "";
|
||||
proc->closeStdin();
|
||||
if (proc->start(KProcess::NotifyOnExit, KProcess::AllOutput) == false) {
|
||||
kdError(4300) << "kpsewhich failed to start" << endl;
|
||||
}
|
||||
|
||||
emit fonts_info(this);
|
||||
return -1; // That says that not all fonts are loaded.
|
||||
}
|
||||
|
@ -215,11 +254,31 @@ void fontPool::kpsewhich_terminated(KProcess *)
|
|||
kdDebug(4300) << "kpsewhich terminated" << endl;
|
||||
#endif
|
||||
|
||||
delete proc;
|
||||
emit(hide_progress_dialog());
|
||||
|
||||
// Handle fatal errors. The content of fatal_error_in_kpsewhich will
|
||||
// later be used to generate the proper text for error messages.
|
||||
bool fatal_error_in_kpsewhich = false;
|
||||
if (proc->normalExit())
|
||||
if (proc->exitStatus() == 127)
|
||||
fatal_error_in_kpsewhich = true;
|
||||
if (fatal_error_in_kpsewhich) {
|
||||
// Mark all fonts as done so kpsewhich will not be called again
|
||||
// soon.
|
||||
class font *fontp=fontList.first();
|
||||
while ( fontp != 0 ) {
|
||||
fontp->flags |= font::FONT_KPSE_NAME;
|
||||
fontp = fontList.next();
|
||||
}
|
||||
}
|
||||
|
||||
delete proc;
|
||||
proc = 0;
|
||||
|
||||
QStringList fileNameList = QStringList::split('\n', kpsewhichOutput);
|
||||
for (class font *fontp=fontList.first(); fontp != 0; fontp=fontList.next() )
|
||||
|
||||
class font *fontp=fontList.first();
|
||||
while ( fontp != 0 ) {
|
||||
if (fontp->filename.isEmpty() == true) {
|
||||
QString fontname = QString("%1.%2pk").arg(fontp->fontname).arg((int)(fontp->fsize + 0.5));
|
||||
QStringList matchingFiles = fileNameList.grep(fontname);
|
||||
|
@ -229,6 +288,7 @@ void fontPool::kpsewhich_terminated(KProcess *)
|
|||
#endif
|
||||
fontp->fontNameReceiver(matchingFiles.first());
|
||||
fontp->flags |= font::FONT_KPSE_NAME;
|
||||
fontp=fontList.first();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -245,13 +305,62 @@ void fontPool::kpsewhich_terminated(KProcess *)
|
|||
// fonts into the fontList. After that, fontList.next() will
|
||||
// no longer work. It is therefore safer to start over.
|
||||
fontp=fontList.first();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} // of if (fontp->filename.isEmpty() == true)
|
||||
fontp = fontList.next();
|
||||
}
|
||||
|
||||
if (check_if_fonts_are_loaded(1) == 0) {
|
||||
#ifdef DEBUG_FONTPOOL
|
||||
kdDebug(4300) << "Emitting fonts_have_been_loaded()" << endl;
|
||||
#endif
|
||||
|
||||
// Now we have at least tried to look up all fonts. It may,
|
||||
// however, have happened that still not all fonts were found. If
|
||||
// that is so, issue a warning here.
|
||||
bool all_fonts_are_found = true;
|
||||
|
||||
fontp = fontList.first();
|
||||
while ( fontp != 0 ) {
|
||||
if (fontp->filename.isEmpty() == true) {
|
||||
all_fonts_are_found = false;
|
||||
break;
|
||||
}
|
||||
fontp=fontList.next();
|
||||
}
|
||||
|
||||
if (all_fonts_are_found == false) {
|
||||
QString title = i18n("Font not found - KDVI");
|
||||
QString nokps = i18n("There were problems running the kpsewhich program.\n"
|
||||
"KDVI will not work if TeX is not installed on your\n"
|
||||
"system or if the kpsewhich program cannot be found\n"
|
||||
"in the standard search path.\n\n");
|
||||
QString body = i18n("KDVI was not able to locate all the font files \n"
|
||||
"which are necessary to display the current DVI file. \n"
|
||||
"Some characters are therefore left blank, and your \n"
|
||||
"document might be unreadable.");
|
||||
QString metaf = i18n("\n\nExperts will find helpfull information in the 'MetaFont'-\n"
|
||||
"section of the document info dialog");
|
||||
|
||||
if (fatal_error_in_kpsewhich == true)
|
||||
QMessageBox::warning( 0, title, nokps+body+metaf );
|
||||
else
|
||||
if (makepk == 0) {
|
||||
if(QMessageBox::warning( 0, title, body+i18n("\nAutomatic font generation is switched off.\n"),
|
||||
"Generate fonts now", "Continue without" ) == 0) {
|
||||
KInstance *instance = new KInstance("kdvi");
|
||||
KConfig *config = instance->config();
|
||||
config->setGroup("kdvi");
|
||||
config->writeEntry( "MakePK", true );
|
||||
config->sync();
|
||||
setMakePK(1);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
QMessageBox::warning( 0, title, body+metaf );
|
||||
}
|
||||
|
||||
emit(fonts_have_been_loaded());
|
||||
}
|
||||
return;
|
||||
|
@ -264,13 +373,15 @@ void fontPool::reset_fonts(void)
|
|||
kdDebug(4300) << "Reset Fonts" << endl;
|
||||
#endif
|
||||
|
||||
struct font *fontp;
|
||||
struct glyph *glyphp;
|
||||
|
||||
for ( fontp=fontList.first(); fontp != 0; fontp=fontList.next() )
|
||||
if ((fontp->flags & font::FONT_LOADED) && !(fontp->flags & font::FONT_VIRTUAL))
|
||||
struct font *fontp = fontList.first();
|
||||
while ( fontp != 0 ) {
|
||||
if ((fontp->flags & font::FONT_LOADED) && !(fontp->flags & font::FONT_VIRTUAL)) {
|
||||
struct glyph *glyphp;
|
||||
for (glyphp = fontp->glyphtable; glyphp < fontp->glyphtable + font::max_num_of_chars_in_font; ++glyphp)
|
||||
glyphp->clearShrunkCharacter();
|
||||
}
|
||||
fontp=fontList.next();
|
||||
}
|
||||
}
|
||||
|
||||
void fontPool::mark_fonts_as_unused(void)
|
||||
|
@ -279,10 +390,11 @@ void fontPool::mark_fonts_as_unused(void)
|
|||
kdDebug(4300) << "Mark_fonts_as_unused" << endl;
|
||||
#endif
|
||||
|
||||
struct font *fontp;
|
||||
|
||||
for ( fontp =fontList.first(); fontp != 0; fontp=fontList.next() )
|
||||
struct font *fontp = fontList.first();
|
||||
while ( fontp != 0 ) {
|
||||
fontp->flags &= ~font::FONT_IN_USE;
|
||||
fontp=fontList.next();
|
||||
}
|
||||
}
|
||||
|
||||
void fontPool::release_fonts(void)
|
||||
|
@ -292,7 +404,6 @@ void fontPool::release_fonts(void)
|
|||
#endif
|
||||
|
||||
struct font *fontp = fontList.first();
|
||||
|
||||
while(fontp != 0) {
|
||||
if ((fontp->flags & font::FONT_IN_USE) != font::FONT_IN_USE) {
|
||||
fontList.removeRef(fontp);
|
||||
|
@ -304,23 +415,36 @@ void fontPool::release_fonts(void)
|
|||
|
||||
void fontPool::mf_output_receiver(KProcess *, char *buffer, int buflen)
|
||||
{
|
||||
int numleft;
|
||||
|
||||
// Paranoia.
|
||||
if (buflen < 0)
|
||||
return;
|
||||
|
||||
QString op = QString::fromLocal8Bit(buffer, buflen);
|
||||
|
||||
|
||||
MetafontOutput.append(op);
|
||||
|
||||
// We'd like to print only full lines of text.
|
||||
int numleft;
|
||||
bool show_prog = false;
|
||||
while( (numleft = MetafontOutput.find('\n')) != -1) {
|
||||
emit(MFOutput(MetafontOutput.left(numleft+1)));
|
||||
// kdDebug(4300) << "MF OUTPUT RECEIVED: " << MetafontOutput.left(numleft+1);
|
||||
QString line = MetafontOutput.left(numleft+1);
|
||||
#ifdef DEBUG_FONTPOOL
|
||||
kdDebug(4300) << "MF OUTPUT RECEIVED: " << line;
|
||||
#endif
|
||||
// Search for a line which marks the beginning of a MetaFont run
|
||||
// and show the progress dialog at the end of this method.
|
||||
if (line.find("kpathsea:") == 0)
|
||||
show_prog = true;
|
||||
emit(MFOutput(line));
|
||||
MetafontOutput = MetafontOutput.remove(0,numleft+1);
|
||||
}
|
||||
|
||||
// It is very important that this signal is emitted at the very end
|
||||
// of the method. The info-dialog is modal and QT branches into a
|
||||
// new event loop. The emit-command will therefore NOT return before
|
||||
// the dialog is closed, and the strings will be screwed up.
|
||||
if (show_prog == true)
|
||||
emit(show_progress());
|
||||
}
|
||||
|
||||
|
||||
|
|
13
fontpool.h
13
fontpool.h
|
@ -8,9 +8,12 @@
|
|||
|
||||
#include <qlist.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qobject.h>
|
||||
|
||||
#include "font.h"
|
||||
|
||||
class KProcess;
|
||||
class KShellProcess;
|
||||
|
||||
#define NumberOfMFModes 3
|
||||
#define DefaultMFMode 1
|
||||
|
@ -67,7 +70,7 @@ Q_OBJECT
|
|||
will be called. Since this is done using a concurrently running
|
||||
process, there is no guarantee that the loading is already
|
||||
performed when the method returns. */
|
||||
class font *appendx(char *fontname, float fsize, long checksum, int magstepval, double dconv);
|
||||
class font *appendx(char *fontname, long checksum, int scale, int design, class font *vfparent);
|
||||
|
||||
/** Prints very basic debugging information about the fonts in the
|
||||
pool to the kdDebug output stream. */
|
||||
|
@ -111,10 +114,16 @@ Q_OBJECT
|
|||
void release_fonts(void);
|
||||
|
||||
signals:
|
||||
/** Emitted to indicate that the progress dialog should show up now. */
|
||||
void show_progress(void);
|
||||
|
||||
/** Emitted to indicate that all the fonts have now been loaded so
|
||||
that the first page can be rendered. */
|
||||
void fonts_have_been_loaded(void);
|
||||
|
||||
/** The title says it all... */
|
||||
void hide_progress_dialog(void);
|
||||
|
||||
/** Emitted at the start of a kpsewhich job to indicate how many
|
||||
fonts there are to be looked up/generated. */
|
||||
void totalFontsInJob(int);
|
||||
|
@ -125,7 +134,7 @@ signals:
|
|||
|
||||
/** Emitted to pass output of MetaFont and friends on to the user
|
||||
interface. */
|
||||
void MFOutput(QString);
|
||||
void MFOutput(const QString);
|
||||
|
||||
/** Emitted when the font-pool has changed. The class receiving the
|
||||
signal might whish to call status() in order to receive the
|
||||
|
|
|
@ -21,20 +21,17 @@
|
|||
/*
|
||||
* Constructs a fontProgressDialog which is a child of 'parent', with the
|
||||
* name 'name' and widget flags set to 'f'
|
||||
*
|
||||
* The dialog will by default be modeless, unless you set 'modal' to
|
||||
* TRUE to construct a modal dialog.
|
||||
*/
|
||||
fontProgressDialog::fontProgressDialog( QWidget* parent, const QString &name )
|
||||
: KDialogBase( parent, "AAA", true, name, Cancel, Cancel, true )
|
||||
: KDialogBase( parent, "Font Generation Progress Dialog", true, name, Cancel, Cancel, true )
|
||||
{
|
||||
setCursor( QCursor( 3 ) );
|
||||
// setCaption( i18n( "Please wait..." ) );
|
||||
|
||||
setButtonCancelText( i18n("Abort"), i18n("Aborts the font generation. Don't do this."));
|
||||
|
||||
setHelp("", "kdvi"); //@@@
|
||||
setHelpLinkText( i18n( "What's going on?") );
|
||||
setHelp("fontgen", "kdvi");
|
||||
setHelpLinkText( i18n( "What's going on here?") );
|
||||
enableLinkedHelp(true);
|
||||
|
||||
QVBox *page = makeVBoxMainWidget();
|
||||
|
@ -68,10 +65,8 @@ fontProgressDialog::~fontProgressDialog()
|
|||
}
|
||||
|
||||
|
||||
void fontProgressDialog::outputReceiver(QString op)
|
||||
void fontProgressDialog::outputReceiver(const QString op)
|
||||
{
|
||||
show();
|
||||
|
||||
// If the Output of the kpsewhich program contains a line starting
|
||||
// with "kpathsea:", this means that a new MetaFont-run has been
|
||||
// started. We filter these lines out and print them in boldface.
|
||||
|
@ -81,7 +76,6 @@ void fontProgressDialog::outputReceiver(QString op)
|
|||
|
||||
int endstartline = op.find("\n",startlineindex);
|
||||
QString startLine = op.mid(startlineindex,endstartline-startlineindex);
|
||||
op = op.mid(endstartline);
|
||||
|
||||
// The last word in the startline is the name of the font which we
|
||||
// are generating. The second-to-last word is the resolution in
|
||||
|
@ -107,7 +101,8 @@ void fontProgressDialog::setTotalSteps(int steps)
|
|||
progress = 0;
|
||||
}
|
||||
|
||||
void fontProgressDialog::helpButtonPressed(void)
|
||||
void fontProgressDialog::show(void)
|
||||
{
|
||||
;
|
||||
KDialogBase::show();
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
public slots:
|
||||
/** Used to receive text from the external program. The text
|
||||
received here is analyzed and presented to the user. */
|
||||
void outputReceiver(QString);
|
||||
void outputReceiver(const QString);
|
||||
|
||||
/** Used to initialize the progress bar. */
|
||||
void setTotalSteps(int);
|
||||
|
@ -56,8 +56,8 @@ public slots:
|
|||
/** Called when font generation is finished. */
|
||||
void hideDialog(void);
|
||||
|
||||
/** Called when the "Help"-Button is pressed. */
|
||||
void helpButtonPressed(void);
|
||||
/** Called to show the dialog. */
|
||||
void show(void);
|
||||
|
||||
protected:
|
||||
int progress;
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
// (C) 2001 Stefan Kebekus
|
||||
// Distributed under the GPL
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <klocale.h>
|
||||
#include <kpushbutton.h>
|
||||
#include <qfile.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlayout.h>
|
||||
#include <qtextview.h>
|
||||
|
@ -83,8 +85,11 @@ void infoDialog::setFontInfo(class fontPool *fp)
|
|||
TextLabel2->setText(fp->status());
|
||||
}
|
||||
|
||||
void infoDialog::outputReceiver(QString op)
|
||||
void infoDialog::outputReceiver(const QString op)
|
||||
{
|
||||
if (MFOutputReceived == false)
|
||||
TextLabel3->setText("");
|
||||
|
||||
// If the Output of the kpsewhich program contains a line starting
|
||||
// with "kpathsea:", this means that a new MetaFont-run has been
|
||||
// started. We filter these lines out and print them in boldface.
|
||||
|
@ -92,14 +97,13 @@ void infoDialog::outputReceiver(QString op)
|
|||
if (startlineindex != -1) {
|
||||
int endstartline = op.find("\n",startlineindex);
|
||||
QString startLine = op.mid(startlineindex,endstartline-startlineindex);
|
||||
op = op.mid(endstartline);
|
||||
if (MFOutputReceived)
|
||||
TextLabel3->append("<hr>\n<b>"+startLine+"</b>");
|
||||
else {
|
||||
TextLabel3->setText("<b>"+startLine+"</b>");
|
||||
MFOutputReceived = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
TextLabel3->append("<b>"+startLine+"</b>");
|
||||
TextLabel3->append(op.mid(endstartline));
|
||||
} else
|
||||
TextLabel3->append(op);
|
||||
|
||||
TextLabel3->append(op);
|
||||
MFOutputReceived = true;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
public slots:
|
||||
/** This slot is called when Output from the MetaFont programm
|
||||
is received via the fontpool/kpsewhich */
|
||||
void outputReceiver(QString);
|
||||
void outputReceiver(const QString);
|
||||
|
||||
/** This slot is called whenever anything in the fontpool has
|
||||
changed. If the infoDialog is shown, the dialog could then
|
||||
|
|
|
@ -203,9 +203,6 @@ bool KDVIMultiPage::preview(QPainter *p, int w, int h)
|
|||
if (!map)
|
||||
return false;
|
||||
|
||||
// TODO: use higher quality preview if anti-aliasing?
|
||||
//p->drawImage(0, 0, window->pix()->convertToImage().smoothScale(w,h));
|
||||
|
||||
p->scale((double)w/(double)map->width(), (double)h/(double)map->height());
|
||||
p->drawPixmap(0, 0, *map);
|
||||
|
||||
|
@ -283,7 +280,7 @@ void KDVIMultiPage::helpme()
|
|||
|
||||
void KDVIMultiPage::preferencesChanged()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_MULTIPAGE
|
||||
kdDebug(4300) << "preferencesChanged" << endl;
|
||||
#endif
|
||||
|
||||
|
@ -353,7 +350,7 @@ bool KDVIMultiPage::print(const QStringList &pages, int current)
|
|||
|
||||
void KDVIMultiPage::timerEvent( QTimerEvent * )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_MULTIPAGE
|
||||
kdDebug(4300) << "Timer Event " << endl;
|
||||
#endif
|
||||
reload();
|
||||
|
@ -361,7 +358,7 @@ void KDVIMultiPage::timerEvent( QTimerEvent * )
|
|||
|
||||
void KDVIMultiPage::reload()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_MULTIPAGE
|
||||
kdDebug(4300) << "Reload file " << m_file << endl;
|
||||
#endif
|
||||
|
||||
|
@ -371,9 +368,14 @@ void KDVIMultiPage::reload()
|
|||
int currsav = window->curr_page();
|
||||
|
||||
window->setFile(m_file);
|
||||
|
||||
// Go to the old page and tell kviewshell where we are.
|
||||
window->gotoPage(currsav);
|
||||
emit pageInfo(window->totalPages(), window->curr_page()-1 ); // We don't use "currsav" here, because that page may no longer exist. In that case, gotoPage already selected another page.
|
||||
scrollView()->resizeContents(window->width(), window->height());
|
||||
// We don't use "currsav" here, because that page may no longer
|
||||
// exist. In that case, gotoPage already selected another page.
|
||||
emit pageInfo(window->totalPages(), window->curr_page()-1 );
|
||||
|
||||
// scrollView()->resizeContents(window->width(), window->height());
|
||||
emit previewChanged(true);
|
||||
} else {
|
||||
if (timer_id == -1)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <kapp.h>
|
||||
#include <kcombobox.h>
|
||||
#include <kconfig.h>
|
||||
#include <kdebug.h>
|
||||
#include <klocale.h>
|
||||
#include <kglobal.h>
|
||||
#include <kinstance.h>
|
||||
|
@ -43,6 +44,7 @@ OptionDialog::OptionDialog( QWidget *parent, const char *name, bool modal )
|
|||
{
|
||||
_instance = new KInstance("kdvi");
|
||||
setHelp("opts", "kdvi");
|
||||
|
||||
makeFontPage();
|
||||
makeRenderingPage();
|
||||
|
||||
|
@ -64,6 +66,17 @@ OptionDialog::OptionDialog( QWidget *parent, const char *name, bool modal )
|
|||
|
||||
void OptionDialog::show()
|
||||
{
|
||||
KConfig *config = _instance->config();
|
||||
config->reparseConfiguration();
|
||||
config->setGroup("kdvi");
|
||||
|
||||
mFont.metafontMode->setCurrentItem( config->readNumEntry( "MetafontMode" , DefaultMFMode ));
|
||||
mFont.fontPathCheck->setChecked( config->readBoolEntry( "MakePK", true ) );
|
||||
|
||||
// Rendering page
|
||||
mRender.showSpecialCheck->setChecked( config->readNumEntry( "ShowPS", 1 ) );
|
||||
mRender.showHyperLinksCheck->setChecked(config->readNumEntry("ShowHyperLinks", 1));
|
||||
|
||||
if( isVisible() == false )
|
||||
showPage(0);
|
||||
KDialogBase::show();
|
||||
|
|
Loading…
Reference in a new issue