Push thickness handling down into EDA_TEXT::SetBold().

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17077

Fixes https://gitlab.com/kicad/code/kicad/-/issues/14875
This commit is contained in:
Jeff Young 2024-02-25 17:28:05 +00:00
parent 6ec51f6a69
commit aef87b9796
23 changed files with 85 additions and 93 deletions

View File

@ -219,6 +219,22 @@ void EDA_TEXT::SetItalic( bool aItalic )
void EDA_TEXT::SetBold( bool aBold )
{
if( m_attributes.m_Bold != aBold )
{
int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
if( aBold )
m_attributes.m_StrokeWidth = GetPenSizeForBold( size );
else
m_attributes.m_StrokeWidth = GetPenSizeForNormal( size );
}
SetBoldFlag( aBold );
}
void EDA_TEXT::SetBoldFlag( bool aBold )
{
m_attributes.m_Bold = aBold;
ClearRenderCache();

View File

@ -293,10 +293,11 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem( SCH_COMMIT* aCommit,
if( m_italic->Get3StateValue() != wxCHK_UNDETERMINED )
eda_text->SetItalic( m_italic->GetValue() );
// Must come after SetTextSize()
if( m_bold->Get3StateValue() != wxCHK_UNDETERMINED )
eda_text->SetBold( m_bold->GetValue() );
// Must come after bold & italic
// Must come after SetBold() & SetItalic()
if( m_fontCtrl->GetStringSelection() != INDETERMINATE_ACTION )
{
eda_text->SetFont( m_fontCtrl->GetFontSelection( eda_text->IsBold(),

View File

@ -553,20 +553,8 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataFromWindow()
else if( m_currentLabel->GetTextWidth() != m_textSize.GetValue() )
m_currentLabel->SetTextSize( VECTOR2I( m_textSize.GetValue(), m_textSize.GetValue() ) );
if( m_bold->IsChecked() != m_currentLabel->IsBold() )
{
if( m_bold->IsChecked() )
{
m_currentLabel->SetBold( true );
m_currentLabel->SetTextThickness( GetPenSizeForBold( m_currentLabel->GetTextWidth() ) );
}
else
{
m_currentLabel->SetBold( false );
m_currentLabel->SetTextThickness( 0 ); // Use default pen width
}
}
// Must come after SetTextSize()
m_currentLabel->SetBold( m_bold->IsChecked() );
m_currentLabel->SetItalic( m_italic->IsChecked() );
m_currentLabel->SetTextColor( m_textColorSwatch->GetSwatchColor() );

View File

@ -264,8 +264,9 @@ bool DIALOG_LIB_TEXT_PROPERTIES::TransferDataFromWindow()
else
m_graphicText->SetBodyStyle( 0 );
m_graphicText->SetItalic( m_italic->IsChecked() );
// Must come after SetTextSize()
m_graphicText->SetBold( m_bold->IsChecked() );
m_graphicText->SetItalic( m_italic->IsChecked() );
m_graphicText->SetTextColor( m_textColorSwatch->GetSwatchColor() );
if( m_hAlignLeft->IsChecked() )

View File

@ -281,21 +281,10 @@ bool DIALOG_LIB_TEXTBOX_PROPERTIES::TransferDataFromWindow()
m_italic->IsChecked() ) );
}
if( m_bold->IsChecked() != m_currentText->IsBold() )
{
if( m_bold->IsChecked() )
{
m_currentText->SetBold( true );
m_currentText->SetTextThickness( GetPenSizeForBold( m_currentText->GetTextWidth() ) );
}
else
{
m_currentText->SetBold( false );
m_currentText->SetTextThickness( 0 ); // Use default pen width
}
}
// Must come after SetTextSize()
m_currentText->SetBold( m_italic->IsChecked() );
m_currentText->SetItalic( m_italic->IsChecked() );
m_currentText->SetTextColor( m_textColorSwatch->GetSwatchColor() );
if( m_hAlignRight->IsChecked() )

View File

@ -147,26 +147,14 @@ bool DIALOG_SHEET_PIN_PROPERTIES::TransferDataFromWindow()
m_italic->IsChecked() ) );
}
if( m_bold->IsChecked() != m_sheetPin->IsBold() )
{
if( m_bold->IsChecked() )
{
m_sheetPin->SetBold( true );
m_sheetPin->SetTextThickness( GetPenSizeForBold( m_sheetPin->GetTextWidth() ) );
}
else
{
m_sheetPin->SetBold( false );
m_sheetPin->SetTextThickness( 0 ); // Use default pen width
}
}
m_sheetPin->SetItalic( m_italic->IsChecked() );
// Currently, eeschema uses only the text width as text size,
// and expects text width = text height
m_sheetPin->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
// Must come after SetTextSize()
m_sheetPin->SetBold( m_bold->IsChecked() );
m_sheetPin->SetItalic( m_italic->IsChecked() );
m_sheetPin->SetTextColor( m_textColorSwatch->GetSwatchColor() );
if( m_input->GetValue() ) m_sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );

View File

@ -474,21 +474,10 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
m_italic->IsChecked() ) );
}
if( m_bold->IsChecked() != m_currentText->IsBold() )
{
if( m_bold->IsChecked() )
{
m_currentText->SetBold( true );
m_currentText->SetTextThickness( GetPenSizeForBold( m_currentText->GetTextWidth() ) );
}
else
{
m_currentText->SetBold( false );
m_currentText->SetTextThickness( 0 ); // Use default pen width
}
}
// Must come after SetTextSize()
m_currentText->SetBold( m_bold->IsChecked() );
m_currentText->SetItalic( m_italic->IsChecked() );
m_currentText->SetTextColor( m_textColorSwatch->GetSwatchColor() );
if( m_hAlignRight->IsChecked() )

View File

@ -1343,9 +1343,11 @@ void SCH_IO_ALTIUM::ParseLabel( const std::map<wxString, wxString>& aProperties,
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
{
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
textItem->SetItalic( font.Italic );
textItem->SetBold( font.Bold );
textItem->SetTextSize( { font.Size / 2, font.Size / 2 } );
// Must come after SetTextSize()
textItem->SetBold( font.Bold );
textItem->SetItalic( font.Italic );
}
textItem->SetFlags(IS_NEW );
@ -1397,9 +1399,11 @@ void SCH_IO_ALTIUM::ParseLabel( const std::map<wxString, wxString>& aProperties,
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
{
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
textItem->SetItalic( font.Italic );
textItem->SetBold( font.Bold );
textItem->SetTextSize( { font.Size / 2, font.Size / 2 } );
// Must come after SetTextSize()
textItem->SetBold( font.Bold );
textItem->SetItalic( font.Italic );
}
else if( fontId > 0 && fontId <= aFontSizes.size() )
{
@ -1477,11 +1481,12 @@ void SCH_IO_ALTIUM::AddTextBox( const ASCH_TEXT_FRAME *aElem )
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
{
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
textBox->SetItalic( font.Italic );
textBox->SetBold( font.Bold );
textBox->SetTextSize( { font.Size / 2, font.Size / 2 } );
//textBox->SetFont( //how to set font, we have a font mane here: ( font.fontname );
// Must come after SetTextSize()
textBox->SetBold( font.Bold );
textBox->SetItalic( font.Italic );
//textBox->SetFont( //how to set font, we have a font name here: ( font.fontname );
}
textBox->SetFlags( IS_NEW );
@ -3187,10 +3192,12 @@ void SCH_IO_ALTIUM::ParseHarnessPort( const ASCH_PORT& aElem )
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
{
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
textBox->SetItalic( font.Italic );
textBox->SetBold( font.Bold );
textBox->SetTextSize( { font.Size / 2, font.Size / 2 } );
//textBox->SetFont( //how to set font, we have a font mane here: ( font.fontname );
// Must come after SetTextSize()
textBox->SetBold( font.Bold );
textBox->SetItalic( font.Italic );
//textBox->SetFont( //how to set font, we have a font name here: ( font.fontname );
}
textBox->SetFlags( IS_NEW );

View File

@ -2992,6 +2992,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextCodeIfExists( EDA_TEXT* aKiCa
aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
#endif
// Must come after SetTextSize()
aKiCadTextItem->SetBold( textCode.Font.Modifier1 == FONT_BOLD );
aKiCadTextItem->SetItalic( textCode.Font.Italic );
}

View File

@ -2767,14 +2767,9 @@ void SCH_IO_EAGLE::loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs )
{
aText->SetTextSize( aAttribs.ConvertSize() );
if( aAttribs.ratio )
{
if( aAttribs.ratio.CGet() > 12 )
{
// Must come after SetTextSize()
if( aAttribs.ratio && aAttribs.ratio.CGet() > 12 )
aText->SetBold( true );
aText->SetTextThickness( GetPenSizeForBold( aText->GetTextWidth() ) );
}
}
int align = aAttribs.align ? *aAttribs.align : ETEXT::BOTTOM_LEFT;
int degrees = aAttribs.rot ? aAttribs.rot->degrees : 0;
@ -2790,7 +2785,11 @@ void SCH_IO_EAGLE::loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText
aField->SetTextPos( aText->GetPosition() );
aField->SetTextSize( aText->GetTextSize() );
aField->SetTextAngle( aText->GetTextAngle() );
// Must come after SetTextSize()
aField->SetBold( aText->IsBold() );
aField->SetItalic( false );
aField->SetVertJustify( aText->GetVertJustify() );
aField->SetHorizJustify( aText->GetHorizJustify() );
}

View File

@ -1086,7 +1086,7 @@ SCH_TEXT* SCH_IO_KICAD_LEGACY::loadText( LINE_READER& aReader )
penWidth = parseInt( aReader, line, &line );
}
text->SetBold( penWidth != 0 );
text->SetBoldFlag( penWidth != 0 );
text->SetTextThickness( penWidth != 0 ? GetPenSizeForBold( size ) : 0 );
// Read the text string for the text.
@ -1356,7 +1356,7 @@ SCH_SYMBOL* SCH_IO_KICAD_LEGACY::loadSymbol( LINE_READER& aReader )
if( textAttrs[2] == 'B' )
{
field.SetBold( true );
field.SetBoldFlag( true );
}
else if( textAttrs[2] != 'N' )
{

View File

@ -649,7 +649,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSym
SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
if ( attr_2 == 'B' ) // Bold
field->SetBold( true );
field->SetBoldFlag( true );
else if( attr_2 != 'N' ) // No bold is default, check for error.
SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
}
@ -1017,7 +1017,7 @@ LIB_TEXT* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadText( std::unique_ptr<LIB_SYMBOL>&
SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
if( parseInt( aReader, line, &line ) > 0 )
text->SetBold( true );
text->SetBoldFlag( true );
// Some old libaries version > 2.0 do not have these options for text justification:
if( !is_eol( *line ) )

View File

@ -739,7 +739,7 @@ void SCH_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOve
case T_bold:
{
bool bold = parseMaybeAbsentBool( true );
aText->SetBold( bold );
aText->SetBoldFlag( bold );
break;
}

View File

@ -1254,8 +1254,11 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
textItem->SetParent( schematic );
textItem->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
if( aType != LAYER_NETCLASS_REFS )
{
// Must be after SetTextSize()
textItem->SetBold( m_lastTextBold );
textItem->SetItalic( m_lastTextItalic );
}
@ -1271,7 +1274,6 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
textItem->SetTextAngle( m_lastTextAngle );
}
textItem->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
textItem->SetFlags( IS_NEW | IS_MOVING );
if( !labelItem )
@ -1864,10 +1866,13 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
{
SCH_TEXTBOX* textbox = new SCH_TEXTBOX( 0, m_lastTextboxFillStyle );
textbox->SetBold( m_lastTextBold );
textbox->SetItalic( m_lastTextItalic );
textbox->SetTextSize( VECTOR2I( sch_settings.m_DefaultTextSize,
sch_settings.m_DefaultTextSize ) );
// Must come after SetTextSize()
textbox->SetBold( m_lastTextBold );
textbox->SetItalic( m_lastTextItalic );
textbox->SetTextAngle( m_lastTextboxAngle );
textbox->SetHorizJustify( m_lastTextboxHJustify );
textbox->SetVertJustify( m_lastTextboxVJustify );

View File

@ -2323,8 +2323,10 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
new_eda_text->SetFont( eda_text->GetFont() );
new_eda_text->SetTextSize( eda_text->GetTextSize() );
new_eda_text->SetTextThickness( eda_text->GetTextThickness() );
new_eda_text->SetItalic( eda_text->IsItalic() );
// Must be after SetTextSize()
new_eda_text->SetBold( eda_text->IsBold() );
new_eda_text->SetItalic( eda_text->IsItalic() );
newtext->AutoplaceFields( m_frame->GetScreen(), false );

View File

@ -463,10 +463,13 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape( const TOOL_EVENT& aEvent, std::opt
{
LIB_TEXTBOX* textbox = new LIB_TEXTBOX( symbol, lineWidth, m_lastFillStyle );
textbox->SetBold( m_lastTextBold );
textbox->SetItalic( m_lastTextItalic );
textbox->SetTextSize( VECTOR2I( schIUScale.MilsToIU( settings->m_Defaults.text_size ),
schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
// Must be after SetTextSize()
textbox->SetBold( m_lastTextBold );
textbox->SetItalic( m_lastTextItalic );
textbox->SetTextAngle( m_lastTextAngle );
textbox->SetHorizJustify( m_lastTextJust );

View File

@ -141,6 +141,7 @@ public:
bool IsItalic() const { return m_attributes.m_Italic; }
void SetBold( bool aBold );
void SetBoldFlag( bool aBold );
bool IsBold() const { return m_attributes.m_Bold; }
virtual void SetVisible( bool aVisible );

View File

@ -414,6 +414,7 @@ void DIALOG_DIMENSION_PROPERTIES::updateDimensionFromDialog( PCB_DIMENSION_BASE*
if( m_fontCtrl->HaveFontSelection() )
aTarget->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) );
// Must come after SetTextWidth/Height()
aTarget->SetBold( m_bold->IsChecked() );
aTarget->SetItalic( m_italic->IsChecked() );

View File

@ -369,6 +369,7 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem( BOARD_COMMIT& aCommit, B
if( !m_thickness.IsIndeterminate() )
text->SetTextThickness( m_thickness.GetValue() );
// Must be after SetTextSize()
if( m_bold->Get3StateValue() != wxCHK_UNDETERMINED )
text->SetBold( m_bold->GetValue() );

View File

@ -510,7 +510,7 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
if( m_KeepUpright->IsShown() )
m_item->SetKeepUpright( m_KeepUpright->GetValue() );
m_item->SetBold( m_bold->IsChecked() );
m_item->SetBoldFlag( m_bold->IsChecked() );
m_item->SetItalic( m_italic->IsChecked() );
if( m_alignLeft->IsChecked() )

View File

@ -346,7 +346,7 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow()
}
m_textBox->SetTextAngle( m_orientation.GetAngleValue().Normalize() );
m_textBox->SetBold( m_bold->IsChecked() );
m_textBox->SetBoldFlag( m_bold->IsChecked() );
m_textBox->SetItalic( m_italic->IsChecked() );
if( m_alignLeft->IsChecked() )

View File

@ -3639,7 +3639,7 @@ void ALTIUM_PCB::ConvertTexts6ToEdaTextSettings( const ATEXT6& aElem, EDA_TEXT*
}
aEdaText->SetTextThickness( aElem.strokewidth );
aEdaText->SetBold( aElem.isBold );
aEdaText->SetBoldFlag( aElem.isBold );
aEdaText->SetItalic( aElem.isItalic );
aEdaText->SetMirrored( aElem.isMirrored );

View File

@ -559,7 +559,7 @@ void PCB_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
case T_bold:
{
bool value = parseMaybeAbsentBool( true );
aText->SetBold( value );
aText->SetBoldFlag( value );
}
break;