2013-05-26 04:36:44 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-10-25 19:50:33 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-04-04 19:28:34 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EDA_TEXT_H_
|
|
|
|
#define EDA_TEXT_H_
|
|
|
|
|
2020-10-15 07:33:14 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-10-15 23:33:18 +00:00
|
|
|
#include <outline_mode.h>
|
2022-08-05 02:40:38 +00:00
|
|
|
#include <eda_search_data.h>
|
2022-01-04 23:00:00 +00:00
|
|
|
#include <font/glyph.h>
|
2021-12-28 22:13:54 +00:00
|
|
|
#include <font/text_attributes.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2020-10-15 01:04:41 +00:00
|
|
|
class OUTPUTFORMATTER;
|
2020-09-19 11:47:43 +00:00
|
|
|
class SHAPE_COMPOUND;
|
2018-08-23 22:41:57 +00:00
|
|
|
class SHAPE_POLY_SET;
|
|
|
|
|
2021-10-25 19:50:33 +00:00
|
|
|
|
2023-06-03 15:59:00 +00:00
|
|
|
// These are only here for algorithmic safety, not to tell the user what to do
|
|
|
|
#define TEXT_MIN_SIZE_MILS 1 ///< Minimum text size in mils
|
|
|
|
#define TEXT_MAX_SIZE_MILS 10000 ///< Maximum text size in mils (10 inches)
|
|
|
|
|
|
|
|
|
2020-10-14 11:29:36 +00:00
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class RENDER_SETTINGS;
|
|
|
|
class COLOR4D;
|
|
|
|
}
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
namespace KIFONT
|
|
|
|
{
|
|
|
|
class METRICS;
|
|
|
|
}
|
|
|
|
|
2020-04-13 19:55:27 +00:00
|
|
|
using KIGFX::RENDER_SETTINGS;
|
2020-10-14 02:46:39 +00:00
|
|
|
using KIGFX::COLOR4D;
|
2020-04-13 19:55:27 +00:00
|
|
|
|
2017-01-27 21:44:41 +00:00
|
|
|
// part of the kicad_plugin.h family of defines.
|
2017-01-29 08:29:49 +00:00
|
|
|
// See kicad_plugin.h for the choice of the value
|
|
|
|
// When set when calling EDA_TEXT::Format, disable writing the "hide" keyword in save file
|
|
|
|
#define CTL_OMIT_HIDE (1 << 6)
|
2017-01-27 21:44:41 +00:00
|
|
|
|
|
|
|
|
2020-01-03 14:29:19 +00:00
|
|
|
/**
|
2023-08-06 19:20:53 +00:00
|
|
|
* This is the "default-of-the-default" hardcoded text size; individual application define their
|
|
|
|
* own default policy starting with this (usually with a user option or project).
|
2020-01-03 14:29:19 +00:00
|
|
|
*/
|
|
|
|
#define DEFAULT_SIZE_TEXT 50 // default text height (in mils, i.e. 1/1000")
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
2020-12-18 14:04:03 +00:00
|
|
|
* 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.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
|
|
|
class EDA_TEXT
|
|
|
|
{
|
|
|
|
public:
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_TEXT( const EDA_IU_SCALE& aIuScale, const wxString& aText = wxEmptyString );
|
2016-05-30 08:36:07 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
EDA_TEXT( const EDA_TEXT& aText );
|
2016-05-30 08:36:07 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
virtual ~EDA_TEXT();
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
EDA_TEXT& operator=( const EDA_TEXT& aItem );
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
2020-01-03 14:29:19 +00:00
|
|
|
* Return the string associated with the text object.
|
2014-09-13 18:15:45 +00:00
|
|
|
*
|
|
|
|
* @return a const wxString reference containing the string of the item.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2019-08-02 00:10:25 +00:00
|
|
|
virtual const wxString& GetText() const { return m_text; }
|
2014-09-13 18:15:45 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-06 13:06:57 +00:00
|
|
|
* Return the string actually shown after processing of the base text.
|
2020-12-18 14:04:03 +00:00
|
|
|
*
|
2022-10-22 10:50:26 +00:00
|
|
|
* @param aAllowExtraText is true to allow adding more text than the initial expanded text,
|
|
|
|
* for intance a title, a prefix for texts in display functions.
|
|
|
|
* False to disable any added text (for instance when writing the shown text in netlists).
|
2023-05-05 13:21:56 +00:00
|
|
|
* @param aDepth is used to prevent infinite recursions and loops when expanding
|
|
|
|
* text variables.
|
2020-01-03 14:29:19 +00:00
|
|
|
*/
|
2023-05-05 13:21:56 +00:00
|
|
|
virtual wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const
|
2023-04-04 19:28:34 +00:00
|
|
|
{
|
|
|
|
return m_shown_text;
|
|
|
|
}
|
2014-09-13 18:15:45 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-29 12:54:40 +00:00
|
|
|
* Indicates the ShownText has text var references which need to be processed.
|
2020-01-03 14:29:19 +00:00
|
|
|
*/
|
2021-06-29 12:54:40 +00:00
|
|
|
bool HasTextVars() const { return m_shown_text_has_text_var_refs; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2019-04-25 04:14:25 +00:00
|
|
|
virtual void SetText( const wxString& aText );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-14 12:25:00 +00:00
|
|
|
* The TextThickness is that set by the user. The EffectiveTextPenWidth also factors
|
|
|
|
* in bold text and thickness clamping.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetTextThickness( int aWidth );
|
2022-02-01 11:19:09 +00:00
|
|
|
int GetTextThickness() const { return m_attributes.m_StrokeWidth; };
|
2020-04-30 06:59:43 +00:00
|
|
|
|
|
|
|
/**
|
2022-06-03 21:30:43 +00:00
|
|
|
* The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
|
2020-04-30 06:59:43 +00:00
|
|
|
*/
|
2022-06-03 21:30:43 +00:00
|
|
|
int GetEffectiveTextPenWidth( int aDefaultPenWidth = 0 ) const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-13 20:23:38 +00:00
|
|
|
virtual void SetTextAngle( const EDA_ANGLE& aAngle );
|
2021-12-28 22:13:54 +00:00
|
|
|
const EDA_ANGLE& GetTextAngle() const { return m_attributes.m_Angle; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-12-03 02:33:21 +00:00
|
|
|
// For property system:
|
|
|
|
void SetTextAngleDegrees( double aOrientation )
|
|
|
|
{
|
|
|
|
SetTextAngle( EDA_ANGLE( aOrientation, DEGREES_T ) );
|
|
|
|
}
|
|
|
|
double GetTextAngleDegrees() const { return m_attributes.m_Angle.AsDegrees(); }
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetItalic( bool aItalic );
|
2021-12-28 22:13:54 +00:00
|
|
|
bool IsItalic() const { return m_attributes.m_Italic; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetBold( bool aBold );
|
2021-12-28 22:13:54 +00:00
|
|
|
bool IsBold() const { return m_attributes.m_Bold; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
virtual void SetVisible( bool aVisible );
|
2021-12-28 22:13:54 +00:00
|
|
|
virtual bool IsVisible() const { return m_attributes.m_Visible; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetMirrored( bool isMirrored );
|
2021-12-28 22:13:54 +00:00
|
|
|
bool IsMirrored() const { return m_attributes.m_Mirrored; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
/**
|
2020-12-18 14:04:03 +00:00
|
|
|
* @param aAllow true if ok to use multiline option, false if ok to use only single line
|
|
|
|
* text. (Single line is faster in calculations than multiline.)
|
2017-01-23 20:30:11 +00:00
|
|
|
*/
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetMultilineAllowed( bool aAllow );
|
2021-12-28 22:13:54 +00:00
|
|
|
bool IsMultilineAllowed() const { return m_attributes.m_Multiline; }
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetHorizJustify( GR_TEXT_H_ALIGN_T aType );
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_H_ALIGN_T GetHorizJustify() const { return m_attributes.m_Halign; };
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetVertJustify( GR_TEXT_V_ALIGN_T aType );
|
|
|
|
GR_TEXT_V_ALIGN_T GetVertJustify() const { return m_attributes.m_Valign; };
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetKeepUpright( bool aKeepUpright );
|
2021-12-29 17:31:40 +00:00
|
|
|
bool IsKeepUpright() const { return m_attributes.m_KeepUpright; }
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
2021-12-28 22:13:54 +00:00
|
|
|
* Set the text attributes from another instance.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2023-09-07 16:09:53 +00:00
|
|
|
void SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition = true );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-28 22:13:54 +00:00
|
|
|
* Swap the text attributes of the two involved instances.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2021-12-28 22:13:54 +00:00
|
|
|
void SwapAttributes( EDA_TEXT& aTradingPartner );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
void SwapText( EDA_TEXT& aTradingPartner );
|
|
|
|
|
2019-09-27 18:57:14 +00:00
|
|
|
void CopyText( const EDA_TEXT& aSrc );
|
|
|
|
|
2022-06-03 17:47:03 +00:00
|
|
|
void SetAttributes( const TEXT_ATTRIBUTES& aTextAttrs ) { m_attributes = aTextAttrs; }
|
2021-12-31 14:07:24 +00:00
|
|
|
const TEXT_ATTRIBUTES& GetAttributes() const { return m_attributes; }
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
/**
|
2020-01-03 14:29:19 +00:00
|
|
|
* Helper function used in search and replace dialog.
|
|
|
|
*
|
|
|
|
* Perform a text replace using the find and replace criteria in \a aSearchData.
|
2019-08-02 00:10:25 +00:00
|
|
|
*
|
2022-08-05 02:40:38 +00:00
|
|
|
* @param aSearchData A reference to a EDA_SEARCH_DATA object containing the
|
2019-08-02 00:10:25 +00:00
|
|
|
* search and replace criteria.
|
|
|
|
* @return True if the text item was modified, otherwise false.
|
|
|
|
*/
|
2022-08-05 02:40:38 +00:00
|
|
|
bool Replace( const EDA_SEARCH_DATA& aSearchData );
|
2019-08-02 00:10:25 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
bool IsDefaultFormatting() const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetFont( KIFONT::FONT* aFont );
|
2021-12-29 17:31:40 +00:00
|
|
|
KIFONT::FONT* GetFont() const { return m_attributes.m_Font; }
|
|
|
|
|
|
|
|
wxString GetFontName() const;
|
|
|
|
|
2023-11-01 00:38:43 +00:00
|
|
|
void SetFontIndex( int aIdx );
|
|
|
|
int GetFontIndex() const;
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetLineSpacing( double aLineSpacing );
|
2021-12-29 17:31:40 +00:00
|
|
|
double GetLineSpacing() const { return m_attributes.m_LineSpacing; }
|
|
|
|
|
2023-06-12 21:33:55 +00:00
|
|
|
void SetTextSize( VECTOR2I aNewSize );
|
2022-05-14 12:12:03 +00:00
|
|
|
VECTOR2I GetTextSize() const { return m_attributes.m_Size; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetTextWidth( int aWidth );
|
2021-12-28 22:13:54 +00:00
|
|
|
int GetTextWidth() const { return m_attributes.m_Size.x; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetTextHeight( int aHeight );
|
2021-12-28 22:13:54 +00:00
|
|
|
int GetTextHeight() const { return m_attributes.m_Size.y; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
void SetTextColor( const COLOR4D& aColor ) { m_attributes.m_Color = aColor; }
|
|
|
|
COLOR4D GetTextColor() const { return m_attributes.m_Color; }
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetTextPos( const VECTOR2I& aPoint );
|
2021-12-29 21:30:11 +00:00
|
|
|
const VECTOR2I& GetTextPos() const { return m_pos; }
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void SetTextX( int aX );
|
|
|
|
void SetTextY( int aY );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void Offset( const VECTOR2I& aOffset );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void Empty();
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
static GR_TEXT_H_ALIGN_T MapHorizJustify( int aHorizJustify );
|
|
|
|
static GR_TEXT_V_ALIGN_T MapVertJustify( int aVertJustify );
|
2019-06-30 22:06:34 +00:00
|
|
|
|
2020-01-03 14:29:19 +00:00
|
|
|
/**
|
|
|
|
* Print this text object to the device context \a aDC.
|
|
|
|
*
|
2020-12-18 14:04:03 +00:00
|
|
|
* @param aDC the current Device Context.
|
|
|
|
* @param aOffset draw offset (usually (0,0)).
|
|
|
|
* @param aColor text color.
|
|
|
|
* @param aDisplay_mode #FILLED or #SKETCH.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2023-08-06 19:20:53 +00:00
|
|
|
void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, const COLOR4D& aColor,
|
|
|
|
OUTLINE_MODE aDisplay_mode = FILLED );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2022-03-09 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* build a list of segments (SHAPE_SEGMENT) to describe a text shape.
|
|
|
|
* @param aTriangulate: true to build also the triangulation of each shape
|
|
|
|
* @param aUseTextRotation: true to use the actual text draw rotation.
|
|
|
|
* false to build a list of shape for a not rotated text ("native" shapes).
|
|
|
|
*/
|
|
|
|
std::shared_ptr<SHAPE_COMPOUND> GetEffectiveTextShape( bool aTriangulate = true,
|
2023-10-03 13:35:46 +00:00
|
|
|
const BOX2I& aBBox = BOX2I(),
|
|
|
|
const EDA_ANGLE& aAngle = ANGLE_0 ) const;
|
2020-07-15 16:22:56 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
|
|
|
* Test if \a aPoint is within the bounds of this object.
|
2020-01-03 14:29:19 +00:00
|
|
|
*
|
2022-01-01 18:08:03 +00:00
|
|
|
* @param aPoint A VECTOR2I to test.
|
2020-12-18 14:04:03 +00:00
|
|
|
* @param aAccuracy Amount to inflate the bounding box.
|
|
|
|
* @return true if a hit, else false.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
virtual bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2020-01-03 14:29:19 +00:00
|
|
|
* Test if object bounding box is contained within or intersects \a aRect.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
2020-12-18 14:04:03 +00:00
|
|
|
* @param aRect Rect to test against.
|
|
|
|
* @param aContains Test for containment instead of intersection if true.
|
|
|
|
* @param aAccuracy Amount to inflate the bounding box.
|
|
|
|
* @return true if a hit, else false.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2022-08-31 09:33:46 +00:00
|
|
|
virtual bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-13 19:55:27 +00:00
|
|
|
* Useful in multiline texts to calculate the full text or a line area (for zones filling,
|
|
|
|
* locate functions....)
|
2020-12-18 14:04:03 +00:00
|
|
|
*
|
2020-04-13 19:55:27 +00:00
|
|
|
* @param aLine The line of text to consider. Pass -1 for all lines.
|
2013-05-26 04:36:44 +00:00
|
|
|
* @param aInvertY Invert the Y axis when calculating bounding box.
|
2020-04-13 19:55:27 +00:00
|
|
|
* @return 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
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I GetTextBox( int aLine = -1, bool aInvertY = false ) const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-13 23:47:05 +00:00
|
|
|
* 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.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2019-08-03 23:03:35 +00:00
|
|
|
int GetInterline() const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-18 14:04:03 +00:00
|
|
|
* @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic).
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2020-10-27 11:03:35 +00:00
|
|
|
wxString GetTextStyleName() const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2013-11-29 08:13:43 +00:00
|
|
|
/**
|
2020-12-18 14:04:03 +00:00
|
|
|
* Populate \a aPositions with the position of each line of a multiline text, according
|
|
|
|
* to the vertical justification and the rotation of the whole text.
|
2020-01-03 14:29:19 +00:00
|
|
|
*
|
2022-01-01 18:08:03 +00:00
|
|
|
* @param aPositions is the list to populate by the VECTOR2I positions.
|
2020-12-18 14:04:03 +00:00
|
|
|
* @param aLineCount is the number of lines (not recalculated here for efficiency reasons.
|
2013-11-29 08:13:43 +00:00
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
void GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const;
|
2020-12-18 14:04:03 +00:00
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
/**
|
|
|
|
* Return the levenstein distance between two texts.
|
|
|
|
*
|
|
|
|
* Return a value of 0.0 - 1.0 where 1.0 is a perfect match.
|
|
|
|
*/
|
|
|
|
double Levenshtein( const EDA_TEXT& aOther ) const;
|
|
|
|
|
|
|
|
|
|
|
|
double Similarity( const EDA_TEXT& aOther ) const;
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
2020-01-03 14:29:19 +00:00
|
|
|
* Output the object to \a aFormatter in s-expression form.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* @param aFormatter The #OUTPUTFORMATTER object to write to.
|
|
|
|
* @param aNestLevel The indentation next level.
|
|
|
|
* @param aControlBits The control bit definition for object specific formatting.
|
|
|
|
* @throw IO_ERROR on write error.
|
|
|
|
*/
|
2017-06-08 21:47:21 +00:00
|
|
|
virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
virtual EDA_ANGLE GetDrawRotation() const { return GetTextAngle(); }
|
2022-01-04 23:00:00 +00:00
|
|
|
virtual VECTOR2I GetDrawPos() const { return GetTextPos(); }
|
2020-10-01 16:45:05 +00:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
virtual void ClearRenderCache();
|
|
|
|
virtual void ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
|
|
|
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
2022-10-22 20:32:10 +00:00
|
|
|
GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
|
|
|
|
const VECTOR2I& aOffset = { 0, 0 } ) const;
|
2022-01-04 23:00:00 +00:00
|
|
|
|
|
|
|
// Support for reading the cache from disk.
|
|
|
|
void SetupRenderCache( const wxString& aResolvedText, const EDA_ANGLE& aAngle );
|
|
|
|
void AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly );
|
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
int Compare( const EDA_TEXT* aOther ) const;
|
|
|
|
|
2023-04-04 19:28:34 +00:00
|
|
|
bool operator==( const EDA_TEXT& aRhs ) const { return Compare( &aRhs ) == 0; }
|
|
|
|
bool operator<( const EDA_TEXT& aRhs ) const { return Compare( &aRhs ) < 0; }
|
|
|
|
bool operator>( const EDA_TEXT& aRhs ) const { return Compare( &aRhs ) > 0; }
|
|
|
|
|
2022-05-14 13:52:53 +00:00
|
|
|
virtual bool HasHyperlink() const { return !m_hyperlink.IsEmpty(); }
|
|
|
|
wxString GetHyperlink() const { return m_hyperlink; }
|
|
|
|
void SetHyperlink( wxString aLink ) { m_hyperlink = aLink; }
|
|
|
|
void RemoveHyperlink() { m_hyperlink = wxEmptyString; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if aURL is a valid hyperlink.
|
|
|
|
*
|
|
|
|
* @param aURL String to validate
|
|
|
|
* @return true if aURL is a valid hyperlink
|
|
|
|
*/
|
|
|
|
static bool ValidateHyperlink( const wxString& aURL );
|
|
|
|
|
2022-07-03 15:19:55 +00:00
|
|
|
/**
|
2022-08-27 18:14:57 +00:00
|
|
|
* Check if aHref is a valid internal hyperlink.
|
2022-07-03 15:19:55 +00:00
|
|
|
*
|
2022-08-27 18:14:57 +00:00
|
|
|
* @param aHref String to validate
|
|
|
|
* @param aDestination [optional] pointer to populate with the destination page
|
|
|
|
* @return true if aHref is a valid internal hyperlink. Does *not* check if the destination
|
|
|
|
* page actually exists.
|
2022-07-03 15:19:55 +00:00
|
|
|
*/
|
2022-08-27 18:14:57 +00:00
|
|
|
static bool IsGotoPageHref( const wxString& aHref, wxString* aDestination = nullptr );
|
2022-07-03 15:19:55 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-27 18:14:57 +00:00
|
|
|
* Generate a href to a page in the current schematic.
|
|
|
|
*
|
|
|
|
* @param aDestination Destination sheet's page number.
|
|
|
|
* @return A hyperlink href string that goes to the specified page.
|
2022-07-03 15:19:55 +00:00
|
|
|
*/
|
2022-08-27 18:14:57 +00:00
|
|
|
static wxString GotoPageHref( const wxString& aDestination );
|
2022-07-03 15:19:55 +00:00
|
|
|
|
2022-05-14 13:52:53 +00:00
|
|
|
protected:
|
2022-10-22 20:32:10 +00:00
|
|
|
virtual KIFONT::FONT* getDrawFont() const;
|
2022-05-14 13:52:53 +00:00
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
virtual const KIFONT::METRICS& getFontMetrics() const;
|
|
|
|
|
2023-08-07 20:43:36 +00:00
|
|
|
virtual void cacheShownText();
|
2021-06-13 11:11:01 +00:00
|
|
|
|
2020-12-18 14:04:03 +00:00
|
|
|
/**
|
2021-12-28 22:13:54 +00:00
|
|
|
* Print each line of this EDA_TEXT.
|
2020-12-18 14:04:03 +00:00
|
|
|
*
|
|
|
|
* @param aOffset draw offset (usually (0,0)).
|
|
|
|
* @param aColor text color.
|
|
|
|
* @param aFillMode FILLED or SKETCH
|
|
|
|
* @param aText the single line of text to draw.
|
|
|
|
* @param aPos the position of this line ).
|
|
|
|
*/
|
2021-12-29 21:30:11 +00:00
|
|
|
void printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
|
2021-06-08 14:09:24 +00:00
|
|
|
const COLOR4D& aColor, OUTLINE_MODE aFillMode, const wxString& aText,
|
2021-12-29 21:30:11 +00:00
|
|
|
const VECTOR2I& aPos );
|
2020-12-18 14:04:03 +00:00
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* A hyperlink URL. If empty, this text object is not a hyperlink.
|
|
|
|
*/
|
|
|
|
wxString m_hyperlink;
|
|
|
|
|
|
|
|
private:
|
2022-01-07 17:42:43 +00:00
|
|
|
wxString m_text;
|
|
|
|
wxString m_shown_text; // Cache of unescaped text for efficient access
|
|
|
|
bool m_shown_text_has_text_var_refs;
|
2021-12-28 22:13:54 +00:00
|
|
|
|
2023-06-12 21:33:55 +00:00
|
|
|
std::reference_wrapper<const EDA_IU_SCALE> m_IuScale;
|
2022-09-16 04:38:10 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
mutable wxString m_render_cache_text;
|
2023-05-27 21:00:21 +00:00
|
|
|
mutable const KIFONT::FONT* m_render_cache_font;
|
2022-01-04 23:00:00 +00:00
|
|
|
mutable EDA_ANGLE m_render_cache_angle;
|
2022-04-25 22:22:45 +00:00
|
|
|
mutable VECTOR2I m_render_cache_offset;
|
2022-01-04 23:00:00 +00:00
|
|
|
mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_render_cache;
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
mutable bool m_bounding_box_cache_valid;
|
2022-01-30 10:52:52 +00:00
|
|
|
mutable VECTOR2I m_bounding_box_cache_pos;
|
2022-02-01 21:37:05 +00:00
|
|
|
mutable int m_bounding_box_cache_line;
|
|
|
|
mutable bool m_bounding_box_cache_inverted;
|
2022-08-31 16:17:14 +00:00
|
|
|
mutable BOX2I m_bounding_box_cache;
|
2022-01-07 17:42:43 +00:00
|
|
|
|
|
|
|
TEXT_ATTRIBUTES m_attributes;
|
|
|
|
VECTOR2I m_pos;
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-04-04 19:28:34 +00:00
|
|
|
extern std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aAttributes );
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct std::hash<EDA_TEXT>
|
|
|
|
{
|
|
|
|
std::size_t operator()( const EDA_TEXT& aText ) const
|
|
|
|
{
|
2023-04-06 12:48:02 +00:00
|
|
|
return hash_val( aText.GetText(), aText.GetAttributes(), aText.GetTextPos().x,
|
|
|
|
aText.GetTextPos().y );
|
2023-04-04 19:28:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
#endif // EDA_TEXT_H_
|