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 <wx/debug.h>
33#include "../../libs/kimath/include/geometry/eda_angle.h"
34
35#if defined( _MSC_VER )
36#pragma warning( push )
37#pragma warning( disable : 4275 )
38#endif
39
40namespace KIFONT
41{
42
43constexpr int GLYPH_DEFAULT_DPI = 72;
44// The FreeType default of 72 DPI is not enough for outline decomposition;
45// so we'll use something larger than that.
46constexpr int GLYPH_RESOLUTION = 288;
48
49
51{
52public:
53 virtual ~GLYPH()
54 {}
55
56 virtual bool IsOutline() const { return false; }
57 virtual bool IsStroke() const { return false; }
58
59 virtual BOX2D BoundingBox() = 0;
60};
61
62
64{
65public:
68 {}
69
70 OUTLINE_GLYPH( const OUTLINE_GLYPH& aGlyph ) :
71 SHAPE_POLY_SET( aGlyph )
72 {}
73
74 OUTLINE_GLYPH( const SHAPE_POLY_SET& aPoly ) :
75 SHAPE_POLY_SET( aPoly )
76 {}
77
78 bool IsOutline() const override { return true; }
79
80 BOX2D BoundingBox() override;
81
82 void Triangulate( std::function<void( const VECTOR2I& aPt1,
83 const VECTOR2I& aPt2,
84 const VECTOR2I& aPt3 )> aCallback ) const;
85
86 void CacheTriangulation( bool aPartition = true, bool aSimplify = false ) override;
87
92 std::vector<std::unique_ptr<SHAPE_POLY_SET::TRIANGULATED_POLYGON>> GetTriangulationData() const;
93
98 void CacheTriangulation( std::vector<std::unique_ptr<SHAPE_POLY_SET::TRIANGULATED_POLYGON>>& aHintData );
99};
100
101
102class GAL_API STROKE_GLYPH : public GLYPH, public std::vector<std::vector<VECTOR2D>>
103{
104public:
106 {}
107
108 STROKE_GLYPH( const STROKE_GLYPH& aGlyph );
109
110 bool IsStroke() const override { return true; }
111
112 void AddPoint( const VECTOR2D& aPoint );
113 void RaisePen();
114 void Finalize();
115
116 BOX2D BoundingBox() override { return m_boundingBox; }
117 void SetBoundingBox( const BOX2D& bbox ) { m_boundingBox = bbox; }
118
119 std::unique_ptr<GLYPH> Transform( const VECTOR2D& aGlyphSize, const VECTOR2I& aOffset,
120 double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
121 const VECTOR2I& aOrigin );
122
123 void Move( const VECTOR2I& aOffset );
124
125private:
126 bool m_penIsDown = false;
128};
129
130
131
132} // namespace KIFONT
133
134#if defined( _MSC_VER )
135#pragma warning( pop )
136#endif
137
138#endif // GLYPH_H
virtual BOX2D BoundingBox()=0
virtual bool IsStroke() const
Definition: glyph.h:57
virtual bool IsOutline() const
Definition: glyph.h:56
virtual ~GLYPH()
Definition: glyph.h:53
OUTLINE_GLYPH(const OUTLINE_GLYPH &aGlyph)
Definition: glyph.h:70
OUTLINE_GLYPH(const SHAPE_POLY_SET &aPoly)
Definition: glyph.h:74
bool IsOutline() const override
Definition: glyph.h:78
bool IsStroke() const override
Definition: glyph.h:110
BOX2D BoundingBox() override
Definition: glyph.h:116
void SetBoundingBox(const BOX2D &bbox)
Definition: glyph.h:117
BOX2D m_boundingBox
Definition: glyph.h:127
Represent a set of closed polygons.
#define GAL_API
Definition: gal.h:28
constexpr int GLYPH_RESOLUTION
Definition: glyph.h:46
constexpr double GLYPH_SIZE_SCALER
Definition: glyph.h:47
constexpr int GLYPH_DEFAULT_DPI
FreeType default.
Definition: glyph.h:43