95#include <fmt/format.h>
98#include <wx/mstream.h>
113static wxString
XmlEsc(
const wxString& aStr,
bool isAttribute =
false )
117 escaped.reserve( aStr.length() );
119 for( wxString::const_iterator it = aStr.begin(); it != aStr.end(); ++it )
121 const wxChar c = *it;
126 escaped.append( wxS(
"<" ) );
129 escaped.append( wxS(
">" ) );
132 escaped.append( wxS(
"&" ) );
135 escaped.append( wxS(
"
" ) );
143 escaped.append( wxS(
""" ) );
146 escaped.append( wxS(
"	" ) );
149 escaped.append( wxS(
"
" ));
181 double aScale,
bool aMirror )
238 case FILL_T::FILLED_SHAPE:
239 case FILL_T::FILLED_WITH_BG_BODYCOLOR:
240 case FILL_T::FILLED_WITH_COLOR:
260 fmt::print(
m_outputFile,
"\nstroke:#{:06X}; stroke-width:{:.{}f}; stroke-opacity:1; \n",
262 fmt::print(
m_outputFile,
"stroke-linecap:round; stroke-linejoin:round;" );
267 case LINE_STYLE::DASH:
268 fmt::print(
m_outputFile,
"stroke-dasharray:{:.{}f},{:.{}f};",
273 case LINE_STYLE::DOT:
278 case LINE_STYLE::DASHDOT:
279 fmt::print(
m_outputFile,
"stroke-dasharray:{:f},{:f},{:f},{:f};",
285 case LINE_STYLE::DASHDOTDOT:
286 fmt::print(
m_outputFile,
"stroke-dasharray:{:f},{:f},{:f},{:f},{:f},{:f};",
292 case LINE_STYLE::DEFAULT:
293 case LINE_STYLE::SOLID:
300 if( aExtraStyle.length() )
323 wxASSERT_MSG( aWidth >= 0,
"Plotter called to set negative pen width" );
348 uint32_t
red = (uint32_t) ( 255.0 * r );
349 uint32_t green = (uint32_t) ( 255.0 * g );
350 uint32_t blue = (uint32_t) ( 255.0 * b );
351 uint32_t rgb_color = (
red << 16 ) | ( green << 8 ) | blue;
382 VECTOR2D size_dev = end_dev - org_dev;
387 BOX2D rect_dev( org_dev, size_dev );
401 "<line x1=\"{:.{}f}\" y1=\"{:.{}f}\" x2=\"{:.{}f}\" y2=\"{:.{}f}\" />\n",
410 "<rect x=\"{:f}\" y=\"{:f}\" width=\"{:f}\" height=\"{:f}\" rx=\"{:f}\" />\n",
432 if( fill == FILL_T::NO_FILL && diametre < width )
441 "<circle cx=\"{:.{}f}\" cy=\"{:.{}f}\" r=\"{:.{}f}\" /> \n",
459 Circle( aCenter, aWidth, FILL_T::FILLED_SHAPE, 0 );
464 EDA_ANGLE endAngle = startAngle - aAngle;
466 if( endAngle < startAngle )
467 std::swap( startAngle, endAngle );
477 std::swap( startAngle, endAngle );
483 startAngle = -startAngle;
484 endAngle = -endAngle;
489 start.
x = radius_device;
492 end.
x = radius_device;
494 start += centre_device;
495 end += centre_device;
500 theta1 = theta1 + M_PI * 2;
505 theta2 = theta2 + M_PI * 2;
507 if( theta2 < theta1 )
508 theta2 = theta2 + M_PI * 2;
512 if( fabs( theta2 - theta1 ) > M_PI )
522 if( aFill != FILL_T::NO_FILL )
533 "<path d=\"M{:.{}f} {:.{}f} A{:.{}f} {:.{}f} 0.0 {:d} {:d} {:.{}f} {:.{}f} L {:.{}f} {:.{}f} Z\" />\n",
553 "<path d=\"M{:.{}f} {:.{}f} A{:.{}f} {:.{}f} 0.0 {:d} {:d} {:.{}f} {:.{}f}\" />\n",
567 int aTolerance,
int aLineThickness )
583 "<path d=\"M{:.{}f},{:.{}f} C{:.{}f},{:.{}f} {:.{}f},{:.{}f} {:.{}f},{:.{}f}\" />\n",
599 int aWidth,
void* aData )
601 if( aCornerList.size() <= 1 )
610 case FILL_T::NO_FILL:
612 case FILL_T::REVERSE_HATCH:
613 case FILL_T::CROSS_HATCH:
617 case FILL_T::FILLED_WITH_BG_BODYCOLOR:
618 case FILL_T::FILLED_SHAPE:
619 case FILL_T::FILLED_WITH_COLOR:
627 for(
unsigned ii = 1; ii < aCornerList.size() - 1; ii++ )
634 if( aCornerList.front() == aCornerList.back() )
642 "{:.{}f},{:.{}f}\n\" /> \n",
651 VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
654 VECTOR2D drawsize( aScaleFactor * pix_size.
x, aScaleFactor * pix_size.
y );
657 VECTOR2I start( aPos.
x - drawsize.
x / 2, aPos.
y - drawsize.
y / 2 );
661 if( drawsize.
x == 0.0 || drawsize.
y == 0.0 )
667 wxMemoryOutputStream img_stream;
671 aImage.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
675 wxImage
image = aImage.ConvertToGreyscale();
676 image.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
679 size_t input_len = img_stream.GetOutputStreamBuffer()->GetBufferSize();
680 std::vector<uint8_t> buffer( input_len );
681 std::vector<uint8_t> encoded;
683 img_stream.CopyTo( buffer.data(), buffer.size() );
687 "<image x=\"{:f}\" y=\"{:f}\" xlink:href=\"data:image/png;base64,",
691 for(
size_t i = 0; i < encoded.size(); i++ )
693 fmt::print(
m_outputFile,
"{}",
static_cast<char>( encoded[i] ) );
695 if( ( i % 64 ) == 63 )
700 "\"\npreserveAspectRatio=\"none\" width=\"{:.{}f}\" height=\"{:.{}f}\" />",
734 fmt::print(
m_outputFile,
"<path d=\"M{:.{}f} {:.{}f}\n",
759 std::string header =
"<?xml version=\"1.0\" standalone=\"no\"?>\n"
760 " <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n"
761 " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n"
763 " xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
764 " xmlns=\"http://www.w3.org/2000/svg\"\n"
765 " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
766 " version=\"1.1\"\n";
774 " width=\"{:.{}f}mm\" height=\"{:.{}f}mm\" viewBox=\"{:.{}f} {:.{}f} {:.{}f} {:.{}f}\">\n",
785 "<title>SVG Image created as {} date {} </title>\n",
790 fmt::print(
m_outputFile,
" <desc>Image generated by {} </desc>\n",
794 double opacity = 1.0;
796 "<g style=\"fill:#{:06X}; fill-opacity:{:.{}f};stroke:#{:06X}; stroke-opacity:{:.{}f};\n",
805 fmt::print(
m_outputFile,
"stroke-linecap:round; stroke-linejoin:round;\"\n" );
806 fmt::print(
m_outputFile,
" transform=\"translate(0 0) scale(1 1)\">\n" );
823 const wxString& aText,
831 bool aMultilineAllowed,
844 const char* hjust =
"start";
852 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
862 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
884 "<g transform=\"rotate({:f} {:.{}f} {:.{}f})\">\n",
893 "<text x=\"{:.{}f}\" y=\"{:.{}f}\"\n",
900 fmt::print(
m_outputFile,
"transform=\"scale(-1 1) translate({:f} 0)\"\n",
901 -2 * text_pos_dev.
x );
905 "textLength=\"{:.{}f}\" font-size=\"{:.{}f}\" lengthAdjust=\"spacingAndGlyphs\"\n"
906 "text-anchor=\"{}\" opacity=\"0\" stroke-opacity=\"0\">{}</text>\n",
922 "<g class=\"stroked-text\"><desc>{}</desc>\n",
925 PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth,
926 aItalic, aBold, aMultilineAllowed, aFont, aFontMetrics );
935 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.
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.
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
uint32_t m_brush_rgb_color
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)
wxString GetISO8601CurrentDateTime()
#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_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ 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