You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.4 KiB

  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. #ifndef GLYPH_H
  25. #define GLYPH_H
  26. #include <gal/gal.h>
  27. #include <memory>
  28. #include <math/box2.h>
  29. #include <geometry/shape_poly_set.h>
  30. #include <wx/debug.h>
  31. #include "../../libs/kimath/include/geometry/eda_angle.h"
  32. #if defined( _MSC_VER )
  33. #pragma warning( push )
  34. #pragma warning( disable : 4275 )
  35. #endif
  36. namespace KIFONT
  37. {
  38. constexpr int GLYPH_DEFAULT_DPI = 72; ///< FreeType default
  39. // The FreeType default of 72 DPI is not enough for outline decomposition;
  40. // so we'll use something larger than that.
  41. constexpr int GLYPH_RESOLUTION = 288;
  42. constexpr double GLYPH_SIZE_SCALER = GLYPH_DEFAULT_DPI / (double) GLYPH_RESOLUTION;
  43. class GAL_API GLYPH
  44. {
  45. public:
  46. virtual ~GLYPH()
  47. {}
  48. virtual bool IsOutline() const { return false; }
  49. virtual bool IsStroke() const { return false; }
  50. virtual BOX2D BoundingBox() = 0;
  51. };
  52. class GAL_API OUTLINE_GLYPH : public GLYPH, public SHAPE_POLY_SET
  53. {
  54. public:
  55. OUTLINE_GLYPH() :
  56. SHAPE_POLY_SET()
  57. {}
  58. OUTLINE_GLYPH( const OUTLINE_GLYPH& aGlyph ) :
  59. SHAPE_POLY_SET( aGlyph )
  60. {}
  61. OUTLINE_GLYPH( const SHAPE_POLY_SET& aPoly ) :
  62. SHAPE_POLY_SET( aPoly )
  63. {}
  64. bool IsOutline() const override { return true; }
  65. BOX2D BoundingBox() override;
  66. void Triangulate( std::function<void( const VECTOR2I& aPt1,
  67. const VECTOR2I& aPt2,
  68. const VECTOR2I& aPt3 )> aCallback ) const;
  69. };
  70. class GAL_API STROKE_GLYPH : public GLYPH, public std::vector<std::vector<VECTOR2D>>
  71. {
  72. public:
  73. STROKE_GLYPH()
  74. {}
  75. STROKE_GLYPH( const STROKE_GLYPH& aGlyph );
  76. bool IsStroke() const override { return true; }
  77. void AddPoint( const VECTOR2D& aPoint );
  78. void RaisePen();
  79. void Finalize();
  80. BOX2D BoundingBox() override { return m_boundingBox; }
  81. void SetBoundingBox( const BOX2D& bbox ) { m_boundingBox = bbox; }
  82. std::unique_ptr<GLYPH> Transform( const VECTOR2D& aGlyphSize, const VECTOR2I& aOffset,
  83. double aTilt, const EDA_ANGLE& aAngle, bool aMirror,
  84. const VECTOR2I& aOrigin );
  85. private:
  86. bool m_penIsDown = false;
  87. BOX2D m_boundingBox;
  88. };
  89. } // namespace KIFONT
  90. #if defined( _MSC_VER )
  91. #pragma warning( pop )
  92. #endif
  93. #endif // GLYPH_H