7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 16:10:10 +00:00

Update font when needed on italic/bold change

When the italic or bold nature is changed, text using outline fonts may
need to change its font. Add this to the SetItalic/SetBold functions.

Also add a counterpart SetItalicFlag function (following SetBoldFlag)
when you only need to set the flag (e.g. when importing or changing
everything in the text properties dialog).

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/18592
This commit is contained in:
John Beard 2024-08-27 23:06:32 +01:00
parent 6167be1e98
commit b043f334de
9 changed files with 67 additions and 13 deletions

View File

@ -210,6 +210,26 @@ void EDA_TEXT::SetTextAngle( const EDA_ANGLE& aAngle )
void EDA_TEXT::SetItalic( bool aItalic )
{
if( m_attributes.m_Italic != aItalic )
{
const KIFONT::FONT* font = GetFont();
if( !font || font->IsStroke() )
{
// For stroke fonts, just need to set the attribute.
}
else
{
// For outline fonts, italic-ness is determined by the font itself.
SetFont( KIFONT::FONT::GetFont( font->GetName(), IsBold(), aItalic ) );
}
}
SetItalicFlag( aItalic );
}
void EDA_TEXT::SetItalicFlag( bool aItalic )
{
m_attributes.m_Italic = aItalic;
ClearRenderCache();
@ -221,12 +241,23 @@ 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 );
const KIFONT::FONT* font = GetFont();
if( aBold )
m_attributes.m_StrokeWidth = GetPenSizeForBold( size );
if( !font || font->IsStroke() )
{
// For stroke fonts, boldness is determined by the pen size.
const 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 );
}
else
m_attributes.m_StrokeWidth = GetPenSizeForNormal( size );
{
// For outline fonts, boldness is determined by the font itself.
SetFont( KIFONT::FONT::GetFont( font->GetName(), aBold, IsItalic() ) );
}
}
SetBoldFlag( aBold );

View File

@ -1075,7 +1075,7 @@ SCH_TEXT* SCH_IO_KICAD_LEGACY::loadText( LINE_READER& aReader )
if( m_version > 2 || *line >= ' ' )
{
if( strCompare( "Italic", line, &line ) )
text->SetItalic( true );
text->SetItalicFlag( true );
else if( !strCompare( "~", line, &line ) )
SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
}
@ -1363,7 +1363,7 @@ SCH_SYMBOL* SCH_IO_KICAD_LEGACY::loadSymbol( LINE_READER& aReader )
if( textAttrs[1] == 'I' )
{
field.SetItalic( true );
field.SetItalicFlag( true );
}
else if( textAttrs[1] != 'N' )
{

View File

@ -650,7 +650,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSym
wxChar attr_2 = attributes[2];
if( attr_1 == 'I' ) // Italic
field->SetItalic( true );
field->SetItalicFlag( true );
else if( attr_1 != 'N' ) // No italics is default, check for error.
SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
@ -1014,7 +1014,7 @@ SCH_TEXT* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadText( LINE_READER& aReader,
&& !is_eol( *line ) )
{
if( strCompare( "Italic", line, &line ) )
text->SetItalic( true );
text->SetItalicFlag( true );
else if( !strCompare( "Normal", line, &line ) )
SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );

View File

@ -754,7 +754,7 @@ void SCH_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOve
case T_italic:
italic = parseMaybeAbsentBool( true );
aText->SetItalic( italic );
aText->SetItalicFlag( italic );
break;
case T_color:

View File

@ -136,10 +136,33 @@ public:
}
double GetTextAngleDegrees() const { return m_attributes.m_Angle.AsDegrees(); }
/**
* Set the text to be italic - this will also update the font if needed.
*
* This is the properties system interface.
*/
void SetItalic( bool aItalic );
/**
* Set only the italic flag, without changing the font.
*
* Used when bulk-changing text attributes (e.g. from a dialog or import).
*/
void SetItalicFlag( bool aItalic );
bool IsItalic() const { return m_attributes.m_Italic; }
/**
* Set the text to be bold - this will also update the font if needed.
*
* This is the properties system interface.
*/
void SetBold( bool aBold );
/**
* Set only the italic flag, without changing the font.
*
* Used when bulk-changing text attributes (e.g. from a dialog or import).
*/
void SetBoldFlag( bool aBold );
bool IsBold() const { return m_attributes.m_Bold; }

View File

@ -531,7 +531,7 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
m_item->SetKeepUpright( m_KeepUpright->GetValue() );
m_item->SetBoldFlag( m_bold->IsChecked() );
m_item->SetItalic( m_italic->IsChecked() );
m_item->SetItalicFlag( m_italic->IsChecked() );
if( m_alignLeft->IsChecked() )
m_item->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );

View File

@ -348,7 +348,7 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow()
m_textBox->SetTextAngle( m_orientation.GetAngleValue().Normalize() );
m_textBox->SetBoldFlag( m_bold->IsChecked() );
m_textBox->SetItalic( m_italic->IsChecked() );
m_textBox->SetItalicFlag( m_italic->IsChecked() );
if( m_alignLeft->IsChecked() )
m_textBox->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );

View File

@ -4408,7 +4408,7 @@ void ALTIUM_PCB::ConvertTexts6ToEdaTextSettings( const ATEXT6& aElem, EDA_TEXT&
aEdaText.SetTextThickness( aElem.strokewidth );
aEdaText.SetBoldFlag( aElem.isBold );
aEdaText.SetItalic( aElem.isItalic );
aEdaText.SetItalicFlag( aElem.isItalic );
aEdaText.SetMirrored( aElem.isMirrored );
aEdaText.SetTextAngle( EDA_ANGLE( aElem.rotation, DEGREES_T ) );
}

View File

@ -572,7 +572,7 @@ void PCB_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
case T_italic:
{
bool value = parseMaybeAbsentBool( true );
aText->SetItalic( value );
aText->SetItalicFlag( value );
}
break;