MCPcopy Create free account
hub / github.com/KiCad/kicad-source-mirror / GetTextBox

Method GetTextBox

common/eda_text.cpp:742–868  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

740
741
742BOX2I EDA_TEXT::GetTextBox( const RENDER_SETTINGS* aSettings, int aLine ) const
743{
744 VECTOR2I drawPos = GetDrawPos();
745
746 {
747 std::lock_guard<std::mutex> bboxLock( m_bbox_cacheMutex );
748 auto cache_it = m_bbox_cache.find( aLine );
749
750 if( cache_it != m_bbox_cache.end() && cache_it->second.m_pos == drawPos )
751 return cache_it->second.m_bbox;
752 }
753
754 BOX2I bbox;
755 wxArrayString strings;
756 wxString text = GetShownText( true );
757 int thickness = GetEffectiveTextPenWidth();
758
759 if( IsMultilineAllowed() )
760 {
761 wxStringSplit( text, strings, '\n' );
762
763 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
764 {
765 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
766 text = strings.Item( aLine );
767 else
768 text = strings.Item( 0 );
769 }
770 }
771
772 // calculate the H and V size
773 KIFONT::FONT* font = GetDrawFont( aSettings );
774 VECTOR2D fontSize( GetTextSize() );
775 bool bold = IsBold();
776 bool italic = IsItalic();
777 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, getFontMetrics() );
778 int overbarOffset = 0;
779
780 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
781 // bounding box will be moved later according to the actual text options
782 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
783 VECTOR2I pos = drawPos;
784 int fudgeFactor = KiROUND( extents.y * 0.17 );
785
786 if( font->IsStroke() )
787 textsize.y += fudgeFactor;
788
789 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
790 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
791
792 if( text.Contains( wxT( "~{" ) ) )
793 overbarOffset = extents.y / 6;
794
795 bbox.SetOrigin( pos );
796
797 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
798 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
799 {

Callers 9

BOOST_AUTO_TEST_CASEFunction · 0.80
handleGetTextExtentsMethod · 0.80
loadSymdefMethod · 0.80
drawMethod · 0.80

Calls 15

wxStringSplitFunction · 0.85
ItemMethod · 0.80
StringBoundaryLimitsMethod · 0.80
IsStrokeMethod · 0.80
IsBoldFunction · 0.50
IsItalicFunction · 0.50
KiROUNDFunction · 0.50
findMethod · 0.45
endMethod · 0.45
GetCountMethod · 0.45
GetInterlineMethod · 0.45
ContainsMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.64