1997-10-18 11:34:02 +00:00
|
|
|
//
|
|
|
|
// Class: dviWindow
|
|
|
|
//
|
|
|
|
// Widget for displaying TeX DVI files.
|
2001-12-14 16:50:02 +00:00
|
|
|
// Part of KDVI- A previewer for TeX DVI files.
|
|
|
|
//
|
|
|
|
// (C) 2001 Stefan Kebekus
|
|
|
|
// Distributed under the GPL
|
1997-10-18 11:34:02 +00:00
|
|
|
//
|
|
|
|
|
1999-06-27 19:06:40 +00:00
|
|
|
#ifndef _dviwin_h_
|
|
|
|
#define _dviwin_h_
|
|
|
|
|
2000-05-15 06:51:49 +00:00
|
|
|
|
1997-10-18 11:34:02 +00:00
|
|
|
#include <qevent.h>
|
2000-05-26 00:00:15 +00:00
|
|
|
#include <qintdict.h>
|
2002-08-07 08:15:17 +00:00
|
|
|
#include <qpainter.h>
|
2001-11-03 14:23:24 +00:00
|
|
|
#include <qptrvector.h>
|
2002-08-07 08:15:17 +00:00
|
|
|
#include <qvaluestack.h>
|
|
|
|
#include <qvaluevector.h>
|
|
|
|
#include <qwidget.h>
|
2000-11-03 14:38:50 +00:00
|
|
|
#include <kviewpart.h>
|
|
|
|
|
2001-10-18 16:40:34 +00:00
|
|
|
#include "bigEndianByteReader.h"
|
2000-06-23 00:22:44 +00:00
|
|
|
#include "dvi_init.h"
|
2003-03-27 08:20:15 +00:00
|
|
|
#include "fontpool.h"
|
2003-03-07 11:54:35 +00:00
|
|
|
#include "psgs.h"
|
2001-11-23 15:26:13 +00:00
|
|
|
#include "selection.h"
|
2000-06-23 00:22:44 +00:00
|
|
|
|
2003-03-07 11:54:35 +00:00
|
|
|
class dviWindow;
|
2001-06-04 09:44:47 +00:00
|
|
|
class fontProgressDialog;
|
2001-03-28 10:16:48 +00:00
|
|
|
class infoDialog;
|
2001-11-26 12:32:34 +00:00
|
|
|
class KAction;
|
2001-11-01 09:53:31 +00:00
|
|
|
class KEdFind;
|
2001-06-04 09:44:47 +00:00
|
|
|
class KPrinter;
|
2003-03-07 11:54:35 +00:00
|
|
|
class KProcess;
|
2001-05-03 08:45:04 +00:00
|
|
|
class KShellProcess;
|
2003-03-07 11:54:35 +00:00
|
|
|
class TeXFontDefinition;
|
|
|
|
|
2003-02-13 21:28:22 +00:00
|
|
|
extern const int MFResolutions[];
|
2000-06-23 00:22:44 +00:00
|
|
|
|
2003-04-06 17:32:11 +00:00
|
|
|
|
|
|
|
// If this is defined, KDVI will emitt debugging messages to tell how
|
|
|
|
// long certain tasks take
|
|
|
|
|
2000-06-09 05:31:11 +00:00
|
|
|
class DVI_Hyperlink {
|
|
|
|
public:
|
2003-01-06 16:41:24 +00:00
|
|
|
DVI_Hyperlink() {}
|
|
|
|
DVI_Hyperlink(Q_UINT32 bl, QRect re, QString lT): baseline(bl), box(re), linkText(lT) {}
|
|
|
|
|
|
|
|
Q_UINT32 baseline;
|
|
|
|
QRect box;
|
|
|
|
QString linkText;
|
2000-06-09 05:31:11 +00:00
|
|
|
};
|
|
|
|
|
2003-01-06 16:41:24 +00:00
|
|
|
class DVI_Anchor {
|
|
|
|
public:
|
|
|
|
DVI_Anchor() {}
|
2003-01-16 15:45:13 +00:00
|
|
|
DVI_Anchor(Q_UINT32 pg, double vc): page(pg), vertical_coordinate(vc) {}
|
2003-01-06 16:41:24 +00:00
|
|
|
|
|
|
|
Q_UINT32 page;
|
|
|
|
double vertical_coordinate;
|
|
|
|
};
|
1997-10-18 11:34:02 +00:00
|
|
|
|
2003-01-16 15:45:13 +00:00
|
|
|
class DVI_SourceFileAnchor {
|
|
|
|
public:
|
|
|
|
DVI_SourceFileAnchor() {}
|
|
|
|
DVI_SourceFileAnchor(QString &name, Q_UINT32 ln, Q_UINT32 pg, double vc): fileName(name), line(ln), page(pg), vertical_coordinate(vc) {}
|
|
|
|
|
|
|
|
QString fileName;
|
|
|
|
Q_UINT32 line;
|
|
|
|
Q_UINT32 page;
|
|
|
|
double vertical_coordinate;
|
|
|
|
};
|
|
|
|
|
2001-10-12 01:32:07 +00:00
|
|
|
/** Compound of registers, as defined in section 2.6.2 of the DVI
|
2001-08-09 07:35:46 +00:00
|
|
|
driver standard, Level 0, published by the TUG DVI driver
|
|
|
|
standards committee. */
|
|
|
|
|
|
|
|
struct framedata {
|
|
|
|
long dvi_h;
|
|
|
|
long dvi_v;
|
|
|
|
long w;
|
|
|
|
long x;
|
|
|
|
long y;
|
|
|
|
long z;
|
|
|
|
int pxl_v;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-02-19 12:54:27 +00:00
|
|
|
/* this information is saved when using virtual fonts */
|
|
|
|
|
|
|
|
typedef void (dviWindow::*set_char_proc)(unsigned int, unsigned int);
|
|
|
|
struct drawinf {
|
2003-03-07 11:54:35 +00:00
|
|
|
struct framedata data;
|
|
|
|
TeXFontDefinition *fontp;
|
|
|
|
set_char_proc set_char_p;
|
2003-02-19 12:54:27 +00:00
|
|
|
|
2003-04-27 15:58:38 +00:00
|
|
|
QIntDict<TeXFontDefinition> *fonttable;
|
2003-03-07 11:54:35 +00:00
|
|
|
TeXFontDefinition *_virtual;
|
2003-02-19 12:54:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-10-18 16:40:34 +00:00
|
|
|
class dviWindow : public QWidget, bigEndianByteReader
|
1997-10-18 11:34:02 +00:00
|
|
|
{
|
2000-05-26 00:00:15 +00:00
|
|
|
Q_OBJECT
|
1997-10-18 11:34:02 +00:00
|
|
|
|
|
|
|
public:
|
2003-03-27 08:20:15 +00:00
|
|
|
dviWindow( double zoom, QWidget *parent=0, const char *name=0 );
|
2000-05-26 00:00:15 +00:00
|
|
|
~dviWindow();
|
|
|
|
|
2001-03-02 21:02:45 +00:00
|
|
|
class dvifile *dviFile;
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2001-03-28 10:16:48 +00:00
|
|
|
void showInfo();
|
2001-06-04 09:44:47 +00:00
|
|
|
void exportPS(QString fname = QString::null, QString options = QString::null, KPrinter *printer = 0);
|
2001-05-03 08:45:04 +00:00
|
|
|
void exportPDF();
|
2001-10-27 11:38:16 +00:00
|
|
|
void exportText();
|
|
|
|
|
2001-11-23 15:26:13 +00:00
|
|
|
void changePageSize(void);
|
|
|
|
int totalPages(void);
|
2003-02-05 08:17:23 +00:00
|
|
|
void setShowPS( bool flag );
|
|
|
|
bool showPS(void) { return _postscript; };
|
2001-11-23 15:26:13 +00:00
|
|
|
int curr_page(void) { return current_page+1; };
|
2003-02-05 08:17:23 +00:00
|
|
|
void setShowHyperLinks( bool flag );
|
|
|
|
bool showHyperLinks(void) { return _showHyperLinks; };
|
2001-08-20 16:13:34 +00:00
|
|
|
void setEditorCommand( QString command ) { editorCommand = command; };
|
2000-05-26 00:00:15 +00:00
|
|
|
void setPaper(double w, double h);
|
2000-06-23 00:22:44 +00:00
|
|
|
bool correctDVI(QString filename);
|
2000-05-26 00:00:15 +00:00
|
|
|
|
|
|
|
// for the preview
|
2000-06-23 00:22:44 +00:00
|
|
|
QPixmap *pix() { return pixmap; };
|
2000-06-07 01:41:55 +00:00
|
|
|
|
|
|
|
// These should not be public... only for the moment
|
2000-06-09 05:31:11 +00:00
|
|
|
void mousePressEvent ( QMouseEvent * e );
|
2001-04-08 09:21:27 +00:00
|
|
|
void mouseMoveEvent ( QMouseEvent * e );
|
2001-11-11 10:50:44 +00:00
|
|
|
void mouseReleaseEvent ( QMouseEvent * e );
|
2000-06-07 01:41:55 +00:00
|
|
|
void read_postamble(void);
|
2001-08-09 07:35:46 +00:00
|
|
|
void draw_part(double current_dimconv, bool is_vfmacro);
|
2000-06-09 05:31:11 +00:00
|
|
|
void set_vf_char(unsigned int cmd, unsigned int ch);
|
|
|
|
void set_char(unsigned int cmd, unsigned int ch);
|
|
|
|
void set_empty_char(unsigned int cmd, unsigned int ch);
|
|
|
|
void set_no_char(unsigned int cmd, unsigned int ch);
|
2000-08-06 10:25:11 +00:00
|
|
|
void applicationDoSpecial(char * cp);
|
2001-08-20 16:13:34 +00:00
|
|
|
|
|
|
|
|
2000-06-09 05:31:11 +00:00
|
|
|
void special(long nbytes);
|
2003-04-02 08:15:44 +00:00
|
|
|
void printErrorMsgForSpecials(QString msg);
|
2003-04-02 18:12:45 +00:00
|
|
|
void background_special(QString cp);
|
2003-04-01 11:09:15 +00:00
|
|
|
void color_special(QString cp);
|
2000-06-09 05:31:11 +00:00
|
|
|
void html_href_special(QString cp);
|
|
|
|
void html_anchor_end(void);
|
2000-06-11 07:04:57 +00:00
|
|
|
void html_anchor_special(QString cp);
|
2001-03-02 21:02:45 +00:00
|
|
|
void draw_page(void);
|
2000-06-23 00:22:44 +00:00
|
|
|
|
2003-03-27 08:20:15 +00:00
|
|
|
fontPool *font_pool;
|
2001-05-03 08:45:04 +00:00
|
|
|
|
2001-07-09 07:41:24 +00:00
|
|
|
double xres; // horizontal resolution of the display device in dots per inch.
|
2003-02-19 12:54:27 +00:00
|
|
|
double paper_width_in_cm; // paper width in centimeters
|
|
|
|
double paper_height_in_cm; // paper height in centimeters
|
2001-07-09 07:41:24 +00:00
|
|
|
|
2001-11-23 15:26:13 +00:00
|
|
|
selection DVIselection;
|
|
|
|
|
2001-11-20 12:46:54 +00:00
|
|
|
/** Reference part of the URL which describes the filename. */
|
|
|
|
QString reference;
|
2001-07-09 07:41:24 +00:00
|
|
|
|
2001-11-26 12:32:34 +00:00
|
|
|
QString searchText;
|
|
|
|
KAction *findNextAction;
|
|
|
|
KAction *findPrevAction;
|
2001-07-09 07:41:24 +00:00
|
|
|
|
1997-10-18 11:34:02 +00:00
|
|
|
public slots:
|
2001-11-23 15:26:13 +00:00
|
|
|
void selectAll(void);
|
|
|
|
void copyText(void);
|
|
|
|
void showFindTextDialog(void);
|
2001-11-26 12:32:34 +00:00
|
|
|
void findText(void);
|
|
|
|
void findNextText(void);
|
|
|
|
void findPrevText(void);
|
2001-11-23 15:26:13 +00:00
|
|
|
|
2001-05-03 08:45:04 +00:00
|
|
|
void abortExternalProgramm(void);
|
2001-11-27 10:56:25 +00:00
|
|
|
bool setFile(QString fname, QString ref = QString::null, bool sourceMarker=true);
|
2001-05-21 07:15:24 +00:00
|
|
|
|
2003-01-02 13:13:09 +00:00
|
|
|
/** simply emits "setStatusBarText( QString::null )". This is used
|
|
|
|
in dviWindow::mouseMoveEvent(), see the explanation there. */;
|
|
|
|
void clearStatusBar(void);
|
|
|
|
|
2001-05-21 07:15:24 +00:00
|
|
|
/** Displays the page of the first argument */
|
2001-08-28 13:02:20 +00:00
|
|
|
void gotoPage(unsigned int page);
|
2001-05-21 07:15:24 +00:00
|
|
|
|
|
|
|
/** Displays the page of the first argument, and blinks the display
|
|
|
|
at the vertical offset vflashOffset. This is used when the user
|
|
|
|
clicks on a hyperlink: the target of the jump flashes so that
|
|
|
|
the user can locate it more easily. */
|
|
|
|
void gotoPage(int page, int vflashOffset);
|
2000-11-03 14:38:50 +00:00
|
|
|
double setZoom(double zoom);
|
2000-06-11 07:04:57 +00:00
|
|
|
double zoom() { return _zoom; };
|
2001-03-02 21:02:45 +00:00
|
|
|
void drawPage();
|
2001-09-03 08:57:03 +00:00
|
|
|
|
|
|
|
/** Slots used in conjunction with external programs */
|
2001-05-03 08:45:04 +00:00
|
|
|
void dvips_output_receiver(KProcess *, char *buffer, int buflen);
|
|
|
|
void dvips_terminated(KProcess *);
|
2001-09-03 08:57:03 +00:00
|
|
|
void editorCommand_terminated(KProcess *);
|
2001-11-26 12:32:34 +00:00
|
|
|
|
2001-11-01 09:53:31 +00:00
|
|
|
|
2001-11-16 16:26:38 +00:00
|
|
|
/** This slot is usually called by the fontpool if all fonts are
|
|
|
|
loaded. The method will try to parse the reference part of the
|
|
|
|
DVI file's URL, e.g. src:<line><filename> and see if a
|
|
|
|
corresponding section of the DVI file can be found. If so, it
|
|
|
|
will emit a "requestGotoPage", otherwise it will just call
|
|
|
|
drawpage */
|
2003-04-06 17:32:11 +00:00
|
|
|
void all_fonts_loaded(fontPool *);
|
2001-11-16 16:26:38 +00:00
|
|
|
|
2000-06-11 07:04:57 +00:00
|
|
|
signals:
|
2001-06-05 07:25:25 +00:00
|
|
|
/** Emitted to indicate that a hyperlink has been clicked on, and
|
|
|
|
that the widget requests that the controlling program goes to the
|
|
|
|
page and the coordinates specified. */
|
2000-06-11 07:04:57 +00:00
|
|
|
void request_goto_page(int page, int y);
|
2000-06-01 10:27:41 +00:00
|
|
|
|
2001-06-05 07:25:25 +00:00
|
|
|
/** Emitted to indicate the the contents of the widget has changed
|
|
|
|
and that the tumbnail image should be updated. */
|
|
|
|
void contents_changed(void);
|
|
|
|
|
2001-06-11 13:40:16 +00:00
|
|
|
/** Passed through to the top-level kpart. */
|
|
|
|
void setStatusBarText( const QString& );
|
|
|
|
|
1997-10-18 11:34:02 +00:00
|
|
|
protected:
|
2001-11-01 09:53:31 +00:00
|
|
|
void paintEvent(QPaintEvent *ev);
|
2000-05-15 06:51:49 +00:00
|
|
|
|
1997-10-18 11:34:02 +00:00
|
|
|
private:
|
2003-03-07 11:54:35 +00:00
|
|
|
/** Shrink factor. Units are not quite clear */
|
|
|
|
double shrinkfactor;
|
2003-02-28 08:27:07 +00:00
|
|
|
|
2001-11-01 09:53:31 +00:00
|
|
|
QString errorMsg;
|
|
|
|
|
2001-08-20 16:13:34 +00:00
|
|
|
/** Methods which handle certain special commands. */
|
|
|
|
void bang_special(QString cp);
|
|
|
|
void quote_special(QString cp);
|
|
|
|
void ps_special(QString cp);
|
|
|
|
void epsf_special(QString cp);
|
|
|
|
void header_special(QString cp);
|
|
|
|
void source_special(QString cp);
|
|
|
|
|
2003-01-02 13:13:09 +00:00
|
|
|
/* This timer is used to delay clearing of the statusbar. Clearing
|
|
|
|
the statusbar is delayed to avoid awful flickering when the mouse
|
|
|
|
moves over a block of text that contains source hyperlinks. The
|
|
|
|
signal timeout() is connected to the method clearStatusBar() of
|
|
|
|
*this. */
|
|
|
|
QTimer clearStatusBarTimer;
|
2002-12-23 12:32:25 +00:00
|
|
|
|
2003-01-16 15:45:13 +00:00
|
|
|
// List of source-hyperlinks in the current page. This vector is
|
|
|
|
// generated when the current page is drawn.
|
|
|
|
QValueVector<DVI_Hyperlink> sourceHyperLinkList;
|
2002-12-23 12:32:25 +00:00
|
|
|
|
2003-01-16 15:45:13 +00:00
|
|
|
// 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
|
|
|
|
// with PostScriptOutPutString != NULL
|
|
|
|
QValueVector<DVI_SourceFileAnchor> sourceHyperLinkAnchors;
|
2001-08-20 16:13:34 +00:00
|
|
|
|
2003-01-16 15:45:13 +00:00
|
|
|
// If not NULL, the text currently drawn represents a source
|
|
|
|
// hyperlink to the (relative) URL given in the string;
|
|
|
|
QString *source_href;
|
2001-08-20 16:13:34 +00:00
|
|
|
|
2003-01-16 15:45:13 +00:00
|
|
|
QValueVector<DVI_Hyperlink> textLinkList; // List of text in the window
|
|
|
|
QValueVector<DVI_Hyperlink> hyperLinkList; // List of ordinary hyperlinks
|
2001-10-27 11:38:16 +00:00
|
|
|
|
2003-01-16 15:45:13 +00:00
|
|
|
// If not NULL, the text currently drawn represents a hyperlink to
|
|
|
|
// the (relative) URL given in the string;
|
|
|
|
QString *HTML_href;
|
|
|
|
|
|
|
|
QString editorCommand;
|
|
|
|
|
2001-08-09 07:35:46 +00:00
|
|
|
/** Stack for register compounds, used for the DVI-commands PUSH/POP
|
|
|
|
as explained in section 2.5 and 2.6.2 of the DVI driver standard,
|
|
|
|
Level 0, published by the TUG DVI driver standards committee. */
|
|
|
|
QValueStack<struct framedata> stack;
|
|
|
|
|
2003-04-01 11:09:15 +00:00
|
|
|
/** A stack where color are stored, according to the documentation of
|
|
|
|
DVIPS */
|
|
|
|
QValueStack<QColor> colorStack;
|
|
|
|
|
|
|
|
/** The global color is to be used when the color stack is empty */
|
|
|
|
QColor globalColor;
|
|
|
|
|
2001-05-21 07:15:24 +00:00
|
|
|
/** Methods and counters used for the animation to mark the target of
|
|
|
|
an hyperlink. */
|
|
|
|
int timerIdent;
|
|
|
|
void timerEvent( QTimerEvent *e );
|
|
|
|
int animationCounter;
|
|
|
|
int flashOffset;
|
|
|
|
|
2001-11-10 19:56:40 +00:00
|
|
|
/** Methods and classes concerned with the find functionality and
|
|
|
|
with selecting text */
|
2001-11-01 09:53:31 +00:00
|
|
|
class KEdFind *findDialog;
|
2001-12-14 16:50:02 +00:00
|
|
|
QPoint firstSelectedPoint;
|
2001-11-10 19:56:40 +00:00
|
|
|
QRect selectedRectangle;
|
|
|
|
|
2001-03-28 10:16:48 +00:00
|
|
|
infoDialog *info;
|
|
|
|
|
2001-08-09 07:35:46 +00:00
|
|
|
/** If PostScriptOutPutFile is non-zero, then no rendering takes
|
|
|
|
place. Instead, the PostScript code which is generated by the
|
|
|
|
\special-commands is written to the PostScriptString */
|
|
|
|
QString *PostScriptOutPutString;
|
2000-06-09 05:31:11 +00:00
|
|
|
|
2000-06-23 00:22:44 +00:00
|
|
|
ghostscript_interface *PS_interface;
|
2000-06-09 05:31:11 +00:00
|
|
|
|
2001-09-03 08:57:03 +00:00
|
|
|
/** TRUE, if gs should be used, otherwise, only bounding boxes are
|
|
|
|
drawn. */
|
2003-02-05 08:17:23 +00:00
|
|
|
bool _postscript;
|
2000-06-09 05:31:11 +00:00
|
|
|
|
2001-09-03 08:57:03 +00:00
|
|
|
/** TRUE, if Hyperlinks should be shown. */
|
2003-02-05 08:17:23 +00:00
|
|
|
bool _showHyperLinks;
|
2000-06-14 04:15:22 +00:00
|
|
|
|
2001-09-03 08:57:03 +00:00
|
|
|
/** This flag is used when rendering a dvi-page. It is set to "true"
|
|
|
|
when any dvi-command other than "set" or "put" series of commands
|
|
|
|
is encountered. This is considered to mark the end of a word. */
|
2001-10-27 11:38:16 +00:00
|
|
|
bool line_boundary_encountered;
|
2001-07-06 10:14:01 +00:00
|
|
|
bool word_boundary_encountered;
|
|
|
|
|
2001-09-03 08:57:03 +00:00
|
|
|
/** List of anchors in a document */
|
2003-01-06 16:41:24 +00:00
|
|
|
QMap<QString, DVI_Anchor> anchorList;
|
2000-06-11 07:04:57 +00:00
|
|
|
|
2003-03-27 08:20:15 +00:00
|
|
|
double fontPixelPerDVIunit() {return dviFile->cmPerDVIunit * MFResolutions[font_pool->getMetafontMode()]/2.54;};
|
2003-02-13 21:28:22 +00:00
|
|
|
|
2000-06-09 05:31:11 +00:00
|
|
|
QPixmap *pixmap;
|
|
|
|
int ChangesPossible;
|
2001-08-28 13:02:20 +00:00
|
|
|
unsigned int current_page;
|
2001-09-03 08:57:03 +00:00
|
|
|
|
|
|
|
/** Indicates if the current page is already drawn (=1) or not
|
|
|
|
(=0). */
|
2000-07-07 02:07:26 +00:00
|
|
|
char is_current_page_drawn;
|
2003-02-19 12:54:27 +00:00
|
|
|
|
|
|
|
// Zoom factor. 1.0 means "100%"
|
2000-06-09 05:31:11 +00:00
|
|
|
double _zoom;
|
2001-05-03 08:45:04 +00:00
|
|
|
|
2001-09-03 08:57:03 +00:00
|
|
|
/** Used to run and to show the progress of dvips and friends. */
|
2001-05-03 08:45:04 +00:00
|
|
|
fontProgressDialog *progress;
|
2001-06-04 09:44:47 +00:00
|
|
|
KShellProcess *proc;
|
|
|
|
KPrinter *export_printer;
|
|
|
|
QString export_fileName;
|
2001-08-28 13:02:20 +00:00
|
|
|
QString export_tmpFileName;
|
2001-09-03 08:57:03 +00:00
|
|
|
QString export_errorString;
|
2003-02-19 12:54:27 +00:00
|
|
|
|
|
|
|
struct drawinf currinf;
|
1997-10-18 11:34:02 +00:00
|
|
|
};
|
1999-06-27 19:06:40 +00:00
|
|
|
|
2000-05-20 05:08:51 +00:00
|
|
|
|
2000-08-18 17:53:00 +00:00
|
|
|
|
1999-06-27 19:06:40 +00:00
|
|
|
#endif
|