60class wxFindReplaceData;
93 m_IuScale( aIuScale ),
94 m_render_cache_font( nullptr ),
95 m_bounding_box_cache_valid( false ),
96 m_bounding_box_cache_line( -1 ),
97 m_bounding_box_cache_inverted( false )
116 m_IuScale( aText.m_IuScale )
132 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.
m_render_cache )
135 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
137 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
168 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.
m_render_cache )
171 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
173 m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
330 penWidth = aDefaultPenWidth;
334 else if( penWidth <= 1 )
379 aEnforceMinTextSize =
false;
381 if( aEnforceMinTextSize )
439 if( aOffset.
x == 0 && aOffset.
y == 0 )
447 outline->Move( aOffset );
449 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0,
ANGLE_0,
false, { 0, 0 } );
511std::vector<std::unique_ptr<KIFONT::GLYPH>>*
557 m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
580 wxArrayString strings;
588 if( strings.GetCount() )
590 if( aLine >= 0 && ( aLine <
static_cast<int>( strings.GetCount() ) ) )
591 text = strings.Item( aLine );
593 text = strings.Item( 0 );
604 int overbarOffset = 0;
610 int fudgeFactor =
KiROUND( extents.
y * 0.17 );
613 textsize.
y += fudgeFactor;
618 if(
text.Contains( wxT(
"~{" ) ) )
619 overbarOffset = extents.
y / 6;
629 for(
unsigned ii = 1; ii < strings.GetCount(); ii++ )
631 text = strings.Item( ii );
634 textsize.
x = std::max( textsize.
x, extents.
x );
643 textsize.
y += overbarOffset;
670 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
677 bbox.
Offset( 0, -fudgeFactor );
686 bbox.
Offset( 0, fudgeFactor );
690 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
736 std::vector<VECTOR2I> positions;
737 wxArrayString strings;
740 positions.reserve( strings.Count() );
744 for(
unsigned ii = 0; ii < strings.Count(); ii++ )
745 printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
772 pos.
y -= ( aLineCount - 1 ) * offset.
y / 2;
776 pos.
y -= ( aLineCount - 1 ) * offset.
y;
780 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
791 for(
int ii = 0; ii < aLineCount; ii++ )
793 aPositions.push_back( (
VECTOR2I) pos );
801 const wxString& aText,
const VECTOR2I& aPos )
807 penWidth = -penWidth;
834 wxString stylemsg[4] = {
841 return stylemsg[style];
850 return wxEmptyString;
862 std::vector<std::string> fontNames;
863 Fontconfig()->ListFonts( fontNames, std::string(
Pgm().GetLanguageTag().utf8_str() ) );
865 for(
int ii = 0; ii < (int) fontNames.size(); ++ii )
881 else if( aIdx == -2 )
887 std::vector<std::string> fontNames;
888 Fontconfig()->ListFonts( fontNames, std::string(
Pgm().GetLanguageTag().utf8_str() ) );
890 if( aIdx >= 0 && aIdx <
static_cast<int>( fontNames.size() ) )
915 aFormatter->
Print( aNestLevel + 1,
"(effects" );
917 aFormatter->
Print( 0,
" (font" );
920 aFormatter->
Print( 0,
" (face \"%s\")",
GetFont()->NameAsToken() );
923 aFormatter->
Print( 0,
" (size %s %s)",
929 aFormatter->
Print( 0,
" (line_spacing %s)",
935 aFormatter->
Print( 0,
" (thickness %s)",
940 aFormatter->
Print( 0,
" (bold yes)" );
943 aFormatter->
Print( 0,
" (italic yes)" );
947 aFormatter->
Print( 0,
" (color %d %d %d %s)",
954 aFormatter->
Print( 0,
")");
959 aFormatter->
Print( 0,
" (justify");
968 aFormatter->
Print( 0,
" mirror" );
970 aFormatter->
Print( 0,
")" );
974 aFormatter->
Print( 0,
" (hide yes)" );
981 aFormatter->
Print( 0,
")\n" );
989 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
997 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache =
nullptr;
1021 shape->AddShape(
new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1028 for(
const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1029 triShape->
Append( point.x, point.y );
1031 shape->AddShape( triShape );
1046 shape->AddShape(
new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1051 shape->AddShape( aPoly.Clone() );
1066 wxCHECK( aOther, 1 );
1096 if( uri.Create( aURL ) && uri.HasScheme() )
1098 const wxString& scheme = uri.GetScheme();
1099 return scheme == wxT(
"file" ) || scheme == wxT(
"http" ) || scheme == wxT(
"https" );
1108 const wxString& str1 =
GetText();
1109 const wxString& str2 = aOther.
GetText();
1111 int m = str1.length();
1112 int n = str2.length();
1114 if( n == 0 || m == 0 )
1118 std::vector<std::vector<int>>
distance(m + 1, std::vector<int>(n + 1));
1121 for(
int i = 0; i <= m; i++ )
1123 for(
int j = 0; j <= n; j++ )
1127 for(
int i = 1; i <= m; i++ )
1129 for(
int j = 1; j <= n; j++ )
1131 if( str1[i - 1] == str2[j - 1] )
1144 int maxLen = std::max( m, n );
1145 double similarity = 1.0 - (
static_cast<double>(
distance[m][n] ) / maxLen );
1153 double retval = 1.0;
1169 return aHref.StartsWith( wxT(
"#" ), aDestination );
1175 return wxT(
"#" ) + aDestination;
1205 PROPERTY_DISPLAY::PT_DEGREE ) );
1207 const wxString textProps =
_HKI(
"Text Properties" );
1222 PROPERTY_DISPLAY::PT_SIZE ),
1239 PROPERTY_DISPLAY::PT_SIZE ),
1244 PROPERTY_DISPLAY::PT_SIZE ),
1248 _HKI(
"Horizontal Justification" ),
1252 _HKI(
"Vertical Justification" ),
constexpr EDA_IU_SCALE unityScale
void SetOrigin(const Vec &pos)
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
void Offset(coord_type dx, coord_type dy)
void SetX(coord_type val)
const Vec GetCenter() const
bool Intersects(const BOX2< Vec > &aRect) const
void SetY(coord_type val)
coord_type GetHeight() const
coord_type GetWidth() const
void SetSize(const Vec &size)
bool Contains(const Vec &aPoint) const
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
int GetTextHeight() const
BOX2I GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
void SetTextColor(const COLOR4D &aColor)
COLOR4D GetTextColor() const
wxString GetTextStyleName() const
bool IsDefaultFormatting() const
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_render_cache
wxString GetFontName() const
void SetupRenderCache(const wxString &aResolvedText, const EDA_ANGLE &aAngle)
BOX2I m_bounding_box_cache
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
bool IsMultilineAllowed() const
virtual const wxString & GetText() const
Return the string associated with the text object.
int GetInterline() const
Return the distance between two lines of text.
virtual bool IsVisible() const
void SetTextPos(const VECTOR2I &aPoint)
bool m_shown_text_has_text_var_refs
KIFONT::FONT * GetFont() const
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
void SetMirrored(bool isMirrored)
int m_bounding_box_cache_line
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
const KIFONT::FONT * m_render_cache_font
virtual EDA_ANGLE GetDrawRotation() const
virtual VECTOR2I GetDrawPos() const
EDA_TEXT & operator=(const EDA_TEXT &aItem)
void printOneLineOfText(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, OUTLINE_MODE aFillMode, const wxString &aText, const VECTOR2I &aPos)
Print each line of this EDA_TEXT.
virtual bool HasHyperlink() const
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
wxString GetHyperlink() const
void Offset(const VECTOR2I &aOffset)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
void SetTextWidth(int aWidth)
void SetBoldFlag(bool aBold)
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
int Compare(const EDA_TEXT *aOther) const
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
virtual void SetVisible(bool aVisible)
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
bool m_bounding_box_cache_valid
void GetLinePositions(std::vector< VECTOR2I > &aPositions, int aLineCount) const
Populate aPositions with the position of each line of a multiline text, according to the vertical jus...
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
virtual void ClearBoundingBoxCache()
virtual KIFONT::FONT * getDrawFont() const
double GetLineSpacing() const
double Similarity(const EDA_TEXT &aOther) const
VECTOR2I m_render_cache_offset
void SetLineSpacing(double aLineSpacing)
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
void SetTextHeight(int aHeight)
virtual void cacheShownText()
EDA_ANGLE m_render_cache_angle
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
bool m_bounding_box_cache_inverted
virtual void ClearRenderCache()
const TEXT_ATTRIBUTES & GetAttributes() const
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
VECTOR2I m_bounding_box_cache_pos
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
wxString m_render_cache_text
double GetTextAngleDegrees() const
virtual const KIFONT::METRICS & getFontMetrics() const
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
build a list of segments (SHAPE_SEGMENT) to describe a text shape.
void SetTextAngleDegrees(double aOrientation)
void SetHyperlink(wxString aLink)
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
void SetKeepUpright(bool aKeepUpright)
void CopyText(const EDA_TEXT &aSrc)
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
virtual void SetText(const wxString &aText)
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetFontIndex(int aIdx)
int GetTextThickness() const
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
void SetItalic(bool aItalic)
void SwapText(EDA_TEXT &aTradingPartner)
void SetMultilineAllowed(bool aAllow)
void SetFont(KIFONT::FONT *aFont)
VECTOR2I GetTextSize() const
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
TEXT_ATTRIBUTES m_attributes
static ENUM_MAP< T > & Instance()
FONT is an abstract base class for both outline and stroke fonts.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
virtual bool IsStroke() const
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
const wxString & GetName() const
virtual bool IsOutline() const
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
virtual double GetInterline(double aGlyphHeight, const METRICS &aFontMetrics) const =0
Compute the distance (interline) between 2 lines of text (for multiline texts).
static const METRICS & Default()
Class OUTLINE_FONT implements outline font drawing.
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) const
A color representation with 4 components: red, green, blue, alpha.
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
const wxString & GetDefaultFont() const
wxDC * GetPrintDC() const
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Provide class metadata.Helper macro to map type hashes to names.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
void Append(int aX, int aY)
Append a new point at the end of the polygon.
int Compare(const TEXT_ATTRIBUTES &aRhs) const
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
static constexpr EDA_ANGLE ANGLE_0
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
static struct EDA_TEXT_DESC _EDA_TEXT_DESC
#define TEXT_MIN_SIZE_MILS
Minimum text size in mils.
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
#define TEXT_MAX_SIZE_MILS
Maximum text size in mils (10 inches)
static constexpr double ITALIC_TILT
Tilt factor for italic style (this is the scaling factor on dY relative coordinates to give a tilted ...
FONTCONFIG * Fontconfig()
int GetPenSizeForBold(int aTextSize)
int GetPenSizeForNormal(int aTextSize)
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
void GRPrintText(wxDC *aDC, const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Print a graphic text through wxDC.
Some functions to handle hotkeys in KiCad.
constexpr int Mils2IU(const EDA_IU_SCALE &aIuScale, int mils)
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
T clamp(T min, T value, T max)
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
wxString UnescapeString(const wxString &aSource)
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
@ GR_TEXT_H_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_INDETERMINATE
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".