#define DEBUG_SPECIAL #include #include "dviwin.h" #include #include #include #include "oconfig.h" extern "C" { #define HAVE_PROTOTYPES #include #include #include #include #include #include } extern QPainter foreGroundPaint; void draw_bbox() { #ifdef auskommentiert if (bbox_valid) { put_border(PXL_H - currwin.base_x, PXL_V - currwin.base_y - bbox_voffset, bbox_width, bbox_height); bbox_valid = False; } #endif } #ifdef auskommentiert /* If FILENAME starts with a left quote, set *DECOMPRESS to 1 and return the rest of FILENAME. Otherwise, look up FILENAME along the usual path for figure files, set *DECOMPRESS to 0, and return the result (NULL if can't find the file). */ static string find_fig_file (char *filename) { char *name; name = kpse_find_pict (filename); if (!name) kdError() << "Cannot open PS file " << filename << endl; return name; } /* If DECOMPRESS is zero, pass NAME to the drawfile proc. But if DECOMPRESS is nonzero, open a pipe to it and pass the resulting output to the drawraw proc (in chunks). */ static void draw_file (psprocs psp, char *name) { kDebugInfo(DEBUG, 4300, "draw file %s",name); psp.drawfile (name); } static void psfig_special(char *cp) { kDebugInfo("PSFig special: %s",cp); char *filename; int raww, rawh; if (strncmp(cp, ":[begin]", 8) == 0) { cp += 8; bbox_valid = False; if (sscanf(cp,"%d %d\n", &raww, &rawh) >= 2) { bbox_valid = True; bbox_width = pixel_conv(spell_conv(raww)); bbox_height = pixel_conv(spell_conv(rawh)); bbox_voffset = 0; } if (currwin.win == mane.win) psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y,cp); } else if (strncmp(cp, " plotfile ", 10) == 0) { cp += 10; while (isspace(*cp)) cp++; for (filename = cp; !isspace(*cp); ++cp); *cp = '\0'; { char *name = find_fig_file (filename); if (name && currwin.win == mane.win) { draw_file(psp, name); if (name != filename) free (name); } } } else if (strncmp(cp, ":[end]", 6) == 0) { cp += 6; if (currwin.win == mane.win) psp.drawend(cp); bbox_valid = False; } else { /* I am going to send some raw postscript stuff */ if (*cp == ':') ++cp; /* skip second colon in ps:: */ if (currwin.win == mane.win) { /* It's drawbegin that initializes the ps process, so make sure it's started up. */ psp.drawbegin(PXL_H - currwin.base_x, PXL_V - currwin.base_y, ""); psp.drawend(""); psp.drawraw(cp); } } } #endif void dviWindow::html_href_special(QString cp) { cp.truncate(cp.find('"')); #ifdef DEBUG_SPECIAL kdDebug() << "HTML-special, href " << cp.latin1() << endl; #endif if (!PostScriptOutPutString) { // only when rendering really takes place HTML_href = new QString(cp); } } void dviWindow::html_anchor_end(void) { #ifdef DEBUG_SPECIAL kdDebug() << "HTML-special, anchor-end" << endl; #endif if (HTML_href != NULL) { delete HTML_href; HTML_href = NULL; } } void dviWindow::header_special(QString cp) { #ifdef DEBUG_SPECIAL kdDebug() << "PostScript-special, header " << cp.latin1() << endl; #endif if (PostScriptOutPutString) { PostScriptHeaderString.append( QString(" (%1) run\n").arg(cp) ); } } static void parse_special_argument(QString strg, char *argument_name, int *variable) { bool OK; int index = strg.find(argument_name); if (index >= 0) { QString tmp = strg.mid(index + strlen(argument_name)); tmp.truncate(tmp.find(' ')); int tmp_int = tmp.toUInt(&OK); if (OK) *variable = tmp_int; else kdError() << "Malformed urx in special" << endl; } } void dviWindow::epsf_special(QString cp) { kdError() << "epsf-special: psfile=" << cp <append( "@beginspecial @setspecial \n" ); PostScriptOutPutString->append( QString(" (%1) run\n").arg(filename) ); PostScriptOutPutString->append( "@endspecial \n" ); } else { kdDebug() << "_postscript " << _postscript << endl; if (!_postscript) { // Don't show PostScript, just draw to bounding box QRect bbox(PXL_H - currwin.base_x, PXL_V - currwin.base_y, (int)bbox_width, (int)bbox_height); foreGroundPaint.setBrush(Qt::lightGray); foreGroundPaint.setPen (Qt::black); foreGroundPaint.drawRoundRect(bbox, 1, 1); foreGroundPaint.drawText (bbox, (int)(Qt::AlignCenter), filename, -1, &bbox); } } return; } void dviWindow::bang_special(QString cp) { #ifdef DEBUG_SPECIAL // kdDebug() << "PostScript-special, literal header " << cp.latin1() << endl; #endif if (currwin.win == mane.win && PostScriptOutPutString) { PostScriptHeaderString.append( " @defspecial \n" ); PostScriptHeaderString.append( cp ); PostScriptHeaderString.append( " @fedspecial \n" ); } } void dviWindow::quote_special(QString cp) { #ifdef DEBUG_SPECIAL // kdError() << "PostScript-special, literal PostScript " << cp.latin1() << endl; #endif if (currwin.win == mane.win && PostScriptOutPutString) { PostScriptOutPutString->append( QString(" %1 %2 moveto\n").arg(DVI_H/65536 - 300).arg(DVI_V/65536 - 520) ); PostScriptOutPutString->append( " @beginspecial @setspecial \n" ); PostScriptOutPutString->append( cp ); PostScriptOutPutString->append( " @endspecial \n" ); } } void dviWindow::applicationDoSpecial(char *cp) { QString special_command(cp); // Literal Postscript inclusion if (special_command[0] == '"') { quote_special(special_command.mid(1)); return; } // Literal Postscript Header if (special_command[0] == '!') { bang_special(special_command.mid(1)); return; } // Encapsulated Postscript File if (special_command.find("PSfile=") == 0 || special_command.find("psfile=") == 0) { epsf_special(special_command.mid(7)); return; } // Postscript Header File if (special_command.find("header=") == 0) { header_special(special_command.mid(7)); return; } // HTML reference if (special_command.find("html:") == 0) { html_anchor_end(); return; } kdError() << "special \"" << cp << "\" not implemented" << endl; return; }