diff --git a/doc/KDVI-features.dvi b/doc/KDVI-features.dvi index bb032ea9a..63dfdb49f 100644 Binary files a/doc/KDVI-features.dvi and b/doc/KDVI-features.dvi differ diff --git a/doc/KDVI-features.tex b/doc/KDVI-features.tex index 79999b968..19df49e4f 100644 --- a/doc/KDVI-features.tex +++ b/doc/KDVI-features.tex @@ -1,6 +1,7 @@ -\documentclass[11pt]{article} +\documentclass{article} \usepackage{amstext} +\usepackage{colordvi} \usepackage{graphicx} \usepackage{times} \usepackage[arrow,matrix,curve,ps]{xy} @@ -17,13 +18,6 @@ \title{Support for \TeX\ extensions in \KDVI} \author{Stefan Kebekus} -%\address{Stefan Kebekus, Institut für Mathematik, Universität -%Bayreuth, 95440 Bayreuth, Germany} -%\curraddr{Research Institute for Mathematical Studies, Kyoto -%University, Oiwake-cho, Kitashirakawa, Sakyo-ku, Kyoto 606-8502, -%Japan} -%\email{kebekus@kde.org} -%\urladdr{http://btm8x5.mat.uni-bayreuth.de/\~{}kebekus} \maketitle \begin{abstract} @@ -304,6 +298,31 @@ Here is an external link which points to the \href{http://www.kde.org}{main website of the KDE project} \end{verbatim} +\section{Colored text} + +The DVI specials for colored text are supported as they are described +in \cite{dvips}. The following code was used to generate the text below: + +\paragraph*{Example} In this document, the following code was used +\begin{verbatim} +\usepackage{colordvi} + +... + +\textGreen This text is green but here we are +\Red{switching to red, \Blue{nesting blue}, +recovering the red} and back to original green. +\textCyan The text from here on will be cyan +unless \Yellow{locally changed to yellow}. Now +we are back to cyan. \textBlack +\end{verbatim} + +This gave the following output: \textGreen This text is green but here +we are \Red{switching to red, \Blue{nesting blue}, recovering the red} +and back to original green. \textCyan The text from here on will be +cyan unless \Yellow{locally changed to yellow}. Now we are back to +cyan. \textBlack + \section{Source text specials} diff --git a/dviwin.h b/dviwin.h index 21fa714ad..8210d3902 100644 --- a/dviwin.h +++ b/dviwin.h @@ -141,6 +141,7 @@ public: void special(long nbytes); void printErrorMsgForSpecials(QString msg); + void background_special(QString cp); void color_special(QString cp); void html_href_special(QString cp); void html_anchor_end(void); diff --git a/psgs.cpp b/psgs.cpp index 9c6324fdd..33ce4060d 100644 --- a/psgs.cpp +++ b/psgs.cpp @@ -50,6 +50,7 @@ ghostscript_interface::~ghostscript_interface() { delete PostScriptHeaderString; } + void ghostscript_interface::setSize(double dpi, int pxlw, int pxlh) { resolution = dpi; pixel_page_w = pxlw; @@ -61,12 +62,35 @@ void ghostscript_interface::setSize(double dpi, int pxlw, int pxlh) { void ghostscript_interface::setPostScript(int page, QString PostScript) { - pageInfo *info = new pageInfo(PostScript); + if (pageList->find(page) == 0) { + pageInfo *info = new pageInfo(PostScript); + // Check if dict is big enough + if (pageList->count() > pageList->size() -2) + pageList->resize(pageList->size()*2); + pageList->insert(page, info); + } else + *(pageList->find(page)->PostScriptString) = PostScript; +} + + +void ghostscript_interface::setColor(int page, QColor background_color) { + if (pageList->find(page) == 0) { + pageInfo *info = new pageInfo(QString::null); + info->background = background_color; + // Check if dict is big enough + if (pageList->count() > pageList->size() -2) + pageList->resize(pageList->size()*2); + pageList->insert(page, info); + } else + pageList->find(page)->background = background_color; +} + - // Check if dict is big enough - if (pageList->count() > pageList->size() -2) - pageList->resize(pageList->size()*2); - pageList->insert(page, info); +QColor ghostscript_interface::getBackgroundColor(int page) { + if (pageList->find(page) == 0) + return Qt::white; + else + return pageList->find(page)->background; } diff --git a/psgs.h b/psgs.h index 4fb46f08c..f456786da 100644 --- a/psgs.h +++ b/psgs.h @@ -15,6 +15,7 @@ public: pageInfo(QString _PostScriptString); ~pageInfo(); + QColor background; QString *PostScriptString; KTempFile *Gfx; }; @@ -39,14 +40,21 @@ public: void clear(); - // + // sets the PostScript which is used on a certain page void setPostScript(int page, QString PostScript); + // sets the background color for a certain page + void setColor(int page, QColor background_color); + // Returns the graphics of the page, if possible. The functions // returns a pointer to a QPixmap, or null. The referred QPixmap // should be deleted after use. QPixmap *graphics(int page); + // Returns the background color for a certain page. If no color was + // set, Qt::white is returned. + QColor getBackgroundColor(int page); + QString *PostScriptHeaderString; private: @@ -61,7 +69,7 @@ private: // slow to render. QIntCache *DiskCache; - double resolution; // in dots per inch + double resolution; // in dots per inch int pixel_page_w; // in pixels int pixel_page_h; // in pixels diff --git a/special.cpp b/special.cpp index 6c45b68ed..dc6bb4887 100644 --- a/special.cpp +++ b/special.cpp @@ -41,7 +41,7 @@ static QColor parseColorSpecification(QString colorSpec) { QString specType = KStringHandler::word(colorSpec, (unsigned int)0); - if (specType.find("rgb") == 0) { + if (specType.find("rgb", false) == 0) { bool ok; double r = KStringHandler::word(colorSpec, (unsigned int)1).toDouble(&ok); @@ -59,11 +59,71 @@ static QColor parseColorSpecification(QString colorSpec) return QColor((int)(r*255.0+0.5), (int)(g*255.0+0.5), (int)(b*255.0+0.5)); } - kdDebug() << "Spec not implemented : " << colorSpec << endl; + if (specType.find("hsb", false) == 0) { + bool ok; + + double h = KStringHandler::word(colorSpec, (unsigned int)1).toDouble(&ok); + if ((ok == false) || (h < 0.0) || (h > 1.0)) + return QColor(); + + double s = KStringHandler::word(colorSpec, (unsigned int)2).toDouble(&ok); + if ((ok == false) || (s < 0.0) || (s > 1.0)) + return QColor(); + + double b = KStringHandler::word(colorSpec, (unsigned int)3).toDouble(&ok); + 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; + + double c = KStringHandler::word(colorSpec, (unsigned int)1).toDouble(&ok); + if ((ok == false) || (c < 0.0) || (c > 1.0)) + return QColor(); + + double m = KStringHandler::word(colorSpec, (unsigned int)2).toDouble(&ok); + if ((ok == false) || (m < 0.0) || (m > 1.0)) + return QColor(); + + double y = KStringHandler::word(colorSpec, (unsigned int)3).toDouble(&ok); + if ((ok == false) || (y < 0.0) || (y > 1.0)) + return QColor(); + + double k = KStringHandler::word(colorSpec, (unsigned int)3).toDouble(&ok); + 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; + + double g = KStringHandler::word(colorSpec, (unsigned int)1).toDouble(&ok); + 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)); + } - return Qt::green; + return QColor(specType); } + void dviWindow::color_special(QString cp) { // The color specials are ignored during the pre-scan phase, we use @@ -107,6 +167,21 @@ void dviWindow::color_special(QString cp) } } + +void dviWindow::background_special(QString cp) +{ + // The color specials are ignored during rendering, and used only in + // the pre-scan phase + if (PostScriptOutPutString == NULL) { + QColor col = parseColorSpecification(cp.stripWhiteSpace()); + + //@@@@ do something with the color! + + return; + } +} + + void dviWindow::html_anchor_special(QString cp) { if (PostScriptOutPutString != NULL) { // only during scanning, not during rendering @@ -445,6 +520,12 @@ void dviWindow::applicationDoSpecial(char *cp) return; } + // color special for background color + if (special_command.find("background", 0, false) == 0) { + background_special(special_command.mid(10)); + return; + } + printErrorMsgForSpecials(i18n("The special command '%1' is not implemented.").arg(special_command)); return; }