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> // 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{
102
103 if( m_text.IsEmpty() )
104 {
105 m_shown_text = wxEmptyString;
107 }
108 else
109 {
111 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
112 }
113}
114
115
117 m_IuScale( aText.m_IuScale )
118{
119 m_text = aText.m_text;
122
124 m_pos = aText.m_pos;
125
130
131 m_render_cache.clear();
132
133 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
134 {
135 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
136 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
137 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
138 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
139 }
140
142
144}
145
146
148{
149}
150
151
153{
154 m_text = aText.m_text;
157
159 m_pos = aText.m_pos;
160
165
166 m_render_cache.clear();
167
168 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
169 {
170 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
171 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
172 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
173 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
174 }
175
177
179
180 return *this;
181}
182
183
184void EDA_TEXT::Serialize( google::protobuf::Any &aContainer ) const
185{
186 using namespace kiapi::common;
187 types::Text text;
188
189 text.set_text( GetText().ToStdString() );
190 text.set_hyperlink( GetHyperlink().ToStdString() );
191 PackVector2( *text.mutable_position(), GetTextPos() );
192
193 types::TextAttributes* attrs = text.mutable_attributes();
194
195 if( GetFont() )
196 attrs->set_font_name( GetFont()->GetName().ToStdString() );
197
198 attrs->set_horizontal_alignment(
199 ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
200
201 attrs->set_vertical_alignment(
202 ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
203
204 attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
205 attrs->set_line_spacing( GetLineSpacing() );
206 attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
207 attrs->set_italic( IsItalic() );
208 attrs->set_bold( IsBold() );
209 attrs->set_underlined( GetAttributes().m_Underlined );
210 attrs->set_visible( IsVisible() );
211 attrs->set_mirrored( IsMirrored() );
212 attrs->set_multiline( IsMultilineAllowed() );
213 attrs->set_keep_upright( IsKeepUpright() );
214 PackVector2( *attrs->mutable_size(), GetTextSize() );
215
216 aContainer.PackFrom( text );
217}
218
219
220bool EDA_TEXT::Deserialize( const google::protobuf::Any &aContainer )
221{
222 using namespace kiapi::common;
223 types::Text text;
224
225 if( !aContainer.UnpackTo( &text ) )
226 return false;
227
228 SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
229 SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
230 SetTextPos( UnpackVector2( text.position() ) );
231
232 if( text.has_attributes() )
233 {
235
236 attrs.m_Bold = text.attributes().bold();
237 attrs.m_Italic = text.attributes().italic();
238 attrs.m_Underlined = text.attributes().underlined();
239 attrs.m_Visible = text.attributes().visible();
240 attrs.m_Mirrored = text.attributes().mirrored();
241 attrs.m_Multiline = text.attributes().multiline();
242 attrs.m_KeepUpright = text.attributes().keep_upright();
243 attrs.m_Size = UnpackVector2( text.attributes().size() );
244
245 if( !text.attributes().font_name().empty() )
246 {
248 wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
249 attrs.m_Italic );
250 }
251
252 attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
253 attrs.m_LineSpacing = text.attributes().line_spacing();
254 attrs.m_StrokeWidth = text.attributes().stroke_width().value_nm();
255 attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
256 text.attributes().horizontal_alignment() );
257
258 attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
259 text.attributes().vertical_alignment() );
260
261 SetAttributes( attrs );
262 }
263
264 return true;
265}
266
267
268void EDA_TEXT::SetText( const wxString& aText )
269{
270 m_text = aText;
272}
273
274
275void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
276{
277 m_text = aSrc.m_text;
279}
280
281
283{
287}
288
289
291{
292 m_attributes.m_Angle = aAngle;
295}
296
297
298void EDA_TEXT::SetItalic( bool aItalic )
299{
300 if( m_attributes.m_Italic != aItalic )
301 {
302 const KIFONT::FONT* font = GetFont();
303
304 if( !font || font->IsStroke() )
305 {
306 // For stroke fonts, just need to set the attribute.
307 }
308 else
309 {
310 // For outline fonts, italic-ness is determined by the font itself.
311 SetFont( KIFONT::FONT::GetFont( font->GetName(), IsBold(), aItalic ) );
312 }
313 }
314
315 SetItalicFlag( aItalic );
316}
317
318void EDA_TEXT::SetItalicFlag( bool aItalic )
319{
320 m_attributes.m_Italic = aItalic;
323}
324
325
326void EDA_TEXT::SetBold( bool aBold )
327{
328 if( m_attributes.m_Bold != aBold )
329 {
330 const KIFONT::FONT* font = GetFont();
331
332 if( !font || font->IsStroke() )
333 {
334 // For stroke fonts, boldness is determined by the pen size.
335 const int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
336
337 if( aBold )
338 {
341 }
342 else
343 {
344 // Restore the original stroke width from `m_StoredStrokeWidth` if it was
345 // previously stored, resetting the width after unbolding.
348 else
349 {
351 // Sets `m_StrokeWidth` to the normal pen size and stores it in
352 // `m_StoredStrokeWidth` as the default, but only if the bold option was
353 // 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.ClearBoundingBoxCache();
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 = ClampTextPenSize( 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
498bool EDA_TEXT::ResolveFont( const std::vector<wxString>* aEmbeddedFonts )
499{
500 if( !m_unresolvedFontName.IsEmpty() )
501 {
503 aEmbeddedFonts );
504
505 if( !m_render_cache.empty() )
507
508 m_unresolvedFontName = wxEmptyString;
509 return true;
510 }
511
512 return false;
513}
514
515
516void EDA_TEXT::SetLineSpacing( double aLineSpacing )
517{
518 m_attributes.m_LineSpacing = aLineSpacing;
521}
522
523
524void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
525{
526 // Plotting uses unityScale and independently scales the text. If we clamp here we'll
527 // clamp to *really* small values.
528 if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
529 aEnforceMinTextSize = false;
530
531 if( aEnforceMinTextSize )
532 {
533 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
534 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
535
536 aNewSize = VECTOR2I( std::clamp( aNewSize.x, min, max ),
537 std::clamp( aNewSize.y, min, max ) );
538 }
539
540 m_attributes.m_Size = aNewSize;
541
544}
545
546
547void EDA_TEXT::SetTextWidth( int aWidth )
548{
549 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
550 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
551
552 m_attributes.m_Size.x = std::clamp( aWidth, min, max );
555}
556
557
558void EDA_TEXT::SetTextHeight( int aHeight )
559{
560 int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
561 int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
562
563 m_attributes.m_Size.y = std::clamp( aHeight, min, max );
566}
567
568
569void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
570{
571 Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
572}
573
574
575void EDA_TEXT::SetTextX( int aX )
576{
577 Offset( VECTOR2I( aX - m_pos.x, 0 ) );
578}
579
580
581void EDA_TEXT::SetTextY( int aY )
582{
583 Offset( VECTOR2I( 0, aY - m_pos.y ) );
584}
585
586
587void EDA_TEXT::Offset( const VECTOR2I& aOffset )
588{
589 if( aOffset.x == 0 && aOffset.y == 0 )
590 return;
591
592 m_pos += aOffset;
593
594 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
595 {
596 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
597 outline->Move( aOffset );
598 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
599 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
600 }
601
603}
604
605
607{
608 m_text.Empty();
611}
612
613
615{
616 if( m_text.IsEmpty() )
617 {
618 m_shown_text = wxEmptyString;
620 }
621 else
622 {
624 m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
625 }
626
629}
630
631
633{
634 KIFONT::FONT* font = GetFont();
635
636 if( !font )
637 font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
638
639 return font;
640}
641
642
644{
646}
647
648
650{
651 m_render_cache.clear();
652}
653
654
656{
657 m_bbox_cache.clear();
658}
659
660
661std::vector<std::unique_ptr<KIFONT::GLYPH>>*
662EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
663 const VECTOR2I& aOffset ) const
664{
665 if( aFont->IsOutline() )
666 {
667 EDA_ANGLE resolvedAngle = GetDrawRotation();
668
669 if( m_render_cache.empty()
670 || m_render_cache_font != aFont
671 || m_render_cache_text != forResolvedText
672 || m_render_cache_angle != resolvedAngle
673 || m_render_cache_offset != aOffset )
674 {
675 m_render_cache.clear();
676
677 const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
679
680 attrs.m_Angle = resolvedAngle;
681
682 font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
683 attrs, getFontMetrics() );
684 m_render_cache_font = aFont;
685 m_render_cache_angle = resolvedAngle;
686 m_render_cache_text = forResolvedText;
687 m_render_cache_offset = aOffset;
688 }
689
690 return &m_render_cache;
691 }
692
693 return nullptr;
694}
695
696
697void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const KIFONT::FONT* aFont,
698 const EDA_ANGLE& aAngle, const VECTOR2I& aOffset )
699{
700 m_render_cache_text = aResolvedText;
701 m_render_cache_font = aFont;
702 m_render_cache_angle = aAngle;
703 m_render_cache_offset = aOffset;
704 m_render_cache.clear();
705}
706
707
709{
710 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
711 static_cast<KIFONT::OUTLINE_GLYPH*>( m_render_cache.back().get() )->CacheTriangulation();
712}
713
714
716{
718}
719
720
721BOX2I EDA_TEXT::GetTextBox( int aLine ) const
722{
723 VECTOR2I drawPos = GetDrawPos();
724
725 auto cache_it = m_bbox_cache.find( aLine );
726
727 if( cache_it != m_bbox_cache.end() && cache_it->second.m_pos == drawPos )
728 return cache_it->second.m_bbox;
729
730 BOX2I bbox;
731 wxArrayString strings;
732 wxString text = GetShownText( true );
733 int thickness = GetEffectiveTextPenWidth();
734
735 if( IsMultilineAllowed() )
736 {
737 wxStringSplit( text, strings, '\n' );
738
739 if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
740 {
741 if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
742 text = strings.Item( aLine );
743 else
744 text = strings.Item( 0 );
745 }
746 }
747
748 // calculate the H and V size
749 KIFONT::FONT* font = getDrawFont();
750 VECTOR2D fontSize( GetTextSize() );
751 bool bold = IsBold();
752 bool italic = IsItalic();
753 VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
754 getFontMetrics() );
755 int overbarOffset = 0;
756
757 // Creates bounding box (rectangle) for horizontal, left and top justified text. The
758 // bounding box will be moved later according to the actual text options
759 VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
760 VECTOR2I pos = drawPos;
761 int fudgeFactor = KiROUND( extents.y * 0.17 );
762
763 if( font->IsStroke() )
764 textsize.y += fudgeFactor;
765
766 if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
767 pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
768
769 if( text.Contains( wxT( "~{" ) ) )
770 overbarOffset = extents.y / 6;
771
772 bbox.SetOrigin( pos );
773
774 // for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
775 if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
776 {
777 for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
778 {
779 text = strings.Item( ii );
780 extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
781 getFontMetrics() );
782 textsize.x = std::max( textsize.x, extents.x );
783 }
784
785 // interline spacing is only *between* lines, so total height is the height of the first
786 // line plus the interline distance (with interline spacing) for all subsequent lines
787 textsize.y += KiROUND( ( strings.GetCount() - 1 )
788 * font->GetInterline( fontSize.y, getFontMetrics() ) );
789 }
790
791 textsize.y += overbarOffset;
792
793 bbox.SetSize( textsize );
794
795 /*
796 * At this point the rectangle origin is the text origin (m_Pos). This is correct only for
797 * left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
798 */
799 int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
800
801 switch( GetHorizJustify() )
802 {
804 if( IsMirrored() )
805 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
806
807 break;
808
810 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
811 break;
812
814 if( !IsMirrored() )
815 bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
816 break;
817
819 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
820 break;
821 }
822
823 switch( GetVertJustify() )
824 {
826 bbox.Offset( 0, -fudgeFactor );
827 break;
828
830 bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
831 break;
832
834 bbox.SetY( bbox.GetY() - bbox.GetHeight() );
835 bbox.Offset( 0, fudgeFactor );
836 break;
837
839 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
840 break;
841 }
842
843 bbox.Normalize(); // Make h and v sizes always >= 0
844
845 m_bbox_cache[ aLine ] = { drawPos, bbox };
846
847 return bbox;
848}
849
850
851bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
852{
853 const BOX2I rect = GetTextBox().GetInflated( aAccuracy );
854 const VECTOR2I location = GetRotated( aPoint, GetDrawPos(), -GetDrawRotation() );
855 return rect.Contains( location );
856}
857
858
859bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
860{
861 const BOX2I rect = aRect.GetInflated( aAccuracy );
862
863 if( aContains )
864 return rect.Contains( GetTextBox() );
865
866 return rect.Intersects( GetTextBox(), GetDrawRotation() );
867}
868
869
870void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
871 const COLOR4D& aColor, OUTLINE_MODE aFillMode )
872{
873 if( IsMultilineAllowed() )
874 {
875 std::vector<VECTOR2I> positions;
876 wxArrayString strings;
877 wxStringSplit( GetShownText( true ), strings, '\n' );
878
879 positions.reserve( strings.Count() );
880
881 GetLinePositions( positions, (int) strings.Count() );
882
883 for( unsigned ii = 0; ii < strings.Count(); ii++ )
884 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
885 }
886 else
887 {
888 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
889 GetDrawPos() );
890 }
891}
892
893
894void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
895{
896 VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
897 // to the center of the multiline text block
898
899 VECTOR2I offset; // Offset to next line.
900
901 offset.y = GetInterline();
902
903 if( aLineCount > 1 )
904 {
905 switch( GetVertJustify() )
906 {
908 break;
909
911 pos.y -= ( aLineCount - 1 ) * offset.y / 2;
912 break;
913
915 pos.y -= ( aLineCount - 1 ) * offset.y;
916 break;
917
919 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
920 break;
921 }
922 }
923
924 // Rotate the position of the first line around the center of the multiline text block
926
927 // Rotate the offset lines to increase happened in the right direction
928 RotatePoint( offset, GetDrawRotation() );
929
930 for( int ii = 0; ii < aLineCount; ii++ )
931 {
932 aPositions.push_back( (VECTOR2I) pos );
933 pos += offset;
934 }
935}
936
937
938void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
939 const COLOR4D& aColor, OUTLINE_MODE aFillMode,
940 const wxString& aText, const VECTOR2I& aPos )
941{
942 wxDC* DC = aSettings->GetPrintDC();
943 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
944
945 if( aFillMode == SKETCH )
946 penWidth = -penWidth;
947
948 VECTOR2I size = GetTextSize();
949
950 if( IsMirrored() )
951 size.x = -size.x;
952
953 KIFONT::FONT* font = GetFont();
954
955 if( !font )
956 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
957
958 GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
959 GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
960}
961
962
964{
965 int style = 0;
966
967 if( IsItalic() )
968 style = 1;
969
970 if( IsBold() )
971 style += 2;
972
973 wxString stylemsg[4] = {
974 _("Normal"),
975 _("Italic"),
976 _("Bold"),
977 _("Bold+Italic")
978 };
979
980 return stylemsg[style];
981}
982
983
984wxString EDA_TEXT::GetFontName() const
985{
986 if( GetFont() )
987 return GetFont()->GetName();
988 else
989 return wxEmptyString;
990}
991
992
994{
995 if( !GetFont() )
996 return -1;
997
998 if( GetFont()->GetName() == KICAD_FONT_NAME )
999 return -2;
1000
1001 std::vector<std::string> fontNames;
1002 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
1003
1004 for( int ii = 0; ii < (int) fontNames.size(); ++ii )
1005 {
1006 if( fontNames[ii] == GetFont()->GetName() )
1007 return ii;
1008 }
1009
1010 return 0;
1011}
1012
1013
1015{
1016 if( aIdx == -1 )
1017 {
1018 SetFont( nullptr );
1019 }
1020 else if( aIdx == -2 )
1021 {
1022 SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
1023 }
1024 else
1025 {
1026 std::vector<std::string> fontNames;
1027 Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
1028
1029 if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
1030 SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
1031 else
1032 SetFont( nullptr );
1033 }
1034}
1035
1036
1038{
1039 return ( IsVisible()
1040 && !IsMirrored()
1043 && GetTextThickness() == 0
1044 && !IsItalic()
1045 && !IsBold()
1046 && !IsMultilineAllowed()
1047 && GetFontName().IsEmpty()
1048 );
1049}
1050
1051
1052void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aControlBits ) const
1053{
1054 aFormatter->Print( "(effects" );
1055
1056 aFormatter->Print( "(font" );
1057
1058 if( GetFont() && !GetFont()->GetName().IsEmpty() )
1059 aFormatter->Print( "(face %s)", aFormatter->Quotew( GetFont()->NameAsToken() ).c_str() );
1060
1061 // Text size
1062 aFormatter->Print( "(size %s %s)",
1065
1066 if( GetLineSpacing() != 1.0 )
1067 {
1068 aFormatter->Print( "(line_spacing %s)",
1069 FormatDouble2Str( GetLineSpacing() ).c_str() );
1070 }
1071
1072 if( GetTextThickness() )
1073 {
1074 aFormatter->Print( "(thickness %s)",
1076 }
1077
1078 if( IsBold() )
1079 KICAD_FORMAT::FormatBool( aFormatter, "bold", true );
1080
1081 if( IsItalic() )
1082 KICAD_FORMAT::FormatBool( aFormatter, "italic", true );
1083
1084 if( !( aControlBits & CTL_OMIT_COLOR ) && GetTextColor() != COLOR4D::UNSPECIFIED )
1085 {
1086 aFormatter->Print( "(color %d %d %d %s)",
1087 KiROUND( GetTextColor().r * 255.0 ),
1088 KiROUND( GetTextColor().g * 255.0 ),
1089 KiROUND( GetTextColor().b * 255.0 ),
1090 FormatDouble2Str( GetTextColor().a ).c_str() );
1091 }
1092
1093 aFormatter->Print( ")"); // (font
1094
1097 {
1098 aFormatter->Print( "(justify");
1099
1101 aFormatter->Print( GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
1102
1104 aFormatter->Print( GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
1105
1106 if( IsMirrored() )
1107 aFormatter->Print( " mirror" );
1108
1109 aFormatter->Print( ")" ); // (justify
1110 }
1111
1112 if( !( aControlBits & CTL_OMIT_HIDE ) && !IsVisible() )
1113 KICAD_FORMAT::FormatBool( aFormatter, "hide", true );
1114
1115 if( !( aControlBits & CTL_OMIT_HYPERLINK ) && HasHyperlink() )
1116 {
1117 aFormatter->Print( "(href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
1118 }
1119
1120 aFormatter->Print( ")" ); // (effects
1121}
1122
1123
1124std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
1125 const BOX2I& aBBox,
1126 const EDA_ANGLE& aAngle ) const
1127{
1128 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
1129 KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
1130 KIFONT::FONT* font = getDrawFont();
1131 int penWidth = GetEffectiveTextPenWidth();
1132 wxString shownText( GetShownText( true ) );
1133 VECTOR2I drawPos = GetDrawPos();
1135
1136 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
1137
1138 if( aBBox.GetWidth() )
1139 {
1140 drawPos = aBBox.GetCenter();
1143 attrs.m_Angle = aAngle;
1144 }
1145 else
1146 {
1147 attrs.m_Angle = GetDrawRotation();
1148
1149 if( font->IsOutline() )
1150 cache = GetRenderCache( font, shownText, VECTOR2I() );
1151 }
1152
1153 if( aTriangulate )
1154 {
1155 CALLBACK_GAL callback_gal(
1156 empty_opts,
1157 // Stroke callback
1158 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1159 {
1160 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1161 },
1162 // Triangulation callback
1163 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
1164 {
1165 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1166
1167 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1168 triShape->Append( point.x, point.y );
1169
1170 shape->AddShape( triShape );
1171 } );
1172
1173 if( cache )
1174 callback_gal.DrawGlyphs( *cache );
1175 else
1176 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1177 }
1178 else
1179 {
1180 CALLBACK_GAL callback_gal(
1181 empty_opts,
1182 // Stroke callback
1183 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
1184 {
1185 shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1186 },
1187 // Outline callback
1188 [&]( const SHAPE_LINE_CHAIN& aPoly )
1189 {
1190 shape->AddShape( aPoly.Clone() );
1191 } );
1192
1193 if( cache )
1194 callback_gal.DrawGlyphs( *cache );
1195 else
1196 font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
1197 }
1198
1199 return shape;
1200}
1201
1202
1203int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
1204{
1205 wxCHECK( aOther, 1 );
1206
1207 int val = m_attributes.Compare( aOther->m_attributes );
1208
1209 if( val != 0 )
1210 return val;
1211
1212 if( m_pos.x != aOther->m_pos.x )
1213 return m_pos.x - aOther->m_pos.x;
1214
1215 if( m_pos.y != aOther->m_pos.y )
1216 return m_pos.y - aOther->m_pos.y;
1217
1218 val = GetFontName().Cmp( aOther->GetFontName() );
1219
1220 if( val != 0 )
1221 return val;
1222
1223 return m_text.Cmp( aOther->m_text );
1224}
1225
1226
1227bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
1228{
1229 if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
1230 return true;
1231
1232 wxURI uri;
1233
1234 return( uri.Create( aURL ) && uri.HasScheme() );
1235}
1236
1237double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
1238{
1239 // Compute the Levenshtein distance between the two strings
1240 const wxString& str1 = GetText();
1241 const wxString& str2 = aOther.GetText();
1242
1243 int m = str1.length();
1244 int n = str2.length();
1245
1246 if( n == 0 || m == 0 )
1247 return 0.0;
1248
1249 // Create a matrix to store the distance values
1250 std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
1251
1252 // Initialize the matrix
1253 for( int i = 0; i <= m; i++ )
1254 distance[i][0] = i;
1255 for( int j = 0; j <= n; j++ )
1256 distance[0][j] = j;
1257
1258 // Calculate the distance
1259 for( int i = 1; i <= m; i++ )
1260 {
1261 for( int j = 1; j <= n; j++ )
1262 {
1263 if( str1[i - 1] == str2[j - 1] )
1264 {
1265 distance[i][j] = distance[i - 1][j - 1];
1266 }
1267 else
1268 {
1269 distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
1270 distance[i - 1][j - 1] } ) + 1;
1271 }
1272 }
1273 }
1274
1275 // Calculate similarity score
1276 int maxLen = std::max( m, n );
1277 double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
1278
1279 return similarity;
1280}
1281
1282
1283double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
1284{
1285 double retval = 1.0;
1286
1287 if( !( m_attributes == aOther.m_attributes ) )
1288 retval *= 0.9;
1289
1290 if( m_pos != aOther.m_pos )
1291 retval *= 0.9;
1292
1293 retval *= Levenshtein( aOther );
1294
1295 return retval;
1296}
1297
1298
1299bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
1300{
1301 return aHref.StartsWith( wxT( "#" ), aDestination );
1302}
1303
1304
1305wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
1306{
1307 return wxT( "#" ) + aDestination;
1308}
1309
1310
1311std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
1312{
1313 aStream << aText.GetText();
1314
1315 return aStream;
1316}
1317
1318
1319static struct EDA_TEXT_DESC
1320{
1322 {
1323 // These are defined in SCH_FIELD as well but initialization order is
1324 // not defined, so this needs to be conditional. Defining in both
1325 // places leads to duplicate symbols.
1327
1328 if( h_inst.Choices().GetCount() == 0)
1329 {
1330 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
1331 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
1332 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
1333 }
1334
1336
1337 if( v_inst.Choices().GetCount() == 0)
1338 {
1339 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
1340 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
1341 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
1342 }
1343
1346
1347 propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
1349 PROPERTY_DISPLAY::PT_DEGREE ) );
1350
1351 const wxString textProps = _HKI( "Text Properties" );
1352
1353 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
1355 textProps );
1356
1357 // This must be a PROPERTY_ENUM to get a choice list.
1358 // SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
1359 propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
1361 textProps )
1363
1364 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
1366 PROPERTY_DISPLAY::PT_SIZE ),
1367 textProps );
1368 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
1371 textProps );
1372 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
1374 textProps );
1375 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
1377 textProps );
1378 propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
1380 textProps );
1381 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
1383 PROPERTY_DISPLAY::PT_SIZE ),
1384 textProps );
1385
1386 propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
1388 PROPERTY_DISPLAY::PT_SIZE ),
1389 textProps );
1390
1392 _HKI( "Horizontal Justification" ),
1394 textProps );
1396 _HKI( "Vertical Justification" ),
1398 textProps );
1399
1400 propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
1402 textProps );
1403
1404 propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
1406 textProps );
1407 }
1409
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:184
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:963
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:1037
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1299
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
Definition: eda_text.h:454
wxString GetFontName() const
Definition: eda_text.cpp:984
virtual ~EDA_TEXT()
Definition: eda_text.cpp:147
bool IsItalic() const
Definition: eda_text.h:156
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:524
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:715
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:569
void SetTextX(int aX)
Definition: eda_text.cpp:575
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:220
KIFONT::FONT * GetFont() const
Definition: eda_text.h:234
bool ResolveFont(const std::vector< wxString > *aEmbeddedFonts)
Definition: eda_text.cpp:498
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:445
int GetFontIndex() const
Definition: eda_text.cpp:993
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:721
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:384
void SetTextY(int aY)
Definition: eda_text.cpp:581
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:662
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:152
void printOneLineOfText(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, OUTLINE_MODE aFillMode, const wxString &aText, const VECTOR2I &aPos)
Print each line of this EDA_TEXT.
Definition: eda_text.cpp:938
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:408
wxString GetHyperlink() const
Definition: eda_text.h:387
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:587
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:1052
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:187
void SetTextWidth(int aWidth)
Definition: eda_text.cpp:547
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:697
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:1203
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
Definition: eda_text.h:448
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
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:894
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1305
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:655
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:632
double GetLineSpacing() const
Definition: eda_text.h:245
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1283
VECTOR2I m_render_cache_offset
Definition: eda_text.h:453
void SetLineSpacing(double aLineSpacing)
Definition: eda_text.cpp:516
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
Definition: eda_text.cpp:708
void Empty()
Definition: eda_text.cpp:606
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:282
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:851
void SetTextHeight(int aHeight)
Definition: eda_text.cpp:558
virtual void cacheShownText()
Definition: eda_text.cpp:614
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:649
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:326
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
Definition: eda_text.cpp:1227
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
Definition: eda_text.cpp:318
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:450
double GetTextAngleDegrees() const
Definition: eda_text.h:141
virtual const KIFONT::METRICS & getFontMetrics() const
Definition: eda_text.cpp:643
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:1124
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:416
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:275
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:268
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
Definition: eda_text.cpp:1237
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:290
void SetFontIndex(int aIdx)
Definition: eda_text.cpp:1014
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:870
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:298
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:248
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:400
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: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:249
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:426
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:50
#define CTL_OMIT_HIDE
Omit the hide attribute in .kicad_xxx files.
Definition: ctl_flags.h:39
#define CTL_OMIT_COLOR
Omit the color attribute in .kicad_xxx files.
Definition: ctl_flags.h:49
#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:1311
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:102
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
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