Don't cover STL types.

This commit is contained in:
Jeff Young 2024-02-05 15:30:44 +00:00
parent 7b3485fcb8
commit a28f092b67
6 changed files with 33 additions and 41 deletions

View File

@ -98,7 +98,7 @@ int OUTLINE_DECOMPOSER::cubicTo( const FT_Vector* aFirstControlPoint,
{ {
OUTLINE_DECOMPOSER* decomposer = static_cast<OUTLINE_DECOMPOSER*>( aCallbackData ); OUTLINE_DECOMPOSER* decomposer = static_cast<OUTLINE_DECOMPOSER*>( aCallbackData );
GLYPH_POINTS bezier; std::vector<VECTOR2D> bezier;
bezier.push_back( decomposer->m_lastEndPoint ); bezier.push_back( decomposer->m_lastEndPoint );
bezier.push_back( toVector2D( aFirstControlPoint ) ); bezier.push_back( toVector2D( aFirstControlPoint ) );
@ -110,8 +110,9 @@ int OUTLINE_DECOMPOSER::cubicTo( const FT_Vector* aFirstControlPoint,
bezier.push_back( toVector2D( aEndPoint ) ); bezier.push_back( toVector2D( aEndPoint ) );
GLYPH_POINTS result; std::vector<VECTOR2D> result;
decomposer->approximateBezierCurve( result, bezier ); decomposer->approximateBezierCurve( result, bezier );
for( const VECTOR2D& p : result ) for( const VECTOR2D& p : result )
decomposer->addContourPoint( p ); decomposer->addContourPoint( p );
@ -121,7 +122,7 @@ int OUTLINE_DECOMPOSER::cubicTo( const FT_Vector* aFirstControlPoint,
} }
void OUTLINE_DECOMPOSER::OutlineToSegments( CONTOURS* aContours ) void OUTLINE_DECOMPOSER::OutlineToSegments( std::vector<CONTOUR>* aContours )
{ {
m_contours = aContours; m_contours = aContours;
@ -147,8 +148,8 @@ void OUTLINE_DECOMPOSER::OutlineToSegments( CONTOURS* aContours )
// use converter in kimath // use converter in kimath
bool OUTLINE_DECOMPOSER::approximateQuadraticBezierCurve( GLYPH_POINTS& aResult, bool OUTLINE_DECOMPOSER::approximateQuadraticBezierCurve( std::vector<VECTOR2D>& aResult,
const GLYPH_POINTS& aBezier ) const const std::vector<VECTOR2D>& aBezier ) const
{ {
wxASSERT( aBezier.size() == 3 ); wxASSERT( aBezier.size() == 3 );
@ -160,7 +161,7 @@ bool OUTLINE_DECOMPOSER::approximateQuadraticBezierCurve( GLYPH_POINTS& aR
// qpn = Quadratic Bezier control points (n = 0..2, 3 in total) // qpn = Quadratic Bezier control points (n = 0..2, 3 in total)
// cp0 = qp0, cp1 = qp0 + 2/3 * (qp1 - qp0), cp2 = qp2 + 2/3 * (qp1 - qp2), cp3 = qp2 // cp0 = qp0, cp1 = qp0 + 2/3 * (qp1 - qp0), cp2 = qp2 + 2/3 * (qp1 - qp2), cp3 = qp2
GLYPH_POINTS cubic; std::vector<VECTOR2D> cubic;
cubic.reserve( 4 ); cubic.reserve( 4 );
cubic.push_back( aBezier[0] ); // cp0 cubic.push_back( aBezier[0] ); // cp0
@ -172,12 +173,11 @@ bool OUTLINE_DECOMPOSER::approximateQuadraticBezierCurve( GLYPH_POINTS& aR
} }
bool OUTLINE_DECOMPOSER::approximateCubicBezierCurve( GLYPH_POINTS& aResult, bool OUTLINE_DECOMPOSER::approximateCubicBezierCurve( std::vector<VECTOR2D>& aResult,
const GLYPH_POINTS& aCubicBezier ) const const std::vector<VECTOR2D>& aCubicBezier ) const
{ {
wxASSERT( aCubicBezier.size() == 4 ); wxASSERT( aCubicBezier.size() == 4 );
static int minimumSegmentLength = ADVANCED_CFG::GetCfg().m_MinimumSegmentLength; static int minimumSegmentLength = ADVANCED_CFG::GetCfg().m_MinimumSegmentLength;
BEZIER_POLY converter( aCubicBezier ); BEZIER_POLY converter( aCubicBezier );
converter.GetPoly( aResult, minimumSegmentLength ); converter.GetPoly( aResult, minimumSegmentLength );
@ -186,17 +186,17 @@ bool OUTLINE_DECOMPOSER::approximateCubicBezierCurve( GLYPH_POINTS& aResul
} }
bool OUTLINE_DECOMPOSER::approximateBezierCurve( GLYPH_POINTS& aResult, bool OUTLINE_DECOMPOSER::approximateBezierCurve( std::vector<VECTOR2D>& aResult,
const GLYPH_POINTS& aBezier ) const const std::vector<VECTOR2D>& aBezier ) const
{ {
switch( aBezier.size() ) switch( aBezier.size() )
{ {
case 4: // cubic case 4: // cubic
return approximateCubicBezierCurve( aResult, aBezier ); return approximateCubicBezierCurve( aResult, aBezier );
break;
case 3: // quadratic case 3: // quadratic
return approximateQuadraticBezierCurve( aResult, aBezier ); return approximateQuadraticBezierCurve( aResult, aBezier );
break;
default: default:
// error, only 3 and 4 are acceptable values // error, only 3 and 4 are acceptable values
return false; return false;
@ -204,7 +204,7 @@ bool OUTLINE_DECOMPOSER::approximateBezierCurve( GLYPH_POINTS& aResult,
} }
int OUTLINE_DECOMPOSER::winding( const GLYPH_POINTS& aContour ) const int OUTLINE_DECOMPOSER::winding( const std::vector<VECTOR2D>& aContour ) const
{ {
// -1 == counterclockwise, 1 == clockwise // -1 == counterclockwise, 1 == clockwise

View File

@ -325,7 +325,7 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphsUnlocked( BOX2I* aBBox,
// contours is a collection of all outlines in the glyph; for example the 'o' glyph // contours is a collection of all outlines in the glyph; for example the 'o' glyph
// generally contains 2 contours, one for the glyph outline and one for the hole // generally contains 2 contours, one for the glyph outline and one for the hole
CONTOURS contours; std::vector<CONTOUR> contours;
OUTLINE_DECOMPOSER decomposer( face->glyph->outline ); OUTLINE_DECOMPOSER decomposer( face->glyph->outline );
decomposer.OutlineToSegments( &contours ); decomposer.OutlineToSegments( &contours );
@ -335,8 +335,8 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphsUnlocked( BOX2I* aBBox,
for( CONTOUR& c : contours ) for( CONTOUR& c : contours )
{ {
GLYPH_POINTS points = c.m_Points; std::vector<VECTOR2D> points = c.m_Points;
SHAPE_LINE_CHAIN shape; SHAPE_LINE_CHAIN shape;
shape.ReservePoints( points.size() ); shape.ReservePoints( points.size() );

View File

@ -112,10 +112,6 @@ private:
}; };
typedef std::vector<VECTOR2D> GLYPH_POINTS;
typedef std::vector<GLYPH_POINTS> GLYPH_POINTS_LIST;
typedef std::vector<BOX2D> GLYPH_BOUNDING_BOX_LIST;
} // namespace KIFONT } // namespace KIFONT

View File

@ -41,42 +41,38 @@
namespace KIFONT namespace KIFONT
{ {
typedef std::vector<VECTOR2D> GLYPH_POINTS;
typedef std::vector<GLYPH_POINTS> GLYPH_POINTS_LIST;
typedef std::vector<BOX2D> GLYPH_BOUNDING_BOX_LIST;
struct CONTOUR struct CONTOUR
{ {
GLYPH_POINTS m_Points; std::vector<VECTOR2D> m_Points;
int m_Winding = 0; int m_Winding = 0;
FT_Orientation m_Orientation; FT_Orientation m_Orientation;
}; };
typedef std::vector<CONTOUR> CONTOURS;
class OUTLINE_DECOMPOSER class OUTLINE_DECOMPOSER
{ {
public: public:
OUTLINE_DECOMPOSER( FT_Outline& aOutline ); OUTLINE_DECOMPOSER( FT_Outline& aOutline );
void OutlineToSegments( CONTOURS* aContours ); void OutlineToSegments( std::vector<CONTOUR>* aContours );
private: private:
void newContour(); void newContour();
void addContourPoint( const VECTOR2D& p ); void addContourPoint( const VECTOR2D& p );
bool approximateBezierCurve( GLYPH_POINTS& result, const GLYPH_POINTS& bezier ) const; bool approximateBezierCurve( std::vector<VECTOR2D>& result,
bool approximateQuadraticBezierCurve( GLYPH_POINTS& result, const GLYPH_POINTS& bezier ) const; const std::vector<VECTOR2D>& bezier ) const;
bool approximateCubicBezierCurve( GLYPH_POINTS& result, const GLYPH_POINTS& bezier ) const; bool approximateQuadraticBezierCurve( std::vector<VECTOR2D>& result,
const std::vector<VECTOR2D>& bezier ) const;
bool approximateCubicBezierCurve( std::vector<VECTOR2D>& result,
const std::vector<VECTOR2D>& bezier ) const;
/** /**
* @return 1 if aContour is in clockwise order, -1 if it is in counterclockwise order, * @return 1 if aContour is in clockwise order, -1 if it is in counterclockwise order,
* or 0 if the winding can't be determined. * or 0 if the winding can't be determined.
*/ */
int winding( const GLYPH_POINTS& aContour ) const; int winding( const std::vector<VECTOR2D>& aContour ) const;
inline static unsigned int onCurve( char aTags ) inline static unsigned int onCurve( char aTags )
{ {
@ -115,10 +111,10 @@ private:
const FT_Vector* aEndPoint, void* aCallbackData ); const FT_Vector* aEndPoint, void* aCallbackData );
private: private:
FT_Outline& m_outline; FT_Outline& m_outline;
CONTOURS* m_contours; std::vector<CONTOUR>* m_contours;
VECTOR2D m_lastEndPoint; VECTOR2D m_lastEndPoint;
}; };
} //namespace KIFONT } //namespace KIFONT

View File

@ -138,7 +138,7 @@ private:
// cache for glyphs converted to straight segments // cache for glyphs converted to straight segments
// key is glyph index (FT_GlyphSlot field glyph_index) // key is glyph index (FT_GlyphSlot field glyph_index)
std::map<unsigned int, GLYPH_POINTS_LIST> m_contourCache; std::map<unsigned int, std::vector<std::vector<VECTOR2D>>> m_contourCache;
// The height of the KiCad stroke font is the distance between stroke endpoints for a vertical // The height of the KiCad stroke font is the distance between stroke endpoints for a vertical
// line of cap-height. So the cap-height of the font is actually stroke-width taller than its // line of cap-height. So the cap-height of the font is actually stroke-width taller than its

View File

@ -87,7 +87,7 @@ private:
private: private:
const std::vector<std::shared_ptr<GLYPH>>* m_glyphs; const std::vector<std::shared_ptr<GLYPH>>* m_glyphs;
const GLYPH_BOUNDING_BOX_LIST* m_glyphBoundingBoxes; const std::vector<BOX2D>* m_glyphBoundingBoxes;
double m_maxGlyphWidth; double m_maxGlyphWidth;
}; };