2021-12-31 14:07:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Ola Rinta-Koski
|
2022-01-04 00:44:59 +00:00
|
|
|
* Copyright (C) 2021-2022 Kicad Developers, see AUTHORS.txt for contributors.
|
2021-12-31 14:07:24 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GLYPH_H
|
|
|
|
#define GLYPH_H
|
|
|
|
|
2023-09-26 11:40:17 +00:00
|
|
|
#include <gal/gal.h>
|
2021-12-31 14:07:24 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <math/box2.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <wx/debug.h>
|
2022-01-15 01:12:24 +00:00
|
|
|
#include "../../libs/kimath/include/geometry/eda_angle.h"
|
2021-12-31 14:07:24 +00:00
|
|
|
|
2023-09-27 06:22:39 +00:00
|
|
|
#if defined( _MSC_VER )
|
2023-09-26 11:40:17 +00:00
|
|
|
#pragma warning( push )
|
|
|
|
#pragma warning( disable : 4275 )
|
2023-09-27 06:22:39 +00:00
|
|
|
#endif
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2021-12-31 14:07:24 +00:00
|
|
|
namespace KIFONT
|
|
|
|
{
|
2022-01-15 12:51:09 +00:00
|
|
|
|
|
|
|
constexpr int GLYPH_DEFAULT_DPI = 72; ///< FreeType default
|
|
|
|
// The FreeType default of 72 DPI is not enough for outline decomposition;
|
|
|
|
// so we'll use something larger than that.
|
|
|
|
constexpr int GLYPH_RESOLUTION = 288;
|
|
|
|
constexpr double GLYPH_SIZE_SCALER = GLYPH_DEFAULT_DPI / (double) GLYPH_RESOLUTION;
|
|
|
|
|
|
|
|
|
2023-09-26 11:40:17 +00:00
|
|
|
class GAL_API GLYPH
|
2021-12-31 14:07:24 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~GLYPH()
|
|
|
|
{}
|
|
|
|
|
2022-01-04 00:44:59 +00:00
|
|
|
virtual bool IsOutline() const { return false; }
|
|
|
|
virtual bool IsStroke() const { return false; }
|
2021-12-31 14:07:24 +00:00
|
|
|
|
|
|
|
virtual BOX2D BoundingBox() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-09-26 11:40:17 +00:00
|
|
|
class GAL_API OUTLINE_GLYPH : public GLYPH, public SHAPE_POLY_SET
|
2022-01-01 01:21:03 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
OUTLINE_GLYPH() :
|
|
|
|
SHAPE_POLY_SET()
|
|
|
|
{}
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
OUTLINE_GLYPH( const OUTLINE_GLYPH& aGlyph ) :
|
|
|
|
SHAPE_POLY_SET( aGlyph )
|
|
|
|
{}
|
|
|
|
|
|
|
|
OUTLINE_GLYPH( const SHAPE_POLY_SET& aPoly ) :
|
|
|
|
SHAPE_POLY_SET( aPoly )
|
|
|
|
{}
|
|
|
|
|
2022-01-01 01:21:03 +00:00
|
|
|
bool IsOutline() const override { return true; }
|
|
|
|
|
|
|
|
BOX2D BoundingBox() override;
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2022-01-10 01:53:01 +00:00
|
|
|
void Triangulate( std::function<void( const VECTOR2I& aPt1,
|
|
|
|
const VECTOR2I& aPt2,
|
|
|
|
const VECTOR2I& aPt3 )> aCallback ) const;
|
2022-01-01 01:21:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-09-26 11:40:17 +00:00
|
|
|
class GAL_API STROKE_GLYPH : public GLYPH, public std::vector<std::vector<VECTOR2D>>
|
2021-12-31 14:07:24 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
STROKE_GLYPH()
|
|
|
|
{}
|
|
|
|
|
|
|
|
STROKE_GLYPH( const STROKE_GLYPH& aGlyph );
|
|
|
|
|
2022-01-04 00:44:59 +00:00
|
|
|
bool IsStroke() const override { return true; }
|
2021-12-31 14:07:24 +00:00
|
|
|
|
2022-01-04 00:44:59 +00:00
|
|
|
void AddPoint( const VECTOR2D& aPoint );
|
|
|
|
void RaisePen();
|
|
|
|
void Finalize();
|
2021-12-31 14:07:24 +00:00
|
|
|
|
2022-01-04 00:44:59 +00:00
|
|
|
BOX2D BoundingBox() override { return m_boundingBox; }
|
|
|
|
void SetBoundingBox( const BOX2D& bbox ) { m_boundingBox = bbox; }
|
2021-12-31 14:07:24 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
std::unique_ptr<GLYPH> Transform( const VECTOR2D& aGlyphSize, const VECTOR2I& aOffset,
|
|
|
|
double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
|
|
|
|
const VECTOR2I& aOrigin );
|
2021-12-31 14:07:24 +00:00
|
|
|
|
|
|
|
private:
|
2022-01-04 00:44:59 +00:00
|
|
|
bool m_penIsDown = false;
|
|
|
|
BOX2D m_boundingBox;
|
2021-12-31 14:07:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace KIFONT
|
|
|
|
|
2023-09-27 06:22:39 +00:00
|
|
|
#if defined( _MSC_VER )
|
2023-09-26 11:40:17 +00:00
|
|
|
#pragma warning( pop )
|
2023-09-27 06:22:39 +00:00
|
|
|
#endif
|
2023-09-26 11:40:17 +00:00
|
|
|
|
2021-12-31 14:07:24 +00:00
|
|
|
#endif // GLYPH_H
|