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 (C) 2004-2023 KiCad Developers, see change_log.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
52#include <wx/debug.h> // for wxASSERT
53#include <wx/string.h>
54#include <wx/url.h> // for wxURL
56#include "font/fontconfig.h"
57#include "pgm_base.h"
58
59class OUTPUTFORMATTER;
60class wxFindReplaceData;
61
62
64{
65 wxASSERT( aHorizJustify >= GR_TEXT_H_ALIGN_LEFT && aHorizJustify <= GR_TEXT_H_ALIGN_RIGHT );
66
67 if( aHorizJustify > GR_TEXT_H_ALIGN_RIGHT )
69
70 if( aHorizJustify < GR_TEXT_H_ALIGN_LEFT )
72
73 return static_cast<GR_TEXT_H_ALIGN_T>( aHorizJustify );
74}
75
76
78{
79 wxASSERT( aVertJustify >= GR_TEXT_V_ALIGN_TOP && aVertJustify <= GR_TEXT_V_ALIGN_BOTTOM );
80
81 if( aVertJustify > GR_TEXT_V_ALIGN_BOTTOM )
83
84 if( aVertJustify < GR_TEXT_V_ALIGN_TOP )
86
87 return static_cast<GR_TEXT_V_ALIGN_T>( aVertJustify );
88}
89
90
91EDA_TEXT::EDA_TEXT( const EDA_IU_SCALE& aIuScale, const wxString& aText ) :
92 m_text( aText ),
93 m_IuScale( aIuScale ),
94 m_render_cache_font( nullptr ),
95 m_bounding_box_cache_valid( false ),
96 m_bounding_box_cache_line( -1 )
97{
100
101 if( m_text.IsEmpty() )
102 {
103 m_shown_text = wxEmptyString;
105 }
106 else
107 {
109 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
110 }
111}
112
113
115 m_IuScale( aText.m_IuScale )
116{
117 m_text = aText.m_text;
120
122 m_pos = aText.m_pos;
123
128
129 m_render_cache.clear();
130
131 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
132 {
133 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
134 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
135 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
136 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
137 }
138
142}
143
144
146{
147}
148
149
151{
152 m_text = aText.m_text;
155
157 m_pos = aText.m_pos;
158
163
164 m_render_cache.clear();
165
166 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
167 {
168 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
169 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
170 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
171 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
172 }
173
176
177 return *this;
178}
179
180
181void EDA_TEXT::SetText( const wxString& aText )
182{
183 m_text = aText;
185}
186
187
188void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
189{
190 m_text = aSrc.m_text;
192}
193
194
196{
200}
201
202
204{
205 m_attributes.m_Angle = aAngle;
208}
209
210
211void EDA_TEXT::SetItalic( bool aItalic )
212{
213 m_attributes.m_Italic = aItalic;
216}
217
218
219void EDA_TEXT::SetBold( bool aBold )
220{
221 if( m_attributes.m_Bold != aBold )
222 {
223 int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
224
225 if( aBold )
227 else
229 }
230
231 SetBoldFlag( aBold );
232}
233
234
235void EDA_TEXT::SetBoldFlag( bool aBold )
236{
237 m_attributes.m_Bold = aBold;
240}
241
242
243void EDA_TEXT::SetVisible( bool aVisible )
244{
245 m_attributes.m_Visible = aVisible;
247}
248
249
250void EDA_TEXT::SetMirrored( bool isMirrored )
251{
252 m_attributes.m_Mirrored = isMirrored;
255}
256
257
259{
260 m_attributes.m_Multiline = aAllow;
263}
264
265
267{
268 m_attributes.m_Halign = aType;
271}
272
273
275{
276 m_attributes.m_Valign = aType;
279}
280
281
282void EDA_TEXT::SetKeepUpright( bool aKeepUpright )
283{
284 m_attributes.m_KeepUpright = aKeepUpright;
287}
288
289
290void EDA_TEXT::SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition )
291{
293
294 if( aSetPosition )
295 m_pos = aSrc.m_pos;
296
299}
300
301
302void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
303{
304 std::swap( m_text, aTradingPartner.m_text );
306}
307
308
309void EDA_TEXT::SwapAttributes( EDA_TEXT& aTradingPartner )
310{
311 std::swap( m_attributes, aTradingPartner.m_attributes );
312 std::swap( m_pos, aTradingPartner.m_pos );
313
315 aTradingPartner.ClearRenderCache();
316
318 aTradingPartner.m_bounding_box_cache_valid = false;
319}
320
321
322int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
323{
324 int penWidth = GetTextThickness();
325
326 if( penWidth <= 1 )
327 {
328 penWidth = aDefaultPenWidth;
329
330 if( IsBold() )
331 penWidth = GetPenSizeForBold( GetTextWidth() );
332 else if( penWidth <= 1 )
333 penWidth = GetPenSizeForNormal( GetTextWidth() );
334 }
335
336 // Clip pen size for small texts:
337 penWidth = Clamp_Text_PenSize( penWidth, GetTextSize() );
338
339 return penWidth;
340}
341
342
343bool EDA_TEXT::Replace( const EDA_SEARCH_DATA& aSearchData )
344{
345 bool retval = EDA_ITEM::Replace( aSearchData, m_text );
346
348
351
352 return retval;
353}
354
355
357{
358 m_attributes.m_Font = aFont;
361}
362
363
364void EDA_TEXT::SetLineSpacing( double aLineSpacing )
365{
366 m_attributes.m_LineSpacing = aLineSpacing;
369}
370
371
372void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
373{
374 // Plotting uses unityScale and independently scales the text. If we clamp here we'll
375 // clamp to *really* small values.
376 if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
377 aEnforceMinTextSize = false;
378
379 if( aEnforceMinTextSize )
380 {
381 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
382 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
383
384 aNewSize = VECTOR2I( alg::clamp( min, aNewSize.x, max ),
385 alg::clamp( min, aNewSize.y, max ) );
386 }
387
388 m_attributes.m_Size = aNewSize;
389
392}
393
394
395void EDA_TEXT::SetTextWidth( int aWidth )
396{
397 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
398 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
399
400 m_attributes.m_Size.x = alg::clamp( min, aWidth, max );
403}
404
405
406void EDA_TEXT::SetTextHeight( int aHeight )
407{
408 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
409 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
410
411 m_attributes.m_Size.y = alg::clamp( min, aHeight, max );
414}
415
416
417void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
418{
419 Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
420}
421
422
423void EDA_TEXT::SetTextX( int aX )
424{
425 Offset( VECTOR2I( aX - m_pos.x, 0 ) );
426}
427
428
429void EDA_TEXT::SetTextY( int aY )
430{
431 Offset( VECTOR2I( 0, aY - m_pos.y ) );
432}
433
434
435void EDA_TEXT::Offset( const VECTOR2I& aOffset )
436{
437 if( aOffset.x == 0 && aOffset.y == 0 )
438 return;
439
440 m_pos += aOffset;
441
442 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
443 {
444 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
445 outline->Move( aOffset );
446 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
447 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
448 }
449
451}
452
453
455{
456 m_text.Empty();
459}
460
461
463{
464 if( m_text.IsEmpty() )
465 {
466 m_shown_text = wxEmptyString;
468 }
469 else
470 {
472 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
473 }
474
477}
478
479
481{
482 KIFONT::FONT* font = GetFont();
483
484 if( !font )
485 font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
486
487 return font;
488}
489
490
492{
494}
495
496
498{
499 m_render_cache.clear();
500}
501
502
504{
506}
507
508
509std::vector<std::unique_ptr<KIFONT::GLYPH>>*
510EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
511 const VECTOR2I& aOffset ) const
512{
513 if( aFont->IsOutline() )
514 {
515 EDA_ANGLE resolvedAngle = GetDrawRotation();
516
517 if( m_render_cache.empty()
518 || m_render_cache_font != aFont
519 || m_render_cache_text != forResolvedText
520 || m_render_cache_angle != resolvedAngle
521 || m_render_cache_offset != aOffset )
522 {
523 m_render_cache.clear();
524
525 const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
527
528 attrs.m_Angle = resolvedAngle;
529
530 font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
531 attrs, getFontMetrics() );
532 m_render_cache_font = aFont;
533 m_render_cache_angle = resolvedAngle;
534 m_render_cache_text = forResolvedText;
535 m_render_cache_offset = aOffset;
536 }
537
538 return &m_render_cache;
539 }
540
541 return nullptr;
542}
543
544
545void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const KIFONT::FONT* aFont,
546 const EDA_ANGLE& aAngle, const VECTOR2I& aOffset )
547{
548 m_render_cache_text = aResolvedText;
549 m_render_cache_font = aFont;
550 m_render_cache_angle = aAngle;
551 m_render_cache_offset = aOffset;
552 m_render_cache.clear();
553}
554
555
557{
558 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
559 static_cast<KIFONT::OUTLINE_GLYPH*>( m_render_cache.back().get() )->CacheTriangulation();
560}
561
562
564{
566}
567
568
569BOX2I EDA_TEXT::GetTextBox( int aLine ) const
570{
571 VECTOR2I drawPos = GetDrawPos();
572
574 && m_bounding_box_cache_pos == drawPos
575 && m_bounding_box_cache_line == aLine )
576 {
578 }
579
580 BOX2I bbox;
581 wxArrayString strings;
582 wxString text = GetShownText( true );
583 int thickness = GetEffectiveTextPenWidth();
584
585 if( IsMultilineAllowed() )
586 {
587 wxStringSplit( text, strings, '\n' );
588
589 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
590 {
591 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
592 text = strings.Item( aLine );
593 else
594 text = strings.Item( 0 );
595 }
596 }
597
598 // calculate the H and V size
599 KIFONT::FONT* font = getDrawFont();
600 VECTOR2D fontSize( GetTextSize() );
601 bool bold = IsBold();
602 bool italic = IsItalic();
603 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
604 getFontMetrics() );
605 int overbarOffset = 0;
606
607 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
608 // bounding box will be moved later according to the actual text options
609 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
610 VECTOR2I pos = drawPos;
611 int fudgeFactor = KiROUND( extents.y * 0.17 );
612
613 if( font->IsStroke() )
614 textsize.y += fudgeFactor;
615
616 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
617 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
618
619 if( text.Contains( wxT( "~{" ) ) )
620 overbarOffset = extents.y / 6;
621
622 bbox.SetOrigin( pos );
623
624 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
625 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
626 {
627 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
628 {
629 text = strings.Item( ii );
630 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
631 getFontMetrics() );
632 textsize.x = std::max( textsize.x, extents.x );
633 }
634
635 // interline spacing is only *between* lines, so total height is the height of the first
636 // line plus the interline distance (with interline spacing) for all subsequent lines
637 textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y,
638 getFontMetrics() ) );
639 }
640
641 textsize.y += overbarOffset;
642
643 bbox.SetSize( textsize );
644
645 /*
646 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
647 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
648 */
649 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
650
651 switch( GetHorizJustify() )
652 {
654 if( IsMirrored() )
655 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
656 break;
657
659 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
660 break;
661
663 if( !IsMirrored() )
664 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
665 break;
666
668 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
669 break;
670 }
671
672 switch( GetVertJustify() )
673 {
675 bbox.Offset( 0, -fudgeFactor );
676 break;
677
679 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
680 break;
681
683 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
684 bbox.Offset( 0, fudgeFactor );
685 break;
686
688 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
689 break;
690 }
691
692 bbox.Normalize(); // Make h and v sizes always >= 0
693
695 m_bounding_box_cache_pos = drawPos;
698
699 return bbox;
700}
701
702
703bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
704{
705 BOX2I rect = GetTextBox();
706 VECTOR2I location = aPoint;
707
708 rect.Inflate( aAccuracy );
709 RotatePoint( location, GetDrawPos(), -GetDrawRotation() );
710
711 return rect.Contains( location );
712}
713
714
715bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
716{
717 BOX2I rect = aRect;
718
719 rect.Inflate( aAccuracy );
720
721 if( aContains )
722 return rect.Contains( GetTextBox() );
723
724 return rect.Intersects( GetTextBox(), GetDrawRotation() );
725}
726
727
728void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
729 const COLOR4D& aColor, OUTLINE_MODE aFillMode )
730{
731 if( IsMultilineAllowed() )
732 {
733 std::vector<VECTOR2I> positions;
734 wxArrayString strings;
735 wxStringSplit( GetShownText( true ), strings, '\n' );
736
737 positions.reserve( strings.Count() );
738
739 GetLinePositions( positions, (int) strings.Count() );
740
741 for( unsigned ii = 0; ii < strings.Count(); ii++ )
742 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
743 }
744 else
745 {
746 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
747 GetDrawPos() );
748 }
749}
750
751
752void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
753{
754 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
755 // to the center of the multiline text block
756
757 VECTOR2I offset; // Offset to next line.
758
759 offset.y = GetInterline();
760
761 if( aLineCount > 1 )
762 {
763 switch( GetVertJustify() )
764 {
766 break;
767
769 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
770 break;
771
773 pos.y -= ( aLineCount - 1 ) * offset.y;
774 break;
775
777 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
778 break;
779 }
780 }
781
782 // Rotate the position of the first line around the center of the multiline text block
784
785 // Rotate the offset lines to increase happened in the right direction
786 RotatePoint( offset, GetDrawRotation() );
787
788 for( int ii = 0; ii < aLineCount; ii++ )
789 {
790 aPositions.push_back( (VECTOR2I) pos );
791 pos += offset;
792 }
793}
794
795
796void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
797 const COLOR4D& aColor, OUTLINE_MODE aFillMode,
798 const wxString& aText, const VECTOR2I& aPos )
799{
800 wxDC* DC = aSettings->GetPrintDC();
801 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
802
803 if( aFillMode == SKETCH )
804 penWidth = -penWidth;
805
806 VECTOR2I size = GetTextSize();
807
808 if( IsMirrored() )
809 size.x = -size.x;
810
811 KIFONT::FONT* font = GetFont();
812
813 if( !font )
814 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
815
816 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
817 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
818}
819
820
822{
823 int style = 0;
824
825 if( IsItalic() )
826 style = 1;
827
828 if( IsBold() )
829 style += 2;
830
831 wxString stylemsg[4] = {
832 _("Normal"),
833 _("Italic"),
834 _("Bold"),
835 _("Bold+Italic")
836 };
837
838 return stylemsg[style];
839}
840
841
842wxString EDA_TEXT::GetFontName() const
843{
844 if( GetFont() )
845 return GetFont()->GetName();
846 else
847 return wxEmptyString;
848}
849
850
852{
853 if( !GetFont() )
854 return -1;
855
856 if( GetFont()->GetName() == KICAD_FONT_NAME )
857 return -2;
858
859 std::vector<std::string> fontNames;
860 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
861
862 for( int ii = 0; ii < (int) fontNames.size(); ++ii )
863 {
864 if( fontNames[ii] == GetFont()->GetName() )
865 return ii;
866 }
867
868 return 0;
869}
870
871
873{
874 if( aIdx == -1 )
875 {
876 SetFont( nullptr );
877 }
878 else if( aIdx == -2 )
879 {
880 SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
881 }
882 else
883 {
884 std::vector<std::string> fontNames;
885 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
886
887 if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
888 SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
889 else
890 SetFont( nullptr );
891 }
892}
893
894
896{
897 return ( IsVisible()
898 && !IsMirrored()
901 && GetTextThickness() == 0
902 && !IsItalic()
903 && !IsBold()
905 && GetFontName().IsEmpty()
906 );
907}
908
909
910void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
911{
912 aFormatter->Print( aNestLevel + 1, "(effects" );
913
914 aFormatter->Print( 0, " (font" );
915
916 if( GetFont() && !GetFont()->GetName().IsEmpty() )
917 aFormatter->Print( 0, " (face \"%s\")", GetFont()->NameAsToken() );
918
919 // Text size
920 aFormatter->Print( 0, " (size %s %s)",
923
924 if( GetLineSpacing() != 1.0 )
925 {
926 aFormatter->Print( 0, " (line_spacing %s)",
927 FormatDouble2Str( GetLineSpacing() ).c_str() );
928 }
929
930 if( GetTextThickness() )
931 {
932 aFormatter->Print( 0, " (thickness %s)",
934 }
935
936 if( IsBold() )
937 aFormatter->Print( 0, " (bold yes)" );
938
939 if( IsItalic() )
940 aFormatter->Print( 0, " (italic yes)" );
941
942 if( GetTextColor() != COLOR4D::UNSPECIFIED )
943 {
944 aFormatter->Print( 0, " (color %d %d %d %s)",
945 KiROUND( GetTextColor().r * 255.0 ),
946 KiROUND( GetTextColor().g * 255.0 ),
947 KiROUND( GetTextColor().b * 255.0 ),
948 FormatDouble2Str( GetTextColor().a ).c_str() );
949 }
950
951 aFormatter->Print( 0, ")"); // (font
952
955 {
956 aFormatter->Print( 0, " (justify");
957
959 aFormatter->Print( 0, GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
960
962 aFormatter->Print( 0, GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
963
964 if( IsMirrored() )
965 aFormatter->Print( 0, " mirror" );
966
967 aFormatter->Print( 0, ")" ); // (justify
968 }
969
970 if( !( aControlBits & CTL_OMIT_HIDE ) && !IsVisible() )
971 aFormatter->Print( 0, " (hide yes)" );
972
973 if( HasHyperlink() )
974 {
975 aFormatter->Print( 0, " (href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
976 }
977
978 aFormatter->Print( 0, ")\n" ); // (effects
979}
980
981
982std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
983 const BOX2I& aBBox,
984 const EDA_ANGLE& aAngle ) const
985{
986 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
988 KIFONT::FONT* font = getDrawFont();
989 int penWidth = GetEffectiveTextPenWidth();
990 wxString shownText( GetShownText( true ) );
991 VECTOR2I drawPos = GetDrawPos();
993
994 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
995
996 if( aBBox.GetWidth() )
997 {
998 drawPos = aBBox.GetCenter();
1001 attrs.m_Angle = aAngle;
1002 }
1003 else
1004 {
1005 attrs.m_Angle = GetDrawRotation();
1006
1007 if( font->IsOutline() )
1008 cache = GetRenderCache( font, shownText, VECTOR2I() );
1009 }
1010
1011 if( aTriangulate )
1012 {
1013 CALLBACK_GAL callback_gal(
1014 empty_opts,
1015 // Stroke callback
1016 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1017 {
1018 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1019 },
1020 // Triangulation callback
1021 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1022 {
1023 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1024
1025 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1026 triShape->Append( point.x, point.y );
1027
1028 shape->AddShape( triShape );
1029 } );
1030
1031 if( cache )
1032 callback_gal.DrawGlyphs( *cache );
1033 else
1034 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1035 }
1036 else
1037 {
1038 CALLBACK_GAL callback_gal(
1039 empty_opts,
1040 // Stroke callback
1041 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1042 {
1043 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1044 },
1045 // Outline callback
1046 [&]( const SHAPE_LINE_CHAIN& aPoly )
1047 {
1048 shape->AddShape( aPoly.Clone() );
1049 } );
1050
1051 if( cache )
1052 callback_gal.DrawGlyphs( *cache );
1053 else
1054 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1055 }
1056
1057 return shape;
1058}
1059
1060
1061int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1062{
1063 wxCHECK( aOther, 1 );
1064
1065 int val = m_attributes.Compare( aOther->m_attributes );
1066
1067 if( val != 0 )
1068 return val;
1069
1070 if( m_pos.x != aOther->m_pos.x )
1071 return m_pos.x - aOther->m_pos.x;
1072
1073 if( m_pos.y != aOther->m_pos.y )
1074 return m_pos.y - aOther->m_pos.y;
1075
1076 val = GetFontName().Cmp( aOther->GetFontName() );
1077
1078 if( val != 0 )
1079 return val;
1080
1081 return m_text.Cmp( aOther->m_text );
1082}
1083
1084
1085bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1086{
1087 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1088 return true;
1089
1090 wxURI uri;
1091
1092 return( uri.Create( aURL ) && uri.HasScheme() );
1093}
1094
1095double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1096{
1097 // Compute the Levenshtein distance between the two strings
1098 const wxString& str1 = GetText();
1099 const wxString& str2 = aOther.GetText();
1100
1101 int m = str1.length();
1102 int n = str2.length();
1103
1104 if( n == 0 || m == 0 )
1105 return 0.0;
1106
1107 // Create a matrix to store the distance values
1108 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1109
1110 // Initialize the matrix
1111 for( int i = 0; i <= m; i++ )
1112 distance[i][0] = i;
1113 for( int j = 0; j <= n; j++ )
1114 distance[0][j] = j;
1115
1116 // Calculate the distance
1117 for( int i = 1; i <= m; i++ )
1118 {
1119 for( int j = 1; j <= n; j++ )
1120 {
1121 if( str1[i - 1] == str2[j - 1] )
1122 {
1123 distance[i][j] = distance[i - 1][j - 1];
1124 }
1125 else
1126 {
1127 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1128 distance[i - 1][j - 1] } ) + 1;
1129 }
1130 }
1131 }
1132
1133 // Calculate similarity score
1134 int maxLen = std::max( m, n );
1135 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1136
1137 return similarity;
1138}
1139
1140
1141double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1142{
1143 double retval = 1.0;
1144
1145 if( !( m_attributes == aOther.m_attributes ) )
1146 retval *= 0.9;
1147
1148 if( m_pos != aOther.m_pos )
1149 retval *= 0.9;
1150
1151 retval *= Levenshtein( aOther );
1152
1153 return retval;
1154}
1155
1156
1157bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1158{
1159 return aHref.StartsWith( wxT( "#" ), aDestination );
1160}
1161
1162
1163wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1164{
1165 return wxT( "#" ) + aDestination;
1166}
1167
1168
1169std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1170{
1171 aStream << aText.GetText();
1172
1173 return aStream;
1174}
1175
1176
1177static struct EDA_TEXT_DESC
1178{
1180 {
1181 // These are defined in SCH_FIELD as well but initialization order is
1182 // not defined, so this needs to be conditional. Defining in both
1183 // places leads to duplicate symbols.
1185
1186 if( h_inst.Choices().GetCount() == 0)
1187 {
1188 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
1189 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
1190 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
1191 }
1192
1194
1195 if( v_inst.Choices().GetCount() == 0)
1196 {
1197 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
1198 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
1199 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
1200 }
1201
1204
1205 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1207 PROPERTY_DISPLAY::PT_DEGREE ) );
1208
1209 const wxString textProps = _HKI( "Text Properties" );
1210
1211 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1213 textProps );
1214
1215 // This must be a PROPERTY_ENUM to get a choice list.
1216 // SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
1217 propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
1219 textProps )
1221
1222 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1224 PROPERTY_DISPLAY::PT_SIZE ),
1225 textProps );
1226 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1229 textProps );
1230 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1232 textProps );
1233 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1235 textProps );
1236 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
1238 textProps );
1239 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1241 PROPERTY_DISPLAY::PT_SIZE ),
1242 textProps );
1243
1244 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1246 PROPERTY_DISPLAY::PT_SIZE ),
1247 textProps );
1248
1250 _HKI( "Horizontal Justification" ),
1252 textProps );
1254 _HKI( "Vertical Justification" ),
1256 textProps );
1257
1258 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1260 textProps );
1261
1262 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1264 textProps );
1265 }
1267
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:111
void SetOrigin(const Vec &pos)
Definition: box2.h:227
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:136
void SetSize(const SizeVec &size)
Definition: box2.h:238
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:249
size_type GetHeight() const
Definition: box2.h:205
void SetX(coord_type val)
Definition: box2.h:260
const Vec GetCenter() const
Definition: box2.h:220
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:294
void SetY(coord_type val)
Definition: box2.h:265
size_type GetWidth() const
Definition: box2.h:204
coord_type GetY() const
Definition: box2.h:198
bool Contains(const Vec &aPoint) const
Definition: box2.h:158
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
coord_type GetX() const
Definition: box2.h:197
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:186
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
int GetTextHeight() const
Definition: eda_text.h:228
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:230
COLOR4D GetTextColor() const
Definition: eda_text.h:231
wxString GetTextStyleName() const
Definition: eda_text.cpp:821
VECTOR2I m_pos
Definition: eda_text.h:437
wxString m_text
Definition: eda_text.h:419
bool IsDefaultFormatting() const
Definition: eda_text.cpp:895
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1157
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:429
wxString GetFontName() const
Definition: eda_text.cpp:842
virtual ~EDA_TEXT()
Definition: eda_text.cpp:145
bool IsItalic() const
Definition: eda_text.h:144
BOX2I m_bounding_box_cache
Definition: eda_text.h:434
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:372
bool IsMultilineAllowed() const
Definition: eda_text.h:161
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:563
virtual bool IsVisible() const
Definition: eda_text.h:151
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:417
void SetTextX(int aX)
Definition: eda_text.cpp:423
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:421
KIFONT::FONT * GetFont() const
Definition: eda_text.h:211
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:290
wxString m_shown_text
Definition: eda_text.h:420
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:910
int GetFontIndex() const
Definition: eda_text.cpp:851
BOX2I GetTextBox(int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:569
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:250
void SetTextY(int aY)
Definition: eda_text.cpp:429
int m_bounding_box_cache_line
Definition: eda_text.h:433
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:510
const KIFONT::FONT * m_render_cache_font
Definition: eda_text.h:426
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:340
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:341
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition: eda_text.cpp:150
void printOneLineOfText(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, OUTLINE_MODE aFillMode, const wxString &aText, const VECTOR2I &aPos)
Print each line of this EDA_TEXT.
Definition: eda_text.cpp:796
int GetTextWidth() const
Definition: eda_text.h:225
virtual bool HasHyperlink() const
Definition: eda_text.h:361
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:274
wxString GetHyperlink() const
Definition: eda_text.h:362
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:435
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:164
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:395
void SetBoldFlag(bool aBold)
Definition: eda_text.cpp:235
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:343
void SetupRenderCache(const wxString &aResolvedText, const KIFONT::FONT *aFont, const EDA_ANGLE &aAngle, const VECTOR2I &aOffset)
Definition: eda_text.cpp:545
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1061
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:423
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:243
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition: eda_text.cpp:91
bool m_bounding_box_cache_valid
Definition: eda_text.h:431
void GetLinePositions(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:752
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1163
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:503
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:480
double GetLineSpacing() const
Definition: eda_text.h:219
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1141
VECTOR2I m_render_cache_offset
Definition: eda_text.h:428
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:364
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:556
void Empty()
Definition: eda_text.cpp:454
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:195
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:703
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:406
virtual void cacheShownText()
Definition: eda_text.cpp:462
EDA_ANGLE m_render_cache_angle
Definition: eda_text.h:427
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:63
virtual void ClearRenderCache()
Definition: eda_text.cpp:497
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:195
void SetBold(bool aBold)
Definition: eda_text.cpp:219
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
Definition: eda_text.cpp:1085
VECTOR2I m_bounding_box_cache_pos
Definition: eda_text.h:432
bool IsMirrored() const
Definition: eda_text.h:154
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:322
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:309
wxString m_render_cache_text
Definition: eda_text.h:425
double GetTextAngleDegrees() const
Definition: eda_text.h:141
virtual const KIFONT::METRICS & getFontMetrics() const
Definition: eda_text.cpp:491
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:982
bool IsBold() const
Definition: eda_text.h:148
void SetTextAngleDegrees(double aOrientation)
Definition: eda_text.h:137
void SetHyperlink(wxString aLink)
Definition: eda_text.h:363
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:77
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:282
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:188
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:167
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:109
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:181
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
Definition: eda_text.cpp:1095
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:203
void SetFontIndex(int aIdx)
Definition: eda_text.cpp:872
int GetTextThickness() const
Definition: eda_text.h:126
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:728
void SetItalic(bool aItalic)
Definition: eda_text.cpp:211
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:302
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:258
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:356
VECTOR2I GetTextSize() const
Definition: eda_text.h:222
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:266
TEXT_ATTRIBUTES m_attributes
Definition: eda_text.h:436
static ENUM_MAP< T > & Instance()
Definition: property.h:663
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)
Definition: font.cpp:146
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:257
const wxString & GetName() const
Definition: font.h:147
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:434
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:52
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:526
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:307
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
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 _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1169
static struct EDA_TEXT_DESC _EDA_TEXT_DESC
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
Definition: eda_text.h:45
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition: eda_text.h:46
#define CTL_OMIT_HIDE
Definition: eda_text.h:66
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:73
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:90
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:64
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
Definition: gr_text.cpp:87
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:142
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:157
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:169
T clamp(T min, T value, T max)
Definition: kicad_algo.h:205
OUTLINE_MODE
Definition: outline_mode.h:25
@ SKETCH
Definition: outline_mode.h:26
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:765
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
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
GR_TEXT_H_ALIGN_T
@ 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
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
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:228
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118
VECTOR2< int > VECTOR2I
Definition: vector2d.h:602