| 740 | |
| 741 | |
| 742 | BOX2I 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 | { |