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-2022 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
87
88class GAL_API STROKE_GLYPH : public GLYPH, public std::vector<std::vector<VECTOR2D>>
89{
90public:
92 {}
93
94 STROKE_GLYPH( const STROKE_GLYPH& aGlyph );
95
96 bool IsStroke() const override { return true; }
97
98 void AddPoint( const VECTOR2D& aPoint );
99 void RaisePen();
100 void Finalize();
101
102 BOX2D BoundingBox() override { return m_boundingBox; }
103 void SetBoundingBox( const BOX2D& bbox ) { m_boundingBox = bbox; }
104
105 std::unique_ptr<GLYPH> Transform( const VECTOR2D& aGlyphSize, const VECTOR2I& aOffset,
106 double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
107 const VECTOR2I& aOrigin );
108
109private:
110 bool m_penIsDown = false;
112};
113
114
115typedef std::vector<VECTOR2D> GLYPH_POINTS;
116typedef std::vector<GLYPH_POINTS> GLYPH_POINTS_LIST;
117typedef std::vector<BOX2D> GLYPH_BOUNDING_BOX_LIST;
118
119
120} // namespace KIFONT
121
122#if defined( _MSC_VER )
123#pragma warning( pop )
124#endif
125
126#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:96
BOX2D BoundingBox() override
Definition: glyph.h:102
void SetBoundingBox(const BOX2D &bbox)
Definition: glyph.h:103
BOX2D m_boundingBox
Definition: glyph.h:111
Represent a set of closed polygons.
#define GAL_API
Definition: gal.h:28
constexpr int GLYPH_RESOLUTION
Definition: glyph.h:46
std::vector< GLYPH_POINTS > GLYPH_POINTS_LIST
Definition: glyph.h:116
constexpr double GLYPH_SIZE_SCALER
Definition: glyph.h:47
std::vector< BOX2D > GLYPH_BOUNDING_BOX_LIST
Definition: glyph.h:117
std::vector< VECTOR2D > GLYPH_POINTS
Definition: glyph.h:115
constexpr int GLYPH_DEFAULT_DPI
FreeType default.
Definition: glyph.h:43