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() )
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  VECTOR2D extents = font.ComputeStringBoundaryLimits( text, fontSize, penWidth );
279  double interline = KIGFX::STROKE_FONT::GetInterline( fontSize.y );
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( KiROUND( extents.x ), KiROUND( extents.y ) );
284  wxPoint pos = GetTextPos();
285 
286  if( IsMultilineAllowed() && aLine > 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
287  pos.y -= KiROUND( aLine * interline );
288 
289  if( aInvertY )
290  pos.y = -pos.y;
291 
292  rect.SetOrigin( pos );
293 
294  if( hasOverBar )
295  { // A overbar adds an extra size to the text
296  // Height from the base line text of chars like [ or {
297  double curr_height = GetTextHeight() * 1.15;
298  double overbarPosition = font.ComputeOverbarVerticalPosition( fontSize.y );
299  int extra_height = KiROUND( overbarPosition - curr_height );
300 
301  extra_height += thickness / 2;
302  textsize.y += extra_height;
303  rect.Move( wxPoint( 0, -extra_height ) );
304  }
305 
306  // for multiline texts and aLine < 0, merge all rectangles
307  // ( if aLine < 0, we want the full text bounding box )
308  if( IsMultilineAllowed() && aLine < 0 )
309  {
310  for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
311  {
312  text = strings.Item( ii );
313  extents = font.ComputeStringBoundaryLimits( text, fontSize, penWidth );
314  textsize.x = std::max( textsize.x, KiROUND( extents.x ) );
315  }
316 
317  // interline spacing is only *between* lines, so total height is the height of the first
318  // line plus the interline distance (with interline spacing) for all subsequent lines
319  // Don't add interline spacing to empty textboxes
320  if( strings.GetCount() )
321  textsize.y += KiROUND( ( strings.GetCount() - 1 ) * interline );
322  }
323 
324  rect.SetSize( textsize );
325 
326  /* Now, calculate the rect origin, according to text justification
327  * At this point the rectangle origin is the text origin (m_Pos).
328  * This is true only for left and top text justified texts (using top to bottom Y axis
329  * orientation). and must be recalculated for others justifications
330  * also, note the V justification is relative to the first line
331  */
332  switch( GetHorizJustify() )
333  {
335  if( IsMirrored() )
336  rect.SetX( rect.GetX() - rect.GetWidth() );
337  break;
338 
340  rect.SetX( rect.GetX() - ( rect.GetWidth() / 2 ) );
341  break;
342 
344  if( !IsMirrored() )
345  rect.SetX( rect.GetX() - rect.GetWidth() );
346  break;
347  }
348 
349  switch( GetVertJustify() )
350  {
352  break;
353 
355  rect.SetY( rect.GetY() - KiROUND( interline / 2.0 ) );
356  break;
357 
359  rect.SetY( rect.GetY() - KiROUND( interline ) );
360  break;
361  }
362 
363  if( linecount > 1 )
364  {
365  int yoffset;
366  linecount -= 1;
367 
368  switch( GetVertJustify() )
369  {
371  break;
372 
374  yoffset = KiROUND( linecount * interline / 2.0 );
375  rect.SetY( rect.GetY() - yoffset );
376  break;
377 
379  yoffset = KiROUND( linecount * interline );
380  rect.SetY( rect.GetY() - yoffset );
381  break;
382  }
383  }
384 
385  // Many fonts draw diacriticals, descenders, etc. outside the X-height of the font. This
386  // will cacth most (but probably not all) of them.
387  rect.Inflate( 0, KiROUND( thickness * 0.75 ) );
388 
389  rect.Normalize(); // Make h and v sizes always >= 0
390 
391  return rect;
392 }
393 
394 
395 bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
396 {
397  EDA_RECT rect = GetTextBox();
398  wxPoint location = aPoint;
399 
400  rect.Inflate( aAccuracy );
401  RotatePoint( &location, GetTextPos(), -GetTextAngle() );
402 
403  return rect.Contains( location );
404 }
405 
406 
407 bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
408 {
409  EDA_RECT rect = aRect;
410 
411  rect.Inflate( aAccuracy );
412 
413  if( aContains )
414  return rect.Contains( GetTextBox() );
415 
416  return rect.Intersects( GetTextBox(), GetTextAngle() );
417 }
418 
419 
420 void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
421  const COLOR4D& aColor, OUTLINE_MODE aFillMode )
422 {
423  if( IsMultilineAllowed() )
424  {
425  std::vector<wxPoint> positions;
426  wxArrayString strings;
427  wxStringSplit( GetShownText(), strings, '\n' );
428 
429  positions.reserve( strings.Count() );
430 
431  GetLinePositions( positions, strings.Count() );
432 
433  for( unsigned ii = 0; ii < strings.Count(); ii++ )
434  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
435  }
436  else
437  {
438  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText(), GetTextPos() );
439  }
440 }
441 
442 
443 void EDA_TEXT::GetLinePositions( std::vector<wxPoint>& aPositions, int aLineCount ) const
444 {
445  wxPoint pos = GetTextPos(); // Position of first line of the
446  // multiline text according to
447  // the center of the multiline text block
448 
449  wxPoint offset; // Offset to next line.
450 
451  offset.y = GetInterline();
452 
453  if( aLineCount > 1 )
454  {
455  switch( GetVertJustify() )
456  {
458  break;
459 
461  pos.y -= ( aLineCount - 1 ) * offset.y / 2;
462  break;
463 
465  pos.y -= ( aLineCount - 1 ) * offset.y;
466  break;
467  }
468  }
469 
470  // Rotate the position of the first line
471  // around the center of the multiline text block
472  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
473 
474  // Rotate the offset lines to increase happened in the right direction
475  RotatePoint( &offset, GetTextAngle() );
476 
477  for( int ii = 0; ii < aLineCount; ii++ )
478  {
479  aPositions.push_back( pos );
480  pos += offset;
481  }
482 }
483 
484 void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
485  const COLOR4D& aColor, OUTLINE_MODE aFillMode,
486  const wxString& aText, const wxPoint &aPos )
487 {
488  wxDC* DC = aSettings->GetPrintDC();
489  int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() );
490 
491  if( aFillMode == SKETCH )
492  penWidth = -penWidth;
493 
494  wxSize size = GetTextSize();
495 
496  if( IsMirrored() )
497  size.x = -size.x;
498 
499  GRText( DC, aOffset + aPos, aColor, aText, GetTextAngle(), size, GetHorizJustify(),
500  GetVertJustify(), penWidth, IsItalic(), IsBold() );
501 }
502 
503 
505 {
506  int style = 0;
507 
508  if( IsItalic() )
509  style = 1;
510 
511  if( IsBold() )
512  style += 2;
513 
514  wxString stylemsg[4] = {
515  _("Normal"),
516  _("Italic"),
517  _("Bold"),
518  _("Bold+Italic")
519  };
520 
521  return stylemsg[style];
522 }
523 
524 
526 {
527  return ( IsVisible()
528  && !IsMirrored()
531  && GetTextThickness() == 0
532  && !IsItalic()
533  && !IsBold()
534  && !IsMultilineAllowed()
535  );
536 }
537 
538 
539 void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
540 {
541 #ifndef GERBVIEW // Gerbview does not use EDA_TEXT::Format
542  // and does not define FormatInternalUnits, used here
543  // however this function should exist
544 
545  aFormatter->Print( aNestLevel + 1, "(effects" );
546 
547  // Text size
548  aFormatter->Print( 0, " (font" );
549 
550  aFormatter->Print( 0, " (size %s %s)",
551  FormatInternalUnits( GetTextHeight() ).c_str(),
552  FormatInternalUnits( GetTextWidth() ).c_str() );
553 
554  if( GetTextThickness() )
555  {
556  aFormatter->Print( 0, " (thickness %s)",
557  FormatInternalUnits( GetTextThickness() ).c_str() );
558  }
559 
560  if( IsBold() )
561  aFormatter->Print( 0, " bold" );
562 
563  if( IsItalic() )
564  aFormatter->Print( 0, " italic" );
565 
566  aFormatter->Print( 0, ")"); // (font
567 
570  {
571  aFormatter->Print( 0, " (justify");
572 
574  aFormatter->Print( 0, GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT ? " left" : " right" );
575 
577  aFormatter->Print( 0, GetVertJustify() == GR_TEXT_VJUSTIFY_TOP ? " top" : " bottom" );
578 
579  if( IsMirrored() )
580  aFormatter->Print( 0, " mirror" );
581 
582  aFormatter->Print( 0, ")" ); // (justify
583  }
584 
585  if( !(aControlBits & CTL_OMIT_HIDE) && !IsVisible() )
586  aFormatter->Print( 0, " hide" );
587 
588  aFormatter->Print( 0, ")\n" ); // (justify
589 
590 #endif
591 }
592 
593 // Convert the text shape to a list of segment
594 // each segment is stored as 2 wxPoints: its starting point and its ending point
595 // we are using GRText to create the segments and therefore a call-back function is needed
596 
597 // This is a call back function, used by GRText to put each segment in buffer
598 static void addTextSegmToBuffer( int x0, int y0, int xf, int yf, void* aData )
599 {
600  std::vector<wxPoint>* cornerBuffer = static_cast<std::vector<wxPoint>*>( aData );
601  cornerBuffer->push_back( wxPoint( x0, y0 ) );
602  cornerBuffer->push_back( wxPoint( xf, yf ) );
603 }
604 
605 
606 std::vector<wxPoint> EDA_TEXT::TransformToSegmentList() const
607 {
608  std::vector<wxPoint> cornerBuffer;
609  wxSize size = GetTextSize();
610 
611  if( IsMirrored() )
612  size.x = -size.x;
613 
614  bool forceBold = true;
615  int penWidth = 0; // use max-width for bold text
616 
617  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
618 
619  if( IsMultilineAllowed() )
620  {
621  wxArrayString strings_list;
622  wxStringSplit( GetShownText(), strings_list, wxChar('\n') );
623  std::vector<wxPoint> positions;
624  positions.reserve( strings_list.Count() );
625  GetLinePositions( positions, strings_list.Count() );
626 
627  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
628  {
629  wxString txt = strings_list.Item( ii );
630  GRText( nullptr, positions[ii], color, txt, GetDrawRotation(), size,
631  GetDrawHorizJustify(), GetDrawVertJustify(), penWidth, IsItalic(), forceBold,
632  addTextSegmToBuffer, &cornerBuffer );
633  }
634  }
635  else
636  {
637  GRText( nullptr, GetDrawPos(), color, GetShownText(), GetDrawRotation(), size,
638  GetDrawHorizJustify(), GetDrawVertJustify(), penWidth, IsItalic(), forceBold,
639  addTextSegmToBuffer, &cornerBuffer );
640  }
641 
642  return cornerBuffer;
643 }
644 
645 
646 std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( ) const
647 {
648  std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
649  int penWidth = GetEffectiveTextPenWidth();
650  std::vector<wxPoint> pts = TransformToSegmentList();
651 
652  for( unsigned jj = 0; jj < pts.size(); jj += 2 )
653  shape->AddShape( new SHAPE_SEGMENT( pts[jj], pts[jj+1], penWidth ) );
654 
655  return shape;
656 }
657 
658 
659 int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
660 {
661 #define EPSILON 2 // Should be enough for rounding errors on calculated items
662 
663 #define TEST( a, b ) { if( a != b ) return a - b; }
664 #define TEST_E( a, b ) { if( abs( a - b ) > EPSILON ) return a - b; }
665 #define TEST_PT( a, b ) { TEST_E( a.x, b.x ); TEST_E( a.y, b.y ); }
666 
667  TEST_PT( m_e.pos, aOther->m_e.pos );
668 
669  TEST_PT( m_e.size, aOther->m_e.size );
670  TEST_E( m_e.penwidth, aOther->m_e.penwidth );
671  TEST( m_e.angle, aOther->m_e.angle );
672 
673  TEST( m_e.hjustify, aOther->m_e.hjustify );
674  TEST( m_e.vjustify, aOther->m_e.vjustify );
675  TEST( m_e.bits, aOther->m_e.bits );
676 
677  return m_text.Cmp( aOther->m_text );
678 }
679 
680 
682  int aClearanceValue ) const
683 {
684  if( GetText().Length() == 0 )
685  return;
686 
687  wxPoint corners[4]; // Buffer of polygon corners
688 
689  EDA_RECT rect = GetTextBox();
690 
691  rect.Inflate( aClearanceValue );
692 
693  corners[0].x = rect.GetOrigin().x;
694  corners[0].y = rect.GetOrigin().y;
695  corners[1].y = corners[0].y;
696  corners[1].x = rect.GetRight();
697  corners[2].x = corners[1].x;
698  corners[2].y = rect.GetBottom();
699  corners[3].y = corners[2].y;
700  corners[3].x = corners[0].x;
701 
702  aCornerBuffer->NewOutline();
703 
704  for( wxPoint& corner : corners )
705  {
706  // Rotate polygon
707  RotatePoint( &corner.x, &corner.y, GetTextPos().x, GetTextPos().y, GetTextAngle() );
708  aCornerBuffer->Append( corner.x, corner.y );
709  }
710 }
711 
712 
713 static struct EDA_TEXT_DESC
714 {
716  {
718  .Map( GR_TEXT_HJUSTIFY_LEFT, _HKI( "Left" ) )
719  .Map( GR_TEXT_HJUSTIFY_CENTER, _HKI( "Center" ) )
720  .Map( GR_TEXT_HJUSTIFY_RIGHT, _HKI( "Right" ) );
722  .Map( GR_TEXT_VJUSTIFY_TOP, _HKI( "Top" ) )
723  .Map( GR_TEXT_VJUSTIFY_CENTER, _HKI( "Center" ) )
724  .Map( GR_TEXT_VJUSTIFY_BOTTOM, _HKI( "Bottom" ) );
725 
728  propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
730  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
734  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
736  &EDA_TEXT::IsItalic ) );
737  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
739  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
742  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
744  &EDA_TEXT::IsVisible ) );
745  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
749  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
753  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT,
754  EDA_TEXT_HJUSTIFY_T>( _HKI( "Horizontal Justification" ),
757  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT,
758  EDA_TEXT_VJUSTIFY_T>( _HKI( "Vertical Justification" ),
761  }
763 
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:107
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:484
std::vector< wxPoint > TransformToSegmentList() const
Convert the text shape to a list of segment.
Definition: eda_text.cpp:606
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:420
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
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:118
static void addTextSegmToBuffer(int x0, int y0, int xf, int yf, void *aData)
Definition: eda_text.cpp:598
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:130
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:681
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:123
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:504
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:110
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:120
#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:167
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:539
#define ALLOW_BOLD_THICKNESS
Definition: base_units.h:56
bool IsDefaultFormatting() const
Definition: eda_text.cpp:525
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:173
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:143
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:646
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:395
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:108
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:443
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:659
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
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:480
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