KiCad PCB EDA Suite
EDA_TEXT Class Reference

A mix-in class (via multiple inheritance) that handles texts such as labels, parts, components, or footprints. More...

#include <eda_text.h>

Inheritance diagram for EDA_TEXT:
LIB_FIELD LIB_TEXT SCH_FIELD SCH_TEXT TEXTE_MODULE TEXTE_PCB WS_DRAW_ITEM_TEXT SCH_GLOBALLABEL SCH_HIERLABEL SCH_LABEL SCH_SHEET_PIN

Public Member Functions

 EDA_TEXT (const wxString &text=wxEmptyString)
 
 EDA_TEXT (const EDA_TEXT &aText)
 
virtual ~EDA_TEXT ()
 
virtual const wxString & GetText () const
 Return the string associated with the text object. More...
 
virtual wxString GetShownText (int aDepth=0) const
 Return the string actually shown after processing of the base text. More...
 
wxString GetShownText (bool *processTextVars) const
 A version of GetShownText() which also indicates whether or not the text needs to be processed for text variables. More...
 
wxString ShortenedShownText () const
 Returns a shortened version (max 15 characters) of the shown text. More...
 
virtual void SetText (const wxString &aText)
 
void SetTextThickness (int aWidth)
 The TextThickness is that set by the user. More...
 
int GetTextThickness () const
 
int GetEffectiveTextPenWidth (int aDefaultWidth=0) const
 The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth. More...
 
virtual void SetTextAngle (double aAngle)
 
double GetTextAngle () const
 
double GetTextAngleDegrees () const
 
double GetTextAngleRadians () const
 
void SetItalic (bool isItalic)
 
bool IsItalic () const
 
void SetBold (bool aBold)
 
bool IsBold () const
 
void SetVisible (bool aVisible)
 
bool IsVisible () const
 
void SetMirrored (bool isMirrored)
 
bool IsMirrored () const
 
void SetMultilineAllowed (bool aAllow)
 
bool IsMultilineAllowed () const
 
EDA_TEXT_HJUSTIFY_T GetHorizJustify () const
 
EDA_TEXT_VJUSTIFY_T GetVertJustify () const
 
void SetHorizJustify (EDA_TEXT_HJUSTIFY_T aType)
 
void SetVertJustify (EDA_TEXT_VJUSTIFY_T aType)
 
void SetEffects (const EDA_TEXT &aSrc)
 Set the text effects from another instance. More...
 
void SwapEffects (EDA_TEXT &aTradingPartner)
 Swap the text effects of the two involved instances. More...
 
void SwapText (EDA_TEXT &aTradingPartner)
 
void CopyText (const EDA_TEXT &aSrc)
 
bool Replace (wxFindReplaceData &aSearchData)
 Helper function used in search and replace dialog. More...
 
bool IsDefaultFormatting () const
 
void SetTextSize (const wxSize &aNewSize)
 
const wxSize & GetTextSize () const
 
void SetTextWidth (int aWidth)
 
int GetTextWidth () const
 
void SetTextHeight (int aHeight)
 
int GetTextHeight () const
 
void SetTextPos (const wxPoint &aPoint)
 
const wxPointGetTextPos () const
 
void SetTextX (int aX)
 
void SetTextY (int aY)
 
void Offset (const wxPoint &aOffset)
 
void Empty ()
 
void Print (RENDER_SETTINGS *aSettings, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aDisplay_mode=FILLED)
 Print this text object to the device context aDC. More...
 
void TransformTextShapeToSegmentList (std::vector< wxPoint > &aCornerBuffer) const
 Convert the text shape to a list of segment. More...
 
void TransformBoundingBoxWithClearanceToPolygon (SHAPE_POLY_SET *aCornerBuffer, int aClearanceValue) const
 Convert the text bounding box to a rectangular polygon depending on the text orientation, the bounding box is not always horizontal or vertical. More...
 
virtual bool TextHitTest (const wxPoint &aPoint, int aAccuracy=0) const
 Test if aPoint is within the bounds of this object. More...
 
virtual bool TextHitTest (const EDA_RECT &aRect, bool aContains, int aAccuracy=0) const
 Test if object bounding box is contained within or intersects aRect. More...
 
int LenSize (const wxString &aLine, int aThickness) const
 
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, locate functions....) More...
 
int GetInterline () const
 Return the distance between two lines of text. More...
 
wxString GetTextStyleName ()
 
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 justification and the rotation of the whole text. More...
 
virtual void Format (OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
 Output the object to aFormatter in s-expression form. More...
 

Static Public Member Functions

static EDA_TEXT_HJUSTIFY_T MapHorizJustify (int aHorizJustify)
 
static EDA_TEXT_VJUSTIFY_T MapVertJustify (int aVertJustify)
 

Private Types

enum  TE_FLAGS {
  TE_MIRROR, TE_ITALIC, TE_BOLD, TE_MULTILINE,
  TE_VISIBLE
}
 

Private Member Functions

void printOneLineOfText (RENDER_SETTINGS *aSettings, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aFillMode, const wxString &aText, const wxPoint &aPos)
 Print each line of this EDA_TEXT. More...
 

Private Attributes

wxString m_text
 
wxString m_shown_text
 
bool m_shown_text_has_text_var_refs
 
TEXT_EFFECTS m_e
 

Detailed Description

A mix-in class (via multiple inheritance) that handles texts such as labels, parts, components, or footprints.

Because it's a mix-in class, care is used to provide function names (accessors) that to not collide with function names likely to be seen in the combined derived classes.

Definition at line 112 of file eda_text.h.

Member Enumeration Documentation

◆ TE_FLAGS

enum EDA_TEXT::TE_FLAGS
private
Enumerator
TE_MIRROR 
TE_ITALIC 
TE_BOLD 
TE_MULTILINE 
TE_VISIBLE 

Definition at line 374 of file eda_text.h.

Constructor & Destructor Documentation

◆ EDA_TEXT() [1/2]

EDA_TEXT::EDA_TEXT ( const wxString &  text = wxEmptyString)

Definition at line 86 of file eda_text.cpp.

86  :
87  m_text( text ),
88  m_e( 1<<TE_VISIBLE )
89 {
90  int sz = Mils2iu( DEFAULT_SIZE_TEXT );
91  SetTextSize( wxSize( sz, sz ) );
93 
94  if( !text.IsEmpty() )
95  {
96  m_shown_text = UnescapeString( text );
97  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
98  }
99 }
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:73
wxString m_shown_text
Definition: eda_text.h:369
TEXT_EFFECTS m_e
Definition: eda_text.h:372
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:370
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
wxString m_text
Definition: eda_text.h:368
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131

References DEFAULT_SIZE_TEXT, m_shown_text, m_shown_text_has_text_var_refs, SetTextSize(), and UnescapeString().

◆ EDA_TEXT() [2/2]

EDA_TEXT::EDA_TEXT ( const EDA_TEXT aText)

Definition at line 102 of file eda_text.cpp.

102  :
103  m_text( aText.m_text ),
104  m_e( aText.m_e )
105 {
107  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
108 }
wxString m_shown_text
Definition: eda_text.h:369
TEXT_EFFECTS m_e
Definition: eda_text.h:372
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:370
wxString m_text
Definition: eda_text.h:368
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131

References m_shown_text, m_shown_text_has_text_var_refs, m_text, and UnescapeString().

◆ ~EDA_TEXT()

EDA_TEXT::~EDA_TEXT ( )
virtual

Definition at line 111 of file eda_text.cpp.

112 {
113 }

Member Function Documentation

◆ CopyText()

void EDA_TEXT::CopyText ( const EDA_TEXT aSrc)

Definition at line 124 of file eda_text.cpp.

125 {
126  m_text = aSrc.m_text;
127  m_shown_text = aSrc.m_shown_text;
129 }
wxString m_shown_text
Definition: eda_text.h:369
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:370
wxString m_text
Definition: eda_text.h:368

References m_shown_text, m_shown_text_has_text_var_refs, and m_text.

Referenced by LIB_FIELD::Copy().

◆ Empty()

void EDA_TEXT::Empty ( )
inline

Definition at line 254 of file eda_text.h.

254 { m_text.Empty(); }
wxString m_text
Definition: eda_text.h:368

References m_text.

Referenced by SCH_LEGACY_PLUGIN_CACHE::LoadPart().

◆ Format()

void EDA_TEXT::Format ( OUTPUTFORMATTER aFormatter,
int  aNestLevel,
int  aControlBits 
) const
virtual

Output the object to aFormatter in s-expression form.

Parameters
aFormatterThe OUTPUTFORMATTER object to write to.
aNestLevelThe indentation next level.
aControlBitsThe control bit definition for object specific formatting.
Exceptions
IO_ERRORon write error.

Definition at line 514 of file eda_text.cpp.

515 {
516 #ifndef GERBVIEW // Gerbview does not use EDA_TEXT::Format
517  // and does not define FormatInternalUnits, used here
518  // however this function should exist
519 
520  aFormatter->Print( aNestLevel + 1, "(effects" );
521 
522  // Text size
523  aFormatter->Print( 0, " (font" );
524 
525  aFormatter->Print( 0, " (size %s %s)",
526  FormatInternalUnits( GetTextHeight() ).c_str(),
527  FormatInternalUnits( GetTextWidth() ).c_str() );
528 
529  if( GetTextThickness() )
530  aFormatter->Print( 0, " (thickness %s)", FormatInternalUnits( GetTextThickness() ).c_str() );
531 
532  if( IsBold() )
533  aFormatter->Print( 0, " bold" );
534 
535  if( IsItalic() )
536  aFormatter->Print( 0, " italic" );
537 
538  aFormatter->Print( 0, ")"); // (font
539 
540  if( IsMirrored() ||
543  {
544  aFormatter->Print( 0, " (justify");
545 
547  aFormatter->Print( 0, (GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT) ? " left" : " right" );
548 
550  aFormatter->Print( 0, (GetVertJustify() == GR_TEXT_VJUSTIFY_TOP) ? " top" : " bottom" );
551 
552  if( IsMirrored() )
553  aFormatter->Print( 0, " mirror" );
554  aFormatter->Print( 0, ")" ); // (justify
555  }
556 
557  if( !(aControlBits & CTL_OMIT_HIDE) && !IsVisible() )
558  aFormatter->Print( 0, " hide" );
559 
560  aFormatter->Print( 0, ")\n" ); // (justify
561 
562 #endif
563 }
bool IsBold() const
Definition: eda_text.h:182
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsMirrored() const
Definition: eda_text.h:188
bool IsVisible() const
Definition: eda_text.h:185
int GetTextThickness() const
Definition: eda_text.h:158
int GetTextHeight() const
Definition: eda_text.h:244
bool IsItalic() const
Definition: eda_text.h:179
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
int GetTextWidth() const
Definition: eda_text.h:241
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
#define CTL_OMIT_HIDE
Definition: eda_text.h:42
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560

References CTL_OMIT_HIDE, FormatInternalUnits(), GetHorizJustify(), GetTextHeight(), GetTextThickness(), GetTextWidth(), GetVertJustify(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, IsBold(), IsItalic(), IsMirrored(), IsVisible(), and OUTPUTFORMATTER::Print().

Referenced by SCH_SEXPR_PLUGIN::saveField(), SCH_SEXPR_PLUGIN_CACHE::saveField(), SCH_SEXPR_PLUGIN::saveText(), and SCH_SEXPR_PLUGIN_CACHE::saveText().

◆ GetEffectiveTextPenWidth()

int EDA_TEXT::GetEffectiveTextPenWidth ( int  aDefaultWidth = 0) const

The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.

Definition at line 152 of file eda_text.cpp.

153 {
154  int width = GetTextThickness();
155 
156  if( width <= 1 )
157  {
158  width = aDefaultWidth;
159 
160  if( IsBold() )
161  width = GetPenSizeForBold( GetTextWidth() );
162  else if( width <= 1 )
163  width = GetPenSizeForNormal( GetTextWidth() );
164  }
165 
166  // Clip pen size for small texts:
168 
169  return width;
170 }
bool IsBold() const
Definition: eda_text.h:182
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
Definition: gr_text.cpp:51
int GetTextThickness() const
Definition: eda_text.h:158
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:72
const wxSize & GetTextSize() const
Definition: eda_text.h:238
int GetPenSizeForNormal(int aTextSize)
Function GetPensizeForNormal.
Definition: gr_text.cpp:57
int GetTextWidth() const
Definition: eda_text.h:241
#define ALLOW_BOLD_THICKNESS

References ALLOW_BOLD_THICKNESS, Clamp_Text_PenSize(), GetPenSizeForBold(), GetPenSizeForNormal(), GetTextSize(), GetTextThickness(), GetTextWidth(), and IsBold().

Referenced by BOARD_ADAPTER::AddShapeWithClearanceToContainer(), DIMENSION::AdjustDimensionDetails(), KIGFX::WS_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), export_vrml_pcbtext(), export_vrml_text_module(), SCH_GLOBALLABEL::GetBoundingBox(), SCH_HIERLABEL::GetBoundingBox(), LIB_TEXT::GetPenWidth(), LIB_FIELD::GetPenWidth(), SCH_FIELD::GetPenWidth(), SCH_TEXT::GetPenWidth(), GetTextBox(), KIGFX::SCH_PAINTER::getTextThickness(), LIB_TEXT::Plot(), SCH_FIELD::Plot(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotFootprintTextItem(), BRDITEMS_PLOTTER::PlotTextePcb(), PlotWorkSheet(), LIB_TEXT::print(), SCH_FIELD::Print(), printOneLineOfText(), PNS_KICAD_IFACE_BASE::syncTextItem(), test::DRC_TEST_PROVIDER_COPPER_CLEARANCE::testCopperDrawItem(), DRC::testCopperDrawItem(), and TEXTE_PCB::TransformShapeWithClearanceToPolygonSet().

◆ GetHorizJustify()

EDA_TEXT_HJUSTIFY_T EDA_TEXT::GetHorizJustify ( ) const
inline

Definition at line 198 of file eda_text.h.

198 { return EDA_TEXT_HJUSTIFY_T( m_e.hjustify ); };
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
TEXT_EFFECTS m_e
Definition: eda_text.h:372
signed char hjustify
horizontal justification
Definition: eda_text.h:94

References TEXT_EFFECTS::hjustify, and m_e.

Referenced by BOARD_ADAPTER::AddShapeWithClearanceToContainer(), DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD(), KIGFX::SCH_PAINTER::draw(), EDA_TEXT_DESC::EDA_TEXT_DESC(), export_vrml_pcbtext(), export_vrml_text_module(), AUTOPLACER::field_horiz_placement(), TEXTE_PCB::Flip(), TEXTE_MODULE::Flip(), Format(), GetTextBox(), hash_eda(), IsDefaultFormatting(), SCH_FIELD::IsHorizJustifyFlipped(), TEXTE_MODULE::KeepUpright(), SCH_EAGLE_PLUGIN::loadFieldAttributes(), LEGACY_PLUGIN::loadPCB_TEXT(), SCH_EDIT_TOOL::Mirror(), LIB_TEXT::MirrorHorizontal(), LIB_TEXT::MirrorVertical(), LIB_TEXT::NormalizeJustification(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotFootprintTextItem(), BRDITEMS_PLOTTER::PlotTextePcb(), PlotWorkSheet(), positioningChanged(), LIB_FIELD::print(), printOneLineOfText(), LIB_TEXT::Rotate(), SCH_LEGACY_PLUGIN::saveField(), SCH_LEGACY_PLUGIN_CACHE::saveField(), SCH_LEGACY_PLUGIN_CACHE::saveText(), KIGFX::GAL::SetTextAttributes(), DIALOG_LIB_EDIT_TEXT::TransferDataToWindow(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(), TransformTextShapeToSegmentList(), DIALOG_SCH_EDIT_ONE_FIELD::UpdateField(), and DIALOG_UPDATE_FIELDS::updateFields().

◆ GetInterline()

int EDA_TEXT::GetInterline ( ) const

Return the distance between two lines of text.

Calculates the distance (pitch) between two lines of text. This distance includes the interline distance plus room for characters like j, {, and [. It also used for single line text, to calculate the text bounding box.

Definition at line 211 of file eda_text.cpp.

212 {
214 }
static double GetInterline(double aGlyphHeight)
Compute the distance (interline) between 2 lines of text (for multiline texts).
int GetTextHeight() const
Definition: eda_text.h:244
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

References KIGFX::STROKE_FONT::GetInterline(), GetTextHeight(), and KiROUND().

Referenced by GetLinePositions(), and GetTextBox().

◆ GetLinePositions()

void EDA_TEXT::GetLinePositions ( std::vector< wxPoint > &  aPositions,
int  aLineCount 
) const

Populate aPositions with the position of each line of a multiline text, according to the vertical justification and the rotation of the whole text.

Parameters
aPositionsis the list to populate by the wxPoint positions
aLineCountis the number of lines (not recalculated here for efficiency reasons

Definition at line 418 of file eda_text.cpp.

419 {
420  wxPoint pos = GetTextPos(); // Position of first line of the
421  // multiline text according to
422  // the center of the multiline text block
423 
424  wxPoint offset; // Offset to next line.
425 
426  offset.y = GetInterline();
427 
428  if( aLineCount > 1 )
429  {
430  switch( GetVertJustify() )
431  {
433  break;
434 
436  pos.y -= ( aLineCount - 1 ) * offset.y / 2;
437  break;
438 
440  pos.y -= ( aLineCount - 1 ) * offset.y;
441  break;
442  }
443  }
444 
445  // Rotate the position of the first line
446  // around the center of the multiline text block
447  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
448 
449  // Rotate the offset lines to increase happened in the right direction
450  RotatePoint( &offset, GetTextAngle() );
451 
452  for( int ii = 0; ii < aLineCount; ii++ )
453  {
454  aPositions.push_back( pos );
455  pos += offset;
456  }
457 }
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:211
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
double GetTextAngle() const
Definition: eda_text.h:173
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
const wxPoint & GetTextPos() const
Definition: eda_text.h:247

References GetInterline(), GetTextAngle(), GetTextPos(), GetVertJustify(), GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, RotatePoint(), and wxPoint::y.

Referenced by BOARD_ADAPTER::AddShapeWithClearanceToContainer(), export_vrml_pcbtext(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotTextePcb(), Print(), TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(), and TransformTextShapeToSegmentList().

◆ GetShownText() [1/2]

virtual wxString EDA_TEXT::GetShownText ( int  aDepth = 0) const
inlinevirtual

Return the string actually shown after processing of the base text.

@aParam aDepth is used to prevent infinite recusions and loops when expanding text variables.

Reimplemented in TEXTE_MODULE, SCH_TEXT, SCH_FIELD, and TEXTE_PCB.

Definition at line 133 of file eda_text.h.

133 { return m_shown_text; }
wxString m_shown_text
Definition: eda_text.h:369

References m_shown_text.

Referenced by KIGFX::WS_PAINTER::draw(), LIB_FIELD::GetMsgPanelInfo(), WS_DRAW_ITEM_TEXT::GetSelectMenuText(), TEXTE_PCB::GetShownText(), SCH_FIELD::GetShownText(), SCH_TEXT::GetShownText(), TEXTE_MODULE::GetShownText(), GetTextBox(), LIB_FIELD::Plot(), LIB_PART::PlotLibFields(), PlotWorkSheet(), LIB_TEXT::print(), Print(), ShortenedShownText(), and TransformTextShapeToSegmentList().

◆ GetShownText() [2/2]

wxString EDA_TEXT::GetShownText ( bool *  processTextVars) const
inline

A version of GetShownText() which also indicates whether or not the text needs to be processed for text variables.

Parameters
processTextVars[out]

Definition at line 140 of file eda_text.h.

141  {
142  *processTextVars = m_shown_text_has_text_var_refs;
143  return m_shown_text;
144  }
wxString m_shown_text
Definition: eda_text.h:369
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:370

References m_shown_text, and m_shown_text_has_text_var_refs.

◆ GetText()

virtual const wxString& EDA_TEXT::GetText ( ) const
inlinevirtual

Return the string associated with the text object.

Returns
a const wxString reference containing the string of the item.

Definition at line 126 of file eda_text.h.

126 { return m_text; }
wxString m_text
Definition: eda_text.h:368

References m_text.

Referenced by NETLIST_EXPORTER_GENERIC::addComponentFields(), SCH_EAGLE_PLUGIN::addImplicitConnections(), SIM_PLOT_FRAME::AddTuner(), BACK_ANNOTATE::applyChangelist(), SCH_EDITOR_CONTROL::BackAnnotateFootprints(), CONNECTION_GRAPH::buildConnectionGraph(), SCH_EDIT_TOOL::ChangeTextType(), BACK_ANNOTATE::checkSharedSchematicErrors(), LIB_TEXT::Clone(), LIB_TEXT::compare(), LIB_FIELD::compare(), SCH_REFERENCE::CompareValue(), SCH_SHEET::ComponentCount(), CreateComponentsSection(), SCH_DRAWING_TOOLS::createNewText(), SCH_EDIT_FRAME::CreateSheetPin(), DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD(), LIB_EDIT_FRAME::DisplayCmpDoc(), KIGFX::SCH_VIEW::DisplayComponent(), KIGFX::SCH_PAINTER::draw(), SCH_EDIT_TOOL::Duplicate(), EDA_TEXT_DESC::EDA_TEXT_DESC(), LIB_PART::Flatten(), PCB_IO::format(), FormatProbeItem(), LIB_FIELD::GetFullText(), FOOTPRINT_INFO_GENERATOR::GetHtmlFieldRow(), TEXTE_MODULE::GetLength(), getMatchingTextItem(), SCH_TEXT::GetNetListItem(), SCH_COMPONENT::GetRef(), LIB_PART::GetSearchText(), NETLIST_EXPORTER_PSPICE::GetSpiceField(), NETLIST_EXPORTER_PSPICE::GetSpiceFieldDefVal(), DIMENSION::GetText(), TEXT_MOD_GRID_TABLE::GetValue(), hash_eda(), LIB_FIELD::HitTest(), SCH_TEXT::IncrementLabel(), GENERAL_COLLECTOR::Inspect(), SCH_SCREEN::IsTerminalPoint(), SCH_FIELD::IsVoid(), LEGACY_PLUGIN::loadPCB_TEXT(), SCH_EAGLE_PLUGIN::loadSchematic(), SCH_EAGLE_PLUGIN::loadSegments(), SCH_SHEET_PIN::Matches(), SCH_TEXT::Matches(), SCH_FIELD::operator<(), SCH_TEXT::operator<(), LIB_FIELD::operator=(), SCH_COMPONENT::operator==(), PCB_PARSER::parseDIMENSION(), SCH_SEXPR_PARSER::parseSchematicSymbol(), SCH_EDITOR_CONTROL::Paste(), pasteModuleItemsToModEdit(), DRAWING_TOOL::PlaceText(), LIB_TEXT::Plot(), LIB_FIELD::Plot(), BRDITEMS_PLOTTER::PlotFootprintTextItems(), DIALOG_RESCUE_EACH::PopulateInstanceList(), LIB_FIELD::print(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), processTextItem(), SCH_COMPONENT::ResolveTextVar(), SCH_LEGACY_PLUGIN::saveComponent(), SCH_SEXPR_PLUGIN::saveField(), SCH_LEGACY_PLUGIN::saveField(), SCH_SEXPR_PLUGIN_CACHE::saveField(), SCH_LEGACY_PLUGIN_CACHE::saveField(), SCH_LEGACY_PLUGIN::saveSheet(), SCH_LEGACY_PLUGIN_CACHE::SaveSymbol(), SCH_SEXPR_PLUGIN::saveText(), SCH_LEGACY_PLUGIN::saveText(), SCH_SEXPR_PLUGIN_CACHE::saveText(), SCH_LEGACY_PLUGIN_CACHE::saveText(), SCH_REFERENCE::SCH_REFERENCE(), SCH_SCREEN::SetComponentFootprint(), SCH_COMPONENT::SetRef(), EE_INSPECTION_TOOL::ShowDatasheet(), LIB_VIEW_FRAME::SyncToolbars(), ERC_TESTER::TestMultiunitFootprints(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow(), DIALOG_EDIT_COMPONENTS_LIBID::TransferDataFromWindow(), DIALOG_EDIT_SHEET_PIN::TransferDataToWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataToWindow(), DIALOG_SCH_SHEET_PROPS::TransferDataToWindow(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_LABEL_EDITOR::TransferDataToWindow(), TransformBoundingBoxWithClearanceToPolygon(), TransformTextShapeToSegmentList(), TUNER_SLIDER::TUNER_SLIDER(), DIALOG_UPDATE_FIELDS::updateFields(), DIALOG_FOOTPRINT_FP_EDITOR::Validate(), DIALOG_FOOTPRINT_BOARD_EDITOR::Validate(), TEXTE_MODULE::ViewGetLOD(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

◆ GetTextAngle()

double EDA_TEXT::GetTextAngle ( ) const
inline

Definition at line 173 of file eda_text.h.

173 { return m_e.angle; }
TEXT_EFFECTS m_e
Definition: eda_text.h:372
double angle
now: 0.1 degrees; future: degrees
Definition: eda_text.h:98

References TEXT_EFFECTS::angle, and m_e.

Referenced by BOARD_ADAPTER::AddShapeWithClearanceToContainer(), CreateComponentsSection(), DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD(), KIGFX::WS_PAINTER::draw(), KIGFX::SCH_PAINTER::draw(), export_vrml_pcbtext(), TEXTE_PCB::Flip(), TEXTE_MODULE::Flip(), PCB_IO::format(), LIB_TEXT::GetBoundingBox(), SCH_FIELD::GetBoundingBox(), TEXTE_PCB::GetBoundingBox(), LIB_FIELD::GetBoundingBox(), SCH_TEXT::GetBoundingBox(), SCH_LABEL::GetBoundingBox(), TEXTE_MODULE::GetDrawRotation(), GetLinePositions(), TEXTE_PCB::GetMsgPanelInfo(), GetTextAngleDegrees(), GetTextAngleRadians(), TEXT_MOD_GRID_TABLE::GetValue(), hash_eda(), LIB_TEXT::HitTest(), LIB_FIELD::HitTest(), TEXTE_MODULE::KeepUpright(), SCH_EAGLE_PLUGIN::loadFieldAttributes(), DIMENSION::Mirror(), LIB_TEXT::MirrorHorizontal(), LIB_TEXT::MirrorVertical(), LIB_TEXT::NormalizeJustification(), EAGLE_PLUGIN::orientModuleText(), PCB_PARSER::parseMODULE_unchecked(), ALTIUM_PCB::ParseTexts6Data(), LIB_TEXT::Plot(), LIB_FIELD::Plot(), SCH_FIELD::Plot(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotTextePcb(), PlotWorkSheet(), positioningChanged(), LIB_TEXT::print(), LIB_FIELD::print(), SCH_FIELD::Print(), printOneLineOfText(), SCH_EDIT_TOOL::Rotate(), LIB_TEXT::Rotate(), TEXTE_PCB::Rotate(), TEXTE_MODULE::Rotate(), LIB_FIELD::Rotate(), DIMENSION::Rotate(), SCH_LEGACY_PLUGIN::saveField(), SCH_SEXPR_PLUGIN_CACHE::saveField(), SCH_LEGACY_PLUGIN_CACHE::saveField(), SCH_SEXPR_PLUGIN::saveText(), SCH_SEXPR_PLUGIN_CACHE::saveText(), SCH_LEGACY_PLUGIN_CACHE::saveText(), SCH_SCREEN::SetComponentFootprint(), TextHitTest(), DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataToWindow(), TransformBoundingBoxWithClearanceToPolygon(), TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(), TransformTextShapeToSegmentList(), DIALOG_SCH_EDIT_ONE_FIELD::UpdateField(), and DIALOG_UPDATE_FIELDS::updateFields().

◆ GetTextAngleDegrees()

double EDA_TEXT::GetTextAngleDegrees ( ) const
inline

Definition at line 175 of file eda_text.h.

175 { return GetTextAngle() / 10.0; }
double GetTextAngle() const
Definition: eda_text.h:173

References GetTextAngle().

Referenced by TEXTE_MODULE::GetMsgPanelInfo(), SCH_SEXPR_PLUGIN::saveField(), and DIALOG_TEXT_PROPERTIES::TransferDataToWindow().

◆ GetTextAngleRadians()

double EDA_TEXT::GetTextAngleRadians ( ) const
inline

Definition at line 176 of file eda_text.h.

176 { return GetTextAngle() * M_PI/1800; }
double GetTextAngle() const
Definition: eda_text.h:173

References GetTextAngle().

Referenced by KIGFX::SCH_PAINTER::draw(), and KIGFX::PCB_PAINTER::draw().

◆ GetTextBox()

EDA_RECT EDA_TEXT::GetTextBox ( int  aLine = -1,
bool  aInvertY = false 
) const

Useful in multiline texts to calculate the full text or a line area (for zones filling, locate functions....)

Parameters
aLineThe line of text to consider. Pass -1 for all lines.
aInvertYInvert the Y axis when calculating bounding box.
Returns
the rect containing the line of text (i.e. the position and the size of one line) this rectangle is calculated for 0 orient text. If orientation is not 0 the rect must be rotated to match the physical area

Definition at line 217 of file eda_text.cpp.

218 {
219  EDA_RECT rect;
220  wxArrayString strings;
221  wxString text = GetShownText();
222  int thickness = GetEffectiveTextPenWidth();
223  int linecount = 1;
224  bool hasOverBar = false; // true if the first line of text as an overbar
225 
226  if( IsMultilineAllowed() )
227  {
228  wxStringSplit( text, strings, '\n' );
229 
230  if( strings.GetCount() ) // GetCount() == 0 for void strings
231  {
232  if( aLine >= 0 && (aLine < (int)strings.GetCount()) )
233  text = strings.Item( aLine );
234  else
235  text = strings.Item( 0 );
236 
237  linecount = strings.GetCount();
238  }
239  }
240 
241  // Search for overbar symbol. Only text is scanned,
242  // because only this line can change the bounding box
243  for( unsigned ii = 1; ii < text.size(); ii++ )
244  {
245  if( text[ii-1] == '~' && text[ii] != '~' )
246  {
247  hasOverBar = true;
248  break;
249  }
250  }
251 
252  // calculate the H and V size
253  const auto& font = basic_gal.GetStrokeFont();
254  VECTOR2D fontSize( GetTextSize() );
255  double penWidth( thickness );
256  int dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
257  int dy = GetInterline();
258 
259  // Creates bounding box (rectangle) for horizontal, left and top justified text. The
260  // bounding box will be moved later according to the actual text options
261  wxSize textsize = wxSize( dx, dy );
262  wxPoint pos = GetTextPos();
263 
264  if( aInvertY )
265  pos.y = -pos.y;
266 
267  rect.SetOrigin( pos );
268 
269  // The bbox vertical size returned by GetInterline( aThickness )
270  // includes letters like j and y and ] + interval between lines.
271  // The interval below the last line is not usefull, and we can use its half value
272  // as vertical margin above the text
273  // the full interval is roughly GetTextHeight() * 0.4 - aThickness/2
274  rect.Move( wxPoint( 0, thickness/4 - KiROUND( GetTextHeight() * 0.22 ) ) );
275 
276  if( hasOverBar )
277  { // A overbar adds an extra size to the text
278  // Height from the base line text of chars like [ or {
279  double curr_height = GetTextHeight() * 1.15;
280  double overbarPosition = font.ComputeOverbarVerticalPosition( fontSize.y, penWidth );
281  int extra_height = KiROUND( overbarPosition - curr_height );
282 
283  extra_height += thickness / 2;
284  textsize.y += extra_height;
285  rect.Move( wxPoint( 0, -extra_height ) );
286  }
287 
288  // for multiline texts and aLine < 0, merge all rectangles
289  // ( if aLine < 0, we want the full text bounding box )
290  if( IsMultilineAllowed() && aLine < 0 )
291  {
292  for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
293  {
294  text = strings.Item( ii );
295  dx = KiROUND( font.ComputeStringBoundaryLimits( text, fontSize, penWidth ).x );
296  textsize.x = std::max( textsize.x, dx );
297  textsize.y += dy;
298  }
299  }
300 
301  rect.SetSize( textsize );
302 
303  /* Now, calculate the rect origin, according to text justification
304  * At this point the rectangle origin is the text origin (m_Pos).
305  * This is true only for left and top text justified texts (using top to bottom Y axis
306  * orientation). and must be recalculated for others justifications
307  * also, note the V justification is relative to the first line
308  */
309  switch( GetHorizJustify() )
310  {
312  if( IsMirrored() )
313  rect.SetX( rect.GetX() - rect.GetWidth() );
314  break;
315 
317  rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
318  break;
319 
321  if( !IsMirrored() )
322  rect.SetX( rect.GetX() - rect.GetWidth() );
323  break;
324  }
325 
326  dy = GetTextHeight() + thickness;
327 
328  switch( GetVertJustify() )
329  {
331  break;
332 
334  rect.SetY( rect.GetY() - ( dy / 2) );
335  break;
336 
338  rect.SetY( rect.GetY() - dy );
339  break;
340  }
341 
342  if( linecount > 1 )
343  {
344  int yoffset;
345  linecount -= 1;
346 
347  switch( GetVertJustify() )
348  {
350  break;
351 
353  yoffset = linecount * GetInterline() / 2;
354  rect.SetY( rect.GetY() - yoffset );
355  break;
356 
358  yoffset = linecount * GetInterline();
359  rect.SetY( rect.GetY() - yoffset );
360  break;
361  }
362  }
363 
364  rect.Normalize(); // Make h and v sizes always >= 0
365 
366  return rect;
367 }
const STROKE_FONT & GetStrokeFont() const
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:341
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:211
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsMirrored() const
Definition: eda_text.h:188
int GetX() const
Definition: eda_rect.h:111
int GetWidth() const
Definition: eda_rect.h:119
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:152
int GetTextHeight() const
Definition: eda_text.h:244
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
const wxSize & GetTextSize() const
Definition: eda_text.h:238
void SetX(int val)
Definition: eda_rect.h:168
bool IsMultilineAllowed() const
Definition: eda_text.h:196
void SetY(int val)
Definition: eda_rect.h:174
void Normalize()
Function Normalize ensures that the height ant width are positive.
void SetSize(const wxSize &size)
Definition: eda_rect.h:144
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
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
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
BASIC_GAL basic_gal(basic_displayOptions)
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:133

References basic_gal, GetEffectiveTextPenWidth(), GetHorizJustify(), GetInterline(), GetShownText(), KIGFX::GAL::GetStrokeFont(), GetTextHeight(), GetTextPos(), GetTextSize(), GetVertJustify(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), EDA_RECT::GetY(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, IsMirrored(), IsMultilineAllowed(), KiROUND(), EDA_RECT::Move(), EDA_RECT::Normalize(), EDA_RECT::SetOrigin(), EDA_RECT::SetSize(), EDA_RECT::SetX(), EDA_RECT::SetY(), wxStringSplit(), wxPoint::y, and VECTOR2< T >::y.

Referenced by TEXTE_PCB::Flip(), LIB_TEXT::GetBoundingBox(), SCH_FIELD::GetBoundingBox(), TEXTE_PCB::GetBoundingBox(), LIB_FIELD::GetBoundingBox(), TEXTE_MODULE::GetBoundingBox(), DIMENSION::GetBoundingBox(), SCH_TEXT::GetBoundingBox(), WS_DRAW_ITEM_TEXT::GetBoundingBox(), SCH_LABEL::GetBoundingBox(), LIB_TEXT::NormalizeJustification(), test::DRC_TEST_PROVIDER_COPPER_CLEARANCE::testCopperDrawItem(), DRC::testCopperDrawItem(), TEXTE_MODULE::TextHitTest(), TextHitTest(), TransformBoundingBoxWithClearanceToPolygon(), and TEXTE_MODULE::ViewBBox().

◆ GetTextHeight()

◆ GetTextPos()

const wxPoint& EDA_TEXT::GetTextPos ( ) const
inline

Definition at line 247 of file eda_text.h.

247 { return m_e.pos; }
TEXT_EFFECTS m_e
Definition: eda_text.h:372
wxPoint pos
Definition: eda_text.h:99

References m_e, and TEXT_EFFECTS::pos.

Referenced by BOARD_ADAPTER::AddShapeWithClearanceToContainer(), LIB_TEXT::compare(), LIB_FIELD::compare(), SCH_SHEET_PIN::ConstrainOnEdge(), DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD(), SCH_LABEL::doIsConnected(), SCH_GLOBALLABEL::doIsConnected(), SCH_HIERLABEL::doIsConnected(), KIGFX::WS_PAINTER::draw(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), export_vrml_pcbtext(), export_vrml_text_module(), TEXTE_PCB::Flip(), TEXTE_MODULE::Flip(), PCB_IO::format(), LIB_TEXT::GetBoundingBox(), SCH_FIELD::GetBoundingBox(), TEXTE_PCB::GetBoundingBox(), LIB_FIELD::GetBoundingBox(), TEXTE_MODULE::GetBoundingBox(), SCH_TEXT::GetBoundingBox(), SCH_LABEL::GetBoundingBox(), SCH_GLOBALLABEL::GetBoundingBox(), SCH_HIERLABEL::GetBoundingBox(), SCH_TEXT::GetConnectionPoints(), SCH_SHEET_PIN::GetEndPoints(), SCH_TEXT::GetEndPoints(), SCH_FIELD::GetLibPosition(), GetLinePositions(), SCH_TEXT::GetNetListItem(), TEXTE_PCB::GetPosition(), LIB_TEXT::GetPosition(), TEXTE_MODULE::GetPosition(), DIMENSION::GetPosition(), LIB_FIELD::GetPosition(), SCH_FIELD::GetPosition(), WS_DRAW_ITEM_TEXT::GetPosition(), SCH_TEXT::GetPosition(), WS_DRAW_ITEM_TEXT::GetSelectMenuText(), GetTextBox(), LIB_TEXT::HitTest(), LIB_FIELD::HitTest(), TEXTE_MODULE::Mirror(), DIMENSION::Mirror(), LIB_TEXT::MirrorHorizontal(), LIB_FIELD::MirrorHorizontal(), LIB_TEXT::MirrorVertical(), LIB_FIELD::MirrorVertical(), SCH_SHEET_PIN::MirrorX(), SCH_TEXT::MirrorX(), SCH_SHEET_PIN::MirrorY(), SCH_TEXT::MirrorY(), LIB_TEXT::NormalizeJustification(), PCB_PARSER::parseDIMENSION(), DRAWING_TOOL::PlaceText(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotFootprintTextItem(), BRDITEMS_PLOTTER::PlotTextePcb(), PlotWorkSheet(), LIB_FIELD::print(), Print(), SCH_GLOBALLABEL::Print(), SCH_HIERLABEL::Print(), LIB_TEXT::Rotate(), TEXTE_PCB::Rotate(), TEXTE_MODULE::Rotate(), SCH_FIELD::Rotate(), SCH_SHEET_PIN::Rotate(), LIB_FIELD::Rotate(), DIMENSION::Rotate(), SCH_TEXT::Rotate(), SCH_LEGACY_PLUGIN_CACHE::saveField(), SCH_LEGACY_PLUGIN_CACHE::saveText(), SCH_SCREEN::SetComponentFootprint(), TEXTE_MODULE::SetDrawCoord(), TEXTE_MODULE::SetLocalCoord(), SCH_COMPONENT::SetRef(), TEXTE_MODULE::TextHitTest(), TextHitTest(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), TransformBoundingBoxWithClearanceToPolygon(), TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(), TransformTextShapeToSegmentList(), SCH_TEXT::UpdateDanglingState(), DIALOG_SCH_EDIT_ONE_FIELD::UpdateField(), DIALOG_UPDATE_FIELDS::updateFields(), and TEXTE_MODULE::ViewBBox().

◆ GetTextSize()

◆ GetTextStyleName()

wxString EDA_TEXT::GetTextStyleName ( )
Returns
a wxString with the style name( Normal, Italic, Bold, Bold+Italic)

Definition at line 479 of file eda_text.cpp.

480 {
481  int style = 0;
482 
483  if( IsItalic() )
484  style = 1;
485 
486  if( IsBold() )
487  style += 2;
488 
489  wxString stylemsg[4] = {
490  _("Normal"),
491  _("Italic"),
492  _("Bold"),
493  _("Bold+Italic")
494  };
495 
496  return stylemsg[style];
497 }
bool IsBold() const
Definition: eda_text.h:182
bool IsItalic() const
Definition: eda_text.h:179
#define _(s)
Definition: 3d_actions.cpp:33

References _, IsBold(), and IsItalic().

Referenced by LIB_FIELD::GetMsgPanelInfo().

◆ GetTextThickness()

◆ GetTextWidth()

◆ GetVertJustify()

◆ IsBold()

◆ IsDefaultFormatting()

bool EDA_TEXT::IsDefaultFormatting ( ) const

Definition at line 500 of file eda_text.cpp.

501 {
502  return ( IsVisible()
503  && !IsMirrored()
506  && GetTextThickness() == 0
507  && !IsItalic()
508  && !IsBold()
509  && !IsMultilineAllowed()
510  );
511 }
bool IsBold() const
Definition: eda_text.h:182
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsMirrored() const
Definition: eda_text.h:188
bool IsVisible() const
Definition: eda_text.h:185
int GetTextThickness() const
Definition: eda_text.h:158
bool IsItalic() const
Definition: eda_text.h:179
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
bool IsMultilineAllowed() const
Definition: eda_text.h:196

References GetHorizJustify(), GetTextThickness(), GetVertJustify(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, IsBold(), IsItalic(), IsMirrored(), IsMultilineAllowed(), and IsVisible().

Referenced by SCH_SEXPR_PLUGIN::saveField().

◆ IsItalic()

◆ IsMirrored()

◆ IsMultilineAllowed()

◆ IsVisible()

◆ LenSize()

int EDA_TEXT::LenSize ( const wxString &  aLine,
int  aThickness 
) const
Returns
the text length in internal units
Parameters
aLine: the line of text to consider. For single line text, this parameter is always m_Text
aThickness: the stroke width of the text

Definition at line 183 of file eda_text.cpp.

184 {
187  basic_gal.SetLineWidth( (float) aThickness );
189 
190  VECTOR2D tsize = basic_gal.GetTextLineSize( aLine );
191 
192  return KiROUND( tsize.x );
193 }
void SetFontItalic(const bool aItalic)
Set italic property of current font.
bool IsBold() const
Definition: eda_text.h:182
VECTOR2D GetTextLineSize(const UTF8 &aText) const
Compute the X and Y size of a given text.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
bool IsItalic() const
Definition: eda_text.h:179
void SetFontBold(const bool aBold)
Set bold property of current font.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
const wxSize & GetTextSize() const
Definition: eda_text.h:238
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
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
BASIC_GAL basic_gal(basic_displayOptions)

References basic_gal, KIGFX::GAL::GetTextLineSize(), GetTextSize(), IsBold(), IsItalic(), KiROUND(), KIGFX::GAL::SetFontBold(), KIGFX::GAL::SetFontItalic(), KIGFX::GAL::SetGlyphSize(), KIGFX::GAL::SetLineWidth(), and VECTOR2< T >::x.

Referenced by SCH_GLOBALLABEL::CreateGraphicShape(), SCH_GLOBALLABEL::GetBoundingBox(), and SCH_HIERLABEL::GetBoundingBox().

◆ MapHorizJustify()

EDA_TEXT_HJUSTIFY_T EDA_TEXT::MapHorizJustify ( int  aHorizJustify)
static

Definition at line 58 of file eda_text.cpp.

59 {
60  wxASSERT( aHorizJustify >= GR_TEXT_HJUSTIFY_LEFT && aHorizJustify <= GR_TEXT_HJUSTIFY_RIGHT );
61 
62  if( aHorizJustify > GR_TEXT_HJUSTIFY_RIGHT )
64 
65  if( aHorizJustify < GR_TEXT_HJUSTIFY_LEFT )
66  return GR_TEXT_HJUSTIFY_LEFT;
67 
68  return (EDA_TEXT_HJUSTIFY_T) aHorizJustify;
69 }
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47

References GR_TEXT_HJUSTIFY_LEFT, and GR_TEXT_HJUSTIFY_RIGHT.

Referenced by DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_SCH_EDIT_ONE_FIELD::UpdateField(), and DIALOG_EDIT_ONE_FIELD::updateText().

◆ MapVertJustify()

EDA_TEXT_VJUSTIFY_T EDA_TEXT::MapVertJustify ( int  aVertJustify)
static

Definition at line 72 of file eda_text.cpp.

73 {
74  wxASSERT( aVertJustify >= GR_TEXT_VJUSTIFY_TOP && aVertJustify <= GR_TEXT_VJUSTIFY_BOTTOM );
75 
76  if( aVertJustify > GR_TEXT_VJUSTIFY_BOTTOM )
78 
79  if( aVertJustify < GR_TEXT_VJUSTIFY_TOP )
80  return GR_TEXT_VJUSTIFY_TOP;
81 
82  return (EDA_TEXT_VJUSTIFY_T) aVertJustify;
83 }
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:54

References GR_TEXT_VJUSTIFY_BOTTOM, and GR_TEXT_VJUSTIFY_TOP.

Referenced by DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_SCH_EDIT_ONE_FIELD::UpdateField(), and DIALOG_EDIT_ONE_FIELD::updateText().

◆ Offset()

◆ Print()

void EDA_TEXT::Print ( RENDER_SETTINGS aSettings,
const wxPoint aOffset,
COLOR4D  aColor,
EDA_DRAW_MODE_T  aDisplay_mode = FILLED 
)

Print this text object to the device context aDC.

Parameters
aDC= the current Device Context
aOffset= draw offset (usually (0,0))
aColor= text color
aDisplay_mode= FILLED or SKETCH

Definition at line 395 of file eda_text.cpp.

397 {
398  if( IsMultilineAllowed() )
399  {
400  std::vector<wxPoint> positions;
401  wxArrayString strings;
402  wxStringSplit( GetShownText(), strings, '\n' );
403 
404  positions.reserve( strings.Count() );
405 
406  GetLinePositions( positions, strings.Count());
407 
408  for( unsigned ii = 0; ii < strings.Count(); ii++ )
409  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
410  }
411  else
412  {
413  printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText(), GetTextPos() );
414  }
415 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:341
void printOneLineOfText(RENDER_SETTINGS *aSettings, 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:459
bool IsMultilineAllowed() const
Definition: eda_text.h:196
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:418
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:133

References GetLinePositions(), GetShownText(), GetTextPos(), IsMultilineAllowed(), printOneLineOfText(), and wxStringSplit().

Referenced by SCH_TEXT::Print(), SCH_GLOBALLABEL::Print(), SCH_HIERLABEL::Print(), and WS_DRAW_ITEM_TEXT::PrintWsItem().

◆ printOneLineOfText()

void EDA_TEXT::printOneLineOfText ( RENDER_SETTINGS aSettings,
const wxPoint aOffset,
COLOR4D  aColor,
EDA_DRAW_MODE_T  aFillMode,
const wxString &  aText,
const wxPoint aPos 
)
private

Print each line of this EDA_TEXT.

Parameters
aOffset= draw offset (usually (0,0))
aColor= text color
aFillMode= FILLED or SKETCH
aText= the single line of text to draw.
aPos= the position of this line ).

Definition at line 459 of file eda_text.cpp.

462 {
463  wxDC* DC = aSettings->GetPrintDC();
464  int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() );
465 
466  if( aFillMode == SKETCH )
467  penWidth = -penWidth;
468 
469  wxSize size = GetTextSize();
470 
471  if( IsMirrored() )
472  size.x = -size.x;
473 
474  GRText( DC, aOffset + aPos, aColor, aText, GetTextAngle(), size, GetHorizJustify(),
475  GetVertJustify(), penWidth, IsItalic(), IsBold() );
476 }
bool IsBold() const
Definition: eda_text.h:182
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsMirrored() const
Definition: eda_text.h:188
double GetTextAngle() const
Definition: eda_text.h:173
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:152
bool IsItalic() const
Definition: eda_text.h:179
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
const wxSize & GetTextSize() const
Definition: eda_text.h:238
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:134
int GetDefaultPenWidth() const

References KIGFX::RENDER_SETTINGS::GetDefaultPenWidth(), GetEffectiveTextPenWidth(), GetHorizJustify(), KIGFX::RENDER_SETTINGS::GetPrintDC(), GetTextAngle(), GetTextSize(), GetVertJustify(), GRText(), IsBold(), IsItalic(), IsMirrored(), and SKETCH.

Referenced by Print().

◆ Replace()

bool EDA_TEXT::Replace ( wxFindReplaceData &  aSearchData)

Helper function used in search and replace dialog.

Perform a text replace using the find and replace criteria in aSearchData.

Parameters
aSearchDataA reference to a wxFindReplaceData object containing the search and replace criteria.
Returns
True if the text item was modified, otherwise false.

Definition at line 173 of file eda_text.cpp.

174 {
175  bool retval = EDA_ITEM::Replace( aSearchData, m_text );
177  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
178 
179  return retval;
180 }
static bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
wxString m_shown_text
Definition: eda_text.h:369
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:370
wxString m_text
Definition: eda_text.h:368
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131

References m_shown_text, m_shown_text_has_text_var_refs, m_text, EDA_ITEM::Replace(), and UnescapeString().

Referenced by SCH_FIELD::Replace(), SCH_SHEET_PIN::Replace(), and SCH_TEXT::Replace().

◆ SetBold()

◆ SetEffects()

void EDA_TEXT::SetEffects ( const EDA_TEXT aSrc)

Set the text effects from another instance.

TEXT_EFFECTS is not exposed in the public API, but includes everything except the actual text string itself.

Definition at line 132 of file eda_text.cpp.

133 {
134  m_e = aSrc.m_e;
135 }
TEXT_EFFECTS m_e
Definition: eda_text.h:372

References m_e.

Referenced by LIB_TEXT::Clone(), LIB_FIELD::Copy(), SCH_FIELD::ImportValues(), LIB_FIELD::operator=(), and TEXTE_MODULE::SetEffects().

◆ SetHorizJustify()

◆ SetItalic()

◆ SetMirrored()

◆ SetMultilineAllowed()

void EDA_TEXT::SetMultilineAllowed ( bool  aAllow)
inline
Parameters
aAllowtrue if ok to use multiline option, false if ok to use only single line text. (Single line is faster in calculations than multiline.)

Definition at line 195 of file eda_text.h.

195 { m_e.Bit( TE_MULTILINE, aAllow ); }
TEXT_EFFECTS m_e
Definition: eda_text.h:372
void Bit(int aBit, bool aValue)
Definition: eda_text.h:101

References TEXT_EFFECTS::Bit(), m_e, and TE_MULTILINE.

Referenced by SCH_GLOBALLABEL::SCH_GLOBALLABEL(), SCH_HIERLABEL::SCH_HIERLABEL(), SCH_LABEL::SCH_LABEL(), SCH_TEXT::SCH_TEXT(), WS_DATA_ITEM_TEXT::SyncDrawItems(), and TEXTE_PCB::TEXTE_PCB().

◆ SetText()

void EDA_TEXT::SetText ( const wxString &  aText)
virtual

Definition at line 116 of file eda_text.cpp.

117 {
118  m_text = aText;
119  m_shown_text = UnescapeString( aText );
120  m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
121 }
wxString m_shown_text
Definition: eda_text.h:369
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:370
wxString m_text
Definition: eda_text.h:368
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131

References m_shown_text, m_shown_text_has_text_var_refs, m_text, and UnescapeString().

Referenced by SCH_EAGLE_PLUGIN::addImplicitConnections(), GRAPHICS_IMPORTER_PCBNEW::AddText(), PCAD2KICAD::PCB_TEXT::AddToBoard(), PCAD2KICAD::PCB_MODULE::AddToBoard(), BACK_ANNOTATE::applyChangelist(), FIELDS_EDITOR_GRID_DATA_MODEL::ApplyData(), SCH_EDITOR_CONTROL::BackAnnotateFootprints(), LIB_TEXT::Clone(), PCB_BASE_FRAME::CreateNewModule(), LIB_EDIT_FRAME::CreateNewPart(), dummy(), KIGFX::dummy(), SCH_EDIT_TOOL::Duplicate(), MODULE::DuplicateItem(), EDA_TEXT_DESC::EDA_TEXT_DESC(), ALTIUM_PCB::HelperParseDimensions6Leader(), LIB_FIELD::HitTest(), SCH_TEXT::IncrementLabel(), SCH_LEGACY_PLUGIN_CACHE::loadAliases(), SCH_LEGACY_PLUGIN_CACHE::loadDocs(), SCH_LEGACY_PLUGIN_CACHE::loadField(), SCH_EAGLE_PLUGIN::loadLibrary(), LEGACY_PLUGIN::loadMODULE_TEXT(), FOOTPRINT_EDIT_FRAME::LoadModuleFromLibrary(), SCH_LEGACY_PLUGIN_CACHE::LoadPart(), LEGACY_PLUGIN::loadPCB_TEXT(), EAGLE_PLUGIN::loadPlain(), SCH_EAGLE_PLUGIN::loadSheet(), SCH_LEGACY_PLUGIN::loadSheet(), SCH_LEGACY_PLUGIN_CACHE::loadText(), TUNER_SLIDER::onSave(), LIB_FIELD::operator=(), EAGLE_PLUGIN::orientModuleText(), EAGLE_PLUGIN::packageText(), ALTIUM_PCB::ParseTexts6Data(), LIB_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), pasteModuleItemsToModEdit(), LIB_PART::PlotLibFields(), SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile(), processTextItem(), SCH_SEXPR_PLUGIN_CACHE::saveDcmInfoAsFields(), SCH_REFERENCE::SCH_REFERENCE(), SCH_SCREEN::SetComponentFootprint(), LIB_PART::SetName(), SCH_COMPONENT::SetRef(), DIMENSION::SetText(), TEXT_MOD_GRID_TABLE::SetValue(), DIALOG_EDIT_SHEET_PIN::TransferDataFromWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), DIALOG_SPICE_MODEL::TransferDataFromWindow(), DIALOG_EDIT_COMPONENTS_LIBID::TransferDataFromWindow(), DIALOG_SCH_SHEET_PROPS::TransferDataToWindow(), DIALOG_LIB_EDIT_ONE_FIELD::UpdateField(), DIALOG_SCH_EDIT_ONE_FIELD::UpdateField(), DIALOG_UPDATE_FIELDS::updateFields(), SCH_COMPONENT::UpdateFields(), and SCH_SHEET_LIST::UpdateSymbolInstances().

◆ SetTextAngle()

virtual void EDA_TEXT::SetTextAngle ( double  aAngle)
inlinevirtual

◆ SetTextHeight()

void EDA_TEXT::SetTextHeight ( int  aHeight)
inline

Definition at line 243 of file eda_text.h.

243 { m_e.size.y = aHeight; }
TEXT_EFFECTS m_e
Definition: eda_text.h:372
wxSize size
Definition: eda_text.h:96

References m_e, and TEXT_EFFECTS::size.

Referenced by GRAPHICS_IMPORTER_PCBNEW::AddText(), EDA_TEXT_DESC::EDA_TEXT_DESC(), and TEXT_MOD_GRID_TABLE::SetValue().

◆ SetTextPos()

void EDA_TEXT::SetTextPos ( const wxPoint aPoint)
inline

◆ SetTextSize()

void EDA_TEXT::SetTextSize ( const wxSize &  aNewSize)
inline

Definition at line 237 of file eda_text.h.

237 { m_e.size = aNewSize; }
TEXT_EFFECTS m_e
Definition: eda_text.h:372
wxSize size
Definition: eda_text.h:96

References m_e, and TEXT_EFFECTS::size.

Referenced by SCH_EAGLE_PLUGIN::addImplicitConnections(), SCH_EDIT_TOOL::ChangeTextType(), MICROWAVE_TOOL::createBaseFootprint(), PCB_BASE_FRAME::CreateNewModule(), SCH_DRAWING_TOOLS::createNewText(), SCH_EDIT_FRAME::CreateSheetPin(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), dummy(), KIGFX::dummy(), EDA_TEXT(), ALTIUM_PCB::HelperParseDimensions6Leader(), ALTIUM_PCB::HelperParseDimensions6Linear(), LIB_TEXT::LIB_TEXT(), SCH_LEGACY_PLUGIN_CACHE::loadField(), SCH_EAGLE_PLUGIN::loadFieldAttributes(), LEGACY_PLUGIN::loadMODULE_TEXT(), LEGACY_PLUGIN::loadPCB_TEXT(), EAGLE_PLUGIN::loadPlain(), SCH_LEGACY_PLUGIN::loadSheet(), SCH_LEGACY_PLUGIN_CACHE::loadText(), SCH_EAGLE_PLUGIN::loadTextAttributes(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnAddField(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAddField(), DIALOG_FOOTPRINT_FP_EDITOR::OnAddField(), DIALOG_FOOTPRINT_BOARD_EDITOR::OnAddField(), EAGLE_PLUGIN::orientModuleText(), EAGLE_PLUGIN::packageText(), SCH_SEXPR_PARSER::parseEDA_TEXT(), PCB_PARSER::parseEDA_TEXT(), ALTIUM_PCB::ParseTexts6Data(), DRAWING_TOOL::PlaceText(), BACK_ANNOTATE::processNetNameChange(), SCH_SCREEN::SetComponentFootprint(), DIMENSION::SetTextSize(), PCAD2KICAD::SetTextSizeFromStrokeFontHeight(), PCAD2KICAD::SetTextSizeFromTrueTypeFontHeight(), DIALOG_EDIT_SHEET_PIN::TransferDataFromWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), LIB_DRAWING_TOOLS::TwoClickPlace(), DIALOG_UPDATE_FIELDS::updateFields(), DIALOG_EDIT_ONE_FIELD::updateText(), and WS_DRAW_ITEM_TEXT::WS_DRAW_ITEM_TEXT().

◆ SetTextThickness()

◆ SetTextWidth()

void EDA_TEXT::SetTextWidth ( int  aWidth)
inline

Definition at line 240 of file eda_text.h.

240 { m_e.size.x = aWidth; }
TEXT_EFFECTS m_e
Definition: eda_text.h:372
wxSize size
Definition: eda_text.h:96

References m_e, and TEXT_EFFECTS::size.

Referenced by GRAPHICS_IMPORTER_PCBNEW::AddText(), EDA_TEXT_DESC::EDA_TEXT_DESC(), and TEXT_MOD_GRID_TABLE::SetValue().

◆ SetTextX()

◆ SetTextY()

◆ SetVertJustify()

◆ SetVisible()

◆ ShortenedShownText()

wxString EDA_TEXT::ShortenedShownText ( ) const

Returns a shortened version (max 15 characters) of the shown text.

Definition at line 196 of file eda_text.cpp.

197 {
198  wxString tmp = GetShownText();
199 
200  tmp.Replace( wxT( "\n" ), wxT( " " ) );
201  tmp.Replace( wxT( "\r" ), wxT( " " ) );
202  tmp.Replace( wxT( "\t" ), wxT( " " ) );
203 
204  if( tmp.Length() > 36 )
205  tmp = tmp.Left( 34 ) + wxT( "..." );
206 
207  return tmp;
208 }
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:133

References GetShownText().

Referenced by LIB_TEXT::GetSelectMenuText(), TEXTE_PCB::GetSelectMenuText(), SCH_FIELD::GetSelectMenuText(), LIB_FIELD::GetSelectMenuText(), SCH_SHEET_PIN::GetSelectMenuText(), TEXTE_MODULE::GetSelectMenuText(), SCH_TEXT::GetSelectMenuText(), SCH_LABEL::GetSelectMenuText(), SCH_GLOBALLABEL::GetSelectMenuText(), and SCH_HIERLABEL::GetSelectMenuText().

◆ SwapEffects()

void EDA_TEXT::SwapEffects ( EDA_TEXT aTradingPartner)

Swap the text effects of the two involved instances.

TEXT_EFFECTS is not exposed in the public API, but includes everything except the actual text string itself.

Definition at line 146 of file eda_text.cpp.

147 {
148  std::swap( m_e, aTradingPartner.m_e );
149 }
TEXT_EFFECTS m_e
Definition: eda_text.h:372

References m_e.

Referenced by SCH_FIELD::SwapData(), SCH_TEXT::SwapData(), and TEXTE_MODULE::SwapEffects().

◆ SwapText()

void EDA_TEXT::SwapText ( EDA_TEXT aTradingPartner)

Definition at line 138 of file eda_text.cpp.

139 {
140  std::swap( m_text, aTradingPartner.m_text );
141  std::swap( m_shown_text, aTradingPartner.m_shown_text );
143 }
wxString m_shown_text
Definition: eda_text.h:369
bool m_shown_text_has_text_var_refs
Definition: eda_text.h:370
wxString m_text
Definition: eda_text.h:368

References m_shown_text, m_shown_text_has_text_var_refs, and m_text.

Referenced by SCH_FIELD::SwapData(), and SCH_TEXT::SwapData().

◆ TextHitTest() [1/2]

bool EDA_TEXT::TextHitTest ( const wxPoint aPoint,
int  aAccuracy = 0 
) const
virtual

Test if aPoint is within the bounds of this object.

Parameters
aPoint-A wxPoint to test
aAccuracy- Amount to inflate the bounding box.
Returns
bool - true if a hit, else false

Reimplemented in TEXTE_MODULE.

Definition at line 370 of file eda_text.cpp.

371 {
372  EDA_RECT rect = GetTextBox();
373  wxPoint location = aPoint;
374 
375  rect.Inflate( aAccuracy );
376  RotatePoint( &location, GetTextPos(), -GetTextAngle() );
377 
378  return rect.Contains( location );
379 }
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:217
double GetTextAngle() const
Definition: eda_text.h:173
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
bool Contains(const wxPoint &aPoint) const
Function Contains.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.

References EDA_RECT::Contains(), GetTextAngle(), GetTextBox(), GetTextPos(), EDA_RECT::Inflate(), and RotatePoint().

Referenced by LIB_TEXT::HitTest(), TEXTE_PCB::HitTest(), LIB_FIELD::HitTest(), DIMENSION::HitTest(), and WS_DRAW_ITEM_TEXT::HitTest().

◆ TextHitTest() [2/2]

bool EDA_TEXT::TextHitTest ( const EDA_RECT aRect,
bool  aContains,
int  aAccuracy = 0 
) const
virtual

Test if object bounding box is contained within or intersects aRect.

Parameters
aRect- Rect to test against.
aContains- Test for containment instead of intersection if true.
aAccuracy- Amount to inflate the bounding box.
Returns
bool - true if a hit, else false

Reimplemented in TEXTE_MODULE.

Definition at line 382 of file eda_text.cpp.

383 {
384  EDA_RECT rect = aRect;
385 
386  rect.Inflate( aAccuracy );
387 
388  if( aContains )
389  return rect.Contains( GetTextBox() );
390 
391  return rect.Intersects( GetTextBox(), GetTextAngle() );
392 }
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:217
double GetTextAngle() const
Definition: eda_text.h:173
bool Contains(const wxPoint &aPoint) const
Function Contains.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.

References EDA_RECT::Contains(), GetTextAngle(), GetTextBox(), EDA_RECT::Inflate(), and EDA_RECT::Intersects().

◆ TransformBoundingBoxWithClearanceToPolygon()

void EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon ( SHAPE_POLY_SET aCornerBuffer,
int  aClearanceValue 
) const

Convert the text bounding box to a rectangular polygon depending on the text orientation, the bounding box is not always horizontal or vertical.

Used in filling zones calculations Circles and arcs are approximated by segments

Parameters
aCornerBuffer= a buffer to store the polygon
aClearanceValue= the clearance around the text bounding box to the real clearance value (usually near from 1.0)

Definition at line 278 of file board_items_to_polygon_shape_transform.cpp.

280 {
281  if( GetText().Length() == 0 )
282  return;
283 
284  wxPoint corners[4]; // Buffer of polygon corners
285 
286  EDA_RECT rect = GetTextBox();
287  rect.Inflate( aClearanceValue + Millimeter2iu( DEFAULT_TEXT_WIDTH ) );
288  corners[0].x = rect.GetOrigin().x;
289  corners[0].y = rect.GetOrigin().y;
290  corners[1].y = corners[0].y;
291  corners[1].x = rect.GetRight();
292  corners[2].x = corners[1].x;
293  corners[2].y = rect.GetBottom();
294  corners[3].y = corners[2].y;
295  corners[3].x = corners[0].x;
296 
297  aCornerBuffer->NewOutline();
298 
299  for( wxPoint& corner : corners )
300  {
301  // Rotate polygon
302  RotatePoint( &corner.x, &corner.y, GetTextPos().x, GetTextPos().y, GetTextAngle() );
303  aCornerBuffer->Append( corner.x, corner.y );
304  }
305 }
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:217
double GetTextAngle() const
Definition: eda_text.h:173
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
int GetBottom() const
Definition: eda_rect.h:124
#define DEFAULT_TEXT_WIDTH
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
int GetRight() const
Definition: eda_rect.h:121
int NewOutline()
Creates a new empty polygon in the set and returns its index
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)

References SHAPE_POLY_SET::Append(), DEFAULT_TEXT_WIDTH, EDA_RECT::GetBottom(), EDA_RECT::GetOrigin(), EDA_RECT::GetRight(), GetText(), GetTextAngle(), GetTextBox(), GetTextPos(), EDA_RECT::Inflate(), SHAPE_POLY_SET::NewOutline(), RotatePoint(), wxPoint::x, and wxPoint::y.

Referenced by ZONE_FILLER::addKnockout().

◆ TransformTextShapeToSegmentList()

void EDA_TEXT::TransformTextShapeToSegmentList ( std::vector< wxPoint > &  aCornerBuffer) const

Convert the text shape to a list of segment.

Each segment is stored as 2 wxPoints: the starting point and the ending point there are therefore 2*n points.

Parameters
aCornerBuffer= a buffer to store the polygon

Definition at line 578 of file eda_text.cpp.

579 {
580  wxSize size = GetTextSize();
581 
582  if( IsMirrored() )
583  size.x = -size.x;
584 
585  bool forceBold = true;
586  int penWidth = 0; // use max-width for bold text
587 
588  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
589 
590  if( IsMultilineAllowed() )
591  {
592  wxArrayString strings_list;
593  wxStringSplit( GetShownText(), strings_list, wxChar('\n') );
594  std::vector<wxPoint> positions;
595  positions.reserve( strings_list.Count() );
596  GetLinePositions( positions, strings_list.Count());
597 
598  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
599  {
600  wxString txt = strings_list.Item( ii );
601  GRText( NULL, positions[ii], color, txt, GetTextAngle(), size, GetHorizJustify(),
602  GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
603  &aCornerBuffer );
604  }
605  }
606  else
607  {
609  GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer,
610  &aCornerBuffer );
611  }
612 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:341
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsMirrored() const
Definition: eda_text.h:188
int color
Definition: DXF_plotter.cpp:61
static void addTextSegmToBuffer(int x0, int y0, int xf, int yf, void *aData)
Definition: eda_text.cpp:570
double GetTextAngle() const
Definition: eda_text.h:173
Definition: color4d.h:44
bool IsItalic() const
Definition: eda_text.h:179
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
#define NULL
const wxSize & GetTextSize() const
Definition: eda_text.h:238
bool IsMultilineAllowed() const
Definition: eda_text.h:196
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:134
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:418
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:133
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

References addTextSegmToBuffer(), BLACK, color, GetHorizJustify(), GetLinePositions(), GetShownText(), GetText(), GetTextAngle(), GetTextPos(), GetTextSize(), GetVertJustify(), GRText(), IsItalic(), IsMirrored(), IsMultilineAllowed(), NULL, and wxStringSplit().

Referenced by PNS_KICAD_IFACE_BASE::syncTextItem(), test::DRC_TEST_PROVIDER_COPPER_CLEARANCE::testCopperDrawItem(), and DRC::testCopperDrawItem().

Member Data Documentation

◆ m_e

◆ m_shown_text

wxString EDA_TEXT::m_shown_text
private

Definition at line 369 of file eda_text.h.

Referenced by CopyText(), EDA_TEXT(), GetShownText(), Replace(), SetText(), and SwapText().

◆ m_shown_text_has_text_var_refs

bool EDA_TEXT::m_shown_text_has_text_var_refs
private

Definition at line 370 of file eda_text.h.

Referenced by CopyText(), EDA_TEXT(), GetShownText(), Replace(), SetText(), and SwapText().

◆ m_text

wxString EDA_TEXT::m_text
private

Definition at line 368 of file eda_text.h.

Referenced by CopyText(), EDA_TEXT(), Empty(), GetText(), Replace(), SetText(), and SwapText().


The documentation for this class was generated from the following files: