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
27
28constexpr int DEFAULT_PNG_DPI = 300;
29constexpr int MIN_PNG_DPI = 72;
30constexpr int MAX_PNG_DPI = 2400;
31
32
39class PNG_PLOTTER : public PLOTTER
40{
41public:
43 virtual ~PNG_PLOTTER();
44
45 virtual PLOT_FORMAT GetPlotterType() const override
46 {
47 return PLOT_FORMAT::PNG;
48 }
49
50 static wxString GetDefaultFileExtension() { return wxString( wxT( "png" ) ); }
51
56 void SetResolution( int aDPI ) { m_dpi = aDPI; }
57 int GetResolution() const { return m_dpi; }
58
64 void SetPixelSize( int aWidth, int aHeight )
65 {
66 m_width = aWidth;
67 m_height = aHeight;
68 }
69
70 int GetPixelWidth() const { return m_width; }
71 int GetPixelHeight() const { return m_height; }
72
77 void SetBackgroundColor( const COLOR4D& aColor ) { m_backgroundColor = aColor; }
79
84 void SetAntialias( bool aEnable ) { m_antialias = aEnable; }
85 bool GetAntialias() const { return m_antialias; }
86
95 void SetYAxisReversed( bool aReversed ) { m_yaxisReversed = aReversed; }
96 bool GetYAxisReversed() const { return m_yaxisReversed; }
97
98 // PLOTTER interface implementation
99 virtual bool OpenFile( const wxString& aFullFilename ) override;
100 virtual bool StartPlot( const wxString& aPageNumber ) override;
101 virtual bool EndPlot() override;
102
103 virtual void SetCurrentLineWidth( int aWidth, void* aData = nullptr ) override;
104 virtual void SetColor( const COLOR4D& aColor ) override;
105 virtual void SetDash( int aLineWidth, LINE_STYLE aLineStyle ) override;
106
113 void SetClearCompositing( bool aClear );
114
115 virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil, double aScale, bool aMirror ) override;
116
117 // Primitive drawing operations
118 virtual void Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T aFill, int aWidth,
119 int aCornerRadius = 0 ) override;
120
121 virtual void Circle( const VECTOR2I& aCenter, int aDiameter, FILL_T aFill, int aWidth ) override;
122
123 virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle, double aRadius,
124 FILL_T aFill, int aWidth ) override;
125
126 virtual void PenTo( const VECTOR2I& aPos, char aPlume ) override;
127
128 virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth,
129 void* aData = nullptr ) override;
130
131 virtual void PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double aScaleFactor ) override;
132
133 // Flash pad operations
134 virtual void FlashPadCircle( const VECTOR2I& aPadPos, int aDiameter, void* aData ) override;
135
136 virtual void FlashPadOval( const VECTOR2I& aPadPos, const VECTOR2I& aSize, const EDA_ANGLE& aPadOrient,
137 void* aData ) override;
138
139 virtual void FlashPadRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize, const EDA_ANGLE& aPadOrient,
140 void* aData ) override;
141
142 virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize, int aCornerRadius,
143 const EDA_ANGLE& aOrient, void* aData ) override;
144
145 virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize, const EDA_ANGLE& aPadOrient,
146 SHAPE_POLY_SET* aPolygons, void* aData ) override;
147
148 virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners, const EDA_ANGLE& aPadOrient,
149 void* aData ) override;
150
151 virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
152 const EDA_ANGLE& aOrient, void* aData ) override;
153
159 bool SaveFile( const wxString& aPath );
160
161protected:
165 virtual VECTOR2D userToDeviceCoordinates( const VECTOR2I& aCoordinate ) override;
166
170 virtual VECTOR2D userToDeviceSize( const VECTOR2I& aSize ) override;
171
175 virtual double userToDeviceSize( double aSize ) const override;
176
177private:
178 void fillRect( double aX, double aY, double aWidth, double aHeight );
179 void strokeRect( double aX, double aY, double aWidth, double aHeight );
180 void fillCircle( double aCx, double aCy, double aRadius );
181 void strokeCircle( double aCx, double aCy, double aRadius );
182
183 cairo_surface_t* m_surface;
184 cairo_t* m_context;
185
186 int m_dpi;
192};
193
194#endif // PLOTTER_PNG_H
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
bool m_yaxisReversed
Definition plotter.h:704
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
bool GetYAxisReversed() const
Definition plotter_png.h:96
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:78
void SetPixelSize(int aWidth, int aHeight)
Set the output image dimensions in pixels.
Definition plotter_png.h:64
bool GetAntialias() const
Definition plotter_png.h:85
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
void SetYAxisReversed(bool aReversed)
Set whether the Y axis is reversed (Y-up vs Y-down).
Definition plotter_png.h:95
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:77
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:56
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:84
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:57
virtual void SetColor(const COLOR4D &aColor) override
int GetPixelWidth() const
Definition plotter_png.h:70
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:45
static wxString GetDefaultFileExtension()
Definition plotter_png.h:50
virtual void FlashPadCustom(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, SHAPE_POLY_SET *aPolygons, void *aData) override
virtual bool OpenFile(const wxString &aFullFilename) override
Open or create the plot file aFullFilename.
void strokeRect(double aX, double aY, double aWidth, double aHeight)
int GetPixelHeight() const
Definition plotter_png.h:71
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 PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor) override
Only PostScript plotters can plot bitmaps.
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:59
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:64
constexpr int DEFAULT_PNG_DPI
Definition plotter_png.h:28
constexpr int MIN_PNG_DPI
Definition plotter_png.h:29
constexpr int MAX_PNG_DPI
Definition plotter_png.h:30
LINE_STYLE
Dashed line types.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687
VECTOR2< double > VECTOR2D
Definition vector2d.h:686