summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp51
1 files changed, 29 insertions, 22 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp
index fe95443215b..310a6b8c34e 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp
@@ -2,7 +2,7 @@
** PsSpecialHandler.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2017 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2018 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 **
@@ -21,6 +21,7 @@
#ifndef PSSPECIALHANDLER_HPP
#define PSSPECIALHANDLER_HPP
+#include <memory>
#include <set>
#include <stack>
#include <string>
@@ -35,15 +36,17 @@
class PSPattern;
class XMLElementNode;
-class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, protected PSActions
-{
- typedef GraphicsPath<double> Path;
- typedef std::vector<double>::const_iterator DoubleVecIt;
- typedef Color::ColorSpace ColorSpace;
+class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, protected PSActions {
+ using Path = GraphicsPath<double>;
+ using ColorSpace = Color::ColorSpace;
- class ClippingStack
- {
+ /** Helper class storing the clipping paths currently present on the graphics context stack.
+ * Since PS operator 'clippath' only delivers a linearly approximated version of the paths
+ * that are sometimes too imprecise for direct usage in SVG, we keep the possibly curved
+ * clipping paths and compute their intersections locally if necessary. */
+ class ClippingStack {
public:
+ ClippingStack () : _maxID(0) {}
void pushEmptyPath ();
void push (const Path &path, int saveID=-1);
void replace (const Path &path);
@@ -54,18 +57,22 @@ class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, prote
bool clippathLoaded () const;
void setClippathLoaded (bool loaded);
const Path* top () const;
- Path* getPath (size_t id);
int topID () const {return _stack.empty() ? 0 : _stack.top().pathID;}
private:
struct Entry {
- int pathID; ///< index referencing a path of the pool
- int saveID; ///< if >=0, path was pushed by 'save', and saveID holds the ID of the
+ std::shared_ptr<Path> path; // pointer to current clipping path
+ int pathID; ///< ID of current clipping path
+ int saveID; ///< if >=0, path was pushed by 'save', and saveID holds the ID of the PS memory object
bool cpathLoaded; ///< true if clipping path was loaded into current path
- Entry (int pid, int sid) : pathID(pid), saveID(sid), cpathLoaded(false) {}
+ Entry () : Entry(-1) {}
+ Entry (const Path &p, int pid, int sid) : path(std::make_shared<Path>(p)), pathID(pid), saveID(sid), cpathLoaded(false) {}
+ Entry (int sid) : path(nullptr), pathID(0), saveID(sid), cpathLoaded(false) {}
+ Entry (const Entry &entry) =default;
+ Entry (Entry &&entry) =default;
};
- std::vector<Path> _paths; ///< pool of all clipping paths
- std::stack<Entry> _stack;
+ size_t _maxID;
+ std::stack<Entry> _stack; ///< stack holding the clipping information of the current graphics context
};
enum PsSection {PS_NONE, PS_HEADERS, PS_BODY};
@@ -75,7 +82,7 @@ class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, prote
~PsSpecialHandler ();
const char* name () const override {return "ps";}
const char* info () const override {return "dvips PostScript specials";}
- const char** prefixes () const override;
+ const std::vector<const char*> prefixes () const override;
void preprocess (const char *prefix, std::istream &is, SpecialActions &actions) override;
bool process (const char *prefix, std::istream &is, SpecialActions &actions) override;
void setDviScaleFactor (double dvi2bp) override {_previewFilter.setDviScaleFactor(dvi2bp);}
@@ -93,14 +100,14 @@ class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, prote
void moveToDVIPos ();
void executeAndSync (std::istream &is, bool updatePos);
void processHeaderFile (const char *fname);
- void psfile (const std::string &fname, const std::map<std::string,std::string> &attr);
+ void psfile (const std::string &fname, const std::unordered_map<std::string,std::string> &attr);
void dviEndPage (unsigned pageno, SpecialActions &actions) override;
void clip (Path &path, bool evenodd);
void processSequentialPatchMesh (int shadingTypeID, ColorSpace cspace, VectorIterator<double> &it);
void processLatticeTriangularPatchMesh (ColorSpace colorSpace, VectorIterator<double> &it);
/// scale given value by current PS scale factors
- double scale (double v) const {return v*(_sx*_cos*_cos + _sy*(1-_cos*_cos));}
+ double scale (double v) const {return v*(_sx*(1-_cos*_cos) + _sy*_cos*_cos);}
void applyscalevals (std::vector<double> &p) override {_sx = p[0]; _sy = p[1]; _cos = p[2];}
void clip (std::vector<double> &p) override {clip(p, false);}
@@ -131,9 +138,9 @@ class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, prote
void sethsbcolor (std::vector<double> &hsb) override;
void setlinecap (std::vector<double> &p) override {_linecap = uint8_t(p[0]);}
void setlinejoin (std::vector<double> &p) override {_linejoin = uint8_t(p[0]);}
- void setlinewidth (std::vector<double> &p) override {_linewidth = p[0] ? scale(p[0])*1.00375 : 0.5;}
+ 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]*1.00375;}
+ void setmiterlimit (std::vector<double> &p) override {_miterlimit = p[0];}
void setopacityalpha (std::vector<double> &p) override {_opacityalpha = p[0];}
void setpattern (std::vector<double> &p) override;
void setrgbcolor (std::vector<double> &rgb) override;
@@ -155,15 +162,15 @@ class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, prote
Color _currentcolor; ///< current stroke/fill color
double _sx, _sy; ///< horizontal and vertical scale factors retrieved by operator "applyscalevals"
double _cos; ///< cosine of angle between (1,0) and transform(1,0)
- double _linewidth; ///< current linewidth
- double _miterlimit; ///< current miter limit
+ double _linewidth; ///< current line width in bp units
+ double _miterlimit; ///< current miter limit in bp units
double _opacityalpha; ///< opacity level (0=fully transparent, ..., 1=opaque)
uint8_t _linecap : 2; ///< current line cap (0=butt, 1=round, 2=projecting square)
uint8_t _linejoin : 2; ///< current line join (0=miter, 1=round, 2=bevel)
double _dashoffset; ///< current dash offset
std::vector<double> _dashpattern;
ClippingStack _clipStack;
- std::map<int, PSPattern*> _patterns;
+ std::unordered_map<int, std::unique_ptr<PSPattern>> _patterns;
PSTilingPattern *_pattern; ///< current pattern
};