summaryrefslogtreecommitdiff
path: root/dviware/dvisvgm/src/optimizer
diff options
context:
space:
mode:
Diffstat (limited to 'dviware/dvisvgm/src/optimizer')
-rw-r--r--dviware/dvisvgm/src/optimizer/AttributeExtractor.cpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/DependencyGraph.hpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/GroupCollapser.cpp22
-rw-r--r--dviware/dvisvgm/src/optimizer/GroupCollapser.hpp12
-rw-r--r--dviware/dvisvgm/src/optimizer/OptimizerModule.hpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/RedundantElementRemover.cpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/RedundantElementRemover.hpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp24
-rw-r--r--dviware/dvisvgm/src/optimizer/SVGOptimizer.hpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/TextSimplifier.cpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/TextSimplifier.hpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/TransformSimplifier.cpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/TransformSimplifier.hpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/WSNodeRemover.cpp2
-rw-r--r--dviware/dvisvgm/src/optimizer/WSNodeRemover.hpp2
16 files changed, 53 insertions, 31 deletions
diff --git a/dviware/dvisvgm/src/optimizer/AttributeExtractor.cpp b/dviware/dvisvgm/src/optimizer/AttributeExtractor.cpp
index e5f3b95536..d36314aae4 100644
--- a/dviware/dvisvgm/src/optimizer/AttributeExtractor.cpp
+++ b/dviware/dvisvgm/src/optimizer/AttributeExtractor.cpp
@@ -2,7 +2,7 @@
** AttributeExtractor.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp b/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp
index c8ab6bd61a..19cd4f0fed 100644
--- a/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp
+++ b/dviware/dvisvgm/src/optimizer/AttributeExtractor.hpp
@@ -2,7 +2,7 @@
** AttributeExtractor.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/DependencyGraph.hpp b/dviware/dvisvgm/src/optimizer/DependencyGraph.hpp
index 912d4a9110..bf1c1cc973 100644
--- a/dviware/dvisvgm/src/optimizer/DependencyGraph.hpp
+++ b/dviware/dvisvgm/src/optimizer/DependencyGraph.hpp
@@ -2,7 +2,7 @@
** DependencyGraph.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/GroupCollapser.cpp b/dviware/dvisvgm/src/optimizer/GroupCollapser.cpp
index c5954d705c..03fc3ac185 100644
--- a/dviware/dvisvgm/src/optimizer/GroupCollapser.cpp
+++ b/dviware/dvisvgm/src/optimizer/GroupCollapser.cpp
@@ -2,7 +2,7 @@
** GroupCollapser.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
@@ -24,10 +24,12 @@
#include <vector>
#include "AttributeExtractor.hpp"
#include "GroupCollapser.hpp"
+#include "TransformSimplifier.hpp"
#include "../XMLNode.hpp"
using namespace std;
+bool GroupCollapser::COMBINE_TRANSFORMS = true;
const char* GroupCollapser::info () const {
return "join nested group elements";
@@ -70,8 +72,9 @@ static void remove_ws_nodes (XMLElement *elem) {
/** Recursively removes all redundant group elements from the given context element
* and moves their attributes to the corresponding parent elements.
- * @param[in] context root of the subtree to process */
-void GroupCollapser::execute (XMLElement *context) {
+ * @param[in] context root of the subtree to process
+ * @param[in] depth depth of tree node being processed (0 = root of local tree) */
+void GroupCollapser::execute (XMLElement *context, int depth) {
if (!context)
return;
@@ -79,7 +82,7 @@ void GroupCollapser::execute (XMLElement *context) {
while (child) {
XMLNode *next=child->next();
if (XMLElement *childElement = child->toElement()) {
- execute(childElement);
+ execute(childElement, depth+1);
// check for groups without attributes and remove them
if (childElement->name() == "g" && childElement->attributes().empty()) {
remove_ws_nodes(childElement);
@@ -97,6 +100,10 @@ void GroupCollapser::execute (XMLElement *context) {
}
}
}
+ if (depth == 0 && COMBINE_TRANSFORMS && _transformCombined) {
+ TransformSimplifier().execute(context);
+ _transformCombined = false;
+ }
}
@@ -110,10 +117,13 @@ bool GroupCollapser::moveAttributes (XMLElement &source, XMLElement &dest) {
for (const auto &attr : source.attributes()) {
if (attr.name == "transform") {
string transform;
- if (const char *destvalue = dest.getAttributeValue("transform"))
+ if (const char *destvalue = dest.getAttributeValue("transform")) {
transform = destvalue+attr.value;
- else
+ _transformCombined = true;
+ }
+ else {
transform = attr.value;
+ }
dest.addAttribute("transform", transform);
movedAttributes.emplace_back("transform");
}
diff --git a/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp b/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp
index 2694c4f355..addf65b4ac 100644
--- a/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp
+++ b/dviware/dvisvgm/src/optimizer/GroupCollapser.hpp
@@ -2,7 +2,7 @@
** GroupCollapser.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
@@ -26,11 +26,17 @@
class GroupCollapser : public OptimizerModule {
public:
void execute (XMLElement*, XMLElement *context) override {execute(context);};
- void execute (XMLElement *context);
+ void execute (XMLElement *context) {execute(context, 0);}
const char* info () const override;
+ static bool COMBINE_TRANSFORMS;
+
protected:
- static bool moveAttributes (XMLElement &source, XMLElement &dest);
+ void execute (XMLElement *context, int depth);
+ bool moveAttributes (XMLElement &source, XMLElement &dest);
static bool collapsible (const XMLElement &elem);
static bool unwrappable (const XMLElement &source, const XMLElement &dest);
+
+ private:
+ bool _transformCombined=false; ///< true if transform attributes have been combined
};
diff --git a/dviware/dvisvgm/src/optimizer/OptimizerModule.hpp b/dviware/dvisvgm/src/optimizer/OptimizerModule.hpp
index 91f0263bb8..94e4c74381 100644
--- a/dviware/dvisvgm/src/optimizer/OptimizerModule.hpp
+++ b/dviware/dvisvgm/src/optimizer/OptimizerModule.hpp
@@ -2,7 +2,7 @@
** OptimizerModule.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/RedundantElementRemover.cpp b/dviware/dvisvgm/src/optimizer/RedundantElementRemover.cpp
index f8d040a329..7d34bbcd11 100644
--- a/dviware/dvisvgm/src/optimizer/RedundantElementRemover.cpp
+++ b/dviware/dvisvgm/src/optimizer/RedundantElementRemover.cpp
@@ -2,7 +2,7 @@
** RedundantElementRemover.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/RedundantElementRemover.hpp b/dviware/dvisvgm/src/optimizer/RedundantElementRemover.hpp
index 52ce905c8e..ce87bf4751 100644
--- a/dviware/dvisvgm/src/optimizer/RedundantElementRemover.hpp
+++ b/dviware/dvisvgm/src/optimizer/RedundantElementRemover.hpp
@@ -2,7 +2,7 @@
** RedundantElementRemover.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp b/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp
index 8f9635a836..9ff1b8163f 100644
--- a/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp
+++ b/dviware/dvisvgm/src/optimizer/SVGOptimizer.cpp
@@ -2,7 +2,7 @@
** SVGOptimizer.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
@@ -51,15 +51,21 @@ void SVGOptimizer::execute () {
return;
if (MODULE_SEQUENCE.empty())
MODULE_SEQUENCE = "remove-clippath"; // default behaviour of previous dvisvgm releases
- if (MODULE_SEQUENCE == "all") {
- for (const auto &entry : _moduleEntries)
- entry.module->execute(_svg->defsNode(), _svg->pageNode());
- }
else {
- vector<string> names = util::split(MODULE_SEQUENCE, ",");
- for (const string &name : names) {
- if (OptimizerModule *module = getModule(name))
- module->execute(_svg->defsNode(), _svg->pageNode());
+ if (MODULE_SEQUENCE == "all") {
+ for (const auto &entry: _moduleEntries)
+ entry.module->execute(_svg->defsNode(), _svg->pageNode());
+ }
+ else {
+ vector<string> names = util::split(MODULE_SEQUENCE, ",");
+ auto it = find_if(names.begin(), names.end(), [](const string &name) {
+ return name == "simplify-transform";
+ });
+ GroupCollapser::COMBINE_TRANSFORMS = (it != names.end());
+ for (const string &name: names) {
+ if (OptimizerModule *module = getModule(name))
+ module->execute(_svg->defsNode(), _svg->pageNode());
+ }
}
}
}
diff --git a/dviware/dvisvgm/src/optimizer/SVGOptimizer.hpp b/dviware/dvisvgm/src/optimizer/SVGOptimizer.hpp
index b15723d9ea..9cd9e64da3 100644
--- a/dviware/dvisvgm/src/optimizer/SVGOptimizer.hpp
+++ b/dviware/dvisvgm/src/optimizer/SVGOptimizer.hpp
@@ -2,7 +2,7 @@
** SVGOptimizer.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/TextSimplifier.cpp b/dviware/dvisvgm/src/optimizer/TextSimplifier.cpp
index 2b778dadbc..b07db7701b 100644
--- a/dviware/dvisvgm/src/optimizer/TextSimplifier.cpp
+++ b/dviware/dvisvgm/src/optimizer/TextSimplifier.cpp
@@ -2,7 +2,7 @@
** TextSimplifier.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/TextSimplifier.hpp b/dviware/dvisvgm/src/optimizer/TextSimplifier.hpp
index 9ad3e0edb0..8908861366 100644
--- a/dviware/dvisvgm/src/optimizer/TextSimplifier.hpp
+++ b/dviware/dvisvgm/src/optimizer/TextSimplifier.hpp
@@ -2,7 +2,7 @@
** TextSimplifier.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/TransformSimplifier.cpp b/dviware/dvisvgm/src/optimizer/TransformSimplifier.cpp
index ce0a6d8d7a..3eca47fc3d 100644
--- a/dviware/dvisvgm/src/optimizer/TransformSimplifier.cpp
+++ b/dviware/dvisvgm/src/optimizer/TransformSimplifier.cpp
@@ -2,7 +2,7 @@
** TransformSimplifier.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/TransformSimplifier.hpp b/dviware/dvisvgm/src/optimizer/TransformSimplifier.hpp
index 10591dc271..023c9655ea 100644
--- a/dviware/dvisvgm/src/optimizer/TransformSimplifier.hpp
+++ b/dviware/dvisvgm/src/optimizer/TransformSimplifier.hpp
@@ -2,7 +2,7 @@
** TransformSimplifier.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/WSNodeRemover.cpp b/dviware/dvisvgm/src/optimizer/WSNodeRemover.cpp
index 09de2f19bb..864c13905b 100644
--- a/dviware/dvisvgm/src/optimizer/WSNodeRemover.cpp
+++ b/dviware/dvisvgm/src/optimizer/WSNodeRemover.cpp
@@ -2,7 +2,7 @@
** WSNodeRemover.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **
diff --git a/dviware/dvisvgm/src/optimizer/WSNodeRemover.hpp b/dviware/dvisvgm/src/optimizer/WSNodeRemover.hpp
index 438c21c8fd..b050b52390 100644
--- a/dviware/dvisvgm/src/optimizer/WSNodeRemover.hpp
+++ b/dviware/dvisvgm/src/optimizer/WSNodeRemover.hpp
@@ -2,7 +2,7 @@
** WSNodeRemover.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2022 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 **