2018-10-13 18:37:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
|
|
|
* @author Janito V. Ferreira Filho <janito.vff@gmail.com>
|
2019-06-15 03:27:36 +00:00
|
|
|
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-10-13 18:37:28 +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 SVG_IMPORT_PLUGIN_H
|
|
|
|
#define SVG_IMPORT_PLUGIN_H
|
|
|
|
|
|
|
|
#include "nanosvg.h"
|
|
|
|
|
|
|
|
#include "graphics_import_plugin.h"
|
2021-12-30 02:48:44 +00:00
|
|
|
#include "graphics_importer_buffer.h"
|
2018-10-13 18:37:28 +00:00
|
|
|
#include <math/vector2d.h>
|
2019-06-15 03:27:36 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
|
|
|
#include <vector>
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SVG_IMPORT_PLUGIN : public GRAPHICS_IMPORT_PLUGIN
|
|
|
|
{
|
|
|
|
public:
|
2021-03-25 08:12:24 +00:00
|
|
|
SVG_IMPORT_PLUGIN():
|
|
|
|
GRAPHICS_IMPORT_PLUGIN(),
|
|
|
|
m_parsedImage( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
const wxString GetName() const override
|
|
|
|
{
|
|
|
|
return "Scalable Vector Graphics";
|
|
|
|
}
|
|
|
|
|
2019-09-26 20:09:09 +00:00
|
|
|
const std::vector<std::string> GetFileExtensions() const override
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2019-09-26 20:09:09 +00:00
|
|
|
static std::vector<std::string> exts = { "svg" };
|
|
|
|
return exts;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
/**
|
|
|
|
* @return the list of messages in one string. Each message ends by '\n'
|
|
|
|
*/
|
2021-03-24 04:29:00 +00:00
|
|
|
const wxString& GetMessages() const override
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2018-11-05 16:04:05 +00:00
|
|
|
return m_messages;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
bool Import() override;
|
|
|
|
bool Load( const wxString& aFileName ) override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
virtual double GetImageHeight() const override;
|
|
|
|
virtual double GetImageWidth() const override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
private:
|
2018-11-05 16:04:05 +00:00
|
|
|
void DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath, bool aFilled, double aLineWidth );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
void DrawCubicBezierPath( const float* aPoints, int aNumPoints,
|
|
|
|
std::vector< VECTOR2D >& aGeneratedPoints );
|
|
|
|
|
|
|
|
void DrawCubicBezierCurve( const float* aPoints,
|
|
|
|
std::vector< VECTOR2D >& aGeneratedPoints );
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
void DrawPolygon( const std::vector< VECTOR2D >& aPoints, double aWidth );
|
|
|
|
void DrawLineSegments( const std::vector< VECTOR2D >& aPoints, double aWidth );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
struct NSVGimage* m_parsedImage;
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2021-03-24 04:29:00 +00:00
|
|
|
wxString m_messages; // messages generated during svg file parsing.
|
2018-11-05 16:04:05 +00:00
|
|
|
// Each message ends by '\n'
|
2021-12-30 02:48:44 +00:00
|
|
|
|
|
|
|
GRAPHICS_IMPORTER_BUFFER m_internalImporter;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SVG_IMPORT_PLUGIN_H */
|