Don't rely on the penWidth already being set when setting the dash style.

Fixes https://gitlab.com/kicad/code/kicad/issues/11908
This commit is contained in:
Jeff Young 2022-06-28 12:06:17 -06:00
parent 4a8aaefdc0
commit dbbdc9d2e6
17 changed files with 111 additions and 89 deletions

View File

@ -587,10 +587,12 @@ void DXF_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
}
void DXF_PLOTTER::SetDash( PLOT_DASH_TYPE aDashed )
void DXF_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
{
wxASSERT( aDashed >= PLOT_DASH_TYPE::FIRST_TYPE && aDashed <= PLOT_DASH_TYPE::LAST_TYPE );
m_currentLineType = aDashed;
wxASSERT( aLineStyle >= PLOT_DASH_TYPE::FIRST_TYPE
&& aLineStyle <= PLOT_DASH_TYPE::LAST_TYPE );
m_currentLineType = aLineStyle;
}

View File

@ -222,7 +222,7 @@ static const double PLUsPERDECIMIL = 0.1016;
HPGL_PLOTTER::HPGL_PLOTTER()
: arcTargetChordLength( 0 ),
arcMinChordDegrees( 5.0, DEGREES_T ),
dashType( PLOT_DASH_TYPE::SOLID ),
m_lineStyle( PLOT_DASH_TYPE::SOLID ),
useUserCoords( false ),
fitUserCoords( false ),
m_current_item( nullptr )
@ -542,9 +542,9 @@ void HPGL_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
}
void HPGL_PLOTTER::SetDash( PLOT_DASH_TYPE dashed )
void HPGL_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
{
dashType = dashed;
m_lineStyle = aLineStyle;
flushItem();
}
@ -854,7 +854,7 @@ bool HPGL_PLOTTER::startOrAppendItem( const VECTOR2D& location, wxString const&
item.loc_end = location;
item.bbox = BOX2D( location );
item.pen = penNumber;
item.dashType = dashType;
item.dashType = m_lineStyle;
item.content = content;
m_items.push_back( item );
m_current_item = &m_items.back();

View File

@ -176,30 +176,35 @@ void PDF_PLOTTER::emitSetRGBColor( double r, double g, double b, double a )
}
void PDF_PLOTTER::SetDash( PLOT_DASH_TYPE dashed )
void PDF_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
{
wxASSERT( workFile );
switch( dashed )
switch( aLineStyle )
{
case PLOT_DASH_TYPE::DASH:
fprintf( workFile, "[%d %d] 0 d\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DOT:
fprintf( workFile, "[%d %d] 0 d\n",
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DASHDOT:
fprintf( workFile, "[%d %d %d %d] 0 d\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DASHDOTDOT:
fprintf( workFile, "[%d %d %d %d %d %d] 0 d\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
default:
fputs( "[] 0 d\n", workFile );
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -510,29 +510,33 @@ void PS_PLOTTER::emitSetRGBColor( double r, double g, double b, double a )
}
void PS_PLOTTER::SetDash( PLOT_DASH_TYPE dashed )
void PS_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
{
switch( dashed )
switch( aLineStyle )
{
case PLOT_DASH_TYPE::DASH:
fprintf( m_outputFile, "[%d %d] 0 setdash\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DOT:
fprintf( m_outputFile, "[%d %d] 0 setdash\n",
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DASHDOT:
fprintf( m_outputFile, "[%d %d %d %d] 0 setdash\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DASHDOTDOT:
fprintf( m_outputFile, "[%d %d %d %d %d %d] 0 setdash\n",
(int) GetDashMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU(),
(int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break;
default:
fputs( "solidline\n", m_outputFile );
}

View File

@ -210,7 +210,7 @@ void SVG_PLOTTER::SetColor( const COLOR4D& color )
PSLIKE_PLOTTER::SetColor( color );
if( m_graphics_changed )
setSVGPlotStyle();
setSVGPlotStyle( GetCurrentLineWidth() );
}
@ -224,7 +224,7 @@ void SVG_PLOTTER::setFillMode( FILL_T fill )
}
void SVG_PLOTTER::setSVGPlotStyle( bool aIsGroup, const std::string& aExtraStyle )
void SVG_PLOTTER::setSVGPlotStyle( int aLineWidth, bool aIsGroup, const std::string& aExtraStyle )
{
if( aIsGroup )
fputs( "</g>\n<g ", m_outputFile );
@ -237,6 +237,7 @@ void SVG_PLOTTER::setSVGPlotStyle( bool aIsGroup, const std::string& aExtraStyle
case FILL_T::NO_FILL:
fputs( "fill-opacity:0.0; ", m_outputFile );
break;
case FILL_T::FILLED_SHAPE:
case FILL_T::FILLED_WITH_BG_BODYCOLOR:
case FILL_T::FILLED_WITH_COLOR:
@ -244,7 +245,7 @@ void SVG_PLOTTER::setSVGPlotStyle( bool aIsGroup, const std::string& aExtraStyle
break;
}
double pen_w = userToDeviceSize( GetCurrentLineWidth() );
double pen_w = userToDeviceSize( aLineWidth );
if( pen_w < 0.0 ) // Ensure pen width validity
pen_w = 0.0;
@ -263,23 +264,28 @@ void SVG_PLOTTER::setSVGPlotStyle( bool aIsGroup, const std::string& aExtraStyle
{
case PLOT_DASH_TYPE::DASH:
fprintf( m_outputFile, "stroke-dasharray:%.*f,%.*f;",
m_precision, GetDashMarkLenIU(), m_precision, GetDashGapLenIU() );
m_precision, GetDashMarkLenIU( aLineWidth ),
m_precision, GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DOT:
fprintf( m_outputFile, "stroke-dasharray:%f,%f;",
GetDotMarkLenIU(), GetDashGapLenIU() );
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DASHDOT:
fprintf( m_outputFile, "stroke-dasharray:%f,%f,%f,%f;",
GetDashMarkLenIU(), GetDashGapLenIU(),
GetDotMarkLenIU(), GetDashGapLenIU() );
GetDashMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ),
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DASHDOTDOT:
fprintf( m_outputFile, "stroke-dasharray:%f,%f,%f,%f,%f,%f;",
GetDashMarkLenIU(), GetDashGapLenIU(),
GetDotMarkLenIU(), GetDashGapLenIU(),
GetDotMarkLenIU(), GetDashGapLenIU() );
GetDashMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ),
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ),
GetDotMarkLenIU( aLineWidth ), GetDashGapLenIU( aLineWidth ) );
break;
case PLOT_DASH_TYPE::DEFAULT:
case PLOT_DASH_TYPE::SOLID:
default:
@ -288,9 +294,7 @@ void SVG_PLOTTER::setSVGPlotStyle( bool aIsGroup, const std::string& aExtraStyle
}
if( aExtraStyle.length() )
{
fputs( aExtraStyle.c_str(), m_outputFile );
}
fputs( "\"", m_outputFile );
@ -322,7 +326,7 @@ void SVG_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData )
}
if( m_graphics_changed )
setSVGPlotStyle();
setSVGPlotStyle( aWidth );
}
@ -366,16 +370,16 @@ void SVG_PLOTTER::emitSetRGBColor( double r, double g, double b, double a )
}
void SVG_PLOTTER::SetDash( PLOT_DASH_TYPE dashed )
void SVG_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
{
if( m_dashed != dashed )
if( m_dashed != aLineStyle )
{
m_graphics_changed = true;
m_dashed = dashed;
m_dashed = aLineStyle;
}
if( m_graphics_changed )
setSVGPlotStyle();
setSVGPlotStyle( aLineWidth );
}
@ -584,13 +588,13 @@ void SVG_PLOTTER::PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFi
switch( aFill )
{
case FILL_T::NO_FILL:
setSVGPlotStyle( false, "fill:none" );
setSVGPlotStyle( aWidth, false, "fill:none" );
break;
case FILL_T::FILLED_WITH_BG_BODYCOLOR:
case FILL_T::FILLED_SHAPE:
case FILL_T::FILLED_WITH_COLOR:
setSVGPlotStyle( false, "fill-rule:evenodd;" );
setSVGPlotStyle( aWidth, false, "fill-rule:evenodd;" );
break;
}
@ -686,15 +690,20 @@ void SVG_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
if( m_fillMode != FILL_T::NO_FILL )
{
setFillMode( FILL_T::NO_FILL );
setSVGPlotStyle();
setSVGPlotStyle( GetCurrentLineWidth() );
}
fprintf( m_outputFile, "<path d=\"M%.*f %.*f\n", m_precision, pos_dev.x, m_precision, pos_dev.y );
fprintf( m_outputFile, "<path d=\"M%.*f %.*f\n",
m_precision, pos_dev.x,
m_precision, pos_dev.y );
}
else if( m_penState != plume || pos != m_penLastpos )
{
VECTOR2D pos_dev = userToDeviceCoordinates( pos );
fprintf( m_outputFile, "L%.*f %.*f\n", m_precision, pos_dev.x, m_precision, pos_dev.y );
fprintf( m_outputFile, "L%.*f %.*f\n",
m_precision, pos_dev.x,
m_precision, pos_dev.y );
}
m_penState = plume;

View File

@ -129,21 +129,21 @@ double PLOTTER::userToDeviceSize( double size ) const
#define IU_PER_MILS ( m_IUsPerDecimil * 10 )
double PLOTTER::GetDotMarkLenIU() const
double PLOTTER::GetDotMarkLenIU( int aLineWidth ) const
{
return userToDeviceSize( m_renderSettings->GetDotLength( GetCurrentLineWidth() ) );
return userToDeviceSize( m_renderSettings->GetDotLength( aLineWidth ) );
}
double PLOTTER::GetDashMarkLenIU() const
double PLOTTER::GetDashMarkLenIU( int aLineWidth ) const
{
return userToDeviceSize( m_renderSettings->GetDashLength( GetCurrentLineWidth() ) );
return userToDeviceSize( m_renderSettings->GetDashLength( aLineWidth ) );
}
double PLOTTER::GetDashGapLenIU() const
double PLOTTER::GetDashGapLenIU( int aLineWidth ) const
{
return userToDeviceSize( m_renderSettings->GetGapLength( GetCurrentLineWidth() ) );
return userToDeviceSize( m_renderSettings->GetGapLength( aLineWidth ) );
}

View File

@ -219,7 +219,7 @@ void LIB_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
}
aPlotter->SetColor( color );
aPlotter->SetDash( lineStyle );
aPlotter->SetDash( penWidth, lineStyle );
switch( GetShape() )
{
@ -250,7 +250,7 @@ void LIB_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
}
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
}

View File

@ -347,9 +347,9 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf
lineStyle = PLOT_DASH_TYPE::DASH;
aPlotter->SetColor( color );
aPlotter->SetDash( lineStyle );
aPlotter->SetDash( penWidth, lineStyle );
aPlotter->Rect( start, end, FILL_T::NO_FILL, penWidth );
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
}
LIB_TEXTBOX text( *this );

View File

@ -506,11 +506,11 @@ void SCH_BUS_ENTRY_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
aPlotter->SetCurrentLineWidth( penWidth );
aPlotter->SetColor( color );
aPlotter->SetDash( GetLineStyle() );
aPlotter->SetDash( penWidth, GetLineStyle() );
aPlotter->MoveTo( m_pos );
aPlotter->FinishTo( GetEnd() );
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
}

View File

@ -881,12 +881,12 @@ void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
aPlotter->SetColor( color );
aPlotter->SetCurrentLineWidth( penWidth );
aPlotter->SetDash( GetEffectiveLineStyle() );
aPlotter->SetDash( penWidth, GetEffectiveLineStyle() );
aPlotter->MoveTo( m_start );
aPlotter->FinishTo( m_end );
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
}

View File

@ -176,7 +176,7 @@ void SCH_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground ) const
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOTES ) );
aPlotter->SetCurrentLineWidth( pen_size );
aPlotter->SetDash( GetEffectiveLineStyle() );
aPlotter->SetDash( pen_size, GetEffectiveLineStyle() );
switch( GetShape() )
{
@ -226,7 +226,7 @@ void SCH_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground ) const
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
}
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
aPlotter->SetDash( pen_size, PLOT_DASH_TYPE::SOLID );
}
}

View File

@ -355,9 +355,9 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground ) const
lineStyle = PLOT_DASH_TYPE::SOLID;
aPlotter->SetColor( color );
aPlotter->SetDash( lineStyle );
aPlotter->SetDash( penWidth, lineStyle );
aPlotter->Rect( m_start, m_end, FILL_T::NO_FILL, penWidth );
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
}
color = GetTextColor();

View File

@ -153,7 +153,7 @@ public:
virtual void SetColor( const COLOR4D& color ) = 0;
virtual void SetDash( PLOT_DASH_TYPE dashed ) = 0;
virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) = 0;
virtual void SetCreator( const wxString& aCreator ) { m_creator = aCreator; }
@ -570,11 +570,11 @@ protected:
*/
virtual double userToDeviceSize( double size ) const;
double GetDotMarkLenIU() const;
double GetDotMarkLenIU( int aLineWidth ) const;
double GetDashMarkLenIU() const;
double GetDashMarkLenIU( int aLineWidth ) const;
double GetDashGapLenIU() const;
double GetDashGapLenIU( int aLineWidth ) const;
protected: // variables used in most of plotters:
/// Plot scale - chosen by the user (even implicitly with 'fit in a4')

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
@ -70,7 +70,7 @@ public:
m_currentPenWidth = 0;
}
virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override;
/**
* The DXF exporter handles 'colors' as layers...

View File

@ -51,14 +51,14 @@ public:
*/
virtual bool StartPlot() override;
virtual bool EndPlot() override;
virtual void SetCurrentLineWidth( int width, void* aData = nullptr ) override;
virtual void SetCurrentLineWidth( int aLineWidth, void* aData = nullptr ) override;
// RS274X has no dashing, nor colors
virtual void SetDash( PLOT_DASH_TYPE dashed ) override
virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override
{
}
virtual void SetColor( const COLOR4D& color ) override {}
virtual void SetColor( const COLOR4D& aColor ) override {}
// Currently, aScale and aMirror are not used in gerber plotter
virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,

View File

@ -78,7 +78,7 @@ public:
/**
* HPGL supports dashed lines.
*/
virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override;
virtual void SetColor( const COLOR4D& color ) override {}
@ -170,15 +170,6 @@ protected:
*/
bool startOrAppendItem( const VECTOR2D& location, const wxString& content );
int penSpeed;
int penNumber;
double penDiameter;
double arcTargetChordLength;
EDA_ANGLE arcMinChordDegrees;
PLOT_DASH_TYPE dashType;
bool useUserCoords;
bool fitUserCoords;
struct HPGL_ITEM
{
HPGL_ITEM() :
@ -223,6 +214,16 @@ protected:
/// Return the plot command corresponding to a line type
static const char* lineTypeCommand( PLOT_DASH_TYPE linetype );
protected:
int penSpeed;
int penNumber;
double penDiameter;
double arcTargetChordLength;
EDA_ANGLE arcMinChordDegrees;
PLOT_DASH_TYPE m_lineStyle;
bool useUserCoords;
bool fitUserCoords;
std::list<HPGL_ITEM> m_items;
HPGL_ITEM* m_current_item;
};

View File

@ -196,7 +196,7 @@ public:
/**
* PostScript supports dashed lines.
*/
virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override;
virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
double aScale, bool aMirror ) override;
@ -299,7 +299,7 @@ public:
/**
* PDF supports dashed lines
*/
virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override;
/**
* PDF can have multiple pages, so SetPageSettings can be called
@ -448,7 +448,7 @@ public:
/**
* SVG supports dashed lines.
*/
virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override;
virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
double aScale, bool aMirror ) override;
@ -529,7 +529,8 @@ protected:
* @param aIsGroup If false, do not form a new group for the style.
* @param aExtraStyle If given, the string will be added into the style string before closing
*/
void setSVGPlotStyle( bool aIsGroup = true, const std::string& aExtraStyle = {} );
void setSVGPlotStyle( int aLineWidth, bool aIsGroup = true,
const std::string& aExtraStyle = {} );
/**
* Prepare parameters for setSVGPlotStyle()