diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-01-20 15:35:01 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-01-20 15:35:01 +0000 |
commit | 415a631440d99d1c3d7f4f236c03bc34a265052b (patch) | |
tree | 64a29c012f171b8c81487e83879a7fb6cc8e98cf /Build/source/texk/dvisvgm/dvisvgm-src/src | |
parent | 42d0780e54824483b089636e0b88fd3546d1f060 (diff) |
dvisvgm 1.14.2
git-svn-id: svn://tug.org/texlive/trunk@39435 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src')
14 files changed, 147 insertions, 53 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.cpp index 89523695683..f1f19cc7691 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.cpp @@ -19,6 +19,7 @@ *************************************************************************/ #include <config.h> +#include <algorithm> #include "BgColorSpecialHandler.h" #include "ColorSpecialHandler.h" #include "SpecialActions.h" @@ -26,9 +27,46 @@ using namespace std; -bool BgColorSpecialHandler::process (const char *prefix, istream &is, SpecialActions *actions) { - ColorSpecialHandler csh; - return csh.process(prefix, is, actions); +/** Collect all background color changes while preprocessing the DVI file. + * We need them in order to apply the correct background colors even if + * not all but only selected DVI pages are converted. */ +void BgColorSpecialHandler::preprocess (const char*, std::istream &is, SpecialActions *actions) { + Color color = ColorSpecialHandler::readColor(is); + unsigned pageno = actions->getCurrentPageNumber(); + if (_pageColors.empty() || _pageColors.back().second != color) { + if (!_pageColors.empty() && _pageColors.back().first == pageno) + _pageColors.back().second = color; + else + _pageColors.push_back(PageColor(pageno, color)); + } + _actions = actions; +} + + +bool BgColorSpecialHandler::process (const char*, istream&, SpecialActions*) { + return true; +} + + +static bool operator < (const pair<unsigned,Color> &pc1, const pair<unsigned,Color> &pc2) { + // order PageColor objects by page number + return pc1.first < pc2.first; +} + + +void BgColorSpecialHandler::dviBeginPage (unsigned pageno) { + // Ensure that the background color of the preceeding page is set as the + // default background color of the current page because this special affects + // the current and all subsequent pages until the next change. + // See the documentation of the color package, section 3.5. + if (_pageColors.empty()) + return; + // find number of page with bg color change not lower than the current one + vector<PageColor>::iterator it = lower_bound(_pageColors.begin(), _pageColors.end(), PageColor(pageno, Color::BLACK)); + if (it != _pageColors.end() && it->first == pageno) + _actions->setBgColor(it->second); + else if (it != _pageColors.begin()) + _actions->setBgColor((--it)->second); } diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.h b/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.h index 17bd2ab3e7b..772e41541f5 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/BgColorSpecialHandler.h @@ -21,14 +21,26 @@ #ifndef DVISVGM_BGCOLORSPECIALHANDLER_H #define DVISVGM_BGCOLORSPECIALHANDLER_H +#include <vector> +#include "Color.h" #include "SpecialHandler.h" -struct BgColorSpecialHandler : SpecialHandler + +class BgColorSpecialHandler : public SpecialHandler, public DVIBeginPageListener { - const char* info () const {return "background color special";} - const char* name () const {return "bgcolor";} - const char** prefixes () const; - bool process (const char *prefix, std::istream &is, SpecialActions *actions); + public: + BgColorSpecialHandler () : _actions(0) {} + void preprocess (const char *prefix, std::istream &is, SpecialActions *actions); + bool process (const char *prefix, std::istream &is, SpecialActions *actions); + void dviBeginPage (unsigned pageno); + const char* info () const {return "background color special";} + const char* name () const {return "bgcolor";} + const char** prefixes () const; + + private: + typedef std::pair<unsigned,Color> PageColor; // page number and color + SpecialActions *_actions; + std::vector<PageColor> _pageColors; }; #endif diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp index 3b8681de94c..f61de4768ca 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp @@ -19,10 +19,7 @@ *************************************************************************/ #include <config.h> -#include <algorithm> -#include <cmath> #include <cstring> -#include <iomanip> #include <sstream> #include <vector> #include "ColorSpecialHandler.h" @@ -51,18 +48,16 @@ static void read_doubles (istream &is, vector<double> &v) { } -/** Reads a color statement from an input stream and converts it to RGB. +/** Reads a color statement from an input stream and converts it to a color object. * A color statement has the following syntax: * _color model_ _component values_ * Currently, the following color models are supported: rgb, cmyk, hsb and gray. * Examples: rgb 1 0.5 0, gray 0.5 - * @param[in] model if model != "" this value specifies the model, otherwise it's read from the stream + * @param[in] model the color model * @param[in] is stream to be read from - * @param[out] color italicresulting RGB triple - * @return true if statement has successfully been read */ -static void read_color (string model, istream &is, Color &color) { - if (model.empty()) - is >> model; + * @return resulting Color object */ +Color ColorSpecialHandler::readColor (const string &model, istream &is) { + Color color; if (model == "rgb") { vector<double> rgb(3); read_doubles(is, rgb); @@ -82,38 +77,40 @@ static void read_color (string model, istream &is, Color &color) { color.setGray(read_double(is)); else if (!color.setPSName(model, true)) throw SpecialException("unknown color statement"); + return color; } -bool ColorSpecialHandler::process (const char *prefix, istream &is, SpecialActions *actions) { - Color color; - if (prefix && strcmp(prefix, "background") == 0) { - read_color("", is, color); - actions->setBgColor(color); +/** Reads the color model (rgb, cmyk, hsb, or gray) and the corresponding color compontents + * from a given input stream. + * @param[in] is stream to be read from + * @return resulting Color object */ +Color ColorSpecialHandler::readColor (istream &is) { + string model; + is >> model; + return readColor(model, is); +} + + +bool ColorSpecialHandler::process (const char*, istream &is, SpecialActions *actions) { + string cmd; + is >> cmd; + if (cmd == "push") // color push <model> <params> + _colorStack.push(readColor(is)); + else if (cmd == "pop") { + if (!_colorStack.empty()) // color pop + _colorStack.pop(); + } + else { // color <model> <params> + while (!_colorStack.empty()) + _colorStack.pop(); + _colorStack.push(readColor(cmd, is)); } - else { - string cmd; - is >> cmd; - if (cmd == "push") { // color push <model> <params> - read_color("", is, color); - _colorStack.push(color); - } - else if (cmd == "pop") { - if (!_colorStack.empty()) // color pop - _colorStack.pop(); - } - else { // color <model> <params> - read_color(cmd, is, color); - while (!_colorStack.empty()) - _colorStack.pop(); - _colorStack.push(color); - } - if (actions) { - if (_colorStack.empty()) - actions->setColor(Color::BLACK); - else - actions->setColor(_colorStack.top()); - } + if (actions) { + if (_colorStack.empty()) + actions->setColor(Color::BLACK); + else + actions->setColor(_colorStack.top()); } return true; } diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.h b/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.h index 7d401d96b86..d1bbd2e0c95 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.h @@ -22,6 +22,7 @@ #define DVISVGM_COLORSPECIALHANDLER_H #include <stack> +#include <string> #include <vector> #include "Color.h" #include "SpecialHandler.h" @@ -31,6 +32,8 @@ class ColorSpecialHandler : public SpecialHandler { public: bool process (const char *prefix, std::istream &is, SpecialActions *actions); + static Color readColor (std::istream &is); + static Color readColor (const std::string &model, std::istream &is); const char* name () const {return "color";} const char* info () const {return "complete support of color specials";} const char** prefixes () const; diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIReader.h b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIReader.h index d161b1f6ac2..19a5042625a 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIReader.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIReader.h @@ -129,8 +129,9 @@ class DVIReader : public BasicDVIReader, protected VFActions double _dvi2bp; ///< factor to convert dvi units to PS points UInt32 _mag; ///< magnification factor * 1000 bool _inPostamble; ///< true if stream pointer is inside the postamble - double _pageHeight, _pageWidth; ///< page height and width in PS points - DVIState _dviState; ///< current cursor position + double _pageHeight; ///< page height in PS points + double _pageWidth; ///< page width in PS points + DVIState _dviState; ///< registers of the DVI processor std::stack<DVIState> _stateStack; std::vector<UInt32> _bopOffsets; double _prevYPos; ///< previous vertical cursor position diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp index b13af95158f..f93a1a49c81 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp @@ -150,6 +150,7 @@ void DVIToSVG::beginPage (unsigned pageno, Int32 *c) { Message::mstream(false) << " [" << c[0] << ']'; Message::mstream().indent(1); _svg.appendToDoc(new XMLCommentNode(" This file was generated by dvisvgm " VERSION " ")); + SpecialManager::instance().notifyBeginPage(pageno); } } diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontStyle.h b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontStyle.h index 932c09291cc..4594986a2dc 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontStyle.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontStyle.h @@ -1,3 +1,23 @@ +/************************************************************************* +** FontStyle.h ** +** ** +** This file is part of dvisvgm -- a fast DVI to SVG converter ** +** Copyright (C) 2005-2016 Martin Gieseking <martin.gieseking@uos.de> ** +** ** +** This program is free software; you can redistribute it and/or ** +** modify it under the terms of the GNU General Public License as ** +** published by the Free Software Foundation; either version 3 of ** +** the License, or (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, but ** +** WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program; if not, see <http://www.gnu.org/licenses/>. ** +*************************************************************************/ + #ifndef FONTSTYLE #define FONTSTYLE diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/GraphicsPath.h b/Build/source/texk/dvisvgm/dvisvgm-src/src/GraphicsPath.h index d065e250c14..b55efdb35dd 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/GraphicsPath.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/GraphicsPath.h @@ -202,10 +202,12 @@ class GraphicsPath return; Iterator prev = it++; while (it != _commands.end()) { - if (prev->type == Command::MOVETO && it->type == Command::MOVETO) - _commands.erase(prev); - else + if (prev->type != Command::MOVETO || it->type != Command::MOVETO) prev = it++; + else { + prev = _commands.erase(prev); // remove leading MOVETO and advance 'prev' to 'it' + ++it; + } } } diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGTree.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGTree.cpp index 867914b322f..0d8310748ee 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGTree.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGTree.cpp @@ -116,7 +116,7 @@ void SVGTree::appendToPage (XMLNode *node) { _page->append(node); else _pageContainerStack.top()->append(node); - if (node != _text) // if the appended node differ from text element currently in use, + if (node != _text) // if the appended node differs from the text element currently in use, _text = 0; // then force creating a new text element for the following characters } diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialHandler.h b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialHandler.h index 3301af7dc57..94d39835e5a 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialHandler.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialHandler.h @@ -43,6 +43,13 @@ struct DVIPreprocessingListener }; +struct DVIBeginPageListener +{ + virtual ~DVIBeginPageListener () {} + virtual void dviBeginPage (unsigned pageno) =0; +}; + + struct DVIEndPageListener { virtual ~DVIEndPageListener () {} diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.cpp index 5b96c6117aa..6abec223167 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.cpp @@ -65,6 +65,8 @@ void SpecialManager::registerHandler (SpecialHandler *handler) { _handlers[*p] = handler; if (DVIPreprocessingListener *listener = dynamic_cast<DVIPreprocessingListener*>(handler)) _preprocListeners.push_back(listener); + if (DVIBeginPageListener *listener = dynamic_cast<DVIBeginPageListener*>(handler)) + _beginPageListeners.push_back(listener); if (DVIEndPageListener *listener = dynamic_cast<DVIEndPageListener*>(handler)) _endPageListeners.push_back(listener); if (DVIPositionListener *listener = dynamic_cast<DVIPositionListener*>(handler)) @@ -153,6 +155,12 @@ void SpecialManager::notifyPreprocessingFinished () const { } +void SpecialManager::notifyBeginPage (unsigned pageno) const { + FORALL(_beginPageListeners, vector<DVIBeginPageListener*>::const_iterator, it) + (*it)->dviBeginPage(pageno); +} + + void SpecialManager::notifyEndPage (unsigned pageno) const { FORALL(_endPageListeners, vector<DVIEndPageListener*>::const_iterator, it) (*it)->dviEndPage(pageno); diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.h b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.h index 6985671b64e..c8f5d6ad446 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.h +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialManager.h @@ -46,6 +46,7 @@ class SpecialManager void preprocess (const std::string &special, SpecialActions *actions) const; bool process (const std::string &special, double dvi2bp, SpecialActions *actions) const; void notifyPreprocessingFinished () const; + void notifyBeginPage (unsigned pageno) const; void notifyEndPage (unsigned pageno) const; void notifyPositionChange (double x, double y) const; void writeHandlerInfo (std::ostream &os) const; @@ -59,6 +60,7 @@ class SpecialManager HandlerPool _pool; ///< stores pointers to all handlers HandlerMap _handlers; ///< pointers to handlers for corresponding prefixes std::vector<DVIPreprocessingListener*> _preprocListeners; + std::vector<DVIBeginPageListener*> _beginPageListeners; std::vector<DVIEndPageListener*> _endPageListeners; std::vector<DVIPositionListener*> _positionListeners; }; diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/TriangularPatch.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/TriangularPatch.cpp index 43618004362..75bb69a27d6 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/TriangularPatch.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/TriangularPatch.cpp @@ -174,7 +174,7 @@ void TriangularPatch::approximate (int gridsize, bool overlap, double delta, Cal double v2 = snap(v1+inc); double ov2 = (overlap && snap(v2+inc) <= 1 ? snap(v2+inc) : v2); if (!overlap || (snap(u1+ov2) <= 1 && snap(ou2+v1) <= 1)) { - // create triangular segments pointing in the same orientation as the whole patch + // create triangular segments pointing in the same direction as the whole patch GraphicsPath<double> path; path.moveto(valueAt(u1, v1)); path.lineto(valueAt(ou2, v1)); diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp index b445c6c4d3c..073b5bd2045 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp @@ -24,6 +24,7 @@ #include <iostream> #include <sstream> #include <string> +#include <xxhash.h> #include "gzstream.h" #include "CommandLine.h" #include "DVIToSVG.h" @@ -175,6 +176,7 @@ static void print_version (bool extended) { string gsver = gs.revision(true); if (!gsver.empty()) oss << "Ghostscript: " << gsver + "\n"; + const unsigned xxh_ver = XXH_versionNumber(); oss << #ifdef MIKTEX "MiKTeX: " << FileFinder::version() << "\n" @@ -182,6 +184,7 @@ static void print_version (bool extended) { "kpathsea: " << FileFinder::version() << "\n" #endif "potrace: " << (strchr(potrace_version(), ' ') ? strchr(potrace_version(), ' ')+1 : "unknown") << "\n" + "xxhash: " << xxh_ver/10000 << '.' << (xxh_ver/100)%100 << '.' << xxh_ver%100 << "\n" "zlib: " << zlibVersion(); } cout << oss.str() << endl; |