summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/kiviosdk/diapathparser.cpp
blob: e071a8e6f209bf9cb581b4ba2a69aa5637e149a4 (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
/* This file is part of the KDE project
   Copyright (C) 2003, The Kivio Developers

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "diapathparser.h"

DiaPointFinder::DiaPointFinder(TQValueList<float> *xlist,  TQValueList<float> *ylist) :
	SVGPathParser(), m_xlist(xlist), m_ylist(ylist)
{
	;
}

void DiaPointFinder::svgMoveTo( double x1, double y1, bool )
{
	m_xlist->append(x1);
	m_ylist->append(y1);
}
void DiaPointFinder::svgLineTo( double x1, double y1, bool )
{
	m_xlist->append(x1);
	m_ylist->append(y1);
}
void DiaPointFinder::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool )
{
	m_xlist->append(x1);
	m_ylist->append(y1);
	m_xlist->append(x2);
	m_ylist->append(y2);
	m_xlist->append(x3);
	m_ylist->append(y3);
}
void DiaPointFinder::svgClosePath()
{

}
DiaPathParser::DiaPathParser(TQDomDocument *doc, TQDomElement *shape, float xscale, float yscale, float lowestx, float lowesty) :
	SVGPathParser(), m_doc(doc), m_shape(shape),
	m_xscale(xscale), m_yscale(yscale),
	m_lowestx(lowestx), m_lowesty(lowesty)
{
	lastX = 0.0;
	lastY = 0.0;
}

void DiaPathParser::svgMoveTo( double x1, double y1, bool )
{
	lastX = x1;
	lastY = y1;
}
void DiaPathParser::svgLineTo( double x1, double y1, bool )
{
	// Line
	float currentX = x1;
	float currentY = y1;

	// Create the line
	TQDomElement kivioPointElement = m_doc->createElement("KivioPoint");
	kivioPointElement.setAttribute("x", TQString::number(diaPointToKivio(lastX,true) * m_xscale));
	kivioPointElement.setAttribute("y", TQString::number(diaPointToKivio(lastY, false) * m_yscale));
	m_shape->appendChild(kivioPointElement);

	kivioPointElement = m_doc->createElement("KivioPoint");
	kivioPointElement.setAttribute("x", TQString::number(diaPointToKivio(currentX,true) * m_xscale));
	kivioPointElement.setAttribute("y", TQString::number(diaPointToKivio(currentY, false) * m_yscale));
	m_shape->appendChild(kivioPointElement);
	lastX = currentX;
	lastY = currentY;
}

void DiaPathParser::svgCurveToCubic( double x1, double y1, double x2, double y2, double x3, double y3, bool )
{
	// Spline
	float lastControlX = x1;
	float lastControlY = y1;
	float currentControlX = x2;
	float currentControlY = y2;
	float currentX = x3;
	float currentY = y3;

	// Create the bezier
	TQDomElement kivioPointElement = m_doc->createElement("KivioPoint");
	kivioPointElement.setAttribute("x",
		TQString::number(diaPointToKivio(lastX,true) * m_xscale));
	kivioPointElement.setAttribute("y",
		TQString::number(diaPointToKivio(lastY, false) * m_yscale));
	kivioPointElement.setAttribute("type", "bezier");
	m_shape->appendChild(kivioPointElement);

	kivioPointElement = m_doc->createElement("KivioPoint");
	kivioPointElement.setAttribute("x",
		TQString::number(diaPointToKivio(lastControlX,true) * m_xscale));
	kivioPointElement.setAttribute("y",
		TQString::number(diaPointToKivio(lastControlY, false) * m_yscale));
	kivioPointElement.setAttribute("type", "bezier");
	m_shape->appendChild(kivioPointElement);

	kivioPointElement = m_doc->createElement("KivioPoint");
	kivioPointElement.setAttribute("x",
			TQString::number(diaPointToKivio(currentControlX,true) * m_xscale));
	kivioPointElement.setAttribute("y",
		TQString::number(diaPointToKivio(currentControlY, false) * m_yscale));
	kivioPointElement.setAttribute("type", "bezier");
	m_shape->appendChild(kivioPointElement);

	kivioPointElement = m_doc->createElement("KivioPoint");
	kivioPointElement.setAttribute("x",
		TQString::number(diaPointToKivio(currentX,true) * m_xscale));
	kivioPointElement.setAttribute("y",
		TQString::number(diaPointToKivio(currentY, false) * m_yscale));
	kivioPointElement.setAttribute("type", "bezier");
	m_shape->appendChild(kivioPointElement);
	lastX = currentX;
	lastY = currentY;
}
void DiaPathParser::svgClosePath()
{

}
float DiaPathParser::diaPointToKivio(float point, bool xpoint)
{
	if(xpoint)
		return point - m_lowestx;
	else
		return point - m_lowesty;
}