KiCad PCB EDA Suite
eda_text.h
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) 2013 Jean-Pierre Charras, jpe.charras at wanadoo.fr
5  * Copyright (C) 2004-2019 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 
25 #ifndef EDA_TEXT_H_
26 #define EDA_TEXT_H_
27 
28 #include <trigo.h> // NORMALIZE_ANGLE_POS( angle );
29 #include <common.h> // wxStringSplit
30 #include <gr_basic.h> // EDA_DRAW_MODE_T
31 #include <base_struct.h> // EDA_RECT
32 #include "kicad_string.h"
33 
34 class SHAPE_POLY_SET;
35 
36 // part of the kicad_plugin.h family of defines.
37 // See kicad_plugin.h for the choice of the value
38 // When set when calling EDA_TEXT::Format, disable writing the "hide" keyword in save file
39 #define CTL_OMIT_HIDE (1 << 6)
40 
41 
42 // Graphic Text justify:
43 // Values -1,0,1 are used in computations, do not change them
48 };
49 
50 
55 };
56 
57 
58 /* Options to draw items with thickness ( segments, arcs, circles, texts...) */
60  FILLED = true, // normal mode: solid segments
61  SKETCH = false // sketch mode: draw segments outlines only
62 };
63 
64 
70 #define DEFAULT_SIZE_TEXT 50 // default text height (in mils, i.e. 1/1000")
71 #define DIM_ANCRE_TEXTE 2 // Anchor size for text
72 
73 
81 {
82  TEXT_EFFECTS( int aSetOfBits = 0 ) :
83  bits( aSetOfBits ),
86  penwidth( 0 ),
87  angle( 0.0 )
88  {}
89 
90  short bits;
91  signed char hjustify;
92  signed char vjustify;
93  wxSize size;
94  int penwidth;
95  double angle;
97 
98  void Bit( int aBit, bool aValue ) { aValue ? bits |= (1<<aBit) : bits &= ~(1<<aBit); }
99  bool Bit( int aBit ) const { return bits & (1<<aBit); }
100 };
101 
102 
109 class EDA_TEXT
110 {
111 public:
112  EDA_TEXT( const wxString& text = wxEmptyString );
113 
114  EDA_TEXT( const EDA_TEXT& aText );
115 
116  virtual ~EDA_TEXT();
117 
123  virtual const wxString& GetText() const { return m_text; }
124 
129  virtual wxString GetShownText() const { return m_shown_text; }
130 
134  wxString ShortenedShownText() const;
135 
136  virtual void SetText( const wxString& aText );
137 
143  void SetThickness( int aNewThickness ) { m_e.penwidth = aNewThickness; };
144 
148  int GetThickness() const { return m_e.penwidth; };
149 
150  void SetTextAngle( double aAngle )
151  {
152  // Higher level classes may be more restrictive than this by
153  // overloading SetTextAngle() (probably non-virtual) or merely
154  // calling EDA_TEXT::SetTextAngle() after clamping aAngle
155  // before calling this lowest inline accessor.
156  m_e.angle = aAngle;
157  }
158  double GetTextAngle() const { return m_e.angle; }
159 
160  double GetTextAngleDegrees() const { return GetTextAngle() / 10.0; }
161  double GetTextAngleRadians() const { return GetTextAngle() * M_PI/1800; }
162 
163  void SetItalic( bool isItalic ) { m_e.Bit( TE_ITALIC, isItalic ); }
164  bool IsItalic() const { return m_e.Bit( TE_ITALIC ); }
165 
166  void SetBold( bool aBold ) { m_e.Bit( TE_BOLD, aBold); }
167  bool IsBold() const { return m_e.Bit( TE_BOLD ); }
168 
169  void SetVisible( bool aVisible ) { m_e.Bit( TE_VISIBLE, aVisible ); }
170  bool IsVisible() const { return m_e.Bit( TE_VISIBLE ); }
171 
172  void SetMirrored( bool isMirrored ) { m_e.Bit( TE_MIRROR, isMirrored ); }
173  bool IsMirrored() const { return m_e.Bit( TE_MIRROR ); }
174 
180  void SetMultilineAllowed( bool aAllow ) { m_e.Bit( TE_MULTILINE, aAllow ); }
181  bool IsMultilineAllowed() const { return m_e.Bit( TE_MULTILINE ); }
182 
185 
186  void SetHorizJustify( EDA_TEXT_HJUSTIFY_T aType ) { m_e.hjustify = aType; };
187  void SetVertJustify( EDA_TEXT_VJUSTIFY_T aType ) { m_e.vjustify = aType; };
188 
195  void SetEffects( const EDA_TEXT& aSrc );
196 
203  void SwapEffects( EDA_TEXT& aTradingPartner );
204 
205  void SwapText( EDA_TEXT& aTradingPartner );
206 
207  void CopyText( const EDA_TEXT& aSrc );
208 
218  bool Replace( wxFindReplaceData& aSearchData );
219 
220  bool IsDefaultFormatting() const;
221 
222  void SetTextSize( const wxSize& aNewSize ) { m_e.size = aNewSize; };
223  const wxSize& GetTextSize() const { return m_e.size; };
224 
225  void SetTextWidth( int aWidth ) { m_e.size.x = aWidth; }
226  int GetTextWidth() const { return m_e.size.x; }
227 
228  void SetTextHeight( int aHeight ) { m_e.size.y = aHeight; }
229  int GetTextHeight() const { return m_e.size.y; }
230 
231  void SetTextPos( const wxPoint& aPoint ) { m_e.pos = aPoint; }
232  const wxPoint& GetTextPos() const { return m_e.pos; }
233 
234  void SetTextX( int aX ) { m_e.pos.x = aX; }
235  void SetTextY( int aY ) { m_e.pos.y = aY; }
236 
237  void Offset( const wxPoint& aOffset ) { m_e.pos += aOffset; }
238 
239  void Empty() { m_text.Empty(); }
240 
241  static EDA_TEXT_HJUSTIFY_T MapHorizJustify( int aHorizJustify );
242 
243  static EDA_TEXT_VJUSTIFY_T MapVertJustify( int aVertJustify );
244 
253  void Print( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor,
254  EDA_DRAW_MODE_T aDisplay_mode = FILLED );
255 
264  void TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuffer ) const;
265 
278  int aClearanceValue ) const;
279 
287  virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const;
288 
297  virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const;
298 
307  int LenSize( const wxString& aLine, int aThickness, int aMarkupFlags ) const;
308 
327  EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false,
328  int aMarkupFlags = 0 ) const;
329 
337  int GetInterline() const;
338 
342  wxString GetTextStyleName();
343 
354  std::vector<wxPoint>& aPositions, int aLineCount ) const;
363  virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
364 
365 private:
366  wxString m_text;
367  wxString m_shown_text; // Cache of unescaped text for efficient access
368 
369 private:
380  void printOneLineOfText( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor,
381  EDA_DRAW_MODE_T aFillMode, const wxString& aText,
382  const wxPoint& aPos );
383 
384  // Private text effects data. API above provides accessor funcs.
386 
388  enum TE_FLAGS {
389  // start at zero, sequence is irrelevant
395  };
396 };
397 
398 
399 #endif // EDA_TEXT_H_
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
EDA_TEXT(const wxString &text=wxEmptyString)
Definition: eda_text.cpp:86
bool IsBold() const
Definition: eda_text.h:167
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:237
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:178
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:138
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
bool Bit(int aBit) const
Definition: eda_text.h:99
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:184
bool IsMirrored() const
Definition: eda_text.h:173
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:118
wxString m_shown_text
Definition: eda_text.h:367
bool IsVisible() const
Definition: eda_text.h:170
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:125
void SetItalic(bool isItalic)
Definition: eda_text.h:163
TEXT_EFFECTS m_e
Definition: eda_text.h:385
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:231
void SetVisible(bool aVisible)
Definition: eda_text.h:169
double GetTextAngle() const
Definition: eda_text.h:158
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:327
int GetThickness() const
Return the pen width.
Definition: eda_text.h:148
signed char vjustify
vertical justification
Definition: eda_text.h:92
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
void TransformBoundingBoxWithClearanceToPolygon(SHAPE_POLY_SET *aCornerBuffer, int aClearanceValue) const
Convert the text bounding box to a rectangular polygon depending on the text orientation,...
wxPoint pos
Definition: eda_text.h:96
void printOneLineOfText(wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aFillMode, const wxString &aText, const wxPoint &aPos)
Print each line of this EDA_TEXT.
Definition: eda_text.cpp:426
wxSize size
Definition: eda_text.h:93
int GetTextHeight() const
Definition: eda_text.h:229
void SetTextX(int aX)
Definition: eda_text.h:234
bool IsItalic() const
Definition: eda_text.h:164
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:109
void Bit(int aBit, bool aValue)
Definition: eda_text.h:98
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:58
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
A container for text effects.
Definition: eda_text.h:80
SHAPE_POLY_SET.
EDA_DRAW_MODE_T
Definition: eda_text.h:59
EDA_RECT GetTextBox(int aLine=-1, int aThickness=-1, bool aInvertY=false, int aMarkupFlags=0) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:184
const wxSize & GetTextSize() const
Definition: eda_text.h:223
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:187
short bits
any set of booleans a client uses.
Definition: eda_text.h:90
TE_FLAGS
EDA_TEXT effects bools.
Definition: eda_text.h:388
void TransformTextShapeToSegmentList(std::vector< wxPoint > &aCornerBuffer) const
Convert the text shape to a list of segment.
Definition: eda_text.cpp:544
void Empty()
Definition: eda_text.h:239
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:163
virtual ~EDA_TEXT()
Definition: eda_text.cpp:106
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:480
bool IsDefaultFormatting() const
Definition: eda_text.cpp:466
wxString m_text
Definition: eda_text.h:366
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.h:180
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:72
bool IsMultilineAllowed() const
Definition: eda_text.h:181
void Print(wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:361
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
void SetTextWidth(int aWidth)
Definition: eda_text.h:225
double GetTextAngleRadians() const
Definition: eda_text.h:161
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:131
double GetTextAngleDegrees() const
Definition: eda_text.h:160
int GetTextWidth() const
Definition: eda_text.h:226
wxString GetTextStyleName()
Definition: eda_text.cpp:445
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:186
bool Replace(wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:144
int LenSize(const wxString &aLine, int aThickness, int aMarkupFlags) const
Definition: eda_text.cpp:150
TEXT_EFFECTS(int aSetOfBits=0)
Definition: eda_text.h:82
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:336
void SetTextHeight(int aHeight)
Definition: eda_text.h:228
The common library.
double angle
now: 0.1 degrees; future: degrees
Definition: eda_text.h:95
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
void GetPositionsOfLinesOfMultilineText(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:384
virtual wxString GetShownText() const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:129
signed char hjustify
horizontal justification
Definition: eda_text.h:91
void SetBold(bool aBold)
Definition: eda_text.h:166
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
void SetThickness(int aNewThickness)
Set the pen width.
Definition: eda_text.h:143
void SetTextY(int aY)
Definition: eda_text.h:235
int penwidth
Definition: eda_text.h:94
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40