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 m_attributes.m_Italic = aItalic;
217}
218
219
220void EDA_TEXT::SetBold( bool aBold )
221{
222 if( m_attributes.m_Bold != aBold )
223 {
224 int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
225
226 if( aBold )
228 else
230 }
231
232 SetBoldFlag( aBold );
233}
234
235
236void EDA_TEXT::SetBoldFlag( bool aBold )
237{
238 m_attributes.m_Bold = aBold;
241}
242
243
244void EDA_TEXT::SetVisible( bool aVisible )
245{
246 m_attributes.m_Visible = aVisible;
248}
249
250
251void EDA_TEXT::SetMirrored( bool isMirrored )
252{
253 m_attributes.m_Mirrored = isMirrored;
256}
257
258
260{
261 m_attributes.m_Multiline = aAllow;
264}
265
266
268{
269 m_attributes.m_Halign = aType;
272}
273
274
276{
277 m_attributes.m_Valign = aType;
280}
281
282
283void EDA_TEXT::SetKeepUpright( bool aKeepUpright )
284{
285 m_attributes.m_KeepUpright = aKeepUpright;
288}
289
290
291void EDA_TEXT::SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition )
292{
294
295 if( aSetPosition )
296 m_pos = aSrc.m_pos;
297
300}
301
302
303void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
304{
305 std::swap( m_text, aTradingPartner.m_text );
307}
308
309
310void EDA_TEXT::SwapAttributes( EDA_TEXT& aTradingPartner )
311{
312 std::swap( m_attributes, aTradingPartner.m_attributes );
313 std::swap( m_pos, aTradingPartner.m_pos );
314
316 aTradingPartner.ClearRenderCache();
317
319 aTradingPartner.m_bounding_box_cache_valid = false;
320}
321
322
323int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
324{
325 int penWidth = GetTextThickness();
326
327 if( penWidth <= 1 )
328 {
329 penWidth = aDefaultPenWidth;
330
331 if( IsBold() )
332 penWidth = GetPenSizeForBold( GetTextWidth() );
333 else if( penWidth <= 1 )
334 penWidth = GetPenSizeForNormal( GetTextWidth() );
335 }
336
337 // Clip pen size for small texts:
338 penWidth = Clamp_Text_PenSize( penWidth, GetTextSize() );
339
340 return penWidth;
341}
342
343
344bool EDA_TEXT::Replace( const EDA_SEARCH_DATA& aSearchData )
345{
346 bool retval = EDA_ITEM::Replace( aSearchData, m_text );
347
349
352
353 return retval;
354}
355
356
358{
359 m_attributes.m_Font = aFont;
362}
363
364
365void EDA_TEXT::SetLineSpacing( double aLineSpacing )
366{
367 m_attributes.m_LineSpacing = aLineSpacing;
370}
371
372
373void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
374{
375 // Plotting uses unityScale and independently scales the text. If we clamp here we'll
376 // clamp to *really* small values.
377 if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
378 aEnforceMinTextSize = false;
379
380 if( aEnforceMinTextSize )
381 {
382 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
383 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
384
385 aNewSize = VECTOR2I( alg::clamp( min, aNewSize.x, max ),
386 alg::clamp( min, aNewSize.y, max ) );
387 }
388
389 m_attributes.m_Size = aNewSize;
390
393}
394
395
396void EDA_TEXT::SetTextWidth( int aWidth )
397{
398 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
399 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
400
401 m_attributes.m_Size.x = alg::clamp( min, aWidth, max );
404}
405
406
407void EDA_TEXT::SetTextHeight( int aHeight )
408{
409 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
410 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
411
412 m_attributes.m_Size.y = alg::clamp( min, aHeight, max );
415}
416
417
418void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
419{
420 Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
421}
422
423
424void EDA_TEXT::SetTextX( int aX )
425{
426 Offset( VECTOR2I( aX - m_pos.x, 0 ) );
427}
428
429
430void EDA_TEXT::SetTextY( int aY )
431{
432 Offset( VECTOR2I( 0, aY - m_pos.y ) );
433}
434
435
436void EDA_TEXT::Offset( const VECTOR2I& aOffset )
437{
438 if( aOffset.x == 0 && aOffset.y == 0 )
439 return;
440
441 m_pos += aOffset;
442
443 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
444 {
445 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
446 outline->Move( aOffset );
447 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
448 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
449 }
450
452}
453
454
456{
457 m_text.Empty();
460}
461
462
464{
465 if( m_text.IsEmpty() )
466 {
467 m_shown_text = wxEmptyString;
469 }
470 else
471 {
473 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
474 }
475
478}
479
480
482{
483 KIFONT::FONT* font = GetFont();
484
485 if( !font )
486 font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
487
488 return font;
489}
490
491
493{
495}
496
497
499{
500 m_render_cache.clear();
501}
502
503
505{
507}
508
509
510std::vector<std::unique_ptr<KIFONT::GLYPH>>*
511EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
512 const VECTOR2I& aOffset ) const
513{
514 if( aFont->IsOutline() )
515 {
516 EDA_ANGLE resolvedAngle = GetDrawRotation();
517
518 if( m_render_cache.empty()
519 || m_render_cache_font != aFont
520 || m_render_cache_text != forResolvedText
521 || m_render_cache_angle != resolvedAngle
522 || m_render_cache_offset != aOffset )
523 {
524 m_render_cache.clear();
525
526 const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
528
529 attrs.m_Angle = resolvedAngle;
530
531 font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
532 attrs, getFontMetrics() );
533 m_render_cache_font = aFont;
534 m_render_cache_angle = resolvedAngle;
535 m_render_cache_text = forResolvedText;
536 m_render_cache_offset = aOffset;
537 }
538
539 return &m_render_cache;
540 }
541
542 return nullptr;
543}
544
545
546void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const KIFONT::FONT* aFont,
547 const EDA_ANGLE& aAngle, const VECTOR2I& aOffset )
548{
549 m_render_cache_text = aResolvedText;
550 m_render_cache_font = aFont;
551 m_render_cache_angle = aAngle;
552 m_render_cache_offset = aOffset;
553 m_render_cache.clear();
554}
555
556
558{
559 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
560 static_cast<KIFONT::OUTLINE_GLYPH*>( m_render_cache.back().get() )->CacheTriangulation();
561}
562
563
565{
567}
568
569
570BOX2I EDA_TEXT::GetTextBox( int aLine ) const
571{
572 VECTOR2I drawPos = GetDrawPos();
573
575 && m_bounding_box_cache_pos == drawPos
576 && m_bounding_box_cache_line == aLine )
577 {
579 }
580
581 BOX2I bbox;
582 wxArrayString strings;
583 wxString text = GetShownText( true );
584 int thickness = GetEffectiveTextPenWidth();
585
586 if( IsMultilineAllowed() )
587 {
588 wxStringSplit( text, strings, '\n' );
589
590 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
591 {
592 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
593 text = strings.Item( aLine );
594 else
595 text = strings.Item( 0 );
596 }
597 }
598
599 // calculate the H and V size
600 KIFONT::FONT* font = getDrawFont();
601 VECTOR2D fontSize( GetTextSize() );
602 bool bold = IsBold();
603 bool italic = IsItalic();
604 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
605 getFontMetrics() );
606 int overbarOffset = 0;
607
608 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
609 // bounding box will be moved later according to the actual text options
610 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
611 VECTOR2I pos = drawPos;
612 int fudgeFactor = KiROUND( extents.y * 0.17 );
613
614 if( font->IsStroke() )
615 textsize.y += fudgeFactor;
616
617 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
618 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
619
620 if( text.Contains( wxT( "~{" ) ) )
621 overbarOffset = extents.y / 6;
622
623 bbox.SetOrigin( pos );
624
625 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
626 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
627 {
628 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
629 {
630 text = strings.Item( ii );
631 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
632 getFontMetrics() );
633 textsize.x = std::max( textsize.x, extents.x );
634 }
635
636 // interline spacing is only *between* lines, so total height is the height of the first
637 // line plus the interline distance (with interline spacing) for all subsequent lines
638 textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y,
639 getFontMetrics() ) );
640 }
641
642 textsize.y += overbarOffset;
643
644 bbox.SetSize( textsize );
645
646 /*
647 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
648 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
649 */
650 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
651
652 switch( GetHorizJustify() )
653 {
655 if( IsMirrored() )
656 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
657 break;
658
660 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
661 break;
662
664 if( !IsMirrored() )
665 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
666 break;
667
669 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
670 break;
671 }
672
673 switch( GetVertJustify() )
674 {
676 bbox.Offset( 0, -fudgeFactor );
677 break;
678
680 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
681 break;
682
684 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
685 bbox.Offset( 0, fudgeFactor );
686 break;
687
689 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
690 break;
691 }
692
693 bbox.Normalize(); // Make h and v sizes always >= 0
694
696 m_bounding_box_cache_pos = drawPos;
699
700 return bbox;
701}
702
703
704bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
705{
706 BOX2I rect = GetTextBox();
707 VECTOR2I location = aPoint;
708
709 rect.Inflate( aAccuracy );
710 RotatePoint( location, GetDrawPos(), -GetDrawRotation() );
711
712 return rect.Contains( location );
713}
714
715
716bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
717{
718 BOX2I rect = aRect;
719
720 rect.Inflate( aAccuracy );
721
722 if( aContains )
723 return rect.Contains( GetTextBox() );
724
725 return rect.Intersects( GetTextBox(), GetDrawRotation() );
726}
727
728
729void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
730 const COLOR4D& aColor, OUTLINE_MODE aFillMode )
731{
732 if( IsMultilineAllowed() )
733 {
734 std::vector<VECTOR2I> positions;
735 wxArrayString strings;
736 wxStringSplit( GetShownText( true ), strings, '\n' );
737
738 positions.reserve( strings.Count() );
739
740 GetLinePositions( positions, (int) strings.Count() );
741
742 for( unsigned ii = 0; ii < strings.Count(); ii++ )
743 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
744 }
745 else
746 {
747 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
748 GetDrawPos() );
749 }
750}
751
752
753void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
754{
755 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
756 // to the center of the multiline text block
757
758 VECTOR2I offset; // Offset to next line.
759
760 offset.y = GetInterline();
761
762 if( aLineCount > 1 )
763 {
764 switch( GetVertJustify() )
765 {
767 break;
768
770 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
771 break;
772
774 pos.y -= ( aLineCount - 1 ) * offset.y;
775 break;
776
778 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
779 break;
780 }
781 }
782
783 // Rotate the position of the first line around the center of the multiline text block
785
786 // Rotate the offset lines to increase happened in the right direction
787 RotatePoint( offset, GetDrawRotation() );
788
789 for( int ii = 0; ii < aLineCount; ii++ )
790 {
791 aPositions.push_back( (VECTOR2I) pos );
792 pos += offset;
793 }
794}
795
796
797void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
798 const COLOR4D& aColor, OUTLINE_MODE aFillMode,
799 const wxString& aText, const VECTOR2I& aPos )
800{
801 wxDC* DC = aSettings->GetPrintDC();
802 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
803
804 if( aFillMode == SKETCH )
805 penWidth = -penWidth;
806
807 VECTOR2I size = GetTextSize();
808
809 if( IsMirrored() )
810 size.x = -size.x;
811
812 KIFONT::FONT* font = GetFont();
813
814 if( !font )
815 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
816
817 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
818 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
819}
820
821
823{
824 int style = 0;
825
826 if( IsItalic() )
827 style = 1;
828
829 if( IsBold() )
830 style += 2;
831
832 wxString stylemsg[4] = {
833 _("Normal"),
834 _("Italic"),
835 _("Bold"),
836 _("Bold+Italic")
837 };
838
839 return stylemsg[style];
840}
841
842
843wxString EDA_TEXT::GetFontName() const
844{
845 if( GetFont() )
846 return GetFont()->GetName();
847 else
848 return wxEmptyString;
849}
850
851
853{
854 if( !GetFont() )
855 return -1;
856
857 if( GetFont()->GetName() == KICAD_FONT_NAME )
858 return -2;
859
860 std::vector<std::string> fontNames;
861 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
862
863 for( int ii = 0; ii < (int) fontNames.size(); ++ii )
864 {
865 if( fontNames[ii] == GetFont()->GetName() )
866 return ii;
867 }
868
869 return 0;
870}
871
872
874{
875 if( aIdx == -1 )
876 {
877 SetFont( nullptr );
878 }
879 else if( aIdx == -2 )
880 {
881 SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
882 }
883 else
884 {
885 std::vector<std::string> fontNames;
886 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
887
888 if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
889 SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
890 else
891 SetFont( nullptr );
892 }
893}
894
895
897{
898 return ( IsVisible()
899 && !IsMirrored()
902 && GetTextThickness() == 0
903 && !IsItalic()
904 && !IsBold()
906 && GetFontName().IsEmpty()
907 );
908}
909
910
911void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
912{
913 aFormatter->Print( aNestLevel + 1, "(effects" );
914
915 aFormatter->Print( 0, " (font" );
916
917 if( GetFont() && !GetFont()->GetName().IsEmpty() )
918 aFormatter->Print( 0, " (face \"%s\")", GetFont()->NameAsToken() );
919
920 // Text size
921 aFormatter->Print( 0, " (size %s %s)",
924
925 if( GetLineSpacing() != 1.0 )
926 {
927 aFormatter->Print( 0, " (line_spacing %s)",
928 FormatDouble2Str( GetLineSpacing() ).c_str() );
929 }
930
931 if( GetTextThickness() )
932 {
933 aFormatter->Print( 0, " (thickness %s)",
935 }
936
937 if( IsBold() )
938 aFormatter->Print( 0, " (bold yes)" );
939
940 if( IsItalic() )
941 aFormatter->Print( 0, " (italic yes)" );
942
943 if( !( aControlBits & CTL_OMIT_COLOR ) && GetTextColor() != COLOR4D::UNSPECIFIED )
944 {
945 aFormatter->Print( 0, " (color %d %d %d %s)",
946 KiROUND( GetTextColor().r * 255.0 ),
947 KiROUND( GetTextColor().g * 255.0 ),
948 KiROUND( GetTextColor().b * 255.0 ),
949 FormatDouble2Str( GetTextColor().a ).c_str() );
950 }
951
952 aFormatter->Print( 0, ")"); // (font
953
956 {
957 aFormatter->Print( 0, " (justify");
958
960 aFormatter->Print( 0, GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
961
963 aFormatter->Print( 0, GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
964
965 if( IsMirrored() )
966 aFormatter->Print( 0, " mirror" );
967
968 aFormatter->Print( 0, ")" ); // (justify
969 }
970
971 if( !( aControlBits & CTL_OMIT_HIDE ) && !IsVisible() )
972 aFormatter->Print( 0, " (hide yes)" );
973
974 if( !( aControlBits & CTL_OMIT_HYPERLINK ) && HasHyperlink() )
975 {
976 aFormatter->Print( 0, " (href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
977 }
978
979 aFormatter->Print( 0, ")\n" ); // (effects
980}
981
982
983std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
984 const BOX2I& aBBox,
985 const EDA_ANGLE& aAngle ) const
986{
987 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
989 KIFONT::FONT* font = getDrawFont();
990 int penWidth = GetEffectiveTextPenWidth();
991 wxString shownText( GetShownText( true ) );
992 VECTOR2I drawPos = GetDrawPos();
994
995 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
996
997 if( aBBox.GetWidth() )
998 {
999 drawPos = aBBox.GetCenter();
1002 attrs.m_Angle = aAngle;
1003 }
1004 else
1005 {
1006 attrs.m_Angle = GetDrawRotation();
1007
1008 if( font->IsOutline() )
1009 cache = GetRenderCache( font, shownText, VECTOR2I() );
1010 }
1011
1012 if( aTriangulate )
1013 {
1014 CALLBACK_GAL callback_gal(
1015 empty_opts,
1016 // Stroke callback
1017 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1018 {
1019 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1020 },
1021 // Triangulation callback
1022 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1023 {
1024 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1025
1026 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1027 triShape->Append( point.x, point.y );
1028
1029 shape->AddShape( triShape );
1030 } );
1031
1032 if( cache )
1033 callback_gal.DrawGlyphs( *cache );
1034 else
1035 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1036 }
1037 else
1038 {
1039 CALLBACK_GAL callback_gal(
1040 empty_opts,
1041 // Stroke callback
1042 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1043 {
1044 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1045 },
1046 // Outline callback
1047 [&]( const SHAPE_LINE_CHAIN& aPoly )
1048 {
1049 shape->AddShape( aPoly.Clone() );
1050 } );
1051
1052 if( cache )
1053 callback_gal.DrawGlyphs( *cache );
1054 else
1055 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1056 }
1057
1058 return shape;
1059}
1060
1061
1062int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1063{
1064 wxCHECK( aOther, 1 );
1065
1066 int val = m_attributes.Compare( aOther->m_attributes );
1067
1068 if( val != 0 )
1069 return val;
1070
1071 if( m_pos.x != aOther->m_pos.x )
1072 return m_pos.x - aOther->m_pos.x;
1073
1074 if( m_pos.y != aOther->m_pos.y )
1075 return m_pos.y - aOther->m_pos.y;
1076
1077 val = GetFontName().Cmp( aOther->GetFontName() );
1078
1079 if( val != 0 )
1080 return val;
1081
1082 return m_text.Cmp( aOther->m_text );
1083}
1084
1085
1086bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1087{
1088 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1089 return true;
1090
1091 wxURI uri;
1092
1093 return( uri.Create( aURL ) && uri.HasScheme() );
1094}
1095
1096double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1097{
1098 // Compute the Levenshtein distance between the two strings
1099 const wxString& str1 = GetText();
1100 const wxString& str2 = aOther.GetText();
1101
1102 int m = str1.length();
1103 int n = str2.length();
1104
1105 if( n == 0 || m == 0 )
1106 return 0.0;
1107
1108 // Create a matrix to store the distance values
1109 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1110
1111 // Initialize the matrix
1112 for( int i = 0; i <= m; i++ )
1113 distance[i][0] = i;
1114 for( int j = 0; j <= n; j++ )
1115 distance[0][j] = j;
1116
1117 // Calculate the distance
1118 for( int i = 1; i <= m; i++ )
1119 {
1120 for( int j = 1; j <= n; j++ )
1121 {
1122 if( str1[i - 1] == str2[j - 1] )
1123 {
1124 distance[i][j] = distance[i - 1][j - 1];
1125 }
1126 else
1127 {
1128 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1129 distance[i - 1][j - 1] } ) + 1;
1130 }
1131 }
1132 }
1133
1134 // Calculate similarity score
1135 int maxLen = std::max( m, n );
1136 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1137
1138 return similarity;
1139}
1140
1141
1142double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1143{
1144 double retval = 1.0;
1145
1146 if( !( m_attributes == aOther.m_attributes ) )
1147 retval *= 0.9;
1148
1149 if( m_pos != aOther.m_pos )
1150 retval *= 0.9;
1151
1152 retval *= Levenshtein( aOther );
1153
1154 return retval;
1155}
1156
1157
1158bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1159{
1160 return aHref.StartsWith( wxT( "#" ), aDestination );
1161}
1162
1163
1164wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1165{
1166 return wxT( "#" ) + aDestination;
1167}
1168
1169
1170std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1171{
1172 aStream << aText.GetText();
1173
1174 return aStream;
1175}
1176
1177
1178static struct EDA_TEXT_DESC
1179{
1181 {
1182 // These are defined in SCH_FIELD as well but initialization order is
1183 // not defined, so this needs to be conditional. Defining in both
1184 // places leads to duplicate symbols.
1186
1187 if( h_inst.Choices().GetCount() == 0)
1188 {
1189 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
1190 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
1191 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
1192 }
1193
1195
1196 if( v_inst.Choices().GetCount() == 0)
1197 {
1198 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
1199 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
1200 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
1201 }
1202
1205
1206 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1208 PROPERTY_DISPLAY::PT_DEGREE ) );
1209
1210 const wxString textProps = _HKI( "Text Properties" );
1211
1212 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1214 textProps );
1215
1216 // This must be a PROPERTY_ENUM to get a choice list.
1217 // SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
1218 propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
1220 textProps )
1222
1223 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1225 PROPERTY_DISPLAY::PT_SIZE ),
1226 textProps );
1227 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1230 textProps );
1231 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1233 textProps );
1234 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1236 textProps );
1237 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
1239 textProps );
1240 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1242 PROPERTY_DISPLAY::PT_SIZE ),
1243 textProps );
1244
1245 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1247 PROPERTY_DISPLAY::PT_SIZE ),
1248 textProps );
1249
1251 _HKI( "Horizontal Justification" ),
1253 textProps );
1255 _HKI( "Vertical Justification" ),
1257 textProps );
1258
1259 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1261 textProps );
1262
1263 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1265 textProps );
1266 }
1268
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:79
int GetTextHeight() const
Definition: eda_text.h:224
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:822
VECTOR2I m_pos
Definition: eda_text.h:433
wxString m_text
Definition: eda_text.h:415
bool IsDefaultFormatting() const
Definition: eda_text.cpp:896
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1158
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:425
wxString GetFontName() const
Definition: eda_text.cpp:843
virtual ~EDA_TEXT()
Definition: eda_text.cpp:146
bool IsItalic() const
Definition: eda_text.h:140
BOX2I m_bounding_box_cache
Definition: eda_text.h:430
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:373
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:94
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:564
virtual bool IsVisible() const
Definition: eda_text.h:147
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:418
void SetTextX(int aX)
Definition: eda_text.cpp:424
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:291
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:911
int GetFontIndex() const
Definition: eda_text.cpp:852
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:570
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:251
void SetTextY(int aY)
Definition: eda_text.cpp:430
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:511
const KIFONT::FONT * m_render_cache_font
Definition: eda_text.h:422
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:336
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:337
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:797
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:275
wxString GetHyperlink() const
Definition: eda_text.h:358
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:436
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:396
void SetBoldFlag(bool aBold)
Definition: eda_text.cpp:236
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:344
void SetupRenderCache(const wxString &aResolvedText, const KIFONT::FONT *aFont, const EDA_ANGLE &aAngle, const VECTOR2I &aOffset)
Definition: eda_text.cpp:546
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1062
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:419
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:244
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: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:753
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1164
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:504
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:481
double GetLineSpacing() const
Definition: eda_text.h:215
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1142
VECTOR2I m_render_cache_offset
Definition: eda_text.h:424
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:365
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:557
void Empty()
Definition: eda_text.cpp:455
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:704
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:407
virtual void cacheShownText()
Definition: eda_text.cpp:463
EDA_ANGLE m_render_cache_angle
Definition: eda_text.h:423
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:64
virtual void ClearRenderCache()
Definition: eda_text.cpp:498
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:191
void SetBold(bool aBold)
Definition: eda_text.cpp:220
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
Definition: eda_text.cpp:1086
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:323
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:310
wxString m_render_cache_text
Definition: eda_text.h:421
double GetTextAngleDegrees() const
Definition: eda_text.h:137
virtual const KIFONT::METRICS & getFontMetrics() const
Definition: eda_text.cpp:492
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:983
bool IsBold() const
Definition: eda_text.h:144
void SetTextAngleDegrees(double aOrientation)
Definition: eda_text.h:133
void SetHyperlink(wxString aLink)
Definition: eda_text.h:359
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:78
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:283
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:189
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: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:1096
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:204
void SetFontIndex(int aIdx)
Definition: eda_text.cpp:873
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:729
void SetItalic(bool aItalic)
Definition: eda_text.cpp:212
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:303
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:259
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:357
VECTOR2I GetTextSize() const
Definition: eda_text.h:218
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:267
TEXT_ATTRIBUTES m_attributes
Definition: eda_text.h:432
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
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
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr)
Definition: font.cpp:146
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: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:1170
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
T clamp(T min, T value, T max)
Definition: kicad_algo.h:205
OUTLINE_MODE
Definition: outline_mode.h:25
@ SKETCH
Definition: outline_mode.h:26
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:765
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
wxString UnescapeString(const wxString &aSource)
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
const double IU_PER_MM
Definition: base_units.h:76
GR_TEXT_H_ALIGN_T
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:228
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:121
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:673