KiCad PCB EDA Suite
Loading...
Searching...
No Matches
glyph.h
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) 2021 Ola Rinta-Koski
5 * Copyright (C) 2021-2024 Kicad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef GLYPH_H
26#define GLYPH_H
27
28#include <gal/gal.h>
29#include <memory>
30#include <math/box2.h>
32#include <geometry/eda_angle.h>
33#include <wx/debug.h>
34
35#if defined( _MSC_VER )
36#pragma warning( push )
37#pragma warning( disable : 4275 )
38#endif
39
40namespace KIFONT
41{
42
43
45{
46public:
47 virtual ~GLYPH()
48 {}
49
50 virtual bool IsOutline() const { return false; }
51 virtual bool IsStroke() const { return false; }
52
53 virtual BOX2D BoundingBox() = 0;
54};
55
56
58{
59public:
62 {}
63
64 OUTLINE_GLYPH( const OUTLINE_GLYPH& aGlyph ) :
65 SHAPE_POLY_SET( aGlyph )
66 {}
67
68 OUTLINE_GLYPH( const SHAPE_POLY_SET& aPoly ) :
69 SHAPE_POLY_SET( aPoly )
70 {}
71
72 bool IsOutline() const override { return true; }
73
74 BOX2D BoundingBox() override;
75
76 void Triangulate( std::function<void( const VECTOR2I& aPt1,
77 const VECTOR2I& aPt2,
78 const VECTOR2I& aPt3 )> aCallback ) const;
79
80 void CacheTriangulation( bool aPartition = true, bool aSimplify = false ) override;
81
86 std::vector<std::unique_ptr<SHAPE_POLY_SET::TRIANGULATED_POLYGON>> GetTriangulationData() const;
87
92 void CacheTriangulation( std::vector<std::unique_ptr<SHAPE_POLY_SET::TRIANGULATED_POLYGON>>& aHintData );
93};
94
95
96class GAL_API STROKE_GLYPH : public GLYPH, public std::vector<std::vector<VECTOR2D>>
97{
98public:
100 {}
101
102 STROKE_GLYPH( const STROKE_GLYPH& aGlyph );
103
104 bool IsStroke() const override { return true; }
105
106 void AddPoint( const VECTOR2D& aPoint );
107 void RaisePen();
108 void Finalize();
109
110 BOX2D BoundingBox() override { return m_boundingBox; }
111 void SetBoundingBox( const BOX2D& bbox ) { m_boundingBox = bbox; }
112
113 std::unique_ptr<GLYPH> Transform( const VECTOR2D& aGlyphSize, const VECTOR2I& aOffset,
114 double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
115 const VECTOR2I& aOrigin );
116
117 void Move( const VECTOR2I& aOffset );
118
119private:
120 bool m_penIsDown = false;
122};
123
124
125
126} // namespace KIFONT
127
128#if defined( _MSC_VER )
129#pragma warning( pop )
130#endif
131
132#endif // GLYPH_H
virtual BOX2D BoundingBox()=0
virtual bool IsStroke() const
Definition: glyph.h:51
virtual bool IsOutline() const
Definition: glyph.h:50
virtual ~GLYPH()
Definition: glyph.h:47
OUTLINE_GLYPH(const OUTLINE_GLYPH &aGlyph)
Definition: glyph.h:64
OUTLINE_GLYPH(const SHAPE_POLY_SET &aPoly)
Definition: glyph.h:68
bool IsOutline() const override
Definition: glyph.h:72
bool IsStroke() const override
Definition: glyph.h:104
BOX2D BoundingBox() override
Definition: glyph.h:110
void SetBoundingBox(const BOX2D &bbox)
Definition: glyph.h:111
BOX2D m_boundingBox
Definition: glyph.h:121
Represent a set of closed polygons.
#define GAL_API
Definition: gal.h:28