Adjust outline font SCH_TEXT positioning so it better matches SCH_FIELD text.
This commit is contained in:
parent
662c1ce88f
commit
85680886f8
|
@ -448,7 +448,7 @@ void EDA_TEXT::ClearBoundingBoxCache()
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
||||||
EDA_TEXT::GetRenderCache( const wxString& forResolvedText ) const
|
EDA_TEXT::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& aOffset ) const
|
||||||
{
|
{
|
||||||
if( GetDrawFont()->IsOutline() )
|
if( GetDrawFont()->IsOutline() )
|
||||||
{
|
{
|
||||||
|
@ -456,7 +456,8 @@ EDA_TEXT::GetRenderCache( const wxString& forResolvedText ) const
|
||||||
|
|
||||||
if( m_render_cache.empty()
|
if( m_render_cache.empty()
|
||||||
|| m_render_cache_text != forResolvedText
|
|| m_render_cache_text != forResolvedText
|
||||||
|| m_render_cache_angle != resolvedAngle )
|
|| m_render_cache_angle != resolvedAngle
|
||||||
|
|| m_render_cache_offset != aOffset )
|
||||||
{
|
{
|
||||||
m_render_cache.clear();
|
m_render_cache.clear();
|
||||||
|
|
||||||
|
@ -465,9 +466,10 @@ EDA_TEXT::GetRenderCache( const wxString& forResolvedText ) const
|
||||||
|
|
||||||
attrs.m_Angle = resolvedAngle;
|
attrs.m_Angle = resolvedAngle;
|
||||||
|
|
||||||
font->GetLinesAsGlyphs( &m_render_cache, GetShownText(), GetDrawPos(), attrs );
|
font->GetLinesAsGlyphs( &m_render_cache, GetShownText(), GetDrawPos() + aOffset, attrs );
|
||||||
m_render_cache_angle = resolvedAngle;
|
m_render_cache_angle = resolvedAngle;
|
||||||
m_render_cache_text = forResolvedText;
|
m_render_cache_text = forResolvedText;
|
||||||
|
m_render_cache_offset = aOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &m_render_cache;
|
return &m_render_cache;
|
||||||
|
@ -570,7 +572,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
|
||||||
wxSize textsize = wxSize( extents.x, extents.y );
|
wxSize textsize = wxSize( extents.x, extents.y );
|
||||||
VECTOR2I pos = drawPos;
|
VECTOR2I pos = drawPos;
|
||||||
|
|
||||||
if( IsMultilineAllowed() && aLine > 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
|
if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
|
||||||
pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y ) );
|
pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y ) );
|
||||||
|
|
||||||
if( text.Contains( wxT( "~{" ) ) )
|
if( text.Contains( wxT( "~{" ) ) )
|
||||||
|
@ -593,9 +595,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
|
||||||
|
|
||||||
// interline spacing is only *between* lines, so total height is the height of the first
|
// interline spacing is only *between* lines, so total height is the height of the first
|
||||||
// line plus the interline distance (with interline spacing) for all subsequent lines
|
// line plus the interline distance (with interline spacing) for all subsequent lines
|
||||||
// Don't add interline spacing to empty textboxes
|
textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y ) );
|
||||||
if( strings.GetCount() )
|
|
||||||
textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.SetSize( textsize );
|
rect.SetSize( textsize );
|
||||||
|
|
|
@ -1883,6 +1883,19 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer )
|
||||||
attrs.m_Angle = aText->GetDrawRotation();
|
attrs.m_Angle = aText->GetDrawRotation();
|
||||||
attrs.m_StrokeWidth = getTextThickness( aText, drawingShadows );
|
attrs.m_StrokeWidth = getTextThickness( aText, drawingShadows );
|
||||||
|
|
||||||
|
// Adjust text drawn in an outline font to more closely mimic the positioning of
|
||||||
|
// SCH_FIELD text.
|
||||||
|
if( aText->GetDrawFont()->IsOutline() )
|
||||||
|
{
|
||||||
|
EDA_RECT firstLineBBox = aText->GetTextBox( 0 );
|
||||||
|
int sizeDiff = firstLineBBox.GetHeight() - aText->GetTextSize().y;
|
||||||
|
int adjust = KiROUND( sizeDiff * 0.4 );
|
||||||
|
VECTOR2I adjust_offset( 0, - adjust );
|
||||||
|
|
||||||
|
RotatePoint( adjust_offset, aText->GetDrawRotation() );
|
||||||
|
text_offset += adjust_offset;
|
||||||
|
}
|
||||||
|
|
||||||
if( nonCached( aText )
|
if( nonCached( aText )
|
||||||
&& underLODThreshold( aText->GetTextHeight() )
|
&& underLODThreshold( aText->GetTextHeight() )
|
||||||
&& !shownText.Contains( wxT( "\n" ) ) )
|
&& !shownText.Contains( wxT( "\n" ) ) )
|
||||||
|
@ -1893,8 +1906,7 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer )
|
||||||
{
|
{
|
||||||
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
|
||||||
|
|
||||||
if( !text_offset.x && !text_offset.y )
|
cache = aText->GetRenderCache( shownText, text_offset );
|
||||||
cache = aText->GetRenderCache( shownText );
|
|
||||||
|
|
||||||
if( cache )
|
if( cache )
|
||||||
{
|
{
|
||||||
|
|
|
@ -287,9 +287,22 @@ KIFONT::FONT* SCH_TEXT::GetDrawFont() const
|
||||||
|
|
||||||
void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
||||||
{
|
{
|
||||||
COLOR4D color = aSettings->GetLayerColor( m_layer );
|
COLOR4D color = aSettings->GetLayerColor( m_layer );
|
||||||
VECTOR2I text_offset = aOffset + GetSchematicTextOffset( aSettings );
|
VECTOR2I text_offset = aOffset + GetSchematicTextOffset( aSettings );
|
||||||
|
|
||||||
|
// Adjust text drawn in an outline font to more closely mimic the positioning of
|
||||||
|
// SCH_FIELD text.
|
||||||
|
if( GetDrawFont()->IsOutline() )
|
||||||
|
{
|
||||||
|
EDA_RECT firstLineBBox = GetTextBox( 0 );
|
||||||
|
int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
|
||||||
|
int adjust = KiROUND( sizeDiff * 0.4 );
|
||||||
|
VECTOR2I adjust_offset( 0, - adjust );
|
||||||
|
|
||||||
|
RotatePoint( adjust_offset, GetDrawRotation() );
|
||||||
|
text_offset += adjust_offset;
|
||||||
|
}
|
||||||
|
|
||||||
EDA_TEXT::Print( aSettings, text_offset, color );
|
EDA_TEXT::Print( aSettings, text_offset, color );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,10 +430,24 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
||||||
COLOR4D color = settings->GetLayerColor( layer );
|
COLOR4D color = settings->GetLayerColor( layer );
|
||||||
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
|
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
|
||||||
KIFONT::FONT* font = GetDrawFont();
|
KIFONT::FONT* font = GetDrawFont();
|
||||||
|
VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() );
|
||||||
|
|
||||||
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
||||||
aPlotter->SetCurrentLineWidth( penWidth );
|
aPlotter->SetCurrentLineWidth( penWidth );
|
||||||
|
|
||||||
|
// Adjust text drawn in an outline font to more closely mimic the positioning of
|
||||||
|
// SCH_FIELD text.
|
||||||
|
if( GetDrawFont()->IsOutline() )
|
||||||
|
{
|
||||||
|
EDA_RECT firstLineBBox = GetTextBox( 0 );
|
||||||
|
int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
|
||||||
|
int adjust = KiROUND( sizeDiff * 0.4 );
|
||||||
|
VECTOR2I adjust_offset( 0, - adjust );
|
||||||
|
|
||||||
|
RotatePoint( adjust_offset, GetDrawRotation() );
|
||||||
|
text_offset += adjust_offset;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<VECTOR2I> positions;
|
std::vector<VECTOR2I> positions;
|
||||||
wxArrayString strings_list;
|
wxArrayString strings_list;
|
||||||
wxStringSplit( GetShownText(), strings_list, '\n' );
|
wxStringSplit( GetShownText(), strings_list, '\n' );
|
||||||
|
@ -430,7 +457,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
||||||
|
|
||||||
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
||||||
{
|
{
|
||||||
VECTOR2I textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() );
|
VECTOR2I textpos = positions[ii] + text_offset;
|
||||||
wxString& txt = strings_list.Item( ii );
|
wxString& txt = strings_list.Item( ii );
|
||||||
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
|
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
|
||||||
GetVertJustify(), penWidth, IsItalic(), IsBold(), false, font );
|
GetVertJustify(), penWidth, IsItalic(), IsBold(), false, font );
|
||||||
|
|
|
@ -324,7 +324,7 @@ public:
|
||||||
virtual void ClearBoundingBoxCache();
|
virtual void ClearBoundingBoxCache();
|
||||||
|
|
||||||
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
||||||
GetRenderCache( const wxString& forResolvedText ) const;
|
GetRenderCache( const wxString& forResolvedText, const VECTOR2I& aOffset = { 0, 0 } ) const;
|
||||||
|
|
||||||
// Support for reading the cache from disk.
|
// Support for reading the cache from disk.
|
||||||
void SetupRenderCache( const wxString& aResolvedText, const EDA_ANGLE& aAngle );
|
void SetupRenderCache( const wxString& aResolvedText, const EDA_ANGLE& aAngle );
|
||||||
|
@ -354,6 +354,7 @@ private:
|
||||||
|
|
||||||
mutable wxString m_render_cache_text;
|
mutable wxString m_render_cache_text;
|
||||||
mutable EDA_ANGLE m_render_cache_angle;
|
mutable EDA_ANGLE m_render_cache_angle;
|
||||||
|
mutable VECTOR2I m_render_cache_offset;
|
||||||
mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_render_cache;
|
mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_render_cache;
|
||||||
|
|
||||||
mutable bool m_bounding_box_cache_valid;
|
mutable bool m_bounding_box_cache_valid;
|
||||||
|
|
Loading…
Reference in New Issue