Browse Source

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
(cherry picked from commit b043f334de)
8.0
John Beard 1 year ago
parent
commit
64365de9de
  1. 39
      common/eda_text.cpp
  2. 4
      eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp
  3. 4
      eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp
  4. 2
      eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp
  5. 23
      include/eda_text.h
  6. 2
      pcbnew/dialogs/dialog_text_properties.cpp
  7. 2
      pcbnew/dialogs/dialog_textbox_properties.cpp
  8. 4
      pcbnew/pcb_io/altium/altium_pcb.cpp
  9. 2
      pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp

39
common/eda_text.cpp

@ -212,6 +212,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();
@ -223,12 +243,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( !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 );
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 );

4
eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp

@ -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 );
}
@ -1359,7 +1359,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' )
{

4
eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp

@ -647,7 +647,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 );
@ -1015,7 +1015,7 @@ LIB_TEXT* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadText( std::unique_ptr<LIB_SYMBOL>&
&& !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 );

2
eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp

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

23
include/eda_text.h

@ -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; }

2
pcbnew/dialogs/dialog_text_properties.cpp

@ -509,7 +509,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 );

2
pcbnew/dialogs/dialog_textbox_properties.cpp

@ -346,7 +346,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 );

4
pcbnew/pcb_io/altium/altium_pcb.cpp

@ -4198,7 +4198,7 @@ void ALTIUM_PCB::HelperSetTextAlignmentAndPos( const ATEXT6& aElem, EDA_TEXT* aT
int rectHeight = aElem.height;
if( aElem.isMirrored )
rectWidth = -rectWidth;
rectWidth = -rectWidth;
ALTIUM_TEXT_POSITION justification = aElem.isJustificationValid
? aElem.textbox_rect_justification
@ -4322,7 +4322,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 );
}

2
pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp

@ -559,7 +559,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;

Loading…
Cancel
Save