summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGCharTspanTextHandler.cpp
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2016-07-04 22:07:54 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2016-07-04 22:07:54 +0000
commitab399d16f49b986d1de514b2fb8434872decf91d (patch)
tree6d3d0faca673d7aa1c0f48ca679ce7841a82e3df /Build/source/texk/dvisvgm/dvisvgm-src/src/SVGCharTspanTextHandler.cpp
parentdd2749b37f7b6a9976869e29a028eeab80d686df (diff)
dvisvgm 1.16
git-svn-id: svn://tug.org/texlive/trunk@41628 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/SVGCharTspanTextHandler.cpp')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/SVGCharTspanTextHandler.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGCharTspanTextHandler.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGCharTspanTextHandler.cpp
new file mode 100644
index 00000000000..0153bacd05d
--- /dev/null
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SVGCharTspanTextHandler.cpp
@@ -0,0 +1,88 @@
+/*************************************************************************
+** SVGCharTspanTextHandler.cpp **
+** **
+** 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/>. **
+*************************************************************************/
+
+#include "SVGCharTspanTextHandler.h"
+#include "XMLNode.h"
+
+using namespace std;
+
+SVGCharTspanTextHandler::SVGCharTspanTextHandler (bool selectFontByClass)
+ : SVGCharTextHandler(selectFontByClass)
+{
+ resetContextNode();
+}
+
+
+void SVGCharTspanTextHandler::appendChar (UInt32 c, double x, double y) {
+ // changes of fonts and transformations require a new text element
+ if (!_textNode || _font.changed() || _matrix.changed() || _vertical.changed()) {
+ resetContextNode();
+ _textNode = createTextNode(x, y);
+ pushContextNode(_textNode);
+ _color.changed(true); // force creating tspan with color attribute if current color differs from font color
+ }
+ if (_tspanNode && (_xchanged || _ychanged || _color.changed())) {
+ // if drawing position or color was explicitly changed, finish current tspan element
+ popContextNode();
+ _tspanNode = 0;
+ }
+ // Apply text color changes only if the color of the entire font is black.
+ // Glyphs of non-black fonts (e.g. defined in a XeTeX document) can't change their color.
+ bool applyColor = _color.get() != Color::BLACK && _font.get()->color() == Color::BLACK;
+ if (_xchanged || _ychanged || (_color.changed() && applyColor)) {
+ _tspanNode = new XMLElementNode("tspan");
+ pushContextNode(_tspanNode);
+ if (applyColor)
+ _tspanNode->addAttribute("fill", _color.get().svgColorString());
+ _color.changed(false);
+ if (_xchanged) {
+ if (_vertical) {
+ // align glyphs designed for horizontal layout properly
+ if (const PhysicalFont *pf = dynamic_cast<const PhysicalFont*>(_font.get()))
+ if (!pf->getMetrics()->verticalLayout())
+ x += pf->scaledAscent()/2.5; // move vertical baseline to the right by strikethrough offset
+ }
+ _tspanNode->addAttribute("x", x);
+ _xchanged = false;
+ }
+ if (_ychanged) {
+ _tspanNode->addAttribute("y", y);
+ _ychanged = false;
+ }
+ }
+ contextNode()->append(XMLString(_font.get()->unicode(c), false));
+}
+
+
+void SVGCharTspanTextHandler::setInitialContextNode (XMLElementNode *node) {
+ SVGCharHandler::setInitialContextNode(node);
+ _textNode = _tspanNode = 0;
+ _xchanged = _ychanged = false;
+}
+
+
+void SVGCharTspanTextHandler::resetContextNode () {
+ SVGCharHandler::resetContextNode();
+ _textNode = _tspanNode = 0;
+ _xchanged = _ychanged = false;
+ _font.changed(false);
+ _matrix.changed(false);
+ _vertical.changed(false);
+}