7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 19:15:11 +00:00

Rationalize penWidth processing as first step in removing some globals.

This commit is contained in:
Jeff Young 2020-04-13 20:55:27 +01:00
parent d014dc47ab
commit 6e800bddae
53 changed files with 261 additions and 425 deletions

View File

@ -93,11 +93,13 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const TEXTE_PCB* aText,
s_boardItem = (const BOARD_ITEM *) &aText;
s_dstcontainer = aDstContainer;
s_textWidth = aText->GetThickness() + ( 2 * aClearanceValue );
s_textWidth = aText->GetEffectiveTextPenWidth( nullptr ) + ( 2 * aClearanceValue );
s_biuTo3Dunits = m_biuTo3Dunits;
// not actually used, but needed by GRText
const COLOR4D dummy_color = COLOR4D::BLACK;
bool forceBold = true;
int penWidth = 0; // force max width for bold
if( aText->IsMultilineAllowed() )
{
@ -111,16 +113,16 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const TEXTE_PCB* aText,
{
wxString txt = strings_list.Item( ii );
GRText( NULL, positions[ii], dummy_color, txt, aText->GetTextAngle(), size,
aText->GetHorizJustify(), aText->GetVertJustify(), aText->GetThickness(),
aText->IsItalic(), true, addTextSegmToContainer );
GRText( nullptr, positions[ii], dummy_color, txt, aText->GetTextAngle(), size,
aText->GetHorizJustify(), aText->GetVertJustify(), penWidth, aText->IsItalic(),
penWidth, addTextSegmToContainer );
}
}
else
{
GRText( NULL, aText->GetTextPos(), dummy_color, aText->GetShownText(),
GRText( nullptr, aText->GetTextPos(), dummy_color, aText->GetShownText(),
aText->GetTextAngle(), size, aText->GetHorizJustify(), aText->GetVertJustify(),
aText->GetThickness(), aText->IsItalic(), true, addTextSegmToContainer );
penWidth, aText->IsItalic(), penWidth, addTextSegmToContainer );
}
}
@ -215,15 +217,17 @@ void BOARD_ADAPTER::AddGraphicsShapesWithClearanceToContainer( const MODULE* aMo
for( TEXTE_MODULE* text : texts )
{
s_textWidth = text->GetThickness() + ( 2 * aInflateValue );
s_textWidth = text->GetEffectiveTextPenWidth( nullptr ) + ( 2 * aInflateValue );
wxSize size = text->GetTextSize();
bool forceBold = true;
int penWidth = 0; // force max width for bold
if( text->IsMirrored() )
size.x = -size.x;
GRText( NULL, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(),
size, text->GetHorizJustify(), text->GetVertJustify(), text->GetThickness(),
text->IsItalic(), true, addTextSegmToContainer );
size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
forceBold, addTextSegmToContainer );
}
}

View File

@ -141,6 +141,23 @@ void EDA_TEXT::SwapEffects( EDA_TEXT& aTradingPartner )
}
int EDA_TEXT::GetEffectiveTextPenWidth( RENDER_SETTINGS* aSettings ) const
{
int width = GetTextPenWidth();
if( width == 0 && IsBold() )
width = GetPenSizeForBold( GetTextWidth() );
if( width <= 0 && aSettings )
width = aSettings->GetDefaultPenWidth();
// Clip pen size for small texts:
width = Clamp_Text_PenSize( width, GetTextSize(), IsBold() );
return width;
}
bool EDA_TEXT::Replace( wxFindReplaceData& aSearchData )
{
return EDA_ITEM::Replace( aSearchData, m_text );
@ -181,14 +198,15 @@ int EDA_TEXT::GetInterline() const
}
EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY, int aMarkupFlags ) const
EDA_RECT EDA_TEXT::GetTextBox( RENDER_SETTINGS* aSettings, int aLine, bool aInvertY ) const
{
EDA_RECT rect;
wxArrayString strings;
wxString text = GetShownText();
int thickness = ( aThickness < 0 ) ? GetThickness() : aThickness;
int thickness = GetEffectiveTextPenWidth( aSettings );
int linecount = 1;
bool hasOverBar = false; // true if the first line of text as an overbar
int markupFlags = aSettings ? aSettings->GetTextMarkupFlags() : 0;
if( IsMultilineAllowed() )
{
@ -220,7 +238,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY, int aMa
const auto& font = basic_gal.GetStrokeFont();
VECTOR2D size( GetTextSize() );
double penWidth( thickness );
int dx = KiROUND( font.ComputeStringBoundaryLimits( text, size, penWidth, aMarkupFlags ).x );
int dx = KiROUND( font.ComputeStringBoundaryLimits( text, size, penWidth, markupFlags ).x );
int dy = GetInterline();
// Creates bounding box (rectangle) for an horizontal
@ -258,7 +276,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY, int aMa
for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
{
text = strings.Item( ii );
dx = KiROUND( font.ComputeStringBoundaryLimits( text, size, penWidth, aMarkupFlags ).x );
dx = KiROUND( font.ComputeStringBoundaryLimits( text, size, penWidth, markupFlags ).x );
textsize.x = std::max( textsize.x, dx );
textsize.y += dy;
}
@ -335,7 +353,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY, int aMa
bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
{
EDA_RECT rect = GetTextBox( -1 ); // Get the full text area.
EDA_RECT rect = GetTextBox( nullptr ); // JEY TODO: requires RENDER_SETTINGS
wxPoint location = aPoint;
rect.Inflate( aAccuracy );
@ -352,9 +370,9 @@ bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy
rect.Inflate( aAccuracy );
if( aContains )
return rect.Contains( GetTextBox( -1 ) );
return rect.Contains( GetTextBox( nullptr ) ); // JEY TODO: requires RENDER_SETTINGS
return rect.Intersects( GetTextBox( -1 ), GetTextAngle() );
return rect.Intersects( GetTextBox( nullptr ), GetTextAngle() ); // JEY TODO: requires RENDER_SETTINGS
}
@ -427,7 +445,7 @@ void EDA_TEXT::printOneLineOfText( wxDC* aDC, const wxPoint& aOffset, COLOR4D aC
EDA_DRAW_MODE_T aFillMode, const wxString& aText,
const wxPoint &aPos )
{
int width = GetThickness();
int width = GetEffectiveTextPenWidth( nullptr );
if( aFillMode == SKETCH )
width = -width;
@ -469,7 +487,7 @@ bool EDA_TEXT::IsDefaultFormatting() const
&& !IsMirrored()
&& GetHorizJustify() == GR_TEXT_HJUSTIFY_CENTER
&& GetVertJustify() == GR_TEXT_VJUSTIFY_CENTER
&& GetThickness() == 0
&& GetTextPenWidth() == 0
&& !IsItalic()
&& !IsBold()
&& !IsMultilineAllowed()
@ -492,8 +510,8 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
FormatInternalUnits( GetTextHeight() ).c_str(),
FormatInternalUnits( GetTextWidth() ).c_str() );
if( GetThickness() )
aFormatter->Print( 0, " (thickness %s)", FormatInternalUnits( GetThickness() ).c_str() );
if( GetTextPenWidth() )
aFormatter->Print( 0, " (thickness %s)", FormatInternalUnits( GetTextPenWidth() ).c_str() );
if( IsBold() )
aFormatter->Print( 0, " bold" );
@ -548,6 +566,9 @@ void EDA_TEXT::TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuf
if( IsMirrored() )
size.x = -size.x;
bool forceBold = true;
int penWidth = 0; // use max-width for bold text
COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
if( IsMultilineAllowed() )
@ -562,14 +583,14 @@ void EDA_TEXT::TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuf
{
wxString txt = strings_list.Item( ii );
GRText( NULL, positions[ii], color, txt, GetTextAngle(), size, GetHorizJustify(),
GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToBuffer,
GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
&aCornerBuffer );
}
}
else
{
GRText( NULL, GetTextPos(), color, GetText(), GetTextAngle(), size, GetHorizJustify(),
GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToBuffer,
GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
&aCornerBuffer );
}
}

View File

@ -220,9 +220,7 @@ void GRHaloText( wxDC * aDC, const wxPoint &aPos, const COLOR4D aBgColor, COLOR4
* @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
* @param aH_justify = horizontal justification (Left, center, right)
* @param aV_justify = vertical justification (bottom, center, top)
* @param aWidth = line width (pen width) (default = 0)
* if width < 0 : draw segments in sketch mode, width = abs(width)
* Use a value min(aSize.x, aSize.y) / 5 for a bold text
* @param aPenWidth = line width (if = 0, use plot default line width)
* @param aItalic = true to simulate an italic font
* @param aBold = true to use a bold font Useful only with default width value (aWidth = 0)
* @param aMultilineAllowed = true to plot text as multiline, otherwise single line
@ -236,29 +234,14 @@ void PLOTTER::Text( const wxPoint& aPos,
const wxSize& aSize,
enum EDA_TEXT_HJUSTIFY_T aH_justify,
enum EDA_TEXT_VJUSTIFY_T aV_justify,
int aWidth,
int aPenWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
void* aData )
{
int textPensize = aWidth;
if( textPensize == 0 && aBold ) // Use default values if aWidth == 0
textPensize = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );
if( textPensize >= 0 )
textPensize = Clamp_Text_PenSize( aWidth, aSize, aBold );
else
textPensize = -Clamp_Text_PenSize( -aWidth, aSize, aBold );
SetCurrentLineWidth( textPensize, aData );
SetColor( aColor );
GRText( NULL, aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, textPensize,
GRText( NULL, aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aPenWidth,
aItalic, aBold, nullptr, nullptr, this );
if( aWidth != textPensize )
SetCurrentLineWidth( aWidth, aData );
}

View File

@ -714,7 +714,7 @@ void WS_DATA_ITEM_TEXT::SetConstrainedTextSize()
dummy.SetVertJustify( m_Vjustify );
dummy.SetTextAngle( m_Orient * 10 );
EDA_RECT rect = dummy.GetTextBox();
EDA_RECT rect = dummy.GetTextBox( nullptr ); // JEY TODO: requires RENDER_SETTINGS
DSIZE size;
size.x = rect.GetWidth() / FSCALE;
size.y = rect.GetHeight() / FSCALE;

View File

@ -163,7 +163,7 @@ void WS_DRAW_ITEM_TEXT::PrintWsItem( wxDC* aDC, const wxPoint& aOffset, COLOR4D
const EDA_RECT WS_DRAW_ITEM_TEXT::GetBoundingBox() const
{
return EDA_TEXT::GetTextBox( -1 );
return EDA_TEXT::GetTextBox( nullptr ); // JEY TODO: requires RENDER_SETTINGS
}

View File

@ -289,7 +289,7 @@ void KIGFX::WS_PAINTER::draw( const WS_DRAW_ITEM_TEXT* aItem, int aLayer ) const
m_gal->Translate( position );
m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
m_gal->SetLineWidth( aItem->GetThickness() );
m_gal->SetLineWidth( aItem->GetEffectiveTextPenWidth( nullptr ) ); // JEY TODO: requires RENDER_SETTINGS
m_gal->SetTextAttributes( aItem );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );

View File

@ -34,7 +34,6 @@ RENDER_SETTINGS::RENDER_SETTINGS()
// Set the default initial values
m_highlightFactor = 0.5f;
m_selectFactor = 0.5f;
m_layerOpacity = 0.8f;
m_highlightItems = false;
m_highlightEnabled = false;
m_hiContrastEnabled = false;
@ -42,6 +41,8 @@ RENDER_SETTINGS::RENDER_SETTINGS()
m_highlightNetcode = -1;
m_outlineWidth = 1;
m_worksheetLineWidth = 100000;
m_defaultPenWidth = 0;
m_textMarkupFlags = 0;
m_showPageLimits = false;
}

View File

@ -116,8 +116,8 @@ void PlotWorkSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK
plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(),
text->GetTextAngle(), text->GetTextSize(),
text->GetHorizJustify(), text->GetVertJustify(),
text->GetPenWidth(), text->IsItalic(), text->IsBold(),
text->IsMultilineAllowed() );
text->GetEffectiveTextPenWidth( nullptr ),
text->IsItalic(), text->IsBold(), text->IsMultilineAllowed() );
}
break;

View File

@ -460,12 +460,12 @@ bool DIALOG_LABEL_EDITOR::TransferDataFromWindow()
if( ( style & 2 ) )
{
m_CurrentText->SetBold( true );
m_CurrentText->SetThickness( GetPenSizeForBold( m_CurrentText->GetTextWidth() ) );
m_CurrentText->SetTextPenWidth( GetPenSizeForBold( m_CurrentText->GetTextWidth() ) );
}
else
{
m_CurrentText->SetBold( false );
m_CurrentText->SetThickness( 0 );
m_CurrentText->SetTextPenWidth( 0 ); // Use default pen width
}
m_Parent->RefreshItem( m_CurrentText );

View File

@ -234,7 +234,7 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType )
newtext->SetShape( aText->GetShape() );
newtext->SetLabelSpinStyle( orientation );
newtext->SetTextSize( aText->GetTextSize() );
newtext->SetThickness( aText->GetThickness() );
newtext->SetTextPenWidth( aText->GetTextPenWidth() );
newtext->SetItalic( aText->IsItalic() );
newtext->SetBold( aText->IsBold() );
newtext->SetIsDangling( aText->IsDangling() );

View File

@ -101,15 +101,7 @@ void LIB_FIELD::Init( int id )
int LIB_FIELD::GetPenSize() const
{
int pensize = GetThickness();
if( pensize == 0 && IsBold() )
pensize = GetPenSizeForBold( GetTextWidth() );
// Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() );
return pensize;
return GetEffectiveTextPenWidth( nullptr ); // JEY TODO: requires RENDER_SETTINGS
}
@ -325,7 +317,7 @@ const EDA_RECT LIB_FIELD::GetBoundingBox() const
/* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
* calling GetTextBox() that works using top to bottom Y axis orientation.
*/
EDA_RECT rect = GetTextBox( -1, -1, true, GetTextMarkupFlags() );
EDA_RECT rect = GetTextBox( nullptr, -1, true ); // JEY TODO: requires RENDER_SETTINGS
rect.RevertYAxis();
// We are using now a bottom to top Y axis.

View File

@ -190,8 +190,8 @@ public:
void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const TRANSFORM& aTransform ) override;
int GetWidth() const override { return GetThickness(); }
void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
int GetWidth() const override { return GetTextPenWidth(); }
void SetWidth( int aWidth ) override { SetTextPenWidth( aWidth ); }
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;

View File

@ -143,7 +143,7 @@ void LIB_TEXT::MoveTo( const wxPoint& newPosition )
void LIB_TEXT::NormalizeJustification( bool inverse )
{
wxPoint delta( 0, 0 );
EDA_RECT bbox = GetTextBox( -1 );
EDA_RECT bbox = GetTextBox( nullptr ); // JEY TODO: requires RENDER_SETTINGS
if( GetTextAngle() == 0.0 )
{
@ -300,15 +300,7 @@ void LIB_TEXT::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
int LIB_TEXT::GetPenSize() const
{
int pensize = GetThickness();
if( pensize == 0 && IsBold() )
pensize = GetPenSizeForBold( GetTextWidth() );
// Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() );
return pensize;
return GetEffectiveTextPenWidth( nullptr ); // JEY TODO: requires RENDER_SETTINGS
}
@ -319,7 +311,7 @@ void LIB_TEXT::print( wxDC* aDC, const wxPoint& aOffset, void* aData, const TRAN
/* Calculate the text orientation, according to the component
* orientation/mirror (needed when draw text in schematic)
*/
int orient = GetTextAngle();
int orient = (int) GetTextAngle();
if( aTransform.y1 ) // Rotate component 90 degrees.
{
@ -350,7 +342,7 @@ void LIB_TEXT::print( wxDC* aDC, const wxPoint& aOffset, void* aData, const TRAN
txtpos = aTransform.TransformCoordinate( txtpos ) + aOffset;
GRText( aDC, txtpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_CENTER, GetPenSize(), IsItalic(), IsBold() );
GR_TEXT_VJUSTIFY_CENTER, GetEffectiveTextPenWidth( nullptr ), IsItalic(), IsBold() );
}
@ -358,7 +350,7 @@ void LIB_TEXT::GetMsgPanelInfo( EDA_UNITS aUnits, MSG_PANEL_ITEMS& aList )
{
LIB_ITEM::GetMsgPanelInfo( aUnits, aList );
wxString msg = MessageTextFromValue( aUnits, GetThickness(), true );
wxString msg = MessageTextFromValue( aUnits, GetTextPenWidth(), true );
aList.push_back( MSG_PANEL_ITEM( _( "Line Width" ), msg, BLUE ) );
}
@ -368,7 +360,7 @@ const EDA_RECT LIB_TEXT::GetBoundingBox() const
/* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
* calling GetTextBox() that works using top to bottom Y axis orientation.
*/
EDA_RECT rect = GetTextBox( -1, -1, true, GetTextMarkupFlags() );
EDA_RECT rect = GetTextBox( nullptr, -1, true ); // JEY TODO: requires RENDER_SETTINGS
rect.RevertYAxis();
// We are using now a bottom to top Y axis.

View File

@ -94,8 +94,8 @@ public:
void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const TRANSFORM& aTransform ) override;
int GetWidth() const override { return GetThickness(); }
void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
int GetWidth() const override { return GetTextPenWidth(); }
void SetWidth( int aWidth ) override { SetTextPenWidth( aWidth ); }
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;

View File

@ -1839,7 +1839,7 @@ void SCH_EAGLE_PLUGIN::loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttrib
if( aAttribs.ratio.CGet() > 12 )
{
aText->SetBold( true );
aText->SetThickness( GetPenSizeForBold( aText->GetTextWidth() ) );
aText->SetTextPenWidth( GetPenSizeForBold( aText->GetTextWidth() ) );
}
}

View File

@ -131,15 +131,7 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
int SCH_FIELD::GetPenSize() const
{
int pensize = GetThickness();
if( pensize == 0 && IsBold() )
pensize = GetPenSizeForBold( GetTextWidth() );
// Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() );
return pensize;
return GetEffectiveTextPenWidth( nullptr ); // JEY TODO: requires RENDER_SETTINGS
}
@ -214,15 +206,12 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem )
const EDA_RECT SCH_FIELD::GetBoundingBox() const
{
// Use the maximum clamped pen width to give us a bit of wiggle room
int linewidth = Clamp_Text_PenSize( GetTextSize().x, GetTextSize(), IsBold() );
// Calculate the text bounding box:
EDA_RECT rect;
SCH_FIELD text( *this ); // Make a local copy to change text
// because GetBoundingBox() is const
text.SetText( GetShownText() );
rect = text.GetTextBox( -1, linewidth, false, GetTextMarkupFlags() );
rect = text.GetTextBox( nullptr ); // JEY TODO: requires RENDER_SETTINGS
// Calculate the bounding box position relative to the parent:
wxPoint origin = GetParentPosition();

View File

@ -1427,7 +1427,7 @@ SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader )
SCH_PARSE_ERROR( "invalid label type", aReader, line );
}
int thickness = 0;
int penWidth = 0;
// The following tokens do not exist in version 1 schematic files,
// and not always in version 2 for HLabels and GLabels
@ -1441,14 +1441,14 @@ SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader )
SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
}
// The thickness token does not exist in older versions of the schematic file format
// The penWidth token does not exist in older versions of the schematic file format
// so calling parseInt will be made only if the EOL is not reached.
if( *line >= ' ' )
thickness = parseInt( aReader, line, &line );
penWidth = parseInt( aReader, line, &line );
}
text->SetBold( thickness != 0 );
text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
text->SetBold( penWidth != 0 );
text->SetTextPenWidth( penWidth != 0 ? GetPenSizeForBold( size ) : 0 );
// Read the text string for the text.
char* tmp = aReader.ReadLine();
@ -2357,7 +2357,7 @@ void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText )
Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
spinStyle,
Iu2Mils( aText->GetTextWidth() ),
italics, Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
italics, Iu2Mils( aText->GetTextPenWidth() ), TO_UTF8( text ) );
}
else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
{
@ -2372,7 +2372,7 @@ void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText )
Iu2Mils( aText->GetTextWidth() ),
shapeLabelIt->second,
italics,
Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
Iu2Mils( aText->GetTextPenWidth() ), TO_UTF8( text ) );
}
}

View File

@ -331,10 +331,7 @@ float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows )
float SCH_PAINTER::getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows )
{
float width = (float) aItem->GetThickness();
if( width == 0 )
width = (float) m_schSettings.m_DefaultLineWidth;
float width = (float) aItem->GetEffectiveTextPenWidth( &m_schSettings );
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();

View File

@ -535,7 +535,7 @@ void SCH_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
}
case T_thickness:
aText->SetThickness( parseInternalUnits( "text thickness" ) );
aText->SetTextPenWidth( parseInternalUnits( "text thickness" ) );
NeedRIGHT();
break;

View File

@ -282,30 +282,16 @@ bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
int SCH_TEXT::GetPenSize() const
{
int pensize = GetThickness();
if( pensize == 0 && IsBold() )
pensize = GetPenSizeForBold( GetTextWidth() );
// Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() );
return pensize;
return GetEffectiveTextPenWidth( nullptr ); // JEY TODO: requires RENDER_SETTINGS
}
void SCH_TEXT::Print( wxDC* DC, const wxPoint& aOffset )
{
COLOR4D color = GetLayerColor( m_Layer );
int linewidth = GetPenSize();
wxPoint text_offset = aOffset + GetSchematicTextOffset();
int savedWidth = GetThickness();
SetThickness( linewidth ); // Set the minimum width
EDA_TEXT::Print( DC, text_offset, color );
SetThickness( savedWidth );
}
@ -415,10 +401,7 @@ void SCH_TEXT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
const EDA_RECT SCH_TEXT::GetBoundingBox() const
{
// Use the maximum clamped pen width to give us a bit of wiggle room
int linewidth = Clamp_Text_PenSize( GetTextSize().x, GetTextSize(), IsBold() );
EDA_RECT rect = GetTextBox( -1, linewidth, false, GetTextMarkupFlags() );
EDA_RECT rect = GetTextBox( nullptr ); // JEY TODO: requires RENDER_SETTINGS
if( GetTextAngle() != 0 ) // Rotate rect
{
@ -586,15 +569,10 @@ bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
void SCH_TEXT::Plot( PLOTTER* aPlotter )
{
static std::vector<wxPoint> Poly;
COLOR4D color = aPlotter->ColorSettings()->GetColor( GetLayer() );
int tmp = GetThickness();
int thickness = GetPenSize();
COLOR4D color = aPlotter->ColorSettings()->GetColor( GetLayer() );
int penWidth = GetEffectiveTextPenWidth( nullptr );
// Two thicknesses are set here:
// The first is for EDA_TEXT, which controls the interline spacing based on text thickness
// The second is for the output that sets the actual stroke size
SetThickness( thickness );
aPlotter->SetCurrentLineWidth( thickness );
aPlotter->SetCurrentLineWidth( penWidth );
if( IsMultilineAllowed() )
{
@ -610,7 +588,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter )
wxPoint textpos = positions[ii] + GetSchematicTextOffset();
wxString& txt = strings_list.Item( ii );
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
GetVertJustify(), thickness, IsItalic(), IsBold() );
GetVertJustify(), penWidth, IsItalic(), IsBold() );
}
}
else
@ -618,7 +596,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter )
wxPoint textpos = GetTextPos() + GetSchematicTextOffset();
aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(),
GetHorizJustify(), GetVertJustify(), thickness, IsItalic(), IsBold() );
GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold() );
}
// Draw graphic symbol for global or hierarchical labels
@ -628,8 +606,6 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter )
if( Poly.size() )
aPlotter->PlotPoly( Poly, NO_FILL );
SetThickness( tmp );
}
@ -765,10 +741,7 @@ bool SCH_LABEL::IsType( const KICAD_T aScanTypes[] ) const
const EDA_RECT SCH_LABEL::GetBoundingBox() const
{
// Use the maximum clamped pen width to give us a bit of wiggle room
int linewidth = Clamp_Text_PenSize( GetTextSize().x, GetTextSize(), IsBold() );
EDA_RECT rect = GetTextBox( -1, linewidth, false, GetTextMarkupFlags() );
EDA_RECT rect = GetTextBox( nullptr ); // JEY TODO: requires RENDER_SETTINGS
if( GetTextAngle() != 0.0 )
{
@ -908,17 +881,11 @@ void SCH_GLOBALLABEL::Print( wxDC* DC, const wxPoint& aOffset )
COLOR4D color = GetLayerColor( m_Layer );
wxPoint text_offset = aOffset + GetSchematicTextOffset();
int linewidth = GetPenSize();
int save_width = GetThickness();
SetThickness( linewidth );
EDA_TEXT::Print( DC, text_offset, color );
SetThickness( save_width ); // restore initial value
CreateGraphicShape( Poly, GetTextPos() + aOffset );
GRPoly( nullptr, DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, GetTextPenWidth(), color, color );
}
@ -1152,18 +1119,12 @@ void SCH_HIERLABEL::Print( wxDC* DC, const wxPoint& offset )
auto conn = Connection( *g_CurrentSheet );
COLOR4D color = GetLayerColor( ( conn && conn->IsBus() ) ? LAYER_BUS : m_Layer );
int linewidth = GetPenSize();
int save_width = GetThickness();
SetThickness( linewidth );
wxPoint text_offset = offset + GetSchematicTextOffset();
EDA_TEXT::Print( DC, text_offset, color );
SetThickness( save_width ); // restore initial value
CreateGraphicShape( Poly, GetTextPos() + offset );
GRPoly( nullptr, DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, GetTextPenWidth(), color, color );
}

View File

@ -30,9 +30,12 @@
#include <gr_basic.h> // EDA_DRAW_MODE_T
#include <base_struct.h> // EDA_RECT
#include "kicad_string.h"
#include "painter.h"
class SHAPE_POLY_SET;
using KIGFX::RENDER_SETTINGS;
// part of the kicad_plugin.h family of defines.
// See kicad_plugin.h for the choice of the value
// When set when calling EDA_TEXT::Format, disable writing the "hide" keyword in save file
@ -137,15 +140,14 @@ public:
virtual void SetText( const wxString& aText );
/**
* Set the pen width.
*
* @param aNewThickness is the new pen width
* The TextPenWidth is that set by the user. The EffectiveTextPenWidth also factors
* in bold text, default text thickness, and thickness clamping.
*/
void SetThickness( int aNewThickness ) { m_e.penwidth = aNewThickness; };
void SetTextPenWidth( int aWidth ) { m_e.penwidth = aWidth; };
int GetTextPenWidth() const { return m_e.penwidth; };
int GetEffectiveTextPenWidth( RENDER_SETTINGS* aSettings ) const;
/**
* Return the pen width.
*/
// JEY TODO: delete
int GetThickness() const { return m_e.penwidth; };
void SetTextAngle( double aAngle )
@ -308,25 +310,16 @@ public:
int LenSize( const wxString& aLine, int aThickness, int aMarkupFlags ) const;
/**
* Useful in multiline texts to calculate the full text or a line area (for
* zones filling, locate functions....)
*
* @return the rect containing the line of text (i.e. the position and the
* size of one line)
* this rectangle is calculated for 0 orient text.
* If orientation is not 0 the rect must be rotated to match the
* physical area
* @param aLine The line of text to consider.
* for single line text, aLine is unused
* If aLine == -1, the full area (considering all lines) is returned
* @param aThickness Overrides the current penwidth when greater than 0.
* This is needed when the current penwidth is 0 and a default penwidth is used.
* Useful in multiline texts to calculate the full text or a line area (for zones filling,
* locate functions....)
* @param aSettings An options rendering context to provide defaults, processing flags, etc.
* @param aLine The line of text to consider. Pass -1 for all lines.
* @param aInvertY Invert the Y axis when calculating bounding box.
* @param aMarkupFlags a flagset of MARKUP_FLAG enums indicating which markup tokens should
* be processed
* @return the rect containing the line of text (i.e. the position and the size of one line)
* this rectangle is calculated for 0 orient text.
* If orientation is not 0 the rect must be rotated to match the physical area
*/
EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false,
int aMarkupFlags = 0 ) const;
EDA_RECT GetTextBox( RENDER_SETTINGS* aSettings, int aLine = -1, bool aInvertY = false ) const;
/**
* Return the distance between two lines of text.

View File

@ -31,7 +31,6 @@
#include <set>
#include <gal/color4d.h>
#include <ws_draw_item.h>
#include <layers_id_colors_and_visibility.h>
#include <memory>
@ -45,11 +44,12 @@ class VIEW_ITEM;
/**
* RENDER_SETTINGS
* Contains all the knowledge about how graphical objects are drawn on
* any output surface/device. This includes:
* Contains all the knowledge about how graphical objects are drawn on any output
* surface/device. This includes:
* - color/transparency settings
* - highlighting and high contrast mode control
* - drawing quality control (sketch/outline mode)
* - text processing flags
* The class acts as an interface between the PAINTER object and the GUI (i.e. Layers/Items
* widget or display options dialog).
*/
@ -143,22 +143,9 @@ public:
/**
* Function SetHighContrast
* Turns on/off high contrast display mode.
* @param aEnabled determines if high contrast display mode should be enabled or not.
*/
inline void SetHighContrast( bool aEnabled )
{
m_hiContrastEnabled = aEnabled;
}
/**
* Function GetHighContrast
* Returns information about high contrast display mode.
* @return True if the high contrast mode is on, false otherwise.
*/
inline bool GetHighContrast() const
{
return m_hiContrastEnabled;
}
void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
bool GetHighContrast() const { return m_hiContrastEnabled; }
/**
* Function GetColor
@ -170,20 +157,13 @@ public:
*/
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
float GetWorksheetLineWidth() const
{
return m_worksheetLineWidth;
}
float GetWorksheetLineWidth() const { return m_worksheetLineWidth; }
inline bool GetShowPageLimits() const
{
return m_showPageLimits;
}
int GetDefaultPenWidth() const { return m_defaultPenWidth; }
int GetTextMarkupFlags() const { return m_textMarkupFlags; }
inline void SetShowPageLimits( bool aDraw )
{
m_showPageLimits = aDraw;
}
bool GetShowPageLimits() const { return m_showPageLimits; }
void SetShowPageLimits( bool aDraw ) { m_showPageLimits = aDraw; }
/**
* Function GetBackgroundColor
@ -256,40 +236,34 @@ protected:
std::set<unsigned int> m_activeLayers; ///< Stores active layers number
///> Colors for all layers (normal)
COLOR4D m_layerColors[LAYER_ID_COUNT];
COLOR4D m_layerColors[LAYER_ID_COUNT]; // Layer colors
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
///> Colors for all layers (highlighted)
COLOR4D m_layerColorsHi[LAYER_ID_COUNT];
COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
///> Colors for all layers (selected)
COLOR4D m_layerColorsSel[LAYER_ID_COUNT];
///> Colors for all layers (darkened)
COLOR4D m_layerColorsDark[LAYER_ID_COUNT];
///< Colora used for high contrast display mode
COLOR4D m_hiContrastColor[LAYER_ID_COUNT];
COLOR4D m_backgroundColor; // The background color
/// Parameters for display modes
bool m_hiContrastEnabled; ///< High contrast display mode on/off
float m_hiContrastFactor; ///< Factor used for computing high contrast color
bool m_hiContrastEnabled; // High contrast display mode on/off
float m_hiContrastFactor; // Factor used for computing high contrast color
bool m_highlightEnabled; ///< Highlight display mode on/off
int m_highlightNetcode; ///< Net number that is displayed in highlight
///< -1 means that there is no specific net, and whole active
///< layer is highlighted
bool m_highlightItems; ///< Highlight items with their HIGHLIGHT flags set
float m_highlightFactor; ///< Factor used for computing highlight color
bool m_highlightEnabled; // Highlight display mode on/off
int m_highlightNetcode; // Net number that is displayed in highlight
// -1 means that there is no specific net, and whole active
// layer is highlighted
bool m_highlightItems; // Highlight items with their HIGHLIGHT flags set
float m_highlightFactor; // Factor used for computing highlight color
float m_selectFactor; ///< Specifies how color of selected items is changed
float m_layerOpacity; ///< Determines opacity of all layers
float m_outlineWidth; ///< Line width used when drawing outlines
float m_worksheetLineWidth; ///< Line width used when drawing worksheet
float m_selectFactor; // Specifies how color of selected items is changed
float m_outlineWidth; // Line width used when drawing outlines
float m_worksheetLineWidth; // Line width used when drawing worksheet
int m_defaultPenWidth;
int m_textMarkupFlags; // Indicates whether or not certain markups (such as super-
// and subscript) should be processed.
bool m_showPageLimits;
COLOR4D m_backgroundColor; ///< The background color
};

View File

@ -25,6 +25,7 @@
#define PREVIEW_PREVIEW_DRAW_CONTEXT__H_
#include <painter.h>
#include <math/vector2d.h>
namespace KIGFX
{

View File

@ -27,7 +27,6 @@
#include <math/vector2d.h>
#include <eda_text.h>
#include <eda_text.h>
#include <bitmap_base.h>
#include "msgpanel.h"
#include <geometry/shape_poly_set.h>
@ -280,7 +279,7 @@ public:
{
SetTextPos( aPos );
SetTextSize( aSize );
SetThickness( aPenWidth );
SetTextPenWidth( aPenWidth );
SetItalic( aItalic );
SetBold( aBold );
}
@ -289,9 +288,6 @@ public:
void PrintWsItem( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor ) override;
// Accessors:
int GetPenWidth() { return GetThickness(); }
void SetTextAngle( double aAngle )
{
EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );

View File

@ -29,6 +29,7 @@
#include <gal/color4d.h>
#include <painter.h>
#include <page_info.h>
#include <ws_draw_item.h>
// Forward declarations:
class EDA_RECT;

Some files were not shown because too many files have changed in this diff Show More