KiCad PCB EDA Suite
Loading...
Searching...
No Matches
outline_decomposer.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 * Outline font class
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef OUTLINE_DECOMPOSER_H
28#define OUTLINE_DECOMPOSER_H
29
30#include <vector>
31#ifdef _MSC_VER
32#include <ft2build.h>
33#else
34#include <freetype2/ft2build.h>
35#endif
36#include FT_FREETYPE_H
37#include FT_OUTLINE_H
38#include <math/box2.h>
39#include <math/vector2d.h>
40#include <font/glyph.h>
41
42namespace KIFONT
43{
44struct CONTOUR
45{
46 std::vector<VECTOR2D> m_Points;
47 int m_Winding = 0;
48 FT_Orientation m_Orientation;
49};
50
52{
53 std::vector<CONTOUR> m_Contours;
54
55 // Cache of the triangulation data. We'll use this as a hint for triangulating the actual
56 // OUTLINE_GLYPHs.
57 std::vector<std::unique_ptr<SHAPE_POLY_SET::TRIANGULATED_POLYGON>> m_TriangulationData;
58};
59
60
62{
63public:
64 OUTLINE_DECOMPOSER( FT_Outline& aOutline );
65
66 bool OutlineToSegments( std::vector<CONTOUR>* aContours );
67
68private:
69 void newContour();
70
71 void addContourPoint( const VECTOR2D& p );
72
73 bool approximateBezierCurve( std::vector<VECTOR2D>& result,
74 const std::vector<VECTOR2D>& bezier ) const;
75 bool approximateQuadraticBezierCurve( std::vector<VECTOR2D>& result,
76 const std::vector<VECTOR2D>& bezier ) const;
77 bool approximateCubicBezierCurve( std::vector<VECTOR2D>& result,
78 const std::vector<VECTOR2D>& bezier ) const;
79
84 int winding( const std::vector<VECTOR2D>& aContour ) const;
85
86 inline static unsigned int onCurve( char aTags )
87 {
88 return aTags & 0x1;
89 }
90
91 inline static unsigned int thirdOrderBezierPoint( char aTags )
92 {
93 return onCurve( aTags ) ? 0 : aTags & 0x2;
94 }
95
96 inline static unsigned int secondOrderBezierPoint( char aTags )
97 {
98 return onCurve( aTags ) ? 0 : !thirdOrderBezierPoint( aTags );
99 }
100
101 inline static unsigned int hasDropout( char aTags )
102 {
103 return aTags & 0x4;
104 }
105
106 inline static unsigned int dropoutMode( char aTags )
107 {
108 return hasDropout( aTags ) ? ( aTags & 0x38 ) : 0;
109 }
110
111 // FT_Outline_Decompose callbacks
112 static int moveTo( const FT_Vector* aEndPoint, void* aCallbackData );
113
114 static int lineTo( const FT_Vector* aEndPoint, void* aCallbackData );
115
116 static int quadraticTo( const FT_Vector* aControlPoint, const FT_Vector* aEndPoint,
117 void* aCallbackData );
118
119 static int cubicTo( const FT_Vector* aFirstControlPoint, const FT_Vector* aSecondControlPoint,
120 const FT_Vector* aEndPoint, void* aCallbackData );
121
122private:
123 FT_Outline& m_outline;
124 std::vector<CONTOUR>* m_contours;
125
127};
128
129} //namespace KIFONT
130
131#endif // OUTLINE_DECOMPOSER_H
static unsigned int hasDropout(char aTags)
bool approximateBezierCurve(std::vector< VECTOR2D > &result, const std::vector< VECTOR2D > &bezier) const
static unsigned int onCurve(char aTags)
void addContourPoint(const VECTOR2D &p)
std::vector< CONTOUR > * m_contours
static int cubicTo(const FT_Vector *aFirstControlPoint, const FT_Vector *aSecondControlPoint, const FT_Vector *aEndPoint, void *aCallbackData)
static int moveTo(const FT_Vector *aEndPoint, void *aCallbackData)
bool OutlineToSegments(std::vector< CONTOUR > *aContours)
bool approximateCubicBezierCurve(std::vector< VECTOR2D > &result, const std::vector< VECTOR2D > &bezier) const
static unsigned int thirdOrderBezierPoint(char aTags)
static int lineTo(const FT_Vector *aEndPoint, void *aCallbackData)
static unsigned int secondOrderBezierPoint(char aTags)
static int quadraticTo(const FT_Vector *aControlPoint, const FT_Vector *aEndPoint, void *aCallbackData)
static unsigned int dropoutMode(char aTags)
bool approximateQuadraticBezierCurve(std::vector< VECTOR2D > &result, const std::vector< VECTOR2D > &bezier) const
int winding(const std::vector< VECTOR2D > &aContour) const
std::vector< VECTOR2D > m_Points
FT_Orientation m_Orientation
std::vector< CONTOUR > m_Contours
std::vector< std::unique_ptr< SHAPE_POLY_SET::TRIANGULATED_POLYGON > > m_TriangulationData