summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-1.0.12/src/SVGTree.h
blob: aae598ef0b32433691da35b84c3de69c2d1f4ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*************************************************************************
** SVGTree.h                                                            **
**                                                                      **
** This file is part of dvisvgm -- the DVI to SVG converter             **
** Copyright (C) 2005-2012 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 SVGTREE_H
#define SVGTREE_H

#include <map>
#include <set>
#include "Color.h"
#include "GFGlyphTracer.h"
#include "Matrix.h"
#include "XMLDocument.h"
#include "XMLNode.h"

class  BoundingBox;
class  Color;
struct Font;
class  Matrix;
class  PhysicalFont;

class SVGTree
{
	template <typename T>
	class Property {
		public:
			Property (const T &v) : _value(v), _changed(false) {}

			void set (const T &v) {
				if (v != _value) {
					_value = v;
					_changed = true;
				}
			}

			const T& get () const {return _value;}
			operator const T& ()  {return _value;}
			bool changed () const {return _changed;}
			void changed (bool c) {_changed = c;}

		private:
			T _value;
			bool _changed;
	};

   public:
      SVGTree ();
		void reset ();
		void write (std::ostream &os) const    {_doc.write(os);}
		void newPage (int pageno);
		void appendToDefs (XMLNode *node);
		void appendToPage (XMLNode *node) {_page->append(node);}
		void prependToPage (XMLNode *node){_page->prepend(node);}
		void appendToDoc (XMLNode *node)  {_doc.append(node);}
		void appendToRoot (XMLNode *node) {_root->append(node);}
		void appendChar (int c, double x, double y, const Font &font);
		void appendFontStyles (const std::set<const Font*> &fonts);
      void append (const PhysicalFont &font, const std::set<int> &chars, GFGlyphTracer::Callback *cb=0);
		void setBBox (const BoundingBox &bbox);
		void setFont (int id, const Font *font);
		void setX (double x) {_xchanged = true;}
		void setY (double y) {_ychanged = true;}
		void setMatrix (const Matrix &m) {_matrix.set(m);}
		void setColor (const Color &c)    {_color.set(c);}
		void transformPage (const Matrix *m);
		const Color& getColor () const    {return _color.get();}
		const Matrix& getMatrix () const {return _matrix.get();}
		XMLElementNode* rootNode () const {return _root;}

   public:
      static bool USE_FONTS;    ///< if true, create font references and don't draw paths directly
      static bool CREATE_STYLE; ///< should <style>...</style> and class attributes be used to reference fonts?
      static bool CREATE_USE_ELEMENTS; ///< allow generation of <use/> elements?

	protected:
		void newTextNode (double x, double y);

   private:
		XMLDocument _doc;
		XMLElementNode *_root, *_page, *_text, *_span, *_defs;
		bool _xchanged, _ychanged;
		Property<const Font*> _font;
		Property<Color> _color;
		Property<Matrix> _matrix;
		int _fontnum;
};

#endif