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>>*
|
||||
EDA_TEXT::GetRenderCache( const wxString& forResolvedText ) const
|
||||
EDA_TEXT::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& aOffset ) const
|
||||
{
|
||||
if( GetDrawFont()->IsOutline() )
|
||||
{
|
||||
|
@ -456,7 +456,8 @@ EDA_TEXT::GetRenderCache( const wxString& forResolvedText ) const
|
|||
|
||||
if( m_render_cache.empty()
|
||||
|| m_render_cache_text != forResolvedText
|
||||
|| m_render_cache_angle != resolvedAngle )
|
||||
|| m_render_cache_angle != resolvedAngle
|
||||
|| m_render_cache_offset != aOffset )
|
||||
{
|
||||
m_render_cache.clear();
|
||||
|
||||
|
@ -465,9 +466,10 @@ EDA_TEXT::GetRenderCache( const wxString& forResolvedText ) const
|
|||
|
||||
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_text = forResolvedText;
|
||||
m_render_cache_offset = aOffset;
|
||||
}
|
||||
|
||||
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 );
|
||||
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 ) );
|
||||
|
||||
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
|
||||
// line plus the interline distance (with interline spacing) for all subsequent lines
|
||||
// Don't add interline spacing to empty textboxes
|
||||
if( strings.GetCount() )
|
||||
textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y ) );
|
||||
textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y ) );
|
||||
}
|
||||
|
||||
rect.SetSize( textsize );
|
||||
|
|
|
@ -1883,6 +1883,19 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer )
|
|||
attrs.m_Angle = aText->GetDrawRotation();
|
||||
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 )
|
||||
&& underLODThreshold( aText->GetTextHeight() )
|
||||
&& !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;
|
||||
|
||||
if( !text_offset.x && !text_offset.y )
|
||||
cache = aText->GetRenderCache( shownText );
|
||||
cache = aText->GetRenderCache( shownText, text_offset );
|
||||
|
||||
if( cache )
|
||||
{
|
||||
|
|
|
@ -287,9 +287,22 @@ KIFONT::FONT* SCH_TEXT::GetDrawFont() const
|
|||
|
||||
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 );
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
|
@ -417,10 +430,24 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
|||
COLOR4D color = settings->GetLayerColor( layer );
|
||||
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
|
||||
KIFONT::FONT* font = GetDrawFont();
|
||||
VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() );
|
||||
|
||||
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
||||
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;
|
||||
wxArrayString strings_list;
|
||||
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++ )
|
||||
{
|
||||
VECTOR2I textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() );
|
||||
VECTOR2I textpos = positions[ii] + text_offset;
|
||||
wxString& txt = strings_list.Item( ii );
|
||||
aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
|
||||
GetVertJustify(), penWidth, IsItalic(), IsBold(), false, font );
|
||||
|
|
|
@ -324,7 +324,7 @@ public:
|
|||
virtual void ClearBoundingBoxCache();
|
||||
|
||||
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.
|
||||
void SetupRenderCache( const wxString& aResolvedText, const EDA_ANGLE& aAngle );
|
||||
|
@ -354,6 +354,7 @@ private:
|
|||
|
||||
mutable wxString m_render_cache_text;
|
||||
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 bool m_bounding_box_cache_valid;
|
||||
|
|
Loading…
Reference in New Issue