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 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{
44typedef std::vector<VECTOR2D> GLYPH_POINTS;
45typedef std::vector<GLYPH_POINTS> GLYPH_POINTS_LIST;
46typedef std::vector<BOX2D> GLYPH_BOUNDING_BOX_LIST;
47
48struct CONTOUR
49{
51 int m_Winding = 0;
52 FT_Orientation m_Orientation;
53};
54
55
56typedef std::vector<CONTOUR> CONTOURS;
57
58
60{
61public:
62 OUTLINE_DECOMPOSER( FT_Outline& aOutline );
63
64 void OutlineToSegments( CONTOURS* aContours );
65
66private:
67 void contourToSegmentsAndArcs( CONTOUR& aResult, unsigned int aContourIndex ) const;
68
69 void newContour();
70
71 void addContourPoint( const VECTOR2D& p );
72
73 int approximateContour( const GLYPH_POINTS& aPoints, const std::vector<bool>& aPointOnCurve,
74 GLYPH_POINTS& aResult ) const;
75
76 bool approximateBezierCurve( GLYPH_POINTS& result, const GLYPH_POINTS& bezier ) const;
77 bool approximateQuadraticBezierCurve( GLYPH_POINTS& result, const GLYPH_POINTS& bezier ) const;
78 bool approximateCubicBezierCurve( GLYPH_POINTS& result, const GLYPH_POINTS& bezier ) const;
79
85 int winding( const GLYPH_POINTS& aContour ) const;
86
87 inline static unsigned int onCurve( char aTags )
88 {
89 return aTags & 0x1;
90 }
91
92 inline static unsigned int thirdOrderBezierPoint( char aTags )
93 {
94 return onCurve( aTags ) ? 0 : aTags & 0x2;
95 }
96
97 inline static unsigned int secondOrderBezierPoint( char aTags )
98 {
99 return onCurve( aTags ) ? 0 : !thirdOrderBezierPoint( aTags );
100 }
101
102 inline static unsigned int hasDropout( char aTags )
103 {
104 return aTags & 0x4;
105 }
106
107 inline static unsigned int dropoutMode( char aTags )
108 {
109 return hasDropout( aTags ) ? ( aTags & 0x38 ) : 0;
110 }
111
112 // FT_Outline_Decompose callbacks
113 static int moveTo( const FT_Vector* aEndPoint, void* aCallbackData );
114
115 static int lineTo( const FT_Vector* aEndPoint, void* aCallbackData );
116
117 static int quadraticTo( const FT_Vector* aControlPoint, const FT_Vector* aEndPoint,
118 void* aCallbackData );
119
120 static int cubicTo( const FT_Vector* aFirstControlPoint, const FT_Vector* aSecondControlPoint,
121 const FT_Vector* aEndPoint, void* aCallbackData );
122
123private:
124 FT_Outline& m_outline;
126
128};
129
130} //namespace KIFONT
131
132#endif // OUTLINE_DECOMPOSER_H
static unsigned int hasDropout(char aTags)
static unsigned int onCurve(char aTags)
void addContourPoint(const VECTOR2D &p)
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)
int approximateContour(const GLYPH_POINTS &aPoints, const std::vector< bool > &aPointOnCurve, GLYPH_POINTS &aResult) const
static unsigned int thirdOrderBezierPoint(char aTags)
static int lineTo(const FT_Vector *aEndPoint, void *aCallbackData)
void OutlineToSegments(CONTOURS *aContours)
void contourToSegmentsAndArcs(CONTOUR &aResult, unsigned int aContourIndex) const
bool approximateQuadraticBezierCurve(GLYPH_POINTS &result, const GLYPH_POINTS &bezier) const
int winding(const GLYPH_POINTS &aContour) const
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 approximateCubicBezierCurve(GLYPH_POINTS &result, const GLYPH_POINTS &bezier) const
bool approximateBezierCurve(GLYPH_POINTS &result, const GLYPH_POINTS &bezier) const
std::vector< GLYPH_POINTS > GLYPH_POINTS_LIST
Definition: glyph.h:116
std::vector< CONTOUR > CONTOURS
std::vector< BOX2D > GLYPH_BOUNDING_BOX_LIST
Definition: glyph.h:117
std::vector< VECTOR2D > GLYPH_POINTS
Definition: glyph.h:115
GLYPH_POINTS m_Points
FT_Orientation m_Orientation