KiCad PCB EDA Suite
Loading...
Searching...
No Matches
plotter_png.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PLOTTER_PNG_H
21#define PLOTTER_PNG_H
22
23#include "plotter.h"
24
25#include <cairo.h>
26
33class PNG_PLOTTER : public PLOTTER
34{
35public:
37 virtual ~PNG_PLOTTER();
38
39 virtual PLOT_FORMAT GetPlotterType() const override
40 {
41 // PNG is not in the standard PLOT_FORMAT enum, but we need to return something
43 }
44
45 static wxString GetDefaultFileExtension() { return wxString( wxT( "png" ) ); }
46
51 void SetResolution( int aDPI ) { m_dpi = aDPI; }
52 int GetResolution() const { return m_dpi; }
53
59 void SetPixelSize( int aWidth, int aHeight )
60 {
61 m_width = aWidth;
62 m_height = aHeight;
63 }
64
65 int GetPixelWidth() const { return m_width; }
66 int GetPixelHeight() const { return m_height; }
67
72 void SetBackgroundColor( const COLOR4D& aColor ) { m_backgroundColor = aColor; }
74
79 void SetAntialias( bool aEnable ) { m_antialias = aEnable; }
80 bool GetAntialias() const { return m_antialias; }
81
82 // PLOTTER interface implementation
83 virtual bool StartPlot( const wxString& aPageNumber ) override;
84 virtual bool EndPlot() override;
85
86 virtual void SetCurrentLineWidth( int aWidth, void* aData = nullptr ) override;
87 virtual void SetColor( const COLOR4D& aColor ) override;
88 virtual void SetDash( int aLineWidth, LINE_STYLE aLineStyle ) override;
89
96 void SetClearCompositing( bool aClear );
97
98 virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil, double aScale, bool aMirror ) override;
99
100 // Primitive drawing operations
101 virtual void Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T aFill, int aWidth,
102 int aCornerRadius = 0 ) override;
103
104 virtual void Circle( const VECTOR2I& aCenter, int aDiameter, FILL_T aFill, int aWidth ) override;
105
106 virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle, double aRadius,
107 FILL_T aFill, int aWidth ) override;
108
109 virtual void PenTo( const VECTOR2I& aPos, char aPlume ) override;
110
111 virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth,
112 void* aData = nullptr ) override;
113
114 // Flash pad operations
115 virtual void FlashPadCircle( const VECTOR2I& aPadPos, int aDiameter, void* aData ) override;
116
117 virtual void FlashPadOval( const VECTOR2I& aPadPos, const VECTOR2I& aSize, const EDA_ANGLE& aPadOrient,
118 void* aData ) override;
119
120 virtual void FlashPadRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize, const EDA_ANGLE& aPadOrient,
121 void* aData ) override;
122
123 virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize, int aCornerRadius,
124 const EDA_ANGLE& aOrient, void* aData ) override;
125
126 virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize, const EDA_ANGLE& aPadOrient,
127 SHAPE_POLY_SET* aPolygons, void* aData ) override;
128
129 virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners, const EDA_ANGLE& aPadOrient,
130 void* aData ) override;
131
132 virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
133 const EDA_ANGLE& aOrient, void* aData ) override;
134
140 bool SaveFile( const wxString& aPath );
141
142protected:
146 virtual VECTOR2D userToDeviceCoordinates( const VECTOR2I& aCoordinate ) override;
147
151 virtual VECTOR2D userToDeviceSize( const VECTOR2I& aSize ) override;
152
156 virtual double userToDeviceSize( double aSize ) const override;
157
158private:
159 void fillRect( double aX, double aY, double aWidth, double aHeight );
160 void strokeRect( double aX, double aY, double aWidth, double aHeight );
161 void fillCircle( double aCx, double aCy, double aRadius );
162 void strokeCircle( double aCx, double aCy, double aRadius );
163
164 cairo_surface_t* m_surface;
165 cairo_t* m_context;
166
167 int m_dpi;
173};
174
175#endif // PLOTTER_PNG_H
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
PLOTTER(const PROJECT *aProject=nullptr)
Definition plotter.cpp:48
virtual void SetCurrentLineWidth(int aWidth, void *aData=nullptr) override
Set the line width for the next drawing.
void fillCircle(double aCx, double aCy, double aRadius)
virtual void FlashPadRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, void *aData) override
cairo_surface_t * m_surface
virtual void PenTo(const VECTOR2I &aPos, char aPlume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
virtual ~PNG_PLOTTER()
COLOR4D GetBackgroundColor() const
Definition plotter_png.h:73
void SetPixelSize(int aWidth, int aHeight)
Set the output image dimensions in pixels.
Definition plotter_png.h:59
bool GetAntialias() const
Definition plotter_png.h:80
virtual void FlashRegularPolygon(const VECTOR2I &aShapePos, int aDiameter, int aCornerCount, const EDA_ANGLE &aOrient, void *aData) override
Flash a regular polygon.
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle) override
virtual void Circle(const VECTOR2I &aCenter, int aDiameter, FILL_T aFill, int aWidth) override
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T aFill, int aWidth, int aCornerRadius=0) override
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth) override
bool SaveFile(const wxString &aPath)
Save the rendered image to a PNG file.
void SetBackgroundColor(const COLOR4D &aColor)
Set the background color for the image.
Definition plotter_png.h:72
virtual void FlashPadOval(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, void *aData) override
COLOR4D m_currentColor
void SetResolution(int aDPI)
Set the output resolution in dots per inch.
Definition plotter_png.h:51
virtual bool EndPlot() override
COLOR4D m_backgroundColor
virtual VECTOR2D userToDeviceCoordinates(const VECTOR2I &aCoordinate) override
Transform coordinates from user space (IU) to device space (pixels).
void fillRect(double aX, double aY, double aWidth, double aHeight)
cairo_t * m_context
void SetAntialias(bool aEnable)
Enable or disable anti-aliasing.
Definition plotter_png.h:79
void strokeCircle(double aCx, double aCy, double aRadius)
virtual void FlashPadCircle(const VECTOR2I &aPadPos, int aDiameter, void *aData) override
int GetResolution() const
Definition plotter_png.h:52
virtual void SetColor(const COLOR4D &aColor) override
int GetPixelWidth() const
Definition plotter_png.h:65
virtual void FlashPadTrapez(const VECTOR2I &aPadPos, const VECTOR2I *aCorners, const EDA_ANGLE &aPadOrient, void *aData) override
Flash a trapezoidal pad.
virtual void FlashPadRoundRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, int aCornerRadius, const EDA_ANGLE &aOrient, void *aData) override
virtual VECTOR2D userToDeviceSize(const VECTOR2I &aSize) override
Transform a size from user space to device space.
virtual PLOT_FORMAT GetPlotterType() const override
Return the effective plot engine in use.
Definition plotter_png.h:39
static wxString GetDefaultFileExtension()
Definition plotter_png.h:45
virtual void FlashPadCustom(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, SHAPE_POLY_SET *aPolygons, void *aData) override
void strokeRect(double aX, double aY, double aWidth, double aHeight)
int GetPixelHeight() const
Definition plotter_png.h:66
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth, void *aData=nullptr) override
Draw a polygon ( filled or not ).
void SetClearCompositing(bool aClear)
Switch the Cairo compositing operator between CLEAR and OVER.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual bool StartPlot(const wxString &aPageNumber) override
Represent a set of closed polygons.
FILL_T
Definition eda_shape.h:58
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:64
LINE_STYLE
Dashed line types.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687
VECTOR2< double > VECTOR2D
Definition vector2d.h:686