91#include <fmt/format.h>
94#include <wx/mstream.h>
109static wxString
XmlEsc(
const wxString& aStr,
bool isAttribute =
false )
113 escaped.reserve( aStr.length() );
115 for( wxString::const_iterator it = aStr.begin(); it != aStr.end(); ++it )
117 const wxChar c = *it;
122 escaped.append( wxS(
"<" ) );
125 escaped.append( wxS(
">" ) );
128 escaped.append( wxS(
"&" ) );
131 escaped.append( wxS(
"
" ) );
139 escaped.append( wxS(
""" ) );
142 escaped.append( wxS(
"	" ) );
145 escaped.append( wxS(
"
" ));
177 double aScale,
bool aMirror )
256 fmt::print(
m_outputFile,
"\nstroke:#{:06X}; stroke-width:{:.{}f}; stroke-opacity:1; \n",
258 fmt::print(
m_outputFile,
"stroke-linecap:round; stroke-linejoin:round;" );
264 fmt::print(
m_outputFile,
"stroke-dasharray:{:.{}f},{:.{}f};",
275 fmt::print(
m_outputFile,
"stroke-dasharray:{:f},{:f},{:f},{:f};",
282 fmt::print(
m_outputFile,
"stroke-dasharray:{:f},{:f},{:f},{:f},{:f},{:f};",
296 if( aExtraStyle.length() )
319 wxASSERT_MSG( aWidth >= 0,
"Plotter called to set negative pen width" );
344 uint32_t
red = (uint32_t) ( 255.0 * r );
345 uint32_t
green = (uint32_t) ( 255.0 * g );
346 uint32_t
blue = (uint32_t) ( 255.0 * b );
347 uint32_t rgb_color = (
red << 16 ) | (
green << 8 ) |
blue;
379 VECTOR2D size_dev = end_dev - org_dev;
384 BOX2D rect_dev( org_dev, size_dev );
398 "<line x1=\"{:.{}f}\" y1=\"{:.{}f}\" x2=\"{:.{}f}\" y2=\"{:.{}f}\" />\n",
407 "<rect x=\"{:f}\" y=\"{:f}\" width=\"{:f}\" height=\"{:f}\" rx=\"{:f}\" />\n",
439 "<circle cx=\"{:.{}f}\" cy=\"{:.{}f}\" r=\"{:.{}f}\" /> \n",
462 EDA_ANGLE endAngle = startAngle - aAngle;
464 if( endAngle < startAngle )
465 std::swap( startAngle, endAngle );
475 std::swap( startAngle, endAngle );
481 startAngle = -startAngle;
482 endAngle = -endAngle;
487 start.
x = radius_device;
490 end.x = radius_device;
492 start += centre_device;
493 end += centre_device;
498 theta1 = theta1 +
M_PI * 2;
503 theta2 = theta2 +
M_PI * 2;
505 if( theta2 < theta1 )
506 theta2 = theta2 +
M_PI * 2;
510 if( fabs( theta2 - theta1 ) >
M_PI )
531 "<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 )
625 for(
unsigned ii = 1; ii < aCornerList.size() - 1; ii++ )
632 if( aCornerList.front() == aCornerList.back() )
640 "{:.{}f},{:.{}f}\n\" /> \n",
649 VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
652 VECTOR2D drawsize( aScaleFactor * pix_size.
x, aScaleFactor * pix_size.
y );
655 VECTOR2I start( aPos.
x - drawsize.
x / 2, aPos.
y - drawsize.
y / 2 );
659 if( drawsize.
x == 0.0 || drawsize.
y == 0.0 )
665 wxMemoryOutputStream img_stream;
669 aImage.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
673 wxImage
image = aImage.ConvertToGreyscale();
674 image.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
677 size_t input_len = img_stream.GetOutputStreamBuffer()->GetBufferSize();
678 std::vector<uint8_t> buffer( input_len );
679 std::vector<uint8_t> encoded;
681 img_stream.CopyTo( buffer.data(), buffer.size() );
686 "<image x=\"{:f}\" y=\"{:f}\" xlink:href=\"data:image/png;base64,", pos.
x, pos.
y );
688 for(
size_t i = 0; i < encoded.size(); i++ )
690 fmt::print(
m_outputFile,
"{}",
static_cast<char>( encoded[i] ) );
692 if( ( i % 64 ) == 63 )
697 "\"\npreserveAspectRatio=\"none\" width=\"{:.{}f}\" height=\"{:.{}f}\" />",
731 fmt::print(
m_outputFile,
"<path d=\"M{:.{}f} {:.{}f}\n",
756 std::string header =
"<?xml version=\"1.0\" standalone=\"no\"?>\n"
757 " <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n"
758 " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n"
760 " xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
761 " xmlns=\"http://www.w3.org/2000/svg\"\n"
762 " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
763 " xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n"
764 " version=\"1.1\"\n";
772 " width=\"{:.{}f}mm\" height=\"{:.{}f}mm\" viewBox=\"{:.{}f} {:.{}f} {:.{}f} {:.{}f}\">\n",
783 "<title>SVG Image created as {} date {} </title>\n",
788 fmt::print(
m_outputFile,
" <desc>Image generated by {} </desc>\n",
792 double opacity = 1.0;
794 "<g style=\"fill:#{:06X}; fill-opacity:{:.{}f};stroke:#{:06X}; stroke-opacity:{:.{}f};\n",
803 fmt::print(
m_outputFile,
"stroke-linecap:round; stroke-linejoin:round;\"\n" );
804 fmt::print(
m_outputFile,
" transform=\"translate(0 0) scale(1 1)\">\n" );
821 const wxString& aText,
829 bool aMultilineAllowed,
842 const char* hjust =
"start";
850 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
860 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
882 "<g transform=\"rotate({:f} {:.{}f} {:.{}f})\">\n",
891 "<text x=\"{:.{}f}\" y=\"{:.{}f}\"\n",
898 fmt::print(
m_outputFile,
"transform=\"scale(-1 1) translate({:f} 0)\"\n",
899 -2 * text_pos_dev.
x );
903 "textLength=\"{:.{}f}\" font-size=\"{:.{}f}\" lengthAdjust=\"spacingAndGlyphs\"\n"
904 "text-anchor=\"{}\" opacity=\"0\" stroke-opacity=\"0\">{}</text>\n",
920 "<g class=\"stroked-text\"><desc>{}</desc>\n",
924 aItalic, aBold, aMultilineAllowed, aFont, aFontMetrics );
933 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.
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 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).
virtual void BezierCurve(const VECTOR2I &aStart, const VECTOR2I &aControl1, const VECTOR2I &aControl2, const VECTOR2I &aEnd, int aTolerance, int aLineThickness)
Generic fallback: Cubic Bezier curve rendered as a polyline.
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.
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb values,...
PSLIKE_PLOTTER(const PROJECT *aProject=nullptr)
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 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 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.
uint32_t m_brush_rgb_color
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) 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 Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width) override
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth, void *aData) override
Draw a polygon ( filled or not ).
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 BezierCurve(const VECTOR2I &aStart, const VECTOR2I &aControl1, const VECTOR2I &aControl2, const VECTOR2I &aEnd, int aTolerance, int aLineThickness) override
Generic fallback: Cubic Bezier curve rendered as a polyline.
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth) override
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
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 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
@ FILLED_WITH_BG_BODYCOLOR
@ FILLED_SHAPE
Fill with object color.
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
VECTOR2< double > VECTOR2D