2000-06-09 05:31:11 +00:00
|
|
|
|
2000-06-11 07:04:57 +00:00
|
|
|
// special.cpp
|
1997-10-18 11:34:02 +00:00
|
|
|
|
2000-06-11 07:04:57 +00:00
|
|
|
// Methods for dviwin which deal with "\special" commands found in the
|
|
|
|
// DVI file
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
// Copyright 2000--2004, Stefan Kebekus (kebekus@kde.org).
|
2000-06-11 07:04:57 +00:00
|
|
|
|
|
|
|
|
2003-03-07 11:54:35 +00:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <klocale.h>
|
2003-03-14 17:09:06 +00:00
|
|
|
#include <kprocio.h>
|
2003-04-01 11:09:15 +00:00
|
|
|
#include <kstringhandler.h>
|
2000-06-23 00:22:44 +00:00
|
|
|
#include <qdir.h>
|
2003-03-07 11:54:35 +00:00
|
|
|
#include <qfile.h>
|
2000-06-23 00:22:44 +00:00
|
|
|
#include <qfileinfo.h>
|
2004-12-21 06:06:43 +00:00
|
|
|
#include <qimage.h>
|
2001-05-15 08:43:44 +00:00
|
|
|
#include <qstringlist.h>
|
2000-05-27 05:05:03 +00:00
|
|
|
|
2000-05-20 05:08:51 +00:00
|
|
|
#include "dviwin.h"
|
2001-03-05 23:16:05 +00:00
|
|
|
#include "kdvi.h"
|
2004-03-29 15:14:35 +00:00
|
|
|
#include "kdvi_multipage.h"
|
2003-02-05 08:17:23 +00:00
|
|
|
#include "xdvi.h"
|
2000-06-09 05:31:11 +00:00
|
|
|
|
2005-01-01 15:26:17 +00:00
|
|
|
//#define DEBUG_SPECIAL
|
2000-02-29 11:27:53 +00:00
|
|
|
|
2000-06-09 05:31:11 +00:00
|
|
|
extern QPainter foreGroundPaint;
|
1997-10-18 11:34:02 +00:00
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::printErrorMsgForSpecials(QString msg)
|
2003-04-02 08:15:44 +00:00
|
|
|
{
|
2004-05-03 20:52:54 +00:00
|
|
|
if (dviFile->errorCounter < 25) {
|
2003-04-02 08:15:44 +00:00
|
|
|
kdError(4300) << msg << endl;
|
2004-05-03 20:52:54 +00:00
|
|
|
dviFile->errorCounter++;
|
|
|
|
if (dviFile->errorCounter == 25)
|
2003-04-02 08:15:44 +00:00
|
|
|
kdError(4300) << i18n("That makes 25 errors. Further error messages will not be printed.") << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parses a color specification, as explained in the manual to
|
|
|
|
// dvips. If the spec could not be parsed, an invalid color will be
|
|
|
|
// returned.
|
|
|
|
|
2003-08-20 07:04:56 +00:00
|
|
|
QColor parseColorSpecification(QString colorSpec)
|
2003-04-02 08:15:44 +00:00
|
|
|
{
|
2005-03-12 11:02:31 +00:00
|
|
|
QString specType = colorSpec.section(' ', 0, 0);
|
2003-04-02 08:15:44 +00:00
|
|
|
|
2003-04-02 18:12:45 +00:00
|
|
|
if (specType.find("rgb", false) == 0) {
|
2003-04-02 08:15:44 +00:00
|
|
|
bool ok;
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double r = colorSpec.section(' ', 1, 1).toDouble(&ok);
|
2003-04-02 08:15:44 +00:00
|
|
|
if ((ok == false) || (r < 0.0) || (r > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double g = colorSpec.section(' ', 2, 2).toDouble(&ok);
|
2003-04-02 08:15:44 +00:00
|
|
|
if ((ok == false) || (g < 0.0) || (g > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double b = colorSpec.section(' ', 3, 3).toDouble(&ok);
|
2003-04-02 08:15:44 +00:00
|
|
|
if ((ok == false) || (b < 0.0) || (b > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
|
|
|
return QColor((int)(r*255.0+0.5), (int)(g*255.0+0.5), (int)(b*255.0+0.5));
|
|
|
|
}
|
|
|
|
|
2003-04-02 18:12:45 +00:00
|
|
|
if (specType.find("hsb", false) == 0) {
|
|
|
|
bool ok;
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double h = colorSpec.section(' ', 1, 1).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (h < 0.0) || (h > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double s = colorSpec.section(' ', 2, 2).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (s < 0.0) || (s > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double b = colorSpec.section(' ', 3, 3).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (b < 0.0) || (b > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
|
|
|
return QColor((int)(h*359.0+0.5), (int)(s*255.0+0.5), (int)(b*255.0+0.5), QColor::Hsv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specType.find("cmyk", false) == 0) {
|
|
|
|
bool ok;
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double c = colorSpec.section(' ', 1, 1).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (c < 0.0) || (c > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double m = colorSpec.section(' ', 2, 2).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (m < 0.0) || (m > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double y = colorSpec.section(' ', 3, 3).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (y < 0.0) || (y > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double k = colorSpec.section(' ', 3, 3).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (k < 0.0) || (k > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
|
|
|
// Convert cmyk coordinates to rgb.
|
|
|
|
double r = 1.0 - c - k;
|
|
|
|
if (r < 0.0)
|
|
|
|
r = 0.0;
|
|
|
|
double g = 1.0 - m - k;
|
|
|
|
if (g < 0.0)
|
|
|
|
g = 0.0;
|
|
|
|
double b = 1.0 - y - k;
|
|
|
|
if (b < 0.0)
|
|
|
|
b = 0.0;
|
|
|
|
|
|
|
|
return QColor((int)(r*255.0+0.5), (int)(g*255.0+0.5), (int)(b*255.0+0.5));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specType.find("gray", false) == 0) {
|
|
|
|
bool ok;
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
double g = colorSpec.section(' ', 1, 1).toDouble(&ok);
|
2003-04-02 18:12:45 +00:00
|
|
|
if ((ok == false) || (g < 0.0) || (g > 1.0))
|
|
|
|
return QColor();
|
|
|
|
|
|
|
|
return QColor((int)(g*255.0+0.5), (int)(g*255.0+0.5), (int)(g*255.0+0.5));
|
|
|
|
}
|
2003-04-02 08:15:44 +00:00
|
|
|
|
2003-04-02 18:12:45 +00:00
|
|
|
return QColor(specType);
|
2003-04-02 08:15:44 +00:00
|
|
|
}
|
|
|
|
|
2003-04-02 18:12:45 +00:00
|
|
|
|
2003-07-10 07:13:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::color_special(QString cp)
|
2003-04-01 11:09:15 +00:00
|
|
|
{
|
2003-04-18 11:17:29 +00:00
|
|
|
cp = cp.stripWhiteSpace();
|
|
|
|
|
2005-03-12 11:02:31 +00:00
|
|
|
QString command = cp.section(' ', 0, 0);
|
2003-04-18 11:17:29 +00:00
|
|
|
|
|
|
|
if (command == "pop") {
|
|
|
|
// Take color off the stack
|
|
|
|
if (colorStack.isEmpty())
|
|
|
|
printErrorMsgForSpecials( i18n("Error in DVIfile '%1', page %2. Color pop command issued when the color stack is empty." ).
|
2004-05-03 20:52:54 +00:00
|
|
|
arg(dviFile->filename).arg(current_page));
|
2003-04-18 11:17:29 +00:00
|
|
|
else
|
|
|
|
colorStack.pop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command == "push") {
|
|
|
|
// Get color specification
|
|
|
|
QColor col = parseColorSpecification(KStringHandler::word(cp, "1:"));
|
2003-04-02 08:15:44 +00:00
|
|
|
// Set color
|
|
|
|
if (col.isValid())
|
2003-04-18 11:17:29 +00:00
|
|
|
colorStack.push(col);
|
2003-04-02 08:15:44 +00:00
|
|
|
else
|
2003-04-18 11:17:29 +00:00
|
|
|
colorStack.push(Qt::black);
|
2003-04-01 11:09:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-04-18 11:17:29 +00:00
|
|
|
|
|
|
|
// Get color specification and set the color for the rest of this
|
|
|
|
// page
|
|
|
|
QColor col = parseColorSpecification(cp);
|
|
|
|
// Set color
|
|
|
|
if (col.isValid())
|
|
|
|
globalColor = col;
|
|
|
|
else
|
|
|
|
globalColor = Qt::black;
|
|
|
|
return;
|
2003-04-01 11:09:15 +00:00
|
|
|
}
|
|
|
|
|
2003-04-02 18:12:45 +00:00
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::html_href_special(QString cp)
|
2000-06-09 05:31:11 +00:00
|
|
|
{
|
|
|
|
cp.truncate(cp.find('"'));
|
2003-04-18 11:17:29 +00:00
|
|
|
|
2000-06-09 05:31:11 +00:00
|
|
|
#ifdef DEBUG_SPECIAL
|
2001-03-15 15:11:36 +00:00
|
|
|
kdDebug(4300) << "HTML-special, href " << cp.latin1() << endl;
|
2000-06-09 05:31:11 +00:00
|
|
|
#endif
|
2003-04-18 11:17:29 +00:00
|
|
|
HTML_href = new QString(cp);
|
2000-06-09 05:31:11 +00:00
|
|
|
}
|
|
|
|
|
2003-08-20 07:04:56 +00:00
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::html_anchor_end(void)
|
2000-06-09 05:31:11 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_SPECIAL
|
2001-03-15 15:11:36 +00:00
|
|
|
kdDebug(4300) << "HTML-special, anchor-end" << endl;
|
2000-06-09 05:31:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (HTML_href != NULL) {
|
|
|
|
delete HTML_href;
|
|
|
|
HTML_href = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::source_special(QString cp)
|
2001-08-20 16:13:34 +00:00
|
|
|
{
|
2003-08-20 07:04:56 +00:00
|
|
|
// only when rendering really takes place: set source_href to the
|
|
|
|
// current special string. When characters are rendered, the
|
|
|
|
// rendering routine will then generate a DVI_HyperLink and add it
|
|
|
|
// to the proper list. This DVI_HyperLink is used to match mouse
|
|
|
|
// positions with the hyperlinks for inverse search.
|
|
|
|
if (source_href)
|
|
|
|
*source_href = cp;
|
|
|
|
else
|
|
|
|
source_href = new QString(cp);
|
2001-08-20 16:13:34 +00:00
|
|
|
}
|
|
|
|
|
2003-08-20 07:04:56 +00:00
|
|
|
|
|
|
|
void parse_special_argument(QString strg, const char *argument_name, int *variable)
|
2000-06-07 01:41:55 +00:00
|
|
|
{
|
|
|
|
bool OK;
|
|
|
|
|
|
|
|
int index = strg.find(argument_name);
|
|
|
|
if (index >= 0) {
|
|
|
|
QString tmp = strg.mid(index + strlen(argument_name));
|
|
|
|
tmp.truncate(tmp.find(' '));
|
2002-04-10 09:46:39 +00:00
|
|
|
float tmp_float = tmp.toFloat(&OK);
|
2000-06-07 01:41:55 +00:00
|
|
|
if (OK)
|
2002-04-10 09:46:39 +00:00
|
|
|
*variable = (int)(tmp_float+0.5);
|
2000-06-07 01:41:55 +00:00
|
|
|
else
|
2000-07-08 11:10:43 +00:00
|
|
|
// Maybe we should open a dialog here.
|
2001-03-15 15:11:36 +00:00
|
|
|
kdError(4300) << i18n("Malformed parameter in the epsf special command.") << endl;
|
2000-06-07 01:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-17 20:34:29 +00:00
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::epsf_special(QString cp)
|
1997-10-18 11:34:02 +00:00
|
|
|
{
|
2000-06-11 07:04:57 +00:00
|
|
|
#ifdef DEBUG_SPECIAL
|
2001-03-15 15:11:36 +00:00
|
|
|
kdDebug(4300) << "epsf-special: psfile=" << cp <<endl;
|
2000-06-11 07:04:57 +00:00
|
|
|
#endif
|
2000-06-07 01:41:55 +00:00
|
|
|
|
2000-06-09 05:31:11 +00:00
|
|
|
QString include_command = cp.simplifyWhiteSpace();
|
2000-06-07 01:41:55 +00:00
|
|
|
|
|
|
|
// The line is supposed to start with "..ile=", and then comes the
|
2000-09-19 12:20:04 +00:00
|
|
|
// filename. Figure out what the filename is and stow it away. Of
|
|
|
|
// course, this does not work if the filename contains spaces
|
|
|
|
// (already the simplifyWhiteSpace() above is wrong). If you have
|
|
|
|
// files like this, go away.
|
2000-06-23 00:22:44 +00:00
|
|
|
QString EPSfilename = include_command;
|
|
|
|
EPSfilename.truncate(EPSfilename.find(' '));
|
2000-09-19 12:20:04 +00:00
|
|
|
|
|
|
|
// Strip enclosing quotation marks which are included by some LaTeX
|
|
|
|
// macro packages (but not by others). This probably means that
|
|
|
|
// graphic files are no longer found if the filename really does
|
|
|
|
// contain quotes, but we don't really care that much.
|
|
|
|
if ((EPSfilename.at(0) == '\"') && (EPSfilename.at(EPSfilename.length()-1) == '\"')) {
|
|
|
|
EPSfilename = EPSfilename.mid(1,EPSfilename.length()-2);
|
|
|
|
}
|
2004-05-03 20:52:54 +00:00
|
|
|
EPSfilename = ghostscript_interface::locateEPSfile(EPSfilename, dviFile);
|
2000-09-19 12:20:04 +00:00
|
|
|
|
2000-06-07 01:41:55 +00:00
|
|
|
// Now parse the arguments.
|
|
|
|
int llx = 0;
|
|
|
|
int lly = 0;
|
|
|
|
int urx = 0;
|
|
|
|
int ury = 0;
|
|
|
|
int rwi = 0;
|
|
|
|
int rhi = 0;
|
2001-03-15 15:11:36 +00:00
|
|
|
int angle = 0;
|
2000-06-07 01:41:55 +00:00
|
|
|
|
|
|
|
// just to avoid ambiguities; the filename could contain keywords
|
|
|
|
include_command = include_command.mid(include_command.find(' '));
|
|
|
|
|
|
|
|
parse_special_argument(include_command, "llx=", &llx);
|
|
|
|
parse_special_argument(include_command, "lly=", &lly);
|
|
|
|
parse_special_argument(include_command, "urx=", &urx);
|
|
|
|
parse_special_argument(include_command, "ury=", &ury);
|
|
|
|
parse_special_argument(include_command, "rwi=", &rwi);
|
|
|
|
parse_special_argument(include_command, "rhi=", &rhi);
|
2001-03-15 15:11:36 +00:00
|
|
|
parse_special_argument(include_command, "angle=", &angle);
|
2000-06-07 01:41:55 +00:00
|
|
|
|
2004-12-21 06:06:43 +00:00
|
|
|
|
|
|
|
// If the file name ends in 'png', 'gif', 'jpg' or 'jpeg', we assume
|
|
|
|
// that this is NOT a PostScript file, and we need to draw that
|
|
|
|
// here.
|
|
|
|
QString ending = EPSfilename.section('.', -1).lower();
|
|
|
|
bool isGFX = false;
|
|
|
|
if ((ending == "png") || (ending == "gif") || (ending == "jpg") || (ending == "jpeg") || (ending == "mng"))
|
|
|
|
isGFX = true;
|
|
|
|
|
|
|
|
// So, if we do not have a PostScript file, but a graphics file, and
|
|
|
|
// if that file exists, we draw it here.
|
|
|
|
if (isGFX && QFile::exists(EPSfilename)) {
|
|
|
|
// Don't show PostScript, just draw the bounding box. For this,
|
|
|
|
// calculate the size of the bounding box in Pixels.
|
|
|
|
double bbox_width = urx - llx;
|
|
|
|
double bbox_height = ury - lly;
|
|
|
|
|
|
|
|
if ((rwi != 0)&&(bbox_width != 0)) {
|
|
|
|
bbox_height *= rwi/bbox_width;
|
|
|
|
bbox_width = rwi;
|
|
|
|
}
|
|
|
|
if ((rhi != 0)&&(bbox_height != 0)) {
|
|
|
|
bbox_width *= rhi/bbox_height;
|
|
|
|
bbox_height = rhi;
|
|
|
|
}
|
|
|
|
|
2005-01-24 07:08:35 +00:00
|
|
|
double fontPixelPerDVIunit = dviFile->getCmPerDVIunit() * 1200.0/2.54;
|
2004-12-21 06:06:43 +00:00
|
|
|
|
|
|
|
bbox_width *= 0.1 * 65536.0*fontPixelPerDVIunit / shrinkfactor;
|
|
|
|
bbox_height *= 0.1 * 65536.0*fontPixelPerDVIunit / shrinkfactor;
|
|
|
|
|
|
|
|
QImage image(EPSfilename);
|
2005-03-12 11:02:31 +00:00
|
|
|
image = image.smoothScale((int)(bbox_width), (int)(bbox_height));
|
2004-12-21 06:06:43 +00:00
|
|
|
foreGroundPaint.drawImage( ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))), currinf.data.pxl_v - (int)bbox_height, image);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-20 07:04:56 +00:00
|
|
|
if (!_postscript || !QFile::exists(EPSfilename)) {
|
|
|
|
// Don't show PostScript, just draw the bounding box. For this,
|
|
|
|
// calculate the size of the bounding box in Pixels.
|
|
|
|
double bbox_width = urx - llx;
|
|
|
|
double bbox_height = ury - lly;
|
|
|
|
|
|
|
|
if ((rwi != 0)&&(bbox_width != 0)) {
|
|
|
|
bbox_height *= rwi/bbox_width;
|
|
|
|
bbox_width = rwi;
|
2000-06-11 07:04:57 +00:00
|
|
|
}
|
2003-08-20 07:04:56 +00:00
|
|
|
if ((rhi != 0)&&(bbox_height != 0)) {
|
|
|
|
bbox_width *= rhi/bbox_height;
|
|
|
|
bbox_height = rhi;
|
2000-05-27 05:05:03 +00:00
|
|
|
}
|
2004-03-29 15:14:35 +00:00
|
|
|
|
2005-01-24 07:08:35 +00:00
|
|
|
double fontPixelPerDVIunit = dviFile->getCmPerDVIunit() * 1200.0/2.54;
|
2001-03-15 15:11:36 +00:00
|
|
|
|
2004-03-29 15:14:35 +00:00
|
|
|
bbox_width *= 0.1 * 65536.0*fontPixelPerDVIunit / shrinkfactor;
|
|
|
|
bbox_height *= 0.1 * 65536.0*fontPixelPerDVIunit / shrinkfactor;
|
2003-08-20 07:04:56 +00:00
|
|
|
|
2004-02-07 17:09:58 +00:00
|
|
|
QRect bbox(((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))), currinf.data.pxl_v - (int)bbox_height,
|
|
|
|
(int)bbox_width, (int)bbox_height);
|
2003-08-20 07:04:56 +00:00
|
|
|
foreGroundPaint.save();
|
|
|
|
if (QFile::exists(EPSfilename))
|
|
|
|
foreGroundPaint.setBrush(Qt::lightGray);
|
|
|
|
else
|
|
|
|
foreGroundPaint.setBrush(Qt::red);
|
|
|
|
foreGroundPaint.setPen(Qt::black);
|
|
|
|
foreGroundPaint.drawRoundRect(bbox, 2, 2);
|
|
|
|
if (QFile::exists(EPSfilename))
|
|
|
|
foreGroundPaint.drawText (bbox, (int)(Qt::AlignCenter), EPSfilename, -1);
|
|
|
|
else
|
|
|
|
foreGroundPaint.drawText (bbox, (int)(Qt::AlignCenter),
|
|
|
|
i18n("File not found: \n %1").arg(EPSfilename), -1);
|
|
|
|
foreGroundPaint.restore();
|
2001-03-15 15:11:36 +00:00
|
|
|
}
|
2003-08-20 07:04:56 +00:00
|
|
|
|
|
|
|
return;
|
2001-03-15 15:11:36 +00:00
|
|
|
}
|
|
|
|
|
2003-07-22 07:02:42 +00:00
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::TPIC_flushPath_special(void)
|
2003-07-22 07:02:42 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_SPECIAL
|
|
|
|
kdDebug(4300) << "TPIC special flushPath" << endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (number_of_elements_in_path == 0) {
|
|
|
|
printErrorMsgForSpecials("TPIC special flushPath called when path was empty.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
QPen pen(Qt::black, (int)(penWidth_in_mInch*resolutionInDPI/1000.0 + 0.5)); // Sets the pen size in milli-inches
|
2003-07-22 07:02:42 +00:00
|
|
|
foreGroundPaint.setPen(pen);
|
|
|
|
foreGroundPaint.drawPolyline(TPIC_path, 0, number_of_elements_in_path);
|
|
|
|
number_of_elements_in_path = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::TPIC_addPath_special(QString cp)
|
2003-07-22 07:02:42 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_SPECIAL
|
|
|
|
kdDebug(4300) << "TPIC special addPath: " << cp << endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Adds a point to the path list
|
|
|
|
QString cp_noWhiteSpace = cp.stripWhiteSpace();
|
|
|
|
bool ok;
|
2005-03-12 11:02:31 +00:00
|
|
|
float xKoord = cp_noWhiteSpace.section(' ', 0, 0).toFloat(&ok);
|
2003-07-22 07:02:42 +00:00
|
|
|
if (ok == false) {
|
|
|
|
printErrorMsgForSpecials( QString("TPIC special; cannot parse first argument in 'pn %1'.").arg(cp) );
|
|
|
|
return;
|
|
|
|
}
|
2005-03-12 11:02:31 +00:00
|
|
|
float yKoord = cp_noWhiteSpace.section(' ', 1, 1).toFloat(&ok);
|
2003-07-22 07:02:42 +00:00
|
|
|
if (ok == false) {
|
|
|
|
printErrorMsgForSpecials( QString("TPIC special; cannot parse second argument in 'pn %1'.").arg(cp) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-18 12:02:23 +00:00
|
|
|
float mag = dviFile->getMagnification()/1000.0;
|
|
|
|
|
|
|
|
int x = (int)( currinf.data.dvi_h/(shrinkfactor*65536.0) + mag*xKoord*resolutionInDPI/1000.0 + 0.5 );
|
|
|
|
int y = (int)( currinf.data.pxl_v + mag*yKoord*resolutionInDPI/1000.0 + 0.5 );
|
2003-07-22 07:02:42 +00:00
|
|
|
|
|
|
|
// Initialize the point array used to store the path
|
|
|
|
if (TPIC_path.size() == 0)
|
|
|
|
number_of_elements_in_path = 0;
|
|
|
|
if (TPIC_path.size() == number_of_elements_in_path)
|
|
|
|
TPIC_path.resize(number_of_elements_in_path+100);
|
|
|
|
TPIC_path.setPoint(number_of_elements_in_path++, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::TPIC_setPen_special(QString cp)
|
2003-07-22 07:02:42 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_SPECIAL
|
|
|
|
kdDebug(4300) << "TPIC special setPen: " << cp << endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Sets the pen size in milli-inches
|
|
|
|
bool ok;
|
|
|
|
penWidth_in_mInch = cp.stripWhiteSpace().toFloat(&ok);
|
|
|
|
if (ok == false) {
|
|
|
|
printErrorMsgForSpecials( QString("TPIC special; cannot parse argument in 'pn %1'.").arg(cp) );
|
|
|
|
penWidth_in_mInch = 0.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-15 07:17:50 +00:00
|
|
|
void dviRenderer::applicationDoSpecial(char *cp)
|
1997-10-18 11:34:02 +00:00
|
|
|
{
|
2000-06-07 01:41:55 +00:00
|
|
|
QString special_command(cp);
|
2001-08-13 07:37:47 +00:00
|
|
|
|
2003-04-18 11:17:29 +00:00
|
|
|
// First come specials which is only interpreted during rendering,
|
|
|
|
// and NOT during the prescan phase
|
|
|
|
|
|
|
|
// font color specials
|
|
|
|
if (strncasecmp(cp, "color", 5) == 0) {
|
2003-08-20 07:04:56 +00:00
|
|
|
color_special(special_command.mid(5));
|
2001-08-13 07:37:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-07 01:41:55 +00:00
|
|
|
|
2003-04-18 11:17:29 +00:00
|
|
|
// HTML reference
|
|
|
|
if (strncasecmp(cp, "html:<A href=", 13) == 0) {
|
2003-08-20 07:04:56 +00:00
|
|
|
html_href_special(special_command.mid(14));
|
2003-07-10 07:13:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-20 07:04:56 +00:00
|
|
|
// HTML anchor end
|
|
|
|
if (strncasecmp(cp, "html:</A>", 9) == 0) {
|
|
|
|
html_anchor_end();
|
2000-06-09 05:31:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-23 07:18:10 +00:00
|
|
|
// TPIC specials
|
|
|
|
if (strncasecmp(cp, "pn", 2) == 0) {
|
2003-08-20 07:04:56 +00:00
|
|
|
TPIC_setPen_special(special_command.mid(2));
|
2003-07-23 07:18:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-09-05 08:57:37 +00:00
|
|
|
if (strncasecmp(cp, "pa ", 3) == 0) {
|
2003-08-20 07:04:56 +00:00
|
|
|
TPIC_addPath_special(special_command.mid(3));
|
2003-07-23 07:18:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strncasecmp(cp, "fp", 2) == 0) {
|
2003-08-20 07:04:56 +00:00
|
|
|
TPIC_flushPath_special();
|
2003-07-23 07:18:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-20 07:04:56 +00:00
|
|
|
// Encapsulated Postscript File
|
|
|
|
if (strncasecmp(cp, "PSfile=", 7) == 0) {
|
|
|
|
epsf_special(special_command.mid(7));
|
|
|
|
return;
|
|
|
|
}
|
2003-04-18 11:17:29 +00:00
|
|
|
|
|
|
|
// source special
|
|
|
|
if (strncasecmp(cp, "src:", 4) == 0) {
|
|
|
|
source_special(special_command.mid(4));
|
2000-06-11 07:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-04-02 18:12:45 +00:00
|
|
|
|
2003-09-23 07:40:32 +00:00
|
|
|
// Unfortunately, in some TeX distribution the hyperref package uses
|
|
|
|
// the dvips driver by default, rather than the hypertex driver. As
|
|
|
|
// a result, the DVI files produced are full of PostScript that
|
|
|
|
// specifies links and anchors, and KDVI would call the ghostscript
|
|
|
|
// interpreter for every page which makes it really slow. This is a
|
|
|
|
// major nuisance, so that we try to filter and interpret the
|
|
|
|
// hypertex generated PostScript here.
|
|
|
|
if (special_command.startsWith("ps:SDict begin")) {
|
2003-11-24 18:50:10 +00:00
|
|
|
|
|
|
|
// Hyperref: start of hyperref rectangle. At this stage it is not
|
|
|
|
// yet clear if the rectangle will conain a hyperlink, an anchor,
|
|
|
|
// or another type of object. We suspect that this rectangle will
|
|
|
|
// define a hyperlink, allocate a QString and set HTML_href to
|
|
|
|
// point to this string. The string contains the name of the
|
|
|
|
// destination which ---due to the nature of the PostScript
|
|
|
|
// language--- will be defined only after characters are drawn and
|
|
|
|
// the hyperref rectangle has been closed. We use "glopglyph" as a
|
|
|
|
// temporary name. Since the pointer HTML_href is not NULL, the
|
|
|
|
// chracter drawing routines will now underline all characters in
|
|
|
|
// blue to point out that they correspond to a hyperlink. Also, as
|
|
|
|
// soon as characters are drawn, the drawing routines will
|
2004-10-23 12:00:07 +00:00
|
|
|
// allocate a Hyperlink and add it to the top of the vector
|
2004-04-19 08:19:15 +00:00
|
|
|
// currentlyDrawnPage->hyperLinkList.
|
2003-11-24 18:50:10 +00:00
|
|
|
if (special_command == "ps:SDict begin H.S end") {
|
|
|
|
// At this stage, the vector 'hyperLinkList' should not contain
|
|
|
|
// links with unspecified destinations (i.e. destination set to
|
|
|
|
// 'glopglyph'). As a protection against bad DVI files, we make
|
|
|
|
// sure to remove all link rectangles which point to
|
|
|
|
// 'glopglyph'.
|
2004-04-19 08:19:15 +00:00
|
|
|
while (!currentlyDrawnPage->hyperLinkList.isEmpty())
|
|
|
|
if (currentlyDrawnPage->hyperLinkList.last().linkText == "glopglyph")
|
|
|
|
currentlyDrawnPage->hyperLinkList.pop_back();
|
2003-11-24 18:50:10 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
2003-09-23 07:40:32 +00:00
|
|
|
HTML_href = new QString("glopglyph");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-24 18:50:10 +00:00
|
|
|
// Hyperref: end of hyperref rectangle of unknown type or hyperref
|
|
|
|
// link rectangle. In these cases we set HTML_href to NULL, which
|
|
|
|
// causes the character drawing routines to stop drawing
|
|
|
|
// characters underlined in blue. Note that the name of the
|
|
|
|
// destination is still set to "glopglyph". In a well-formed DVI
|
|
|
|
// file, this special command is immediately followed by another
|
|
|
|
// special, where the destination is specified. This special is
|
|
|
|
// treated below.
|
|
|
|
if ((special_command == "ps:SDict begin H.R end") || special_command.endsWith("H.L end")) {
|
2003-09-23 07:40:32 +00:00
|
|
|
if (HTML_href != NULL) {
|
|
|
|
delete HTML_href;
|
|
|
|
HTML_href = NULL;
|
|
|
|
}
|
|
|
|
return; // end of hyperref rectangle
|
|
|
|
}
|
|
|
|
|
2003-11-24 18:50:10 +00:00
|
|
|
// Hyperref: end of anchor rectangle. If this special is
|
|
|
|
// encountered, the rectangle, which was started with "ps:SDict
|
|
|
|
// begin H.S end" does not contain a link, but an anchor for a
|
|
|
|
// link. Anchors, however, have already been dealt with in the
|
|
|
|
// prescan phase and will not be considered here. Thus, we set
|
|
|
|
// HTML_href to NULL so that character drawing routines will no
|
|
|
|
// longer underline hyperlinks in blue, and remove the link from
|
|
|
|
// the hyperLinkList. NOTE: in a well-formed DVI file, the "H.A"
|
|
|
|
// special comes directly after the "H.S" special. A
|
|
|
|
// hyperlink-anchor rectangle therefore never contains characters,
|
|
|
|
// so no character will by accidentally underlined in blue.
|
2003-09-23 07:40:32 +00:00
|
|
|
if (special_command.endsWith("H.A end")) {
|
|
|
|
if (HTML_href != NULL) {
|
|
|
|
delete HTML_href;
|
|
|
|
HTML_href = NULL;
|
|
|
|
}
|
2004-04-19 08:19:15 +00:00
|
|
|
while (!currentlyDrawnPage->hyperLinkList.isEmpty())
|
|
|
|
if (currentlyDrawnPage->hyperLinkList.last().linkText == "glopglyph")
|
|
|
|
currentlyDrawnPage->hyperLinkList.pop_back();
|
2003-11-24 18:50:10 +00:00
|
|
|
else
|
|
|
|
break;
|
2003-09-23 07:40:32 +00:00
|
|
|
return; // end of hyperref anchor
|
|
|
|
}
|
|
|
|
|
2003-11-24 18:50:10 +00:00
|
|
|
// Hyperref: specification of a hyperref link rectangle's
|
|
|
|
// destination. As mentioned above, the destination of a hyperlink
|
|
|
|
// is specified only AFTER the rectangle has been specified. We
|
|
|
|
// will therefore go through the list of rectangles stored in
|
2004-04-19 08:19:15 +00:00
|
|
|
// currentlyDrawnPage->hyperLinkList, find those whose destination
|
2003-11-24 18:50:10 +00:00
|
|
|
// is open and fill in the value found here. NOTE: the character
|
|
|
|
// drawing routines sometimes split a single hyperlink rectangle
|
|
|
|
// into several rectangles (e.g. if the font changes, or when a
|
|
|
|
// line break is encountered)
|
2003-09-23 07:40:32 +00:00
|
|
|
if (special_command.startsWith("ps:SDict begin [") && special_command.endsWith(" pdfmark end")) {
|
2004-04-19 08:19:15 +00:00
|
|
|
if (!currentlyDrawnPage->hyperLinkList.isEmpty()) {
|
2003-09-23 07:40:32 +00:00
|
|
|
QString targetName = special_command.section('(', 1, 1).section(')', 0, 0);
|
2004-10-23 12:00:07 +00:00
|
|
|
QValueVector<Hyperlink>::iterator it;
|
2004-04-19 08:19:15 +00:00
|
|
|
for( it = currentlyDrawnPage->hyperLinkList.begin(); it != currentlyDrawnPage->hyperLinkList.end(); ++it )
|
2003-11-24 18:50:10 +00:00
|
|
|
if (it->linkText == "glopglyph")
|
|
|
|
it->linkText = targetName;
|
2003-09-23 07:40:32 +00:00
|
|
|
}
|
|
|
|
return; // hyperref definition of link/anchor/bookmark/etc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-17 20:34:29 +00:00
|
|
|
// Detect text rotation specials that are included by the graphicx
|
|
|
|
// package. If one of these specials is found, the state of the
|
|
|
|
// painter is saved, and the coordinate system is rotated
|
|
|
|
// accordingly
|
|
|
|
if (special_command.startsWith("ps: gsave currentpoint currentpoint translate ") &&
|
|
|
|
special_command.endsWith(" neg rotate neg exch neg exch translate") ) {
|
|
|
|
bool ok;
|
|
|
|
double angle = special_command.section(' ', 5, 5).toDouble(&ok);
|
|
|
|
if (ok == true) {
|
|
|
|
int x = ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536)));
|
|
|
|
int y = currinf.data.pxl_v;
|
|
|
|
|
|
|
|
foreGroundPaint.save();
|
|
|
|
// Rotate about the current point
|
|
|
|
foreGroundPaint.translate(x,y);
|
|
|
|
foreGroundPaint.rotate(-angle);
|
|
|
|
foreGroundPaint.translate(-x,-y);
|
|
|
|
} else
|
|
|
|
printErrorMsgForSpecials( i18n("Error in DVIfile '%1', page %2. Could not interpret angle in text rotation special." ).
|
|
|
|
arg(dviFile->filename).arg(current_page));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The graphicx package marks the end of rotated text with this
|
|
|
|
// special. The state of the painter is restored.
|
|
|
|
if (special_command == "ps: currentpoint grestore moveto") {
|
|
|
|
foreGroundPaint.restore();
|
|
|
|
}
|
2003-09-23 07:40:32 +00:00
|
|
|
|
2003-08-20 07:04:56 +00:00
|
|
|
// The following special commands are not used here; they are of
|
|
|
|
// interest only during the prescan phase. We recognize them here
|
|
|
|
// anyway, to make sure that KDVI doesn't complain about
|
|
|
|
// unrecognized special commands.
|
|
|
|
if ((cp[0] == '!') ||
|
|
|
|
(cp[0] == '"') ||
|
|
|
|
(strncasecmp(cp, "html:<A name=", 13) == 0) ||
|
|
|
|
(strncasecmp(cp, "ps:", 3) == 0) ||
|
2003-09-05 08:57:37 +00:00
|
|
|
(strncasecmp(cp, "papersize", 9) == 0) ||
|
2003-08-20 07:04:56 +00:00
|
|
|
(strncasecmp(cp, "background", 10) == 0) )
|
2003-04-18 11:17:29 +00:00
|
|
|
return;
|
|
|
|
|
2003-04-02 08:15:44 +00:00
|
|
|
printErrorMsgForSpecials(i18n("The special command '%1' is not implemented.").arg(special_command));
|
2000-06-07 01:41:55 +00:00
|
|
|
return;
|
1997-10-18 11:34:02 +00:00
|
|
|
}
|