From e7d0318fb2e24e2a30df7978eb1e208ef8cd336f Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 13 Jan 2022 17:04:14 -0800 Subject: [PATCH] Plot fonts in outline mode, not triangulated Putting 1,000s of tiny triangles on a gerber file will cause mfg fits. Instead, we use easy outline plotting for plots and triangulation for everything else. --- common/callback_gal.cpp | 17 +++++++++++++++-- common/plotters/plotter.cpp | 12 +++--------- include/callback_gal.h | 19 ++++++++++++++++++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/common/callback_gal.cpp b/common/callback_gal.cpp index 3d26ce0b56..e567d8df49 100644 --- a/common/callback_gal.cpp +++ b/common/callback_gal.cpp @@ -44,9 +44,22 @@ void CALLBACK_GAL::DrawGlyph( const KIFONT::GLYPH& aGlyph, int aNth, int aTotal } else if( aGlyph.IsOutline() ) { - const KIFONT::OUTLINE_GLYPH& glyph = static_cast( aGlyph ); + if( m_triangulate ) + { + const KIFONT::OUTLINE_GLYPH& glyph = static_cast( aGlyph ); - glyph.Triangulate( m_triangleCallback ); + glyph.Triangulate( m_triangleCallback ); + } + else + { + KIFONT::OUTLINE_GLYPH glyph = static_cast( aGlyph ); + + if( glyph.HasHoles() ) + glyph.Fracture( SHAPE_POLY_SET::POLYGON_MODE::PM_FAST ); + + for( int ii = 0; ii < glyph.OutlineCount(); ++ii ) + m_outlineCallback( glyph.Outline( ii ) ); + } } } diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp index 1062a4b832..9e32debf9c 100644 --- a/common/plotters/plotter.cpp +++ b/common/plotters/plotter.cpp @@ -686,16 +686,10 @@ void PLOTTER::Text( const VECTOR2I& aPos, LineTo( (wxPoint) aPt2 ); PenFinish(); }, - // Triangulation callback - [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 ) + // Polygon callback + [&]( const SHAPE_LINE_CHAIN& aPoly ) { - std::vector cornerList; - cornerList.reserve( 3 ); - - for( const VECTOR2I& pt : { aPt1, aPt2, aPt3, aPt1 } ) - cornerList.emplace_back( pt ); - - PlotPoly( cornerList, FILL_T::FILLED_SHAPE, 0, aData ); + PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, aData ); } ); TEXT_ATTRIBUTES attributes; diff --git a/include/callback_gal.h b/include/callback_gal.h index c1dde731fe..bad24b624b 100644 --- a/include/callback_gal.h +++ b/include/callback_gal.h @@ -26,7 +26,6 @@ #include - class CALLBACK_GAL: public KIGFX::GAL { public: @@ -40,6 +39,20 @@ public: { m_strokeCallback = aStrokeCallback; m_triangleCallback = aTriangleCallback; + m_outlineCallback = [](const SHAPE_LINE_CHAIN&){}; + m_triangulate = true; + } + + CALLBACK_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions, + std::function aStrokeCallback, + std::function aOutlineCallback ) : + GAL( aDisplayOptions ) + { + m_strokeCallback = aStrokeCallback; + m_triangleCallback = []( const VECTOR2I&, const VECTOR2I&, const VECTOR2I& ){}; + m_outlineCallback = aOutlineCallback; + m_triangulate = false; } /** @@ -54,6 +67,10 @@ private: std::function m_triangleCallback; + + std::function m_outlineCallback; + + bool m_triangulate; };