102 #include <wx/mstream.h> 112 static 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(
"
" ));
177 double aScale,
bool aMirror )
252 fprintf(
m_outputFile,
"\nstroke:#%6.6lX; stroke-width:%f; stroke-opacity:1; \n",
254 fputs(
"stroke-linecap:round; stroke-linejoin:round;",
m_outputFile );
277 if( aExtraStyle.length() )
300 else if( aWidth == 0 )
303 wxASSERT_MSG( aWidth > 0,
"Plotter called to set negative pen width" );
318 std::string* idstr = reinterpret_cast<std::string*>( aData );
339 int red = (int) ( 255.0 *
r );
340 int green = (int) ( 255.0 * g );
341 int blue = (int) ( 255.0 * b );
342 long rgb_color = (
red << 16) | (green << 8) | blue;
370 EDA_RECT rect( p1, wxSize( p2.x -p1.x, p2.y -p1.y ) );
374 DSIZE size_dev = end_dev - org_dev;
379 DBOX rect_dev( org_dev, size_dev);
390 "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" />\n",
397 "<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"%f\" />\n",
423 "<circle cx=\"%f\" cy=\"%f\" r=\"%f\" /> \n",
424 pos_dev.
x, pos_dev.
y, radius );
445 if( StAngle > EndAngle )
446 std::swap( StAngle, EndAngle );
454 double tmp = StAngle;
463 StAngle = 1800.0 -StAngle;
464 EndAngle = 1800.0 -EndAngle;
465 std::swap( StAngle, EndAngle );
470 EndAngle = -EndAngle;
475 start.
x = radius_dev;
486 theta1 = theta1 + M_PI * 2;
491 theta2 = theta2 + M_PI * 2;
493 if( theta2 < theta1 )
494 theta2 = theta2 + M_PI * 2;
498 if( fabs( theta2 - theta1 ) > M_PI )
515 fprintf(
m_outputFile,
"<path d=\"M%f %f A%f %f 0.0 %d %d %f %f L %f %f Z\" />\n",
516 start.
x, start.
y, radius_dev, radius_dev,
518 end.
x, end.
y, centre_dev.
x, centre_dev.
y );
523 fprintf(
m_outputFile,
"<path d=\"M%f %f A%f %f 0.0 %d %d %f %f\" />\n",
524 start.
x, start.
y, radius_dev, radius_dev,
531 const wxPoint& aControl2,
const wxPoint& aEnd,
532 int aTolerance,
int aLineThickness )
544 fprintf(
m_outputFile,
"<path d=\"M%f,%f C%f,%f %f,%f %f,%f\" />\n",
545 start.
x, start.
y, ctrl1.
x, ctrl1.
y,
546 ctrl2.
x, ctrl2.
y, end.
x, end.
y );
554 int aWidth,
void* aData )
556 if( aCornerList.size() <= 1 )
575 wxFAIL_MSG(
"FILLED_WITH_COLOR not implemented" );
582 for(
unsigned ii = 1; ii < aCornerList.size() - 1; ii++ )
589 if( aCornerList.front() == aCornerList.back() )
603 wxSize pix_size( aImage.GetWidth(), aImage.GetHeight() );
606 DPOINT drawsize( aScaleFactor * pix_size.x, aScaleFactor * pix_size.y );
609 wxPoint start( aPos.x - drawsize.x / 2, aPos.y - drawsize.y / 2);
613 if( drawsize.x == 0.0 || drawsize.y == 0.0 )
619 wxMemoryOutputStream img_stream;
621 aImage.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
622 size_t input_len = img_stream.GetOutputStreamBuffer()->GetBufferSize();
623 std::vector<uint8_t> buffer( input_len );
624 std::vector<uint8_t> encoded;
626 img_stream.CopyTo( buffer.data(), buffer.size() );
630 "<image x=\"%f\" y=\"%f\" xlink:href=\"data:image/png;base64,",
633 for(
size_t i = 0; i < encoded.size(); i++ )
635 fprintf(
m_outputFile,
"%c", static_cast<char>( encoded[i] ) );
637 if( ( i % 64 ) == 63 )
641 fprintf(
m_outputFile,
"\"\npreserveAspectRatio=\"none\" width=\"%f\" height=\"%f\" />",
674 fprintf(
m_outputFile,
"<path d=\"M%d %d\n", (
int) pos_dev.
x, (
int) pos_dev.
y );
679 fprintf(
m_outputFile,
"L%d %d\n", (
int) pos_dev.
x, (
int) pos_dev.
y );
692 static const char* header[] =
694 "<?xml version=\"1.0\" standalone=\"no\"?>\n",
695 " <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n",
696 " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n",
698 " xmlns:svg=\"http://www.w3.org/2000/svg\"\n" 699 " xmlns=\"http://www.w3.org/2000/svg\"\n",
700 " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n",
701 " version=\"1.1\"\n",
706 for(
int ii = 0; header[ii] !=
nullptr; ii++ )
713 fprintf(
m_outputFile,
" width=\"%fcm\" height=\"%fcm\" viewBox=\"%d %d %d %d\">\n",
721 time_t ltime = time(
nullptr );
722 strftime( date_buf, 250,
"%Y/%m/%d %H:%M:%S", localtime( <ime ) );
725 "<title>SVG Picture created as %s date %s </title>\n",
729 fprintf(
m_outputFile,
" <desc>Picture generated by %s </desc>\n",
733 double opacity = 1.0;
735 "<g style=\"fill:#%6.6lX; fill-opacity:%f;stroke:#%6.6lX; stroke-opacity:%f;\n",
739 fputs(
"stroke-linecap:round; stroke-linejoin:round;\"\n",
m_outputFile );
740 fputs(
" transform=\"translate(0 0) scale(1 1)\">\n",
m_outputFile );
757 const wxString& aText,
765 bool aMultilineAllowed,
772 wxPoint text_pos = aPos;
773 const char *hjust =
"start";
793 text_pos.y += aSize.y / 2;
797 text_pos.y += aSize.y;
808 text_size.x = std::abs(
GraphicTextWidth( aText, aSize, aItalic, aWidth ) );
809 text_size.y = std::abs( aSize.x * 4/3 );
816 "<g transform=\"rotate(%f %f %f)\">\n",
817 - aOrient * 0.1, anchor_pos_dev.
x, anchor_pos_dev.
y );
821 "<text x=\"%f\" y=\"%f\"\n", text_pos_dev.
x, text_pos_dev.
y );
825 fprintf(
m_outputFile,
"transform=\"scale(-1 1) translate(%f 0)\"\n", -2 * text_pos_dev.
x );
828 "textLength=\"%f\" font-size=\"%f\" lengthAdjust=\"spacingAndGlyphs\"\n" 829 "text-anchor=\"%s\" opacity=\"0\">%s</text>\n",
837 "<g class=\"stroked-text\"><desc>%s</desc>\n",
839 PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify,
840 aWidth, aItalic, aBold, aMultilineAllowed );
double GetDotMarkLenIU() const
virtual void SetDash(PLOT_DASH_TYPE dashed) override
SVG supports dashed lines.
virtual void PlotImage(const wxImage &aImage, const wxPoint &aPos, double aScaleFactor) override
PostScript-likes at the moment are the only plot engines supporting bitmaps.
virtual void SetSvgCoordinatesFormat(unsigned aResolution, bool aUseInches=false) override
Select SVG step size (number of digits needed for 1 mm or 1 inch )
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
void setFillMode(FILL_T fill)
Prepare parameters for setSVGPlotStyle()
virtual void PenTo(const wxPoint &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
FILE * m_outputFile
Output file.
void setSVGPlotStyle(bool aIsGroup=true, const std::string &aExtraStyle={})
Output the string which define pen and brush color, shape, transparency.
virtual void BezierCurve(const wxPoint &aStart, const wxPoint &aControl1, const wxPoint &aControl2, const wxPoint &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...
int GraphicTextWidth(const wxString &aText, const wxSize &aSize, bool aItalic, bool aBold)
The full X size is GraphicTextWidth + the thickness of graphic lines.
void RotatePoint(int *pX, int *pY, double angle)
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
static wxString XmlEsc(const wxString &aStr, bool isAttribute=false)
Translates '<' to "<", '>' to ">" and so on, according to the spec: http://www.w3....
This file contains miscellaneous commonly used macros and functions.
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
void encode(const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput)
double GetDashGapLenIU() const
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
virtual int GetCurrentLineWidth() const
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
virtual bool EndPlot() override
const wxPoint GetEnd() const
static const int USE_DEFAULT_LINE_WIDTH
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)
const wxPoint GetOrigin() const
virtual void Arc(const wxPoint ¢re, double StAngle, double EndAngle, int rayon, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: arc rendered as a polyline.
BOX2< Vec > & Normalize()
Ensure that the height ant width are positive.
#define UNIMPLEMENTED_FOR(type)
virtual bool StartPlot() override
Create SVG file header.
RENDER_SETTINGS * m_renderSettings
const wxSize & GetSizeMils() const
virtual DPOINT userToDeviceSize(const wxSize &size)
Modify size according to the plotter scale factors (wxSize version, returns a DPOINT).
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
PLOT_DASH_TYPE
Dashed line types.
Plotting engines similar to ps (PostScript, Gerber, svg)
const Vec & GetPosition() const
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
void Normalize()
Ensures that the height ant width are positive.
virtual void PlotImage(const wxImage &aImage, const wxPoint &aPos, double aScaleFactor)
Only PostScript plotters can plot bitmaps.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the current line width (in IUs) for the next plot.
double GetDashMarkLenIU() const
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...
Handle the component boundary box.
double DECIDEG2RAD(double deg)
virtual void emitSetRGBColor(double r, double g, double b) override
Initialize m_pen_rgb_color from reduced values r, g ,b ( reduced values are 0.0 to 1....
int GetDefaultPenWidth() const
virtual void Text(const wxPoint &aPos, const COLOR4D &aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=nullptr) override
Draw text with the plotter.
virtual void Text(const wxPoint &aPos, const COLOR4D &aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=nullptr)
Draw text with the plotter.
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...
const Vec & GetSize() const
static const int DO_NOT_SET_LINE_WIDTH
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Draw a polygon ( filled or not ).
virtual void BezierCurve(const wxPoint &aStart, const wxPoint &aControl1, const wxPoint &aControl2, const wxPoint &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...
bool m_mirrorIsHorizontal
A color representation with 4 components: red, green, blue, alpha.