summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-0.8.7/src/FontGlyph.h
blob: 44a6b65553b5c127af9f128326f1007298c2f26e (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*************************************************************************
** FontGlyph.h                                                          **
**                                                                      **
** This file is part of dvisvgm -- the DVI to SVG converter             **
** Copyright (C) 2005-2009 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 FONTGLYPH_H
#define FONTGLYPH_H

#include <ostream>
#include <list>
#include <vector>
#include "Pair.h"

using std::ostream;
using std::list;
using std::vector;

class GlyphCommand
{
	public:
		GlyphCommand () {}
		GlyphCommand (const LPair &p);
		GlyphCommand (const LPair &p1, const LPair &p2);
		GlyphCommand (const LPair &p1, const LPair &p2, const LPair &p3);
		virtual ~GlyphCommand () {}
		virtual char getSVGPathCommand () const =0;
		virtual GlyphCommand* combine (GlyphCommand &cmd) {return 0;}
		virtual const vector<LPair>& params () const      {return _params;}
		virtual LPair param (int n) const;
		virtual void writeSVGCommand (ostream &os, double sx=1, double sy=1) const;

	protected:
		typedef vector<LPair>::iterator Iterator;
		typedef vector<LPair>::const_iterator ConstIterator;
		vector<LPair> _params;
};


struct GlyphMoveTo : public GlyphCommand
{
	GlyphMoveTo (const LPair &p) : GlyphCommand(p) {}
	char getSVGPathCommand () const {return 'M';}
	GlyphCommand* combine (GlyphCommand &cmd);
};


struct GlyphLineTo : public GlyphCommand
{
	GlyphLineTo (const LPair &p) : GlyphCommand(p) {}
	char getSVGPathCommand () const {return 'L';}
	GlyphCommand* combine (GlyphCommand &cmd);
};


struct GlyphHorizontalLineTo : public GlyphLineTo
{
	GlyphHorizontalLineTo (const LPair &p) : GlyphLineTo(LPair(p.x(), 0)) {}
	char getSVGPathCommand () const {return 'H';}
	void writeSVGCommand (ostream &os, double sx=1, double sy=1) const;
};


struct GlyphVerticalLineTo : public GlyphLineTo
{
	GlyphVerticalLineTo (const LPair &p) : GlyphLineTo(LPair(0, p.y())) {}
	char getSVGPathCommand () const {return 'V';}
	void writeSVGCommand (ostream &os, double sx=1, double sy=1) const;
};


struct GlyphConicTo : public GlyphCommand
{
	GlyphConicTo (const LPair &p1, const LPair &p2) : GlyphCommand(p1, p2) {}
	char getSVGPathCommand () const {return 'Q';}
};


struct GlyphShortConicTo : public GlyphCommand
{
	GlyphShortConicTo (const LPair &p) : GlyphCommand(p) {}
	char getSVGPathCommand () const {return 'T';}
};


struct GlyphCubicTo : public GlyphCommand
{
	GlyphCubicTo (const LPair &p1, const LPair &p2, const LPair &p3) : GlyphCommand(p1, p2, p3) {}
	char getSVGPathCommand () const {return 'C';}
	GlyphCommand* combine (GlyphCommand &cmd);
};


struct GlyphShortCubicTo : public GlyphCommand
{
	GlyphShortCubicTo (const LPair &p1, const LPair &p2) : GlyphCommand(p1, p2) {}
	char getSVGPathCommand () const {return 'S';}
};


struct GlyphClosePath : public GlyphCommand
{
	char getSVGPathCommand () const {return 'Z';}
};


class FontEncoding;
class FontEngine;

class Glyph
{
	typedef list<GlyphCommand*> CommandList;
	typedef CommandList::iterator Iterator;
	typedef CommandList::const_iterator ConstIterator;
	public:
		~Glyph ();
		void addCommand(GlyphCommand *cmd);
		void clear ();
		void closeOpenPaths ();
		void optimizeCommands ();
		void read (unsigned char c, const FontEncoding *encoding, const FontEngine &fontEngine);
		void writeSVGCommands (ostream &os, double sx, double sy) const;
		void forAllCommands (void (*f)(GlyphCommand*, void*), void *userParam=0);
		bool empty () const {return _commands.empty();}
		const CommandList& commands () const {return _commands;}

	private:
		CommandList _commands;
};

#endif