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