diff options
Diffstat (limited to 'dviware/dvisvgm/src')
24 files changed, 378 insertions, 184 deletions
diff --git a/dviware/dvisvgm/src/CMapReader.cpp b/dviware/dvisvgm/src/CMapReader.cpp index f873bded0a..6661afbbb1 100644 --- a/dviware/dvisvgm/src/CMapReader.cpp +++ b/dviware/dvisvgm/src/CMapReader.cpp @@ -32,10 +32,6 @@ using namespace std; -CMapReader::CMapReader () : _inCMap(false) { -} - - /** Reads a cmap file and returns the corresponding CMap object. * @param fname[in] name/path of cmap file * @return CMap object representing the read data, or 0 if file could not be read */ @@ -155,37 +151,33 @@ static uint32_t parse_hexentry (InputReader &ir) { } -void CMapReader::op_begincidchar (InputReader &ir) { +void CMapReader::parseCIDChars (InputReader &ir, bool isRange) { if (!_tokens.empty() && _tokens.back().type() == Token::Type::NUMBER) { ir.skipSpace(); int num_entries = static_cast<int>(popToken().numvalue()); while (num_entries > 0 && ir.peek() == '<') { uint32_t first = parse_hexentry(ir); - uint32_t cid; + uint32_t last = first; + if (isRange) + last = parse_hexentry(ir); ir.skipSpace(); + uint32_t cid; if (!ir.parseUInt(cid)) throw CMapReaderException("invalid char entry (decimal value expected)"); - _cmap->addCIDRange(first, first, cid); + _cmap->addCIDRange(first, last, cid); ir.skipSpace(); } } } + +void CMapReader::op_begincidchar (InputReader &ir) { + parseCIDChars(ir, false); +} + + void CMapReader::op_begincidrange (InputReader &ir) { - if (!_tokens.empty() && _tokens.back().type() == Token::Type::NUMBER) { - ir.skipSpace(); - int num_entries = static_cast<int>(popToken().numvalue()); - while (num_entries > 0 && ir.peek() == '<') { - uint32_t first = parse_hexentry(ir); - uint32_t last = parse_hexentry(ir); - uint32_t cid; - ir.skipSpace(); - if (!ir.parseUInt(cid)) - throw CMapReaderException("invalid range entry (decimal value expected)"); - _cmap->addCIDRange(first, last, cid); - ir.skipSpace(); - } - } + parseCIDChars(ir, true); } diff --git a/dviware/dvisvgm/src/CMapReader.hpp b/dviware/dvisvgm/src/CMapReader.hpp index b39ca9874c..3e5b841e0c 100644 --- a/dviware/dvisvgm/src/CMapReader.hpp +++ b/dviware/dvisvgm/src/CMapReader.hpp @@ -50,13 +50,13 @@ class CMapReader { }; public: - CMapReader (); std::unique_ptr<CMap> read (const std::string &fname); std::unique_ptr<CMap> read (std::istream &is, const std::string &name); protected: Token popToken () {Token t=_tokens.back(); _tokens.pop_back(); return t;} void executeOperator (const std::string &op, InputReader &ir); + void parseCIDChars (InputReader &ir, bool isRange); void op_beginbfchar (InputReader &ir); void op_beginbfrange (InputReader &ir); void op_begincidchar (InputReader &ir); @@ -68,11 +68,10 @@ class CMapReader { private: std::unique_ptr<SegmentedCMap> _cmap; ///< pointer to CMap being read std::vector<Token> _tokens; ///< stack of tokens to be processed - bool _inCMap; ///< operator begincmap has been executed + bool _inCMap=false; ///< true if operator begincmap has been executed }; - struct CMapReaderException : public MessageException { explicit CMapReaderException (const std::string &msg) : MessageException(msg) {} }; diff --git a/dviware/dvisvgm/src/DVIToSVGActions.cpp b/dviware/dvisvgm/src/DVIToSVGActions.cpp index 3d53d1bd4d..bb8e4d6f84 100644 --- a/dviware/dvisvgm/src/DVIToSVGActions.cpp +++ b/dviware/dvisvgm/src/DVIToSVGActions.cpp @@ -32,14 +32,6 @@ using namespace std; -DVIToSVGActions::DVIToSVGActions (DVIToSVG &dvisvg, SVGTree &svg) - : _svg(svg), _dvireader(&dvisvg), _bgcolor(Color::TRANSPARENT) -{ - _currentFontNum = -1; - _pageCount = 0; -} - - void DVIToSVGActions::reset() { _usedChars.clear(); _usedFonts.clear(); @@ -93,6 +85,9 @@ string DVIToSVGActions::getBBoxFormatString () const { * @param[in] vertical true if we're in vertical mode * @param[in] font font to be used */ void DVIToSVGActions::setChar (double x, double y, unsigned c, bool vertical, const Font &font) { + if (_outputLocked) + return; + // If we use SVG fonts there is no need to record all font name/char/size combinations // because the SVG font mechanism handles this automatically. It's sufficient to // record font names and chars. The various font sizes can be ignored here. @@ -167,6 +162,9 @@ void DVIToSVGActions::setChar (double x, double y, unsigned c, bool vertical, co * @param[in] height length of the vertical edges * @param[in] width length of the horizontal edges */ void DVIToSVGActions::setRule (double x, double y, double height, double width) { + if (_outputLocked) + return; + // (x,y) is the lower left corner of the rectangle auto rect = util::make_unique<XMLElement>("rect"); rect->addAttribute("x", x); diff --git a/dviware/dvisvgm/src/DVIToSVGActions.hpp b/dviware/dvisvgm/src/DVIToSVGActions.hpp index 88fa6028ee..e9adc63e38 100644 --- a/dviware/dvisvgm/src/DVIToSVGActions.hpp +++ b/dviware/dvisvgm/src/DVIToSVGActions.hpp @@ -42,7 +42,7 @@ class DVIToSVGActions : public DVIActions, public SpecialActions { using BoxMap = std::unordered_map<std::string,BoundingBox>; public: - DVIToSVGActions (DVIToSVG &dvisvg, SVGTree &svg); + DVIToSVGActions (DVIToSVG &dvisvg, SVGTree &svg) : _svg(svg), _dvireader(&dvisvg) {} void reset () override; void setChar (double x, double y, unsigned c, bool vertical, const Font &f) override; void setRule (double x, double y, double height, double width) override; @@ -68,6 +68,9 @@ class DVIToSVGActions : public DVIActions, public SpecialActions { void setX (double x) override {_dvireader->translateToX(x); _svg.setX(x);} void setY (double y) override {_dvireader->translateToY(y); _svg.setY(y);} void finishLine () override {_dvireader->finishLine();} + void lockOutput () override {_outputLocked = true;} + void unlockOutput () override {_outputLocked = false;} + bool outputLocked () const override {return _outputLocked;} const SVGTree& svgTree () const override {return _svg;} BoundingBox& bbox () override {return _bbox;} BoundingBox& bbox (const std::string &name, bool reset=false) override; @@ -83,12 +86,13 @@ class DVIToSVGActions : public DVIActions, public SpecialActions { SVGTree &_svg; BasicDVIReader *_dvireader; BoundingBox _bbox; - int _pageCount; - int _currentFontNum; + int _pageCount=0; + int _currentFontNum=-1; mutable CharMap _usedChars; FontSet _usedFonts; - Color _bgcolor; + Color _bgcolor=Color::TRANSPARENT; BoxMap _boxes; + bool _outputLocked=false; }; diff --git a/dviware/dvisvgm/src/EmSpecialHandler.cpp b/dviware/dvisvgm/src/EmSpecialHandler.cpp index 49fdb11aa1..c93a798fd7 100644 --- a/dviware/dvisvgm/src/EmSpecialHandler.cpp +++ b/dviware/dvisvgm/src/EmSpecialHandler.cpp @@ -31,10 +31,6 @@ using namespace std; -EmSpecialHandler::EmSpecialHandler () : _linewidth(0.4*72/72.27) { -} - - /** Computes the "cut vector" that is used to compute the line shape. * Because each line has a width > 0 the actual shape of the line is a tetragon. * The 4 vertices can be influenced by the cut parameter c that specifies @@ -79,6 +75,8 @@ static DPair cut_vector (char cuttype, const DPair &linedir, double linewidth) { * @param[in] lw line width in PS point units * @param[in] actions object providing the actions that can be performed by the SpecialHandler */ static void create_line (const DPair &p1, const DPair &p2, char c1, char c2, double lw, SpecialActions &actions) { + if (actions.outputLocked()) + return; unique_ptr<XMLElement> node; DPair dir = p2-p1; if (dir.x() == 0 || dir.y() == 0 || (c1 == 'p' && c2 == 'p')) { diff --git a/dviware/dvisvgm/src/EmSpecialHandler.hpp b/dviware/dvisvgm/src/EmSpecialHandler.hpp index 546702c97c..242ef248ef 100644 --- a/dviware/dvisvgm/src/EmSpecialHandler.hpp +++ b/dviware/dvisvgm/src/EmSpecialHandler.hpp @@ -38,7 +38,6 @@ class EmSpecialHandler : public SpecialHandler { }; public: - EmSpecialHandler (); const char* name () const override {return "em";} const char* info () const override {return "line drawing statements of the emTeX special set";} std::vector<const char*> prefixes() const override; @@ -54,9 +53,9 @@ class EmSpecialHandler : public SpecialHandler { private: std::unordered_map<int, DPair> _points; ///< points defined by special em:point - std::vector<Line> _lines; ///< list of lines with undefined end points - double _linewidth; ///< global line width - DPair _pos; ///< current position of "graphic cursor" + std::vector<Line> _lines; ///< list of lines with undefined end points + double _linewidth=0.4*72/72.27; ///< global line width + DPair _pos; ///< current position of "graphic cursor" }; #endif diff --git a/dviware/dvisvgm/src/FileFinder.cpp b/dviware/dvisvgm/src/FileFinder.cpp index 87d22d73c9..dfd60412cb 100644 --- a/dviware/dvisvgm/src/FileFinder.cpp +++ b/dviware/dvisvgm/src/FileFinder.cpp @@ -174,6 +174,10 @@ const char* FileFinder::findFile (const std::string &fname, const char *ftype) c {"pro", kpse_tex_ps_header_format}, {"sfd", kpse_sfd_format}, {"eps", kpse_pict_format}, + {"png", kpse_pict_format}, + {"jpg", kpse_pict_format}, + {"jpeg", kpse_pict_format}, + {"svg", kpse_pict_format}, {"pdf", kpse_tex_format}, }; auto it = types.find(ext); diff --git a/dviware/dvisvgm/src/FilePath.cpp b/dviware/dvisvgm/src/FilePath.cpp index 95fdab8c25..c859d30469 100644 --- a/dviware/dvisvgm/src/FilePath.cpp +++ b/dviware/dvisvgm/src/FilePath.cpp @@ -277,6 +277,11 @@ string FilePath::relative (string reldir, bool with_filename) const { } +string FilePath::relative (const FilePath &filepath, bool with_filename) const { + return relative(filepath.absolute(false), with_filename); +} + + /** Return the absolute or relative path whichever is shorter. * @param[in] reldir absolute path to a directory * @param[in] with_filename if false, the filename is omitted */ @@ -289,4 +294,18 @@ string FilePath::shorterAbsoluteOrRelative (string reldir, bool with_filename) c bool FilePath::exists () const { return empty() ? false : FileSystem::exists(absolute()); -}
\ No newline at end of file +} + + +/** Checks if a given path is absolute or relative. + * @param[in] path path string to check + * @return true if path is absolute */ +bool FilePath::isAbsolute (string path) { + path = util::trim(path); +#ifdef _WIN32 + path = FileSystem::adaptPathSeperators(path); + if (path.length() >= 2 && path[1] == ':' && isalpha(path[0])) + path.erase(0, 2); // remove drive letter and colon +#endif + return !path.empty() && path[0] == '/'; +} diff --git a/dviware/dvisvgm/src/FilePath.hpp b/dviware/dvisvgm/src/FilePath.hpp index abcea4a9dc..32a9be6814 100644 --- a/dviware/dvisvgm/src/FilePath.hpp +++ b/dviware/dvisvgm/src/FilePath.hpp @@ -48,6 +48,7 @@ class FilePath { void set (const std::string &path, bool isfile, const std::string ¤t_dir); std::string absolute (bool with_filename=true) const; std::string relative (std::string reldir="", bool with_filename=true) const; + std::string relative (const FilePath &filepath, bool with_filename=true) const; std::string shorterAbsoluteOrRelative (std::string reldir="", bool with_filename=true) const; std::string basename () const; std::string suffix () const; @@ -58,6 +59,7 @@ class FilePath { const std::string& filename () const {return _fname;} void filename (const std::string &fname) {_fname = fname;} bool exists () const; + static bool isAbsolute (std::string path); protected: void init (std::string path, bool isfile, std::string current_dir); diff --git a/dviware/dvisvgm/src/PSInterpreter.cpp b/dviware/dvisvgm/src/PSInterpreter.cpp index ba368f17ee..aa9cab2107 100644 --- a/dviware/dvisvgm/src/PSInterpreter.cpp +++ b/dviware/dvisvgm/src/PSInterpreter.cpp @@ -286,6 +286,7 @@ void PSInterpreter::callActions (InputReader &in) { {"setlinewidth", { 1, &PSActions::setlinewidth}}, {"setmatrix", { 6, &PSActions::setmatrix}}, {"setmiterlimit", { 1, &PSActions::setmiterlimit}}, + {"setnulldevice", { 1, &PSActions::setnulldevice}}, {"setopacityalpha",{ 1, &PSActions::setopacityalpha}}, {"setshapealpha", { 1, &PSActions::setshapealpha}}, {"setpagedevice", { 0, &PSActions::setpagedevice}}, diff --git a/dviware/dvisvgm/src/PSInterpreter.hpp b/dviware/dvisvgm/src/PSInterpreter.hpp index 7d35261a59..8e75e3c5f1 100644 --- a/dviware/dvisvgm/src/PSInterpreter.hpp +++ b/dviware/dvisvgm/src/PSInterpreter.hpp @@ -71,6 +71,7 @@ struct PSActions { virtual void setlinewidth (std::vector<double> &p) =0; virtual void setmatrix (std::vector<double> &p) =0; virtual void setmiterlimit (std::vector<double> &p) =0; + virtual void setnulldevice (std::vector<double> &p) =0; virtual void setopacityalpha (std::vector<double> &p) =0; virtual void setshapealpha (std::vector<double> &p) =0; virtual void setpagedevice (std::vector<double> &p) =0; diff --git a/dviware/dvisvgm/src/PsSpecialHandler.cpp b/dviware/dvisvgm/src/PsSpecialHandler.cpp index 871a34b4f2..405da48434 100644 --- a/dviware/dvisvgm/src/PsSpecialHandler.cpp +++ b/dviware/dvisvgm/src/PsSpecialHandler.cpp @@ -213,7 +213,8 @@ bool PsSpecialHandler::process (const string &prefix, istream &is, SpecialAction else if (prefix == "psfile=" || prefix == "PSfile=" || prefix == "pdffile=") { if (_actions) { StreamInputReader in(is); - const string fname = in.getQuotedString(in.peek() == '"' ? "\"" : nullptr); + string fname = in.getQuotedString(in.peek() == '"' ? "\"" : nullptr); + fname = FileSystem::adaptPathSeperators(fname); FileType fileType = FileType::EPS; if (prefix == "pdffile") fileType = FileType::PDF; @@ -295,15 +296,6 @@ void PsSpecialHandler::imgfile (FileType filetype, const string &fname, const ma if (fname == "/dev/null") return; - string filepath; - if (const char *path = FileFinder::instance().lookup(fname, false)) - filepath = FileSystem::adaptPathSeperators(path); - if ((filepath.empty() || !FileSystem::exists(filepath)) && FileSystem::exists(fname)) - filepath = fname; - if (filepath.empty()) { - Message::wstream(true) << "file '" << fname << "' not found\n"; - return; - } map<string,string>::const_iterator it; // bounding box of EPS figure in PS point units (lower left and upper right corner) @@ -362,7 +354,7 @@ void PsSpecialHandler::imgfile (FileType filetype, const string &fname, const ma _actions->setY(0); moveToDVIPos(); - auto imgNode = createImageNode(filetype, filepath, pageno, BoundingBox(llx, lly, urx, ury), clipToBbox); + auto imgNode = createImageNode(filetype, fname, pageno, BoundingBox(llx, lly, urx, ury), clipToBbox); if (imgNode) { // has anything been drawn? Matrix matrix(1); if (filetype == FileType::EPS || filetype == FileType::PDF) @@ -391,23 +383,34 @@ void PsSpecialHandler::imgfile (FileType filetype, const string &fname, const ma /** Creates an XML element containing the image data depending on the file type. * @param[in] type file type of the image - * @param[in] pathstr absolute path to image file + * @param[in] fname file name/path of image file * @param[in] pageno number of page to process (PDF only) * @param[in] bbox bounding box of the image * @param[in] clip if true, the image is clipped to its bounding box * @return pointer to the element or nullptr if there's no image data */ -unique_ptr<XMLElement> PsSpecialHandler::createImageNode (FileType type, const string &pathstr, int pageno, BoundingBox bbox, bool clip) { +unique_ptr<XMLElement> PsSpecialHandler::createImageNode (FileType type, const string &fname, int pageno, BoundingBox bbox, bool clip) { unique_ptr<XMLElement> node; - if (type == FileType::BITMAP || type == FileType::SVG) { + string pathstr; + if (const char *path = FileFinder::instance().lookup(fname, false)) + pathstr = FileSystem::adaptPathSeperators(path); + if ((pathstr.empty() || !FileSystem::exists(pathstr)) && FileSystem::exists(fname)) + pathstr = fname; + if (pathstr.empty()) + Message::wstream(true) << "file '" << fname << "' not found\n"; + else if (type == FileType::BITMAP || type == FileType::SVG) { node = util::make_unique<XMLElement>("image"); node->addAttribute("x", 0); node->addAttribute("y", 0); node->addAttribute("width", bbox.width()); node->addAttribute("height", bbox.height()); - // add path to image file relative to SVG file being generated - FilePath imgPath(pathstr); - string svgPathStr = _actions->getSVGFilePath(pageno).absolute(false); - node->addAttribute("xlink:href", imgPath.relative(svgPathStr)); + + // Only reference the image with an absolute path if either an absolute path was given by the user + // or a given plain filename is not present in the current working directory but was found through + // the FileFinder, i.e. it's usually located somewhere in the texmf tree. + string href = pathstr; + if (!FilePath::isAbsolute(fname) && (fname.find('/') != string::npos || FilePath(fname).exists())) + href = FilePath(pathstr).relative(FilePath(_actions->getSVGFilePath(pageno))); + node->addAttribute("xlink:href", href); } else { // PostScript or PDF // clip image to its bounding box if flag 'clip' is given @@ -1228,6 +1231,18 @@ void PsSpecialHandler::executed () { _actions->progress("ps"); } + +/** This method is called by PSInterpreter if the status of the output devices has changed. + * @param[in] p 1 if output device is the nulldevice, 1 otherwise */ +void PsSpecialHandler::setnulldevice (vector<double> &p) { + if (_actions) { + if (p[0] != 0) + _actions->lockOutput(); // prevent further SVG output + else + _actions->unlockOutput(); // enable SVG output again + } +} + //////////////////////////////////////////// void PsSpecialHandler::ClippingStack::pushEmptyPath () { diff --git a/dviware/dvisvgm/src/PsSpecialHandler.hpp b/dviware/dvisvgm/src/PsSpecialHandler.hpp index 27da9c8471..c7a8a97815 100644 --- a/dviware/dvisvgm/src/PsSpecialHandler.hpp +++ b/dviware/dvisvgm/src/PsSpecialHandler.hpp @@ -104,7 +104,7 @@ class PsSpecialHandler : public SpecialHandler, protected PSActions { void executeAndSync (std::istream &is, bool updatePos); void processHeaderFile (const char *fname); void imgfile (FileType type, const std::string &fname, const std::map<std::string,std::string> &attr); - std::unique_ptr<XMLElement> createImageNode (FileType type, const std::string &pathstr, int pageno, BoundingBox bbox, bool clip); + std::unique_ptr<XMLElement> createImageNode (FileType type, const std::string &fname, int pageno, BoundingBox bbox, bool clip); void dviEndPage (unsigned pageno, SpecialActions &actions) override; void clip (Path path, bool evenodd); void processSequentialPatchMesh (int shadingTypeID, ColorSpace cspace, VectorIterator<double> &it); @@ -146,6 +146,7 @@ class PsSpecialHandler : public SpecialHandler, protected PSActions { void setlinewidth (std::vector<double> &p) override {_linewidth = scale(p[0] ? p[0] : 0.5);} void setmatrix (std::vector<double> &p) override; void setmiterlimit (std::vector<double> &p) override {_miterlimit = p[0];} + void setnulldevice (std::vector<double> &p) override; void setopacityalpha (std::vector<double> &p) override {_opacityalpha = p[0];} void setshapealpha (std::vector<double> &p) override {_shapealpha = p[0];} void setpagedevice (std::vector<double> &p) override; diff --git a/dviware/dvisvgm/src/SpecialActions.hpp b/dviware/dvisvgm/src/SpecialActions.hpp index 3a510e9ea3..7e53303792 100644 --- a/dviware/dvisvgm/src/SpecialActions.hpp +++ b/dviware/dvisvgm/src/SpecialActions.hpp @@ -57,6 +57,9 @@ class SpecialActions { virtual std::string getBBoxFormatString () const =0; virtual void progress (const char *id) {} virtual int getDVIStackDepth () const {return 0;} + virtual void lockOutput () {} + virtual void unlockOutput () {} + virtual bool outputLocked () const {return false;} static double PROGRESSBAR_DELAY; ///< progress bar doesn't appear before this time has elapsed (in sec) }; diff --git a/dviware/dvisvgm/src/TpicSpecialHandler.cpp b/dviware/dvisvgm/src/TpicSpecialHandler.cpp index 7bfb7937eb..b97fa439af 100644 --- a/dviware/dvisvgm/src/TpicSpecialHandler.cpp +++ b/dviware/dvisvgm/src/TpicSpecialHandler.cpp @@ -101,7 +101,7 @@ static unique_ptr<XMLElement> create_ellipse_element (double cx, double cy, doub * @param[in] ddist dash/dot distance of line in PS point units (0:solid line, >0:dashed line, <0:dotted line) * @param[in] actions object providing the actions that can be performed by the SpecialHandler */ void TpicSpecialHandler::drawLines (double ddist, SpecialActions &actions) { - if (!_points.empty() && (_penwidth > 0 || _grayLevel >= 0)) { + if (!_points.empty() && (_penwidth > 0 || _grayLevel >= 0) && !actions.outputLocked()) { unique_ptr<XMLElement> elem; if (_points.size() == 1) { const DPair &p = _points.back(); @@ -147,7 +147,7 @@ void TpicSpecialHandler::drawLines (double ddist, SpecialActions &actions) { * @param[in] ddist length of dashes and gaps * @param[in] actions object providing the actions that can be performed by the SpecialHandler */ void TpicSpecialHandler::drawSplines (double ddist, SpecialActions &actions) { - if (!_points.empty() && _penwidth > 0) { + if (!_points.empty() && _penwidth > 0 && !actions.outputLocked()) { const size_t numPoints = _points.size(); if (numPoints < 3) { _grayLevel = -1; @@ -197,7 +197,7 @@ void TpicSpecialHandler::drawSplines (double ddist, SpecialActions &actions) { * @param[in] angle2 ending angle (clockwise) relative to x-axis * @param[in] actions object providing the actions that can be performed by the SpecialHandler */ void TpicSpecialHandler::drawArc (double cx, double cy, double rx, double ry, double angle1, double angle2, SpecialActions &actions) { - if (_penwidth > 0 || _grayLevel >= 0) { + if ((_penwidth > 0 || _grayLevel >= 0) && !actions.outputLocked()) { cx += actions.getX(); cy += actions.getY(); unique_ptr<XMLElement> elem; diff --git a/dviware/dvisvgm/src/XMLNode.hpp b/dviware/dvisvgm/src/XMLNode.hpp index a8def772d8..b4e5ed6f2b 100644 --- a/dviware/dvisvgm/src/XMLNode.hpp +++ b/dviware/dvisvgm/src/XMLNode.hpp @@ -144,14 +144,15 @@ class XMLElement : public XMLNode { XMLNode* lastChild () const {return _lastChild;} std::ostream& write (std::ostream &os) const override; bool empty () const {return !_firstChild;} -// const Children& children () const {return _children;} Attributes& attributes () {return _attributes;} + const Attributes& attributes () const {return _attributes;} XMLNodeIterator begin () {return XMLNodeIterator(_firstChild.get());} XMLNodeIterator end () {return XMLNodeIterator(nullptr);} ConstXMLNodeIterator begin () const {return ConstXMLNodeIterator(_firstChild.get());} ConstXMLNodeIterator end () const {return ConstXMLNodeIterator(nullptr);} const std::string& name () const {return _name;} const XMLElement* toElement () const override {return this;} + const Attribute* getAttribute (const std::string &name) const; static std::unique_ptr<XMLNode> remove (XMLNode *child); static XMLElement* wrap (XMLNode *first, XMLNode *last, const std::string &name); @@ -159,7 +160,6 @@ class XMLElement : public XMLNode { protected: Attribute* getAttribute (const std::string &name); - const Attribute* getAttribute (const std::string &name) const; XMLNode* insertFirst (std::unique_ptr<XMLNode> child); XMLNode* insertLast (std::unique_ptr<XMLNode> child); diff --git a/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp b/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp index 8cb9de5bab..c882e8b4c8 100644 --- a/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp +++ b/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp @@ -27,35 +27,32 @@ /** Moves common attributes of adjacent elements to enclosing groups. */ class AttributeExtractor : public OptimizerModule { - friend class GroupCollapser; - using Attribute = XMLElement::Attribute; + using Attribute = XMLElement::Attribute; - /** Represents a range of adjacent nodes where all elements have a common attribute. */ - struct AttributeRun { - public: - AttributeRun (const Attribute &attr, XMLElement *first); - XMLNode* first () {return _first;} - XMLNode* last () {return _last;} -// XMLNodeIterator begin () {return XMLNodeIterator(_first);} -// XMLNodeIterator end () {return XMLNodeIterator(_last);} - int length () const {return _length;} + /** Represents a range of adjacent nodes where all elements have a common attribute. */ + struct AttributeRun { + public: + AttributeRun (const Attribute &attr, XMLElement *first); + XMLNode* first () {return _first;} + XMLNode* last () {return _last;} + int length () const {return _length;} - private: - int _length; ///< run length excluding non-element nodes - XMLNode *_first, *_last; ///< first and last node in run - }; + private: + int _length; ///< run length excluding non-element nodes + XMLNode *_first, *_last; ///< first and last node in run + }; public: void execute (XMLElement*, XMLElement *context) override {execute(context, true);}; const char* info () const override; + static bool groupable (const XMLElement &elem); + static bool inheritable (const Attribute &attrib); + static bool extractable (const Attribute &attr, XMLElement &element); protected: void execute (XMLElement *context, bool recurse); XMLNode* extractAttribute (XMLElement *elem); bool extracted (const Attribute &attr) const; - static bool groupable (const XMLElement &elem); - static bool inheritable (const Attribute &attrib); - static bool extractable (const Attribute &attr, XMLElement &element); private: std::set<std::string> _extractedAttributes; diff --git a/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp b/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp index 8f8a22d4ba..9b5eb01829 100644 --- a/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp +++ b/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp @@ -30,7 +30,7 @@ class GroupCollapser : public OptimizerModule { const char* info () const override; protected: - bool moveAttributes (XMLElement &source, XMLElement &dest); + static bool moveAttributes (XMLElement &source, XMLElement &dest); static bool collapsible (const XMLElement &elem); static bool unwrappable (const XMLElement &source, const XMLElement &dest); }; diff --git a/dviware/dvisvgm/src/optimizer/Makefile.am b/dviware/dvisvgm/src/optimizer/Makefile.am index fec405662a..1039627843 100644 --- a/dviware/dvisvgm/src/optimizer/Makefile.am +++ b/dviware/dvisvgm/src/optimizer/Makefile.am @@ -7,6 +7,7 @@ liboptimizer_la_SOURCES = \ OptimizerModule.hpp \ RedundantElementRemover.hpp RedundantElementRemover.cpp \ SVGOptimizer.hpp SVGOptimizer.cpp \ + TextSimplifier.hpp TextSimplifier.cpp \ TransformSimplifier.hpp TransformSimplifier.cpp \ WSNodeRemover.hpp WSNodeRemover.cpp diff --git a/dviware/dvisvgm/src/optimizer/Makefile.in b/dviware/dvisvgm/src/optimizer/Makefile.in index 45344c1933..d31d32c12a 100644 --- a/dviware/dvisvgm/src/optimizer/Makefile.in +++ b/dviware/dvisvgm/src/optimizer/Makefile.in @@ -107,7 +107,7 @@ CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) liboptimizer_la_LIBADD = am_liboptimizer_la_OBJECTS = AttributeExtractor.lo GroupCollapser.lo \ - RedundantElementRemover.lo SVGOptimizer.lo \ + RedundantElementRemover.lo SVGOptimizer.lo TextSimplifier.lo \ TransformSimplifier.lo WSNodeRemover.lo liboptimizer_la_OBJECTS = $(am_liboptimizer_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) @@ -132,7 +132,7 @@ am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/AttributeExtractor.Plo \ ./$(DEPDIR)/GroupCollapser.Plo \ ./$(DEPDIR)/RedundantElementRemover.Plo \ - ./$(DEPDIR)/SVGOptimizer.Plo \ + ./$(DEPDIR)/SVGOptimizer.Plo ./$(DEPDIR)/TextSimplifier.Plo \ ./$(DEPDIR)/TransformSimplifier.Plo \ ./$(DEPDIR)/WSNodeRemover.Plo am__mv = mv -f @@ -366,6 +366,7 @@ liboptimizer_la_SOURCES = \ OptimizerModule.hpp \ RedundantElementRemover.hpp RedundantElementRemover.cpp \ SVGOptimizer.hpp SVGOptimizer.cpp \ + TextSimplifier.hpp TextSimplifier.cpp \ TransformSimplifier.hpp TransformSimplifier.cpp \ WSNodeRemover.hpp WSNodeRemover.cpp @@ -428,6 +429,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GroupCollapser.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RedundantElementRemover.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SVGOptimizer.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TextSimplifier.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TransformSimplifier.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/WSNodeRemover.Plo@am__quote@ # am--include-marker @@ -596,6 +598,7 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/GroupCollapser.Plo -rm -f ./$(DEPDIR)/RedundantElementRemover.Plo -rm -f ./$(DEPDIR)/SVGOptimizer.Plo + -rm -f ./$(DEPDIR)/TextSimplifier.Plo -rm -f ./$(DEPDIR)/TransformSimplifier.Plo -rm -f ./$(DEPDIR)/WSNodeRemover.Plo -rm -f Makefile @@ -647,6 +650,7 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/GroupCollapser.Plo -rm -f ./$(DEPDIR)/RedundantElementRemover.Plo -rm -f ./$(DEPDIR)/SVGOptimizer.Plo + -rm -f ./$(DEPDIR)/TextSimplifier.Plo -rm -f ./$(DEPDIR)/TransformSimplifier.Plo -rm -f ./$(DEPDIR)/WSNodeRemover.Plo -rm -f Makefile diff --git a/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp b/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp index 31cfeff6ff..0320f8b565 100644 --- a/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp +++ b/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp @@ -27,6 +27,7 @@ #include "AttributeExtractor.hpp" #include "GroupCollapser.hpp" #include "RedundantElementRemover.hpp" +#include "TextSimplifier.hpp" #include "TransformSimplifier.hpp" #include "WSNodeRemover.hpp" @@ -37,6 +38,7 @@ string SVGOptimizer::MODULE_SEQUENCE; SVGOptimizer::SVGOptimizer (SVGTree *svg) : _svg(svg) { // optimizer modules available to the user; must be listed in default order // _moduleEntries.emplace_back(ModuleEntry("remove-ws", util::make_unique<WSNodeRemover>())); + _moduleEntries.emplace_back(ModuleEntry("simplify-text", util::make_unique<TextSimplifier>())); _moduleEntries.emplace_back(ModuleEntry("group-attributes", util::make_unique<AttributeExtractor>())); _moduleEntries.emplace_back(ModuleEntry("collapse-groups", util::make_unique<GroupCollapser>())); _moduleEntries.emplace_back(ModuleEntry("simplify-transform", util::make_unique<TransformSimplifier>())); diff --git a/dviware/dvisvgm/src/optimizer/TextSimplifier.cpp b/dviware/dvisvgm/src/optimizer/TextSimplifier.cpp new file mode 100644 index 0000000000..23e0e386df --- /dev/null +++ b/dviware/dvisvgm/src/optimizer/TextSimplifier.cpp @@ -0,0 +1,118 @@ +/************************************************************************* +** TextSimplifier.cpp ** +** ** +** This file is part of dvisvgm -- a fast DVI to SVG converter ** +** Copyright (C) 2005-2019 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/>. ** +*************************************************************************/ + +#include <vector> +#include "AttributeExtractor.hpp" +#include "TextSimplifier.hpp" +#include "../XMLNode.hpp" + +using namespace std; + + +const char* TextSimplifier::info () const { + return "merge data of tspans into enclosing text elements"; +} + + +/** Returns all common inheritable attributes of multiple elements. */ +static XMLElement::Attributes common_inheritable_attributes (const vector<XMLElement*> &elements) { + bool intersected=false; + XMLElement::Attributes commonAttribs; + for (const XMLElement *elem : elements) { + if (commonAttribs.empty()) { + if (intersected) + break; + for (const auto attrib : elem->attributes()) { + if (AttributeExtractor::inheritable(attrib)) + commonAttribs.push_back(attrib); + } + } + else { + for (auto it = commonAttribs.begin(); it != commonAttribs.end();) { + auto *attrib = elem->getAttribute(it->name); + if (!attrib || attrib->value != it->value) + it = commonAttribs.erase(it); + else + ++it; + } + } + intersected = true; + } + return commonAttribs; +} + + +/** Returns all tspan elements of a text element if the latter doesn't contain + * any non-whitespace text nodes. Otherwise, the returned vector is empty. + * @param[in] textElement text element to check + * @return the tspan children of the text element */ +static vector<XMLElement*> get_tspans (XMLElement *textElement) { + vector<XMLElement*> tspans; + bool failed=false; + for (XMLNode *child : *textElement) { + if (child->toWSNode() || child->toComment()) + continue; + if (child->toText()) + failed = true; + else if (XMLElement *childElement = child->toElement()) { + if (childElement->name() != "tspan") + failed = true; + else + tspans.push_back(childElement); + } + if (failed) { + tspans.clear(); + break; + } + } + return tspans; +} + + +void TextSimplifier::execute (XMLElement *context) { + if (!context) + return; + if (context->name() == "text") { + vector<XMLElement*> tspans = get_tspans(context); + vector<XMLElement::Attribute> attribs = common_inheritable_attributes(tspans); + if (!tspans.empty() && !attribs.empty()) { + // move all common tspan attributes to the parent text element + for (const XMLElement::Attribute &attr : attribs) + context->addAttribute(attr.name, attr.value); + // remove all common attributes from the tspan elements + for (XMLElement *tspan : tspans) { + for (const XMLElement::Attribute &attr : attribs) + tspan->removeAttribute(attr.name); + // unwrap the tspan if there are no remaining attributes + if (tspan->attributes().empty()) + XMLElement::unwrap(tspan); + } + } + } + else { + XMLNode *node = context->firstChild(); + while (node) { + XMLNode *next = node->next(); // keep safe pointer to next node + if (XMLElement *elem = node->toElement()) + execute(elem); + node = next; + } + } +} diff --git a/dviware/dvisvgm/src/optimizer/TextSimplifier.hpp b/dviware/dvisvgm/src/optimizer/TextSimplifier.hpp new file mode 100644 index 0000000000..86f44e5051 --- /dev/null +++ b/dviware/dvisvgm/src/optimizer/TextSimplifier.hpp @@ -0,0 +1,30 @@ +/************************************************************************* +** TextSimplifier.hpp ** +** ** +** This file is part of dvisvgm -- a fast DVI to SVG converter ** +** Copyright (C) 2005-2019 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/>. ** +*************************************************************************/ + +#pragma once + +#include "OptimizerModule.hpp" + +class TextSimplifier : public OptimizerModule { + public: + void execute (XMLElement *defs, XMLElement *context) override {execute(context);} + static void execute (XMLElement *context); + const char *info () const override; +}; diff --git a/dviware/dvisvgm/src/psdefs.cpp b/dviware/dvisvgm/src/psdefs.cpp index 39c938dac9..d38e2354e0 100644 --- a/dviware/dvisvgm/src/psdefs.cpp +++ b/dviware/dvisvgm/src/psdefs.cpp @@ -22,97 +22,103 @@ const char *PSInterpreter::PSDEFS = "<</Install{matrix setmatrix}/HWResolution[72 72]/PageSize[10000 10000]/Imaging" -"BBox null>>setpagedevice/@dodraw true store/@patcnt 0 store/@SD systemdict def" -"/@UD userdict def true setglobal @SD/:save @SD/save get put @SD/:restore @SD/r" -"estore get put @SD/:gsave @SD/gsave get put @SD/:grestore @SD/grestore get put" -" @SD/:grestoreall @SD/grestoreall get put @SD/:newpath @SD/newpath get put @SD" -"/:stroke @SD/stroke get put @SD/:fill @SD/fill get put @SD/:eofill @SD/eofill " -"get put @SD/:clip @SD/clip get put @SD/:eoclip @SD/eoclip get put @SD/:charpat" -"h @SD/charpath get put @SD/:show @SD/show get put @SD/:stringwidth @SD/stringw" -"idth get put @SD/.setopacityalpha known not{@SD/.setopacityalpha{pop}put}if @S" -"D/.setshapealpha known not{@SD/.setshapealpha{pop}put}if @SD/.setblendmode kno" -"wn not{@SD/.setblendmode{pop}put}if @SD/prseq{-1 1{-1 roll =only( )print}for(\\" -"n)print}put @SD/prcmd{( )exch(\\ndvi.)3{print}repeat prseq}put @SD/cvxall{{cvx" -"}forall}put @SD/defpr{[exch[/copy @SD]cvxall 5 -1 roll dup 6 1 roll[/get/exec]" -"cvxall 6 -1 roll dup 7 1 roll 4 -1 roll dup 5 1 roll dup length string cvs/prc" -"md cvx]cvx def}put @SD/querypos{{currentpoint}stopped{$error/newerror false pu" -"t}{2(querypos)prcmd}ifelse}put @SD/applyscalevals{1 0 dtransform exch dup mul " -"exch dup mul add sqrt 0 1 dtransform exch dup mul exch dup mul add sqrt 1 0 dt" -"ransform dup mul exch dup dup mul 3 -1 roll add dup 0 eq{pop}{sqrt div}ifelse " -"3(applyscalevals)prcmd}put @SD/prpath{{2(moveto)prcmd}{2(lineto)prcmd}{6(curve" -"to)prcmd}{0(closepath)prcmd}pathforall}put @SD/charpath{/@dodraw false store :" -"charpath/@dodraw true store}put @SD/stringwidth{/@dodraw false store :stringwi" -"dth/@dodraw true store}put @SD/show{@dodraw{dup :gsave currentpoint 2{50 mul e" -"xch}repeat :newpath moveto 50 50/scale sysexec true charpath fill :grestore/@d" -"odraw false store :show/@dodraw true store}{:show}ifelse}put @SD/varxyshow{exc" -"h dup type/arraytype eq{<</arr 3 -1 roll/prc 5 -1 roll/chr 1 string/idx 0>>beg" -"in{chr 0 3 -1 roll put :gsave chr show :grestore currentpoint prc moveto/idx i" -"dx 1 add store}forall end}{pop show}ifelse}put @SD/xyshow{{exch arr idx 2 mul " -"get add exch arr idx 2 mul 1 add get add}varxyshow}put @SD/xshow{{exch arr idx" -" get add exch}varxyshow}put @SD/yshow{{arr idx get add}varxyshow}put @SD/awidt" -"hshow{{1 string dup 0 5 index put :gsave show :grestore pop 0 rmoveto 3 index " -"eq{4 index 4 index rmoveto}if 1 index 1 index rmoveto}exch cshow 5{pop}repeat}" -"put @SD/widthshow{0 0 3 -1 roll pstack awidthshow}put @SD/ashow{0 0 0 6 3 roll" -" awidthshow}put @SD/newpath{:newpath 1 1(newpath)prcmd}put @SD/stroke{@dodraw{" -"prcolor 0 1(newpath)prcmd prpath 0(stroke)prcmd :newpath}{:stroke}ifelse}put @" -"SD/fill{@dodraw{prcolor 0 1(newpath)prcmd prpath 0(fill)prcmd :newpath}{:fill}" -"ifelse}put @SD/eofill{@dodraw{prcolor 0 1(newpath)prcmd prpath 0(eofill)prcmd " -":newpath}{:eofill}ifelse}put @SD/clip{:clip 0 1(newpath)prcmd prpath 0(clip)pr" -"cmd}put @SD/eoclip{:eoclip 0 1(newpath)prcmd prpath 0(eoclip)prcmd}put @SD/shf" -"ill{begin currentdict/ShadingType known currentdict/ColorSpace known and curre" -"ntdict/DataSource known and currentdict/Function known not and ShadingType 4 g" -"e and DataSource type/arraytype eq and{<</DeviceGray 1/DeviceRGB 3/DeviceCMYK " -"4/bgknown currentdict/Background known/bbknown currentdict/BBox known>>begin c" -"urrentdict ColorSpace known{ShadingType ColorSpace load bgknown{1 Background a" -"load pop}{0}ifelse bbknown{1 BBox aload pop}{0}ifelse ShadingType 5 eq{Vertice" -"sPerRow}if DataSource aload length 4 add bgknown{ColorSpace load add}if bbknow" -"n{4 add}if ShadingType 5 eq{1 add}if(shfill)prcmd}if end}if end}put/@rect{4 -2" -" roll moveto exch dup 0 rlineto exch 0 exch rlineto neg 0 rlineto closepath}bi" -"nd def/@rectcc{4 -2 roll moveto 2 copy 0 lt exch 0 lt xor{dup 0 exch rlineto e" -"xch 0 rlineto neg 0 exch rlineto}{exch dup 0 rlineto exch 0 exch rlineto neg 0" -" rlineto}ifelse closepath}bind def @SD/rectclip{:newpath dup type/arraytype eq" -"{aload length 4 idiv{@rectcc}repeat}{@rectcc}ifelse clip :newpath}put @SD/rect" -"fill{gsave :newpath dup type/arraytype eq{aload length 4 idiv{@rectcc}repeat}{" -"@rectcc}ifelse fill grestore}put @SD/rectstroke{gsave :newpath dup type/arrayt" -"ype eq{aload length 4 idiv{@rect}repeat}{@rect}ifelse stroke grestore}put fals" -"e setglobal @SD readonly pop/initclip 0 defpr/clippath 0 defpr/sysexec{@SD exc" -"h get exec}def/adddot{dup length 1 add string dup 0 46 put dup 3 -1 roll 1 exc" -"h putinterval}def/setlinewidth{dup/setlinewidth sysexec 1(setlinewidth)prcmd}d" -"ef/setlinecap 1 defpr/setlinejoin 1 defpr/setmiterlimit 1 defpr/setdash{mark 3" -" 1 roll 2 copy/setdash sysexec exch aload length 1 add -1 roll counttomark(set" -"dash)prcmd pop}def/@setpagedevice{pop<<>>/setpagedevice sysexec matrix setmatr" -"ix newpath 0(setpagedevice)prcmd}def/prcolor{currentrgbcolor 3(setrgbcolor)prc" -"md}def/printgstate{@dodraw{matrix currentmatrix aload pop 6(setmatrix)prcmd ap" -"plyscalevals currentlinewidth 1(setlinewidth)prcmd currentlinecap 1(setlinecap" -")prcmd currentlinejoin 1(setlinejoin)prcmd currentmiterlimit 1(setmiterlimit)p" -"rcmd currentrgbcolor 3(setrgbcolor)prcmd currentdash mark 3 1 roll exch aload " -"length 1 add -1 roll counttomark(setdash)prcmd pop}if}def/setgstate{/setgstate" -" sysexec printgstate}def/save{@UD begin/@saveID vmstatus pop pop def end :save" -" @saveID 1(save)prcmd}def/restore{:restore printgstate @UD/@saveID known{@UD b" -"egin @saveID end}{0}ifelse 1(restore)prcmd}def/gsave 0 defpr/grestore{:grestor" -"e printgstate 0(grestore)prcmd}def/grestoreall{:grestoreall setstate 0(grestor" -"eall)prcmd}def/rotate{dup type/arraytype ne @dodraw and{dup 1(rotate)prcmd}if/" -"rotate sysexec applyscalevals}def/scale{dup type/arraytype ne @dodraw and{2 co" -"py 2(scale)prcmd}if/scale sysexec applyscalevals}def/translate{dup type/arrayt" -"ype ne @dodraw and{2 copy 2(translate)prcmd}if/translate sysexec}def/setmatrix" -"{dup/setmatrix sysexec @dodraw{aload pop 6(setmatrix)prcmd applyscalevals}{pop" -"}ifelse}def/initmatrix{matrix setmatrix}def/concat{matrix currentmatrix matrix" -" concatmatrix setmatrix}def/makepattern{gsave<</mx 3 -1 roll>>begin dup/XUID[1" -"000000 @patcnt]put mx/makepattern sysexec dup dup begin PatternType @patcnt BB" -"ox aload pop XStep YStep PaintType mx aload pop 15(makepattern)prcmd :newpath " -"matrix setmatrix PaintProc 0 1(makepattern)prcmd end/@patcnt @patcnt 1 add sto" -"re end grestore}def/setpattern{begin PatternType 1 eq{PaintType 1 eq{XUID aloa" -"d pop exch pop 1}{:gsave[currentcolorspace aload length -1 roll pop]setcolorsp" -"ace/setcolor sysexec XUID aload pop exch pop currentrgbcolor :grestore 4}ifels" -"e(setpattern)prcmd}{/setpattern sysexec}ifelse end}def/setcolor{dup type/dictt" -"ype eq{setpattern}{/setcolor sysexec/currentrgbcolor sysexec setrgbcolor}ifels" -"e}def/setgray 1 defpr/setcmykcolor 4 defpr/sethsbcolor 3 defpr/setrgbcolor 3 d" -"efpr/.setopacityalpha{dup/.setopacityalpha sysexec 1(setopacityalpha)prcmd}def" -"/.setshapealpha{dup/.setshapealpha sysexec 1(setshapealpha)prcmd}def/.setblend" -"mode{dup/.setblendmode sysexec<</Normal 0/Compatible 0/Multiply 1/Screen 2/Ove" -"rlay 3/SoftLight 4/HardLight 5/ColorDodge 6/ColorBurn 7/Darken 8/Lighten 9/Dif" -"ference 10/Exclusion 11/Hue 12/Saturation 13/Color 14/Luminosity 15/Compatible" -"Overprint 16>>exch get 1(setblendmode)prcmd}def/@pdfpagecount{(r)file runpdfbe" -"gin pdfpagecount runpdfend}def/@pdfpagebox{(r)file runpdfbegin dup dup 1 lt ex" -"ch pdfpagecount gt or{pop}{pdfgetpage/MediaBox pget pop aload pop}ifelse runpd" -"fend}def DELAYBIND{.bindnow}if "; +"BBox null>>setpagedevice/@dodraw true store/@nulldev false store/@patcnt 0 sto" +"re/@SD systemdict def/@UD userdict def true setglobal @SD/:save @SD/save get p" +"ut @SD/:restore @SD/restore get put @SD/:gsave @SD/gsave get put @SD/:grestore" +" @SD/grestore get put @SD/:grestoreall @SD/grestoreall get put @SD/:newpath @S" +"D/newpath get put @SD/:stroke @SD/stroke get put @SD/:fill @SD/fill get put @S" +"D/:eofill @SD/eofill get put @SD/:clip @SD/clip get put @SD/:eoclip @SD/eoclip" +" get put @SD/:charpath @SD/charpath get put @SD/:show @SD/show get put @SD/:st" +"ringwidth @SD/stringwidth get put @SD/:nulldevice @SD/nulldevice get put @SD/." +"setopacityalpha known not{@SD/.setopacityalpha{pop}put}if @SD/.setshapealpha k" +"nown not{@SD/.setshapealpha{pop}put}if @SD/.setblendmode known not{@SD/.setble" +"ndmode{pop}put}if @SD/prseq{-1 1{-1 roll =only( )print}for(\\n)print}put @SD/p" +"rcmd{( )exch(\\ndvi.)3{print}repeat prseq}put @SD/cvxall{{cvx}forall}put @SD/d" +"efpr{[exch[/copy @SD]cvxall 5 -1 roll dup 6 1 roll[/get/exec]cvxall 6 -1 roll " +"dup 7 1 roll 4 -1 roll dup 5 1 roll dup length string cvs/prcmd cvx]cvx def}pu" +"t @SD/querypos{{currentpoint}stopped{$error/newerror false put}{2(querypos)prc" +"md}ifelse}put @SD/applyscalevals{1 0 dtransform exch dup mul exch dup mul add " +"sqrt 0 1 dtransform exch dup mul exch dup mul add sqrt 1 0 dtransform dup mul " +"exch dup dup mul 3 -1 roll add dup 0 eq{pop}{sqrt div}ifelse 3(applyscalevals)" +"prcmd}put @SD/prpath{{2(moveto)prcmd}{2(lineto)prcmd}{6(curveto)prcmd}{0(close" +"path)prcmd}pathforall}put @SD/nulldevice{/@nulldev true store :nulldevice 1 1(" +"setnulldevice)prcmd}put @SD/charpath{/@dodraw false store :charpath/@dodraw tr" +"ue store}put @SD/stringwidth{/@dodraw false store :stringwidth/@dodraw true st" +"ore}put @SD/show{@dodraw @nulldev not and{dup :gsave currentpoint 2{50 mul exc" +"h}repeat :newpath moveto 50 50/scale sysexec true charpath fill :grestore/@dod" +"raw false store :show/@dodraw true store}{:show}ifelse}put @SD/varxyshow{exch " +"dup type/arraytype eq{<</arr 3 -1 roll/prc 5 -1 roll/chr 1 string/idx 0>>begin" +"{chr 0 3 -1 roll put :gsave chr show :grestore currentpoint prc moveto/idx idx" +" 1 add store}forall end}{pop show}ifelse}put @SD/xyshow{{exch arr idx 2 mul ge" +"t add exch arr idx 2 mul 1 add get add}varxyshow}put @SD/xshow{{exch arr idx g" +"et add exch}varxyshow}put @SD/yshow{{arr idx get add}varxyshow}put @SD/awidths" +"how{{1 string dup 0 5 index put :gsave show :grestore pop 0 rmoveto 3 index eq" +"{4 index 4 index rmoveto}if 1 index 1 index rmoveto}exch cshow 5{pop}repeat}pu" +"t @SD/widthshow{0 0 3 -1 roll pstack awidthshow}put @SD/ashow{0 0 0 6 3 roll a" +"widthshow}put @SD/newpath{:newpath 1 1(newpath)prcmd}put @SD/stroke{@dodraw @n" +"ulldev not and{prcolor 0 1(newpath)prcmd prpath 0(stroke)prcmd :newpath}{:stro" +"ke}ifelse}put @SD/fill{@dodraw @nulldev not and{prcolor 0 1(newpath)prcmd prpa" +"th 0(fill)prcmd :newpath}{:fill}ifelse}put @SD/eofill{@dodraw @nulldev not and" +"{prcolor 0 1(newpath)prcmd prpath 0(eofill)prcmd :newpath}{:eofill}ifelse}put " +"@SD/clip{:clip @nulldev not{0 1(newpath)prcmd prpath 0(clip)prcmd}if}put @SD/e" +"oclip{:eoclip @nulldev not{0 1(newpath)prcmd prpath 0(eoclip)prcmd}}put @SD/sh" +"fill{begin currentdict/ShadingType known currentdict/ColorSpace known and curr" +"entdict/DataSource known and currentdict/Function known not and ShadingType 4 " +"ge and DataSource type/arraytype eq and{<</DeviceGray 1/DeviceRGB 3/DeviceCMYK" +" 4/bgknown currentdict/Background known/bbknown currentdict/BBox known>>begin " +"currentdict ColorSpace known{ShadingType ColorSpace load bgknown{1 Background " +"aload pop}{0}ifelse bbknown{1 BBox aload pop}{0}ifelse ShadingType 5 eq{Vertic" +"esPerRow}if DataSource aload length 4 add bgknown{ColorSpace load add}if bbkno" +"wn{4 add}if ShadingType 5 eq{1 add}if(shfill)prcmd}if end}if end}put/@rect{4 -" +"2 roll moveto exch dup 0 rlineto exch 0 exch rlineto neg 0 rlineto closepath}b" +"ind def/@rectcc{4 -2 roll moveto 2 copy 0 lt exch 0 lt xor{dup 0 exch rlineto " +"exch 0 rlineto neg 0 exch rlineto}{exch dup 0 rlineto exch 0 exch rlineto neg " +"0 rlineto}ifelse closepath}bind def @SD/rectclip{:newpath dup type/arraytype e" +"q{aload length 4 idiv{@rectcc}repeat}{@rectcc}ifelse clip :newpath}put @SD/rec" +"tfill{gsave :newpath dup type/arraytype eq{aload length 4 idiv{@rectcc}repeat}" +"{@rectcc}ifelse fill grestore}put @SD/rectstroke{gsave :newpath dup type/array" +"type eq{aload length 4 idiv{@rect}repeat}{@rect}ifelse stroke grestore}put fal" +"se setglobal @SD readonly pop/initclip 0 defpr/clippath 0 defpr/sysexec{@SD ex" +"ch get exec}def/adddot{dup length 1 add string dup 0 46 put dup 3 -1 roll 1 ex" +"ch putinterval}def/setlinewidth{dup/setlinewidth sysexec 1(setlinewidth)prcmd}" +"def/setlinecap 1 defpr/setlinejoin 1 defpr/setmiterlimit 1 defpr/setdash{mark " +"3 1 roll 2 copy/setdash sysexec exch aload length 1 add -1 roll counttomark(se" +"tdash)prcmd pop}def/@setpagedevice{pop<<>>/setpagedevice sysexec matrix setmat" +"rix newpath 0(setpagedevice)prcmd}def/@checknulldev{@nulldev{currentpagedevice" +" maxlength 0 ne{/@nulldev false store 0 1(setnulldevice)prcmd}if}if}def/prcolo" +"r{currentrgbcolor 3(setrgbcolor)prcmd}def/printgstate{@dodraw @nulldev not and" +"{matrix currentmatrix aload pop 6(setmatrix)prcmd applyscalevals currentlinewi" +"dth 1(setlinewidth)prcmd currentlinecap 1(setlinecap)prcmd currentlinejoin 1(s" +"etlinejoin)prcmd currentmiterlimit 1(setmiterlimit)prcmd currentrgbcolor 3(set" +"rgbcolor)prcmd currentdash mark 3 1 roll exch aload length 1 add -1 roll count" +"tomark(setdash)prcmd pop}if}def/setgstate{/setgstate sysexec printgstate}def/s" +"ave{@UD begin/@saveID vmstatus pop pop def end :save @saveID 1(save)prcmd}def/" +"restore{:restore @checknulldev printgstate @UD/@saveID known{@UD begin @saveID" +" end}{0}ifelse 1(restore)prcmd}def/gsave 0 defpr/grestore{:grestore @checknull" +"dev printgstate 0(grestore)prcmd}def/grestoreall{:grestoreall @checknulldev se" +"tstate 0(grestoreall)prcmd}def/rotate{dup type/arraytype ne @dodraw and{dup 1(" +"rotate)prcmd}if/rotate sysexec applyscalevals}def/scale{dup type/arraytype ne " +"@dodraw and{2 copy 2(scale)prcmd}if/scale sysexec applyscalevals}def/translate" +"{dup type/arraytype ne @dodraw and{2 copy 2(translate)prcmd}if/translate sysex" +"ec}def/setmatrix{dup/setmatrix sysexec @dodraw{aload pop 6(setmatrix)prcmd app" +"lyscalevals}{pop}ifelse}def/initmatrix{matrix setmatrix}def/concat{matrix curr" +"entmatrix matrix concatmatrix setmatrix}def/makepattern{gsave<</mx 3 -1 roll>>" +"begin dup/XUID[1000000 @patcnt]put mx/makepattern sysexec dup dup begin Patter" +"nType @patcnt BBox aload pop XStep YStep PaintType mx aload pop 15(makepattern" +")prcmd :newpath matrix setmatrix PaintProc 0 1(makepattern)prcmd end/@patcnt @" +"patcnt 1 add store end grestore}def/setpattern{begin PatternType 1 eq{PaintTyp" +"e 1 eq{XUID aload pop exch pop 1}{:gsave[currentcolorspace aload length -1 rol" +"l pop]setcolorspace/setcolor sysexec XUID aload pop exch pop currentrgbcolor :" +"grestore 4}ifelse(setpattern)prcmd}{/setpattern sysexec}ifelse end}def/setcolo" +"r{dup type/dicttype eq{setpattern}{/setcolor sysexec/currentrgbcolor sysexec s" +"etrgbcolor}ifelse}def/setgray 1 defpr/setcmykcolor 4 defpr/sethsbcolor 3 defpr" +"/setrgbcolor 3 defpr/.setopacityalpha{dup/.setopacityalpha sysexec 1(setopacit" +"yalpha)prcmd}def/.setshapealpha{dup/.setshapealpha sysexec 1(setshapealpha)prc" +"md}def/.setblendmode{dup/.setblendmode sysexec<</Normal 0/Compatible 0/Multipl" +"y 1/Screen 2/Overlay 3/SoftLight 4/HardLight 5/ColorDodge 6/ColorBurn 7/Darken" +" 8/Lighten 9/Difference 10/Exclusion 11/Hue 12/Saturation 13/Color 14/Luminosi" +"ty 15/CompatibleOverprint 16>>exch get 1(setblendmode)prcmd}def/@pdfpagecount{" +"(r)file runpdfbegin pdfpagecount runpdfend}def/@pdfpagebox{(r)file runpdfbegin" +" dup dup 1 lt exch pdfpagecount gt or{pop}{pdfgetpage/MediaBox pget pop aload " +"pop}ifelse runpdfend}def DELAYBIND{.bindnow}if "; + |