57#include <api/common/types/base_types.pb.h>
179 types::TextAttributes* attrs =
text.mutable_attributes();
182 attrs->set_visible(
true );
189 kiapi::common::types::Text
text;
191 aContainer.PackFrom(
text );
205 SetText( wxString(
text.text().c_str(), wxConvUTF8 ) );
209 if(
text.has_attributes() )
222 kiapi::common::types::Text
text;
224 if( !aContainer.UnpackTo( &
text ) )
274 return font->IsStroke();
428 penWidth = aDefaultPenWidth;
432 else if( penWidth <= 1 )
500 aEnforceMinTextSize =
false;
502 if( aEnforceMinTextSize )
507 aNewSize =
VECTOR2I( std::clamp( aNewSize.
x, min, max ), std::clamp( aNewSize.
y, min, max ) );
533 m_attributes.m_Size.y = std::clamp( aHeight, min, max );
560 if( aOffset.
x == 0 && aOffset.
y == 0 )
567 for( std::unique_ptr<KIFONT::GLYPH>& glyph :
m_render_cache->glyphs )
570 outline->Move( aOffset );
572 glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0,
ANGLE_0,
false, { 0, 0 } );
665std::vector<std::unique_ptr<KIFONT::GLYPH>>*
725 m_render_cache->glyphs.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
745 if( cache_it !=
m_bbox_cache.end() && cache_it->second.m_pos == drawPos )
746 return cache_it->second.m_bbox;
750 wxArrayString strings;
758 if( strings.GetCount() )
760 if( aLine >= 0 && ( aLine <
static_cast<int>( strings.GetCount() ) ) )
761 text = strings.Item( aLine );
763 text = strings.Item( 0 );
773 int overbarOffset = 0;
779 int fudgeFactor =
KiROUND( extents.
y * 0.17 );
782 textsize.
y += fudgeFactor;
787 pos.
y -= aLine * interline;
789 if(
text.Contains( wxT(
"~{" ) ) )
790 overbarOffset = extents.
y / 6;
797 for(
unsigned ii = 1; ii < strings.GetCount(); ii++ )
799 text = strings.Item( ii );
801 textsize.
x = std::max( textsize.
x, extents.
x );
806 textsize.
y += ( strings.GetCount() - 1 ) * interline;
809 textsize.
y += overbarOffset;
838 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
845 bbox.
Offset( 0, -fudgeFactor );
854 bbox.
Offset( 0, fudgeFactor );
858 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
896 std::vector<VECTOR2I> positions;
897 wxArrayString strings;
900 positions.reserve( strings.Count() );
904 for(
unsigned ii = 0; ii < strings.Count(); ii++ )
915 int aLineCount )
const
932 pos.
y -= ( aLineCount - 1 ) * offset.
y / 2;
936 pos.
y -= ( aLineCount - 1 ) * offset.
y;
940 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
951 for(
int ii = 0; ii < aLineCount; ii++ )
953 aPositions.push_back( (
VECTOR2I) pos );
960 const wxString& aText,
const VECTOR2I& aPos )
982 for(
const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
1010 wxString stylemsg[4] = {
_(
"Normal" ),
_(
"Italic" ),
_(
"Bold" ),
_(
"Bold+Italic" ) };
1012 return stylemsg[style];
1021 return wxEmptyString;
1028 return font->GetName();
1031 return _(
"Default Font" );
1041 if( aFontName ==
_(
"Default Font" ) )
1065 aFormatter->
Print(
"(effects" );
1067 aFormatter->
Print(
"(font" );
1070 aFormatter->
Print(
"(face %s)", aFormatter->
Quotew(
GetFont()->NameAsToken() ).c_str() );
1083 aFormatter->
Print(
"(thickness %s)",
1100 aFormatter->
Print(
")" );
1104 aFormatter->
Print(
"(justify" );
1113 aFormatter->
Print(
" mirror" );
1115 aFormatter->
Print(
")" );
1121 aFormatter->
Print(
")" );
1128 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
1138 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache =
nullptr;
1162 shape->AddShape(
new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1169 for(
const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
1170 triShape->
Append( point.x, point.y );
1172 shape->AddShape( triShape );
1187 shape->AddShape(
new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
1192 shape->AddShape( aPoly.Clone() );
1207 wxCHECK( aOther, 1 );
1217 if( pos.
x != otherPos.
x )
1218 return pos.
x - otherPos.
x;
1220 if( pos.
y != otherPos.
y )
1221 return pos.
y - otherPos.
y;
1239 return ( uri.Create( aURL ) && uri.HasScheme() );
1245 const wxString& str1 =
GetText();
1246 const wxString& str2 = aOther.
GetText();
1248 int m = str1.length();
1249 int n = str2.length();
1251 if( n == 0 || m == 0 )
1255 std::vector<std::vector<int>>
distance( m + 1, std::vector<int>( n + 1 ) );
1258 for(
int i = 0; i <= m; i++ )
1260 for(
int j = 0; j <= n; j++ )
1264 for(
int i = 1; i <= m; i++ )
1266 for(
int j = 1; j <= n; j++ )
1268 if( str1[i - 1] == str2[j - 1] )
1280 int maxLen = std::max( m, n );
1281 double similarity = 1.0 - (
static_cast<double>(
distance[m][n] ) / maxLen );
1289 double retval = 1.0;
1305 return aHref.StartsWith( wxT(
"#" ), aDestination );
1311 return wxT(
"#" ) + aDestination;
1332 if( h_inst.Choices().GetCount() == 0 )
1341 if( v_inst.Choices().GetCount() == 0 )
1354 const wxString textProps =
_HKI(
"Text Properties" );
1369 std::vector<std::string> fontNames;
1371 Fontconfig()->ListFonts( fontNames, std::string(
Pgm().GetLanguageTag().utf8_str() ),
1375 fonts.Add(
_(
"Default Font" ) );
1379 for(
const std::string& fontName : fontNames )
1380 fonts.Add( wxString( fontName ) );
1383 } ).SetIsCopyable();
constexpr EDA_IU_SCALE pcbIUScale
constexpr EDA_IU_SCALE unityScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr void SetOrigin(const Vec &pos)
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr coord_type GetY() const
constexpr size_type GetWidth() const
constexpr coord_type GetX() const
constexpr const Vec GetCenter() const
constexpr void SetSize(const SizeVec &size)
constexpr size_type GetHeight() const
constexpr bool Contains(const Vec &aPoint) const
constexpr void SetX(coord_type val)
constexpr BOX2< Vec > GetInflated(coord_type aDx, coord_type aDy) const
Get a new rectangle that is this one, inflated by aDx and aDy.
constexpr void SetY(coord_type val)
constexpr void Offset(coord_type dx, coord_type dy)
constexpr bool Intersects(const BOX2< Vec > &aRect) const
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
virtual const std::vector< wxString > * GetEmbeddedFonts()
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,...
std::unique_ptr< EDA_TEXT_RENDER_CACHE_DATA > m_render_cache
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
virtual VECTOR2I GetTextSize() const
void SetTextColor(const COLOR4D &aColor)
COLOR4D GetTextColor() const
wxString GetTextStyleName() const
virtual VECTOR2I GetTextPos() const
std::map< int, BBOX_CACHE_ENTRY > m_bbox_cache
bool IsDefaultFormatting() const
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
void SetFontProp(const wxString &aFontName)
wxString GetFontName() const
const std::vector< TEXT_VAR_REF_KEY > & GetTextVarReferences() const
Return the set of ${...} references extracted from the source text.
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
bool IsMultilineAllowed() const
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
virtual void SetTextPos(const VECTOR2I &aPoint)
virtual void SetTextX(int aX)
virtual int GetTextHeight() const
bool m_shown_text_has_text_var_refs
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
KIFONT::FONT * GetFont() const
bool ResolveFont(const std::vector< wxString > *aEmbeddedFonts)
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
void SetMirrored(bool isMirrored)
wxString GetFontProp() const
virtual void SetTextY(int aY)
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
virtual EDA_ANGLE GetDrawRotation() const
wxString m_unresolvedFontName
virtual VECTOR2I GetDrawPos() const
EDA_TEXT & operator=(const EDA_TEXT &aItem)
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
virtual bool HasHyperlink() const
virtual wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
Return the string actually shown after processing of the base text.
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
wxString GetHyperlink() const
virtual void Offset(const VECTOR2I &aOffset)
virtual int GetTextWidth() const
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetTextWidth(int aWidth)
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
void SetBoldFlag(bool aBold)
Set only the bold flag, without changing the font.
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
void SetupRenderCache(const wxString &aResolvedText, const KIFONT::FONT *aFont, const EDA_ANGLE &aAngle, const VECTOR2I &aOffset)
int Compare(const EDA_TEXT *aOther) const
std::reference_wrapper< const EDA_IU_SCALE > m_IuScale
std::mutex m_bbox_cacheMutex
virtual void SetVisible(bool aVisible)
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
void MigrateLegacyBoldStrokeWidth()
Migrate a pre-v11 bold stroke text so its stored thickness holds the base (non-bold) width.
virtual void ClearBoundingBoxCache()
bool GetAutoThickness() const
double GetLineSpacing() const
double Similarity(const EDA_TEXT &aOther) const
void SetLineSpacing(double aLineSpacing)
wxString EvaluateText(const wxString &aText) const
void AddRenderCacheGlyph(const SHAPE_POLY_SET &aPoly)
virtual 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.
virtual void SetTextHeight(int aHeight)
virtual void cacheShownText()
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
virtual void ClearRenderCache()
const TEXT_ATTRIBUTES & GetAttributes() const
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
static bool ValidateHyperlink(const wxString &aURL)
Check if aURL is a valid hyperlink.
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
void SetAutoThickness(bool aAuto)
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.
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor)
Print this text object to the device context aDC.
double GetTextAngleDegrees() const
void GetLinePositions(const RENDER_SETTINGS *aSettings, std::vector< VECTOR2I > &aPositions, int aLineCount) const
Populate aPositions with the position of each line of a multiline text, according to the vertical jus...
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.
bool isStrokeFont() const
Return true if this text is (or, while a font resolution is still pending, is named as) a stroke font...
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
int GetInterline(const RENDER_SETTINGS *aSettings) const
Return the distance between two lines of text.
int GetTextThicknessProperty() const
virtual int GetTextThickness() const
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)
std::vector< TEXT_VAR_REF_KEY > m_text_var_refs
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
void SwapText(EDA_TEXT &aTradingPartner)
void SetMultilineAllowed(bool aAllow)
void SetFont(KIFONT::FONT *aFont)
void printOneLineOfText(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, const wxString &aText, const VECTOR2I &aPos)
Print each line of this EDA_TEXT.
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
TEXT_ATTRIBUTES m_attributes
static ENUM_MAP< T > & Instance()
High-level wrapper for evaluating mathematical and string expressions in wxString format.
wxString Evaluate(const wxString &aInput)
Main evaluation function - processes input string and evaluates all} expressions.
Class that other classes need to inherit from, in order to be inspectable.
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, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=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, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) 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
void CacheTriangulation(bool aSimplify=false, const TASK_SUBMITTER &aSubmitter={}) override
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
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
std::unique_ptr< NODE > Parse()
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
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.
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
std::vector< TEXT_VAR_REF_KEY > ExtractTextVarReferences(const wxString &aSource)
Lex-scan aSource and return every ${...} reference that appears, without resolving.
#define CTL_OMIT_HYPERLINK
Omit the hyperlink attribute in .kicad_xxx files.
#define CTL_OMIT_COLOR
Omit the color attribute in .kicad_xxx files.
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
static constexpr EDA_ANGLE ANGLE_0
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
bool recursiveDescent(const std::unique_ptr< MARKUP::NODE > &aNode)
static struct EDA_TEXT_DESC _EDA_TEXT_DESC
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
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)
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.
int ClampTextPenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
constexpr double BOLD_STROKE_MULTIPLIER
Factor a bold stroke font applies to its base pen width.
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, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
void PackTextAttributes(types::TextAttributes &aOutput, const TEXT_ATTRIBUTES &aInput, const EDA_IU_SCALE &aScale)
void UnpackTextAttributes(TEXT_ATTRIBUTES &aOutput, const types::TextAttributes &aInput, const EDA_IU_SCALE &aScale)
PGM_BASE & Pgm()
The global program "get" accessor.
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
@ PT_DEGREE
Angle expressed in degrees.
@ PT_SIZE
Size expressed in distance units (mm/inch)
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
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...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_INDETERMINATE
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
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.
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
constexpr bool IsEeschemaType(const KICAD_T aType)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D