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