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 The KiCad Developers, see AUTHORS.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>
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_visible( true )
100{
103
104 if( m_text.IsEmpty() )
105 {
106 m_shown_text = wxEmptyString;
108 }
109 else
110 {
112 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
113 }
114}
115
116
118 m_IuScale( aText.m_IuScale )
119{
120 m_text = aText.m_text;
123
125 m_pos = aText.m_pos;
126 m_visible = aText.m_visible;
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
144
146}
147
148
150{
151}
152
153
155{
156 m_text = aText.m_text;
159
161 m_pos = aText.m_pos;
162 m_visible = aText.m_visible;
163
168
169 m_render_cache.clear();
170
171 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
172 {
173 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
174 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
175 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
176 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
177 }
178
180
182
183 return *this;
184}
185
186
187void EDA_TEXT::Serialize( google::protobuf::Any &aContainer ) const
188{
189 using namespace kiapi::common;
190 types::Text text;
191
192 text.set_text( GetText().ToStdString() );
193 text.set_hyperlink( GetHyperlink().ToStdString() );
194 PackVector2( *text.mutable_position(), GetTextPos() );
195
196 types::TextAttributes* attrs = text.mutable_attributes();
197
198 if( GetFont() )
199 attrs->set_font_name( GetFont()->GetName().ToStdString() );
200
201 attrs->set_horizontal_alignment(
202 ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
203
204 attrs->set_vertical_alignment(
205 ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
206
207 attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
208 attrs->set_line_spacing( GetLineSpacing() );
209 attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
210 attrs->set_italic( IsItalic() );
211 attrs->set_bold( IsBold() );
212 attrs->set_underlined( GetAttributes().m_Underlined );
213 attrs->set_visible( true );
214 attrs->set_mirrored( IsMirrored() );
215 attrs->set_multiline( IsMultilineAllowed() );
216 attrs->set_keep_upright( IsKeepUpright() );
217 PackVector2( *attrs->mutable_size(), GetTextSize() );
218
219 aContainer.PackFrom( text );
220}
221
222
223bool EDA_TEXT::Deserialize( const google::protobuf::Any &aContainer )
224{
225 using namespace kiapi::common;
226 types::Text text;
227
228 if( !aContainer.UnpackTo( &text ) )
229 return false;
230
231 SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
232 SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
233 SetTextPos( UnpackVector2( text.position() ) );
234
235 if( text.has_attributes() )
236 {
238
239 attrs.m_Bold = text.attributes().bold();
240 attrs.m_Italic = text.attributes().italic();
241 attrs.m_Underlined = text.attributes().underlined();
242 attrs.m_Mirrored = text.attributes().mirrored();
243 attrs.m_Multiline = text.attributes().multiline();
244 attrs.m_KeepUpright = text.attributes().keep_upright();
245 attrs.m_Size = UnpackVector2( text.attributes().size() );
246
247 if( !text.attributes().font_name().empty() )
248 {
250 wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
251 attrs.m_Italic );
252 }
253
254 attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
255 attrs.m_LineSpacing = text.attributes().line_spacing();
256 attrs.m_StrokeWidth = text.attributes().stroke_width().value_nm();
257 attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
258 text.attributes().horizontal_alignment() );
259
260 attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
261 text.attributes().vertical_alignment() );
262
263 SetAttributes( attrs );
264 }
265
266 return true;
267}
268
269
270void EDA_TEXT::SetText( const wxString& aText )
271{
272 m_text = aText;
274}
275
276
277void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
278{
279 m_text = aSrc.m_text;
281}
282
283
285{
289}
290
291
293{
294 m_attributes.m_Angle = aAngle;
297}
298
299
300void EDA_TEXT::SetItalic( bool aItalic )
301{
302 if( m_attributes.m_Italic != aItalic )
303 {
304 const KIFONT::FONT* font = GetFont();
305
306 if( !font || font->IsStroke() )
307 {
308 // For stroke fonts, just need to set the attribute.
309 }
310 else
311 {
312 // For outline fonts, italic-ness is determined by the font itself.
313 SetFont( KIFONT::FONT::GetFont( font->GetName(), IsBold(), aItalic ) );
314 }
315 }
316
317 SetItalicFlag( aItalic );
318}
319
320void EDA_TEXT::SetItalicFlag( bool aItalic )
321{
322 m_attributes.m_Italic = aItalic;
325}
326
327
328void EDA_TEXT::SetBold( bool aBold )
329{
330 if( m_attributes.m_Bold != aBold )
331 {
332 const KIFONT::FONT* font = GetFont();
333
334 if( !font || font->IsStroke() )
335 {
336 // For stroke fonts, boldness is determined by the pen size.
337 const int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
338
339 if( aBold )
340 {
343 }
344 else
345 {
346 // Restore the original stroke width from `m_StoredStrokeWidth` if it was
347 // previously stored, resetting the width after unbolding.
350 else
351 {
353 // Sets `m_StrokeWidth` to the normal pen size and stores it in
354 // `m_StoredStrokeWidth` as the default, but only if the bold option was
355 // applied before this feature was implemented.
357 }
358 }
359 }
360 else
361 {
362 // For outline fonts, boldness is determined by the font itself.
363 SetFont( KIFONT::FONT::GetFont( font->GetName(), aBold, IsItalic() ) );
364 }
365 }
366
367 SetBoldFlag( aBold );
368}
369
370
371void EDA_TEXT::SetBoldFlag( bool aBold )
372{
373 m_attributes.m_Bold = aBold;
376}
377
378
379void EDA_TEXT::SetVisible( bool aVisible )
380{
381 m_visible = aVisible;
383}
384
385
386void EDA_TEXT::SetMirrored( bool isMirrored )
387{
388 m_attributes.m_Mirrored = isMirrored;
391}
392
393
395{
396 m_attributes.m_Multiline = aAllow;
399}
400
401
403{
404 m_attributes.m_Halign = aType;
407}
408
409
411{
412 m_attributes.m_Valign = aType;
415}
416
417
418void EDA_TEXT::SetKeepUpright( bool aKeepUpright )
419{
420 m_attributes.m_KeepUpright = aKeepUpright;
423}
424
425
426void EDA_TEXT::SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition )
427{
429
430 if( aSetPosition )
431 m_pos = aSrc.m_pos;
432
435}
436
437
438void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
439{
440 std::swap( m_text, aTradingPartner.m_text );
442}
443
444
445void EDA_TEXT::SwapAttributes( EDA_TEXT& aTradingPartner )
446{
447 std::swap( m_attributes, aTradingPartner.m_attributes );
448 std::swap( m_pos, aTradingPartner.m_pos );
449
451 aTradingPartner.ClearRenderCache();
452
454 aTradingPartner.ClearBoundingBoxCache();
455}
456
457
458int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
459{
460 int penWidth = GetTextThickness();
461
462 if( penWidth <= 1 )
463 {
464 penWidth = aDefaultPenWidth;
465
466 if( IsBold() )
467 penWidth = GetPenSizeForBold( GetTextWidth() );
468 else if( penWidth <= 1 )
469 penWidth = GetPenSizeForNormal( GetTextWidth() );
470 }
471
472 // Clip pen size for small texts:
473 penWidth = ClampTextPenSize( penWidth, GetTextSize() );
474
475 return penWidth;
476}
477
478
479bool EDA_TEXT::Replace( const EDA_SEARCH_DATA& aSearchData )
480{
481 bool retval = EDA_ITEM::Replace( aSearchData, m_text );
482
484
487
488 return retval;
489}
490
491
493{
494 m_attributes.m_Font = aFont;
497}
498
499
500bool EDA_TEXT::ResolveFont( const std::vector<wxString>* aEmbeddedFonts )
501{
502 if( !m_unresolvedFontName.IsEmpty() )
503 {
505 aEmbeddedFonts );
506
507 if( !m_render_cache.empty() )
509
510 m_unresolvedFontName = wxEmptyString;
511 return true;
512 }
513
514 return false;
515}
516
517
518void EDA_TEXT::SetLineSpacing( double aLineSpacing )
519{
520 m_attributes.m_LineSpacing = aLineSpacing;
523}
524
525
526void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
527{
528 // Plotting uses unityScale and independently scales the text. If we clamp here we'll
529 // clamp to *really* small values.
530 if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
531 aEnforceMinTextSize = false;
532
533 if( aEnforceMinTextSize )
534 {
535 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
536 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
537
538 aNewSize = VECTOR2I( std::clamp( aNewSize.x, min, max ),
539 std::clamp( aNewSize.y, min, max ) );
540 }
541
542 m_attributes.m_Size = aNewSize;
543
546}
547
548
549void EDA_TEXT::SetTextWidth( int aWidth )
550{
551 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
552 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
553
554 m_attributes.m_Size.x = std::clamp( aWidth, min, max );
557}
558
559
560void EDA_TEXT::SetTextHeight( int aHeight )
561{
562 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
563 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
564
565 m_attributes.m_Size.y = std::clamp( aHeight, min, max );
568}
569
570
571void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
572{
573 Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
574}
575
576
577void EDA_TEXT::SetTextX( int aX )
578{
579 Offset( VECTOR2I( aX - m_pos.x, 0 ) );
580}
581
582
583void EDA_TEXT::SetTextY( int aY )
584{
585 Offset( VECTOR2I( 0, aY - m_pos.y ) );
586}
587
588
589void EDA_TEXT::Offset( const VECTOR2I& aOffset )
590{
591 if( aOffset.x == 0 && aOffset.y == 0 )
592 return;
593
594 m_pos += aOffset;
595
596 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
597 {
598 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
599 outline->Move( aOffset );
600 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
601 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
602 }
603
605}
606
607
609{
610 m_text.Empty();
613}
614
615
617{
618 if( m_text.IsEmpty() )
619 {
620 m_shown_text = wxEmptyString;
622 }
623 else
624 {
626 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
627 }
628
631}
632
633
635{
636 KIFONT::FONT* font = GetFont();
637
638 if( !font )
639 font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
640
641 return font;
642}
643
644
646{
648}
649
650
652{
653 m_render_cache.clear();
654}
655
656
658{
659 m_bbox_cache.clear();
660}
661
662
663std::vector<std::unique_ptr<KIFONT::GLYPH>>*
664EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
665 const VECTOR2I& aOffset ) const
666{
667 if( aFont->IsOutline() )
668 {
669 EDA_ANGLE resolvedAngle = GetDrawRotation();
670
671 if( m_render_cache.empty()
672 || m_render_cache_font != aFont
673 || m_render_cache_text != forResolvedText
674 || m_render_cache_angle != resolvedAngle
675 || m_render_cache_offset != aOffset )
676 {
677 m_render_cache.clear();
678
679 const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
681
682 attrs.m_Angle = resolvedAngle;
683
684 font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
685 attrs, getFontMetrics() );
686 m_render_cache_font = aFont;
687 m_render_cache_angle = resolvedAngle;
688 m_render_cache_text = forResolvedText;
689 m_render_cache_offset = aOffset;
690 }
691
692 return &m_render_cache;
693 }
694
695 return nullptr;
696}
697
698
699void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const KIFONT::FONT* aFont,
700 const EDA_ANGLE& aAngle, const VECTOR2I& aOffset )
701{
702 m_render_cache_text = aResolvedText;
703 m_render_cache_font = aFont;
704 m_render_cache_angle = aAngle;
705 m_render_cache_offset = aOffset;
706 m_render_cache.clear();
707}
708
709
711{
712 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
713 static_cast<KIFONT::OUTLINE_GLYPH*>( m_render_cache.back().get() )->CacheTriangulation();
714}
715
716
718{
720}
721
722
723BOX2I EDA_TEXT::GetTextBox( int aLine ) const
724{
725 VECTOR2I drawPos = GetDrawPos();
726
727 auto cache_it = m_bbox_cache.find( aLine );
728
729 if( cache_it != m_bbox_cache.end() && cache_it->second.m_pos == drawPos )
730 return cache_it->second.m_bbox;
731
732 BOX2I bbox;
733 wxArrayString strings;
734 wxString text = GetShownText( true );
735 int thickness = GetEffectiveTextPenWidth();
736
737 if( IsMultilineAllowed() )
738 {
739 wxStringSplit( text, strings, '\n' );
740
741 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
742 {
743 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
744 text = strings.Item( aLine );
745 else
746 text = strings.Item( 0 );
747 }
748 }
749
750 // calculate the H and V size
751 KIFONT::FONT* font = getDrawFont();
752 VECTOR2D fontSize( GetTextSize() );
753 bool bold = IsBold();
754 bool italic = IsItalic();
755 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
756 getFontMetrics() );
757 int overbarOffset = 0;
758
759 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
760 // bounding box will be moved later according to the actual text options
761 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
762 VECTOR2I pos = drawPos;
763 int fudgeFactor = KiROUND( extents.y * 0.17 );
764
765 if( font->IsStroke() )
766 textsize.y += fudgeFactor;
767
768 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
769 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
770
771 if( text.Contains( wxT( "~{" ) ) )
772 overbarOffset = extents.y / 6;
773
774 bbox.SetOrigin( pos );
775
776 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
777 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
778 {
779 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
780 {
781 text = strings.Item( ii );
782 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
783 getFontMetrics() );
784 textsize.x = std::max( textsize.x, extents.x );
785 }
786
787 // interline spacing is only *between* lines, so total height is the height of the first
788 // line plus the interline distance (with interline spacing) for all subsequent lines
789 textsize.y += KiROUND( ( strings.GetCount() - 1 )
790 * font->GetInterline( fontSize.y, getFontMetrics() ) );
791 }
792
793 textsize.y += overbarOffset;
794
795 bbox.SetSize( textsize );
796
797 /*
798 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
799 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
800 */
801 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
802
803 switch( GetHorizJustify() )
804 {
806 if( IsMirrored() )
807 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
808
809 break;
810
812 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
813 break;
814
816 if( !IsMirrored() )
817 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
818 break;
819
821 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
822 break;
823 }
824
825 switch( GetVertJustify() )
826 {
828 bbox.Offset( 0, -fudgeFactor );
829 break;
830
832 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
833 break;
834
836 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
837 bbox.Offset( 0, fudgeFactor );
838 break;
839
841 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
842 break;
843 }
844
845 bbox.Normalize(); // Make h and v sizes always >= 0
846
847 m_bbox_cache[ aLine ] = { drawPos, bbox };
848
849 return bbox;
850}
851
852
853bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
854{
855 const BOX2I rect = GetTextBox().GetInflated( aAccuracy );
856 const VECTOR2I location = GetRotated( aPoint, GetDrawPos(), -GetDrawRotation() );
857 return rect.Contains( location );
858}
859
860
861bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
862{
863 const BOX2I rect = aRect.GetInflated( aAccuracy );
864
865 if( aContains )
866 return rect.Contains( GetTextBox() );
867
868 return rect.Intersects( GetTextBox(), GetDrawRotation() );
869}
870
871
872void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
873 const COLOR4D& aColor, OUTLINE_MODE aFillMode )
874{
875 if( IsMultilineAllowed() )
876 {
877 std::vector<VECTOR2I> positions;
878 wxArrayString strings;
879 wxStringSplit( GetShownText( true ), strings, '\n' );
880
881 positions.reserve( strings.Count() );
882
883 GetLinePositions( positions, (int) strings.Count() );
884
885 for( unsigned ii = 0; ii < strings.Count(); ii++ )
886 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
887 }
888 else
889 {
890 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
891 GetDrawPos() );
892 }
893}
894
895
896void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
897{
898 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
899 // to the center of the multiline text block
900
901 VECTOR2I offset; // Offset to next line.
902
903 offset.y = GetInterline();
904
905 if( aLineCount > 1 )
906 {
907 switch( GetVertJustify() )
908 {
910 break;
911
913 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
914 break;
915
917 pos.y -= ( aLineCount - 1 ) * offset.y;
918 break;
919
921 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
922 break;
923 }
924 }
925
926 // Rotate the position of the first line around the center of the multiline text block
928
929 // Rotate the offset lines to increase happened in the right direction
930 RotatePoint( offset, GetDrawRotation() );
931
932 for( int ii = 0; ii < aLineCount; ii++ )
933 {
934 aPositions.push_back( (VECTOR2I) pos );
935 pos += offset;
936 }
937}
938
939
940void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
941 const COLOR4D& aColor, OUTLINE_MODE aFillMode,
942 const wxString& aText, const VECTOR2I& aPos )
943{
944 wxDC* DC = aSettings->GetPrintDC();
945 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
946
947 if( aFillMode == SKETCH )
948 penWidth = -penWidth;
949
950 VECTOR2I size = GetTextSize();
951
952 if( IsMirrored() )
953 size.x = -size.x;
954
955 KIFONT::FONT* font = GetFont();
956
957 if( !font )
958 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
959
960 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
961 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
962}
963
964
966{
967 int style = 0;
968
969 if( IsItalic() )
970 style = 1;
971
972 if( IsBold() )
973 style += 2;
974
975 wxString stylemsg[4] = {
976 _("Normal"),
977 _("Italic"),
978 _("Bold"),
979 _("Bold+Italic")
980 };
981
982 return stylemsg[style];
983}
984
985
986wxString EDA_TEXT::GetFontName() const
987{
988 if( GetFont() )
989 return GetFont()->GetName();
990 else
991 return wxEmptyString;
992}
993
994
996{
997 if( !GetFont() )
998 return -1;
999
1000 if( GetFont()->GetName() == KICAD_FONT_NAME )
1001 return -2;
1002
1003 std::vector<std::string> fontNames;
1004 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
1005
1006 for( int ii = 0; ii < (int) fontNames.size(); ++ii )
1007 {
1008 if( fontNames[ii] == GetFont()->GetName() )
1009 return ii;
1010 }
1011
1012 return 0;
1013}
1014
1015
1017{
1018 if( aIdx == -1 )
1019 {
1020 SetFont( nullptr );
1021 }
1022 else if( aIdx == -2 )
1023 {
1024 SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
1025 }
1026 else
1027 {
1028 std::vector<std::string> fontNames;
1029 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
1030
1031 if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
1032 SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
1033 else
1034 SetFont( nullptr );
1035 }
1036}
1037
1038
1040{
1041 return ( !IsMirrored()
1044 && GetTextThickness() == 0
1045 && !IsItalic()
1046 && !IsBold()
1047 && !IsMultilineAllowed()
1048 && GetFontName().IsEmpty()
1049 );
1050}
1051
1052
1053void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aControlBits ) const
1054{
1055 aFormatter->Print( "(effects" );
1056
1057 aFormatter->Print( "(font" );
1058
1059 if( GetFont() && !GetFont()->GetName().IsEmpty() )
1060 aFormatter->Print( "(face %s)", aFormatter->Quotew( GetFont()->NameAsToken() ).c_str() );
1061
1062 // Text size
1063 aFormatter->Print( "(size %s %s)",
1066
1067 if( GetLineSpacing() != 1.0 )
1068 {
1069 aFormatter->Print( "(line_spacing %s)",
1070 FormatDouble2Str( GetLineSpacing() ).c_str() );
1071 }
1072
1073 if( GetTextThickness() )
1074 {
1075 aFormatter->Print( "(thickness %s)",
1077 }
1078
1079 if( IsBold() )
1080 KICAD_FORMAT::FormatBool( aFormatter, "bold", true );
1081
1082 if( IsItalic() )
1083 KICAD_FORMAT::FormatBool( aFormatter, "italic", true );
1084
1085 if( !( aControlBits & CTL_OMIT_COLOR ) && GetTextColor() != COLOR4D::UNSPECIFIED )
1086 {
1087 aFormatter->Print( "(color %d %d %d %s)",
1088 KiROUND( GetTextColor().r * 255.0 ),
1089 KiROUND( GetTextColor().g * 255.0 ),
1090 KiROUND( GetTextColor().b * 255.0 ),
1091 FormatDouble2Str( GetTextColor().a ).c_str() );
1092 }
1093
1094 aFormatter->Print( ")"); // (font
1095
1098 {
1099 aFormatter->Print( "(justify");
1100
1102 aFormatter->Print( GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
1103
1105 aFormatter->Print( GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
1106
1107 if( IsMirrored() )
1108 aFormatter->Print( " mirror" );
1109
1110 aFormatter->Print( ")" ); // (justify
1111 }
1112
1113 if( !( aControlBits & CTL_OMIT_HYPERLINK ) && HasHyperlink() )
1114 aFormatter->Print( "(href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
1115
1116 aFormatter->Print( ")" ); // (effects
1117}
1118
1119
1120std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
1121 const BOX2I& aBBox,
1122 const EDA_ANGLE& aAngle ) const
1123{
1124 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
1125 KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
1126 KIFONT::FONT* font = getDrawFont();
1127 int penWidth = GetEffectiveTextPenWidth();
1128 wxString shownText( GetShownText( true ) );
1129 VECTOR2I drawPos = GetDrawPos();
1131
1132 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
1133
1134 if( aBBox.GetWidth() )
1135 {
1136 drawPos = aBBox.GetCenter();
1139 attrs.m_Angle = aAngle;
1140 }
1141 else
1142 {
1143 attrs.m_Angle = GetDrawRotation();
1144
1145 if( font->IsOutline() )
1146 cache = GetRenderCache( font, shownText, VECTOR2I() );
1147 }
1148
1149 if( aTriangulate )
1150 {
1151 CALLBACK_GAL callback_gal(
1152 empty_opts,
1153 // Stroke callback
1154 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1155 {
1156 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1157 },
1158 // Triangulation callback
1159 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1160 {
1161 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1162
1163 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1164 triShape->Append( point.x, point.y );
1165
1166 shape->AddShape( triShape );
1167 } );
1168
1169 if( cache )
1170 callback_gal.DrawGlyphs( *cache );
1171 else
1172 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1173 }
1174 else
1175 {
1176 CALLBACK_GAL callback_gal(
1177 empty_opts,
1178 // Stroke callback
1179 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1180 {
1181 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1182 },
1183 // Outline callback
1184 [&]( const SHAPE_LINE_CHAIN& aPoly )
1185 {
1186 shape->AddShape( aPoly.Clone() );
1187 } );
1188
1189 if( cache )
1190 callback_gal.DrawGlyphs( *cache );
1191 else
1192 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1193 }
1194
1195 return shape;
1196}
1197
1198
1199int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1200{
1201 wxCHECK( aOther, 1 );
1202
1203 int val = m_attributes.Compare( aOther->m_attributes );
1204
1205 if( val != 0 )
1206 return val;
1207
1208 if( m_pos.x != aOther->m_pos.x )
1209 return m_pos.x - aOther->m_pos.x;
1210
1211 if( m_pos.y != aOther->m_pos.y )
1212 return m_pos.y - aOther->m_pos.y;
1213
1214 val = GetFontName().Cmp( aOther->GetFontName() );
1215
1216 if( val != 0 )
1217 return val;
1218
1219 return m_text.Cmp( aOther->m_text );
1220}
1221
1222
1223bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1224{
1225 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1226 return true;
1227
1228 wxURI uri;
1229
1230 return( uri.Create( aURL ) && uri.HasScheme() );
1231}
1232
1233double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1234{
1235 // Compute the Levenshtein distance between the two strings
1236 const wxString& str1 = GetText();
1237 const wxString& str2 = aOther.GetText();
1238
1239 int m = str1.length();
1240 int n = str2.length();
1241
1242 if( n == 0 || m == 0 )
1243 return 0.0;
1244
1245 // Create a matrix to store the distance values
1246 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1247
1248 // Initialize the matrix
1249 for( int i = 0; i <= m; i++ )
1250 distance[i][0] = i;
1251 for( int j = 0; j <= n; j++ )
1252 distance[0][j] = j;
1253
1254 // Calculate the distance
1255 for( int i = 1; i <= m; i++ )
1256 {
1257 for( int j = 1; j <= n; j++ )
1258 {
1259 if( str1[i - 1] == str2[j - 1] )
1260 {
1261 distance[i][j] = distance[i - 1][j - 1];
1262 }
1263 else
1264 {
1265 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1266 distance[i - 1][j - 1] } ) + 1;
1267 }
1268 }
1269 }
1270
1271 // Calculate similarity score
1272 int maxLen = std::max( m, n );
1273 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1274
1275 return similarity;
1276}
1277
1278
1279double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1280{
1281 double retval = 1.0;
1282
1283 if( !( m_attributes == aOther.m_attributes ) )
1284 retval *= 0.9;
1285
1286 if( m_pos != aOther.m_pos )
1287 retval *= 0.9;
1288
1289 retval *= Levenshtein( aOther );
1290
1291 return retval;
1292}
1293
1294
1295bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1296{
1297 return aHref.StartsWith( wxT( "#" ), aDestination );
1298}
1299
1300
1301wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1302{
1303 return wxT( "#" ) + aDestination;
1304}
1305
1306
1307std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1308{
1309 aStream << aText.GetText();
1310
1311 return aStream;
1312}
1313
1314
1315static struct EDA_TEXT_DESC
1316{
1318 {
1319 // These are defined in SCH_FIELD as well but initialization order is
1320 // not defined, so this needs to be conditional. Defining in both
1321 // places leads to duplicate symbols.
1323
1324 if( h_inst.Choices().GetCount() == 0)
1325 {
1326 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
1327 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
1328 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
1329 }
1330
1332
1333 if( v_inst.Choices().GetCount() == 0)
1334 {
1335 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
1336 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
1337 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
1338 }
1339
1342
1343 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1345 PROPERTY_DISPLAY::PT_DEGREE ) );
1346
1347 const wxString textProps = _HKI( "Text Properties" );
1348
1349 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1351 textProps );
1352
1353 // This must be a PROPERTY_ENUM to get a choice list.
1354 // SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
1355 propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
1357 textProps )
1359
1360 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1362 PROPERTY_DISPLAY::PT_SIZE ),
1363 textProps );
1364 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1367 textProps );
1368 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1370 textProps );
1371 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1373 textProps );
1374 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1376 PROPERTY_DISPLAY::PT_SIZE ),
1377 textProps );
1378
1379 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1381 PROPERTY_DISPLAY::PT_SIZE ),
1382 textProps );
1383
1385 _HKI( "Horizontal Justification" ),
1387 textProps );
1389 _HKI( "Vertical Justification" ),
1391 textProps );
1392
1393 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1395 textProps );
1396
1397 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1399 textProps );
1400 }
1402
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:254
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: eda_text.cpp:187
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:256
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:260
COLOR4D GetTextColor() const
Definition: eda_text.h:257
wxString GetTextStyleName() const
Definition: eda_text.cpp:965
VECTOR2I m_pos
Definition: eda_text.h:466
wxString m_text
Definition: eda_text.h:444
std::map< int, BBOX_CACHE_ENTRY > m_bbox_cache
Definition: eda_text.h:462
bool IsDefaultFormatting() const
Definition: eda_text.cpp:1039
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1295
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:454
wxString GetFontName() const
Definition: eda_text.cpp:986
virtual ~EDA_TEXT()
Definition: eda_text.cpp:149
bool IsItalic() const
Definition: eda_text.h:156
bool m_visible
Definition: eda_text.h:467
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:526
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:717
bool IsKeepUpright() const
Definition: eda_text.h:193
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:571
void SetTextX(int aX)
Definition: eda_text.cpp:577
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:446
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: eda_text.cpp:223
KIFONT::FONT * GetFont() const
Definition: eda_text.h:234
bool ResolveFont(const std::vector< wxString > *aEmbeddedFonts)
Definition: eda_text.cpp:500
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:426
wxString m_shown_text
Definition: eda_text.h:445
int GetFontIndex() const
Definition: eda_text.cpp:995
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:723
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:386
void SetTextY(int aY)
Definition: eda_text.cpp:583
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:664
const KIFONT::FONT * m_render_cache_font
Definition: eda_text.h:451
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:365
wxString m_unresolvedFontName
Definition: eda_text.h:465
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:366
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:940
int GetTextWidth() const
Definition: eda_text.h:251
virtual bool HasHyperlink() const
Definition: eda_text.h:386
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:410
wxString GetHyperlink() const
Definition: eda_text.h:387
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:589
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:1053
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:187
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:549
void SetBoldFlag(bool aBold)
Set only the bold flag, without changing the font.
Definition: eda_text.cpp:371
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:479
void SetupRenderCache(const wxString &aResolvedText, const KIFONT::FONT *aFont, const EDA_ANGLE &aAngle, const VECTOR2I &aOffset)
Definition: eda_text.cpp:699
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1199
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:448
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:379
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition: eda_text.cpp:95
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:896
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1301
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:657
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:634
double GetLineSpacing() const
Definition: eda_text.h:245
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1279
VECTOR2I m_render_cache_offset
Definition: eda_text.h:453
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:518
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:710
void Empty()
Definition: eda_text.cpp:608
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:284
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:853
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:560
virtual void cacheShownText()
Definition: eda_text.cpp:616
EDA_ANGLE m_render_cache_angle
Definition: eda_text.h:452
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:67
virtual void ClearRenderCache()
Definition: eda_text.cpp:651
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:328
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
Definition: eda_text.cpp:1223
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
Definition: eda_text.cpp:320
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:458
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:445
wxString m_render_cache_text
Definition: eda_text.h:450
double GetTextAngleDegrees() const
Definition: eda_text.h:141
virtual const KIFONT::METRICS & getFontMetrics() const
Definition: eda_text.cpp:645
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:1120
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:388
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:81
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:418
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:277
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:270
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
Definition: eda_text.cpp:1233
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:292
void SetFontIndex(int aIdx)
Definition: eda_text.cpp:1016
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:872
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:300
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:438
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:394
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:492
VECTOR2I GetTextSize() const
Definition: eda_text.h:248
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:402
TEXT_ATTRIBUTES m_attributes
Definition: eda_text.h:464
static ENUM_MAP< T > & Instance()
Definition: property.h:680
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:147
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:250
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:427
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:545
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:460
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:46
#define CTL_OMIT_COLOR
Omit the color attribute in .kicad_xxx files.
Definition: ctl_flags.h:45
#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:1307
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:104
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:36
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:60
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:109
int ClampTextPenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
Definition: gr_text.cpp:72
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:159
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:170
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:1073
see class PGM_BASE
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:782
#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
VECTOR2I location
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ 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
This is API surface mapped to common.types.VertialAlignment.
@ 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:695