KiCad PCB EDA Suite
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 <memory>
29#include <math/box2.h>
31#include <wx/debug.h>
32#include "../../libs/kimath/include/geometry/eda_angle.h"
33
34
35namespace KIFONT
36{
37
38constexpr int GLYPH_DEFAULT_DPI = 72;
39// The FreeType default of 72 DPI is not enough for outline decomposition;
40// so we'll use something larger than that.
41constexpr int GLYPH_RESOLUTION = 288;
43
44
45class GLYPH
46{
47public:
48 virtual ~GLYPH()
49 {}
50
51 virtual bool IsOutline() const { return false; }
52 virtual bool IsStroke() const { return false; }
53
54 virtual BOX2D BoundingBox() = 0;
55};
56
57
58class OUTLINE_GLYPH : public GLYPH, public SHAPE_POLY_SET
59{
60public:
63 {}
64
65 OUTLINE_GLYPH( const OUTLINE_GLYPH& aGlyph ) :
66 SHAPE_POLY_SET( aGlyph )
67 {}
68
69 OUTLINE_GLYPH( const SHAPE_POLY_SET& aPoly ) :
70 SHAPE_POLY_SET( aPoly )
71 {}
72
73 bool IsOutline() const override { return true; }
74
75 BOX2D BoundingBox() override;
76
77 void Triangulate( std::function<void( const VECTOR2I& aPt1,
78 const VECTOR2I& aPt2,
79 const VECTOR2I& aPt3 )> aCallback ) const;
80};
81
82
83class STROKE_GLYPH : public GLYPH, public std::vector<std::vector<VECTOR2D>>
84{
85public:
87 {}
88
89 STROKE_GLYPH( const STROKE_GLYPH& aGlyph );
90
91 bool IsStroke() const override { return true; }
92
93 void AddPoint( const VECTOR2D& aPoint );
94 void RaisePen();
95 void Finalize();
96
97 BOX2D BoundingBox() override { return m_boundingBox; }
98 void SetBoundingBox( const BOX2D& bbox ) { m_boundingBox = bbox; }
99
100 std::unique_ptr<GLYPH> Transform( const VECTOR2D& aGlyphSize, const VECTOR2I& aOffset,
101 double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
102 const VECTOR2I& aOrigin );
103
104private:
105 bool m_penIsDown = false;
107};
108
109
110typedef std::vector<VECTOR2D> GLYPH_POINTS;
111typedef std::vector<GLYPH_POINTS> GLYPH_POINTS_LIST;
112typedef std::vector<BOX2D> GLYPH_BOUNDING_BOX_LIST;
113
114
115} // namespace KIFONT
116
117#endif // GLYPH_H
virtual BOX2D BoundingBox()=0
virtual bool IsStroke() const
Definition: glyph.h:52
virtual bool IsOutline() const
Definition: glyph.h:51
virtual ~GLYPH()
Definition: glyph.h:48
OUTLINE_GLYPH(const OUTLINE_GLYPH &aGlyph)
Definition: glyph.h:65
OUTLINE_GLYPH(const SHAPE_POLY_SET &aPoly)
Definition: glyph.h:69
BOX2D BoundingBox() override
Definition: glyph.cpp:114
void Triangulate(std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const VECTOR2I &aPt3)> aCallback) const
Definition: glyph.cpp:121
bool IsOutline() const override
Definition: glyph.h:73
void AddPoint(const VECTOR2D &aPoint)
Definition: glyph.cpp:39
bool IsStroke() const override
Definition: glyph.h:91
BOX2D BoundingBox() override
Definition: glyph.h:97
void SetBoundingBox(const BOX2D &bbox)
Definition: glyph.h:98
BOX2D m_boundingBox
Definition: glyph.h:106
std::unique_ptr< GLYPH > Transform(const VECTOR2D &aGlyphSize, const VECTOR2I &aOffset, double aTilt, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin)
Definition: glyph.cpp:74
Represent a set of closed polygons.
Definition: font.h:100
constexpr int GLYPH_RESOLUTION
Definition: glyph.h:41
std::vector< GLYPH_POINTS > GLYPH_POINTS_LIST
Definition: glyph.h:111
constexpr double GLYPH_SIZE_SCALER
Definition: glyph.h:42
std::vector< BOX2D > GLYPH_BOUNDING_BOX_LIST
Definition: glyph.h:112
std::vector< VECTOR2D > GLYPH_POINTS
Definition: glyph.h:110
constexpr int GLYPH_DEFAULT_DPI
FreeType default.
Definition: glyph.h:38