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 m_bounding_box_cache_inverted( false )
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
144}
145
146
148{
149}
150
151
153{
154 m_text = aText.m_text;
157
159 m_pos = aText.m_pos;
160
165
166 m_render_cache.clear();
167
168 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
169 {
170 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
171 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
172 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
173 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
174 }
175
178
179 return *this;
180}
181
182
183void EDA_TEXT::SetText( const wxString& aText )
184{
185 m_text = aText;
187}
188
189
190void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
191{
192 m_text = aSrc.m_text;
194}
195
196
198{
202}
203
204
206{
207 m_attributes.m_Angle = aAngle;
210}
211
212
213void EDA_TEXT::SetItalic( bool aItalic )
214{
215 m_attributes.m_Italic = aItalic;
218}
219
220
221void EDA_TEXT::SetBold( bool aBold )
222{
223 m_attributes.m_Bold = aBold;
226}
227
228
229void EDA_TEXT::SetVisible( bool aVisible )
230{
231 m_attributes.m_Visible = aVisible;
233}
234
235
236void EDA_TEXT::SetMirrored( bool isMirrored )
237{
238 m_attributes.m_Mirrored = isMirrored;
241}
242
243
245{
246 m_attributes.m_Multiline = aAllow;
249}
250
251
253{
254 m_attributes.m_Halign = aType;
257}
258
259
261{
262 m_attributes.m_Valign = aType;
265}
266
267
268void EDA_TEXT::SetKeepUpright( bool aKeepUpright )
269{
270 m_attributes.m_KeepUpright = aKeepUpright;
273}
274
275
276void EDA_TEXT::SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition )
277{
279
280 if( aSetPosition )
281 m_pos = aSrc.m_pos;
282
285}
286
287
288void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
289{
290 std::swap( m_text, aTradingPartner.m_text );
292}
293
294
295void EDA_TEXT::SwapAttributes( EDA_TEXT& aTradingPartner )
296{
297 std::swap( m_attributes, aTradingPartner.m_attributes );
298 std::swap( m_pos, aTradingPartner.m_pos );
299
301 aTradingPartner.ClearRenderCache();
302
304 aTradingPartner.m_bounding_box_cache_valid = false;
305}
306
307
308int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
309{
310 int penWidth = GetTextThickness();
311
312 if( penWidth <= 1 )
313 {
314 penWidth = aDefaultPenWidth;
315
316 if( IsBold() )
317 penWidth = GetPenSizeForBold( GetTextWidth() );
318 else if( penWidth <= 1 )
319 penWidth = GetPenSizeForNormal( GetTextWidth() );
320 }
321
322 // Clip pen size for small texts:
323 penWidth = Clamp_Text_PenSize( penWidth, GetTextSize() );
324
325 return penWidth;
326}
327
328
329bool EDA_TEXT::Replace( const EDA_SEARCH_DATA& aSearchData )
330{
331 bool retval = EDA_ITEM::Replace( aSearchData, m_text );
332
334
337
338 return retval;
339}
340
341
343{
344 m_attributes.m_Font = aFont;
347}
348
349
350void EDA_TEXT::SetLineSpacing( double aLineSpacing )
351{
352 m_attributes.m_LineSpacing = aLineSpacing;
355}
356
357
358void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
359{
360 // Plotting uses unityScale and independently scales the text. If we clamp here we'll
361 // clamp to *really* small values.
362 if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
363 aEnforceMinTextSize = false;
364
365 if( aEnforceMinTextSize )
366 {
367 int min = m_IuScale.get().MilsToIU( TEXT_MIN_SIZE_MILS );
368 int max = m_IuScale.get().MilsToIU( TEXT_MAX_SIZE_MILS );
369
370 aNewSize = VECTOR2I( alg::clamp( min, aNewSize.x, max ),
371 alg::clamp( min, aNewSize.y, max ) );
372 }
373
374 m_attributes.m_Size = aNewSize;
375
378}
379
380
381void EDA_TEXT::SetTextWidth( int aWidth )
382{
383 int min = m_IuScale.get().MilsToIU( TEXT_MIN_SIZE_MILS );
384 int max = m_IuScale.get().MilsToIU( TEXT_MAX_SIZE_MILS );
385
386 m_attributes.m_Size.x = alg::clamp( min, aWidth, max );
389}
390
391
392void EDA_TEXT::SetTextHeight( int aHeight )
393{
394 int min = m_IuScale.get().MilsToIU( TEXT_MIN_SIZE_MILS );
395 int max = m_IuScale.get().MilsToIU( TEXT_MAX_SIZE_MILS );
396
397 m_attributes.m_Size.y = alg::clamp( min, aHeight, max );
400}
401
402
403void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
404{
405 Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
406}
407
408
409void EDA_TEXT::SetTextX( int aX )
410{
411 Offset( VECTOR2I( aX - m_pos.x, 0 ) );
412}
413
414
415void EDA_TEXT::SetTextY( int aY )
416{
417 Offset( VECTOR2I( 0, aY - m_pos.y ) );
418}
419
420
421void EDA_TEXT::Offset( const VECTOR2I& aOffset )
422{
423 if( aOffset.x == 0 && aOffset.y == 0 )
424 return;
425
426 m_pos += aOffset;
427
428 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
429 {
430 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
431 outline->Move( aOffset );
432 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
433 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
434 }
435
437}
438
439
441{
442 m_text.Empty();
445}
446
447
449{
450 if( m_text.IsEmpty() )
451 {
452 m_shown_text = wxEmptyString;
454 }
455 else
456 {
458 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
459 }
460
463}
464
465
467{
468 KIFONT::FONT* font = GetFont();
469
470 if( !font )
471 font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
472
473 return font;
474}
475
476
478{
480}
481
482
484{
485 m_render_cache.clear();
486}
487
488
490{
492}
493
494
495std::vector<std::unique_ptr<KIFONT::GLYPH>>*
496EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
497 const VECTOR2I& aOffset ) const
498{
499 if( aFont->IsOutline() )
500 {
501 EDA_ANGLE resolvedAngle = GetDrawRotation();
502
503 if( m_render_cache.empty()
504 || m_render_cache_font != aFont
505 || m_render_cache_text != forResolvedText
506 || m_render_cache_angle != resolvedAngle
507 || m_render_cache_offset != aOffset )
508 {
509 m_render_cache.clear();
510
511 const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
513
514 attrs.m_Angle = resolvedAngle;
515
516 font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
517 attrs, getFontMetrics() );
518 m_render_cache_font = aFont;
519 m_render_cache_angle = resolvedAngle;
520 m_render_cache_text = forResolvedText;
521 m_render_cache_offset = aOffset;
522 }
523
524 return &m_render_cache;
525 }
526
527 return nullptr;
528}
529
530
531void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const EDA_ANGLE& aAngle )
532{
533 m_render_cache_text = aResolvedText;
534 m_render_cache_angle = aAngle;
535 m_render_cache.clear();
536}
537
538
540{
541 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
542}
543
544
546{
548}
549
550
551BOX2I EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
552{
553 VECTOR2I drawPos = GetDrawPos();
554
556 && m_bounding_box_cache_pos == drawPos
557 && m_bounding_box_cache_line == aLine
558 && m_bounding_box_cache_inverted == aInvertY )
559 {
561 }
562
563 BOX2I bbox;
564 wxArrayString strings;
565 wxString text = GetShownText( true );
566 int thickness = GetEffectiveTextPenWidth();
567
568 if( IsMultilineAllowed() )
569 {
570 wxStringSplit( text, strings, '\n' );
571
572 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
573 {
574 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
575 text = strings.Item( aLine );
576 else
577 text = strings.Item( 0 );
578 }
579 }
580
581 // calculate the H and V size
582 KIFONT::FONT* font = getDrawFont();
583 VECTOR2D fontSize( GetTextSize() );
584 bool bold = IsBold();
585 bool italic = IsItalic();
586 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
587 getFontMetrics() );
588 int overbarOffset = 0;
589
590 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
591 // bounding box will be moved later according to the actual text options
592 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
593 VECTOR2I pos = drawPos;
594 int fudgeFactor = KiROUND( extents.y * 0.17 );
595
596 if( font->IsStroke() )
597 textsize.y += fudgeFactor;
598
599 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
600 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
601
602 if( text.Contains( wxT( "~{" ) ) )
603 overbarOffset = extents.y / 6;
604
605 if( aInvertY )
606 pos.y = -pos.y;
607
608 bbox.SetOrigin( pos );
609
610 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
611 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
612 {
613 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
614 {
615 text = strings.Item( ii );
616 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
617 getFontMetrics() );
618 textsize.x = std::max( textsize.x, extents.x );
619 }
620
621 // interline spacing is only *between* lines, so total height is the height of the first
622 // line plus the interline distance (with interline spacing) for all subsequent lines
623 textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y,
624 getFontMetrics() ) );
625 }
626
627 textsize.y += overbarOffset;
628
629 bbox.SetSize( textsize );
630
631 /*
632 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
633 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
634 */
635 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
636
637 switch( GetHorizJustify() )
638 {
640 if( IsMirrored() )
641 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
642 break;
643
645 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
646 break;
647
649 if( !IsMirrored() )
650 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
651 break;
652
654 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
655 break;
656 }
657
658 switch( GetVertJustify() )
659 {
661 bbox.Offset( 0, -fudgeFactor );
662 break;
663
665 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
666 break;
667
669 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
670 bbox.Offset( 0, fudgeFactor );
671 break;
672
674 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
675 break;
676 }
677
678 bbox.Normalize(); // Make h and v sizes always >= 0
679
681 m_bounding_box_cache_pos = drawPos;
685
686 return bbox;
687}
688
689
690bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
691{
692 BOX2I rect = GetTextBox();
693 VECTOR2I location = aPoint;
694
695 rect.Inflate( aAccuracy );
696 RotatePoint( location, GetDrawPos(), -GetDrawRotation() );
697
698 return rect.Contains( location );
699}
700
701
702bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
703{
704 BOX2I rect = aRect;
705
706 rect.Inflate( aAccuracy );
707
708 if( aContains )
709 return rect.Contains( GetTextBox() );
710
711 return rect.Intersects( GetTextBox(), GetDrawRotation() );
712}
713
714
715void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
716 const COLOR4D& aColor, OUTLINE_MODE aFillMode )
717{
718 if( IsMultilineAllowed() )
719 {
720 std::vector<VECTOR2I> positions;
721 wxArrayString strings;
722 wxStringSplit( GetShownText( true ), strings, '\n' );
723
724 positions.reserve( strings.Count() );
725
726 GetLinePositions( positions, (int) strings.Count() );
727
728 for( unsigned ii = 0; ii < strings.Count(); ii++ )
729 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
730 }
731 else
732 {
733 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
734 GetDrawPos() );
735 }
736}
737
738
739void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
740{
741 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
742 // to the center of the multiline text block
743
744 VECTOR2I offset; // Offset to next line.
745
746 offset.y = GetInterline();
747
748 if( aLineCount > 1 )
749 {
750 switch( GetVertJustify() )
751 {
753 break;
754
756 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
757 break;
758
760 pos.y -= ( aLineCount - 1 ) * offset.y;
761 break;
762
764 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
765 break;
766 }
767 }
768
769 // Rotate the position of the first line around the center of the multiline text block
771
772 // Rotate the offset lines to increase happened in the right direction
773 RotatePoint( offset, GetDrawRotation() );
774
775 for( int ii = 0; ii < aLineCount; ii++ )
776 {
777 aPositions.push_back( (VECTOR2I) pos );
778 pos += offset;
779 }
780}
781
782
783void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
784 const COLOR4D& aColor, OUTLINE_MODE aFillMode,
785 const wxString& aText, const VECTOR2I& aPos )
786{
787 wxDC* DC = aSettings->GetPrintDC();
788 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
789
790 if( aFillMode == SKETCH )
791 penWidth = -penWidth;
792
793 VECTOR2I size = GetTextSize();
794
795 if( IsMirrored() )
796 size.x = -size.x;
797
798 KIFONT::FONT* font = GetFont();
799
800 if( !font )
801 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
802
803 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
804 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
805}
806
807
809{
810 int style = 0;
811
812 if( IsItalic() )
813 style = 1;
814
815 if( IsBold() )
816 style += 2;
817
818 wxString stylemsg[4] = {
819 _("Normal"),
820 _("Italic"),
821 _("Bold"),
822 _("Bold+Italic")
823 };
824
825 return stylemsg[style];
826}
827
828
829wxString EDA_TEXT::GetFontName() const
830{
831 if( GetFont() )
832 return GetFont()->GetName();
833 else
834 return wxEmptyString;
835}
836
837
839{
840 if( !GetFont() )
841 return -1;
842
843 if( GetFont()->GetName() == KICAD_FONT_NAME )
844 return -2;
845
846 std::vector<std::string> fontNames;
847 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
848
849 for( int ii = 0; ii < (int) fontNames.size(); ++ii )
850 {
851 if( fontNames[ii] == GetFont()->GetName() )
852 return ii;
853 }
854
855 return 0;
856}
857
858
860{
861 if( aIdx == -1 )
862 {
863 SetFont( nullptr );
864 }
865 else if( aIdx == -2 )
866 {
867 SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
868 }
869 else
870 {
871 std::vector<std::string> fontNames;
872 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
873
874 if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
875 SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
876 else
877 SetFont( nullptr );
878 }
879}
880
881
883{
884 return ( IsVisible()
885 && !IsMirrored()
888 && GetTextThickness() == 0
889 && !IsItalic()
890 && !IsBold()
892 && GetFontName().IsEmpty()
893 );
894}
895
896
897void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
898{
899 aFormatter->Print( aNestLevel + 1, "(effects" );
900
901 aFormatter->Print( 0, " (font" );
902
903 if( GetFont() && !GetFont()->GetName().IsEmpty() )
904 aFormatter->Print( 0, " (face \"%s\")", GetFont()->NameAsToken() );
905
906 // Text size
907 aFormatter->Print( 0, " (size %s %s)",
910
911 if( GetLineSpacing() != 1.0 )
912 {
913 aFormatter->Print( 0, " (line_spacing %s)",
914 FormatDouble2Str( GetLineSpacing() ).c_str() );
915 }
916
917 if( GetTextThickness() )
918 {
919 aFormatter->Print( 0, " (thickness %s)",
921 }
922
923 if( IsBold() )
924 aFormatter->Print( 0, " (bold yes)" );
925
926 if( IsItalic() )
927 aFormatter->Print( 0, " (italic yes)" );
928
929 if( GetTextColor() != COLOR4D::UNSPECIFIED )
930 {
931 aFormatter->Print( 0, " (color %d %d %d %s)",
932 KiROUND( GetTextColor().r * 255.0 ),
933 KiROUND( GetTextColor().g * 255.0 ),
934 KiROUND( GetTextColor().b * 255.0 ),
935 FormatDouble2Str( GetTextColor().a ).c_str() );
936 }
937
938 aFormatter->Print( 0, ")"); // (font
939
942 {
943 aFormatter->Print( 0, " (justify");
944
946 aFormatter->Print( 0, GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
947
949 aFormatter->Print( 0, GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
950
951 if( IsMirrored() )
952 aFormatter->Print( 0, " mirror" );
953
954 aFormatter->Print( 0, ")" ); // (justify
955 }
956
957 if( !( aControlBits & CTL_OMIT_HIDE ) && !IsVisible() )
958 aFormatter->Print( 0, " (hide yes)" );
959
960 if( HasHyperlink() )
961 {
962 aFormatter->Print( 0, " (href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
963 }
964
965 aFormatter->Print( 0, ")\n" ); // (effects
966}
967
968
969std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
970 const BOX2I& aBBox,
971 const EDA_ANGLE& aAngle ) const
972{
973 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
975 KIFONT::FONT* font = getDrawFont();
976 int penWidth = GetEffectiveTextPenWidth();
977 wxString shownText( GetShownText( true ) );
978 VECTOR2I drawPos = GetDrawPos();
980
981 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
982
983 if( aBBox.GetWidth() )
984 {
985 drawPos = aBBox.GetCenter();
988 attrs.m_Angle = aAngle;
989 }
990 else
991 {
992 attrs.m_Angle = GetDrawRotation();
993
994 if( font->IsOutline() )
995 cache = GetRenderCache( font, shownText, VECTOR2I() );
996 }
997
998 if( aTriangulate )
999 {
1000 CALLBACK_GAL callback_gal(
1001 empty_opts,
1002 // Stroke callback
1003 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1004 {
1005 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1006 },
1007 // Triangulation callback
1008 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1009 {
1010 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1011
1012 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1013 triShape->Append( point.x, point.y );
1014
1015 shape->AddShape( triShape );
1016 } );
1017
1018 if( cache )
1019 callback_gal.DrawGlyphs( *cache );
1020 else
1021 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1022 }
1023 else
1024 {
1025 CALLBACK_GAL callback_gal(
1026 empty_opts,
1027 // Stroke callback
1028 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1029 {
1030 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1031 },
1032 // Outline callback
1033 [&]( const SHAPE_LINE_CHAIN& aPoly )
1034 {
1035 shape->AddShape( aPoly.Clone() );
1036 } );
1037
1038 if( cache )
1039 callback_gal.DrawGlyphs( *cache );
1040 else
1041 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1042 }
1043
1044 return shape;
1045}
1046
1047
1048int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1049{
1050 wxCHECK( aOther, 1 );
1051
1052 int val = m_attributes.Compare( aOther->m_attributes );
1053
1054 if( val != 0 )
1055 return val;
1056
1057 if( m_pos.x != aOther->m_pos.x )
1058 return m_pos.x - aOther->m_pos.x;
1059
1060 if( m_pos.y != aOther->m_pos.y )
1061 return m_pos.y - aOther->m_pos.y;
1062
1063 val = GetFontName().Cmp( aOther->GetFontName() );
1064
1065 if( val != 0 )
1066 return val;
1067
1068 return m_text.Cmp( aOther->m_text );
1069}
1070
1071
1072bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1073{
1074 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1075 return true;
1076
1077 // Limit valid urls to file, http and https for now. Note wxURL doesn't support https
1078 wxURI uri;
1079
1080 if( uri.Create( aURL ) && uri.HasScheme() )
1081 {
1082 const wxString& scheme = uri.GetScheme();
1083 return scheme == wxT( "file" ) || scheme == wxT( "http" ) || scheme == wxT( "https" );
1084 }
1085
1086 return false;
1087}
1088
1089double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1090{
1091 // Compute the Levenshtein distance between the two strings
1092 const wxString& str1 = GetText();
1093 const wxString& str2 = aOther.GetText();
1094
1095 int m = str1.length();
1096 int n = str2.length();
1097
1098 if( n == 0 || m == 0 )
1099 return 0.0;
1100
1101 // Create a matrix to store the distance values
1102 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1103
1104 // Initialize the matrix
1105 for( int i = 0; i <= m; i++ )
1106 distance[i][0] = i;
1107 for( int j = 0; j <= n; j++ )
1108 distance[0][j] = j;
1109
1110 // Calculate the distance
1111 for( int i = 1; i <= m; i++ )
1112 {
1113 for( int j = 1; j <= n; j++ )
1114 {
1115 if( str1[i - 1] == str2[j - 1] )
1116 {
1117 distance[i][j] = distance[i - 1][j - 1];
1118 }
1119 else
1120 {
1121 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1122 distance[i - 1][j - 1] } ) + 1;
1123 }
1124 }
1125 }
1126
1127 // Calculate similarity score
1128 int maxLen = std::max( m, n );
1129 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1130
1131 return similarity;
1132}
1133
1134
1135double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1136{
1137 double retval = 1.0;
1138
1139 if( !( m_attributes == aOther.m_attributes ) )
1140 retval *= 0.9;
1141
1142 if( m_pos != aOther.m_pos )
1143 retval *= 0.9;
1144
1145 retval *= Levenshtein( aOther );
1146
1147 return retval;
1148}
1149
1150
1151bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1152{
1153 return aHref.StartsWith( wxT( "#" ), aDestination );
1154}
1155
1156
1157wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1158{
1159 return wxT( "#" ) + aDestination;
1160}
1161
1162
1163std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1164{
1165 aStream << aText.GetText();
1166
1167 return aStream;
1168}
1169
1170
1171static struct EDA_TEXT_DESC
1172{
1174 {
1176 .Map( GR_TEXT_H_ALIGN_LEFT, _HKI( "Left" ) )
1177 .Map( GR_TEXT_H_ALIGN_CENTER, _HKI( "Center" ) )
1178 .Map( GR_TEXT_H_ALIGN_RIGHT, _HKI( "Right" ) );
1180 .Map( GR_TEXT_V_ALIGN_TOP, _HKI( "Top" ) )
1181 .Map( GR_TEXT_V_ALIGN_CENTER, _HKI( "Center" ) )
1182 .Map( GR_TEXT_V_ALIGN_BOTTOM, _HKI( "Bottom" ) );
1183
1186
1187 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1189 PROPERTY_DISPLAY::PT_DEGREE ) );
1190
1191 const wxString textProps = _( "Text Properties" );
1192
1193 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1195 textProps );
1196
1197 // This must be a PROPERTY_ENUM to get a choice list.
1198 // SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
1199 propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
1201 textProps )
1203
1204 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1206 PROPERTY_DISPLAY::PT_SIZE ),
1207 textProps );
1208 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1211 textProps );
1212 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1214 textProps );
1215 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1217 textProps );
1218 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
1220 textProps );
1221 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1223 PROPERTY_DISPLAY::PT_SIZE ),
1224 textProps );
1225
1226 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1228 PROPERTY_DISPLAY::PT_SIZE ),
1229 textProps );
1230
1232 _HKI( "Horizontal Justification" ),
1234 textProps );
1236 _HKI( "Vertical Justification" ),
1238 textProps );
1239
1240 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1242 textProps );
1243
1244 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1246 textProps );
1247 }
1249
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:112
void SetOrigin(const Vec &pos)
Definition: box2.h:203
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:120
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:225
void SetX(coord_type val)
Definition: box2.h:236
const Vec GetCenter() const
Definition: box2.h:196
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:270
void SetY(coord_type val)
Definition: box2.h:241
coord_type GetHeight() const
Definition: box2.h:189
coord_type GetY() const
Definition: box2.h:182
coord_type GetWidth() const
Definition: box2.h:188
void SetSize(const Vec &size)
Definition: box2.h:214
bool Contains(const Vec &aPoint) const
Definition: box2.h:142
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:507
coord_type GetX() const
Definition: box2.h:181
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:80
int GetTextHeight() const
Definition: eda_text.h:224
BOX2I GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:551
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:226
COLOR4D GetTextColor() const
Definition: eda_text.h:227
wxString GetTextStyleName() const
Definition: eda_text.cpp:808
VECTOR2I m_pos
Definition: eda_text.h:434
wxString m_text
Definition: eda_text.h:415
bool IsDefaultFormatting() const
Definition: eda_text.cpp:882
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1151
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:425
wxString GetFontName() const
Definition: eda_text.cpp:829
void SetupRenderCache(const wxString &aResolvedText, const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:531
virtual ~EDA_TEXT()
Definition: eda_text.cpp:147
bool IsItalic() const
Definition: eda_text.h:141
BOX2I m_bounding_box_cache
Definition: eda_text.h:431
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:358
bool IsMultilineAllowed() const
Definition: eda_text.h:157
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:545
virtual bool IsVisible() const
Definition: eda_text.h:147
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:403
void SetTextX(int aX)
Definition: eda_text.cpp:409
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:417
KIFONT::FONT * GetFont() const
Definition: eda_text.h:207
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:276
wxString m_shown_text
Definition: eda_text.h:416
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:897
int GetFontIndex() const
Definition: eda_text.cpp:838
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:236
void SetTextY(int aY)
Definition: eda_text.cpp:415
int m_bounding_box_cache_line
Definition: eda_text.h:429
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:496
const KIFONT::FONT * m_render_cache_font
Definition: eda_text.h:422
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:337
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:338
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition: eda_text.cpp:152
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:783
int GetTextWidth() const
Definition: eda_text.h:221
virtual bool HasHyperlink() const
Definition: eda_text.h:357
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:260
wxString GetHyperlink() const
Definition: eda_text.h:358
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:421
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:381
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:329
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1048
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:419
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:229
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:427
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:739
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1157
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:489
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:466
double GetLineSpacing() const
Definition: eda_text.h:215
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1135
VECTOR2I m_render_cache_offset
Definition: eda_text.h:424
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:350
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:539
void Empty()
Definition: eda_text.cpp:440
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:197
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:690
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:392
virtual void cacheShownText()
Definition: eda_text.cpp:448
EDA_ANGLE m_render_cache_angle
Definition: eda_text.h:423
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:63
bool m_bounding_box_cache_inverted
Definition: eda_text.h:430
virtual void ClearRenderCache()
Definition: eda_text.cpp:483
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:191
void SetBold(bool aBold)
Definition: eda_text.cpp:221
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
Definition: eda_text.cpp:1072
VECTOR2I m_bounding_box_cache_pos
Definition: eda_text.h:428
bool IsMirrored() const
Definition: eda_text.h:150
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:308
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:295
wxString m_render_cache_text
Definition: eda_text.h:421
double GetTextAngleDegrees() const
Definition: eda_text.h:138
virtual const KIFONT::METRICS & getFontMetrics() const
Definition: eda_text.cpp:477
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:969
bool IsBold() const
Definition: eda_text.h:144
void SetTextAngleDegrees(double aOrientation)
Definition: eda_text.h:134
void SetHyperlink(wxString aLink)
Definition: eda_text.h:359
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:77
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:268
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:190
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:163
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:106
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
Definition: eda_text.cpp:1089
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
void SetFontIndex(int aIdx)
Definition: eda_text.cpp:859
int GetTextThickness() const
Definition: eda_text.h:123
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:715
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:288
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:244
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:342
VECTOR2I GetTextSize() const
Definition: eda_text.h:218
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:252
TEXT_ATTRIBUTES m_attributes
Definition: eda_text.h:433
static ENUM_MAP< T > & Instance()
Definition: property.h:653
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:302
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:1163
static struct EDA_TEXT_DESC _EDA_TEXT_DESC
#define TEXT_MIN_SIZE_MILS
Minimum text size in mils.
Definition: eda_text.h:42
#define CTL_OMIT_HIDE
Definition: eda_text.h:63
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:70
#define TEXT_MAX_SIZE_MILS
Maximum text size in mils (10 inches)
Definition: eda_text.h:43
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:153
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
see class PGM_BASE
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:755
#define REGISTER_TYPE(x)
Definition: property_mgr.h:366
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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:77
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:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588