KiCad PCB EDA Suite
svg_import_plugin.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) 2016 CERN
5  * @author Janito V. Ferreira Filho <janito.vff@gmail.com>
6  * Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef SVG_IMPORT_PLUGIN_H
27 #define SVG_IMPORT_PLUGIN_H
28 
29 #include "nanosvg.h"
30 
31 #include "graphics_import_plugin.h"
32 #include <math/vector2d.h>
34 
35 #include <vector>
36 
37 
39 {
40 public:
41  const wxString GetName() const override
42  {
43  return "Scalable Vector Graphics";
44  }
45 
46  const wxArrayString GetFileExtensions() const override
47  {
48  static wxString wildcardExt = formatWildcardExt( "svg" );
49  return wxArrayString( 1, &wildcardExt );
50  }
51 
55  const std::string& GetMessages() const override
56  {
57  return m_messages;
58  }
59 
60  bool Import() override;
61  bool Load( const wxString& aFileName ) override;
62 
63  virtual double GetImageHeight() const override;
64  virtual double GetImageWidth() const override;
65 
66 private:
67  void DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath, bool aFilled, double aLineWidth );
68 
69  void DrawCubicBezierPath( const float* aPoints, int aNumPoints,
70  std::vector< VECTOR2D >& aGeneratedPoints );
71 
72  void DrawCubicBezierCurve( const float* aPoints,
73  std::vector< VECTOR2D >& aGeneratedPoints );
74 
75  void DrawPolygon( const std::vector< VECTOR2D >& aPoints, double aWidth );
76  void DrawLineSegments( const std::vector< VECTOR2D >& aPoints, double aWidth );
77 
79 
80  std::string m_messages; // messages generated during svg file parsing.
81  // Each message ends by '\n'
82 };
83 
84 #endif /* SVG_IMPORT_PLUGIN_H */
bool Load(const wxString &aFileName) override
Load file for import.
void DrawPolygon(const std::vector< VECTOR2D > &aPoints, double aWidth)
void DrawCubicBezierPath(const float *aPoints, int aNumPoints, std::vector< VECTOR2D > &aGeneratedPoints)
Interface for vector graphics import plugins.
void DrawPath(const float *aPoints, int aNumPoints, bool aClosedPath, bool aFilled, double aLineWidth)
virtual double GetImageWidth() const override
Return image width from original imported file.
bool Import() override
Actually imports the file.
std::string m_messages
const wxArrayString GetFileExtensions() const override
Return a string array of the file extensions handled by this plugin.
void DrawCubicBezierCurve(const float *aPoints, std::vector< VECTOR2D > &aGeneratedPoints)
struct NSVGimage * m_parsedImage
const wxString GetName() const override
Return the plugin name.
Definition of file extensions used in Kicad.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
void DrawLineSegments(const std::vector< VECTOR2D > &aPoints, double aWidth)
const std::string & GetMessages() const override
virtual double GetImageHeight() const override
Return image height from original imported file.