2012-09-15 12:13:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-24 14:28:12 +00:00
|
|
|
* Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-08-07 01:53:08 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-09-15 12:13:03 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Some info on basic items SVG format, used here:
|
|
|
|
* The root element of all SVG files is the <svg> element.
|
|
|
|
*
|
|
|
|
* The <g> element is used to group SVG shapes together.
|
|
|
|
* Once grouped you can transform the whole group of shapes as if it was a single shape.
|
|
|
|
* This is an advantage compared to a nested <svg> element
|
|
|
|
* which cannot be the target of transformation by itself.
|
|
|
|
*
|
|
|
|
* The <rect> element represents a rectangle.
|
|
|
|
* Using this element you can draw rectangles of various width, height,
|
|
|
|
* with different stroke (outline) and fill colors, with sharp or rounded corners etc.
|
|
|
|
*
|
|
|
|
* <svg xmlns="http://www.w3.org/2000/svg"
|
|
|
|
* xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
|
|
*
|
|
|
|
* <rect x="10" y="10" height="100" width="100"
|
|
|
|
* style="stroke:#006600; fill: #00cc00"/>
|
|
|
|
*
|
|
|
|
* </svg>
|
|
|
|
*
|
|
|
|
* The <circle> element is used to draw circles.
|
|
|
|
* <circle cx="40" cy="40" r="24" style="stroke:#006600; fill:#00cc00"/>
|
|
|
|
*
|
|
|
|
* The <ellipse> element is used to draw ellipses.
|
|
|
|
* An ellipse is a circle that does not have equal height and width.
|
|
|
|
* Its radius in the x and y directions are different, in other words.
|
|
|
|
* <ellipse cx="40" cy="40" rx="30" ry="15"
|
|
|
|
* style="stroke:#006600; fill:#00cc00"/>
|
|
|
|
*
|
|
|
|
* The <line> element is used to draw lines.
|
|
|
|
*
|
|
|
|
* <line x1="0" y1="10" x2="0" y2="100" style="stroke:#006600;"/>
|
|
|
|
* <line x1="10" y1="10" x2="100" y2="100" style="stroke:#006600;"/>
|
|
|
|
*
|
|
|
|
* The <polyline> element is used to draw multiple connected lines
|
|
|
|
* Here is a simple example:
|
|
|
|
*
|
|
|
|
* <polyline points="0,0 30,0 15,30" style="stroke:#006600;"/>
|
|
|
|
*
|
|
|
|
* The <polygon> element is used to draw with multiple (3 or more) sides / edges.
|
|
|
|
* Here is a simple example:
|
|
|
|
*
|
|
|
|
* <polygon points="0,0 50,0 25,50" style="stroke:#660000; fill:#cc3333;"/>
|
|
|
|
*
|
2012-09-18 14:50:30 +00:00
|
|
|
* The <path> element is used to draw advanced shapes combined from lines and arcs,
|
2012-09-15 12:13:03 +00:00
|
|
|
* with or without fill.
|
|
|
|
* It is probably the most advanced and versatile SVG shape of them all.
|
|
|
|
* It is probably also the hardest element to master.
|
|
|
|
* <path d="M50,50
|
|
|
|
* A30,30 0 0,1 35,20
|
|
|
|
* L100,100
|
|
|
|
* M110,110
|
|
|
|
* L100,0"
|
|
|
|
* style="stroke:#660000; fill:none;"/>
|
2012-09-18 14:50:30 +00:00
|
|
|
*
|
|
|
|
* Draw an elliptic arc: it is one of basic path command:
|
|
|
|
* <path d="M(startx,starty) A(radiusx,radiusy)
|
|
|
|
* rotation-axe-x
|
|
|
|
* flag_arc_large,flag_sweep endx,endy">
|
|
|
|
* flag_arc_large: 0 = small arc > 180 deg, 1 = large arc > 180 deg
|
|
|
|
* flag_sweep : 0 = CCW, 1 = CW
|
|
|
|
* The center of ellipse is automatically calculated.
|
2012-09-15 12:13:03 +00:00
|
|
|
*/
|
2019-12-08 16:47:04 +00:00
|
|
|
|
|
|
|
#include <base64.h>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <eda_shape.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-12-31 14:07:24 +00:00
|
|
|
#include <font/font.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2019-12-08 16:47:04 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <wx/mstream.h>
|
2013-04-27 02:12:57 +00:00
|
|
|
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotters_pslike.h>
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
// Note:
|
|
|
|
// During tests, we (JPC) found issues when the coordinates used 6 digits in mantissa
|
|
|
|
// especially for stroke-width using very small (but not null) values < 0.00001 mm
|
|
|
|
// So to avoid this king of issue, we are using 4 digits in mantissa
|
|
|
|
// The resolution (m_precision ) is 0.1 micron, that looks enougt for a SVG file
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2013-04-27 02:12:57 +00:00
|
|
|
/**
|
2021-06-07 18:31:53 +00:00
|
|
|
* Translates '<' to "<", '>' to ">" and so on, according to the spec:
|
2013-04-27 02:12:57 +00:00
|
|
|
* http://www.w3.org/TR/2000/WD-xml-c14n-20000119.html#charescaping
|
|
|
|
* May be moved to a library if needed generally, but not expecting that.
|
|
|
|
*/
|
|
|
|
static wxString XmlEsc( const wxString& aStr, bool isAttribute = false )
|
|
|
|
{
|
|
|
|
wxString escaped;
|
|
|
|
|
|
|
|
escaped.reserve( aStr.length() );
|
|
|
|
|
|
|
|
for( wxString::const_iterator it = aStr.begin(); it != aStr.end(); ++it )
|
|
|
|
{
|
|
|
|
const wxChar c = *it;
|
|
|
|
|
|
|
|
switch( c )
|
|
|
|
{
|
|
|
|
case wxS( '<' ):
|
|
|
|
escaped.append( wxS( "<" ) );
|
|
|
|
break;
|
|
|
|
case wxS( '>' ):
|
|
|
|
escaped.append( wxS( ">" ) );
|
|
|
|
break;
|
|
|
|
case wxS( '&' ):
|
|
|
|
escaped.append( wxS( "&" ) );
|
|
|
|
break;
|
|
|
|
case wxS( '\r' ):
|
|
|
|
escaped.append( wxS( "
" ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if( isAttribute )
|
|
|
|
{
|
|
|
|
switch( c )
|
|
|
|
{
|
|
|
|
case wxS( '"' ):
|
|
|
|
escaped.append( wxS( """ ) );
|
|
|
|
break;
|
|
|
|
case wxS( '\t' ):
|
|
|
|
escaped.append( wxS( "	" ) );
|
|
|
|
break;
|
|
|
|
case wxS( '\n' ):
|
|
|
|
escaped.append( wxS( "
" ));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
escaped.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2023-08-07 12:06:46 +00:00
|
|
|
{
|
2013-04-27 02:12:57 +00:00
|
|
|
escaped.append(c);
|
2023-08-07 12:06:46 +00:00
|
|
|
}
|
2013-04-27 02:12:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return escaped;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-15 12:13:03 +00:00
|
|
|
SVG_PLOTTER::SVG_PLOTTER()
|
|
|
|
{
|
|
|
|
m_graphics_changed = true;
|
2019-12-28 00:55:11 +00:00
|
|
|
SetTextMode( PLOT_TEXT_MODE::STROKE );
|
2021-07-18 23:08:54 +00:00
|
|
|
m_fillMode = FILL_T::NO_FILL; // or FILLED_SHAPE or FILLED_WITH_BG_BODYCOLOR
|
2022-01-28 17:06:47 +00:00
|
|
|
m_pen_rgb_color = 0; // current color value (black)
|
|
|
|
m_brush_rgb_color = 0; // current color value (black)
|
2022-04-08 10:35:52 +00:00
|
|
|
m_brush_alpha = 1.0;
|
2019-12-28 00:55:11 +00:00
|
|
|
m_dashed = PLOT_DASH_TYPE::SOLID;
|
2022-01-28 17:06:47 +00:00
|
|
|
m_precision = 4; // default: 4 digits in mantissa.
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void SVG_PLOTTER::SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
|
2012-09-15 12:13:03 +00:00
|
|
|
double aScale, bool aMirror )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
m_plotMirror = aMirror;
|
2013-12-06 18:31:15 +00:00
|
|
|
m_yaxisReversed = true; // unlike other plotters, SVG has Y axis reversed
|
2020-11-16 00:04:55 +00:00
|
|
|
m_plotOffset = aOffset;
|
|
|
|
m_plotScale = aScale;
|
2012-09-15 12:13:03 +00:00
|
|
|
m_IUsPerDecimil = aIusPerDecimil;
|
2020-04-20 22:02:03 +00:00
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
// Compute the paper size in IUs. for historical reasons the page size is in mils
|
2020-11-16 00:04:55 +00:00
|
|
|
m_paperSize = m_pageInfo.GetSizeMils();
|
|
|
|
m_paperSize.x *= 10.0 * aIusPerDecimil;
|
|
|
|
m_paperSize.y *= 10.0 * aIusPerDecimil;
|
2020-04-20 22:02:03 +00:00
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
// gives now a default value to iuPerDeviceUnit (because the units of the caller is now known)
|
|
|
|
double iusPerMM = m_IUsPerDecimil / 2.54 * 1000;
|
|
|
|
m_iuPerDeviceUnit = 1 / iusPerMM;
|
|
|
|
|
|
|
|
SetSvgCoordinatesFormat( 4 );
|
2020-04-20 22:02:03 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
void SVG_PLOTTER::SetSvgCoordinatesFormat( unsigned aPrecision )
|
2020-04-20 22:02:03 +00:00
|
|
|
{
|
2022-01-28 17:06:47 +00:00
|
|
|
// Only number of digits in mantissa are adjustable.
|
|
|
|
// SVG units are always mm
|
|
|
|
m_precision = aPrecision;
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void SVG_PLOTTER::setFillMode( FILL_T fill )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
|
|
|
if( m_fillMode != fill )
|
|
|
|
{
|
|
|
|
m_graphics_changed = true;
|
|
|
|
m_fillMode = fill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
void SVG_PLOTTER::setSVGPlotStyle( int aLineWidth, bool aIsGroup, const std::string& aExtraStyle )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2019-01-30 15:25:57 +00:00
|
|
|
if( aIsGroup )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "</g>\n<g ", m_outputFile );
|
2019-01-30 15:25:57 +00:00
|
|
|
|
2012-09-15 12:13:03 +00:00
|
|
|
// output the background fill color
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "style=\"fill:#%6.6lX; ", m_brush_rgb_color );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
switch( m_fillMode )
|
|
|
|
{
|
2022-04-08 10:35:52 +00:00
|
|
|
case FILL_T::NO_FILL:
|
|
|
|
fputs( "fill-opacity:0.0; ", m_outputFile );
|
|
|
|
break;
|
2022-06-28 18:06:17 +00:00
|
|
|
|
2022-04-08 10:35:52 +00:00
|
|
|
case FILL_T::FILLED_SHAPE:
|
2021-12-15 10:18:39 +00:00
|
|
|
case FILL_T::FILLED_WITH_BG_BODYCOLOR:
|
2022-04-08 10:35:52 +00:00
|
|
|
case FILL_T::FILLED_WITH_COLOR:
|
|
|
|
fprintf( m_outputFile, "fill-opacity:%.*f; ", m_precision, m_brush_alpha );
|
|
|
|
break;
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
double pen_w = userToDeviceSize( aLineWidth );
|
2020-04-23 05:59:41 +00:00
|
|
|
|
|
|
|
if( pen_w < 0.0 ) // Ensure pen width validity
|
|
|
|
pen_w = 0.0;
|
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
// Fix a strange issue found in Inkscape: aWidth < 100 nm create issues on degrouping objects
|
|
|
|
// So we use only 4 digits in mantissa for stroke-width.
|
|
|
|
// TODO: perhaps used only 3 or 4 digits in mantissa for all values in mm, because some
|
Fix various typos
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-07-03 04:20:05 +00:00
|
|
|
// issues were previously reported reported when using nm as integer units
|
2022-01-28 17:06:47 +00:00
|
|
|
|
|
|
|
fprintf( m_outputFile, "\nstroke:#%6.6lX; stroke-width:%.*f; stroke-opacity:1; \n",
|
|
|
|
m_pen_rgb_color, m_precision, pen_w );
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "stroke-linecap:round; stroke-linejoin:round;", m_outputFile );
|
2015-03-06 17:46:04 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
//set any extra attributes for non-solid lines
|
2017-11-13 03:53:27 +00:00
|
|
|
switch( m_dashed )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
case PLOT_DASH_TYPE::DASH:
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "stroke-dasharray:%.*f,%.*f;",
|
2022-06-28 18:06:17 +00:00
|
|
|
m_precision, GetDashMarkLenIU( aLineWidth ),
|
|
|
|
m_precision, GetDashGapLenIU( aLineWidth ) );
|
2017-11-13 03:53:27 +00:00
|
|
|
break;
|
2022-06-28 18:06:17 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case PLOT_DASH_TYPE::DOT:
|
2021-07-22 23:05:01 +00:00
|
|
|
fprintf( m_outputFile, "stroke-dasharray:%f,%f;",
|
2022-06-28 18:06:17 +00:00
|
|
|
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ) );
|
2017-11-13 03:53:27 +00:00
|
|
|
break;
|
2022-06-28 18:06:17 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case PLOT_DASH_TYPE::DASHDOT:
|
2021-06-07 18:31:53 +00:00
|
|
|
fprintf( m_outputFile, "stroke-dasharray:%f,%f,%f,%f;",
|
2022-06-28 18:06:17 +00:00
|
|
|
GetDashMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ),
|
|
|
|
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ) );
|
2019-12-28 00:55:11 +00:00
|
|
|
break;
|
2022-06-28 18:06:17 +00:00
|
|
|
|
2021-07-22 23:05:01 +00:00
|
|
|
case PLOT_DASH_TYPE::DASHDOTDOT:
|
|
|
|
fprintf( m_outputFile, "stroke-dasharray:%f,%f,%f,%f,%f,%f;",
|
2022-06-28 18:06:17 +00:00
|
|
|
GetDashMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ),
|
|
|
|
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ),
|
|
|
|
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ) );
|
2021-07-22 23:05:01 +00:00
|
|
|
break;
|
2022-06-28 18:06:17 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case PLOT_DASH_TYPE::DEFAULT:
|
|
|
|
case PLOT_DASH_TYPE::SOLID:
|
|
|
|
default:
|
|
|
|
//do nothing
|
2017-11-13 03:53:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-03-06 17:46:04 +00:00
|
|
|
|
2019-01-30 15:25:57 +00:00
|
|
|
if( aExtraStyle.length() )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( aExtraStyle.c_str(), m_outputFile );
|
2019-01-30 15:25:57 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "\"", m_outputFile );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2019-01-30 15:25:57 +00:00
|
|
|
if( aIsGroup )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( ">", m_outputFile );
|
2019-01-30 15:25:57 +00:00
|
|
|
m_graphics_changed = false;
|
|
|
|
}
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "\n", m_outputFile );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void SVG_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2020-05-13 16:44:21 +00:00
|
|
|
if( aWidth == DO_NOT_SET_LINE_WIDTH )
|
|
|
|
return;
|
|
|
|
else if( aWidth == USE_DEFAULT_LINE_WIDTH )
|
|
|
|
aWidth = m_renderSettings->GetDefaultPenWidth();
|
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
// Note: aWidth == 0 is fine: used for filled shapes with no outline thickness
|
|
|
|
|
|
|
|
wxASSERT_MSG( aWidth >= 0, "Plotter called to set negative pen width" );
|
2020-05-13 16:44:21 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
if( aWidth != m_currentPenWidth )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
|
|
|
m_graphics_changed = true;
|
2022-01-28 17:06:47 +00:00
|
|
|
m_currentPenWidth = aWidth;
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-27 00:58:33 +00:00
|
|
|
void SVG_PLOTTER::StartBlock( void* aData )
|
|
|
|
{
|
2023-08-07 12:06:46 +00:00
|
|
|
// We can't use <g></g> for blocks because we're already using it for graphics context, and
|
|
|
|
// our graphics context handling is lazy (ie: it leaves the last group open until the context
|
|
|
|
// changes).
|
2019-01-27 00:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SVG_PLOTTER::EndBlock( void* aData )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-08 10:35:52 +00:00
|
|
|
void SVG_PLOTTER::emitSetRGBColor( double r, double g, double b, double a )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
|
|
|
int red = (int) ( 255.0 * r );
|
|
|
|
int green = (int) ( 255.0 * g );
|
|
|
|
int blue = (int) ( 255.0 * b );
|
|
|
|
long rgb_color = (red << 16) | (green << 8) | blue;
|
|
|
|
|
|
|
|
if( m_pen_rgb_color != rgb_color )
|
|
|
|
{
|
|
|
|
m_graphics_changed = true;
|
|
|
|
m_pen_rgb_color = rgb_color;
|
|
|
|
|
2021-08-17 17:44:11 +00:00
|
|
|
// Currently, use the same color for brush and pen (i.e. to draw and fill a contour).
|
2012-09-15 12:13:03 +00:00
|
|
|
m_brush_rgb_color = rgb_color;
|
2022-04-08 10:35:52 +00:00
|
|
|
m_brush_alpha = a;
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
void SVG_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2022-06-28 18:06:17 +00:00
|
|
|
if( m_dashed != aLineStyle )
|
2015-03-06 17:46:04 +00:00
|
|
|
{
|
|
|
|
m_graphics_changed = true;
|
2022-06-28 18:06:17 +00:00
|
|
|
m_dashed = aLineStyle;
|
2015-03-06 17:46:04 +00:00
|
|
|
}
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void SVG_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int width )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2022-08-31 22:57:24 +00:00
|
|
|
BOX2I rect( p1, VECTOR2I( p2.x - p1.x, p2.y - p1.y ) );
|
2012-09-18 14:50:30 +00:00
|
|
|
rect.Normalize();
|
2022-08-31 22:57:24 +00:00
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
VECTOR2D org_dev = userToDeviceCoordinates( rect.GetOrigin() );
|
|
|
|
VECTOR2D end_dev = userToDeviceCoordinates( rect.GetEnd() );
|
|
|
|
VECTOR2D size_dev = end_dev - org_dev;
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2012-09-24 06:39:59 +00:00
|
|
|
// Ensure size of rect in device coordinates is > 0
|
2015-07-13 18:36:06 +00:00
|
|
|
// I don't know if this is a SVG issue or a Inkscape issue, but
|
|
|
|
// Inkscape has problems with negative or null values for width and/or height, so avoid them
|
2022-08-31 22:57:24 +00:00
|
|
|
BOX2D rect_dev( org_dev, size_dev );
|
2012-09-24 06:39:59 +00:00
|
|
|
rect_dev.Normalize();
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
setFillMode( fill );
|
|
|
|
SetCurrentLineWidth( width );
|
|
|
|
|
2023-08-07 12:06:46 +00:00
|
|
|
if( m_graphics_changed )
|
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
// Rectangles having a 0 size value for height or width are just not drawn on Inkscape,
|
2015-07-13 18:36:06 +00:00
|
|
|
// so use a line when happens.
|
|
|
|
if( rect_dev.GetSize().x == 0.0 || rect_dev.GetSize().y == 0.0 ) // Draw a line
|
2020-11-16 00:04:55 +00:00
|
|
|
{
|
|
|
|
fprintf( m_outputFile,
|
2022-01-28 17:06:47 +00:00
|
|
|
"<line x1=\"%.*f\" y1=\"%.*f\" x2=\"%.*f\" y2=\"%.*f\" />\n",
|
|
|
|
m_precision, rect_dev.GetPosition().x, m_precision, rect_dev.GetPosition().y,
|
|
|
|
m_precision, rect_dev.GetEnd().x, m_precision, rect_dev.GetEnd().y );
|
2020-11-16 00:04:55 +00:00
|
|
|
}
|
2015-07-13 18:36:06 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
{
|
|
|
|
fprintf( m_outputFile,
|
2020-04-23 05:59:41 +00:00
|
|
|
"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"%f\" />\n",
|
2015-07-13 18:36:06 +00:00
|
|
|
rect_dev.GetPosition().x, rect_dev.GetPosition().y,
|
|
|
|
rect_dev.GetSize().x, rect_dev.GetSize().y,
|
2020-11-16 00:04:55 +00:00
|
|
|
0.0 /* radius of rounded corners */ );
|
|
|
|
}
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void SVG_PLOTTER::Circle( const VECTOR2I& pos, int diametre, FILL_T fill, int width )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2022-08-31 22:57:24 +00:00
|
|
|
VECTOR2D pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
double radius = userToDeviceSize( diametre / 2.0 );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
setFillMode( fill );
|
|
|
|
SetCurrentLineWidth( width );
|
|
|
|
|
2023-08-07 12:06:46 +00:00
|
|
|
if( m_graphics_changed )
|
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
|
|
|
|
2018-03-09 03:44:26 +00:00
|
|
|
// If diameter is less than width, switch to filled mode
|
2021-07-18 23:08:54 +00:00
|
|
|
if( fill == FILL_T::NO_FILL && diametre < width )
|
2018-03-09 03:44:26 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
setFillMode( FILL_T::FILLED_SHAPE );
|
2018-03-09 03:44:26 +00:00
|
|
|
SetCurrentLineWidth( 0 );
|
|
|
|
|
|
|
|
radius = userToDeviceSize( ( diametre / 2.0 ) + ( width / 2.0 ) );
|
|
|
|
}
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2022-01-28 17:06:47 +00:00
|
|
|
"<circle cx=\"%.*f\" cy=\"%.*f\" r=\"%.*f\" /> \n",
|
|
|
|
m_precision, pos_dev.x, m_precision, pos_dev.y, m_precision, radius );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-06 15:39:24 +00:00
|
|
|
void SVG_PLOTTER::Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
|
|
|
|
const EDA_ANGLE& aEndAngle, double aRadius, FILL_T aFill, int aWidth )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
/* Draws an arc of a circle, centered on (xc,yc), with starting point (x1, y1) and ending
|
|
|
|
* at (x2, y2). The current pen is used for the outline and the current brush for filling
|
|
|
|
* the shape.
|
2012-09-15 12:13:03 +00:00
|
|
|
*
|
2022-01-16 01:06:25 +00:00
|
|
|
* The arc is drawn in an anticlockwise direction from the start point to the end point.
|
2012-09-15 12:13:03 +00:00
|
|
|
*/
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aRadius <= 0 )
|
2018-03-09 03:44:26 +00:00
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
Circle( aCenter, aWidth, FILL_T::FILLED_SHAPE, 0 );
|
2012-09-15 12:13:03 +00:00
|
|
|
return;
|
2018-03-09 03:44:26 +00:00
|
|
|
}
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE startAngle( aStartAngle );
|
|
|
|
EDA_ANGLE endAngle( aEndAngle );
|
|
|
|
|
2023-08-07 01:53:08 +00:00
|
|
|
while( endAngle < startAngle )
|
|
|
|
endAngle += ANGLE_360;
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
// Calculate start point.
|
2022-01-28 17:06:47 +00:00
|
|
|
VECTOR2D centre_device = userToDeviceCoordinates( aCenter );
|
|
|
|
double radius_device = userToDeviceSize( aRadius );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2013-12-06 18:31:15 +00:00
|
|
|
if( m_plotMirror )
|
|
|
|
{
|
|
|
|
if( m_mirrorIsHorizontal )
|
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
std::swap( startAngle, endAngle );
|
|
|
|
startAngle = ANGLE_180 - startAngle;
|
|
|
|
endAngle = ANGLE_180 - endAngle;
|
2013-12-06 18:31:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-16 01:06:25 +00:00
|
|
|
startAngle = -startAngle;
|
|
|
|
endAngle = -endAngle;
|
2013-12-06 18:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D start;
|
2022-01-16 01:06:25 +00:00
|
|
|
start.x = radius_device;
|
|
|
|
RotatePoint( start, startAngle );
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D end;
|
2022-01-16 01:06:25 +00:00
|
|
|
end.x = radius_device;
|
|
|
|
RotatePoint( end, endAngle );
|
|
|
|
start += centre_device;
|
|
|
|
end += centre_device;
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
double theta1 = startAngle.AsRadians();
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
if( theta1 < 0 )
|
|
|
|
theta1 = theta1 + M_PI * 2;
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
double theta2 = endAngle.AsRadians();
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
if( theta2 < 0 )
|
|
|
|
theta2 = theta2 + M_PI * 2;
|
|
|
|
|
|
|
|
if( theta2 < theta1 )
|
|
|
|
theta2 = theta2 + M_PI * 2;
|
|
|
|
|
|
|
|
int flg_arc = 0; // flag for large or small arc. 0 means less than 180 degrees
|
|
|
|
|
|
|
|
if( fabs( theta2 - theta1 ) > M_PI )
|
|
|
|
flg_arc = 1;
|
|
|
|
|
|
|
|
int flg_sweep = 0; // flag for sweep always 0
|
|
|
|
|
|
|
|
// Draw a single arc: an arc is one of 3 curve commands (2 other are 2 bezier curves)
|
|
|
|
// params are start point, radius1, radius2, X axe rotation,
|
|
|
|
// flag arc size (0 = small arc > 180 deg, 1 = large arc > 180 deg),
|
|
|
|
// sweep arc ( 0 = CCW, 1 = CW),
|
2012-09-18 14:50:30 +00:00
|
|
|
// end point
|
2022-01-16 01:06:25 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL )
|
2019-08-20 13:45:57 +00:00
|
|
|
{
|
2021-06-07 18:31:53 +00:00
|
|
|
// Filled arcs (in Eeschema) consist of the pie wedge and a stroke only on the arc
|
2019-08-20 13:45:57 +00:00
|
|
|
// This needs to be drawn in two steps.
|
2022-01-16 01:06:25 +00:00
|
|
|
setFillMode( aFill );
|
2019-08-20 13:45:57 +00:00
|
|
|
SetCurrentLineWidth( 0 );
|
|
|
|
|
2023-08-07 12:06:46 +00:00
|
|
|
if( m_graphics_changed )
|
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "<path d=\"M%.*f %.*f A%.*f %.*f 0.0 %d %d %.*f %.*f L %.*f %.*f Z\" />\n",
|
|
|
|
m_precision, start.x, m_precision, start.y,
|
|
|
|
m_precision, radius_device, m_precision, radius_device,
|
2019-08-20 13:45:57 +00:00
|
|
|
flg_arc, flg_sweep,
|
2022-01-28 17:06:47 +00:00
|
|
|
m_precision, end.x, m_precision, end.y,
|
|
|
|
m_precision, centre_device.x, m_precision, centre_device.y );
|
2019-08-20 13:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
setFillMode( FILL_T::NO_FILL );
|
2022-01-16 01:06:25 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
2023-08-07 12:06:46 +00:00
|
|
|
|
|
|
|
if( m_graphics_changed )
|
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "<path d=\"M%.*f %.*f A%.*f %.*f 0.0 %d %d %.*f %.*f\" />\n",
|
|
|
|
m_precision, start.x, m_precision, start.y,
|
|
|
|
m_precision, radius_device, m_precision, radius_device,
|
2012-09-15 12:13:03 +00:00
|
|
|
flg_arc, flg_sweep,
|
2022-01-28 17:06:47 +00:00
|
|
|
m_precision, end.x, m_precision, end.y );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void SVG_PLOTTER::BezierCurve( const VECTOR2I& aStart, const VECTOR2I& aControl1,
|
|
|
|
const VECTOR2I& aControl2, const VECTOR2I& aEnd,
|
2021-06-07 18:31:53 +00:00
|
|
|
int aTolerance, int aLineThickness )
|
2019-11-05 13:27:07 +00:00
|
|
|
{
|
|
|
|
#if 1
|
2021-07-18 23:08:54 +00:00
|
|
|
setFillMode( FILL_T::NO_FILL );
|
2019-11-05 13:27:07 +00:00
|
|
|
SetCurrentLineWidth( aLineThickness );
|
|
|
|
|
2023-08-07 12:06:46 +00:00
|
|
|
if( m_graphics_changed )
|
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
VECTOR2D start = userToDeviceCoordinates( aStart );
|
|
|
|
VECTOR2D ctrl1 = userToDeviceCoordinates( aControl1 );
|
|
|
|
VECTOR2D ctrl2 = userToDeviceCoordinates( aControl2 );
|
|
|
|
VECTOR2D end = userToDeviceCoordinates( aEnd );
|
2019-11-05 13:27:07 +00:00
|
|
|
|
|
|
|
// Generate a cubic curve: start point and 3 other control points.
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "<path d=\"M%.*f,%.*f C%.*f,%.*f %.*f,%.*f %.*f,%.*f\" />\n",
|
|
|
|
m_precision, start.x, m_precision, start.y,
|
|
|
|
m_precision, ctrl1.x, m_precision, ctrl1.y,
|
|
|
|
m_precision, ctrl2.x, m_precision, ctrl2.y,
|
|
|
|
m_precision, end.x, m_precision, end.y );
|
2019-11-05 13:27:07 +00:00
|
|
|
#else
|
2021-08-17 17:44:11 +00:00
|
|
|
PLOTTER::BezierCurve( aStart, aControl1, aControl2, aEnd, aTolerance, aLineThickness );
|
2019-11-05 13:27:07 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void SVG_PLOTTER::PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill,
|
2021-06-07 18:31:53 +00:00
|
|
|
int aWidth, void* aData )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
|
|
|
if( aCornerList.size() <= 1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
setFillMode( aFill );
|
|
|
|
SetCurrentLineWidth( aWidth );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "<path ");
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2012-09-18 14:50:30 +00:00
|
|
|
switch( aFill )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
case FILL_T::NO_FILL:
|
2022-06-28 18:06:17 +00:00
|
|
|
setSVGPlotStyle( aWidth, false, "fill:none" );
|
2014-06-24 16:17:18 +00:00
|
|
|
break;
|
2012-09-18 14:50:30 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case FILL_T::FILLED_WITH_BG_BODYCOLOR:
|
|
|
|
case FILL_T::FILLED_SHAPE:
|
|
|
|
case FILL_T::FILLED_WITH_COLOR:
|
2022-06-28 18:06:17 +00:00
|
|
|
setSVGPlotStyle( aWidth, false, "fill-rule:evenodd;" );
|
2020-04-16 17:38:52 +00:00
|
|
|
break;
|
2012-09-18 14:50:30 +00:00
|
|
|
}
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D pos = userToDeviceCoordinates( aCornerList[0] );
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "d=\"M %.*f,%.*f\n", m_precision, pos.x, m_precision, pos.y );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2019-08-20 13:45:57 +00:00
|
|
|
for( unsigned ii = 1; ii < aCornerList.size() - 1; ii++ )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
|
|
|
pos = userToDeviceCoordinates( aCornerList[ii] );
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "%.*f,%.*f\n", m_precision, pos.x, m_precision, pos.y );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
// If the corner list ends where it begins, then close the poly
|
2019-08-20 13:45:57 +00:00
|
|
|
if( aCornerList.front() == aCornerList.back() )
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "Z\" /> \n" );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2019-08-20 13:45:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = userToDeviceCoordinates( aCornerList.back() );
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "%.*f,%.*f\n\" /> \n", m_precision, pos.x, m_precision, pos.y );
|
2019-08-20 13:45:57 +00:00
|
|
|
}
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void SVG_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double aScaleFactor )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
|
2019-12-08 16:47:04 +00:00
|
|
|
|
|
|
|
// Requested size (in IUs)
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D drawsize( aScaleFactor * pix_size.x, aScaleFactor * pix_size.y );
|
2019-12-08 16:47:04 +00:00
|
|
|
|
|
|
|
// calculate the bitmap start position
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I start( aPos.x - drawsize.x / 2, aPos.y - drawsize.y / 2 );
|
2019-12-08 16:47:04 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
// Rectangles having a 0 size value for height or width are just not drawn on Inkscape,
|
2019-12-08 16:47:04 +00:00
|
|
|
// so use a line when happens.
|
|
|
|
if( drawsize.x == 0.0 || drawsize.y == 0.0 ) // Draw a line
|
|
|
|
{
|
|
|
|
PLOTTER::PlotImage( aImage, aPos, aScaleFactor );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMemoryOutputStream img_stream;
|
|
|
|
|
2023-02-23 08:50:05 +00:00
|
|
|
if( m_colorMode )
|
2023-08-07 12:06:46 +00:00
|
|
|
{
|
2023-02-23 08:50:05 +00:00
|
|
|
aImage.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
|
2023-08-07 12:06:46 +00:00
|
|
|
}
|
2023-02-23 08:50:05 +00:00
|
|
|
else // Plot in B&W
|
|
|
|
{
|
|
|
|
wxImage image = aImage.ConvertToGreyscale();
|
|
|
|
image.SaveFile( img_stream, wxBITMAP_TYPE_PNG );
|
|
|
|
}
|
2019-12-08 16:47:04 +00:00
|
|
|
size_t input_len = img_stream.GetOutputStreamBuffer()->GetBufferSize();
|
|
|
|
std::vector<uint8_t> buffer( input_len );
|
|
|
|
std::vector<uint8_t> encoded;
|
|
|
|
|
|
|
|
img_stream.CopyTo( buffer.data(), buffer.size() );
|
|
|
|
base64::encode( buffer, encoded );
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2020-04-23 05:59:41 +00:00
|
|
|
"<image x=\"%f\" y=\"%f\" xlink:href=\"data:image/png;base64,",
|
2021-06-07 18:31:53 +00:00
|
|
|
userToDeviceSize( start.x ), userToDeviceSize( start.y ) );
|
2019-12-08 16:47:04 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < encoded.size(); i++ )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "%c", static_cast<char>( encoded[i] ) );
|
2019-12-08 16:47:04 +00:00
|
|
|
|
|
|
|
if( ( i % 64 ) == 63 )
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "\n" );
|
2019-12-08 16:47:04 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "\"\npreserveAspectRatio=\"none\" width=\"%.*f\" height=\"%.*f\" />",
|
|
|
|
m_precision, userToDeviceSize( drawsize.x ), m_precision, userToDeviceSize( drawsize.y ) );
|
2019-12-08 16:47:04 +00:00
|
|
|
}
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
void SVG_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
|
|
|
if( plume == 'Z' )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
if( m_penState != 'Z' )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "\" />\n", m_outputFile );
|
|
|
|
m_penState = 'Z';
|
|
|
|
m_penLastpos.x = -1;
|
|
|
|
m_penLastpos.y = -1;
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
if( m_penState == 'Z' ) // here plume = 'D' or 'U'
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D pos_dev = userToDeviceCoordinates( pos );
|
2014-04-28 16:13:18 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
// Ensure we do not use a fill mode when moving the pen,
|
2014-04-28 16:13:18 +00:00
|
|
|
// in SVG mode (i;e. we are plotting only basic lines, not a filled area
|
2021-07-18 23:08:54 +00:00
|
|
|
if( m_fillMode != FILL_T::NO_FILL )
|
|
|
|
setFillMode( FILL_T::NO_FILL );
|
2023-08-07 12:06:46 +00:00
|
|
|
|
|
|
|
if( m_graphics_changed )
|
2022-06-28 18:06:17 +00:00
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
2014-04-28 16:13:18 +00:00
|
|
|
|
2022-06-28 18:06:17 +00:00
|
|
|
fprintf( m_outputFile, "<path d=\"M%.*f %.*f\n",
|
|
|
|
m_precision, pos_dev.x,
|
|
|
|
m_precision, pos_dev.y );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
2020-11-16 00:04:55 +00:00
|
|
|
else if( m_penState != plume || pos != m_penLastpos )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2023-08-07 12:06:46 +00:00
|
|
|
if( m_graphics_changed )
|
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
|
|
|
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D pos_dev = userToDeviceCoordinates( pos );
|
2022-06-28 18:06:17 +00:00
|
|
|
|
|
|
|
fprintf( m_outputFile, "L%.*f %.*f\n",
|
|
|
|
m_precision, pos_dev.x,
|
|
|
|
m_precision, pos_dev.y );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
m_penState = plume;
|
|
|
|
m_penLastpos = pos;
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
bool SVG_PLOTTER::StartPlot( const wxString& aPageNumber )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
static const char* header[] =
|
|
|
|
{
|
|
|
|
"<?xml version=\"1.0\" standalone=\"no\"?>\n",
|
|
|
|
" <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n",
|
|
|
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n",
|
2020-04-24 14:28:12 +00:00
|
|
|
"<svg\n"
|
|
|
|
" xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
|
|
|
|
" xmlns=\"http://www.w3.org/2000/svg\"\n",
|
|
|
|
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n",
|
|
|
|
" version=\"1.1\"\n",
|
2021-06-07 18:31:53 +00:00
|
|
|
nullptr
|
2012-09-15 12:13:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Write header.
|
2021-06-07 18:31:53 +00:00
|
|
|
for( int ii = 0; header[ii] != nullptr; ii++ )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( header[ii], m_outputFile );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write viewport pos and size
|
2022-01-28 17:06:47 +00:00
|
|
|
VECTOR2D origin; // TODO set to actual value
|
|
|
|
fprintf( m_outputFile, " width=\"%.*fmm\" height=\"%.*fmm\" viewBox=\"%.*f %.*f %.*f %.*f\">\n",
|
|
|
|
m_precision, (double) m_paperSize.x / m_IUsPerDecimil * 2.54 / 1000,
|
|
|
|
m_precision, (double) m_paperSize.y / m_IUsPerDecimil * 2.54 / 1000,
|
|
|
|
m_precision, origin.x, m_precision, origin.y,
|
|
|
|
m_precision, m_paperSize.x * m_iuPerDeviceUnit,
|
|
|
|
m_precision, m_paperSize.y * m_iuPerDeviceUnit);
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
// Write title
|
|
|
|
char date_buf[250];
|
2021-06-07 18:31:53 +00:00
|
|
|
time_t ltime = time( nullptr );
|
|
|
|
strftime( date_buf, 250, "%Y/%m/%d %H:%M:%S", localtime( <ime ) );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2022-12-13 03:42:22 +00:00
|
|
|
"<title>SVG Image created as %s date %s </title>\n",
|
2020-11-16 00:04:55 +00:00
|
|
|
TO_UTF8( XmlEsc( wxFileName( m_filename ).GetFullName() ) ), date_buf );
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2012-09-15 12:13:03 +00:00
|
|
|
// End of header
|
2022-12-13 03:42:22 +00:00
|
|
|
fprintf( m_outputFile, " <desc>Image generated by %s </desc>\n",
|
2020-11-16 00:04:55 +00:00
|
|
|
TO_UTF8( XmlEsc( m_creator ) ) );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
// output the pen and brush color (RVB values in hex) and opacity
|
|
|
|
double opacity = 1.0; // 0.0 (transparent to 1.0 (solid)
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2022-01-28 17:06:47 +00:00
|
|
|
"<g style=\"fill:#%6.6lX; fill-opacity:%.*f;stroke:#%6.6lX; stroke-opacity:%.*f;\n",
|
2022-04-08 10:35:52 +00:00
|
|
|
m_brush_rgb_color, m_precision, m_brush_alpha, m_pen_rgb_color, m_precision, opacity );
|
2012-09-20 18:58:41 +00:00
|
|
|
|
|
|
|
// output the pen cap and line joint
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "stroke-linecap:round; stroke-linejoin:round;\"\n", m_outputFile );
|
|
|
|
fputs( " transform=\"translate(0 0) scale(1 1)\">\n", m_outputFile );
|
2012-09-15 12:13:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SVG_PLOTTER::EndPlot()
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "</g> \n</svg>\n", m_outputFile );
|
|
|
|
fclose( m_outputFile );
|
2021-06-07 18:31:53 +00:00
|
|
|
m_outputFile = nullptr;
|
2012-09-15 12:13:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
void SVG_PLOTTER::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 )
|
2012-09-15 12:13:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
setFillMode( FILL_T::NO_FILL );
|
2012-09-15 12:13:03 +00:00
|
|
|
SetColor( aColor );
|
|
|
|
SetCurrentLineWidth( aWidth );
|
|
|
|
|
2023-08-07 20:43:52 +00:00
|
|
|
if( m_graphics_changed )
|
|
|
|
setSVGPlotStyle( GetCurrentLineWidth() );
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I text_pos = aPos;
|
|
|
|
const char* hjust = "start";
|
2015-08-16 21:52:42 +00:00
|
|
|
|
|
|
|
switch( aH_justify )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_CENTER: hjust = "middle"; break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: hjust = "end"; break;
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT: hjust = "start"; break;
|
2015-08-16 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( aV_justify )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_CENTER: text_pos.y += aSize.y / 2; break;
|
|
|
|
case GR_TEXT_V_ALIGN_TOP: text_pos.y += aSize.y; break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: break;
|
2015-08-16 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 19:02:50 +00:00
|
|
|
VECTOR2I text_size;
|
2021-08-17 17:44:11 +00:00
|
|
|
|
2020-01-09 17:07:37 +00:00
|
|
|
// aSize.x or aSize.y is < 0 for mirrored texts.
|
2021-06-07 18:31:53 +00:00
|
|
|
// The actual text size value is the absolute value
|
2023-08-06 19:20:53 +00:00
|
|
|
text_size.x = std::abs( GRTextWidth( aText, aFont, aSize, aWidth, aBold, aItalic, aFontMetrics ) );
|
2020-01-09 17:07:37 +00:00
|
|
|
text_size.y = std::abs( aSize.x * 4/3 ); // Hershey font height to em size conversion
|
2022-01-20 00:17:44 +00:00
|
|
|
VECTOR2D anchor_pos_dev = userToDeviceCoordinates( aPos );
|
|
|
|
VECTOR2D text_pos_dev = userToDeviceCoordinates( text_pos );
|
|
|
|
VECTOR2D sz_dev = userToDeviceSize( text_size );
|
2015-08-16 21:52:42 +00:00
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
if( !aOrient.IsZero() )
|
2021-12-28 22:13:54 +00:00
|
|
|
{
|
2023-08-16 07:42:59 +00:00
|
|
|
fprintf( m_outputFile, "<g transform=\"rotate(%f %.*f %.*f)\">\n",
|
|
|
|
m_plotMirror ? aOrient.AsDegrees() : -aOrient.AsDegrees(), m_precision,
|
|
|
|
anchor_pos_dev.x, m_precision, anchor_pos_dev.y );
|
2015-08-16 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 17:06:47 +00:00
|
|
|
fprintf( m_outputFile, "<text x=\"%.*f\" y=\"%.*f\"\n",
|
|
|
|
m_precision, text_pos_dev.x, m_precision, text_pos_dev.y );
|
2020-07-30 13:16:04 +00:00
|
|
|
|
|
|
|
/// If the text is mirrored, we should also mirror the hidden text to match
|
2023-08-16 07:42:59 +00:00
|
|
|
if( m_plotMirror != ( aSize.x < 0 ) )
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "transform=\"scale(-1 1) translate(%f 0)\"\n", -2 * text_pos_dev.x );
|
2020-07-30 13:16:04 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2022-01-28 17:06:47 +00:00
|
|
|
"textLength=\"%.*f\" font-size=\"%.*f\" lengthAdjust=\"spacingAndGlyphs\"\n"
|
2015-08-16 21:52:42 +00:00
|
|
|
"text-anchor=\"%s\" opacity=\"0\">%s</text>\n",
|
2022-01-28 17:06:47 +00:00
|
|
|
m_precision, sz_dev.x, m_precision, sz_dev.y, hjust, TO_UTF8( XmlEsc( aText ) ) );
|
2015-08-16 21:52:42 +00:00
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
if( !aOrient.IsZero() )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "</g>\n", m_outputFile );
|
2012-09-15 12:13:03 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
fprintf( m_outputFile, "<g class=\"stroked-text\"><desc>%s</desc>\n",
|
2019-06-28 21:17:46 +00:00
|
|
|
TO_UTF8( XmlEsc( aText ) ) );
|
2021-12-28 22:13:54 +00:00
|
|
|
|
2021-12-29 17:31:40 +00:00
|
|
|
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
|
2023-08-06 19:20:53 +00:00
|
|
|
aBold, aMultilineAllowed, aFont, aFontMetrics );
|
2021-12-28 22:13:54 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "</g>", m_outputFile );
|
2012-09-15 12:13:03 +00:00
|
|
|
}
|
2023-02-24 08:44:25 +00:00
|
|
|
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
void SVG_PLOTTER::PlotText( const VECTOR2I& aPos,
|
|
|
|
const COLOR4D& aColor,
|
|
|
|
const wxString& aText,
|
|
|
|
const TEXT_ATTRIBUTES& aAttributes,
|
|
|
|
KIFONT::FONT* aFont,
|
|
|
|
const KIFONT::METRICS& aFontMetrics,
|
|
|
|
void* aData )
|
2023-02-24 08:44:25 +00:00
|
|
|
{
|
|
|
|
VECTOR2I size = aAttributes.m_Size;
|
|
|
|
|
|
|
|
if( aAttributes.m_Mirrored )
|
|
|
|
size.x = -size.x;
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
SVG_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size, aAttributes.m_Halign,
|
|
|
|
aAttributes.m_Valign, aAttributes.m_StrokeWidth, aAttributes.m_Italic,
|
|
|
|
aAttributes.m_Bold, aAttributes.m_Multiline, aFont, aFontMetrics, aData );
|
2023-02-24 08:44:25 +00:00
|
|
|
}
|