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 )
 
 
  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;" );
 
  268            fmt::print( 
m_outputFile, 
"stroke-dasharray:{:.{}f},{:.{}f};",
 
  279            fmt::print( 
m_outputFile, 
"stroke-dasharray:{:f},{:f},{:f},{:f};",
 
  286            fmt::print( 
m_outputFile, 
"stroke-dasharray:{:f},{:f},{:f},{:f},{:f},{:f};",
 
  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;
 
 
  383    VECTOR2D  size_dev = end_dev - org_dev;
 
  388    BOX2D rect_dev( org_dev, size_dev );
 
  402                    "<line x1=\"{:.{}f}\" y1=\"{:.{}f}\" x2=\"{:.{}f}\" y2=\"{:.{}f}\" />\n",
 
  411                      "<rect x=\"{:f}\" y=\"{:f}\" width=\"{:f}\" height=\"{:f}\" rx=\"{:f}\" />\n",
 
 
  443                  "<circle cx=\"{:.{}f}\" cy=\"{:.{}f}\" r=\"{:.{}f}\" /> \n",
 
 
  466    EDA_ANGLE endAngle = startAngle - aAngle;
 
  468    if( endAngle < startAngle )
 
  469        std::swap( startAngle, endAngle );
 
  479            std::swap( startAngle, endAngle );
 
  485            startAngle = -startAngle;
 
  486            endAngle = -endAngle;
 
  491    start.
x = radius_device;
 
  494    end.x = radius_device;
 
  496    start += centre_device;
 
  497    end += centre_device;
 
  502        theta1 = theta1 + 
M_PI * 2;
 
  507        theta2 = theta2 + 
M_PI * 2;
 
  509    if( theta2 < theta1 )
 
  510        theta2 = theta2 + 
M_PI * 2;
 
  514    if( fabs( theta2 - theta1 ) > 
M_PI )
 
  535                   "<path d=\"M{:.{}f} {:.{}f} A{:.{}f} {:.{}f} 0.0 {:d} {:d} {:.{}f} {:.{}f} L {:.{}f} {:.{}f} Z\" />\n",
 
  555                "<path d=\"M{:.{}f} {:.{}f} A{:.{}f} {:.{}f} 0.0 {:d} {:d} {:.{}f} {:.{}f}\" />\n",
 
 
  569                               int aTolerance, 
int aLineThickness )
 
  585                "<path d=\"M{:.{}f},{:.{}f} C{:.{}f},{:.{}f} {:.{}f},{:.{}f} {:.{}f},{:.{}f}\" />\n",
 
 
  601                            int aWidth, 
void* aData )
 
  603    if( aCornerList.size() <= 1 )
 
  629    for( 
unsigned ii = 1; ii < aCornerList.size() - 1; ii++ )
 
  636    if( aCornerList.front() == aCornerList.back() )
 
  644                    "{:.{}f},{:.{}f}\n\" /> \n",
 
 
  653    VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
 
  656    VECTOR2D drawsize( aScaleFactor * pix_size.
x, aScaleFactor * pix_size.
y );
 
  659    VECTOR2I start( aPos.
x - drawsize.
x / 2, aPos.
y - drawsize.
y / 2 );
 
  663    if( drawsize.
x == 0.0 || drawsize.
y == 0.0 )    
 
  669        wxMemoryOutputStream img_stream;
 
  673            aImage.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
 
  677            wxImage 
image = aImage.ConvertToGreyscale();
 
  678            image.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
 
  681        size_t input_len = img_stream.GetOutputStreamBuffer()->GetBufferSize();
 
  682        std::vector<uint8_t> buffer( input_len );
 
  683        std::vector<uint8_t> encoded;
 
  685        img_stream.CopyTo( buffer.data(), buffer.size() );
 
  689                    "<image x=\"{:f}\" y=\"{:f}\" xlink:href=\"data:image/png;base64,",
 
  693        for( 
size_t i = 0; i < encoded.size(); i++ )
 
  695            fmt::print( 
m_outputFile, 
"{}", 
static_cast<char>( encoded[i] ) );
 
  697            if( ( i % 64 )  == 63 )
 
  702                    "\"\npreserveAspectRatio=\"none\" width=\"{:.{}f}\" height=\"{:.{}f}\" />",
 
 
  736        fmt::print( 
m_outputFile, 
"<path d=\"M{:.{}f} {:.{}f}\n",
 
 
  761    std::string header = 
"<?xml version=\"1.0\" standalone=\"no\"?>\n" 
  762                " <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n" 
  763                " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n" 
  765                "  xmlns:svg=\"http://www.w3.org/2000/svg\"\n" 
  766                "  xmlns=\"http://www.w3.org/2000/svg\"\n" 
  767                "  xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" 
  768                "  version=\"1.1\"\n";
 
  776                "  width=\"{:.{}f}mm\" height=\"{:.{}f}mm\" viewBox=\"{:.{}f} {:.{}f} {:.{}f} {:.{}f}\">\n",
 
  787                "<title>SVG Image created as {} date {} </title>\n",
 
  792    fmt::print( 
m_outputFile, 
"  <desc>Image generated by {} </desc>\n",
 
  796    double opacity = 1.0;      
 
  798                  "<g style=\"fill:#{:06X}; fill-opacity:{:.{}f};stroke:#{:06X}; stroke-opacity:{:.{}f};\n",
 
  807    fmt::print( 
m_outputFile, 
"stroke-linecap:round; stroke-linejoin:round;\"\n" );
 
  808    fmt::print( 
m_outputFile, 
" transform=\"translate(0 0) scale(1 1)\">\n" );
 
 
  825                        const wxString&        aText,
 
  833                        bool                   aMultilineAllowed,
 
  846    const char* hjust = 
"start";
 
  854        wxFAIL_MSG( wxT( 
"Indeterminate state legal only in dialogs." ) );
 
  864        wxFAIL_MSG( wxT( 
"Indeterminate state legal only in dialogs." ) );
 
  886                         "<g transform=\"rotate({:f} {:.{}f} {:.{}f})\">\n",
 
  895                    "<text x=\"{:.{}f}\" y=\"{:.{}f}\"\n",
 
  902            fmt::print( 
m_outputFile, 
"transform=\"scale(-1 1) translate({:f} 0)\"\n",
 
  903                        -2 * text_pos_dev.
x );
 
  907                    "textLength=\"{:.{}f}\" font-size=\"{:.{}f}\" lengthAdjust=\"spacingAndGlyphs\"\n" 
  908                    "text-anchor=\"{}\" opacity=\"0\" stroke-opacity=\"0\">{}</text>\n",
 
  924                    "<g class=\"stroked-text\"><desc>{}</desc>\n",
 
  928                       aItalic, aBold, aMultilineAllowed, aFont, aFontMetrics );
 
 
  937                            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