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#include <api/api_enums.h>
53#include <api/api_utils.h>
54#include <api/common/types/base_types.pb.h>
55
56#include <wx/debug.h> // for wxASSERT
57#include <wx/string.h>
58#include <wx/url.h> // for wxURL
61#include "font/fontconfig.h"
62#include "pgm_base.h"
63
64class OUTPUTFORMATTER;
65
66
68{
69 wxASSERT( aHorizJustify >= GR_TEXT_H_ALIGN_LEFT && aHorizJustify <= GR_TEXT_H_ALIGN_RIGHT );
70
71 if( aHorizJustify > GR_TEXT_H_ALIGN_RIGHT )
73
74 if( aHorizJustify < GR_TEXT_H_ALIGN_LEFT )
76
77 return static_cast<GR_TEXT_H_ALIGN_T>( aHorizJustify );
78}
79
80
82{
83 wxASSERT( aVertJustify >= GR_TEXT_V_ALIGN_TOP && aVertJustify <= GR_TEXT_V_ALIGN_BOTTOM );
84
85 if( aVertJustify > GR_TEXT_V_ALIGN_BOTTOM )
87
88 if( aVertJustify < GR_TEXT_V_ALIGN_TOP )
90
91 return static_cast<GR_TEXT_V_ALIGN_T>( aVertJustify );
92}
93
94
95EDA_TEXT::EDA_TEXT( const EDA_IU_SCALE& aIuScale, const wxString& aText ) :
96 m_text( aText ),
97 m_IuScale( aIuScale ),
98 m_render_cache_font( nullptr ),
99 m_bounding_box_cache_valid( false ),
100 m_bounding_box_cache_line( -1 )
101{
104
105 if( m_text.IsEmpty() )
106 {
107 m_shown_text = wxEmptyString;
109 }
110 else
111 {
113 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
114 }
115}
116
117
119 m_IuScale( aText.m_IuScale )
120{
121 m_text = aText.m_text;
124
126 m_pos = aText.m_pos;
127
132
133 m_render_cache.clear();
134
135 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
136 {
137 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
138 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
139 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
140 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
141 }
142
146}
147
148
150{
151}
152
153
155{
156 m_text = aText.m_text;
159
161 m_pos = aText.m_pos;
162
167
168 m_render_cache.clear();
169
170 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
171 {
172 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
173 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
174 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
175 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
176 }
177
180
181 return *this;
182}
183
184
185void EDA_TEXT::Serialize( google::protobuf::Any &aContainer ) const
186{
187 using namespace kiapi::common;
188 types::Text text;
189
190 text.set_text( GetText().ToStdString() );
191 text.set_hyperlink( GetHyperlink().ToStdString() );
192 PackVector2( *text.mutable_position(), GetTextPos() );
193
194 types::TextAttributes* attrs = text.mutable_attributes();
195
196 if( GetFont() )
197 attrs->set_font_name( GetFont()->GetName().ToStdString() );
198
199 attrs->set_horizontal_alignment(
200 ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
201
202 attrs->set_vertical_alignment(
203 ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
204
205 attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
206 attrs->set_line_spacing( GetLineSpacing() );
207 attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
208 attrs->set_italic( IsItalic() );
209 attrs->set_bold( IsBold() );
210 attrs->set_underlined( GetAttributes().m_Underlined );
211 attrs->set_visible( IsVisible() );
212 attrs->set_mirrored( IsMirrored() );
213 attrs->set_multiline( IsMultilineAllowed() );
214 attrs->set_keep_upright( IsKeepUpright() );
215 PackVector2( *attrs->mutable_size(), GetTextSize() );
216
217 aContainer.PackFrom( text );
218}
219
220
221bool EDA_TEXT::Deserialize( const google::protobuf::Any &aContainer )
222{
223 using namespace kiapi::common;
224 types::Text text;
225
226 if( !aContainer.UnpackTo( &text ) )
227 return false;
228
229 SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
230 SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
231 SetTextPos( UnpackVector2( text.position() ) );
232
233 if( text.has_attributes() )
234 {
236
237 attrs.m_Bold = text.attributes().bold();
238 attrs.m_Italic = text.attributes().italic();
239 attrs.m_Underlined = text.attributes().underlined();
240 attrs.m_Visible = text.attributes().visible();
241 attrs.m_Mirrored = text.attributes().mirrored();
242 attrs.m_Multiline = text.attributes().multiline();
243 attrs.m_KeepUpright = text.attributes().keep_upright();
244 attrs.m_Size = UnpackVector2( text.attributes().size() );
245
246 if( !text.attributes().font_name().empty() )
247 {
249 wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
250 attrs.m_Italic );
251 }
252
253 attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
254 attrs.m_LineSpacing = text.attributes().line_spacing();
255 attrs.m_StrokeWidth = text.attributes().stroke_width().value_nm();
256 attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
257 text.attributes().horizontal_alignment() );
258
259 attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
260 text.attributes().vertical_alignment() );
261
262 SetAttributes( attrs );
263 }
264
265 return true;
266}
267
268
269void EDA_TEXT::SetText( const wxString& aText )
270{
271 m_text = aText;
273}
274
275
276void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
277{
278 m_text = aSrc.m_text;
280}
281
282
284{
288}
289
290
292{
293 m_attributes.m_Angle = aAngle;
296}
297
298
299void EDA_TEXT::SetItalic( bool aItalic )
300{
301 if( m_attributes.m_Italic != aItalic )
302 {
303 const KIFONT::FONT* font = GetFont();
304
305 if( !font || font->IsStroke() )
306 {
307 // For stroke fonts, just need to set the attribute.
308 }
309 else
310 {
311 // For outline fonts, italic-ness is determined by the font itself.
312 SetFont( KIFONT::FONT::GetFont( font->GetName(), IsBold(), aItalic ) );
313 }
314 }
315
316 SetItalicFlag( aItalic );
317}
318
319void EDA_TEXT::SetItalicFlag( bool aItalic )
320{
321 m_attributes.m_Italic = aItalic;
324}
325
326
327void EDA_TEXT::SetBold( bool aBold )
328{
329 if( m_attributes.m_Bold != aBold )
330 {
331 const KIFONT::FONT* font = GetFont();
332
333 if( !font || font->IsStroke() )
334 {
335 // For stroke fonts, boldness is determined by the pen size.
336 const int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
337
338 if( aBold )
339 {
342 }
343 else
344 {
345 // Restore the original stroke width from `m_StoredStrokeWidth` if it was previously stored,
346 // resetting the width after unbolding.
349 else
350 {
352 // Sets `m_StrokeWidth` to the normal pen size and stores it in `m_StoredStrokeWidth`
353 // as the default, but only if the bold option was applied before this feature was implemented.
355 }
356 }
357 }
358 else
359 {
360 // For outline fonts, boldness is determined by the font itself.
361 SetFont( KIFONT::FONT::GetFont( font->GetName(), aBold, IsItalic() ) );
362 }
363 }
364
365 SetBoldFlag( aBold );
366}
367
368
369void EDA_TEXT::SetBoldFlag( bool aBold )
370{
371 m_attributes.m_Bold = aBold;
374}
375
376
377void EDA_TEXT::SetVisible( bool aVisible )
378{
379 m_attributes.m_Visible = aVisible;
381}
382
383
384void EDA_TEXT::SetMirrored( bool isMirrored )
385{
386 m_attributes.m_Mirrored = isMirrored;
389}
390
391
393{
394 m_attributes.m_Multiline = aAllow;
397}
398
399
401{
402 m_attributes.m_Halign = aType;
405}
406
407
409{
410 m_attributes.m_Valign = aType;
413}
414
415
416void EDA_TEXT::SetKeepUpright( bool aKeepUpright )
417{
418 m_attributes.m_KeepUpright = aKeepUpright;
421}
422
423
424void EDA_TEXT::SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition )
425{
427
428 if( aSetPosition )
429 m_pos = aSrc.m_pos;
430
433}
434
435
436void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
437{
438 std::swap( m_text, aTradingPartner.m_text );
440}
441
442
443void EDA_TEXT::SwapAttributes( EDA_TEXT& aTradingPartner )
444{
445 std::swap( m_attributes, aTradingPartner.m_attributes );
446 std::swap( m_pos, aTradingPartner.m_pos );
447
449 aTradingPartner.ClearRenderCache();
450
452 aTradingPartner.m_bounding_box_cache_valid = false;
453}
454
455
456int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
457{
458 int penWidth = GetTextThickness();
459
460 if( penWidth <= 1 )
461 {
462 penWidth = aDefaultPenWidth;
463
464 if( IsBold() )
465 penWidth = GetPenSizeForBold( GetTextWidth() );
466 else if( penWidth <= 1 )
467 penWidth = GetPenSizeForNormal( GetTextWidth() );
468 }
469
470 // Clip pen size for small texts:
471 penWidth = Clamp_Text_PenSize( penWidth, GetTextSize() );
472
473 return penWidth;
474}
475
476
477bool EDA_TEXT::Replace( const EDA_SEARCH_DATA& aSearchData )
478{
479 bool retval = EDA_ITEM::Replace( aSearchData, m_text );
480
482
485
486 return retval;
487}
488
489
491{
492 m_attributes.m_Font = aFont;
495}
496
497
498void EDA_TEXT::SetLineSpacing( double aLineSpacing )
499{
500 m_attributes.m_LineSpacing = aLineSpacing;
503}
504
505
506void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
507{
508 // Plotting uses unityScale and independently scales the text. If we clamp here we'll
509 // clamp to *really* small values.
510 if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
511 aEnforceMinTextSize = false;
512
513 if( aEnforceMinTextSize )
514 {
515 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
516 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
517
518 aNewSize = VECTOR2I( std::clamp( aNewSize.x, min, max ),
519 std::clamp( aNewSize.y, min, max ) );
520 }
521
522 m_attributes.m_Size = aNewSize;
523
526}
527
528
529void EDA_TEXT::SetTextWidth( int aWidth )
530{
531 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
532 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
533
534 m_attributes.m_Size.x = std::clamp( aWidth, min, max );
537}
538
539
540void EDA_TEXT::SetTextHeight( int aHeight )
541{
542 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
543 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
544
545 m_attributes.m_Size.y = std::clamp( aHeight, min, max );
548}
549
550
551void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
552{
553 Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
554}
555
556
557void EDA_TEXT::SetTextX( int aX )
558{
559 Offset( VECTOR2I( aX - m_pos.x, 0 ) );
560}
561
562
563void EDA_TEXT::SetTextY( int aY )
564{
565 Offset( VECTOR2I( 0, aY - m_pos.y ) );
566}
567
568
569void EDA_TEXT::Offset( const VECTOR2I& aOffset )
570{
571 if( aOffset.x == 0 && aOffset.y == 0 )
572 return;
573
574 m_pos += aOffset;
575
576 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
577 {
578 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
579 outline->Move( aOffset );
580 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
581 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
582 }
583
585}
586
587
589{
590 m_text.Empty();
593}
594
595
597{
598 if( m_text.IsEmpty() )
599 {
600 m_shown_text = wxEmptyString;
602 }
603 else
604 {
606 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
607 }
608
611}
612
613
615{
616 KIFONT::FONT* font = GetFont();
617
618 if( !font )
619 font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
620
621 return font;
622}
623
624
626{
628}
629
630
632{
633 m_render_cache.clear();
634}
635
636
638{
640}
641
642
643std::vector<std::unique_ptr<KIFONT::GLYPH>>*
644EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
645 const VECTOR2I& aOffset ) const
646{
647 if( aFont->IsOutline() )
648 {
649 EDA_ANGLE resolvedAngle = GetDrawRotation();
650
651 if( m_render_cache.empty()
652 || m_render_cache_font != aFont
653 || m_render_cache_text != forResolvedText
654 || m_render_cache_angle != resolvedAngle
655 || m_render_cache_offset != aOffset )
656 {
657 m_render_cache.clear();
658
659 const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
661
662 attrs.m_Angle = resolvedAngle;
663
664 font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
665 attrs, getFontMetrics() );
666 m_render_cache_font = aFont;
667 m_render_cache_angle = resolvedAngle;
668 m_render_cache_text = forResolvedText;
669 m_render_cache_offset = aOffset;
670 }
671
672 return &m_render_cache;
673 }
674
675 return nullptr;
676}
677
678
679void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const KIFONT::FONT* aFont,
680 const EDA_ANGLE& aAngle, const VECTOR2I& aOffset )
681{
682 m_render_cache_text = aResolvedText;
683 m_render_cache_font = aFont;
684 m_render_cache_angle = aAngle;
685 m_render_cache_offset = aOffset;
686 m_render_cache.clear();
687}
688
689
691{
692 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
693 static_cast<KIFONT::OUTLINE_GLYPH*>( m_render_cache.back().get() )->CacheTriangulation();
694}
695
696
698{
700}
701
702
703BOX2I EDA_TEXT::GetTextBox( int aLine ) const
704{
705 VECTOR2I drawPos = GetDrawPos();
706
708 && m_bounding_box_cache_pos == drawPos
709 && m_bounding_box_cache_line == aLine )
710 {
712 }
713
714 BOX2I bbox;
715 wxArrayString strings;
716 wxString text = GetShownText( true );
717 int thickness = GetEffectiveTextPenWidth();
718
719 if( IsMultilineAllowed() )
720 {
721 wxStringSplit( text, strings, '\n' );
722
723 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
724 {
725 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
726 text = strings.Item( aLine );
727 else
728 text = strings.Item( 0 );
729 }
730 }
731
732 // calculate the H and V size
733 KIFONT::FONT* font = getDrawFont();
734 VECTOR2D fontSize( GetTextSize() );
735 bool bold = IsBold();
736 bool italic = IsItalic();
737 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
738 getFontMetrics() );
739 int overbarOffset = 0;
740
741 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
742 // bounding box will be moved later according to the actual text options
743 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
744 VECTOR2I pos = drawPos;
745 int fudgeFactor = KiROUND( extents.y * 0.17 );
746
747 if( font->IsStroke() )
748 textsize.y += fudgeFactor;
749
750 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
751 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
752
753 if( text.Contains( wxT( "~{" ) ) )
754 overbarOffset = extents.y / 6;
755
756 bbox.SetOrigin( pos );
757
758 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
759 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
760 {
761 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
762 {
763 text = strings.Item( ii );
764 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
765 getFontMetrics() );
766 textsize.x = std::max( textsize.x, extents.x );
767 }
768
769 // interline spacing is only *between* lines, so total height is the height of the first
770 // line plus the interline distance (with interline spacing) for all subsequent lines
771 textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y,
772 getFontMetrics() ) );
773 }
774
775 textsize.y += overbarOffset;
776
777 bbox.SetSize( textsize );
778
779 /*
780 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
781 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
782 */
783 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
784
785 switch( GetHorizJustify() )
786 {
788 if( IsMirrored() )
789 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
790 break;
791
793 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
794 break;
795
797 if( !IsMirrored() )
798 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
799 break;
800
802 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
803 break;
804 }
805
806 switch( GetVertJustify() )
807 {
809 bbox.Offset( 0, -fudgeFactor );
810 break;
811
813 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
814 break;
815
817 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
818 bbox.Offset( 0, fudgeFactor );
819 break;
820
822 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
823 break;
824 }
825
826 bbox.Normalize(); // Make h and v sizes always >= 0
827
829 m_bounding_box_cache_pos = drawPos;
832
833 return bbox;
834}
835
836
837bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
838{
839 const BOX2I rect = GetTextBox().GetInflated( aAccuracy );
840 const VECTOR2I location = GetRotated( aPoint, GetDrawPos(), -GetDrawRotation() );
841 return rect.Contains( location );
842}
843
844
845bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
846{
847 const BOX2I rect = aRect.GetInflated( aAccuracy );
848
849 if( aContains )
850 return rect.Contains( GetTextBox() );
851
852 return rect.Intersects( GetTextBox(), GetDrawRotation() );
853}
854
855
856void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
857 const COLOR4D& aColor, OUTLINE_MODE aFillMode )
858{
859 if( IsMultilineAllowed() )
860 {
861 std::vector<VECTOR2I> positions;
862 wxArrayString strings;
863 wxStringSplit( GetShownText( true ), strings, '\n' );
864
865 positions.reserve( strings.Count() );
866
867 GetLinePositions( positions, (int) strings.Count() );
868
869 for( unsigned ii = 0; ii < strings.Count(); ii++ )
870 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
871 }
872 else
873 {
874 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
875 GetDrawPos() );
876 }
877}
878
879
880void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
881{
882 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
883 // to the center of the multiline text block
884
885 VECTOR2I offset; // Offset to next line.
886
887 offset.y = GetInterline();
888
889 if( aLineCount > 1 )
890 {
891 switch( GetVertJustify() )
892 {
894 break;
895
897 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
898 break;
899
901 pos.y -= ( aLineCount - 1 ) * offset.y;
902 break;
903
905 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
906 break;
907 }
908 }
909
910 // Rotate the position of the first line around the center of the multiline text block
912
913 // Rotate the offset lines to increase happened in the right direction
914 RotatePoint( offset, GetDrawRotation() );
915
916 for( int ii = 0; ii < aLineCount; ii++ )
917 {
918 aPositions.push_back( (VECTOR2I) pos );
919 pos += offset;
920 }
921}
922
923
924void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
925 const COLOR4D& aColor, OUTLINE_MODE aFillMode,
926 const wxString& aText, const VECTOR2I& aPos )
927{
928 wxDC* DC = aSettings->GetPrintDC();
929 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
930
931 if( aFillMode == SKETCH )
932 penWidth = -penWidth;
933
934 VECTOR2I size = GetTextSize();
935
936 if( IsMirrored() )
937 size.x = -size.x;
938
939 KIFONT::FONT* font = GetFont();
940
941 if( !font )
942 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
943
944 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
945 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
946}
947
948
950{
951 int style = 0;
952
953 if( IsItalic() )
954 style = 1;
955
956 if( IsBold() )
957 style += 2;
958
959 wxString stylemsg[4] = {
960 _("Normal"),
961 _("Italic"),
962 _("Bold"),
963 _("Bold+Italic")
964 };
965
966 return stylemsg[style];
967}
968
969
970wxString EDA_TEXT::GetFontName() const
971{
972 if( GetFont() )
973 return GetFont()->GetName();
974 else
975 return wxEmptyString;
976}
977
978
980{
981 if( !GetFont() )
982 return -1;
983
984 if( GetFont()->GetName() == KICAD_FONT_NAME )
985 return -2;
986
987 std::vector<std::string> fontNames;
988 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
989
990 for( int ii = 0; ii < (int) fontNames.size(); ++ii )
991 {
992 if( fontNames[ii] == GetFont()->GetName() )
993 return ii;
994 }
995
996 return 0;
997}
998
999
1001{
1002 if( aIdx == -1 )
1003 {
1004 SetFont( nullptr );
1005 }
1006 else if( aIdx == -2 )
1007 {
1008 SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
1009 }
1010 else
1011 {
1012 std::vector<std::string> fontNames;
1013 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
1014
1015 if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
1016 SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
1017 else
1018 SetFont( nullptr );
1019 }
1020}
1021
1022
1024{
1025 return ( IsVisible()
1026 && !IsMirrored()
1029 && GetTextThickness() == 0
1030 && !IsItalic()
1031 && !IsBold()
1032 && !IsMultilineAllowed()
1033 && GetFontName().IsEmpty()
1034 );
1035}
1036
1037
1038void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aControlBits ) const
1039{
1040 aFormatter->Print( "(effects" );
1041
1042 aFormatter->Print( "(font" );
1043
1044 if( GetFont() && !GetFont()->GetName().IsEmpty() )
1045 aFormatter->Print( "(face %s)", aFormatter->Quotew( GetFont()->NameAsToken() ).c_str() );
1046
1047 // Text size
1048 aFormatter->Print( "(size %s %s)",
1051
1052 if( GetLineSpacing() != 1.0 )
1053 {
1054 aFormatter->Print( "(line_spacing %s)",
1055 FormatDouble2Str( GetLineSpacing() ).c_str() );
1056 }
1057
1058 if( GetTextThickness() )
1059 {
1060 aFormatter->Print( "(thickness %s)",
1062 }
1063
1064 if( IsBold() )
1065 KICAD_FORMAT::FormatBool( aFormatter, "bold", true );
1066
1067 if( IsItalic() )
1068 KICAD_FORMAT::FormatBool( aFormatter, "italic", true );
1069
1070 if( !( aControlBits & CTL_OMIT_COLOR ) && GetTextColor() != COLOR4D::UNSPECIFIED )
1071 {
1072 aFormatter->Print( "(color %d %d %d %s)",
1073 KiROUND( GetTextColor().r * 255.0 ),
1074 KiROUND( GetTextColor().g * 255.0 ),
1075 KiROUND( GetTextColor().b * 255.0 ),
1076 FormatDouble2Str( GetTextColor().a ).c_str() );
1077 }
1078
1079 aFormatter->Print( ")"); // (font
1080
1083 {
1084 aFormatter->Print( "(justify");
1085
1087 aFormatter->Print( GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
1088
1090 aFormatter->Print( GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
1091
1092 if( IsMirrored() )
1093 aFormatter->Print( " mirror" );
1094
1095 aFormatter->Print( ")" ); // (justify
1096 }
1097
1098 if( !( aControlBits & CTL_OMIT_HIDE ) && !IsVisible() )
1099 KICAD_FORMAT::FormatBool( aFormatter, "hide", true );
1100
1101 if( !( aControlBits & CTL_OMIT_HYPERLINK ) && HasHyperlink() )
1102 {
1103 aFormatter->Print( "(href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
1104 }
1105
1106 aFormatter->Print( ")" ); // (effects
1107}
1108
1109
1110std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
1111 const BOX2I& aBBox,
1112 const EDA_ANGLE& aAngle ) const
1113{
1114 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
1115 KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
1116 KIFONT::FONT* font = getDrawFont();
1117 int penWidth = GetEffectiveTextPenWidth();
1118 wxString shownText( GetShownText( true ) );
1119 VECTOR2I drawPos = GetDrawPos();
1121
1122 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
1123
1124 if( aBBox.GetWidth() )
1125 {
1126 drawPos = aBBox.GetCenter();
1129 attrs.m_Angle = aAngle;
1130 }
1131 else
1132 {
1133 attrs.m_Angle = GetDrawRotation();
1134
1135 if( font->IsOutline() )
1136 cache = GetRenderCache( font, shownText, VECTOR2I() );
1137 }
1138
1139 if( aTriangulate )
1140 {
1141 CALLBACK_GAL callback_gal(
1142 empty_opts,
1143 // Stroke callback
1144 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1145 {
1146 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1147 },
1148 // Triangulation callback
1149 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1150 {
1151 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1152
1153 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1154 triShape->Append( point.x, point.y );
1155
1156 shape->AddShape( triShape );
1157 } );
1158
1159 if( cache )
1160 callback_gal.DrawGlyphs( *cache );
1161 else
1162 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1163 }
1164 else
1165 {
1166 CALLBACK_GAL callback_gal(
1167 empty_opts,
1168 // Stroke callback
1169 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1170 {
1171 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1172 },
1173 // Outline callback
1174 [&]( const SHAPE_LINE_CHAIN& aPoly )
1175 {
1176 shape->AddShape( aPoly.Clone() );
1177 } );
1178
1179 if( cache )
1180 callback_gal.DrawGlyphs( *cache );
1181 else
1182 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1183 }
1184
1185 return shape;
1186}
1187
1188
1189int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1190{
1191 wxCHECK( aOther, 1 );
1192
1193 int val = m_attributes.Compare( aOther->m_attributes );
1194
1195 if( val != 0 )
1196 return val;
1197
1198 if( m_pos.x != aOther->m_pos.x )
1199 return m_pos.x - aOther->m_pos.x;
1200
1201 if( m_pos.y != aOther->m_pos.y )
1202 return m_pos.y - aOther->m_pos.y;
1203
1204 val = GetFontName().Cmp( aOther->GetFontName() );
1205
1206 if( val != 0 )
1207 return val;
1208
1209 return m_text.Cmp( aOther->m_text );
1210}
1211
1212
1213bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1214{
1215 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1216 return true;
1217
1218 wxURI uri;
1219
1220 return( uri.Create( aURL ) && uri.HasScheme() );
1221}
1222
1223double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1224{
1225 // Compute the Levenshtein distance between the two strings
1226 const wxString& str1 = GetText();
1227 const wxString& str2 = aOther.GetText();
1228
1229 int m = str1.length();
1230 int n = str2.length();
1231
1232 if( n == 0 || m == 0 )
1233 return 0.0;
1234
1235 // Create a matrix to store the distance values
1236 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1237
1238 // Initialize the matrix
1239 for( int i = 0; i <= m; i++ )
1240 distance[i][0] = i;
1241 for( int j = 0; j <= n; j++ )
1242 distance[0][j] = j;
1243
1244 // Calculate the distance
1245 for( int i = 1; i <= m; i++ )
1246 {
1247 for( int j = 1; j <= n; j++ )
1248 {
1249 if( str1[i - 1] == str2[j - 1] )
1250 {
1251 distance[i][j] = distance[i - 1][j - 1];
1252 }
1253 else
1254 {
1255 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1256 distance[i - 1][j - 1] } ) + 1;
1257 }
1258 }
1259 }
1260
1261 // Calculate similarity score
1262 int maxLen = std::max( m, n );
1263 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1264
1265 return similarity;
1266}
1267
1268
1269double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1270{
1271 double retval = 1.0;
1272
1273 if( !( m_attributes == aOther.m_attributes ) )
1274 retval *= 0.9;
1275
1276 if( m_pos != aOther.m_pos )
1277 retval *= 0.9;
1278
1279 retval *= Levenshtein( aOther );
1280
1281 return retval;
1282}
1283
1284
1285bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1286{
1287 return aHref.StartsWith( wxT( "#" ), aDestination );
1288}
1289
1290
1291wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1292{
1293 return wxT( "#" ) + aDestination;
1294}
1295
1296
1297std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1298{
1299 aStream << aText.GetText();
1300
1301 return aStream;
1302}
1303
1304
1305static struct EDA_TEXT_DESC
1306{
1308 {
1309 // These are defined in SCH_FIELD as well but initialization order is
1310 // not defined, so this needs to be conditional. Defining in both
1311 // places leads to duplicate symbols.
1313
1314 if( h_inst.Choices().GetCount() == 0)
1315 {
1316 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
1317 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
1318 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
1319 }
1320
1322
1323 if( v_inst.Choices().GetCount() == 0)
1324 {
1325 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
1326 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
1327 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
1328 }
1329
1332
1333 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1335 PROPERTY_DISPLAY::PT_DEGREE ) );
1336
1337 const wxString textProps = _HKI( "Text Properties" );
1338
1339 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1341 textProps );
1342
1343 // This must be a PROPERTY_ENUM to get a choice list.
1344 // SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
1345 propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
1347 textProps )
1349
1350 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1352 PROPERTY_DISPLAY::PT_SIZE ),
1353 textProps );
1354 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1357 textProps );
1358 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1360 textProps );
1361 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1363 textProps );
1364 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
1366 textProps );
1367 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1369 PROPERTY_DISPLAY::PT_SIZE ),
1370 textProps );
1371
1372 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1374 PROPERTY_DISPLAY::PT_SIZE ),
1375 textProps );
1376
1378 _HKI( "Horizontal Justification" ),
1380 textProps );
1382 _HKI( "Vertical Justification" ),
1384 textProps );
1385
1386 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1388 textProps );
1389
1390 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1392 textProps );
1393 }
1395
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:111
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:146
constexpr coord_type GetY() const
Definition: box2.h:208
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr coord_type GetX() const
Definition: box2.h:207
constexpr const Vec GetCenter() const
Definition: box2.h:230
constexpr void SetSize(const SizeVec &size)
Definition: box2.h:248
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr bool Contains(const Vec &aPoint) const
Definition: box2.h:168
constexpr void SetX(coord_type val)
Definition: box2.h:277
constexpr BOX2< Vec > GetInflated(coord_type aDx, coord_type aDy) const
Get a new rectangle that is this one, inflated by aDx and aDy.
Definition: box2.h:638
constexpr void SetY(coord_type val)
Definition: box2.h:282
constexpr void Offset(coord_type dx, coord_type dy)
Definition: box2.h:259
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:189
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
int GetTextHeight() const
Definition: eda_text.h:251
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: eda_text.cpp:185
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:253
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:257
COLOR4D GetTextColor() const
Definition: eda_text.h:254
wxString GetTextStyleName() const
Definition: eda_text.cpp:949
VECTOR2I m_pos
Definition: eda_text.h:459
wxString m_text
Definition: eda_text.h:441
bool IsDefaultFormatting() const
Definition: eda_text.cpp:1023
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1285
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:451
wxString GetFontName() const
Definition: eda_text.cpp:970
virtual ~EDA_TEXT()
Definition: eda_text.cpp:149
bool IsItalic() const
Definition: eda_text.h:156
BOX2I m_bounding_box_cache
Definition: eda_text.h:456
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:506
bool IsMultilineAllowed() const
Definition: eda_text.h:184
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:697
bool IsKeepUpright() const
Definition: eda_text.h:193
virtual bool IsVisible() const
Definition: eda_text.h:174
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:551
void SetTextX(int aX)
Definition: eda_text.cpp:557
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:443
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: eda_text.cpp:221
KIFONT::FONT * GetFont() const
Definition: eda_text.h:234
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:424
wxString m_shown_text
Definition: eda_text.h:442
int GetFontIndex() const
Definition: eda_text.cpp:979
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:703
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:384
void SetTextY(int aY)
Definition: eda_text.cpp:563
int m_bounding_box_cache_line
Definition: eda_text.h:455
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:644
const KIFONT::FONT * m_render_cache_font
Definition: eda_text.h:448
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:362
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:363
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition: eda_text.cpp:154
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:924
int GetTextWidth() const
Definition: eda_text.h:248
virtual bool HasHyperlink() const
Definition: eda_text.h:383
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:408
wxString GetHyperlink() const
Definition: eda_text.h:384
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:569
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:1038
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:187
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:529
void SetBoldFlag(bool aBold)
Set only the italic flag, without changing the font.
Definition: eda_text.cpp:369
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:477
void SetupRenderCache(const wxString &aResolvedText, const KIFONT::FONT *aFont, const EDA_ANGLE &aAngle, const VECTOR2I &aOffset)
Definition: eda_text.cpp:679
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1189
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:445
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:377
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition: eda_text.cpp:95
bool m_bounding_box_cache_valid
Definition: eda_text.h:453
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:880
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1291
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:637
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:614
double GetLineSpacing() const
Definition: eda_text.h:242
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1269
VECTOR2I m_render_cache_offset
Definition: eda_text.h:450
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:498
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:690
void Empty()
Definition: eda_text.cpp:588
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:283
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:837
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:540
virtual void cacheShownText()
Definition: eda_text.cpp:596
EDA_ANGLE m_render_cache_angle
Definition: eda_text.h:449
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:67
virtual void ClearRenderCache()
Definition: eda_text.cpp:631
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:218
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
Definition: eda_text.cpp:327
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
Definition: eda_text.cpp:1213
VECTOR2I m_bounding_box_cache_pos
Definition: eda_text.h:454
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
Definition: eda_text.cpp:319
bool IsMirrored() const
Definition: eda_text.h:177
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:456
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:443
wxString m_render_cache_text
Definition: eda_text.h:447
double GetTextAngleDegrees() const
Definition: eda_text.h:141
virtual const KIFONT::METRICS & getFontMetrics() const
Definition: eda_text.cpp:625
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:1110
bool IsBold() const
Definition: eda_text.h:171
void SetTextAngleDegrees(double aOrientation)
Definition: eda_text.h:137
void SetHyperlink(wxString aLink)
Definition: eda_text.h:385
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:81
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:416
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:276
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:190
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:109
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:269
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
Definition: eda_text.cpp:1223
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:291
void SetFontIndex(int aIdx)
Definition: eda_text.cpp:1000
int GetTextThickness() const
Definition: eda_text.h:126
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:856
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:299
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:436
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:392
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:490
VECTOR2I GetTextSize() const
Definition: eda_text.h:245
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:400
TEXT_ATTRIBUTES m_attributes
Definition: eda_text.h:458
static ENUM_MAP< T > & Instance()
Definition: property.h:663
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition: font.cpp:146
virtual bool IsStroke() const
Definition: font.h:138
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
Definition: font.cpp:258
const wxString & GetName() const
Definition: font.h:149
virtual bool IsOutline() const
Definition: font.h:139
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
Definition: font.cpp:435
virtual double GetInterline(double aGlyphHeight, const METRICS &aFontMetrics) const =0
Compute the distance (interline) between 2 lines of text (for multiline texts).
static const METRICS & Default()
Definition: font.cpp:52
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:53
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
const wxString & GetDefaultFont() const
wxDC * GetPrintDC() const
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:543
int PRINTF_FUNC_N 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
@ DEGREES_T
Definition: eda_angle.h:31
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1297
static struct EDA_TEXT_DESC _EDA_TEXT_DESC
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
Definition: eda_text.h:47
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition: eda_text.h:48
#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
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
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
OUTLINE_MODE
Definition: outline_mode.h:25
@ SKETCH
Definition: outline_mode.h:26
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:765
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
wxString UnescapeString(const wxString &aSource)
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
const double IU_PER_MM
Definition: base_units.h:76
GR_TEXT_H_ALIGN_T
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
Definition: trigo.h:77
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:229
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691