KiCad PCB EDA Suite
eda_text.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include <algorithm> // for max
31 #include <stddef.h> // for NULL
32 #include <type_traits> // for swap
33 #include <vector> // for vector
34 
35 #include <eda_item.h> // for EDA_ITEM
36 #include <base_units.h>
37 #include <basic_gal.h> // for BASIC_GAL, basic_gal
38 #include <convert_to_biu.h> // for Mils2iu
40 #include <eda_rect.h> // for EDA_RECT
41 #include <eda_text.h> // for EDA_TEXT, TEXT_EFFECTS, GR_TEXT_VJUSTIF...
42 #include <gal/color4d.h> // for COLOR4D, COLOR4D::BLACK
43 #include <gal/stroke_font.h> // for STROKE_FONT
44 #include <gr_text.h> // for GRText
45 #include <string_utils.h> // for UnescapeString
46 #include <math/util.h> // for KiROUND
47 #include <math/vector2d.h> // for VECTOR2D
48 #include <richio.h>
49 #include <render_settings.h>
50 #include <trigo.h> // for RotatePoint
51 #include <i18n_utility.h>
52 #include <geometry/shape_segment.h>
55 
56 
57 #include <wx/debug.h> // for wxASSERT
58 #include <wx/string.h> // wxString, wxArrayString
59 #include <wx/gdicmn.h> // for wxPoint,wxSize
60 
61 class OUTPUTFORMATTER;
62 class wxFindReplaceData;
63 
64 
65 void addTextSegmToPoly( int x0, int y0, int xf, int yf, void* aData )
66 {
67  TSEGM_2_POLY_PRMS* prm = static_cast<TSEGM_2_POLY_PRMS*>( aData );
68  TransformOvalToPolygon( *prm->m_cornerBuffer, wxPoint( x0, y0 ), wxPoint( xf, yf ),
69  prm->m_textWidth, prm->m_error, ERROR_INSIDE );
70 }
71 
72 
74 {
75  wxASSERT( aHorizJustify >= GR_TEXT_HJUSTIFY_LEFT && aHorizJustify <= GR_TEXT_HJUSTIFY_RIGHT );
76 
77  if( aHorizJustify > GR_TEXT_HJUSTIFY_RIGHT )
79 
80  if( aHorizJustify < GR_TEXT_HJUSTIFY_LEFT )
81  return GR_TEXT_HJUSTIFY_LEFT;
82 
83  return static_cast<EDA_TEXT_HJUSTIFY_T>( aHorizJustify );
84 }
85 
86 
88 {
89  wxASSERT( aVertJustify >= GR_TEXT_VJUSTIFY_TOP && aVertJustify <= GR_TEXT_VJUSTIFY_BOTTOM );
90 
91  if( aVertJustify > GR_TEXT_VJUSTIFY_BOTTOM )
93 
94  if( aVertJustify < GR_TEXT_VJUSTIFY_TOP )
95  return GR_TEXT_VJUSTIFY_TOP;
96 
97  return static_cast<EDA_TEXT_VJUSTIFY_T>( aVertJustify );
98 }
99 
100 
101 EDA_TEXT::EDA_TEXT( const wxString& text ) :
102  m_text( text ),
103  m_e( 1 << TE_VISIBLE )
104 {
105  int sz = Mils2iu( DEFAULT_SIZE_TEXT );
106  SetTextSize( wxSize( sz, sz ) );
107  cacheShownText();
108 }
109 
110 
111 EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) :
112  m_text( aText.m_text ),
113  m_e( aText.m_e )
114 {
115  cacheShownText();
116 }
117 
118 
120 {
121 }
122 
123 
124 void EDA_TEXT::SetText( const wxString& aText )
125 {
126  m_text = aText;
127  cacheShownText();
128 }
129 
130 
131 void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
132 {
133  m_text = aSrc.m_text;
134  m_shown_text = aSrc.m_shown_text;
136 }
137 
138 
139 void EDA_TEXT::SetEffects( const EDA_TEXT& aSrc )
140 {
141  m_e = aSrc.m_e;
142 }
143 
144 
145 void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
146 {
147  std::swap( m_text, aTradingPartner.m_text );
148  std::swap( m_shown_text, aTradingPartner.m_shown_text );
150 }
151 
152 
153 void EDA_TEXT::SwapEffects( EDA_TEXT& aTradingPartner )
154 {
155  std::swap( m_e, aTradingPartner.m_e );
156 }
157 
158 
159 int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultWidth ) const
160 {
161  int width = GetTextThickness();
162 
163  if( width <= 1 )
164  {
165  width = aDefaultWidth;
166 
167  if( IsBold() )
168  width = GetPenSizeForBold( GetTextWidth() );
169  else if( width <= 1 )
170  width = GetPenSizeForNormal( GetTextWidth() );
171  }
172 
173  // Clip pen size for small texts:
175 
176  return width;
177 }
178 
179 
180 bool EDA_TEXT::Replace( const wxFindReplaceData& aSearchData )
181 {
182  bool retval = EDA_ITEM::Replace( aSearchData, m_text );
183  cacheShownText();
184 
185  return retval;
186 }
187 
188 
190 {
191  if( m_text.IsEmpty() || m_text == wxT( "~" ) ) // ~ is legacy empty-string token
192  {
193  m_shown_text = wxEmptyString;
195  }
196  else
197  {
199  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
200  }
201 }
202 
203 
204 int EDA_TEXT::LenSize( const wxString& aLine, int aThickness ) const
205 {
208  basic_gal.SetFontUnderlined( false );
209  basic_gal.SetLineWidth( (float) aThickness );
211 
212  VECTOR2D tsize = basic_gal.GetTextLineSize( aLine );
213 
214  return KiROUND( tsize.x );
215 }
216 
217 
219 {
220  wxString tmp = GetShownText();
221 
222  tmp.Replace( wxT( "\n" ), wxT( " " ) );
223  tmp.Replace( wxT( "\r" ), wxT( " " ) );
224  tmp.Replace( wxT( "\t" ), wxT( " " ) );
225 
226  if( tmp.Length() > 36 )
227  tmp = tmp.Left( 34 ) + wxT( "..." );
228 
229  return tmp;
230 }
231 
232 
234 {
236 }
237 
238 
239 EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
240 {
241  EDA_RECT rect;
242  wxArrayString strings;
243  wxString text = GetShownText();
244  int thickness = GetEffectiveTextPenWidth();
245  int linecount = 1;
246  bool hasOverBar = false; // true if the first line of text as an overbar
247 
248  if( IsMultilineAllowed() )
249  {
250  wxStringSplit( text, strings, '\n' );
251 
252  if( strings.GetCount() ) // GetCount() == 0 for void strings
253  {
254  if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
255  text = strings.Item( aLine );
256  else
257  text = strings.Item( 0 );
258 
259  linecount = strings.GetCount();
260  }
261  }
262 
263  // Search for overbar symbol. Only text is scanned,
264  // because only this line can change the bounding box
265  for( unsigned ii = 1; ii < text.size(); ii++ )
266  {
267  if( text[ii-1] == '~' && text[ii] == '{' )
268  {
269  hasOverBar = true;
270  break;
271  }
272  }
273 
274  // calculate the H and V size
275  const auto& font = basic_gal.GetStrokeFont();
276  VECTOR2D fontSize( GetTextSize() );
277  double penWidth( thickness );
278  int dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
279  int dy = GetInterline();
280 
281  // Creates bounding box (rectangle) for horizontal, left and top justified text. The
282  // bounding box will be moved later according to the actual text options
283  wxSize textsize = wxSize( dx, dy );
284  wxPoint pos = GetTextPos();
285 
286  if( IsMultilineAllowed() && aLine > 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
287  {
288  pos.y -= aLine * GetInterline();
289  }
290 
291  if( aInvertY )
292  pos.y = -pos.y;
293 
294  rect.SetOrigin( pos );
295 
296  if( hasOverBar )
297  { // A overbar adds an extra size to the text
298  // Height from the base line text of chars like [ or {
299  double curr_height = GetTextHeight() * 1.15;
300  double overbarPosition = font.ComputeOverbarVerticalPosition( fontSize.y );
301  int extra_height = KiROUND( overbarPosition - curr_height );
302 
303  extra_height += thickness / 2;
304  textsize.y += extra_height;
305  rect.Move( wxPoint( 0, -extra_height ) );
306  }
307 
308  // for multiline texts and aLine < 0, merge all rectangles
309  // ( if aLine < 0, we want the full text bounding box )
310  if( IsMultilineAllowed() && aLine < 0 )
311  {
312  for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
313  {
314  text = strings.Item( ii );
315  dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
316  textsize.x = std::max( textsize.x, dx );
317  textsize.y += dy;
318  }
319  }
320 
321  rect.SetSize( textsize );
322 
323  /* Now, calculate the rect origin, according to text justification
324  * At this point the rectangle origin is the text origin (m_Pos).
325  * This is true only for left and top text justified texts (using top to bottom Y axis
326  * orientation). and must be recalculated for others justifications
327  * also, note the V justification is relative to the first line
328  */
329  switch( GetHorizJustify() )
330  {
332  if( IsMirrored() )
333  rect.SetX( rect.GetX() - rect.GetWidth() );
334  break;
335 
337  rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
338  break;
339 
341  if( !IsMirrored() )
342  rect.SetX( rect.GetX() - rect.GetWidth() );
343  break;
344  }
345 
346  switch( GetVertJustify() )
347  {
349  break;
350 
352  rect.SetY( rect.GetY() - ( dy / 2) );
353  break;
354 
356  rect.SetY( rect.GetY() - dy );
357  break;
358  }
359 
360  if( linecount > 1 )
361  {
362  int yoffset;
363  linecount -= 1;
364 
365  switch( GetVertJustify() )
366  {
368  break;
369 
371  yoffset = linecount * GetInterline() / 2;
372  rect.SetY( rect.GetY() - yoffset );
373  break;
374 
376  yoffset = linecount * GetInterline();
377  rect.SetY( rect.GetY() - yoffset );
378  break;
379  }
380  }
381 
382  // Many fonts draw diacriticals, descenders, etc. outside the X-height of the font. This
383  // will cacth most (but probably not all) of them.
384  rect.Inflate( 0, thickness * 1.5 );
385 
386  rect.Normalize(); // Make h and v sizes always >= 0
387 
388  return rect;
389 }
390 
391 
392 bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
393 {
394  EDA_RECT rect = GetTextBox();
395  wxPoint location = aPoint;
396 
397  rect.Inflate( aAccuracy );
398  RotatePoint( &location, GetTextPos(), -GetTextAngle() );
399 
400  return rect.Contains( location );
401 }
402 
403 
404 bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
405 {
406  EDA_RECT rect = aRect;
407 
408  rect.Inflate( aAccuracy );
409 
410  if( aContains )
411  return rect.Contains( GetTextBox() );
412 
413  return rect.Intersects( GetTextBox(), GetTextAngle() );
414 }
415 
416 
417 void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
418  const COLOR4D& aColor, OUTLINE_MODE aFillMode )
419 {
420  if( IsMultilineAllowed() )
421  {
422  std::vector<wxPoint> positions;
423  wxArrayString strings;
424  wxStringSplit( GetShownText(), strings, '\n' );
425 
426  positions.reserve( strings.Count() );
427 
428  GetLinePositions( positions, strings.Count() );
429 
430  for( unsigned ii = 0; ii < strings.Count(); ii++ )
431  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
432  }
433  else
434  {
435  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText(), GetTextPos() );
436  }
437 }
438 
439 
440 void EDA_TEXT::GetLinePositions( std::vector<wxPoint>& aPositions, int aLineCount ) const
441 {
442  wxPoint pos = GetTextPos(); // Position of first line of the
443  // multiline text according to
444  // the center of the multiline text block
445 
446  wxPoint offset; // Offset to next line.
447 
448  offset.y = GetInterline();
449 
450  if( aLineCount > 1 )
451  {
452  switch( GetVertJustify() )
453  {
455  break;
456 
458  pos.y -= ( aLineCount - 1 ) * offset.y / 2;
459  break;
460 
462  pos.y -= ( aLineCount - 1 ) * offset.y;
463  break;
464  }
465  }
466 
467  // Rotate the position of the first line
468  // around the center of the multiline text block
469  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
470 
471  // Rotate the offset lines to increase happened in the right direction
472  RotatePoint( &offset, GetTextAngle() );
473 
474  for( int ii = 0; ii < aLineCount; ii++ )
475  {
476  aPositions.push_back( pos );
477  pos += offset;
478  }
479 }
480 
481 void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
482  const COLOR4D& aColor, OUTLINE_MODE aFillMode,
483  const wxString& aText, const wxPoint &aPos )
484 {
485  wxDC* DC = aSettings->GetPrintDC();
486  int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() );
487 
488  if( aFillMode == SKETCH )
489  penWidth = -penWidth;
490 
491  wxSize size = GetTextSize();
492 
493  if( IsMirrored() )
494  size.x = -size.x;
495 
496  GRText( DC, aOffset + aPos, aColor, aText, GetTextAngle(), size, GetHorizJustify(),
497  GetVertJustify(), penWidth, IsItalic(), IsBold() );
498 }
499 
500 
502 {
503  int style = 0;
504 
505  if( IsItalic() )
506  style = 1;
507 
508  if( IsBold() )
509  style += 2;
510 
511  wxString stylemsg[4] = {
512  _("Normal"),
513  _("Italic"),
514  _("Bold"),
515  _("Bold+Italic")
516  };
517 
518  return stylemsg[style];
519 }
520 
521 
523 {
524  return ( IsVisible()
525  && !IsMirrored()
528  && GetTextThickness() == 0
529  && !IsItalic()
530  && !IsBold()
531  && !IsMultilineAllowed()
532  );
533 }
534 
535 
536 void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
537 {
538 #ifndef GERBVIEW // Gerbview does not use EDA_TEXT::Format
539  // and does not define FormatInternalUnits, used here
540  // however this function should exist
541 
542  aFormatter->Print( aNestLevel + 1, "(effects" );
543 
544  // Text size
545  aFormatter->Print( 0, " (font" );
546 
547  aFormatter->Print( 0, " (size %s %s)",
548  FormatInternalUnits( GetTextHeight() ).c_str(),
549  FormatInternalUnits( GetTextWidth() ).c_str() );
550 
551  if( GetTextThickness() )
552  {
553  aFormatter->Print( 0, " (thickness %s)",
554  FormatInternalUnits( GetTextThickness() ).c_str() );
555  }
556 
557  if( IsBold() )
558  aFormatter->Print( 0, " bold" );
559 
560  if( IsItalic() )
561  aFormatter->Print( 0, " italic" );
562 
563  aFormatter->Print( 0, ")"); // (font
564 
567  {
568  aFormatter->Print( 0, " (justify");
569 
571  aFormatter->Print( 0, GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT ? " left" : " right" );
572 
574  aFormatter->Print( 0, GetVertJustify() == GR_TEXT_VJUSTIFY_TOP ? " top" : " bottom" );
575 
576  if( IsMirrored() )
577  aFormatter->Print( 0, " mirror" );
578 
579  aFormatter->Print( 0, ")" ); // (justify
580  }
581 
582  if( !(aControlBits & CTL_OMIT_HIDE) && !IsVisible() )
583  aFormatter->Print( 0, " hide" );
584 
585  aFormatter->Print( 0, ")\n" ); // (justify
586 
587 #endif
588 }
589 
590 // Convert the text shape to a list of segment
591 // each segment is stored as 2 wxPoints: its starting point and its ending point
592 // we are using GRText to create the segments and therefore a call-back function is needed
593 
594 // This is a call back function, used by GRText to put each segment in buffer
595 static void addTextSegmToBuffer( int x0, int y0, int xf, int yf, void* aData )
596 {
597  std::vector<wxPoint>* cornerBuffer = static_cast<std::vector<wxPoint>*>( aData );
598  cornerBuffer->push_back( wxPoint( x0, y0 ) );
599  cornerBuffer->push_back( wxPoint( xf, yf ) );
600 }
601 
602 
603 std::vector<wxPoint> EDA_TEXT::TransformToSegmentList() const
604 {
605  std::vector<wxPoint> cornerBuffer;
606  wxSize size = GetTextSize();
607 
608  if( IsMirrored() )
609  size.x = -size.x;
610 
611  bool forceBold = true;
612  int penWidth = 0; // use max-width for bold text
613 
614  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
615 
616  if( IsMultilineAllowed() )
617  {
618  wxArrayString strings_list;
619  wxStringSplit( GetShownText(), strings_list, wxChar('\n') );
620  std::vector<wxPoint> positions;
621  positions.reserve( strings_list.Count() );
622  GetLinePositions( positions, strings_list.Count() );
623 
624  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
625  {
626  wxString txt = strings_list.Item( ii );
627  GRText( nullptr, positions[ii], color, txt, GetDrawRotation(), size,
628  GetDrawHorizJustify(), GetDrawVertJustify(), penWidth, IsItalic(), forceBold,
629  addTextSegmToBuffer, &cornerBuffer );
630  }
631  }
632  else
633  {
634  GRText( nullptr, GetDrawPos(), color, GetShownText(), GetDrawRotation(), size,
635  GetDrawHorizJustify(), GetDrawVertJustify(), penWidth, IsItalic(), forceBold,
636  addTextSegmToBuffer, &cornerBuffer );
637  }
638 
639  return cornerBuffer;
640 }
641 
642 
643 std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( ) const
644 {
645  std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
646  int penWidth = GetEffectiveTextPenWidth();
647  std::vector<wxPoint> pts = TransformToSegmentList();
648 
649  for( unsigned jj = 0; jj < pts.size(); jj += 2 )
650  shape->AddShape( new SHAPE_SEGMENT( pts[jj], pts[jj+1], penWidth ) );
651 
652  return shape;
653 }
654 
655 
656 int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
657 {
658 #define EPSILON 2 // Should be enough for rounding errors on calculated items
659 
660 #define TEST( a, b ) { if( a != b ) return a - b; }
661 #define TEST_E( a, b ) { if( abs( a - b ) > EPSILON ) return a - b; }
662 #define TEST_PT( a, b ) { TEST_E( a.x, b.x ); TEST_E( a.y, b.y ); }
663 
664  TEST_PT( m_e.pos, aOther->m_e.pos );
665 
666  TEST_PT( m_e.size, aOther->m_e.size );
667  TEST_E( m_e.penwidth, aOther->m_e.penwidth );
668  TEST( m_e.angle, aOther->m_e.angle );
669 
670  TEST( m_e.hjustify, aOther->m_e.hjustify );
671  TEST( m_e.vjustify, aOther->m_e.vjustify );
672  TEST( m_e.bits, aOther->m_e.bits );
673 
674  return m_text.Cmp( aOther->m_text );
675 }
676 
677 
679  int aClearanceValue ) const
680 {
681  if( GetText().Length() == 0 )
682  return;
683 
684  wxPoint corners[4]; // Buffer of polygon corners
685 
686  EDA_RECT rect = GetTextBox();
687 
688  // This ugly hack is because this code used to be defined in the board polygon code
689  // file rather than in the EDA_TEXT source file where it belonged. Using the board
690  // default text width was dubious so this recreates the same code with the exception
691  // if for some reason a different default text width is require for some other object.
692 #if !defined( DEFAULT_TEXT_WIDTH )
693 #define LOCAL_DEFAULT_TEXT_WIDTH
694 #define DEFAULT_TEXT_WIDTH 0.15
695 #endif
696 
697  rect.Inflate( aClearanceValue + Millimeter2iu( DEFAULT_TEXT_WIDTH ) );
698 
699 #if defined( LOCAL_DEFAULT_TEXT_WIDTH )
700 #undef DEFAULT_TEXT_WIDTH
701 #undef LOCAL_DEFAULT_TEXT_WIDTH
702 #endif
703 
704  corners[0].x = rect.GetOrigin().x;
705  corners[0].y = rect.GetOrigin().y;
706  corners[1].y = corners[0].y;
707  corners[1].x = rect.GetRight();
708  corners[2].x = corners[1].x;
709  corners[2].y = rect.GetBottom();
710  corners[3].y = corners[2].y;
711  corners[3].x = corners[0].x;
712 
713  aCornerBuffer->NewOutline();
714 
715  for( wxPoint& corner : corners )
716  {
717  // Rotate polygon
718  RotatePoint( &corner.x, &corner.y, GetTextPos().x, GetTextPos().y, GetTextAngle() );
719  aCornerBuffer->Append( corner.x, corner.y );
720  }
721 }
722 
723 
724 static struct EDA_TEXT_DESC
725 {
727  {
729  .Map( GR_TEXT_HJUSTIFY_LEFT, _HKI( "Left" ) )
730  .Map( GR_TEXT_HJUSTIFY_CENTER, _HKI( "Center" ) )
731  .Map( GR_TEXT_HJUSTIFY_RIGHT, _HKI( "Right" ) );
733  .Map( GR_TEXT_VJUSTIFY_TOP, _HKI( "Top" ) )
734  .Map( GR_TEXT_VJUSTIFY_CENTER, _HKI( "Center" ) )
735  .Map( GR_TEXT_VJUSTIFY_BOTTOM, _HKI( "Bottom" ) );
736 
739  propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
741  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
745  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
747  &EDA_TEXT::IsItalic ) );
748  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
750  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
753  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
755  &EDA_TEXT::IsVisible ) );
756  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
760  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
764  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT,
765  EDA_TEXT_HJUSTIFY_T>( _HKI( "Horizontal Justification" ),
768  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT,
769  EDA_TEXT_VJUSTIFY_T>( _HKI( "Vertical Justification" ),
772  }
774 
void SetMirrored(bool isMirrored)
Definition: eda_text.h:209
const STROKE_FONT & GetStrokeFont() const
EDA_TEXT(const wxString &text=wxEmptyString)
Definition: eda_text.cpp:101
bool IsBold() const
Definition: eda_text.h:204
OUTLINE_MODE
Definition: outline_mode.h:24
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:233
#define TEST(a, b)
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:153
void Move(const wxPoint &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: eda_rect.cpp:51
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:101
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:82
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:220
bool IsMirrored() const
Definition: eda_text.h:210
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:46
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:131
static double GetInterline(double aGlyphHeight)
Compute the distance (interline) between 2 lines of text (for multiline texts).
Implementation of conversion functions that require both schematic and board internal units.
virtual double GetDrawRotation() const
Definition: eda_text.h:388
int GetX() const
Definition: eda_rect.h:98
wxString m_shown_text
Definition: eda_text.h:412
void printOneLineOfText(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, const COLOR4D &aColor, OUTLINE_MODE aFillMode, const wxString &aText, const wxPoint &aPos)
Print each line of this EDA_TEXT.
Definition: eda_text.cpp:481
std::vector< wxPoint > TransformToSegmentList() const
Convert the text shape to a list of segment.
Definition: eda_text.cpp:603
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, const COLOR4D &aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:417
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:139
bool Replace(const wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:180
#define DEFAULT_TEXT_WIDTH
void SetItalic(bool isItalic)
Definition: eda_text.h:200
TEXT_EFFECTS m_e
Definition: eda_text.h:415
int color
Definition: DXF_plotter.cpp:57
void cacheShownText()
Definition: eda_text.cpp:189
EDA_RECT GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:239
void SetFontBold(bool aBold)
Set bold property of current font.
SHAPE_POLY_SET * m_cornerBuffer
Definition: eda_text.h:50
int GetWidth() const
Definition: eda_rect.h:109
static void addTextSegmToBuffer(int x0, int y0, int xf, int yf, void *aData)
Definition: eda_text.cpp:595
static ENUM_MAP< T > & Instance()
Definition: property.h:510
double GetTextAngle() const
Definition: eda_text.h:195
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:413
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:121
static struct EDA_TEXT_DESC _EDA_TEXT_DESC
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:309
signed char vjustify
vertical justification
Definition: eda_text.h:123
void GRText(wxDC *aDC, const wxPoint &aPos, const COLOR4D &aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf, void *aData), void *aCallbackData, PLOTTER *aPlotter)
Draw a graphic text (like footprint texts).
Definition: gr_text.cpp:129
A helper for the text to polygon callback function.
Definition: eda_text.h:46
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:258
#define TEST_PT(a, b)
Definition: color4d.h:44
void TransformBoundingBoxWithClearanceToPolygon(SHAPE_POLY_SET *aCornerBuffer, int aClearanceValue) const
Convert the text bounding box to a rectangular polygon depending on the text orientation,...
Definition: eda_text.cpp:678
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
int GetTextThickness() const
Definition: eda_text.h:181
void addTextSegmToPoly(int x0, int y0, int xf, int yf, void *aData)
Callback function used to convert text segments to polygons.
Definition: eda_text.cpp:65
VECTOR2D GetTextLineSize(const UTF8 &aText) const
Compute the X and Y size of a given text.
#define REGISTER_TYPE(x)
Definition: property_mgr.h:248
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
wxPoint pos
Definition: eda_text.h:127
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:159
virtual void SetLineWidth(float aLineWidth)
Set the line width.
wxSize size
Definition: eda_text.h:124
int GetBottom() const
Definition: eda_rect.h:114
int GetTextHeight() const
Definition: eda_text.h:265
bool IsItalic() const
Definition: eda_text.h:201
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:140
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
wxString GetTextStyleName() const
Definition: eda_text.cpp:501
int LenSize(const wxString &aLine, int aThickness) const
Definition: eda_text.cpp:204
Display value expressed in distance units (mm/inch)
Definition: property.h:53
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Don't allow text to become cluttered up in its own fatness.
Definition: gr_text.cpp:67
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:219
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:73
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
Represent a set of closed polygons.
virtual bool IsVisible() const
Definition: eda_text.h:207
const wxPoint GetOrigin() const
Definition: eda_rect.h:101
const wxSize & GetTextSize() const
Definition: eda_text.h:259
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:223
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:52
int GetRight() const
Definition: eda_rect.h:111
#define TEST_E(a, b)
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:218
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:612
#define _(s)
void SetX(int val)
Definition: eda_rect.h:158
virtual ~EDA_TEXT()
Definition: eda_text.cpp:119
wxDC * GetPrintDC() const
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:536
#define ALLOW_BOLD_THICKNESS
Definition: base_units.h:56
bool IsDefaultFormatting() const
Definition: eda_text.cpp:522
wxString m_text
Definition: eda_text.h:411
static bool Replace(const wxFindReplaceData &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:170
void SetFontItalic(bool aItalic)
Set italic property of current font.
int NewOutline()
Creates a new hole in a given outline.
virtual EDA_TEXT_VJUSTIFY_T GetDrawVertJustify() const
Definition: eda_text.h:391
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:87
wxString UnescapeString(const wxString &aSource)
bool IsMultilineAllowed() const
Definition: eda_text.h:217
void SetGlyphSize(const VECTOR2D &aSize)
Set the font glyph size.
void SetY(int val)
Definition: eda_rect.h:164
int bits
any set of booleans a client uses.
Definition: eda_text.h:121
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:89
Some functions to handle hotkeys in KiCad.
void SetTextWidth(int aWidth)
Definition: eda_text.h:261
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
void SetSize(const wxSize &size)
Definition: eda_rect.h:134
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:145
int GetTextWidth() const
Definition: eda_text.h:262
void SetFontUnderlined(bool aUnderlined)
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape() const
Definition: eda_text.cpp:643
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:222
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
Handle the component boundary box.
Definition: eda_rect.h:42
virtual bool TextHitTest(const wxPoint &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:392
void SetTextHeight(int aHeight)
Definition: eda_text.h:264
void TransformOvalToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aStart, const wxPoint &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
int GetY() const
Definition: eda_rect.h:99
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
void GetLinePositions(std::vector< wxPoint > &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:440
double angle
now: 0.1 degrees; future: degrees
Definition: eda_text.h:126
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:268
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:180
int Compare(const EDA_TEXT *aOther) const
Definition: eda_text.cpp:656
BASIC_GAL basic_gal(basic_displayOptions)
virtual EDA_TEXT_HJUSTIFY_T GetDrawHorizJustify() const
Definition: eda_text.h:390
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
signed char hjustify
horizontal justification
Definition: eda_text.h:122
#define CTL_OMIT_HIDE
Definition: eda_text.h:77
static constexpr int Millimeter2iu(double mm)
void SetBold(bool aBold)
Definition: eda_text.h:203
#define _HKI(x)
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154
virtual wxPoint GetDrawPos() const
Definition: eda_text.h:389
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:162
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:485
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
int penwidth
Definition: eda_text.h:125
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103