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
39 #include <eda_rect.h> // for EDA_RECT
40 #include <eda_text.h> // for EDA_TEXT, TEXT_EFFECTS, GR_TEXT_VJUSTIF...
41 #include <gal/color4d.h> // for COLOR4D, COLOR4D::BLACK
42 #include <gal/stroke_font.h> // for STROKE_FONT
43 #include <gr_text.h> // for GRText
44 #include <kicad_string.h> // for UnescapeString
45 #include <math/util.h> // for KiROUND
46 #include <math/vector2d.h> // for VECTOR2D
47 #include <richio.h>
48 #include <render_settings.h>
49 #include <trigo.h> // for RotatePoint
50 #include <i18n_utility.h>
51 #include <geometry/shape_segment.h>
53 
54 
55 #include <wx/debug.h> // for wxASSERT
56 #include <wx/string.h> // wxString, wxArrayString
57 #include <wx/gdicmn.h> // for wxPoint,wxSize
58 
59 class OUTPUTFORMATTER;
60 class wxFindReplaceData;
61 
62 
64 {
65  wxASSERT( aHorizJustify >= GR_TEXT_HJUSTIFY_LEFT && aHorizJustify <= GR_TEXT_HJUSTIFY_RIGHT );
66 
67  if( aHorizJustify > GR_TEXT_HJUSTIFY_RIGHT )
69 
70  if( aHorizJustify < GR_TEXT_HJUSTIFY_LEFT )
71  return GR_TEXT_HJUSTIFY_LEFT;
72 
73  return static_cast<EDA_TEXT_HJUSTIFY_T>( aHorizJustify );
74 }
75 
76 
78 {
79  wxASSERT( aVertJustify >= GR_TEXT_VJUSTIFY_TOP && aVertJustify <= GR_TEXT_VJUSTIFY_BOTTOM );
80 
81  if( aVertJustify > GR_TEXT_VJUSTIFY_BOTTOM )
83 
84  if( aVertJustify < GR_TEXT_VJUSTIFY_TOP )
85  return GR_TEXT_VJUSTIFY_TOP;
86 
87  return static_cast<EDA_TEXT_VJUSTIFY_T>( aVertJustify );
88 }
89 
90 
91 EDA_TEXT::EDA_TEXT( const wxString& text ) :
92  m_text( text ),
93  m_e( 1 << TE_VISIBLE )
94 {
95  int sz = Mils2iu( DEFAULT_SIZE_TEXT );
96  SetTextSize( wxSize( sz, sz ) );
98 }
99 
100 
101 EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) :
102  m_text( aText.m_text ),
103  m_e( aText.m_e )
104 {
105  cacheShownText();
106 }
107 
108 
110 {
111 }
112 
113 
114 void EDA_TEXT::SetText( const wxString& aText )
115 {
116  m_text = aText;
117  cacheShownText();
118 }
119 
120 
121 void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
122 {
123  m_text = aSrc.m_text;
124  m_shown_text = aSrc.m_shown_text;
126 }
127 
128 
129 void EDA_TEXT::SetEffects( const EDA_TEXT& aSrc )
130 {
131  m_e = aSrc.m_e;
132 }
133 
134 
135 void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
136 {
137  std::swap( m_text, aTradingPartner.m_text );
138  std::swap( m_shown_text, aTradingPartner.m_shown_text );
140 }
141 
142 
143 void EDA_TEXT::SwapEffects( EDA_TEXT& aTradingPartner )
144 {
145  std::swap( m_e, aTradingPartner.m_e );
146 }
147 
148 
149 int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultWidth ) const
150 {
151  int width = GetTextThickness();
152 
153  if( width <= 1 )
154  {
155  width = aDefaultWidth;
156 
157  if( IsBold() )
158  width = GetPenSizeForBold( GetTextWidth() );
159  else if( width <= 1 )
160  width = GetPenSizeForNormal( GetTextWidth() );
161  }
162 
163  // Clip pen size for small texts:
165 
166  return width;
167 }
168 
169 
170 bool EDA_TEXT::Replace( const wxFindReplaceData& aSearchData )
171 {
172  bool retval = EDA_ITEM::Replace( aSearchData, m_text );
173  cacheShownText();
174 
175  return retval;
176 }
177 
178 
180 {
181  if( m_text.IsEmpty() || m_text == wxT( "~" ) ) // ~ is legacy empty-string token
182  {
183  m_shown_text = wxEmptyString;
185  }
186  else
187  {
189  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
190  }
191 }
192 
193 
194 int EDA_TEXT::LenSize( const wxString& aLine, int aThickness ) const
195 {
198  basic_gal.SetFontUnderlined( false );
199  basic_gal.SetLineWidth( (float) aThickness );
201 
202  VECTOR2D tsize = basic_gal.GetTextLineSize( aLine );
203 
204  return KiROUND( tsize.x );
205 }
206 
207 
209 {
210  wxString tmp = GetShownText();
211 
212  tmp.Replace( wxT( "\n" ), wxT( " " ) );
213  tmp.Replace( wxT( "\r" ), wxT( " " ) );
214  tmp.Replace( wxT( "\t" ), wxT( " " ) );
215 
216  if( tmp.Length() > 36 )
217  tmp = tmp.Left( 34 ) + wxT( "..." );
218 
219  return tmp;
220 }
221 
222 
224 {
226 }
227 
228 
229 EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
230 {
231  EDA_RECT rect;
232  wxArrayString strings;
233  wxString text = GetShownText();
234  int thickness = GetEffectiveTextPenWidth();
235  int linecount = 1;
236  bool hasOverBar = false; // true if the first line of text as an overbar
237 
238  if( IsMultilineAllowed() )
239  {
240  wxStringSplit( text, strings, '\n' );
241 
242  if( strings.GetCount() ) // GetCount() == 0 for void strings
243  {
244  if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
245  text = strings.Item( aLine );
246  else
247  text = strings.Item( 0 );
248 
249  linecount = strings.GetCount();
250  }
251  }
252 
253  // Search for overbar symbol. Only text is scanned,
254  // because only this line can change the bounding box
255  for( unsigned ii = 1; ii < text.size(); ii++ )
256  {
257  if( text[ii-1] == '~' && text[ii] == '{' )
258  {
259  hasOverBar = true;
260  break;
261  }
262  }
263 
264  // calculate the H and V size
265  const auto& font = basic_gal.GetStrokeFont();
266  VECTOR2D fontSize( GetTextSize() );
267  double penWidth( thickness );
268  int dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
269  int dy = GetInterline();
270 
271  // Creates bounding box (rectangle) for horizontal, left and top justified text. The
272  // bounding box will be moved later according to the actual text options
273  wxSize textsize = wxSize( dx, dy );
274  wxPoint pos = GetTextPos();
275 
276  if( IsMultilineAllowed() && aLine > 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
277  {
278  pos.y -= aLine * GetInterline();
279  }
280 
281  if( aInvertY )
282  pos.y = -pos.y;
283 
284  rect.SetOrigin( pos );
285 
286  if( hasOverBar )
287  { // A overbar adds an extra size to the text
288  // Height from the base line text of chars like [ or {
289  double curr_height = GetTextHeight() * 1.15;
290  double overbarPosition = font.ComputeOverbarVerticalPosition( fontSize.y );
291  int extra_height = KiROUND( overbarPosition - curr_height );
292 
293  extra_height += thickness / 2;
294  textsize.y += extra_height;
295  rect.Move( wxPoint( 0, -extra_height ) );
296  }
297 
298  // for multiline texts and aLine < 0, merge all rectangles
299  // ( if aLine < 0, we want the full text bounding box )
300  if( IsMultilineAllowed() && aLine < 0 )
301  {
302  for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
303  {
304  text = strings.Item( ii );
305  dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
306  textsize.x = std::max( textsize.x, dx );
307  textsize.y += dy;
308  }
309  }
310 
311  rect.SetSize( textsize );
312 
313  /* Now, calculate the rect origin, according to text justification
314  * At this point the rectangle origin is the text origin (m_Pos).
315  * This is true only for left and top text justified texts (using top to bottom Y axis
316  * orientation). and must be recalculated for others justifications
317  * also, note the V justification is relative to the first line
318  */
319  switch( GetHorizJustify() )
320  {
322  if( IsMirrored() )
323  rect.SetX( rect.GetX() - rect.GetWidth() );
324  break;
325 
327  rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
328  break;
329 
331  if( !IsMirrored() )
332  rect.SetX( rect.GetX() - rect.GetWidth() );
333  break;
334  }
335 
336  switch( GetVertJustify() )
337  {
339  break;
340 
342  rect.SetY( rect.GetY() - ( dy / 2) );
343  break;
344 
346  rect.SetY( rect.GetY() - dy );
347  break;
348  }
349 
350  if( linecount > 1 )
351  {
352  int yoffset;
353  linecount -= 1;
354 
355  switch( GetVertJustify() )
356  {
358  break;
359 
361  yoffset = linecount * GetInterline() / 2;
362  rect.SetY( rect.GetY() - yoffset );
363  break;
364 
366  yoffset = linecount * GetInterline();
367  rect.SetY( rect.GetY() - yoffset );
368  break;
369  }
370  }
371 
372  // Many fonts draw diacriticals, descenders, etc. outside the X-height of the font. This
373  // will cacth most (but probably not all) of them.
374  rect.Inflate( 0, thickness * 1.5 );
375 
376  rect.Normalize(); // Make h and v sizes always >= 0
377 
378  return rect;
379 }
380 
381 
382 bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
383 {
384  EDA_RECT rect = GetTextBox();
385  wxPoint location = aPoint;
386 
387  rect.Inflate( aAccuracy );
388  RotatePoint( &location, GetTextPos(), -GetTextAngle() );
389 
390  return rect.Contains( location );
391 }
392 
393 
394 bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
395 {
396  EDA_RECT rect = aRect;
397 
398  rect.Inflate( aAccuracy );
399 
400  if( aContains )
401  return rect.Contains( GetTextBox() );
402 
403  return rect.Intersects( GetTextBox(), GetTextAngle() );
404 }
405 
406 
407 void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
408  COLOR4D aColor, OUTLINE_MODE aFillMode )
409 {
410  if( IsMultilineAllowed() )
411  {
412  std::vector<wxPoint> positions;
413  wxArrayString strings;
414  wxStringSplit( GetShownText(), strings, '\n' );
415 
416  positions.reserve( strings.Count() );
417 
418  GetLinePositions( positions, strings.Count() );
419 
420  for( unsigned ii = 0; ii < strings.Count(); ii++ )
421  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
422  }
423  else
424  {
425  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText(), GetTextPos() );
426  }
427 }
428 
429 
430 void EDA_TEXT::GetLinePositions( std::vector<wxPoint>& aPositions, int aLineCount ) const
431 {
432  wxPoint pos = GetTextPos(); // Position of first line of the
433  // multiline text according to
434  // the center of the multiline text block
435 
436  wxPoint offset; // Offset to next line.
437 
438  offset.y = GetInterline();
439 
440  if( aLineCount > 1 )
441  {
442  switch( GetVertJustify() )
443  {
445  break;
446 
448  pos.y -= ( aLineCount - 1 ) * offset.y / 2;
449  break;
450 
452  pos.y -= ( aLineCount - 1 ) * offset.y;
453  break;
454  }
455  }
456 
457  // Rotate the position of the first line
458  // around the center of the multiline text block
459  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
460 
461  // Rotate the offset lines to increase happened in the right direction
462  RotatePoint( &offset, GetTextAngle() );
463 
464  for( int ii = 0; ii < aLineCount; ii++ )
465  {
466  aPositions.push_back( pos );
467  pos += offset;
468  }
469 }
470 
471 void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
472  const COLOR4D& aColor, OUTLINE_MODE aFillMode,
473  const wxString& aText, const wxPoint &aPos )
474 {
475  wxDC* DC = aSettings->GetPrintDC();
476  int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() );
477 
478  if( aFillMode == SKETCH )
479  penWidth = -penWidth;
480 
481  wxSize size = GetTextSize();
482 
483  if( IsMirrored() )
484  size.x = -size.x;
485 
486  GRText( DC, aOffset + aPos, aColor, aText, GetTextAngle(), size, GetHorizJustify(),
487  GetVertJustify(), penWidth, IsItalic(), IsBold() );
488 }
489 
490 
492 {
493  int style = 0;
494 
495  if( IsItalic() )
496  style = 1;
497 
498  if( IsBold() )
499  style += 2;
500 
501  wxString stylemsg[4] = {
502  _("Normal"),
503  _("Italic"),
504  _("Bold"),
505  _("Bold+Italic")
506  };
507 
508  return stylemsg[style];
509 }
510 
511 
513 {
514  return ( IsVisible()
515  && !IsMirrored()
518  && GetTextThickness() == 0
519  && !IsItalic()
520  && !IsBold()
521  && !IsMultilineAllowed()
522  );
523 }
524 
525 
526 void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
527 {
528 #ifndef GERBVIEW // Gerbview does not use EDA_TEXT::Format
529  // and does not define FormatInternalUnits, used here
530  // however this function should exist
531 
532  aFormatter->Print( aNestLevel + 1, "(effects" );
533 
534  // Text size
535  aFormatter->Print( 0, " (font" );
536 
537  aFormatter->Print( 0, " (size %s %s)",
538  FormatInternalUnits( GetTextHeight() ).c_str(),
539  FormatInternalUnits( GetTextWidth() ).c_str() );
540 
541  if( GetTextThickness() )
542  aFormatter->Print( 0, " (thickness %s)",
543  FormatInternalUnits( GetTextThickness() ).c_str() );
544 
545  if( IsBold() )
546  aFormatter->Print( 0, " bold" );
547 
548  if( IsItalic() )
549  aFormatter->Print( 0, " italic" );
550 
551  aFormatter->Print( 0, ")"); // (font
552 
553  if( IsMirrored() ||
556  {
557  aFormatter->Print( 0, " (justify");
558 
560  aFormatter->Print( 0,
561  ( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT ) ? " left" : " right" );
562 
564  aFormatter->Print( 0, (GetVertJustify() == GR_TEXT_VJUSTIFY_TOP) ? " top" : " bottom" );
565 
566  if( IsMirrored() )
567  aFormatter->Print( 0, " mirror" );
568 
569  aFormatter->Print( 0, ")" ); // (justify
570  }
571 
572  if( !(aControlBits & CTL_OMIT_HIDE) && !IsVisible() )
573  aFormatter->Print( 0, " hide" );
574 
575  aFormatter->Print( 0, ")\n" ); // (justify
576 
577 #endif
578 }
579 
580 // Convert the text shape to a list of segment
581 // each segment is stored as 2 wxPoints: its starting point and its ending point
582 // we are using GRText to create the segments and therefore a call-back function is needed
583 
584 // This is a call back function, used by GRText to put each segment in buffer
585 static void addTextSegmToBuffer( int x0, int y0, int xf, int yf, void* aData )
586 {
587  std::vector<wxPoint>* cornerBuffer = static_cast<std::vector<wxPoint>*>( aData );
588  cornerBuffer->push_back( wxPoint( x0, y0 ) );
589  cornerBuffer->push_back( wxPoint( xf, yf ) );
590 }
591 
592 
593 std::vector<wxPoint> EDA_TEXT::TransformToSegmentList() const
594 {
595  std::vector<wxPoint> cornerBuffer;
596  wxSize size = GetTextSize();
597 
598  if( IsMirrored() )
599  size.x = -size.x;
600 
601  bool forceBold = true;
602  int penWidth = 0; // use max-width for bold text
603 
604  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
605 
606  if( IsMultilineAllowed() )
607  {
608  wxArrayString strings_list;
609  wxStringSplit( GetShownText(), strings_list, wxChar('\n') );
610  std::vector<wxPoint> positions;
611  positions.reserve( strings_list.Count() );
612  GetLinePositions( positions, strings_list.Count() );
613 
614  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
615  {
616  wxString txt = strings_list.Item( ii );
617  GRText( NULL, positions[ii], color, txt, GetDrawRotation(), size, GetHorizJustify(),
618  GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
619  &cornerBuffer );
620  }
621  }
622  else
623  {
625  GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), forceBold,
626  addTextSegmToBuffer, &cornerBuffer );
627  }
628 
629  return cornerBuffer;
630 }
631 
632 
633 std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( ) const
634 {
635  std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
636  int penWidth = GetEffectiveTextPenWidth();
637  std::vector<wxPoint> pts = TransformToSegmentList();
638 
639  for( unsigned jj = 0; jj < pts.size(); jj += 2 )
640  shape->AddShape( new SHAPE_SEGMENT( pts[jj], pts[jj+1], penWidth ) );
641 
642  return shape;
643 }
644 
645 
647 {
648  return GetTextAngle();
649 }
650 
651 
652 static struct EDA_TEXT_DESC
653 {
655  {
657  .Map( GR_TEXT_HJUSTIFY_LEFT, _HKI( "Left" ) )
658  .Map( GR_TEXT_HJUSTIFY_CENTER, _HKI( "Center" ) )
659  .Map( GR_TEXT_HJUSTIFY_RIGHT, _HKI( "Right" ) );
661  .Map( GR_TEXT_VJUSTIFY_TOP, _HKI( "Top" ) )
662  .Map( GR_TEXT_VJUSTIFY_CENTER, _HKI( "Center" ) )
663  .Map( GR_TEXT_VJUSTIFY_BOTTOM, _HKI( "Bottom" ) );
664 
667  propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
669  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
673  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
675  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
677  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
679  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
681  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
685  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
689  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT,
690  EDA_TEXT_HJUSTIFY_T>( _HKI( "Horizontal Justification" ),
693  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT,
694  EDA_TEXT_VJUSTIFY_T>( _HKI( "Vertical Justification" ),
697  }
699 
void SetMirrored(bool isMirrored)
Definition: eda_text.h:195
const STROKE_FONT & GetStrokeFont() const
EDA_TEXT(const wxString &text=wxEmptyString)
Definition: eda_text.cpp:91
bool IsBold() const
Definition: eda_text.h:190
OUTLINE_MODE
Definition: outline_mode.h:24
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:223
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:143
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:80
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:206
bool IsMirrored() const
Definition: eda_text.h:196
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:47
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:121
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.
int GetX() const
Definition: eda_rect.h:98
wxString m_shown_text
Definition: eda_text.h:393
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:471
std::vector< wxPoint > TransformToSegmentList() const
Convert the text shape to a list of segment.
Definition: eda_text.cpp:593
bool IsVisible() const
Definition: eda_text.h:193
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:129
bool Replace(const wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:170
void SetItalic(bool isItalic)
Definition: eda_text.h:186
TEXT_EFFECTS m_e
Definition: eda_text.h:396
int color
Definition: DXF_plotter.cpp:60
void cacheShownText()
Definition: eda_text.cpp:179
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:229
void SetFontBold(bool aBold)
Set bold property of current font.
void SetVisible(bool aVisible)
Definition: eda_text.h:192
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:585
static ENUM_MAP< T > & Instance()
Definition: property.h:510
double GetTextAngle() const
Definition: eda_text.h:181
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:394
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:306
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
virtual double GetDrawRotation() const
Definition: eda_text.cpp:646
Definition: color4d.h:44
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
int GetTextThickness() const
Definition: eda_text.h:167
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
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:149
virtual void SetLineWidth(float aLineWidth)
Set the line width.
int GetTextHeight() const
Definition: eda_text.h:251
bool IsItalic() const
Definition: eda_text.h:187
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
wxString GetTextStyleName() const
Definition: eda_text.cpp:491
int LenSize(const wxString &aLine, int aThickness) const
Definition: eda_text.cpp:194
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:68
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:63
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
#define NULL
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
const wxSize & GetTextSize() const
Definition: eda_text.h:245
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:53
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:208
#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:109
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:526
#define ALLOW_BOLD_THICKNESS
Definition: base_units.h:56
bool IsDefaultFormatting() const
Definition: eda_text.cpp:512
wxString m_text
Definition: eda_text.h:392
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:145
void SetFontItalic(bool aItalic)
Set italic property of current font.
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:77
bool IsMultilineAllowed() const
Definition: eda_text.h:203
void SetGlyphSize(const VECTOR2D &aSize)
Set the font glyph size.
void SetY(int val)
Definition: eda_rect.h:164
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: string.cpp:895
void GRText(wxDC *aDC, const wxPoint &aPos, 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:130
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:68
Some functions to handle hotkeys in KiCad.
void SetTextWidth(int aWidth)
Definition: eda_text.h:247
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
void SetSize(const wxSize &size)
Definition: eda_rect.h:134
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:135
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, COLOR4D aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:407
int GetTextWidth() const
Definition: eda_text.h:248
void SetFontUnderlined(bool aUnderlined)
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape() const
Definition: eda_text.cpp:633
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:214
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:382
void SetTextHeight(int aHeight)
Definition: eda_text.h:250
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:70
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:430
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
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:166
BASIC_GAL basic_gal(basic_displayOptions)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
#define CTL_OMIT_HIDE
Definition: eda_text.h:56
void SetBold(bool aBold)
Definition: eda_text.h:189
#define _HKI(x)
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:141
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:484
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103