25#include <wx/translation.h>
33 if( !aValue.ToCDouble( &value ) )
34 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse number from '%s'" ), aValue ) );
67 const wxString& baselineAlign )
71 if( baselineAlign == wxS(
"" ) || baselineAlign == wxS(
"auto" )
72 || baselineAlign == wxS(
"use-script" ) || baselineAlign == wxS(
"no-change" )
73 || baselineAlign == wxS(
"reset-size" ) || baselineAlign == wxS(
"alphabetic" )
74 || baselineAlign == wxS(
"inherit" ) )
78 else if( baselineAlign == wxS(
"ideographic" ) || baselineAlign == wxS(
"text-after-edge" ) )
82 else if( baselineAlign == wxS(
"central" ) )
86 else if( baselineAlign == wxS(
"middle" ) )
90 else if( baselineAlign == wxS(
"mathematical" ) )
94 else if( baselineAlign == wxS(
"hanging" ) || baselineAlign == wxS(
"text-before-edge" ) )
106std::vector<SHAPE_LINE_CHAIN>
109 std::vector<SHAPE_LINE_CHAIN>
result;
115 auto readNumber = [&]( wxString& aOut )
117 wxUniChar ch = data[pos];
119 while( ch ==
' ' || ch ==
',' )
122 while( isdigit( ch ) || ch ==
'.' || ch ==
'-' )
127 if( pos == data.size() )
136 wxUniChar sym = data[pos++];
148 if(
chain.PointCount() > 1 )
151 chain.SetClosed(
true );
163 else if( sym ==
'Z' )
165 if(
chain.PointCount() > 2 )
167 chain.SetClosed(
true );
172 else if( sym ==
'L' || isdigit( sym ) || sym ==
'-' )
176 if( isdigit( sym ) || sym ==
'-' )
181 if( pos >= data.size() )
184 wxUniChar ch = data[pos];
186 while( ch ==
' ' || ch ==
',' )
188 if( ++pos >= data.size() )
194 if( !isdigit( ch ) && ch !=
'-' )
208 else if( sym ==
'A' )
213 if( pos >= data.size() )
216 wxUniChar ch = data[pos];
218 while( ch ==
' ' || ch ==
',' )
220 if( ++pos >= data.size() )
226 if( !isdigit( ch ) && ch !=
'-' )
229 wxString radX, radY,
unknown, farFlag, cwFlag, endX, endY;
234 readNumber( farFlag );
235 readNumber( cwFlag );
239 bool isFar = farFlag == wxS(
"1" );
240 bool cw = cwFlag == wxS(
"1" );
247 double d =
delta.EuclideanNorm();
248 double h = sqrt( std::max( 0.0, rad.
x * rad.
x - d * d / 4 ) );
254 VECTOR2D arcCenter = start +
delta / 2 +
delta.Perpendicular().Resize( ( isFar ^
cw ) ? h : -h );
259 chain.Append( arc, aMaxError );
264 else if( sym ==
'C' )
266 wxString p1_xStr, p1_yStr, p2_xStr, p2_yStr, p3_xStr, p3_yStr;
267 readNumber( p1_xStr );
268 readNumber( p1_yStr );
269 readNumber( p2_xStr );
270 readNumber( p2_yStr );
271 readNumber( p3_xStr );
272 readNumber( p3_yStr );
282 std::vector<VECTOR2I> bezierPoints;
283 converter.
GetPoly( bezierPoints, aMaxError );
285 chain.Append( bezierPoints );
289 }
while( pos < data.size() );
291 if(
chain.PointCount() > 1 )
294 chain.SetClosed(
true );
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
static double Convert(const wxString &aValue)
double RelPosX(double aValue)
double RelPosY(double aValue)
VECTOR2< T > RelPos(const VECTOR2< T > &aVec)
void TransformTextToBaseline(EDA_TEXT *textItem, const wxString &baselineAlign)
std::vector< SHAPE_LINE_CHAIN > ParseLineChains(const wxString &aData, int aMaxError, bool aForceClosed)
virtual double ScaleSize(double aValue)=0
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual VECTOR2I GetTextSize() const
virtual VECTOR2I GetTextPos() const
virtual void SetTextPos(const VECTOR2I &aPoint)
virtual EDA_ANGLE GetTextAngle() const
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
const SHAPE_LINE_CHAIN chain
wxString result
Test unit parsing edge cases and error handling.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D