20#include "KPrSVGPathParser.h"
23ObjType KPrSVGPathParser::getType( TQString &d )
27 ObjType objType = OT_UNDEFINED;
29 if ( m_pathType & UNSUPPORTED )
31 objType = OT_UNDEFINED;
33 else if ( m_pathType & SEEN_CLOSE )
35 objType = OT_CLOSED_LINE;
37 else if ( m_pathType & NO_BEZIER )
39 objType = OT_FREEHAND;
41 else if ( ( m_pathType & SEEN_QUADRIC ) && ! ( m_pathType & SEEN_CUBIC ) )
43 objType = OT_QUADRICBEZIERCURVE;
45 else if ( m_pathType & SEEN_CUBIC )
47 objType = OT_CUBICBEZIERCURVE;
53KoPointArray KPrSVGPathParser::getPoints( TQString &d,
bool convert2lines )
57 m_convert2lines = convert2lines;
63void KPrSVGPathParser::svgMoveTo(
double x1,
double y1,
bool )
67 if ( m_pathType != 0 )
69 m_pathType |= UNSUPPORTED;
73 m_pathType |= SEEN_MOVE;
78 m_curPoint = KoPoint( x1, y1 );
83void KPrSVGPathParser::svgLineTo(
double x1,
double y1,
bool )
87 if ( m_pathType & SEEN_MOVE )
89 if ( m_pathType & SEEN_LINE )
91 m_pathType |= NO_BEZIER;
93 m_pathType |= SEEN_LINE;
97 m_pathType |= UNSUPPORTED;
102 m_points.putPoints( m_pointIdx, 2, m_curPoint.x(), m_curPoint.y(), x1, y1 );
103 m_curPoint = KoPoint( x1, y1 );
109void KPrSVGPathParser::svgCurveToCubic(
double x1,
double y1,
double x2,
double y2,
double x,
double y,
bool )
113 if ( m_pathType & SEEN_MOVE )
115 if ( m_pathType & SEEN_LINE )
117 m_pathType |= NO_BEZIER;
120 if ( x1 == x2 && y1 == y2 )
122 m_pathType |= SEEN_QUADRIC;
126 m_pathType |= SEEN_CUBIC;
131 m_pathType |= UNSUPPORTED;
136 if ( m_convert2lines )
138 KoPointArray bezierPoints;
139 bezierPoints.putPoints( 0, 4, m_curPoint.x(), m_curPoint.y(), x1, y1, x2, y2, x, y );
141 bezierPoints = bezierPoints.cubicBezier();
142 KoPointArray::ConstIterator it;
143 for ( it = bezierPoints.begin(); it != bezierPoints.end(); ++it )
145 KoPoint point = (*it);
146 m_points.putPoints( m_pointIdx, 1, point.x(), point.y() );
152 m_points.putPoints( m_pointIdx, 4, m_curPoint.x(), m_curPoint.y(), x, y, x1, y1, x2, y2 );
155 m_curPoint = KoPoint( x, y );
161void KPrSVGPathParser::svgClosePath()
165 if ( m_pathType & SEEN_CLOSE )
167 m_pathType |= UNSUPPORTED;
171 m_pathType |= SEEN_CLOSE;