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 EDA_ANGLE& aAngle )
546{
547 m_render_cache_text = aResolvedText;
548 m_render_cache_angle = aAngle;
549 m_render_cache.clear();
550}
551
552
554{
555 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
556}
557
558
560{
562}
563
564
565BOX2I EDA_TEXT::GetTextBox( int aLine ) const
566{
567 VECTOR2I drawPos = GetDrawPos();
568
570 && m_bounding_box_cache_pos == drawPos
571 && m_bounding_box_cache_line == aLine )
572 {
574 }
575
576 BOX2I bbox;
577 wxArrayString strings;
578 wxString text = GetShownText( true );
579 int thickness = GetEffectiveTextPenWidth();
580
581 if( IsMultilineAllowed() )
582 {
583 wxStringSplit( text, strings, '\n' );
584
585 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
586 {
587 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
588 text = strings.Item( aLine );
589 else
590 text = strings.Item( 0 );
591 }
592 }
593
594 // calculate the H and V size
595 KIFONT::FONT* font = getDrawFont();
596 VECTOR2D fontSize( GetTextSize() );
597 bool bold = IsBold();
598 bool italic = IsItalic();
599 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
600 getFontMetrics() );
601 int overbarOffset = 0;
602
603 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
604 // bounding box will be moved later according to the actual text options
605 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
606 VECTOR2I pos = drawPos;
607 int fudgeFactor = KiROUND( extents.y * 0.17 );
608
609 if( font->IsStroke() )
610 textsize.y += fudgeFactor;
611
612 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
613 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
614
615 if( text.Contains( wxT( "~{" ) ) )
616 overbarOffset = extents.y / 6;
617
618 bbox.SetOrigin( pos );
619
620 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
621 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
622 {
623 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
624 {
625 text = strings.Item( ii );
626 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
627 getFontMetrics() );
628 textsize.x = std::max( textsize.x, extents.x );
629 }
630
631 // interline spacing is only *between* lines, so total height is the height of the first
632 // line plus the interline distance (with interline spacing) for all subsequent lines
633 textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y,
634 getFontMetrics() ) );
635 }
636
637 textsize.y += overbarOffset;
638
639 bbox.SetSize( textsize );
640
641 /*
642 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
643 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
644 */
645 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
646
647 switch( GetHorizJustify() )
648 {
650 if( IsMirrored() )
651 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
652 break;
653
655 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
656 break;
657
659 if( !IsMirrored() )
660 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
661 break;
662
664 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
665 break;
666 }
667
668 switch( GetVertJustify() )
669 {
671 bbox.Offset( 0, -fudgeFactor );
672 break;
673
675 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
676 break;
677
679 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
680 bbox.Offset( 0, fudgeFactor );
681 break;
682
684 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
685 break;
686 }
687
688 bbox.Normalize(); // Make h and v sizes always >= 0
689
691 m_bounding_box_cache_pos = drawPos;
694
695 return bbox;
696}
697
698
699bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
700{
701 BOX2I rect = GetTextBox();
702 VECTOR2I location = aPoint;
703
704 rect.Inflate( aAccuracy );
705 RotatePoint( location, GetDrawPos(), -GetDrawRotation() );
706
707 return rect.Contains( location );
708}
709
710
711bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
712{
713 BOX2I rect = aRect;
714
715 rect.Inflate( aAccuracy );
716
717 if( aContains )
718 return rect.Contains( GetTextBox() );
719
720 return rect.Intersects( GetTextBox(), GetDrawRotation() );
721}
722
723
724void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
725 const COLOR4D& aColor, OUTLINE_MODE aFillMode )
726{
727 if( IsMultilineAllowed() )
728 {
729 std::vector<VECTOR2I> positions;
730 wxArrayString strings;
731 wxStringSplit( GetShownText( true ), strings, '\n' );
732
733 positions.reserve( strings.Count() );
734
735 GetLinePositions( positions, (int) strings.Count() );
736
737 for( unsigned ii = 0; ii < strings.Count(); ii++ )
738 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
739 }
740 else
741 {
742 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
743 GetDrawPos() );
744 }
745}
746
747
748void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
749{
750 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
751 // to the center of the multiline text block
752
753 VECTOR2I offset; // Offset to next line.
754
755 offset.y = GetInterline();
756
757 if( aLineCount > 1 )
758 {
759 switch( GetVertJustify() )
760 {
762 break;
763
765 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
766 break;
767
769 pos.y -= ( aLineCount - 1 ) * offset.y;
770 break;
771
773 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
774 break;
775 }
776 }
777
778 // Rotate the position of the first line around the center of the multiline text block
780
781 // Rotate the offset lines to increase happened in the right direction
782 RotatePoint( offset, GetDrawRotation() );
783
784 for( int ii = 0; ii < aLineCount; ii++ )
785 {
786 aPositions.push_back( (VECTOR2I) pos );
787 pos += offset;
788 }
789}
790
791
792void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
793 const COLOR4D& aColor, OUTLINE_MODE aFillMode,
794 const wxString& aText, const VECTOR2I& aPos )
795{
796 wxDC* DC = aSettings->GetPrintDC();
797 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
798
799 if( aFillMode == SKETCH )
800 penWidth = -penWidth;
801
802 VECTOR2I size = GetTextSize();
803
804 if( IsMirrored() )
805 size.x = -size.x;
806
807 KIFONT::FONT* font = GetFont();
808
809 if( !font )
810 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
811
812 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
813 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
814}
815
816
818{
819 int style = 0;
820
821 if( IsItalic() )
822 style = 1;
823
824 if( IsBold() )
825 style += 2;
826
827 wxString stylemsg[4] = {
828 _("Normal"),
829 _("Italic"),
830 _("Bold"),
831 _("Bold+Italic")
832 };
833
834 return stylemsg[style];
835}
836
837
838wxString EDA_TEXT::GetFontName() const
839{
840 if( GetFont() )
841 return GetFont()->GetName();
842 else
843 return wxEmptyString;
844}
845
846
848{
849 if( !GetFont() )
850 return -1;
851
852 if( GetFont()->GetName() == KICAD_FONT_NAME )
853 return -2;
854
855 std::vector<std::string> fontNames;
856 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
857
858 for( int ii = 0; ii < (int) fontNames.size(); ++ii )
859 {
860 if( fontNames[ii] == GetFont()->GetName() )
861 return ii;
862 }
863
864 return 0;
865}
866
867
869{
870 if( aIdx == -1 )
871 {
872 SetFont( nullptr );
873 }
874 else if( aIdx == -2 )
875 {
876 SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
877 }
878 else
879 {
880 std::vector<std::string> fontNames;
881 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
882
883 if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
884 SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
885 else
886 SetFont( nullptr );
887 }
888}
889
890
892{
893 return ( IsVisible()
894 && !IsMirrored()
897 && GetTextThickness() == 0
898 && !IsItalic()
899 && !IsBold()
901 && GetFontName().IsEmpty()
902 );
903}
904
905
906void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
907{
908 aFormatter->Print( aNestLevel + 1, "(effects" );
909
910 aFormatter->Print( 0, " (font" );
911
912 if( GetFont() && !GetFont()->GetName().IsEmpty() )
913 aFormatter->Print( 0, " (face \"%s\")", GetFont()->NameAsToken() );
914
915 // Text size
916 aFormatter->Print( 0, " (size %s %s)",
919
920 if( GetLineSpacing() != 1.0 )
921 {
922 aFormatter->Print( 0, " (line_spacing %s)",
923 FormatDouble2Str( GetLineSpacing() ).c_str() );
924 }
925
926 if( GetTextThickness() )
927 {
928 aFormatter->Print( 0, " (thickness %s)",
930 }
931
932 if( IsBold() )
933 aFormatter->Print( 0, " (bold yes)" );
934
935 if( IsItalic() )
936 aFormatter->Print( 0, " (italic yes)" );
937
938 if( GetTextColor() != COLOR4D::UNSPECIFIED )
939 {
940 aFormatter->Print( 0, " (color %d %d %d %s)",
941 KiROUND( GetTextColor().r * 255.0 ),
942 KiROUND( GetTextColor().g * 255.0 ),
943 KiROUND( GetTextColor().b * 255.0 ),
944 FormatDouble2Str( GetTextColor().a ).c_str() );
945 }
946
947 aFormatter->Print( 0, ")"); // (font
948
951 {
952 aFormatter->Print( 0, " (justify");
953
955 aFormatter->Print( 0, GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
956
958 aFormatter->Print( 0, GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
959
960 if( IsMirrored() )
961 aFormatter->Print( 0, " mirror" );
962
963 aFormatter->Print( 0, ")" ); // (justify
964 }
965
966 if( !( aControlBits & CTL_OMIT_HIDE ) && !IsVisible() )
967 aFormatter->Print( 0, " (hide yes)" );
968
969 if( HasHyperlink() )
970 {
971 aFormatter->Print( 0, " (href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
972 }
973
974 aFormatter->Print( 0, ")\n" ); // (effects
975}
976
977
978std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
979 const BOX2I& aBBox,
980 const EDA_ANGLE& aAngle ) const
981{
982 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
984 KIFONT::FONT* font = getDrawFont();
985 int penWidth = GetEffectiveTextPenWidth();
986 wxString shownText( GetShownText( true ) );
987 VECTOR2I drawPos = GetDrawPos();
989
990 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
991
992 if( aBBox.GetWidth() )
993 {
994 drawPos = aBBox.GetCenter();
997 attrs.m_Angle = aAngle;
998 }
999 else
1000 {
1001 attrs.m_Angle = GetDrawRotation();
1002
1003 if( font->IsOutline() )
1004 cache = GetRenderCache( font, shownText, VECTOR2I() );
1005 }
1006
1007 if( aTriangulate )
1008 {
1009 CALLBACK_GAL callback_gal(
1010 empty_opts,
1011 // Stroke callback
1012 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1013 {
1014 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1015 },
1016 // Triangulation callback
1017 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1018 {
1019 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1020
1021 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1022 triShape->Append( point.x, point.y );
1023
1024 shape->AddShape( triShape );
1025 } );
1026
1027 if( cache )
1028 callback_gal.DrawGlyphs( *cache );
1029 else
1030 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1031 }
1032 else
1033 {
1034 CALLBACK_GAL callback_gal(
1035 empty_opts,
1036 // Stroke callback
1037 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1038 {
1039 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1040 },
1041 // Outline callback
1042 [&]( const SHAPE_LINE_CHAIN& aPoly )
1043 {
1044 shape->AddShape( aPoly.Clone() );
1045 } );
1046
1047 if( cache )
1048 callback_gal.DrawGlyphs( *cache );
1049 else
1050 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1051 }
1052
1053 return shape;
1054}
1055
1056
1057int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1058{
1059 wxCHECK( aOther, 1 );
1060
1061 int val = m_attributes.Compare( aOther->m_attributes );
1062
1063 if( val != 0 )
1064 return val;
1065
1066 if( m_pos.x != aOther->m_pos.x )
1067 return m_pos.x - aOther->m_pos.x;
1068
1069 if( m_pos.y != aOther->m_pos.y )
1070 return m_pos.y - aOther->m_pos.y;
1071
1072 val = GetFontName().Cmp( aOther->GetFontName() );
1073
1074 if( val != 0 )
1075 return val;
1076
1077 return m_text.Cmp( aOther->m_text );
1078}
1079
1080
1081bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1082{
1083 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1084 return true;
1085
1086 // Limit valid urls to file, http and https for now. Note wxURL doesn't support https
1087 wxURI uri;
1088
1089 if( uri.Create( aURL ) && uri.HasScheme() )
1090 {
1091 const wxString& scheme = uri.GetScheme();
1092 return scheme == wxT( "file" ) || scheme == wxT( "http" ) || scheme == wxT( "https" );
1093 }
1094
1095 return false;
1096}
1097
1098double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1099{
1100 // Compute the Levenshtein distance between the two strings
1101 const wxString& str1 = GetText();
1102 const wxString& str2 = aOther.GetText();
1103
1104 int m = str1.length();
1105 int n = str2.length();
1106
1107 if( n == 0 || m == 0 )
1108 return 0.0;
1109
1110 // Create a matrix to store the distance values
1111 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1112
1113 // Initialize the matrix
1114 for( int i = 0; i <= m; i++ )
1115 distance[i][0] = i;
1116 for( int j = 0; j <= n; j++ )
1117 distance[0][j] = j;
1118
1119 // Calculate the distance
1120 for( int i = 1; i <= m; i++ )
1121 {
1122 for( int j = 1; j <= n; j++ )
1123 {
1124 if( str1[i - 1] == str2[j - 1] )
1125 {
1126 distance[i][j] = distance[i - 1][j - 1];
1127 }
1128 else
1129 {
1130 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1131 distance[i - 1][j - 1] } ) + 1;
1132 }
1133 }
1134 }
1135
1136 // Calculate similarity score
1137 int maxLen = std::max( m, n );
1138 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1139
1140 return similarity;
1141}
1142
1143
1144double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1145{
1146 double retval = 1.0;
1147
1148 if( !( m_attributes == aOther.m_attributes ) )
1149 retval *= 0.9;
1150
1151 if( m_pos != aOther.m_pos )
1152 retval *= 0.9;
1153
1154 retval *= Levenshtein( aOther );
1155
1156 return retval;
1157}
1158
1159
1160bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1161{
1162 return aHref.StartsWith( wxT( "#" ), aDestination );
1163}
1164
1165
1166wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1167{
1168 return wxT( "#" ) + aDestination;
1169}
1170
1171
1172std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1173{
1174 aStream << aText.GetText();
1175
1176 return aStream;
1177}
1178
1179
1180static struct EDA_TEXT_DESC
1181{
1183 {
1185 .Map( GR_TEXT_H_ALIGN_LEFT, _HKI( "Left" ) )
1186 .Map( GR_TEXT_H_ALIGN_CENTER, _HKI( "Center" ) )
1187 .Map( GR_TEXT_H_ALIGN_RIGHT, _HKI( "Right" ) );
1189 .Map( GR_TEXT_V_ALIGN_TOP, _HKI( "Top" ) )
1190 .Map( GR_TEXT_V_ALIGN_CENTER, _HKI( "Center" ) )
1191 .Map( GR_TEXT_V_ALIGN_BOTTOM, _HKI( "Bottom" ) );
1192
1195
1196 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1198 PROPERTY_DISPLAY::PT_DEGREE ) );
1199
1200 const wxString textProps = _HKI( "Text Properties" );
1201
1202 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1204 textProps );
1205
1206 // This must be a PROPERTY_ENUM to get a choice list.
1207 // SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
1208 propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
1210 textProps )
1212
1213 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1215 PROPERTY_DISPLAY::PT_SIZE ),
1216 textProps );
1217 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1220 textProps );
1221 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1223 textProps );
1224 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1226 textProps );
1227 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
1229 textProps );
1230 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1232 PROPERTY_DISPLAY::PT_SIZE ),
1233 textProps );
1234
1235 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1237 PROPERTY_DISPLAY::PT_SIZE ),
1238 textProps );
1239
1241 _HKI( "Horizontal Justification" ),
1243 textProps );
1245 _HKI( "Vertical Justification" ),
1247 textProps );
1248
1249 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1251 textProps );
1252
1253 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1255 textProps );
1256 }
1258
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:817
VECTOR2I m_pos
Definition: eda_text.h:436
wxString m_text
Definition: eda_text.h:418
bool IsDefaultFormatting() const
Definition: eda_text.cpp:891
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1160
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:428
wxString GetFontName() const
Definition: eda_text.cpp:838
void SetupRenderCache(const wxString &aResolvedText, const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:545
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:433
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:559
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:420
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:419
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:906
int GetFontIndex() const
Definition: eda_text.cpp:847
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:565
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:432
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:425
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:792
int GetTextWidth() const
Definition: eda_text.h:225
virtual bool HasHyperlink() const
Definition: eda_text.h:360
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:274
wxString GetHyperlink() const
Definition: eda_text.h:361
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
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1057
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:422
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:430
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:748
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1166
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:1144
VECTOR2I m_render_cache_offset
Definition: eda_text.h:427
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:364
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:553
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:699
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:426
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:1081
VECTOR2I m_bounding_box_cache_pos
Definition: eda_text.h:431
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:424
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:978
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:362
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:1098
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:203
void SetFontIndex(int aIdx)
Definition: eda_text.cpp:868
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:724
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:435
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:1172
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:366
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:588