KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_text.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <algorithm> // for max
26#include <stddef.h> // for NULL
27#include <type_traits> // for swap
28#include <vector>
29
30#include <eda_item.h>
31#include <base_units.h>
32#include <callback_gal.h>
33#include <eda_text.h> // for EDA_TEXT, TEXT_EFFECTS, GR_TEXT_VJUSTIF...
34#include <gal/color4d.h> // for COLOR4D, COLOR4D::BLACK
35#include <font/glyph.h>
36#include <gr_text.h>
37#include <string_utils.h> // for UnescapeString
38#include <math/util.h> // for KiROUND
39#include <math/vector2d.h>
40#include <core/kicad_algo.h>
41#include <richio.h>
42#include <render_settings.h>
43#include <trigo.h> // for RotatePoint
44#include <i18n_utility.h>
48#include <font/outline_font.h>
51#include <ctl_flags.h>
52#include <api/api_enums.h>
53#include <api/api_utils.h>
54#include <api/common/types/base_types.pb.h>
55
56#include <wx/debug.h> // for wxASSERT
57#include <wx/string.h>
58#include <wx/url.h> // for wxURL
61#include "font/fontconfig.h"
62#include "pgm_base.h"
63
64class OUTPUTFORMATTER;
65
66
68{
69 wxASSERT( aHorizJustify >= GR_TEXT_H_ALIGN_LEFT && aHorizJustify <= GR_TEXT_H_ALIGN_RIGHT );
70
71 if( aHorizJustify > GR_TEXT_H_ALIGN_RIGHT )
73
74 if( aHorizJustify < GR_TEXT_H_ALIGN_LEFT )
76
77 return static_cast<GR_TEXT_H_ALIGN_T>( aHorizJustify );
78}
79
80
82{
83 wxASSERT( aVertJustify >= GR_TEXT_V_ALIGN_TOP && aVertJustify <= GR_TEXT_V_ALIGN_BOTTOM );
84
85 if( aVertJustify > GR_TEXT_V_ALIGN_BOTTOM )
87
88 if( aVertJustify < GR_TEXT_V_ALIGN_TOP )
90
91 return static_cast<GR_TEXT_V_ALIGN_T>( aVertJustify );
92}
93
94
95EDA_TEXT::EDA_TEXT( const EDA_IU_SCALE& aIuScale, const wxString& aText ) :
96 m_text( aText ),
97 m_IuScale( aIuScale ),
98 m_render_cache_font( nullptr ),
99 m_visible( true )
100{
103
104 if( m_text.IsEmpty() )
105 {
106 m_shown_text = wxEmptyString;
108 }
109 else
110 {
112 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
113 }
114}
115
116
118 m_IuScale( aText.m_IuScale )
119{
120 m_text = aText.m_text;
123
125 m_pos = aText.m_pos;
126 m_visible = aText.m_visible;
127
132
133 m_render_cache.clear();
134
135 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
136 {
137 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
138 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
139 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
140 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
141 }
142
144
146}
147
148
150{
151}
152
153
155{
156 m_text = aText.m_text;
159
161 m_pos = aText.m_pos;
162 m_visible = aText.m_visible;
163
168
169 m_render_cache.clear();
170
171 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
172 {
173 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
174 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
175 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
176 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
177 }
178
180
182
183 return *this;
184}
185
186
187void EDA_TEXT::Serialize( google::protobuf::Any &aContainer ) const
188{
189 using namespace kiapi::common;
190 types::Text text;
191
192 text.set_text( GetText().ToStdString() );
193 text.set_hyperlink( GetHyperlink().ToStdString() );
194 PackVector2( *text.mutable_position(), GetTextPos() );
195
196 types::TextAttributes* attrs = text.mutable_attributes();
197
198 if( GetFont() )
199 attrs->set_font_name( GetFont()->GetName().ToStdString() );
200
201 attrs->set_horizontal_alignment(
202 ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
203
204 attrs->set_vertical_alignment(
205 ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
206
207 attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
208 attrs->set_line_spacing( GetLineSpacing() );
209 attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
210 attrs->set_italic( IsItalic() );
211 attrs->set_bold( IsBold() );
212 attrs->set_underlined( GetAttributes().m_Underlined );
213 attrs->set_visible( true );
214 attrs->set_mirrored( IsMirrored() );
215 attrs->set_multiline( IsMultilineAllowed() );
216 attrs->set_keep_upright( IsKeepUpright() );
217 PackVector2( *attrs->mutable_size(), GetTextSize() );
218
219 aContainer.PackFrom( text );
220}
221
222
223bool EDA_TEXT::Deserialize( const google::protobuf::Any &aContainer )
224{
225 using namespace kiapi::common;
226 types::Text text;
227
228 if( !aContainer.UnpackTo( &text ) )
229 return false;
230
231 SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
232 SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
233 SetTextPos( UnpackVector2( text.position() ) );
234
235 if( text.has_attributes() )
236 {
238
239 attrs.m_Bold = text.attributes().bold();
240 attrs.m_Italic = text.attributes().italic();
241 attrs.m_Underlined = text.attributes().underlined();
242 attrs.m_Mirrored = text.attributes().mirrored();
243 attrs.m_Multiline = text.attributes().multiline();
244 attrs.m_KeepUpright = text.attributes().keep_upright();
245 attrs.m_Size = UnpackVector2( text.attributes().size() );
246
247 if( !text.attributes().font_name().empty() )
248 {
250 wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
251 attrs.m_Italic );
252 }
253
254 attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
255 attrs.m_LineSpacing = text.attributes().line_spacing();
256 attrs.m_StrokeWidth = text.attributes().stroke_width().value_nm();
257 attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
258 text.attributes().horizontal_alignment() );
259
260 attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
261 text.attributes().vertical_alignment() );
262
263 SetAttributes( attrs );
264 }
265
266 return true;
267}
268
269
270void EDA_TEXT::SetText( const wxString& aText )
271{
272 m_text = aText;
274}
275
276
277void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
278{
279 m_text = aSrc.m_text;
281}
282
283
285{
289}
290
291
293{
294 if( GetAutoThickness() != aAuto )
296}
297
298
300{
301 m_attributes.m_Angle = aAngle;
304}
305
306
307void EDA_TEXT::SetItalic( bool aItalic )
308{
309 if( m_attributes.m_Italic != aItalic )
310 {
311 const KIFONT::FONT* font = GetFont();
312
313 if( !font || font->IsStroke() )
314 {
315 // For stroke fonts, just need to set the attribute.
316 }
317 else
318 {
319 // For outline fonts, italic-ness is determined by the font itself.
320 SetFont( KIFONT::FONT::GetFont( font->GetName(), IsBold(), aItalic ) );
321 }
322 }
323
324 SetItalicFlag( aItalic );
325}
326
327void EDA_TEXT::SetItalicFlag( bool aItalic )
328{
329 m_attributes.m_Italic = aItalic;
332}
333
334
335void EDA_TEXT::SetBold( bool aBold )
336{
337 if( m_attributes.m_Bold != aBold )
338 {
339 const KIFONT::FONT* font = GetFont();
340
341 if( !font || font->IsStroke() )
342 {
343 // For stroke fonts, boldness is determined by the pen size.
344 const int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
345
346 if( aBold )
347 {
350 }
351 else
352 {
353 // Restore the original stroke width from `m_StoredStrokeWidth` if it was
354 // previously stored, resetting the width after unbolding.
357 else
358 {
360 // Sets `m_StrokeWidth` to the normal pen size and stores it in
361 // `m_StoredStrokeWidth` as the default, but only if the bold option was
362 // applied before this feature was implemented.
364 }
365 }
366 }
367 else
368 {
369 // For outline fonts, boldness is determined by the font itself.
370 SetFont( KIFONT::FONT::GetFont( font->GetName(), aBold, IsItalic() ) );
371 }
372 }
373
374 SetBoldFlag( aBold );
375}
376
377
378void EDA_TEXT::SetBoldFlag( bool aBold )
379{
380 m_attributes.m_Bold = aBold;
383}
384
385
386void EDA_TEXT::SetVisible( bool aVisible )
387{
388 m_visible = aVisible;
390}
391
392
393void EDA_TEXT::SetMirrored( bool isMirrored )
394{
395 m_attributes.m_Mirrored = isMirrored;
398}
399
400
402{
403 m_attributes.m_Multiline = aAllow;
406}
407
408
410{
411 m_attributes.m_Halign = aType;
414}
415
416
418{
419 m_attributes.m_Valign = aType;
422}
423
424
425void EDA_TEXT::SetKeepUpright( bool aKeepUpright )
426{
427 m_attributes.m_KeepUpright = aKeepUpright;
430}
431
432
433void EDA_TEXT::SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition )
434{
436
437 if( aSetPosition )
438 m_pos = aSrc.m_pos;
439
442}
443
444
445void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
446{
447 std::swap( m_text, aTradingPartner.m_text );
449}
450
451
452void EDA_TEXT::SwapAttributes( EDA_TEXT& aTradingPartner )
453{
454 std::swap( m_attributes, aTradingPartner.m_attributes );
455 std::swap( m_pos, aTradingPartner.m_pos );
456
458 aTradingPartner.ClearRenderCache();
459
461 aTradingPartner.ClearBoundingBoxCache();
462}
463
464
465int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
466{
467 int penWidth = GetTextThickness();
468
469 if( penWidth <= 1 )
470 {
471 penWidth = aDefaultPenWidth;
472
473 if( IsBold() )
474 penWidth = GetPenSizeForBold( GetTextWidth() );
475 else if( penWidth <= 1 )
476 penWidth = GetPenSizeForNormal( GetTextWidth() );
477 }
478
479 // Clip pen size for small texts:
480 penWidth = ClampTextPenSize( penWidth, GetTextSize() );
481
482 return penWidth;
483}
484
485
486bool EDA_TEXT::Replace( const EDA_SEARCH_DATA& aSearchData )
487{
488 bool retval = EDA_ITEM::Replace( aSearchData, m_text );
489
491
494
495 return retval;
496}
497
498
500{
501 m_attributes.m_Font = aFont;
504}
505
506
507bool EDA_TEXT::ResolveFont( const std::vector<wxString>* aEmbeddedFonts )
508{
509 if( !m_unresolvedFontName.IsEmpty() )
510 {
512 aEmbeddedFonts );
513
514 if( !m_render_cache.empty() )
516
517 m_unresolvedFontName = wxEmptyString;
518 return true;
519 }
520
521 return false;
522}
523
524
525void EDA_TEXT::SetLineSpacing( double aLineSpacing )
526{
527 m_attributes.m_LineSpacing = aLineSpacing;
530}
531
532
533void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
534{
535 // Plotting uses unityScale and independently scales the text. If we clamp here we'll
536 // clamp to *really* small values.
537 if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
538 aEnforceMinTextSize = false;
539
540 if( aEnforceMinTextSize )
541 {
542 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
543 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
544
545 aNewSize = VECTOR2I( std::clamp( aNewSize.x, min, max ),
546 std::clamp( aNewSize.y, min, max ) );
547 }
548
549 m_attributes.m_Size = aNewSize;
550
553}
554
555
556void EDA_TEXT::SetTextWidth( int aWidth )
557{
558 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
559 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
560
561 m_attributes.m_Size.x = std::clamp( aWidth, min, max );
564}
565
566
567void EDA_TEXT::SetTextHeight( int aHeight )
568{
569 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
570 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
571
572 m_attributes.m_Size.y = std::clamp( aHeight, min, max );
575}
576
577
578void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
579{
580 Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
581}
582
583
584void EDA_TEXT::SetTextX( int aX )
585{
586 Offset( VECTOR2I( aX - m_pos.x, 0 ) );
587}
588
589
590void EDA_TEXT::SetTextY( int aY )
591{
592 Offset( VECTOR2I( 0, aY - m_pos.y ) );
593}
594
595
596void EDA_TEXT::Offset( const VECTOR2I& aOffset )
597{
598 if( aOffset.x == 0 && aOffset.y == 0 )
599 return;
600
601 m_pos += aOffset;
602
603 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
604 {
605 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
606 outline->Move( aOffset );
607 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
608 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
609 }
610
612}
613
614
616{
617 m_text.Empty();
620}
621
622
624{
625 if( m_text.IsEmpty() )
626 {
627 m_shown_text = wxEmptyString;
629 }
630 else
631 {
633 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
634 }
635
638}
639
640
642{
643 KIFONT::FONT* font = GetFont();
644
645 if( !font )
646 {
647 if( aSettings )
648 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
649 else
650 font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
651 }
652
653 return font;
654}
655
656
658{
660}
661
662
664{
665 m_render_cache.clear();
666}
667
668
670{
671 m_bbox_cache.clear();
672}
673
674
675std::vector<std::unique_ptr<KIFONT::GLYPH>>*
676EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
677 const VECTOR2I& aOffset ) const
678{
679 if( aFont->IsOutline() )
680 {
681 EDA_ANGLE resolvedAngle = GetDrawRotation();
682
683 if( m_render_cache.empty()
684 || m_render_cache_font != aFont
685 || m_render_cache_text != forResolvedText
686 || m_render_cache_angle != resolvedAngle
687 || m_render_cache_offset != aOffset )
688 {
689 m_render_cache.clear();
690
691 const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
693
694 attrs.m_Angle = resolvedAngle;
695
696 font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
697 attrs, getFontMetrics() );
698 m_render_cache_font = aFont;
699 m_render_cache_angle = resolvedAngle;
700 m_render_cache_text = forResolvedText;
701 m_render_cache_offset = aOffset;
702 }
703
704 return &m_render_cache;
705 }
706
707 return nullptr;
708}
709
710
711void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const KIFONT::FONT* aFont,
712 const EDA_ANGLE& aAngle, const VECTOR2I& aOffset )
713{
714 m_render_cache_text = aResolvedText;
715 m_render_cache_font = aFont;
716 m_render_cache_angle = aAngle;
717 m_render_cache_offset = aOffset;
718 m_render_cache.clear();
719}
720
721
723{
724 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
725 static_cast<KIFONT::OUTLINE_GLYPH*>( m_render_cache.back().get() )->CacheTriangulation();
726}
727
728
729int EDA_TEXT::GetInterline( const RENDER_SETTINGS* aSettings ) const
730{
731 return KiROUND( GetDrawFont( aSettings )->GetInterline( GetTextHeight(), getFontMetrics() ) );
732}
733
734
735BOX2I EDA_TEXT::GetTextBox( const RENDER_SETTINGS* aSettings, int aLine ) const
736{
737 VECTOR2I drawPos = GetDrawPos();
738
739 auto cache_it = m_bbox_cache.find( aLine );
740
741 if( cache_it != m_bbox_cache.end() && cache_it->second.m_pos == drawPos )
742 return cache_it->second.m_bbox;
743
744 BOX2I bbox;
745 wxArrayString strings;
746 wxString text = GetShownText( true );
747 int thickness = GetEffectiveTextPenWidth();
748
749 if( IsMultilineAllowed() )
750 {
751 wxStringSplit( text, strings, '\n' );
752
753 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
754 {
755 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
756 text = strings.Item( aLine );
757 else
758 text = strings.Item( 0 );
759 }
760 }
761
762 // calculate the H and V size
763 KIFONT::FONT* font = GetDrawFont( aSettings );
764 VECTOR2D fontSize( GetTextSize() );
765 bool bold = IsBold();
766 bool italic = IsItalic();
767 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, getFontMetrics() );
768 int overbarOffset = 0;
769
770 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
771 // bounding box will be moved later according to the actual text options
772 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
773 VECTOR2I pos = drawPos;
774 int fudgeFactor = KiROUND( extents.y * 0.17 );
775
776 if( font->IsStroke() )
777 textsize.y += fudgeFactor;
778
779 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
780 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
781
782 if( text.Contains( wxT( "~{" ) ) )
783 overbarOffset = extents.y / 6;
784
785 bbox.SetOrigin( pos );
786
787 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
788 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
789 {
790 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
791 {
792 text = strings.Item( ii );
793 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic, getFontMetrics() );
794 textsize.x = std::max( textsize.x, extents.x );
795 }
796
797 // interline spacing is only *between* lines, so total height is the height of the first
798 // line plus the interline distance (with interline spacing) for all subsequent lines
799 textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y, getFontMetrics() ) );
800 }
801
802 textsize.y += overbarOffset;
803
804 bbox.SetSize( textsize );
805
806 /*
807 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
808 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
809 */
810 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
811
812 switch( GetHorizJustify() )
813 {
815 if( IsMirrored() )
816 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
817
818 break;
819
821 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
822 break;
823
825 if( !IsMirrored() )
826 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
827 break;
828
830 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
831 break;
832 }
833
834 switch( GetVertJustify() )
835 {
837 bbox.Offset( 0, -fudgeFactor );
838 break;
839
841 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
842 break;
843
845 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
846 bbox.Offset( 0, fudgeFactor );
847 break;
848
850 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
851 break;
852 }
853
854 bbox.Normalize(); // Make h and v sizes always >= 0
855
856 m_bbox_cache[ aLine ] = { drawPos, bbox };
857
858 return bbox;
859}
860
861
862bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
863{
864 const BOX2I rect = GetTextBox( nullptr ).GetInflated( aAccuracy );
865 const VECTOR2I location = GetRotated( aPoint, GetDrawPos(), -GetDrawRotation() );
866 return rect.Contains( location );
867}
868
869
870bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
871{
872 const BOX2I rect = aRect.GetInflated( aAccuracy );
873
874 if( aContains )
875 return rect.Contains( GetTextBox( nullptr ) );
876
877 return rect.Intersects( GetTextBox( nullptr ), GetDrawRotation() );
878}
879
880
881void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, const COLOR4D& aColor )
882{
883 if( IsMultilineAllowed() )
884 {
885 std::vector<VECTOR2I> positions;
886 wxArrayString strings;
887 wxStringSplit( GetShownText( true ), strings, '\n' );
888
889 positions.reserve( strings.Count() );
890
891 GetLinePositions( aSettings, positions, (int) strings.Count() );
892
893 for( unsigned ii = 0; ii < strings.Count(); ii++ )
894 printOneLineOfText( aSettings, aOffset, aColor, strings[ii], positions[ii] );
895 }
896 else
897 {
898 printOneLineOfText( aSettings, aOffset, aColor, GetShownText( true ), GetDrawPos() );
899 }
900}
901
902
903void EDA_TEXT::GetLinePositions( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPositions,
904 int aLineCount ) const
905{
906 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
907 // to the center of the multiline text block
908
909 VECTOR2I offset; // Offset to next line.
910
911 offset.y = GetInterline( aSettings );
912
913 if( aLineCount > 1 )
914 {
915 switch( GetVertJustify() )
916 {
918 break;
919
921 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
922 break;
923
925 pos.y -= ( aLineCount - 1 ) * offset.y;
926 break;
927
929 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
930 break;
931 }
932 }
933
934 // Rotate the position of the first line around the center of the multiline text block
936
937 // Rotate the offset lines to increase happened in the right direction
938 RotatePoint( offset, GetDrawRotation() );
939
940 for( int ii = 0; ii < aLineCount; ii++ )
941 {
942 aPositions.push_back( (VECTOR2I) pos );
943 pos += offset;
944 }
945}
946
947
948void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
949 const COLOR4D& aColor, const wxString& aText, const VECTOR2I& aPos )
950{
951 wxDC* DC = aSettings->GetPrintDC();
952 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
953
954 VECTOR2I size = GetTextSize();
955
956 if( IsMirrored() )
957 size.x = -size.x;
958
959 KIFONT::FONT* font = GetDrawFont( aSettings );
960
961 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
962 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
963}
964
965
967{
968 int style = 0;
969
970 if( IsItalic() )
971 style = 1;
972
973 if( IsBold() )
974 style += 2;
975
976 wxString stylemsg[4] = {
977 _("Normal"),
978 _("Italic"),
979 _("Bold"),
980 _("Bold+Italic")
981 };
982
983 return stylemsg[style];
984}
985
986
987wxString EDA_TEXT::GetFontName() const
988{
989 if( GetFont() )
990 return GetFont()->GetName();
991 else
992 return wxEmptyString;
993}
994
995
996wxString EDA_TEXT::GetFontProp() const
997{
998 if( KIFONT::FONT* font = GetFont() )
999 return font->GetName();
1000
1001 if( IsEeschemaType( dynamic_cast<const EDA_ITEM*>( this )->Type() ) )
1002 return _( "Default Font" );
1003 else
1004 return KICAD_FONT_NAME;
1005}
1006
1007
1008void EDA_TEXT::SetFontProp( const wxString& aFontName )
1009{
1010 if( IsEeschemaType( dynamic_cast<const EDA_ITEM*>( this )->Type() ) )
1011 {
1012 if( aFontName == _( "Default Font" ) )
1013 SetFont( nullptr );
1014 else
1015 SetFont( KIFONT::FONT::GetFont( aFontName, IsBold(), IsItalic() ) );
1016 }
1017 else
1018 {
1019 if( aFontName == KICAD_FONT_NAME )
1020 SetFont( nullptr );
1021 else
1022 SetFont( KIFONT::FONT::GetFont( aFontName, IsBold(), IsItalic() ) );
1023 }
1024}
1025
1026
1028{
1029 return ( !IsMirrored()
1032 && GetAutoThickness()
1033 && !IsItalic()
1034 && !IsBold()
1035 && !IsMultilineAllowed()
1036 && GetFontName().IsEmpty()
1037 );
1038}
1039
1040
1041void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aControlBits ) const
1042{
1043 aFormatter->Print( "(effects" );
1044
1045 aFormatter->Print( "(font" );
1046
1047 if( GetFont() && !GetFont()->GetName().IsEmpty() )
1048 aFormatter->Print( "(face %s)", aFormatter->Quotew( GetFont()->NameAsToken() ).c_str() );
1049
1050 // Text size
1051 aFormatter->Print( "(size %s %s)",
1054
1055 if( GetLineSpacing() != 1.0 )
1056 {
1057 aFormatter->Print( "(line_spacing %s)",
1058 FormatDouble2Str( GetLineSpacing() ).c_str() );
1059 }
1060
1061 if( !GetAutoThickness() )
1062 {
1063 aFormatter->Print( "(thickness %s)",
1065 }
1066
1067 if( IsBold() )
1068 KICAD_FORMAT::FormatBool( aFormatter, "bold", true );
1069
1070 if( IsItalic() )
1071 KICAD_FORMAT::FormatBool( aFormatter, "italic", true );
1072
1073 if( !( aControlBits & CTL_OMIT_COLOR ) && GetTextColor() != COLOR4D::UNSPECIFIED )
1074 {
1075 aFormatter->Print( "(color %d %d %d %s)",
1076 KiROUND( GetTextColor().r * 255.0 ),
1077 KiROUND( GetTextColor().g * 255.0 ),
1078 KiROUND( GetTextColor().b * 255.0 ),
1079 FormatDouble2Str( GetTextColor().a ).c_str() );
1080 }
1081
1082 aFormatter->Print( ")"); // (font
1083
1086 {
1087 aFormatter->Print( "(justify");
1088
1090 aFormatter->Print( GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
1091
1093 aFormatter->Print( GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
1094
1095 if( IsMirrored() )
1096 aFormatter->Print( " mirror" );
1097
1098 aFormatter->Print( ")" ); // (justify
1099 }
1100
1101 if( !( aControlBits & CTL_OMIT_HYPERLINK ) && HasHyperlink() )
1102 aFormatter->Print( "(href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
1103
1104 aFormatter->Print( ")" ); // (effects
1105}
1106
1107
1108std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
1109 const BOX2I& aBBox,
1110 const EDA_ANGLE& aAngle ) const
1111{
1112 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
1113 KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
1114 KIFONT::FONT* font = GetDrawFont( nullptr );
1115 int penWidth = GetEffectiveTextPenWidth();
1116 wxString shownText( GetShownText( true ) );
1117 VECTOR2I drawPos = GetDrawPos();
1119
1120 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
1121
1122 if( aBBox.GetWidth() )
1123 {
1124 drawPos = aBBox.GetCenter();
1127 attrs.m_Angle = aAngle;
1128 }
1129 else
1130 {
1131 attrs.m_Angle = GetDrawRotation();
1132
1133 if( font->IsOutline() )
1134 cache = GetRenderCache( font, shownText, VECTOR2I() );
1135 }
1136
1137 if( aTriangulate )
1138 {
1139 CALLBACK_GAL callback_gal(
1140 empty_opts,
1141 // Stroke callback
1142 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1143 {
1144 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1145 },
1146 // Triangulation callback
1147 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1148 {
1149 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1150
1151 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1152 triShape->Append( point.x, point.y );
1153
1154 shape->AddShape( triShape );
1155 } );
1156
1157 if( cache )
1158 callback_gal.DrawGlyphs( *cache );
1159 else
1160 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1161 }
1162 else
1163 {
1164 CALLBACK_GAL callback_gal(
1165 empty_opts,
1166 // Stroke callback
1167 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1168 {
1169 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1170 },
1171 // Outline callback
1172 [&]( const SHAPE_LINE_CHAIN& aPoly )
1173 {
1174 shape->AddShape( aPoly.Clone() );
1175 } );
1176
1177 if( cache )
1178 callback_gal.DrawGlyphs( *cache );
1179 else
1180 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1181 }
1182
1183 return shape;
1184}
1185
1186
1187int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1188{
1189 wxCHECK( aOther, 1 );
1190
1191 int val = m_attributes.Compare( aOther->m_attributes );
1192
1193 if( val != 0 )
1194 return val;
1195
1196 if( m_pos.x != aOther->m_pos.x )
1197 return m_pos.x - aOther->m_pos.x;
1198
1199 if( m_pos.y != aOther->m_pos.y )
1200 return m_pos.y - aOther->m_pos.y;
1201
1202 val = GetFontName().Cmp( aOther->GetFontName() );
1203
1204 if( val != 0 )
1205 return val;
1206
1207 return m_text.Cmp( aOther->m_text );
1208}
1209
1210
1211bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1212{
1213 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1214 return true;
1215
1216 wxURI uri;
1217
1218 return( uri.Create( aURL ) && uri.HasScheme() );
1219}
1220
1221double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1222{
1223 // Compute the Levenshtein distance between the two strings
1224 const wxString& str1 = GetText();
1225 const wxString& str2 = aOther.GetText();
1226
1227 int m = str1.length();
1228 int n = str2.length();
1229
1230 if( n == 0 || m == 0 )
1231 return 0.0;
1232
1233 // Create a matrix to store the distance values
1234 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1235
1236 // Initialize the matrix
1237 for( int i = 0; i <= m; i++ )
1238 distance[i][0] = i;
1239 for( int j = 0; j <= n; j++ )
1240 distance[0][j] = j;
1241
1242 // Calculate the distance
1243 for( int i = 1; i <= m; i++ )
1244 {
1245 for( int j = 1; j <= n; j++ )
1246 {
1247 if( str1[i - 1] == str2[j - 1] )
1248 {
1249 distance[i][j] = distance[i - 1][j - 1];
1250 }
1251 else
1252 {
1253 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1254 distance[i - 1][j - 1] } ) + 1;
1255 }
1256 }
1257 }
1258
1259 // Calculate similarity score
1260 int maxLen = std::max( m, n );
1261 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1262
1263 return similarity;
1264}
1265
1266
1267double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1268{
1269 double retval = 1.0;
1270
1271 if( !( m_attributes == aOther.m_attributes ) )
1272 retval *= 0.9;
1273
1274 if( m_pos != aOther.m_pos )
1275 retval *= 0.9;
1276
1277 retval *= Levenshtein( aOther );
1278
1279 return retval;
1280}
1281
1282
1283bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1284{
1285 return aHref.StartsWith( wxT( "#" ), aDestination );
1286}
1287
1288
1289wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1290{
1291 return wxT( "#" ) + aDestination;
1292}
1293
1294
1295std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1296{
1297 aStream << aText.GetText();
1298
1299 return aStream;
1300}
1301
1302
1303static struct EDA_TEXT_DESC
1304{
1306 {
1307 // These are defined in SCH_FIELD as well but initialization order is
1308 // not defined, so this needs to be conditional. Defining in both
1309 // places leads to duplicate symbols.
1311
1312 if( h_inst.Choices().GetCount() == 0)
1313 {
1314 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
1315 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
1316 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
1317 }
1318
1320
1321 if( v_inst.Choices().GetCount() == 0)
1322 {
1323 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
1324 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
1325 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
1326 }
1327
1330
1331 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1333 PROPERTY_DISPLAY::PT_DEGREE ) );
1334
1335 const wxString textProps = _HKI( "Text Properties" );
1336
1337 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1339 textProps );
1340
1341 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Font" ),
1343 textProps )
1345 .SetChoicesFunc( []( INSPECTABLE* aItem )
1346 {
1347 EDA_ITEM* eda_item = static_cast<EDA_ITEM*>( aItem );
1348 wxPGChoices fonts;
1349 std::vector<std::string> fontNames;
1350
1351 Fontconfig()->ListFonts( fontNames,
1352 std::string( Pgm().GetLanguageTag().utf8_str() ),
1353 eda_item->GetEmbeddedFonts() );
1354
1355 if( IsEeschemaType( eda_item->Type() ) )
1356 fonts.Add( _( "Default Font" ) );
1357
1358 fonts.Add( KICAD_FONT_NAME );
1359
1360 for( const std::string& fontName : fontNames )
1361 fonts.Add( wxString( fontName ) );
1362
1363 return fonts;
1364 } );
1365
1366 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Auto Thickness" ),
1368 textProps );
1369 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1371 PROPERTY_DISPLAY::PT_SIZE ),
1372 textProps );
1373 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1376 textProps );
1377 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1379 textProps );
1380 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1382 textProps );
1383
1384 auto isField =
1385 []( INSPECTABLE* aItem ) -> bool
1386 {
1387 if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( aItem ) )
1388 return item->Type() == SCH_FIELD_T || item->Type() == PCB_FIELD_T;
1389
1390 return false;
1391 };
1392
1393 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
1395 textProps )
1396 .SetAvailableFunc( isField );
1397
1398 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1400 PROPERTY_DISPLAY::PT_SIZE ),
1401 textProps );
1402
1403 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1405 PROPERTY_DISPLAY::PT_SIZE ),
1406 textProps );
1407
1409 _HKI( "Horizontal Justification" ),
1411 textProps );
1413 _HKI( "Vertical Justification" ),
1415 textProps );
1416
1417 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1419 textProps );
1420
1421 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1423 textProps );
1424 }
1426
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:115
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:146
constexpr coord_type GetY() const
Definition: box2.h:208
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr coord_type GetX() const
Definition: box2.h:207
constexpr const Vec GetCenter() const
Definition: box2.h:230
constexpr void SetSize(const SizeVec &size)
Definition: box2.h:248
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr bool Contains(const Vec &aPoint) const
Definition: box2.h:168
constexpr void SetX(coord_type val)
Definition: box2.h:277
constexpr BOX2< Vec > GetInflated(coord_type aDx, coord_type aDy) const
Get a new rectangle that is this one, inflated by aDx and aDy.
Definition: box2.h:638
constexpr void SetY(coord_type val)
Definition: box2.h:282
constexpr void Offset(coord_type dx, coord_type dy)
Definition: box2.h:259
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
virtual const std::vector< wxString > * GetEmbeddedFonts()
Definition: eda_item.h:469
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:237
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
int GetTextHeight() const
Definition: eda_text.h:264
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: eda_text.cpp:187
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:266
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:270
COLOR4D GetTextColor() const
Definition: eda_text.h:267
wxString GetTextStyleName() const
Definition: eda_text.cpp:966
VECTOR2I m_pos
Definition: eda_text.h:473
wxString m_text
Definition: eda_text.h:451
std::map< int, BBOX_CACHE_ENTRY > m_bbox_cache
Definition: eda_text.h:469
bool IsDefaultFormatting() const
Definition: eda_text.cpp:1027
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1283
void SetFontProp(const wxString &aFontName)
Definition: eda_text.cpp:1008
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:461
wxString GetFontName() const
Definition: eda_text.cpp:987
virtual ~EDA_TEXT()
Definition: eda_text.cpp:149
bool IsItalic() const
Definition: eda_text.h:166
bool m_visible
Definition: eda_text.h:474
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:533
bool IsMultilineAllowed() const
Definition: eda_text.h:194
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
bool IsKeepUpright() const
Definition: eda_text.h:203
virtual bool IsVisible() const
Definition: eda_text.h:184
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:578
void SetTextX(int aX)
Definition: eda_text.cpp:584
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:453
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: eda_text.cpp:223
KIFONT::FONT * GetFont() const
Definition: eda_text.h:244
bool ResolveFont(const std::vector< wxString > *aEmbeddedFonts)
Definition: eda_text.cpp:507
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:433
wxString m_shown_text
Definition: eda_text.h:452
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:393
wxString GetFontProp() const
Definition: eda_text.cpp:996
void SetTextY(int aY)
Definition: eda_text.cpp:590
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
Definition: eda_text.cpp:676
const KIFONT::FONT * m_render_cache_font
Definition: eda_text.h:458
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:374
wxString m_unresolvedFontName
Definition: eda_text.h:472
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:375
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition: eda_text.cpp:154
int GetTextWidth() const
Definition: eda_text.h:261
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:735
virtual bool HasHyperlink() const
Definition: eda_text.h:397
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:417
wxString GetHyperlink() const
Definition: eda_text.h:398
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:596
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:1041
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:197
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:556
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition: eda_text.cpp:641
void SetBoldFlag(bool aBold)
Set only the bold flag, without changing the font.
Definition: eda_text.cpp:378
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:486
void SetupRenderCache(const wxString &aResolvedText, const KIFONT::FONT *aFont, const EDA_ANGLE &aAngle, const VECTOR2I &aOffset)
Definition: eda_text.cpp:711
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1187
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:455
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:386
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition: eda_text.cpp:95
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1289
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:669
bool GetAutoThickness() const
Definition: eda_text.h:136
double GetLineSpacing() const
Definition: eda_text.h:255
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1267
VECTOR2I m_render_cache_offset
Definition: eda_text.h:460
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:525
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:722
void Empty()
Definition: eda_text.cpp:615
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:284
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:862
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:567
virtual void cacheShownText()
Definition: eda_text.cpp:623
EDA_ANGLE m_render_cache_angle
Definition: eda_text.h:459
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:67
virtual void ClearRenderCache()
Definition: eda_text.cpp:663
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:228
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
Definition: eda_text.cpp:335
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
Definition: eda_text.cpp:1211
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
Definition: eda_text.cpp:327
void SetAutoThickness(bool aAuto)
Definition: eda_text.cpp:292
bool IsMirrored() const
Definition: eda_text.h:187
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:465
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:452
wxString m_render_cache_text
Definition: eda_text.h:457
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor)
Print this text object to the device context aDC.
Definition: eda_text.cpp:881
double GetTextAngleDegrees() const
Definition: eda_text.h:151
void GetLinePositions(const RENDER_SETTINGS *aSettings, std::vector< VECTOR2I > &aPositions, int aLineCount) const
Populate aPositions with the position of each line of a multiline text, according to the vertical jus...
Definition: eda_text.cpp:903
virtual const KIFONT::METRICS & getFontMetrics() const
Definition: eda_text.cpp:657
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
build a list of segments (SHAPE_SEGMENT) to describe a text shape.
Definition: eda_text.cpp:1108
bool IsBold() const
Definition: eda_text.h:181
void SetTextAngleDegrees(double aOrientation)
Definition: eda_text.h:147
void SetHyperlink(wxString aLink)
Definition: eda_text.h:399
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:81
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:425
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:277
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:200
int GetInterline(const RENDER_SETTINGS *aSettings) const
Return the distance between two lines of text.
Definition: eda_text.cpp:729
int GetTextThicknessProperty() const
Definition: eda_text.h:127
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:108
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:270
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
Definition: eda_text.cpp:1221
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:299
int GetTextThickness() const
Definition: eda_text.h:125
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:307
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:445
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:401
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:499
void printOneLineOfText(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, const wxString &aText, const VECTOR2I &aPos)
Print each line of this EDA_TEXT.
Definition: eda_text.cpp:948
VECTOR2I GetTextSize() const
Definition: eda_text.h:258
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:409
TEXT_ATTRIBUTES m_attributes
Definition: eda_text.h:471
static ENUM_MAP< T > & Instance()
Definition: property.h:697
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:37
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition: font.cpp:147
virtual bool IsStroke() const
Definition: font.h:138
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
Definition: font.cpp:250
const wxString & GetName() const
Definition: font.h:149
virtual bool IsOutline() const
Definition: font.h:139
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
Definition: font.cpp:427
virtual double GetInterline(double aGlyphHeight, const METRICS &aFontMetrics) const =0
Compute the distance (interline) between 2 lines of text (for multiline texts).
static const METRICS & Default()
Definition: font.cpp:52
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:53
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
const wxString & GetDefaultFont() const
wxDC * GetPrintDC() const
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:548
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:463
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
Definition: property.h:272
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition: property.h:258
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:322
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:74
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:76
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition: shape_simple.h:42
void Append(int aX, int aY)
Append a new point at the end of the polygon.
Definition: shape_simple.h:135
int Compare(const TEXT_ATTRIBUTES &aRhs) const
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
KIFONT::FONT * m_Font
#define CTL_OMIT_HYPERLINK
Omit the hyperlink attribute in .kicad_xxx files.
Definition: ctl_flags.h:46
#define CTL_OMIT_COLOR
Omit the color attribute in .kicad_xxx files.
Definition: ctl_flags.h:45
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:411
@ DEGREES_T
Definition: eda_angle.h:31
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1295
static struct EDA_TEXT_DESC _EDA_TEXT_DESC
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
Definition: eda_text.h:46
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition: eda_text.h:47
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:69
static constexpr double ITALIC_TILT
Tilt factor for italic style (this is the scaling factor on dY relative coordinates to give a tilted ...
Definition: font.h:61
FONTCONFIG * Fontconfig()
Definition: fontconfig.cpp:103
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:36
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:60
void GRPrintText(wxDC *aDC, const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Print a graphic text through wxDC.
Definition: gr_text.cpp:109
int ClampTextPenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
Definition: gr_text.cpp:72
Some functions to handle hotkeys in KiCad.
#define KICAD_FONT_NAME
constexpr int Mils2IU(const EDA_IU_SCALE &aIuScale, int mils)
Definition: eda_units.h:166
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:194
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:902
see class PGM_BASE
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:799
#define REGISTER_TYPE(x)
Definition: property_mgr.h:351
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
wxString UnescapeString(const wxString &aSource)
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
const double IU_PER_MM
Definition: base_units.h:76
VECTOR2I location
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
Definition: trigo.h:77
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:229
@ SCH_FIELD_T
Definition: typeinfo.h:151
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition: typeinfo.h:90
constexpr bool IsEeschemaType(const KICAD_T aType)
Definition: typeinfo.h:369
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695