29#include <wx/translation.h>
37 if( !aValue.ToCDouble( &value ) )
38 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse number from '%s'" ), aValue ) );
71 const wxString& baselineAlign )
75 if( baselineAlign == wxS(
"" ) || baselineAlign == wxS(
"auto" )
76 || baselineAlign == wxS(
"use-script" ) || baselineAlign == wxS(
"no-change" )
77 || baselineAlign == wxS(
"reset-size" ) || baselineAlign == wxS(
"alphabetic" )
78 || baselineAlign == wxS(
"inherit" ) )
82 else if( baselineAlign == wxS(
"ideographic" ) || baselineAlign == wxS(
"text-after-edge" ) )
86 else if( baselineAlign == wxS(
"central" ) )
90 else if( baselineAlign == wxS(
"middle" ) )
94 else if( baselineAlign == wxS(
"mathematical" ) )
98 else if( baselineAlign == wxS(
"hanging" ) || baselineAlign == wxS(
"text-before-edge" ) )
110std::vector<SHAPE_LINE_CHAIN>
113 std::vector<SHAPE_LINE_CHAIN> result;
119 auto readNumber = [&]( wxString& aOut )
121 wxUniChar ch = data[pos];
123 while( ch ==
' ' || ch ==
',' )
126 while( isdigit( ch ) || ch ==
'.' || ch ==
'-' )
131 if( pos == data.size() )
140 wxUniChar sym = data[pos++];
157 result.emplace_back( chain );
167 else if( sym ==
'Z' )
172 result.emplace_back( chain );
176 else if( sym ==
'L' || isdigit( sym ) || sym ==
'-' )
180 if( isdigit( sym ) || sym ==
'-' )
185 if( pos >= data.size() )
188 wxUniChar ch = data[pos];
190 while( ch ==
' ' || ch ==
',' )
192 if( ++pos >= data.size() )
198 if( !isdigit( ch ) && ch !=
'-' )
212 else if( sym ==
'A' )
214 wxString radX, radY,
unknown, farFlag, cwFlag, endX, endY;
219 readNumber( farFlag );
220 readNumber( cwFlag );
224 bool isFar = farFlag == wxS(
"1" );
225 bool cw = cwFlag == wxS(
"1" );
232 double d =
delta.EuclideanNorm();
233 double h = sqrt( std::max( 0.0, rad.
x * rad.
x - d * d / 4 ) );
240 start +
delta / 2 +
delta.Perpendicular().Resize( ( isFar ^ cw ) ? h : -h );
246 chain.
Append( arc, aArcMinSegLen );
250 else if( sym ==
'C' )
252 wxString p1_xStr, p1_yStr, p2_xStr, p2_yStr, p3_xStr, p3_yStr;
253 readNumber( p1_xStr );
254 readNumber( p1_yStr );
255 readNumber( p2_xStr );
256 readNumber( p2_yStr );
257 readNumber( p3_xStr );
258 readNumber( p3_yStr );
268 std::vector<VECTOR2I> bezierPoints;
269 converter.
GetPoly( bezierPoints, aArcMinSegLen );
271 chain.
Append( bezierPoints );
275 }
while( pos < data.size() );
282 result.emplace_back( chain );
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
std::vector< SHAPE_LINE_CHAIN > ParseLineChains(const wxString &aData, int aArcMinSegLen, bool aForceClosed)
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)
virtual double ScaleSize(double aValue)=0
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
const VECTOR2I & GetTextPos() const
const EDA_ANGLE & GetTextAngle() const
void SetTextPos(const VECTOR2I &aPoint)
VECTOR2I GetTextSize() 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...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
void Clear()
Remove all points from the line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
#define THROW_IO_ERROR(msg)
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.