Re-implement negative-width-means-don't-stroke hack.

This commit is contained in:
Jeff Young 2020-04-21 18:12:36 +01:00
parent 1916ea868b
commit da7205ff32
6 changed files with 134 additions and 60 deletions

View File

@ -271,11 +271,12 @@ void LIB_ARC::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
auto pen_size = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
int pen_size = GetPenWidth();
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( 0, pen_size );
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetDefaultPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->Arc( pos, -t2, -t1, m_Radius, already_filled ? NO_FILL : m_Fill, pen_size );
}
@ -284,17 +285,26 @@ void LIB_ARC::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_ARC::GetPenWidth() const
{
return std::max( m_Width, 1 );
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
}
void LIB_ARC::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
if( forceNoFill && m_Fill != NO_FILL && penWidth == 0 )
return;
wxDC* DC = aSettings->GetPrintDC();
wxPoint pos1, pos2, posc;
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
COLOR4D bgColor = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
pos1 = aTransform.TransformCoordinate( m_ArcEnd ) + aOffset;
pos2 = aTransform.TransformCoordinate( m_ArcStart ) + aOffset;
@ -309,15 +319,19 @@ void LIB_ARC::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* a
std::swap( pos1.y, pos2.y );
}
FILL_T fill = aData ? NO_FILL : m_Fill;
int penSize = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
if( forceNoFill || m_Fill == NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRFilledArc( nullptr, DC, posc.x, posc.y, pt1, pt2, m_Radius, penSize, bgColor, bgColor );
else if( fill == FILLED_SHAPE && !aData )
GRFilledArc( nullptr, DC, posc.x, posc.y, pt1, pt2, m_Radius, color, color );
GRArc1( nullptr, DC, pos1.x, pos1.y, pos2.x, pos2.y, posc.x, posc.y, penWidth, color );
}
else
GRArc1( nullptr, DC, pos1.x, pos1.y, pos2.x, pos2.y, posc.x, posc.y, penSize, color );
{
if( m_Fill == FILLED_WITH_BG_BODYCOLOR )
color = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
GRFilledArc( nullptr, DC, posc.x, posc.y, pt1, pt2, m_Radius, penWidth, color, color );
}
}

View File

@ -182,10 +182,12 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
auto pen_size = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
int pen_size = GetPenWidth();
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetDefaultPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, pen_size );
}
@ -194,18 +196,27 @@ void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_BEZIER::GetPenWidth() const
{
return std::max( m_Width, 1 );
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
}
void LIB_BEZIER::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
if( forceNoFill && m_Fill != NO_FILL && penWidth == 0 )
return;
std::vector<wxPoint> PolyPointsTraslated;
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
COLOR4D bgColor = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
BEZIER_POLY converter( m_BezierPoints );
converter.GetPoly( m_PolyPoints );
@ -214,22 +225,19 @@ void LIB_BEZIER::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void
for( wxPoint& point : m_PolyPoints )
PolyPointsTraslated.push_back( aTransform.TransformCoordinate( point ) + aOffset );
FILL_T fill = aData ? NO_FILL : m_Fill;
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
if( forceNoFill || m_Fill == NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
if( fill == FILLED_WITH_BG_BODYCOLOR )
{
GRPoly( nullptr, DC, m_PolyPoints.size(), &PolyPointsTraslated[0], true, penWidth,
bgColor, bgColor );
}
else if( fill == FILLED_SHAPE )
{
GRPoly( nullptr, DC, m_PolyPoints.size(), &PolyPointsTraslated[0], true, penWidth,
GRPoly( nullptr, DC, m_PolyPoints.size(), &PolyPointsTraslated[0], false, penWidth,
color, color );
}
else
{
GRPoly( nullptr, DC, m_PolyPoints.size(), &PolyPointsTraslated[0], false, penWidth,
if( m_Fill == FILLED_WITH_BG_BODYCOLOR )
color = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
GRPoly( nullptr, DC, m_PolyPoints.size(), &PolyPointsTraslated[0], true, penWidth,
color, color );
}
}

View File

@ -174,11 +174,12 @@ void LIB_CIRCLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
auto pen_size = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
int pen_size = GetPenWidth();
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( 0, pen_size );
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetDefaultPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->Circle( pos, GetRadius() * 2, already_filled ? NO_FILL : m_Fill, pen_size );
}
@ -187,26 +188,40 @@ void LIB_CIRCLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_CIRCLE::GetPenWidth() const
{
return std::max( m_Width, 1 );
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
}
void LIB_CIRCLE::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
if( forceNoFill && m_Fill != NO_FILL && penWidth == 0 )
return;
wxDC* DC = aSettings->GetPrintDC();
wxPoint pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
COLOR4D bgColor = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
FILL_T fill = aData ? NO_FILL : m_Fill;
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRFilledCircle( nullptr, DC, pos1.x, pos1.y, GetRadius(), penWidth, bgColor, bgColor );
else if( fill == FILLED_SHAPE )
GRFilledCircle( nullptr, DC, pos1.x, pos1.y, GetRadius(), 0, color, color );
else
if( forceNoFill || m_Fill == NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
GRCircle( nullptr, DC, pos1.x, pos1.y, GetRadius(), penWidth, color );
}
else
{
if( m_Fill == FILLED_WITH_BG_BODYCOLOR )
color = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
GRFilledCircle( nullptr, DC, pos1.x, pos1.y, GetRadius(), 0, color, color );
}
}

View File

@ -141,10 +141,12 @@ void LIB_POLYLINE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
auto pen_size = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
int pen_size = GetPenWidth();
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetDefaultPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->PlotPoly( cornerList, already_filled ? NO_FILL : m_Fill, pen_size );
}
@ -185,30 +187,43 @@ void LIB_POLYLINE::RemoveCorner( int aIdx )
int LIB_POLYLINE::GetPenWidth() const
{
return std::max( m_Width, 1 );
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
}
void LIB_POLYLINE::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
if( forceNoFill && m_Fill != NO_FILL && penWidth == 0 )
return;
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
COLOR4D bgColor = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
wxPoint* buffer = new wxPoint[ m_PolyPoints.size() ];
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
buffer[ii] = aTransform.TransformCoordinate( m_PolyPoints[ii] ) + aOffset;
FILL_T fill = aData ? NO_FILL : m_Fill;
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
if( forceNoFill || m_Fill == NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRPoly( nullptr, DC, m_PolyPoints.size(), buffer, true, penWidth, bgColor, bgColor );
else if( fill == FILLED_SHAPE )
GRPoly( nullptr, DC, m_PolyPoints.size(), buffer, true, penWidth, color, color );
else
GRPoly( nullptr, DC, m_PolyPoints.size(), buffer, false, penWidth, color, color );
}
else
{
if( m_Fill == FILLED_WITH_BG_BODYCOLOR )
color = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
GRPoly( nullptr, DC, m_PolyPoints.size(), buffer, true, penWidth, color, color );
}
delete[] buffer;
}

View File

@ -140,10 +140,12 @@ void LIB_RECTANGLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
auto pen_size = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
int pen_size = GetPenWidth();
if( !already_filled || pen_size > 0 )
{
pen_size = std::max( pen_size, aPlotter->RenderSettings()->GetDefaultPenWidth() );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
aPlotter->Rect( pos, end, already_filled ? NO_FILL : m_Fill, pen_size );
}
@ -152,28 +154,40 @@ void LIB_RECTANGLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
int LIB_RECTANGLE::GetPenWidth() const
{
return std::max( m_Width, 1 );
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
if( m_Width < 0 && GetFillMode() != NO_FILL )
return 0;
else
return std::max( m_Width, 1 );
}
void LIB_RECTANGLE::print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform )
{
bool forceNoFill = static_cast<bool>( aData );
int penWidth = GetPenWidth();
if( forceNoFill && m_Fill != NO_FILL && penWidth == 0 )
return;
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
COLOR4D bgColor = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
wxPoint pt1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
wxPoint pt2 = aTransform.TransformCoordinate( m_End ) + aOffset;
FILL_T fill = aData ? NO_FILL : m_Fill;
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
if( fill == FILLED_WITH_BG_BODYCOLOR && !aData )
GRFilledRect( nullptr, DC, pt1.x, pt1.y, pt2.x, pt2.y, penWidth, bgColor, bgColor );
else if( m_Fill == FILLED_SHAPE && !aData )
GRFilledRect( nullptr, DC, pt1.x, pt1.y, pt2.x, pt2.y, penWidth, color, color );
else
if( forceNoFill || m_Fill == NO_FILL )
{
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
GRRect( nullptr, DC, pt1.x, pt1.y, pt2.x, pt2.y, penWidth, color );
}
else
{
if( m_Fill == FILLED_WITH_BG_BODYCOLOR )
color = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
GRFilledRect( nullptr, DC, pt1.x, pt1.y, pt2.x, pt2.y, penWidth, color, color );
}
}

View File

@ -459,9 +459,17 @@ bool SCH_PAINTER::setDeviceColors( const LIB_ITEM* aItem, int aLayer )
case LAYER_DEVICE:
m_gal->SetIsFill( aItem->GetFillMode() == FILLED_SHAPE );
m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( getLineWidth( aItem, false ) );
m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
if( aItem->GetPenWidth() > 0 || aItem->GetFillMode() == NO_FILL )
{
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( getLineWidth( aItem, false ) );
m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
}
else
{
m_gal->SetIsStroke( false );
}
return true;