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-2017 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 (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 (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  if( !text.IsEmpty() )
100  {
101  m_shown_text = UnescapeString( text );
102  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
103  }
104 }
105 
106 
107 EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) :
108  m_text( aText.m_text ),
109  m_e( aText.m_e )
110 {
112  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
113 }
114 
115 
117 {
118 }
119 
120 
121 void EDA_TEXT::SetText( const wxString& aText )
122 {
123  m_text = aText;
124  m_shown_text = UnescapeString( aText );
125  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
126 }
127 
128 
129 void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
130 {
131  m_text = aSrc.m_text;
132  m_shown_text = aSrc.m_shown_text;
134 }
135 
136 
137 void EDA_TEXT::SetEffects( const EDA_TEXT& aSrc )
138 {
139  m_e = aSrc.m_e;
140 }
141 
142 
143 void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
144 {
145  std::swap( m_text, aTradingPartner.m_text );
146  std::swap( m_shown_text, aTradingPartner.m_shown_text );
148 }
149 
150 
151 void EDA_TEXT::SwapEffects( EDA_TEXT& aTradingPartner )
152 {
153  std::swap( m_e, aTradingPartner.m_e );
154 }
155 
156 
157 int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultWidth ) const
158 {
159  int width = GetTextThickness();
160 
161  if( width <= 1 )
162  {
163  width = aDefaultWidth;
164 
165  if( IsBold() )
166  width = GetPenSizeForBold( GetTextWidth() );
167  else if( width <= 1 )
168  width = GetPenSizeForNormal( GetTextWidth() );
169  }
170 
171  // Clip pen size for small texts:
173 
174  return width;
175 }
176 
177 
178 bool EDA_TEXT::Replace( const wxFindReplaceData& aSearchData )
179 {
180  bool retval = EDA_ITEM::Replace( aSearchData, m_text );
182  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
183 
184  return retval;
185 }
186 
187 
188 int EDA_TEXT::LenSize( const wxString& aLine, int aThickness ) const
189 {
192  basic_gal.SetFontUnderlined( false );
193  basic_gal.SetLineWidth( (float) aThickness );
195 
196  VECTOR2D tsize = basic_gal.GetTextLineSize( aLine );
197 
198  return KiROUND( tsize.x );
199 }
200 
201 
203 {
204  wxString tmp = GetShownText();
205 
206  tmp.Replace( wxT( "\n" ), wxT( " " ) );
207  tmp.Replace( wxT( "\r" ), wxT( " " ) );
208  tmp.Replace( wxT( "\t" ), wxT( " " ) );
209 
210  if( tmp.Length() > 36 )
211  tmp = tmp.Left( 34 ) + wxT( "..." );
212 
213  return tmp;
214 }
215 
216 
218 {
220 }
221 
222 
223 EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
224 {
225  EDA_RECT rect;
226  wxArrayString strings;
227  wxString text = GetShownText();
228  int thickness = GetEffectiveTextPenWidth();
229  int linecount = 1;
230  bool hasOverBar = false; // true if the first line of text as an overbar
231 
232  if( IsMultilineAllowed() )
233  {
234  wxStringSplit( text, strings, '\n' );
235 
236  if( strings.GetCount() ) // GetCount() == 0 for void strings
237  {
238  if( aLine >= 0 && ( aLine < (int)strings.GetCount() ) )
239  text = strings.Item( aLine );
240  else
241  text = strings.Item( 0 );
242 
243  linecount = strings.GetCount();
244  }
245  }
246 
247  // Search for overbar symbol. Only text is scanned,
248  // because only this line can change the bounding box
249  for( unsigned ii = 1; ii < text.size(); ii++ )
250  {
251  if( text[ii-1] == '~' && text[ii] != '~' )
252  {
253  hasOverBar = true;
254  break;
255  }
256  }
257 
258  // calculate the H and V size
259  const auto& font = basic_gal.GetStrokeFont();
260  VECTOR2D fontSize( GetTextSize() );
261  double penWidth( thickness );
262  int dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
263  int dy = GetInterline();
264 
265  // Creates bounding box (rectangle) for horizontal, left and top justified text. The
266  // bounding box will be moved later according to the actual text options
267  wxSize textsize = wxSize( dx, dy );
268  wxPoint pos = GetTextPos();
269 
270  if( aInvertY )
271  pos.y = -pos.y;
272 
273  rect.SetOrigin( pos );
274 
275  // The bbox vertical size returned by GetInterline( aThickness )
276  // includes letters like j and y and ] + interval between lines.
277  // The interval below the last line is not usefull, and we can use its half value
278  // as vertical margin above the text
279  // the full interval is roughly GetTextHeight() * 0.4 - aThickness/2
280  rect.Move( wxPoint( 0, thickness/4 - KiROUND( GetTextHeight() * 0.22 ) ) );
281 
282  if( hasOverBar )
283  { // A overbar adds an extra size to the text
284  // Height from the base line text of chars like [ or {
285  double curr_height = GetTextHeight() * 1.15;
286  double overbarPosition = font.ComputeOverbarVerticalPosition( fontSize.y );
287  int extra_height = KiROUND( overbarPosition - curr_height );
288 
289  extra_height += thickness / 2;
290  textsize.y += extra_height;
291  rect.Move( wxPoint( 0, -extra_height ) );
292  }
293 
294  // for multiline texts and aLine < 0, merge all rectangles
295  // ( if aLine < 0, we want the full text bounding box )
296  if( IsMultilineAllowed() && aLine < 0 )
297  {
298  for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
299  {
300  text = strings.Item( ii );
301  dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
302  textsize.x = std::max( textsize.x, dx );
303  textsize.y += dy;
304  }
305  }
306 
307  rect.SetSize( textsize );
308 
309  /* Now, calculate the rect origin, according to text justification
310  * At this point the rectangle origin is the text origin (m_Pos).
311  * This is true only for left and top text justified texts (using top to bottom Y axis
312  * orientation). and must be recalculated for others justifications
313  * also, note the V justification is relative to the first line
314  */
315  switch( GetHorizJustify() )
316  {
318  if( IsMirrored() )
319  rect.SetX( rect.GetX() - rect.GetWidth() );
320  break;
321 
323  rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
324  break;
325 
327  if( !IsMirrored() )
328  rect.SetX( rect.GetX() - rect.GetWidth() );
329  break;
330  }
331 
332  dy = GetTextHeight() + thickness;
333 
334  switch( GetVertJustify() )
335  {
337  break;
338 
340  rect.SetY( rect.GetY() - ( dy / 2) );
341  break;
342 
344  rect.SetY( rect.GetY() - dy );
345  break;
346  }
347 
348  if( linecount > 1 )
349  {
350  int yoffset;
351  linecount -= 1;
352 
353  switch( GetVertJustify() )
354  {
356  break;
357 
359  yoffset = linecount * GetInterline() / 2;
360  rect.SetY( rect.GetY() - yoffset );
361  break;
362 
364  yoffset = linecount * GetInterline();
365  rect.SetY( rect.GetY() - yoffset );
366  break;
367  }
368  }
369 
370  rect.Normalize(); // Make h and v sizes always >= 0
371 
372  return rect;
373 }
374 
375 
376 bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
377 {
378  EDA_RECT rect = GetTextBox();
379  wxPoint location = aPoint;
380 
381  rect.Inflate( aAccuracy );
382  RotatePoint( &location, GetTextPos(), -GetTextAngle() );
383 
384  return rect.Contains( location );
385 }
386 
387 
388 bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
389 {
390  EDA_RECT rect = aRect;
391 
392  rect.Inflate( aAccuracy );
393 
394  if( aContains )
395  return rect.Contains( GetTextBox() );
396 
397  return rect.Intersects( GetTextBox(), GetTextAngle() );
398 }
399 
400 
401 void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
402  COLOR4D aColor, OUTLINE_MODE aFillMode )
403 {
404  if( IsMultilineAllowed() )
405  {
406  std::vector<wxPoint> positions;
407  wxArrayString strings;
408  wxStringSplit( GetShownText(), strings, '\n' );
409 
410  positions.reserve( strings.Count() );
411 
412  GetLinePositions( positions, strings.Count() );
413 
414  for( unsigned ii = 0; ii < strings.Count(); ii++ )
415  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
416  }
417  else
418  {
419  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText(), GetTextPos() );
420  }
421 }
422 
423 
424 void EDA_TEXT::GetLinePositions( std::vector<wxPoint>& aPositions, int aLineCount ) const
425 {
426  wxPoint pos = GetTextPos(); // Position of first line of the
427  // multiline text according to
428  // the center of the multiline text block
429 
430  wxPoint offset; // Offset to next line.
431 
432  offset.y = GetInterline();
433 
434  if( aLineCount > 1 )
435  {
436  switch( GetVertJustify() )
437  {
439  break;
440 
442  pos.y -= ( aLineCount - 1 ) * offset.y / 2;
443  break;
444 
446  pos.y -= ( aLineCount - 1 ) * offset.y;
447  break;
448  }
449  }
450 
451  // Rotate the position of the first line
452  // around the center of the multiline text block
453  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
454 
455  // Rotate the offset lines to increase happened in the right direction
456  RotatePoint( &offset, GetTextAngle() );
457 
458  for( int ii = 0; ii < aLineCount; ii++ )
459  {
460  aPositions.push_back( pos );
461  pos += offset;
462  }
463 }
464 
465 void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
466  COLOR4D aColor, OUTLINE_MODE aFillMode,
467  const wxString& aText, const wxPoint &aPos )
468 {
469  wxDC* DC = aSettings->GetPrintDC();
470  int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() );
471 
472  if( aFillMode == SKETCH )
473  penWidth = -penWidth;
474 
475  wxSize size = GetTextSize();
476 
477  if( IsMirrored() )
478  size.x = -size.x;
479 
480  GRText( DC, aOffset + aPos, aColor, aText, GetTextAngle(), size, GetHorizJustify(),
481  GetVertJustify(), penWidth, IsItalic(), IsBold() );
482 }
483 
484 
486 {
487  int style = 0;
488 
489  if( IsItalic() )
490  style = 1;
491 
492  if( IsBold() )
493  style += 2;
494 
495  wxString stylemsg[4] = {
496  _("Normal"),
497  _("Italic"),
498  _("Bold"),
499  _("Bold+Italic")
500  };
501 
502  return stylemsg[style];
503 }
504 
505 
507 {
508  return ( IsVisible()
509  && !IsMirrored()
512  && GetTextThickness() == 0
513  && !IsItalic()
514  && !IsBold()
515  && !IsMultilineAllowed()
516  );
517 }
518 
519 
520 void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
521 {
522 #ifndef GERBVIEW // Gerbview does not use EDA_TEXT::Format
523  // and does not define FormatInternalUnits, used here
524  // however this function should exist
525 
526  aFormatter->Print( aNestLevel + 1, "(effects" );
527 
528  // Text size
529  aFormatter->Print( 0, " (font" );
530 
531  aFormatter->Print( 0, " (size %s %s)",
532  FormatInternalUnits( GetTextHeight() ).c_str(),
533  FormatInternalUnits( GetTextWidth() ).c_str() );
534 
535  if( GetTextThickness() )
536  aFormatter->Print( 0, " (thickness %s)", FormatInternalUnits( GetTextThickness() ).c_str() );
537 
538  if( IsBold() )
539  aFormatter->Print( 0, " bold" );
540 
541  if( IsItalic() )
542  aFormatter->Print( 0, " italic" );
543 
544  aFormatter->Print( 0, ")"); // (font
545 
546  if( IsMirrored() ||
549  {
550  aFormatter->Print( 0, " (justify");
551 
553  aFormatter->Print( 0, (GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT) ? " left" : " right" );
554 
556  aFormatter->Print( 0, (GetVertJustify() == GR_TEXT_VJUSTIFY_TOP) ? " top" : " bottom" );
557 
558  if( IsMirrored() )
559  aFormatter->Print( 0, " mirror" );
560  aFormatter->Print( 0, ")" ); // (justify
561  }
562 
563  if( !(aControlBits & CTL_OMIT_HIDE) && !IsVisible() )
564  aFormatter->Print( 0, " hide" );
565 
566  aFormatter->Print( 0, ")\n" ); // (justify
567 
568 #endif
569 }
570 
571 // Convert the text shape to a list of segment
572 // each segment is stored as 2 wxPoints: its starting point and its ending point
573 // we are using GRText to create the segments and therefore a call-back function is needed
574 
575 // This is a call back function, used by GRText to put each segment in buffer
576 static void addTextSegmToBuffer( int x0, int y0, int xf, int yf, void* aData )
577 {
578  std::vector<wxPoint>* cornerBuffer = static_cast<std::vector<wxPoint>*>( aData );
579  cornerBuffer->push_back( wxPoint( x0, y0 ) );
580  cornerBuffer->push_back( wxPoint( xf, yf ) );
581 }
582 
583 
584 std::vector<wxPoint> EDA_TEXT::TransformToSegmentList() const
585 {
586  std::vector<wxPoint> cornerBuffer;
587  wxSize size = GetTextSize();
588 
589  if( IsMirrored() )
590  size.x = -size.x;
591 
592  bool forceBold = true;
593  int penWidth = 0; // use max-width for bold text
594 
595  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
596 
597  if( IsMultilineAllowed() )
598  {
599  wxArrayString strings_list;
600  wxStringSplit( GetShownText(), strings_list, wxChar('\n') );
601  std::vector<wxPoint> positions;
602  positions.reserve( strings_list.Count() );
603  GetLinePositions( positions, strings_list.Count() );
604 
605  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
606  {
607  wxString txt = strings_list.Item( ii );
608  GRText( NULL, positions[ii], color, txt, GetDrawRotation(), size, GetHorizJustify(),
609  GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
610  &cornerBuffer );
611  }
612  }
613  else
614  {
616  GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), forceBold,
617  addTextSegmToBuffer, &cornerBuffer );
618  }
619 
620  return cornerBuffer;
621 }
622 
623 
624 std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( ) const
625 {
626  std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
627  int penWidth = GetEffectiveTextPenWidth();
628  std::vector<wxPoint> pts = TransformToSegmentList();
629 
630  for( unsigned jj = 0; jj < pts.size(); jj += 2 )
631  shape->AddShape( new SHAPE_SEGMENT( pts[jj], pts[jj+1], penWidth ) );
632 
633  return shape;
634 }
635 
636 
638 {
639  return GetTextAngle();
640 }
641 
642 
643 static struct EDA_TEXT_DESC
644 {
646  {
648  .Map( GR_TEXT_HJUSTIFY_LEFT, _HKI( "Left" ) )
649  .Map( GR_TEXT_HJUSTIFY_CENTER, _HKI( "Center" ) )
650  .Map( GR_TEXT_HJUSTIFY_RIGHT, _HKI( "Right" ) );
652  .Map( GR_TEXT_VJUSTIFY_TOP, _HKI( "Top" ) )
653  .Map( GR_TEXT_VJUSTIFY_CENTER, _HKI( "Center" ) )
654  .Map( GR_TEXT_VJUSTIFY_BOTTOM, _HKI( "Bottom" ) );
655 
658  propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
660  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
662  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
664  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
666  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
668  propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
670  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
672  propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
674  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, EDA_TEXT_HJUSTIFY_T>( _HKI( "Horizontal Justification" ),
676  propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, EDA_TEXT_VJUSTIFY_T>( _HKI( "Vertical Justification" ),
678  }
680 
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:217
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:66
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:151
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)
Function GetPensizeForBold.
Definition: gr_text.cpp:48
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:129
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:103
wxString m_shown_text
Definition: eda_text.h:390
std::vector< wxPoint > TransformToSegmentList() const
Convert the text shape to a list of segment.
Definition: eda_text.cpp:584
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:137
bool Replace(const wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:178
void SetItalic(bool isItalic)
Definition: eda_text.h:186
TEXT_EFFECTS m_e
Definition: eda_text.h:393
int color
Definition: DXF_plotter.cpp:60
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:223
void SetVisible(bool aVisible)
Definition: eda_text.h:192
int GetWidth() const
Definition: eda_rect.h:114
static void addTextSegmToBuffer(int x0, int y0, int xf, int yf, void *aData)
Definition: eda_text.cpp:576
static ENUM_MAP< T > & Instance()
Definition: property.h:508
double GetTextAngle() const
Definition: eda_text.h:181
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:391
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:126
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:637
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:249
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:157
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
void SetFontBold(const bool aBold)
Set bold property of current font.
wxString GetTextStyleName() const
Definition: eda_text.cpp:485
int LenSize(const wxString &aLine, int aThickness) const
Definition: eda_text.cpp:188
Display value expressed in distance units (mm/inch)
Definition: property.h:51
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize Don't allow text to become cluttered up in its own fatness.
Definition: gr_text.cpp:69
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:121
#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:54
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:202
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:596
void SetX(int val)
Definition: eda_rect.h:163
virtual ~EDA_TEXT()
Definition: eda_text.cpp:116
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:520
#define ALLOW_BOLD_THICKNESS
Definition: base_units.h:57
bool IsDefaultFormatting() const
Definition: eda_text.cpp:506
wxString m_text
Definition: eda_text.h:389
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:159
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 SetY(int val)
Definition: eda_rect.h:169
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: string.cpp:807
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)
Function GRText Draw a graphic text (like footprint texts)
Definition: gr_text.cpp:131
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 printOneLineOfText(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, COLOR4D aColor, OUTLINE_MODE aFillMode, const wxString &aText, const wxPoint &aPos)
Print each line of this EDA_TEXT.
Definition: eda_text.cpp:465
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
void SetSize(const wxSize &size)
Definition: eda_rect.h:139
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:143
void SetGlyphSize(const VECTOR2D aSize)
Set the font glyph size.
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:401
int GetTextWidth() const
Definition: eda_text.h:248
void SetFontUnderlined(bool aUnderlined)
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape() const
Definition: eda_text.cpp:624
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:150
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:376
void SetTextHeight(int aHeight)
Definition: eda_text.h:250
int GetY() const
Definition: eda_rect.h:104
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:68
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:424
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:63
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:533
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98