74 constexpr int MAX_PNG_DIMENSION = 32767;
93 if( cairo_surface_status(
m_surface ) != CAIRO_STATUS_SUCCESS )
102 if( cairo_status(
m_context ) != CAIRO_STATUS_SUCCESS )
120 cairo_set_line_cap(
m_context, CAIRO_LINE_CAP_ROUND );
121 cairo_set_line_join(
m_context, CAIRO_LINE_JOIN_ROUND );
157 cairo_status_t status = cairo_surface_write_to_png(
m_surface, aPath.ToUTF8().data() );
159 return status == CAIRO_STATUS_SUCCESS;
173 cairo_set_line_width(
m_context, deviceWidth > 0 ? deviceWidth : 1.0 );
188 effective.
r = 1.0 - effective.
r;
189 effective.
g = 1.0 - effective.
g;
190 effective.
b = 1.0 - effective.
b;
200 effective =
COLOR4D( k, k, k, 1.0 );
209 cairo_set_source_rgba(
m_context, effective.
r, effective.
g, effective.
b, effective.
a );
216 cairo_set_operator(
m_context, aClear ? CAIRO_OPERATOR_CLEAR : CAIRO_OPERATOR_OVER );
227 cairo_set_dash(
m_context,
nullptr, 0, 0 );
232 double base = std::max( 1.0,
userToDeviceSize(
static_cast<double>( aLineWidth ) ) );
239 dash[0] = 4.0 * base;
240 dash[1] = 2.0 * base;
245 dash[0] = 1.0 * base;
246 dash[1] = 2.0 * base;
251 dash[0] = 4.0 * base;
252 dash[1] = 2.0 * base;
253 dash[2] = 1.0 * base;
254 dash[3] = 2.0 * base;
259 dash[0] = 4.0 * base;
260 dash[1] = 2.0 * base;
261 dash[2] = 1.0 * base;
262 dash[3] = 2.0 * base;
263 dash[4] = 1.0 * base;
264 dash[5] = 2.0 * base;
269 cairo_set_dash(
m_context,
nullptr, 0, 0 );
273 cairo_set_dash(
m_context, dash, num_dashes, 0 );
297 double x = std::min( start.
x,
end.x );
298 double y = std::min( start.
y,
end.y );
335 FILL_T aFill,
int aWidth )
343 double startRad = aStartAngle.
AsRadians();
344 double endRad = ( aStartAngle + aAngle ).AsRadians();
403 if( !
m_context || aCornerList.size() < 2 )
409 for(
size_t i = 1; i < aCornerList.size(); i++ )
433 int imgW = aImage.GetWidth();
434 int imgH = aImage.GetHeight();
436 if( imgW == 0 || imgH == 0 )
440 cairo_surface_t* imgSurface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, imgW, imgH );
442 if( cairo_surface_status( imgSurface ) != CAIRO_STATUS_SUCCESS )
444 cairo_surface_destroy( imgSurface );
448 const unsigned char* srcData = aImage.GetData();
449 const unsigned char* alphaData = aImage.HasAlpha() ? aImage.GetAlpha() :
nullptr;
450 unsigned char* dstBytes = cairo_image_surface_get_data( imgSurface );
451 int dstStride = cairo_image_surface_get_stride( imgSurface );
453 for(
int y = 0; y < imgH; y++ )
455 const unsigned char* srcRow = srcData + y * imgW * 3;
456 const unsigned char* alphaRow = alphaData ? alphaData + y * imgW :
nullptr;
457 uint32_t* dstRow =
reinterpret_cast<uint32_t*
>( dstBytes + y * dstStride );
461 for(
int x = 0; x < imgW; x++ )
463 uint32_t r = srcRow[x * 3 + 0];
464 uint32_t g = srcRow[x * 3 + 1];
465 uint32_t b = srcRow[x * 3 + 2];
466 dstRow[x] = ( 0xFFu << 24 ) | ( r << 16 ) | ( g << 8 ) | b;
471 for(
int x = 0; x < imgW; x++ )
473 uint32_t r = srcRow[x * 3 + 0];
474 uint32_t g = srcRow[x * 3 + 1];
475 uint32_t b = srcRow[x * 3 + 2];
476 uint32_t a = alphaRow[x];
480 r = ( r * a + 127 ) / 255;
481 g = ( g * a + 127 ) / 255;
482 b = ( b * a + 127 ) / 255;
485 dstRow[x] = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b;
490 cairo_surface_mark_dirty( imgSurface );
493 double drawW =
userToDeviceSize(
static_cast<double>( imgW ) * aScaleFactor );
494 double drawH =
userToDeviceSize(
static_cast<double>( imgH ) * aScaleFactor );
497 pos.
x -= drawW / 2.0;
498 pos.
y -= drawH / 2.0;
502 cairo_scale(
m_context, drawW / imgW, drawH / imgH );
503 cairo_set_source_surface(
m_context, imgSurface, 0, 0 );
507 cairo_surface_destroy( imgSurface );
521 int width = std::min( aSize.
x, aSize.
y );
522 int len = std::max( aSize.
x, aSize.
y ) - width;
532 if( aSize.
x > aSize.
y )
555 std::vector<VECTOR2I> corners;
557 int dx = aSize.
x / 2;
558 int dy = aSize.
y / 2;
560 corners.push_back(
VECTOR2I( -dx, -dy ) );
561 corners.push_back(
VECTOR2I( -dx, dy ) );
562 corners.push_back(
VECTOR2I( dx, dy ) );
563 corners.push_back(
VECTOR2I( dx, -dy ) );
585 std::vector<VECTOR2I> corners;
588 corners.push_back( poly.
CPoint( i ) );
604 std::vector<VECTOR2I> corners;
606 for(
int j = 0; j < outline.
PointCount(); j++ )
607 corners.push_back( outline.
CPoint( j ) );
617 std::vector<VECTOR2I> corners;
619 for(
int i = 0; i < 4; i++ )
624 corners.push_back( corner );
634 std::vector<VECTOR2I> corners;
635 double radius = aDiameter / 2.0;
638 for(
int i = 0; i < aCornerCount; i++ )
643 corners.push_back( corner );
689 cairo_rectangle(
m_context, aX, aY, aWidth, aHeight );
699 cairo_rectangle(
m_context, aX, aY, aWidth, aHeight );
static const COLOR4D WHITE
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
A color representation with 4 components: red, green, blue, alpha.
int GetPlotterArcHighDef() const
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
FILE * m_outputFile
Output file.
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, void *aData)
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 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.
virtual void FlashPadOval(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, void *aData) override
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)
void strokeCircle(double aCx, double aCy, double aRadius)
virtual void FlashPadCircle(const VECTOR2I &aPadPos, int aDiameter, void *aData) override
virtual void SetColor(const COLOR4D &aColor) override
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 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)
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 polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
static constexpr EDA_ANGLE ANGLE_360
@ FILLED_SHAPE
Fill with object color.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
constexpr int DEFAULT_PNG_DPI
LINE_STYLE
Dashed line types.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D