diff --git a/common/class_plotter.cpp b/common/class_plotter.cpp index 0503cfec93..427a0941a0 100644 --- a/common/class_plotter.cpp +++ b/common/class_plotter.cpp @@ -63,7 +63,8 @@ PLOTTER::PLOTTER( ) // Temporary init to avoid not initialized vars, will be set later m_IUsPerDecimil = 1; // will be set later to the actual value iuPerDeviceUnit = 1; // will be set later to the actual value - + m_dashMarkLength_mm = 0.5; // Dashed line parameter in mm: segment + m_dashGapLength_mm = 0.25; // Dashed line parameter in mm: gap } PLOTTER::~PLOTTER() @@ -71,9 +72,7 @@ PLOTTER::~PLOTTER() // Emergency cleanup, but closing the file is // usually made in EndPlot(). if( outputFile ) - { fclose( outputFile ); - } } @@ -126,12 +125,24 @@ DPOINT PLOTTER::userToDeviceSize( const wxSize& size ) } -double PLOTTER::userToDeviceSize( double size ) +double PLOTTER::userToDeviceSize( double size ) const { return size * plotScale * iuPerDeviceUnit; } +double PLOTTER::GetDashMarkLenIU() const +{ + double mark = userToDeviceSize( m_dashMarkLength_mm*10000/25.4*m_IUsPerDecimil - GetCurrentLineWidth() ); + return ( mark < 0.0 ) ? 0.0 : mark; +} + + +double PLOTTER::GetDashGapLenIU() const +{ + return userToDeviceSize( m_dashGapLength_mm*10000/25.4*m_IUsPerDecimil + GetCurrentLineWidth() ); +} + void PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius, FILL_T fill, int width ) { diff --git a/common/common_plotPDF_functions.cpp b/common/common_plotPDF_functions.cpp index 4f76a24326..078c25b9ba 100644 --- a/common/common_plotPDF_functions.cpp +++ b/common/common_plotPDF_functions.cpp @@ -132,7 +132,8 @@ void PDF_PLOTTER::SetDash( bool dashed ) { wxASSERT( workFile ); if( dashed ) - fputs( "[200] 100 d\n", workFile ); + fprintf( workFile, "[%d %d] 0 d\n", + (int) GetDashMarkLenIU(), (int) GetDashGapLenIU() ); else fputs( "[] 0 d\n", workFile ); } diff --git a/common/common_plotPS_functions.cpp b/common/common_plotPS_functions.cpp index c1ba968f2d..244a7f52a3 100644 --- a/common/common_plotPS_functions.cpp +++ b/common/common_plotPS_functions.cpp @@ -228,7 +228,7 @@ void PSLIKE_PLOTTER::FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCor /** - * Write on a stream a string escaped for postscript/PDF + * Write on a stream a string escaped for postscript/PDF */ void PSLIKE_PLOTTER::fputsPostscriptString(FILE *fout, const wxString& txt) { @@ -469,7 +469,8 @@ void PS_PLOTTER::SetDash( bool dashed ) { wxASSERT( outputFile ); if( dashed ) - fputs( "dashedline\n", outputFile ); + fprintf( outputFile, "[%d %d] 0 setdash\n", + (int) GetDashMarkLenIU(), (int) GetDashGapLenIU() ); else fputs( "solidline\n", outputFile ); } diff --git a/common/common_plotSVG_functions.cpp b/common/common_plotSVG_functions.cpp index 5610b7cac9..e79bcd04e3 100644 --- a/common/common_plotSVG_functions.cpp +++ b/common/common_plotSVG_functions.cpp @@ -231,14 +231,8 @@ void SVG_PLOTTER::setSVGPlotStyle() fputs( "stroke-linecap:round; stroke-linejoin:round;", outputFile ); if( m_dashed ) - { - // Use a simple dash shape: a segment + a space - #define DASH_SIZE 0.3 // length in mm of a dash - double segm_len = DASH_SIZE * 10000/2.54 * m_IUsPerDecimil; - // Use a space to the same len as segment, between segments - double space_len = segm_len + pen_w; - fprintf( outputFile, "stroke-dasharray:%g,%g;", segm_len, space_len ); - } + fprintf( outputFile, "stroke-dasharray:%g,%g;", + GetDashMarkLenIU(), GetDashGapLenIU() ); fputs( "\">\n", outputFile ); diff --git a/include/plot_common.h b/include/plot_common.h index 024bc996ed..1c24afcc33 100644 --- a/include/plot_common.h +++ b/include/plot_common.h @@ -82,6 +82,10 @@ enum PlotTextMode { */ class PLOTTER { +private: + double m_dashMarkLength_mm ; ///< Dashed line parameter in mm: segment + double m_dashGapLength_mm; ///< Dashed line parameter in mm: gap + public: static const int DEFAULT_LINE_WIDTH = -1; @@ -396,7 +400,11 @@ protected: * Modifies size according to the plotter scale factors * (simple double version) */ - virtual double userToDeviceSize( double size ); + virtual double userToDeviceSize( double size ) const; + + double GetDashMarkLenIU() const; + + double GetDashGapLenIU() const; /// Plot scale - chosen by the user (even implicitly with 'fit in a4') double plotScale;