KiCad PCB EDA Suite
Loading...
Searching...
No Matches
callback_gal.cpp
Go to the documentation of this file.
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
24#include <trigo.h>
27
28#include <callback_gal.h>
29
30using namespace KIGFX;
31
32
33void CALLBACK_GAL::DrawGlyph( const KIFONT::GLYPH& aGlyph, int aNth, int aTotal )
34{
35 if( aGlyph.IsStroke() )
36 {
37 const KIFONT::STROKE_GLYPH& glyph = static_cast<const KIFONT::STROKE_GLYPH&>( aGlyph );
38
39 for( const std::vector<VECTOR2D>& pointList : glyph )
40 {
41 for( size_t ii = 1; ii < pointList.size(); ii++ )
42 {
43 if( m_stroke )
44 {
45 m_strokeCallback( pointList[ ii - 1 ], pointList[ ii ] );
46 }
47 else
48 {
49 int strokeWidth = GetLineWidth();
50 SHAPE_POLY_SET poly;
51
52 // Use ERROR_INSIDE because it avoids Clipper and is therefore much faster.
53 TransformOvalToPolygon( poly, pointList[ ii - 1 ], pointList[ ii ],
54 strokeWidth, strokeWidth / 180, ERROR_INSIDE );
55
56 m_outlineCallback( poly.Outline( 0 ) );
57 }
58 }
59 }
60 }
61 else if( aGlyph.IsOutline() )
62 {
63 if( m_triangulate )
64 {
65 const KIFONT::OUTLINE_GLYPH& glyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( aGlyph );
66
68 }
69 else
70 {
71 KIFONT::OUTLINE_GLYPH glyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( aGlyph );
72
73 if( glyph.HasHoles() )
75
76 for( int ii = 0; ii < glyph.OutlineCount(); ++ii )
77 m_outlineCallback( glyph.Outline( ii ) );
78 }
79 }
80}
81
82
@ ERROR_INSIDE
Definition: approximation.h:34
std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const VECTOR2I &aPt3)> m_triangleCallback
Definition: callback_gal.h:83
void DrawGlyph(const KIFONT::GLYPH &aGlyph, int aNth, int aTotal) override
Draw a polygon representing an outline font glyph.
bool m_triangulate
Definition: callback_gal.h:88
std::function< void(const SHAPE_LINE_CHAIN &aPoly)> m_outlineCallback
Definition: callback_gal.h:85
std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2)> m_strokeCallback
Definition: callback_gal.h:79
virtual bool IsStroke() const
Definition: glyph.h:51
virtual bool IsOutline() const
Definition: glyph.h:50
void Triangulate(std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const VECTOR2I &aPt3)> aCallback) const
Definition: glyph.cpp:133
float GetLineWidth() const
Get the line width.
Represent a set of closed polygons.
bool HasHoles() const
Return true if the polygon set has any holes.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
a few functions useful in geometry calculations.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247