21#include "KPrBezierCurveObject.h"
22#include "KPrCubicBezierCurveObjectIface.h"
23#include "KPrQuadricBezierCurveObjectIface.h"
25#include <KoTextZoomHandler.h>
29#include "KoPointArray.h"
35KPrBezierCurveObject::KPrBezierCurveObject()
40KPrBezierCurveObject::KPrBezierCurveObject(
const KoPointArray &_controlPoints,
41 const KoPointArray &_allPoints,
42 const KoSize &_size,
const KoPen &_pen,
43 LineEnd _lineBegin, LineEnd _lineEnd )
44: KPrPointObject( _pen, _lineBegin, _lineEnd )
46 points = KoPointArray( _controlPoints );
47 allPoints = KoPointArray( _allPoints );
53KPrBezierCurveObject &KPrBezierCurveObject::operator=(
const KPrBezierCurveObject & )
59bool KPrBezierCurveObject::saveOasisObjectAttributes( KPOasisSaveContext &sc )
const
61 KoRect rect( getRect() );
62 sc.xmlWriter.addAttribute(
"svg:viewBox", TQString(
"0 0 %1 %2" ).arg(
int( rect.width() * 100 ) )
63 .arg(
int( rect.height() * 100 ) ) );
65 unsigned int pointCount = points.count();
69 d += TQString(
"M%1 %2" ).arg(
int( points.at(pos).x() * 100 ) )
70 .arg(
int( points.at(pos).y() * 100 ) );
72 while ( pos + 4 <= pointCount )
74 d += TQString(
"C%1 %2 %3 %4 %5 %6" ).arg(
int( points.at( pos + 2 ).x() * 100 ) )
75 .arg(
int( points.at( pos + 2 ).y() * 100 ) )
76 .arg(
int( points.at( pos + 3 ).x() * 100 ) )
77 .arg(
int( points.at( pos + 3 ).y() * 100 ) )
78 .arg(
int( points.at( pos + 1 ).x() * 100 ) )
79 .arg(
int( points.at( pos + 1 ).y() * 100 ) );
83 if ( pos < pointCount )
85 d += TQString(
"L%1 %2" ).arg(
int( points.at( pos + 1 ).x() * 100 ) )
86 .arg(
int( points.at( pos + 1 ).y() * 100 ) );
89 sc.xmlWriter.addAttribute(
"svg:d", d );
95const char * KPrBezierCurveObject::getOasisElementName()
const
101void KPrBezierCurveObject::loadOasis(
const TQDomElement &element, KoOasisContext & context,
KPrLoadingInfo* info )
103 kdDebug(33001) <<
"KPrBezierCurveObject::loadOasis" << endl;
104 KPrPointObject::loadOasis( element, context, info );
106 allPoints = bezier2polyline( points );
109 loadOasisMarker( context );
112TQDomDocumentFragment KPrBezierCurveObject::save( TQDomDocument& doc,
double offset )
114 return KPrPointObject::save( doc,offset );
117double KPrBezierCurveObject::load(
const TQDomElement &element)
119 double offset = KPrPointObject::load( element );
121 allPoints = bezier2polyline( points );
126void KPrBezierCurveObject::updatePoints(
double _fx,
double _fy )
128 KPrPointObject::updatePoints( _fx, _fy );
131 KoPointArray tmpPoints;
132 KoPointArray::ConstIterator it;
133 for ( it = allPoints.begin(); it != allPoints.end(); ++it ) {
134 KoPoint point = (*it);
135 double tmpX = point.x() * _fx;
136 double tmpY = point.y() * _fy;
138 tmpPoints.putPoints( index, 1, tmpX,tmpY );
141 allPoints = tmpPoints;
144KoPointArray KPrBezierCurveObject::bezier2polyline(
const KoPointArray &bezierPoints )
146 if ( bezierPoints.isNull() )
149 KoPointArray _points( bezierPoints );
150 KoPointArray _allPoints;
151 unsigned int pointCount = _points.count();
153 if ( pointCount == 2 )
155 _allPoints = _points;
159 KoPointArray tmpPointArray;
160 unsigned int _tmpIndex = 0;
161 unsigned int count = 0;
162 while ( count < pointCount )
164 if ( pointCount >= ( count + 4 ) )
166 double _firstX = _points.at( count ).x();
167 double _firstY = _points.at( count ).y();
169 double _fourthX = _points.at( count + 1 ).x();
170 double _fourthY = _points.at( count + 1 ).y();
172 double _secondX = _points.at( count + 2 ).x();
173 double _secondY = _points.at( count + 2 ).y();
175 double _thirdX = _points.at( count + 3 ).x();
176 double _thirdY = _points.at( count + 3 ).y();
178 KoPointArray bezierPoint;
179 bezierPoint.putPoints( 0, 4, _firstX,_firstY, _secondX,_secondY,
180 _thirdX,_thirdY, _fourthX,_fourthY );
181 bezierPoint = bezierPoint.cubicBezier();
183 KoPointArray::ConstIterator it;
184 for ( it = bezierPoint.begin(); it != bezierPoint.end(); ++it )
186 KoPoint _point = (*it);
187 tmpPointArray.putPoints( _tmpIndex, 1, _point.x(), _point.y() );
195 double _x1 = _points.at( count ).x();
196 double _y1 = _points.at( count ).y();
198 double _x2 = _points.at( count + 1 ).x();
199 double _y2 = _points.at( count + 1 ).y();
201 tmpPointArray.putPoints( _tmpIndex, 2, _x1,_y1, _x2,_y2 );
207 _allPoints = tmpPointArray;
213void KPrBezierCurveObject::flip(
bool horizontal )
215 KPrPointObject::flip( horizontal );
217 KoPointArray tmpPoints;
221 KoPointArray::ConstIterator it;
222 double horiz = getSize().height()/2;
223 for ( it = allPoints.begin(); it != allPoints.end(); ++it )
225 KoPoint point = (*it);
226 if ( point.y()> horiz )
227 tmpPoints.putPoints( index, 1, point.x(),point.y()- 2*(point.y()-horiz) );
229 tmpPoints.putPoints( index, 1, point.x(),point.y()+ 2*(horiz - point.y()) );
235 KoPointArray::ConstIterator it;
236 double vert = getSize().width()/2;
237 for ( it = allPoints.begin(); it != allPoints.end(); ++it )
239 KoPoint point = (*it);
240 if ( point.y()> vert )
241 tmpPoints.putPoints( index, 1, point.x()- 2*(point.x()-vert), point.y() );
243 tmpPoints.putPoints( index, 1, point.x()+ 2*(vert - point.x()),point.y() );
248 allPoints = tmpPoints;
252KoPointArray KPrBezierCurveObject::getDrawingPoints()
const
258KPrCubicBezierCurveObject::KPrCubicBezierCurveObject()
259: KPrBezierCurveObject()
264KPrCubicBezierCurveObject::KPrCubicBezierCurveObject(
const KoPointArray &_controlPoints,
265 const KoPointArray &_allPoints,
266 const KoSize & _size,
const KoPen &_pen,
267 LineEnd _lineBegin, LineEnd _lineEnd )
268: KPrBezierCurveObject( _controlPoints, _allPoints, _size, _pen, _lineBegin, _lineEnd )
273DCOPObject* KPrCubicBezierCurveObject::dcopObject()
276 dcop =
new KPrCubicBezierCurveObjectIface(
this );
281KPrQuadricBezierCurveObject::KPrQuadricBezierCurveObject()
282: KPrBezierCurveObject()
287KPrQuadricBezierCurveObject::KPrQuadricBezierCurveObject(
const KoPointArray &_controlPoints,
288 const KoPointArray &_allPoints,
289 const KoSize & _size,
const KoPen &_pen,
290 LineEnd _lineBegin, LineEnd _lineEnd )
291: KPrBezierCurveObject( _controlPoints, _allPoints, _size, _pen, _lineBegin, _lineEnd )
296DCOPObject* KPrQuadricBezierCurveObject::dcopObject()
299 dcop =
new KPrQuadricBezierCurveObjectIface(
this );
Temporary information used only during loading.