1997-10-18 11:34:02 +00:00
|
|
|
//
|
2004-11-15 07:17:50 +00:00
|
|
|
// Class: dviRenderer
|
1997-10-18 11:34:02 +00:00
|
|
|
//
|
2004-11-15 07:17:50 +00:00
|
|
|
// Class for rendering TeX DVI files.
|
2001-12-14 16:50:02 +00:00
|
|
|
// Part of KDVI- A previewer for TeX DVI files.
|
|
|
|
//
|
2004-11-13 11:23:53 +00:00
|
|
|
// (C) 2001-2004 Stefan Kebekus. Distributed under the GPL.
|
2003-05-16 07:17:38 +00:00
|
|
|
|
1997-10-18 11:34:02 +00:00
|
|
|
|
2005-06-02 10:05:50 +00:00
|
|
|
#ifndef _dvirenderer_h_
|
|
|
|
#define _dvirenderer_h_
|
1999-06-27 19:06:40 +00:00
|
|
|
|
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>
|
|
|
|
|
2004-11-13 11:23:53 +00:00
|
|
|
#include "anchor.h"
|
2001-10-18 16:40:34 +00:00
|
|
|
#include "bigEndianByteReader.h"
|
2004-11-13 11:23:53 +00:00
|
|
|
#include "documentRenderer.h"
|
2003-06-17 06:42:22 +00:00
|
|
|
#include "dviFile.h"
|
2003-03-27 08:20:15 +00:00
|
|
|
#include "fontpool.h"
|
2004-05-03 20:52:54 +00:00
|
|
|
#include "infodialog.h"
|
2004-11-20 14:50:29 +00:00
|
|
|
#include "pageSize.h"
|
2003-03-07 11:54:35 +00:00
|
|
|
#include "psgs.h"
|
2005-04-30 08:51:52 +00:00
|
|
|
#include "renderedDocumentPage.h"
|
2004-04-14 07:45:04 +00:00
|
|
|
|
2000-06-23 00:22:44 +00:00
|
|
|
|
2005-05-05 08:50:23 +00:00
|
|
|
class DocumentWidget;
|
2004-11-15 07:17:50 +00:00
|
|
|
class dviRenderer;
|
2001-06-04 09:44:47 +00:00
|
|
|
class fontProgressDialog;
|
2004-05-03 20:52:54 +00:00
|
|
|
class infoDialog;
|
2001-11-26 12:32:34 +00:00
|
|
|
class KAction;
|
2004-03-29 15:14:35 +00:00
|
|
|
class KDVIMultiPage;
|
2001-06-04 09:44:47 +00:00
|
|
|
class KPrinter;
|
2003-03-07 11:54:35 +00:00
|
|
|
class KProcess;
|
2003-09-07 12:12:29 +00:00
|
|
|
class KProgressDialog;
|
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-01-16 15:45:13 +00:00
|
|
|
class DVI_SourceFileAnchor {
|
|
|
|
public:
|
|
|
|
DVI_SourceFileAnchor() {}
|
2005-04-30 08:51:52 +00:00
|
|
|
DVI_SourceFileAnchor(QString &name, Q_UINT32 ln, Q_UINT32 pg, Length _distance_from_top): fileName(name), line(ln), page(pg),
|
|
|
|
distance_from_top(_distance_from_top) {}
|
2003-01-16 15:45:13 +00:00
|
|
|
|
|
|
|
QString fileName;
|
|
|
|
Q_UINT32 line;
|
|
|
|
Q_UINT32 page;
|
2005-04-30 08:51:52 +00:00
|
|
|
Length distance_from_top;
|
2003-01-16 15:45:13 +00:00
|
|
|
};
|
|
|
|
|
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 */
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
typedef void (dviRenderer::*set_char_proc)(unsigned int, unsigned int);
|
|
|
|
typedef void (dviRenderer::*parseSpecials)(char *, Q_UINT8 *);
|
2003-09-05 08:57:37 +00:00
|
|
|
|
2003-02-19 12:54:27 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-05-16 07:17:38 +00:00
|
|
|
|
2005-04-30 08:51:52 +00:00
|
|
|
class dviRenderer : public DocumentRenderer, 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:
|
2004-11-15 07:17:50 +00:00
|
|
|
dviRenderer(QWidget *parent);
|
|
|
|
~dviRenderer();
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2004-11-13 11:23:53 +00:00
|
|
|
virtual bool setFile(const QString &fname);
|
|
|
|
|
2004-05-03 20:52:54 +00:00
|
|
|
class dvifile *dviFile;
|
|
|
|
|
2005-01-24 07:08:35 +00:00
|
|
|
void setPrefs(bool flag_showPS, const QString &editorCommand, bool useFontHints );
|
2004-05-03 20:52:54 +00:00
|
|
|
|
2005-01-01 15:26:17 +00:00
|
|
|
virtual bool supportsTextSearch(void) {return true;};
|
2001-10-27 11:38:16 +00:00
|
|
|
|
2003-02-05 08:17:23 +00:00
|
|
|
bool showPS(void) { return _postscript; };
|
2001-11-23 15:26:13 +00:00
|
|
|
int curr_page(void) { return current_page+1; };
|
2004-12-10 19:05:16 +00:00
|
|
|
virtual bool isValidFile(const QString fileName);
|
2004-11-09 14:16:30 +00:00
|
|
|
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
/** This method will try to parse the reference part of the DVI
|
|
|
|
file's URL, (either a number, which is supposed to be a page
|
|
|
|
number, or src:<line><filename>) and see if a corresponding
|
|
|
|
section of the DVI file can be found. If so, it returns an
|
|
|
|
anchor to that section. If not, it returns an invalid anchor. */
|
2005-03-06 06:11:22 +00:00
|
|
|
virtual Anchor parseReference(const QString &reference);
|
2000-05-26 00:00:15 +00:00
|
|
|
|
2000-06-07 01:41:55 +00:00
|
|
|
// These should not be public... only for the moment
|
|
|
|
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-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);
|
2001-03-02 21:02:45 +00:00
|
|
|
void draw_page(void);
|
2000-06-23 00:22:44 +00:00
|
|
|
|
1997-10-18 11:34:02 +00:00
|
|
|
public slots:
|
2005-01-01 15:26:17 +00:00
|
|
|
void exportPS(QString fname = QString::null, QString options = QString::null, KPrinter *printer = 0);
|
|
|
|
void exportPDF();
|
|
|
|
|
2004-05-03 20:52:54 +00:00
|
|
|
void showInfo(void);
|
2005-05-05 08:50:23 +00:00
|
|
|
void handleSRCLink(const QString &linkText, QMouseEvent *e, DocumentWidget *widget);
|
2004-04-14 07:45:04 +00:00
|
|
|
|
2003-09-05 08:57:37 +00:00
|
|
|
void embedPostScript(void);
|
2001-05-03 08:45:04 +00:00
|
|
|
void abortExternalProgramm(void);
|
2001-05-21 07:15:24 +00:00
|
|
|
|
2003-01-02 13:13:09 +00:00
|
|
|
/** simply emits "setStatusBarText( QString::null )". This is used
|
2004-11-15 07:17:50 +00:00
|
|
|
in dviRenderer::mouseMoveEvent(), see the explanation there. */
|
2003-01-02 13:13:09 +00:00
|
|
|
void clearStatusBar(void);
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
|
2004-11-29 08:14:53 +00:00
|
|
|
|
2005-04-30 08:51:52 +00:00
|
|
|
void drawPage(double res, RenderedDocumentPage *page);
|
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
|
|
|
|
2000-06-11 07:04:57 +00:00
|
|
|
signals:
|
2001-06-11 13:40:16 +00:00
|
|
|
/** Passed through to the top-level kpart. */
|
2005-04-25 16:07:47 +00:00
|
|
|
// void setStatusBarText( const QString& );
|
2001-06-11 13:40:16 +00:00
|
|
|
|
2004-11-13 11:23:53 +00:00
|
|
|
private slots:
|
|
|
|
/** This method shows a dialog that tells the user that source
|
|
|
|
information is present, and gives the opportunity to open the
|
|
|
|
manual and learn more about forward and inverse search */
|
|
|
|
void showThatSourceInformationIsPresent(void);
|
2000-05-15 06:51:49 +00:00
|
|
|
|
1997-10-18 11:34:02 +00:00
|
|
|
private:
|
2004-11-29 08:14:53 +00:00
|
|
|
void setResolution(double resolution_in_DPI);
|
|
|
|
|
2004-05-03 20:52:54 +00:00
|
|
|
fontPool font_pool;
|
2004-06-01 14:56:52 +00:00
|
|
|
infoDialog *info;
|
2004-05-03 20:52:54 +00:00
|
|
|
|
2004-11-29 08:14:53 +00:00
|
|
|
double resolutionInDPI;
|
2004-05-03 20:52:54 +00:00
|
|
|
|
2003-09-05 08:57:37 +00:00
|
|
|
// @@@ explanation
|
|
|
|
void prescan(parseSpecials specialParser);
|
|
|
|
void prescan_embedPS(char *cp, Q_UINT8 *);
|
2004-08-22 17:39:15 +00:00
|
|
|
void prescan_removePageSizeInfo(char *cp, Q_UINT8 *);
|
2003-09-05 08:57:37 +00:00
|
|
|
void prescan_parseSpecials(char *cp, Q_UINT8 *);
|
|
|
|
void prescan_ParsePapersizeSpecial(QString cp);
|
|
|
|
void prescan_ParseBackgroundSpecial(QString cp);
|
|
|
|
void prescan_ParseHTMLAnchorSpecial(QString cp);
|
|
|
|
void prescan_ParsePSHeaderSpecial(QString cp);
|
|
|
|
void prescan_ParsePSBangSpecial(QString cp);
|
|
|
|
void prescan_ParsePSQuoteSpecial(QString cp);
|
|
|
|
void prescan_ParsePSSpecial(QString cp);
|
|
|
|
void prescan_ParsePSFileSpecial(QString cp);
|
|
|
|
void prescan_ParseSourceSpecial(QString cp);
|
|
|
|
void prescan_setChar(unsigned int ch);
|
2005-06-22 08:30:51 +00:00
|
|
|
|
|
|
|
/* */
|
|
|
|
QStringList bookMarkTitles;
|
|
|
|
QStringList bookMarkAnchors;
|
|
|
|
|
|
|
|
|
2003-09-07 12:12:29 +00:00
|
|
|
/** Utility fields used by the embedPostScript method*/
|
|
|
|
KProgressDialog *embedPS_progress;
|
|
|
|
Q_UINT16 embedPS_numOfProgressedFiles;
|
|
|
|
|
2003-09-05 08:57:37 +00:00
|
|
|
/** Shrink factor. Units are not quite clear */
|
|
|
|
double shrinkfactor;
|
|
|
|
|
|
|
|
QString errorMsg;
|
|
|
|
|
|
|
|
/** Methods which handle certain special commands. */
|
|
|
|
void epsf_special(QString cp);
|
|
|
|
void source_special(QString cp);
|
|
|
|
|
|
|
|
/** TPIC specials */
|
|
|
|
void TPIC_setPen_special(QString cp);
|
|
|
|
void TPIC_addPath_special(QString cp);
|
|
|
|
void TPIC_flushPath_special(void);
|
|
|
|
|
2004-11-20 14:50:29 +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. */
|
2003-09-05 08:57:37 +00:00
|
|
|
QTimer clearStatusBarTimer;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// If not NULL, the text currently drawn represents a source
|
|
|
|
// hyperlink to the (relative) URL given in the string;
|
|
|
|
QString *source_href;
|
|
|
|
|
|
|
|
// If not NULL, the text currently drawn represents a hyperlink to
|
|
|
|
// the (relative) URL given in the string;
|
|
|
|
QString *HTML_href;
|
|
|
|
|
|
|
|
QString editorCommand;
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
|
|
|
|
/** 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;
|
2004-04-14 07:45:04 +00:00
|
|
|
|
2003-09-05 08:57:37 +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;
|
|
|
|
|
|
|
|
ghostscript_interface *PS_interface;
|
|
|
|
|
|
|
|
/** TRUE, if gs should be used, otherwise, only bounding boxes are
|
|
|
|
drawn. */
|
|
|
|
bool _postscript;
|
|
|
|
|
|
|
|
/** 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. */
|
|
|
|
bool line_boundary_encountered;
|
|
|
|
bool word_boundary_encountered;
|
|
|
|
|
|
|
|
unsigned int current_page;
|
|
|
|
|
|
|
|
/** Used to run and to show the progress of dvips and friends. */
|
|
|
|
fontProgressDialog *progress;
|
|
|
|
KShellProcess *proc;
|
|
|
|
KPrinter *export_printer;
|
|
|
|
QString export_fileName;
|
|
|
|
QString export_tmpFileName;
|
|
|
|
QString export_errorString;
|
|
|
|
|
|
|
|
/** Data required for handling TPIC specials */
|
|
|
|
float penWidth_in_mInch;
|
|
|
|
QPointArray TPIC_path;
|
|
|
|
Q_UINT16 number_of_elements_in_path;
|
|
|
|
|
|
|
|
struct drawinf currinf;
|
2005-04-30 08:51:52 +00:00
|
|
|
RenderedDocumentPage* currentlyDrawnPage;
|
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
|