97#include <wx/mstream.h>
112static wxString
XmlEsc(
const wxString& aStr,
bool isAttribute =
false )
116 escaped.reserve( aStr.length() );
118 for( wxString::const_iterator it = aStr.begin(); it != aStr.end(); ++it )
120 const wxChar c = *it;
125 escaped.append( wxS(
"<" ) );
128 escaped.append( wxS(
">" ) );
131 escaped.append( wxS(
"&" ) );
134 escaped.append( wxS(
"
" ) );
142 escaped.append( wxS(
""" ) );
145 escaped.append( wxS(
"	" ) );
148 escaped.append( wxS(
"
" ));
180 double aScale,
bool aMirror )
237 case FILL_T::FILLED_SHAPE:
238 case FILL_T::FILLED_WITH_BG_BODYCOLOR:
239 case FILL_T::FILLED_WITH_COLOR:
259 fprintf(
m_outputFile,
"\nstroke:#%6.6lX; stroke-width:%.*f; stroke-opacity:1; \n",
261 fputs(
"stroke-linecap:round; stroke-linejoin:round;",
m_outputFile );
266 case LINE_STYLE::DASH:
271 case LINE_STYLE::DOT:
276 case LINE_STYLE::DASHDOT:
282 case LINE_STYLE::DASHDOTDOT:
283 fprintf(
m_outputFile,
"stroke-dasharray:%f,%f,%f,%f,%f,%f;",
289 case LINE_STYLE::DEFAULT:
290 case LINE_STYLE::SOLID:
297 if( aExtraStyle.length() )
321 wxASSERT_MSG( aWidth >= 0,
"Plotter called to set negative pen width" );
346 int red = (int) ( 255.0 * r );
347 int green = (int) ( 255.0 * g );
348 int blue = (int) ( 255.0 * b );
349 long rgb_color = (
red << 16) | (green << 8) | blue;
380 VECTOR2D size_dev = end_dev - org_dev;
385 BOX2D rect_dev( org_dev, size_dev );
399 "<line x1=\"%.*f\" y1=\"%.*f\" x2=\"%.*f\" y2=\"%.*f\" />\n",
408 "<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"%f\" />\n",
430 if( fill == FILL_T::NO_FILL && diametre < width )
439 "<circle cx=\"%.*f\" cy=\"%.*f\" r=\"%.*f\" /> \n",
458 Circle( aCenter, aWidth, FILL_T::FILLED_SHAPE, 0 );
463 EDA_ANGLE endAngle = startAngle - aAngle;
465 if( endAngle < startAngle )
466 std::swap( startAngle, endAngle );
476 std::swap( startAngle, endAngle );
482 startAngle = -startAngle;
483 endAngle = -endAngle;
488 start.
x = radius_device;
491 end.
x = radius_device;
493 start += centre_device;
494 end += centre_device;
499 theta1 = theta1 + M_PI * 2;
504 theta2 = theta2 + M_PI * 2;
506 if( theta2 < theta1 )
507 theta2 = theta2 + M_PI * 2;
511 if( fabs( theta2 - theta1 ) > M_PI )
521 if( aFill != FILL_T::NO_FILL )
531 fprintf(
m_outputFile,
"<path d=\"M%.*f %.*f A%.*f %.*f 0.0 %d %d %.*f %.*f L %.*f %.*f Z\" />\n",
551 "<path d=\"M%.*f %.*f A%.*f %.*f 0.0 %d %d %.*f %.*f\" />\n",
565 int aTolerance,
int aLineThickness )
581 "<path d=\"M%.*f,%.*f C%.*f,%.*f %.*f,%.*f %.*f,%.*f\" />\n",
597 int aWidth,
void* aData )
599 if( aCornerList.size() <= 1 )
608 case FILL_T::NO_FILL:
612 case FILL_T::FILLED_WITH_BG_BODYCOLOR:
613 case FILL_T::FILLED_SHAPE:
614 case FILL_T::FILLED_WITH_COLOR:
625 for(
unsigned ii = 1; ii < aCornerList.size() - 1; ii++ )
635 if( aCornerList.front() == aCornerList.back() )
643 "%.*f,%.*f\n\" /> \n",
652 VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
655 VECTOR2D drawsize( aScaleFactor * pix_size.
x, aScaleFactor * pix_size.
y );
658 VECTOR2I start( aPos.
x - drawsize.
x / 2, aPos.
y - drawsize.
y / 2 );
662 if( drawsize.
x == 0.0 || drawsize.
y == 0.0 )
668 wxMemoryOutputStream img_stream;
672 aImage.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
676 wxImage
image = aImage.ConvertToGreyscale();
677 image.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
680 size_t input_len = img_stream.GetOutputStreamBuffer()->GetBufferSize();
681 std::vector<uint8_t> buffer( input_len );
682 std::vector<uint8_t> encoded;
684 img_stream.CopyTo( buffer.data(), buffer.size() );
688 "<image x=\"%f\" y=\"%f\" xlink:href=\"data:image/png;base64,",
692 for(
size_t i = 0; i < encoded.size(); i++ )
694 fprintf(
m_outputFile,
"%c",
static_cast<char>( encoded[i] ) );
696 if( ( i % 64 ) == 63 )
701 "\"\npreserveAspectRatio=\"none\" width=\"%.*f\" height=\"%.*f\" />",
762 static const char* header[] =
764 "<?xml version=\"1.0\" standalone=\"no\"?>\n",
765 " <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n",
766 " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n",
768 " xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
769 " xmlns=\"http://www.w3.org/2000/svg\"\n",
770 " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n",
771 " version=\"1.1\"\n",
776 for(
int ii = 0; header[ii] !=
nullptr; ii++ )
783 fprintf(
m_outputFile,
" width=\"%.*fmm\" height=\"%.*fmm\" viewBox=\"%.*f %.*f %.*f %.*f\">\n",
792 time_t ltime = time(
nullptr );
793 strftime( date_buf, 250,
"%Y/%m/%d %H:%M:%S", localtime( <ime ) );
796 "<title>SVG Image created as %s date %s </title>\n",
802 " <desc>Image generated by %s </desc>\n",
806 double opacity = 1.0;
808 "<g style=\"fill:#%6.6lX; fill-opacity:%.*f;stroke:#%6.6lX; stroke-opacity:%.*f;\n",
817 fputs(
"stroke-linecap:round; stroke-linejoin:round;\"\n",
m_outputFile );
818 fputs(
" transform=\"translate(0 0) scale(1 1)\">\n",
m_outputFile );
835 const wxString& aText,
843 bool aMultilineAllowed,
856 const char* hjust =
"start";
864 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
874 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
882 text_size.
x =
std::abs(
GRTextWidth( aText, aFont, aSize, aWidth, aBold, aItalic, aFontMetrics ) );
895 "<g transform=\"rotate(%f %.*f %.*f)\">\n",
904 "<text x=\"%.*f\" y=\"%.*f\"\n",
912 fprintf(
m_outputFile,
"transform=\"scale(-1 1) translate(%f 0)\"\n",
913 -2 * text_pos_dev.
x );
917 "textLength=\"%.*f\" font-size=\"%.*f\" lengthAdjust=\"spacingAndGlyphs\"\n"
918 "text-anchor=\"%s\" opacity=\"0\" stroke-opacity=\"0\">%s</text>\n",
934 "<g class=\"stroked-text\"><desc>%s</desc>\n",
937 PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth,
938 aItalic, aBold, aMultilineAllowed, aFont, aFontMetrics );
947 const wxString& aText,
static wxString XmlEsc(const wxString &aStr, bool isAttribute=false)
Translates '<' to "<", '>' to ">" and so on, according to the spec: http://www.w3....
constexpr const Vec & GetPosition() const
constexpr const Vec GetEnd() const
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr const Vec & GetOrigin() const
constexpr const SizeVec & GetSize() const
FONT is an abstract base class for both outline and stroke fonts.
A color representation with 4 components: red, green, blue, alpha.
int GetDefaultPenWidth() const
const VECTOR2D & GetSizeMils() const
double GetDotMarkLenIU(int aLineWidth) const
virtual void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor)
Only PostScript plotters can plot bitmaps.
double GetDashGapLenIU(int aLineWidth) const
bool m_mirrorIsHorizontal
static const int USE_DEFAULT_LINE_WIDTH
virtual void BezierCurve(const VECTOR2I &aStart, const VECTOR2I &aControl1, const VECTOR2I &aControl2, const VECTOR2I &aEnd, int aTolerance, int aLineThickness=USE_DEFAULT_LINE_WIDTH)
Generic fallback: Cubic Bezier curve rendered as a polyline In KiCad the bezier curves have 4 control...
virtual VECTOR2D userToDeviceCoordinates(const VECTOR2I &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
virtual VECTOR2D userToDeviceSize(const VECTOR2I &size)
Modify size according to the plotter scale factors (VECTOR2I version, returns a VECTOR2D).
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
FILE * m_outputFile
Output file.
static const int DO_NOT_SET_LINE_WIDTH
RENDER_SETTINGS * m_renderSettings
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aPenWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Draw text with the plotter.
virtual int GetCurrentLineWidth() const
double GetDashMarkLenIU(int aLineWidth) const
Container for project specific data.
The PSLIKE_PLOTTER class is an intermediate class to handle common routines for engines working more ...
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb values,...
virtual void SetTextMode(PLOT_TEXT_MODE mode) override
PS and PDF fully implement native text (for the Latin-1 subset)
virtual void emitSetRGBColor(double r, double g, double b, double a) override
Initialize m_pen_rgb_color from reduced values r, g ,b ( reduced values are 0.0 to 1....
virtual void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor) override
PostScript-likes at the moment are the only plot engines supporting bitmaps.
virtual bool StartPlot(const wxString &aPageNumber) override
Create SVG file header.
virtual void EndBlock(void *aData) override
Calling this function allows one to define the end of a group of drawing items the group is started b...
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Draw a polygon ( filled or not ).
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
SVG_PLOTTER(const PROJECT *aProject=nullptr)
virtual void BezierCurve(const VECTOR2I &aStart, const VECTOR2I &aControl1, const VECTOR2I &aControl2, const VECTOR2I &aEnd, int aTolerance, int aLineThickness=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: Cubic Bezier curve rendered as a polyline In KiCad the bezier curves have 4 control...
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
Draw text with the plotter.
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
virtual void SetSvgCoordinatesFormat(unsigned aPrecision) override
Select SVG coordinate precision (number of digits needed for 1 mm ) (SVG plotter uses always metric u...
virtual bool EndPlot() override
void setSVGPlotStyle(int aLineWidth, bool aIsGroup=true, const std::string &aExtraStyle={})
Output the string which define pen and brush color, shape, transparency.
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle) override
SVG supports dashed lines.
virtual void StartBlock(void *aData) override
Calling this function allows one to define the beginning of a group of drawing items (used in SVG for...
void setFillMode(FILL_T fill)
Prepare parameters for setSVGPlotStyle()
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the current line width (in IUs) for the next plot.
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
static constexpr EDA_ANGLE ANGLE_180
int GRTextWidth(const wxString &aText, KIFONT::FONT *aFont, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS &aFontMetrics)
This file contains miscellaneous commonly used macros and functions.
void encode(const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Plotting engines similar to ps (PostScript, Gerber, svg)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
LINE_STYLE
Dashed line types.
@ GR_TEXT_H_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_INDETERMINATE
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