You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <trigo.h>
  24. #include <convert_basic_shapes_to_polygon.h>
  25. #include <geometry/geometry_utils.h>
  26. #include <callback_gal.h>
  27. using namespace KIGFX;
  28. void CALLBACK_GAL::DrawGlyph( const KIFONT::GLYPH& aGlyph, int aNth, int aTotal )
  29. {
  30. if( aGlyph.IsStroke() )
  31. {
  32. const KIFONT::STROKE_GLYPH& glyph = static_cast<const KIFONT::STROKE_GLYPH&>( aGlyph );
  33. for( const std::vector<VECTOR2D>& pointList : glyph )
  34. {
  35. for( size_t ii = 1; ii < pointList.size(); ii++ )
  36. {
  37. if( m_stroke )
  38. {
  39. m_strokeCallback( pointList[ ii - 1 ], pointList[ ii ] );
  40. }
  41. else
  42. {
  43. int strokeWidth = GetLineWidth();
  44. SHAPE_POLY_SET poly;
  45. // Use ERROR_INSIDE because it avoids Clipper and is therefore much faster.
  46. TransformOvalToPolygon( poly, pointList[ ii - 1 ], pointList[ ii ],
  47. strokeWidth, strokeWidth / 180, ERROR_INSIDE );
  48. m_outlineCallback( poly.Outline( 0 ) );
  49. }
  50. }
  51. }
  52. }
  53. else if( aGlyph.IsOutline() )
  54. {
  55. if( m_triangulate )
  56. {
  57. const KIFONT::OUTLINE_GLYPH& glyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( aGlyph );
  58. glyph.Triangulate( m_triangleCallback );
  59. }
  60. else
  61. {
  62. KIFONT::OUTLINE_GLYPH glyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( aGlyph );
  63. if( glyph.HasHoles() )
  64. glyph.Fracture( SHAPE_POLY_SET::POLYGON_MODE::PM_FAST );
  65. for( int ii = 0; ii < glyph.OutlineCount(); ++ii )
  66. m_outlineCallback( glyph.Outline( ii ) );
  67. }
  68. }
  69. }