Iron out some issues with linestyle handling in SCH printing and plotting.

Fixes https://gitlab.com/kicad/code/kicad/issues/11498
This commit is contained in:
Jeff Young 2022-04-29 13:51:49 +01:00
parent 3589eb33f0
commit dc1e063b00
6 changed files with 91 additions and 80 deletions

View File

@ -172,9 +172,10 @@ void LIB_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
std::swap( start, end ); std::swap( start, end );
} }
int penWidth; int penWidth;
COLOR4D color; COLOR4D color = GetStroke().GetColor();
FILL_T fill = m_fill; PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle();
FILL_T fill = m_fill;
if( aBackground ) if( aBackground )
{ {
@ -199,19 +200,26 @@ void LIB_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
} }
penWidth = 0; penWidth = 0;
lineStyle = PLOT_DASH_TYPE::SOLID;
} }
else else
{ {
if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
lineStyle = PLOT_DASH_TYPE::DASH;
if( m_fill == FILL_T::FILLED_SHAPE ) if( m_fill == FILL_T::FILLED_SHAPE )
fill = m_fill; fill = m_fill;
else else
fill = FILL_T::NO_FILL; fill = FILL_T::NO_FILL;
penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() ); penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() );
color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
} }
aPlotter->SetColor( color ); aPlotter->SetColor( color );
aPlotter->SetDash( lineStyle );
switch( GetShape() ) switch( GetShape() )
{ {
@ -235,6 +243,8 @@ void LIB_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
default: default:
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); UNIMPLEMENTED_FOR( SHAPE_T_asString() );
} }
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
} }

View File

@ -276,20 +276,10 @@ void LIB_TEXT::Plot( PLOTTER* plotter, bool aBackground, const VECTOR2I& offset,
int t1 = ( aTransform.x1 != 0 ) ^ ( GetTextAngle() != ANGLE_HORIZONTAL ); int t1 = ( aTransform.x1 != 0 ) ^ ( GetTextAngle() != ANGLE_HORIZONTAL );
VECTOR2I pos = aTransform.TransformCoordinate( txtpos ) + offset; VECTOR2I pos = aTransform.TransformCoordinate( txtpos ) + offset;
// Get color COLOR4D color = GetTextColor();
COLOR4D color;
if( plotter->GetColorMode() ) if( !plotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
{ color = plotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
if( GetTextColor() != COLOR4D::UNSPECIFIED )
color = GetTextColor();
else
color = plotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
}
else
{
color = COLOR4D::BLACK;
}
RENDER_SETTINGS* settings = plotter->RenderSettings(); RENDER_SETTINGS* settings = plotter->RenderSettings();
@ -322,12 +312,12 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
const TRANSFORM& aTransform ) const TRANSFORM& aTransform )
{ {
wxDC* DC = aSettings->GetPrintDC(); wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE ); COLOR4D color = GetTextColor();
bool blackAndWhiteMode = GetGRForceBlackPenState(); bool blackAndWhiteMode = GetGRForceBlackPenState();
int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() ); int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() );
if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED ) if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
color = GetTextColor(); color = aSettings->GetLayerColor( LAYER_DEVICE );
// Calculate the text orientation, according to the symbol orientation/mirror (needed when // Calculate the text orientation, according to the symbol orientation/mirror (needed when
// draw text in schematic) // draw text in schematic)

View File

@ -193,26 +193,30 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
if( IsPrivate() ) if( IsPrivate() )
return; return;
bool forceNoFill = static_cast<bool>( aData ); bool forceNoFill = static_cast<bool>( aData );
bool blackAndWhiteMode = GetGRForceBlackPenState(); bool blackAndWhiteMode = GetGRForceBlackPenState();
int penWidth = GetEffectivePenWidth( aSettings ); int penWidth = GetEffectivePenWidth( aSettings );
COLOR4D color = GetStroke().GetColor();
PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle();
wxDC* DC = aSettings->GetPrintDC(); wxDC* DC = aSettings->GetPrintDC();
VECTOR2I pt1 = aTransform.TransformCoordinate( m_start ) + aOffset; VECTOR2I pt1 = aTransform.TransformCoordinate( m_start ) + aOffset;
VECTOR2I pt2 = aTransform.TransformCoordinate( m_end ) + aOffset; VECTOR2I pt2 = aTransform.TransformCoordinate( m_end ) + aOffset;
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
if( !forceNoFill && GetFillMode() == FILL_T::FILLED_WITH_COLOR && !blackAndWhiteMode ) if( !forceNoFill && GetFillMode() == FILL_T::FILLED_WITH_COLOR && !blackAndWhiteMode )
GRFilledRect( DC, pt1, pt2, penWidth, color, GetFillColor() ); GRFilledRect( DC, pt1, pt2, penWidth, GetFillColor(), GetFillColor() );
if( GetStroke().GetColor() != COLOR4D::UNSPECIFIED )
color = GetStroke().GetColor();
if( penWidth > 0 ) if( penWidth > 0 )
{ {
penWidth = std::max( penWidth, aSettings->GetMinPenWidth() ); penWidth = std::max( penWidth, aSettings->GetMinPenWidth() );
if( GetStroke().GetPlotStyle() <= PLOT_DASH_TYPE::FIRST_TYPE ) if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
color = aSettings->GetLayerColor( LAYER_DEVICE );
if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
lineStyle = PLOT_DASH_TYPE::DASH;
if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE )
{ {
GRRect( DC, pt1, pt2, penWidth, color ); GRRect( DC, pt1, pt2, penWidth, color );
} }
@ -222,7 +226,7 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
for( SHAPE* shape : shapes ) for( SHAPE* shape : shapes )
{ {
STROKE_PARAMS::Stroke( shape, GetStroke().GetPlotStyle(), penWidth, aSettings, STROKE_PARAMS::Stroke( shape, lineStyle, penWidth, aSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b ) [&]( const VECTOR2I& a, const VECTOR2I& b )
{ {
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color ); GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
@ -236,8 +240,10 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
LIB_TEXTBOX text( *this ); LIB_TEXTBOX text( *this );
if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED ) color = GetTextColor();
color = GetTextColor();
if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
color = aSettings->GetLayerColor( LAYER_DEVICE );
penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetMinPenWidth() ); penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetMinPenWidth() );
@ -324,34 +330,31 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf
return; return;
} }
VECTOR2I start = aTransform.TransformCoordinate( m_start ) + aOffset; VECTOR2I start = aTransform.TransformCoordinate( m_start ) + aOffset;
VECTOR2I end = aTransform.TransformCoordinate( m_end ) + aOffset; VECTOR2I end = aTransform.TransformCoordinate( m_end ) + aOffset;
int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() ); int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() );
COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ); COLOR4D color = GetStroke().GetColor();
PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle();
if( penWidth > 0 ) if( penWidth > 0 )
{ {
if( aPlotter->GetColorMode() && GetStroke().GetColor() != COLOR4D::UNSPECIFIED ) if( !aPlotter->GetColorMode() || color != COLOR4D::UNSPECIFIED )
aPlotter->SetColor( GetStroke().GetColor() ); color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
else
aPlotter->SetColor( color );
if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
lineStyle = PLOT_DASH_TYPE::DASH;
aPlotter->SetColor( color );
aPlotter->SetDash( lineStyle );
aPlotter->Rect( start, end, FILL_T::NO_FILL, penWidth ); aPlotter->Rect( start, end, FILL_T::NO_FILL, penWidth );
} }
LIB_TEXTBOX text( *this ); LIB_TEXTBOX text( *this );
if( aPlotter->GetColorMode() ) color = GetTextColor();
{
if( GetTextColor() != COLOR4D::UNSPECIFIED ) if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
color = GetTextColor(); color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
else
color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
}
else
{
color = COLOR4D::BLACK;
}
penWidth = std::max( GetEffectiveTextPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() ); penWidth = std::max( GetEffectiveTextPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() );

View File

@ -305,7 +305,7 @@ void SCH_SHAPE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
else else
color = GetStroke().GetColor(); color = GetStroke().GetColor();
if( GetStroke().GetPlotStyle() <= PLOT_DASH_TYPE::FIRST_TYPE ) if( GetEffectiveLineStyle() == PLOT_DASH_TYPE::SOLID )
{ {
switch( GetShape() ) switch( GetShape() )
{ {
@ -339,7 +339,7 @@ void SCH_SHAPE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
for( SHAPE* shape : shapes ) for( SHAPE* shape : shapes )
{ {
STROKE_PARAMS::Stroke( shape, GetStroke().GetPlotStyle(), penWidth, aSettings, STROKE_PARAMS::Stroke( shape, GetEffectiveLineStyle(), penWidth, aSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b ) [&]( const VECTOR2I& a, const VECTOR2I& b )
{ {
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color ); GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );

View File

@ -287,12 +287,12 @@ KIFONT::FONT* SCH_TEXT::GetDrawFont() const
void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
{ {
COLOR4D color = aSettings->GetLayerColor( m_layer ); COLOR4D color = GetTextColor();
bool blackAndWhiteMode = GetGRForceBlackPenState(); bool blackAndWhiteMode = GetGRForceBlackPenState();
VECTOR2I text_offset = aOffset + GetSchematicTextOffset( aSettings ); VECTOR2I text_offset = aOffset + GetSchematicTextOffset( aSettings );
if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED ) if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
color = GetTextColor(); color = aSettings->GetLayerColor( m_layer );
// Adjust text drawn in an outline font to more closely mimic the positioning of // Adjust text drawn in an outline font to more closely mimic the positioning of
// SCH_FIELD text. // SCH_FIELD text.
@ -431,13 +431,13 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const
RENDER_SETTINGS* settings = aPlotter->RenderSettings(); RENDER_SETTINGS* settings = aPlotter->RenderSettings();
SCH_CONNECTION* connection = Connection(); SCH_CONNECTION* connection = Connection();
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer; int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
COLOR4D color = settings->GetLayerColor( layer ); COLOR4D color = GetTextColor();
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() ); int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
KIFONT::FONT* font = GetDrawFont(); KIFONT::FONT* font = GetDrawFont();
VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() ); VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() );
if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED ) if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
color = GetTextColor(); color = settings->GetLayerColor( layer );
penWidth = std::max( penWidth, settings->GetMinPenWidth() ); penWidth = std::max( penWidth, settings->GetMinPenWidth() );
aPlotter->SetCurrentLineWidth( penWidth ); aPlotter->SetCurrentLineWidth( penWidth );

View File

@ -191,12 +191,13 @@ KIFONT::FONT* SCH_TEXTBOX::GetDrawFont() const
void SCH_TEXTBOX::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) void SCH_TEXTBOX::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
{ {
wxDC* DC = aSettings->GetPrintDC(); wxDC* DC = aSettings->GetPrintDC();
int penWidth = GetPenWidth(); int penWidth = GetPenWidth();
bool blackAndWhiteMode = GetGRForceBlackPenState(); bool blackAndWhiteMode = GetGRForceBlackPenState();
VECTOR2I pt1 = GetStart(); VECTOR2I pt1 = GetStart();
VECTOR2I pt2 = GetEnd(); VECTOR2I pt2 = GetEnd();
COLOR4D color; COLOR4D color = GetStroke().GetColor();
PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle();
if( GetFillMode() == FILL_T::FILLED_WITH_COLOR && !blackAndWhiteMode ) if( GetFillMode() == FILL_T::FILLED_WITH_COLOR && !blackAndWhiteMode )
GRFilledRect( DC, pt1, pt2, 0, GetFillColor(), GetFillColor() ); GRFilledRect( DC, pt1, pt2, 0, GetFillColor(), GetFillColor() );
@ -205,12 +206,13 @@ void SCH_TEXTBOX::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
{ {
penWidth = std::max( penWidth, aSettings->GetMinPenWidth() ); penWidth = std::max( penWidth, aSettings->GetMinPenWidth() );
if( GetStroke().GetColor() == COLOR4D::UNSPECIFIED ) if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
color = aSettings->GetLayerColor( m_layer ); color = aSettings->GetLayerColor( m_layer );
else
color = GetStroke().GetColor();
if( GetStroke().GetPlotStyle() <= PLOT_DASH_TYPE::FIRST_TYPE ) if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
lineStyle = PLOT_DASH_TYPE::DASH;
if( lineStyle == PLOT_DASH_TYPE::SOLID )
{ {
GRRect( DC, pt1, pt2, penWidth, color ); GRRect( DC, pt1, pt2, penWidth, color );
} }
@ -220,7 +222,7 @@ void SCH_TEXTBOX::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
for( SHAPE* shape : shapes ) for( SHAPE* shape : shapes )
{ {
STROKE_PARAMS::Stroke( shape, GetStroke().GetPlotStyle(), penWidth, aSettings, STROKE_PARAMS::Stroke( shape, lineStyle, penWidth, aSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b ) [&]( const VECTOR2I& a, const VECTOR2I& b )
{ {
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color ); GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
@ -232,10 +234,10 @@ void SCH_TEXTBOX::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
} }
} }
color = aSettings->GetLayerColor( m_layer ); color = GetTextColor();
if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED ) if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
color = GetTextColor(); color = aSettings->GetLayerColor( m_layer );
EDA_TEXT::Print( aSettings, aOffset, color ); EDA_TEXT::Print( aSettings, aOffset, color );
} }
@ -339,22 +341,28 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground ) const
RENDER_SETTINGS* settings = aPlotter->RenderSettings(); RENDER_SETTINGS* settings = aPlotter->RenderSettings();
KIFONT::FONT* font = GetDrawFont(); KIFONT::FONT* font = GetDrawFont();
int penWidth = GetPenWidth(); int penWidth = GetPenWidth();
COLOR4D color = settings->GetLayerColor( LAYER_NOTES ); COLOR4D color = GetStroke().GetColor();
PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle();
if( penWidth > 0 ) if( penWidth > 0 )
{ {
penWidth = std::max( penWidth, settings->GetMinPenWidth() ); penWidth = std::max( penWidth, settings->GetMinPenWidth() );
if( aPlotter->GetColorMode() && GetStroke().GetColor() != COLOR4D::UNSPECIFIED ) if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
aPlotter->SetColor( GetStroke().GetColor() ); color = settings->GetLayerColor( m_layer );
else
aPlotter->SetColor( color );
if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
lineStyle = PLOT_DASH_TYPE::DASH;
aPlotter->SetColor( color );
aPlotter->SetDash( lineStyle );
aPlotter->Rect( m_start, m_end, FILL_T::NO_FILL, penWidth ); aPlotter->Rect( m_start, m_end, FILL_T::NO_FILL, penWidth );
} }
if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED ) color = GetTextColor();
color = GetTextColor();
if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
color = settings->GetLayerColor( m_layer );
penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() ); penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
penWidth = std::max( penWidth, settings->GetMinPenWidth() ); penWidth = std::max( penWidth, settings->GetMinPenWidth() );