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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <trigo.h>
23
24#include <callback_gal.h>
25
26using namespace KIGFX;
27
28
29void CALLBACK_GAL::DrawGlyph( const KIFONT::GLYPH& aGlyph, int aNth, int aTotal )
30{
31 if( aGlyph.IsStroke() )
32 {
33 const KIFONT::STROKE_GLYPH& glyph = static_cast<const KIFONT::STROKE_GLYPH&>( aGlyph );
34
35 for( const std::vector<VECTOR2D>& pointList : glyph )
36 {
37 for( size_t ii = 1; ii < pointList.size(); ii++ )
38 {
39 if( m_stroke )
40 {
41 m_strokeCallback( pointList[ ii - 1 ], pointList[ ii ] );
42 }
43 else
44 {
45 int strokeWidth = GetLineWidth();
46 SHAPE_POLY_SET poly;
47
48 // Use ERROR_INSIDE because it avoids Clipper and is therefore much faster.
49 TransformOvalToPolygon( poly, pointList[ ii - 1 ], pointList[ ii ],
50 strokeWidth, strokeWidth / 180, ERROR_INSIDE );
51
52 m_outlineCallback( poly.Outline( 0 ) );
53 }
54 }
55 }
56 }
57 else if( aGlyph.IsOutline() )
58 {
59 if( m_triangulate )
60 {
61 const KIFONT::OUTLINE_GLYPH& glyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( aGlyph );
62
64 }
65 else
66 {
67 KIFONT::OUTLINE_GLYPH glyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( aGlyph );
68
69 if( glyph.HasHoles() )
70 glyph.Fracture();
71
72 for( int ii = 0; ii < glyph.OutlineCount(); ++ii )
73 m_outlineCallback( glyph.Outline( ii ) );
74 }
75 }
76}
77
78
@ ERROR_INSIDE
std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const VECTOR2I &aPt3)> m_triangleCallback
void DrawGlyph(const KIFONT::GLYPH &aGlyph, int aNth, int aTotal) override
Draw a polygon representing an outline font glyph.
std::function< void(const SHAPE_LINE_CHAIN &aPoly)> m_outlineCallback
std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2)> m_strokeCallback
virtual bool IsStroke() const
Definition glyph.h:47
virtual bool IsOutline() const
Definition glyph.h:46
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.
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 Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
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 eda_group.h:29