diapathparser.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003, The Kivio Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "diapathparser.h"
21
22DiaPointFinder::DiaPointFinder(TQValueList<float> *xlist, TQValueList<float> *ylist) :
23 SVGPathParser(), m_xlist(xlist), m_ylist(ylist)
24{
25 ;
26}
27
28void DiaPointFinder::svgMoveTo( double x1, double y1, bool )
29{
30 m_xlist->append(x1);
31 m_ylist->append(y1);
32}
33void DiaPointFinder::svgLineTo( double x1, double y1, bool )
34{
35 m_xlist->append(x1);
36 m_ylist->append(y1);
37}
38void DiaPointFinder::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool )
39{
40 m_xlist->append(x1);
41 m_ylist->append(y1);
42 m_xlist->append(x2);
43 m_ylist->append(y2);
44 m_xlist->append(x3);
45 m_ylist->append(y3);
46}
47void DiaPointFinder::svgClosePath()
48{
49
50}
51DiaPathParser::DiaPathParser(TQDomDocument *doc, TQDomElement *shape, float xscale, float yscale, float lowestx, float lowesty) :
52 SVGPathParser(), m_doc(doc), m_shape(shape),
53 m_xscale(xscale), m_yscale(yscale),
54 m_lowestx(lowestx), m_lowesty(lowesty)
55{
56 lastX = 0.0;
57 lastY = 0.0;
58}
59
60void DiaPathParser::svgMoveTo( double x1, double y1, bool )
61{
62 lastX = x1;
63 lastY = y1;
64}
65void DiaPathParser::svgLineTo( double x1, double y1, bool )
66{
67 // Line
68 float currentX = x1;
69 float currentY = y1;
70
71 // Create the line
72 TQDomElement kivioPointElement = m_doc->createElement("KivioPoint");
73 kivioPointElement.setAttribute("x", TQString::number(diaPointToKivio(lastX,true) * m_xscale));
74 kivioPointElement.setAttribute("y", TQString::number(diaPointToKivio(lastY, false) * m_yscale));
75 m_shape->appendChild(kivioPointElement);
76
77 kivioPointElement = m_doc->createElement("KivioPoint");
78 kivioPointElement.setAttribute("x", TQString::number(diaPointToKivio(currentX,true) * m_xscale));
79 kivioPointElement.setAttribute("y", TQString::number(diaPointToKivio(currentY, false) * m_yscale));
80 m_shape->appendChild(kivioPointElement);
81 lastX = currentX;
82 lastY = currentY;
83}
84
85void DiaPathParser::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool )
86{
87 // Spline
88 float lastControlX = x1;
89 float lastControlY = y1;
90 float currentControlX = x2;
91 float currentControlY = y2;
92 float currentX = x3;
93 float currentY = y3;
94
95 // Create the bezier
96 TQDomElement kivioPointElement = m_doc->createElement("KivioPoint");
97 kivioPointElement.setAttribute("x",
98 TQString::number(diaPointToKivio(lastX,true) * m_xscale));
99 kivioPointElement.setAttribute("y",
100 TQString::number(diaPointToKivio(lastY, false) * m_yscale));
101 kivioPointElement.setAttribute("type", "bezier");
102 m_shape->appendChild(kivioPointElement);
103
104 kivioPointElement = m_doc->createElement("KivioPoint");
105 kivioPointElement.setAttribute("x",
106 TQString::number(diaPointToKivio(lastControlX,true) * m_xscale));
107 kivioPointElement.setAttribute("y",
108 TQString::number(diaPointToKivio(lastControlY, false) * m_yscale));
109 kivioPointElement.setAttribute("type", "bezier");
110 m_shape->appendChild(kivioPointElement);
111
112 kivioPointElement = m_doc->createElement("KivioPoint");
113 kivioPointElement.setAttribute("x",
114 TQString::number(diaPointToKivio(currentControlX,true) * m_xscale));
115 kivioPointElement.setAttribute("y",
116 TQString::number(diaPointToKivio(currentControlY, false) * m_yscale));
117 kivioPointElement.setAttribute("type", "bezier");
118 m_shape->appendChild(kivioPointElement);
119
120 kivioPointElement = m_doc->createElement("KivioPoint");
121 kivioPointElement.setAttribute("x",
122 TQString::number(diaPointToKivio(currentX,true) * m_xscale));
123 kivioPointElement.setAttribute("y",
124 TQString::number(diaPointToKivio(currentY, false) * m_yscale));
125 kivioPointElement.setAttribute("type", "bezier");
126 m_shape->appendChild(kivioPointElement);
127 lastX = currentX;
128 lastY = currentY;
129}
130void DiaPathParser::svgClosePath()
131{
132
133}
134float DiaPathParser::diaPointToKivio(float point, bool xpoint)
135{
136 if(xpoint)
137 return point - m_lowestx;
138 else
139 return point - m_lowesty;
140}