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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef GLYPH_H
22#define GLYPH_H
23
24#include <gal/gal.h>
25#include <memory>
26#include <math/box2.h>
28#include <geometry/eda_angle.h>
29#include <wx/debug.h>
30
31#if defined( _MSC_VER )
32#pragma warning( push )
33#pragma warning( disable : 4275 )
34#endif
35
36namespace KIFONT
37{
38
39
41{
42public:
43 virtual ~GLYPH()
44 {}
45
46 virtual bool IsOutline() const { return false; }
47 virtual bool IsStroke() const { return false; }
48
49 virtual BOX2D BoundingBox() = 0;
50
51 bool IsHover() const { return m_isHover; }
52 void SetIsHover( bool aIsHover ) { m_isHover = aIsHover; }
53
54private:
55 bool m_isHover = false;
56};
57
58
60{
61public:
65
66 OUTLINE_GLYPH( const OUTLINE_GLYPH& aGlyph ) :
67 SHAPE_POLY_SET( aGlyph )
68 {}
69
70 OUTLINE_GLYPH( const SHAPE_POLY_SET& aPoly ) :
71 SHAPE_POLY_SET( aPoly )
72 {}
73
74 bool IsOutline() const override { return true; }
75
76 BOX2D BoundingBox() override;
77
78 void Triangulate( std::function<void( const VECTOR2I& aPt1,
79 const VECTOR2I& aPt2,
80 const VECTOR2I& aPt3 )> aCallback ) const;
81
82 void CacheTriangulation( bool aSimplify = false,
83 const TASK_SUBMITTER& aSubmitter = {} ) override;
84
89 std::vector<std::unique_ptr<SHAPE_POLY_SET::TRIANGULATED_POLYGON>> GetTriangulationData() const;
90
95 void CacheTriangulation( std::vector<std::unique_ptr<SHAPE_POLY_SET::TRIANGULATED_POLYGON>>& aHintData );
96};
97
98
99class GAL_API STROKE_GLYPH : public GLYPH, public std::vector<std::vector<VECTOR2D>>
100{
101public:
103 {}
104
105 STROKE_GLYPH( const STROKE_GLYPH& aGlyph );
106
107 bool IsStroke() const override { return true; }
108
109 void AddPoint( const VECTOR2D& aPoint );
110 void RaisePen();
111 void Finalize();
112
113 BOX2D BoundingBox() override { return m_boundingBox; }
114 void SetBoundingBox( const BOX2D& bbox ) { m_boundingBox = bbox; }
115
116 std::unique_ptr<GLYPH> Transform( const VECTOR2D& aGlyphSize, const VECTOR2I& aOffset,
117 double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
118 const VECTOR2I& aOrigin );
119
120 void Move( const VECTOR2I& aOffset );
121
122private:
123 bool m_penIsDown = false;
125};
126
127
128
129} // namespace KIFONT
130
131#if defined( _MSC_VER )
132#pragma warning( pop )
133#endif
134
135#endif // GLYPH_H
BOX2< VECTOR2D > BOX2D
Definition box2.h:919
virtual BOX2D BoundingBox()=0
virtual bool IsStroke() const
Definition glyph.h:47
virtual bool IsOutline() const
Definition glyph.h:46
void SetIsHover(bool aIsHover)
Definition glyph.h:52
bool IsHover() const
Definition glyph.h:51
virtual ~GLYPH()
Definition glyph.h:43
bool m_isHover
Definition glyph.h:55
OUTLINE_GLYPH(const OUTLINE_GLYPH &aGlyph)
Definition glyph.h:66
OUTLINE_GLYPH(const SHAPE_POLY_SET &aPoly)
Definition glyph.h:70
bool IsOutline() const override
Definition glyph.h:74
bool IsStroke() const override
Definition glyph.h:107
BOX2D BoundingBox() override
Definition glyph.h:113
void SetBoundingBox(const BOX2D &bbox)
Definition glyph.h:114
#define GAL_API
Definition gal.h:27
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682