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