2012-06-10 20:47:15 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-03-11 13:08:34 +01:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-10 20:47:15 -04: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
|
|
|
|
*/
|
|
|
|
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <algorithm> // for max
|
|
|
|
#include <stddef.h> // for NULL
|
|
|
|
#include <type_traits> // for swap
|
2022-01-10 01:53:01 +00:00
|
|
|
#include <vector>
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2022-01-10 01:53:01 +00:00
|
|
|
#include <eda_item.h>
|
2019-01-07 21:42:50 -08:00
|
|
|
#include <base_units.h>
|
2022-01-10 01:53:01 +00:00
|
|
|
#include <callback_gal.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <eda_text.h> // for EDA_TEXT, TEXT_EFFECTS, GR_TEXT_VJUSTIF...
|
|
|
|
#include <gal/color4d.h> // for COLOR4D, COLOR4D::BLACK
|
2023-04-17 15:15:29 +01:00
|
|
|
#include <font/glyph.h>
|
2022-01-10 01:53:01 +00:00
|
|
|
#include <gr_text.h>
|
2021-07-29 10:56:22 +01:00
|
|
|
#include <string_utils.h> // for UnescapeString
|
2021-06-08 10:09:24 -04:00
|
|
|
#include <math/util.h> // for KiROUND
|
2022-01-10 01:53:01 +00:00
|
|
|
#include <math/vector2d.h>
|
2023-06-03 16:59:00 +01:00
|
|
|
#include <core/kicad_algo.h>
|
2020-10-24 08:44:03 -04:00
|
|
|
#include <richio.h>
|
2020-10-14 07:29:36 -04:00
|
|
|
#include <render_settings.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <trigo.h> // for RotatePoint
|
2020-10-16 16:51:24 +01:00
|
|
|
#include <i18n_utility.h>
|
2020-07-15 18:22:56 +02:00
|
|
|
#include <geometry/shape_segment.h>
|
|
|
|
#include <geometry/shape_compound.h>
|
2022-01-03 16:14:55 +00:00
|
|
|
#include <geometry/shape_simple.h>
|
|
|
|
#include <font/outline_font.h>
|
2021-10-25 15:50:33 -04:00
|
|
|
#include <geometry/shape_poly_set.h>
|
2023-03-04 12:13:12 -05:00
|
|
|
#include <properties/property_validators.h>
|
2025-02-11 12:55:33 +00:00
|
|
|
#include <ctl_flags.h>
|
2024-11-26 20:53:04 -05:00
|
|
|
#include <api/api_enums.h>
|
|
|
|
#include <api/api_utils.h>
|
|
|
|
#include <api/common/types/base_types.pb.h>
|
2020-07-15 18:22:56 +02:00
|
|
|
|
2020-11-23 11:43:22 +01:00
|
|
|
#include <wx/debug.h> // for wxASSERT
|
2022-01-10 01:53:01 +00:00
|
|
|
#include <wx/string.h>
|
2022-05-14 15:52:53 +02:00
|
|
|
#include <wx/url.h> // for wxURL
|
2024-11-27 18:12:53 +00:00
|
|
|
#include <io/kicad/kicad_io_utils.h>
|
2023-11-01 00:38:43 +00:00
|
|
|
#include "font/kicad_font_name.h"
|
|
|
|
#include "font/fontconfig.h"
|
|
|
|
#include "pgm_base.h"
|
2020-01-07 17:12:59 +00:00
|
|
|
|
|
|
|
class OUTPUTFORMATTER;
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2019-10-01 15:03:08 +01:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_H_ALIGN_T EDA_TEXT::MapHorizJustify( int aHorizJustify )
|
2019-06-30 23:06:34 +01:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
wxASSERT( aHorizJustify >= GR_TEXT_H_ALIGN_LEFT && aHorizJustify <= GR_TEXT_H_ALIGN_RIGHT );
|
2019-06-30 23:06:34 +01:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aHorizJustify > GR_TEXT_H_ALIGN_RIGHT )
|
|
|
|
return GR_TEXT_H_ALIGN_RIGHT;
|
2019-06-30 23:06:34 +01:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aHorizJustify < GR_TEXT_H_ALIGN_LEFT )
|
|
|
|
return GR_TEXT_H_ALIGN_LEFT;
|
2019-06-30 23:06:34 +01:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
return static_cast<GR_TEXT_H_ALIGN_T>( aHorizJustify );
|
2019-06-30 23:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_V_ALIGN_T EDA_TEXT::MapVertJustify( int aVertJustify )
|
2019-06-30 23:06:34 +01:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
wxASSERT( aVertJustify >= GR_TEXT_V_ALIGN_TOP && aVertJustify <= GR_TEXT_V_ALIGN_BOTTOM );
|
2019-06-30 23:06:34 +01:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aVertJustify > GR_TEXT_V_ALIGN_BOTTOM )
|
|
|
|
return GR_TEXT_V_ALIGN_BOTTOM;
|
2019-06-30 23:06:34 +01:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aVertJustify < GR_TEXT_V_ALIGN_TOP )
|
|
|
|
return GR_TEXT_V_ALIGN_TOP;
|
2019-06-30 23:06:34 +01:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
return static_cast<GR_TEXT_V_ALIGN_T>( aVertJustify );
|
2019-06-30 23:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_TEXT::EDA_TEXT( const EDA_IU_SCALE& aIuScale, const wxString& aText ) :
|
|
|
|
m_IuScale( aIuScale ),
|
2025-03-02 17:05:42 +00:00
|
|
|
m_text( aText ),
|
2025-02-11 12:55:33 +00:00
|
|
|
m_render_cache_font( nullptr ),
|
|
|
|
m_visible( true )
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2022-09-16 04:38:10 +00:00
|
|
|
SetTextSize( VECTOR2I( EDA_UNIT_UTILS::Mils2IU( m_IuScale, DEFAULT_SIZE_TEXT ),
|
|
|
|
EDA_UNIT_UTILS::Mils2IU( m_IuScale, DEFAULT_SIZE_TEXT ) ) );
|
2023-08-07 23:21:58 +01:00
|
|
|
|
|
|
|
if( m_text.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_shown_text = wxEmptyString;
|
|
|
|
m_shown_text_has_text_var_refs = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_shown_text = UnescapeString( m_text );
|
|
|
|
m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
|
|
|
|
}
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) :
|
|
|
|
m_IuScale( aText.m_IuScale )
|
2019-05-08 19:56:03 +01:00
|
|
|
{
|
2022-01-04 23:00:00 +00:00
|
|
|
m_text = aText.m_text;
|
|
|
|
m_shown_text = aText.m_shown_text;
|
|
|
|
m_shown_text_has_text_var_refs = aText.m_shown_text_has_text_var_refs;
|
|
|
|
|
|
|
|
m_attributes = aText.m_attributes;
|
|
|
|
m_pos = aText.m_pos;
|
2025-02-11 12:55:33 +00:00
|
|
|
m_visible = aText.m_visible;
|
2022-01-04 23:00:00 +00:00
|
|
|
|
2023-05-27 16:30:12 +01:00
|
|
|
m_render_cache_font = aText.m_render_cache_font;
|
2022-01-04 23:00:00 +00:00
|
|
|
m_render_cache_text = aText.m_render_cache_text;
|
|
|
|
m_render_cache_angle = aText.m_render_cache_angle;
|
2023-05-27 16:30:12 +01:00
|
|
|
m_render_cache_offset = aText.m_render_cache_offset;
|
2022-01-04 23:00:00 +00:00
|
|
|
|
|
|
|
m_render_cache.clear();
|
|
|
|
|
|
|
|
for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
|
|
|
|
{
|
2023-04-17 15:15:29 +01:00
|
|
|
if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
|
|
|
|
else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2025-01-14 12:24:04 +00:00
|
|
|
m_bbox_cache = aText.m_bbox_cache;
|
2024-12-27 18:58:55 +00:00
|
|
|
|
|
|
|
m_unresolvedFontName = aText.m_unresolvedFontName;
|
2019-05-08 19:56:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-10 20:47:15 -04:00
|
|
|
EDA_TEXT::~EDA_TEXT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
EDA_TEXT& EDA_TEXT::operator=( const EDA_TEXT& aText )
|
|
|
|
{
|
|
|
|
m_text = aText.m_text;
|
|
|
|
m_shown_text = aText.m_shown_text;
|
|
|
|
m_shown_text_has_text_var_refs = aText.m_shown_text_has_text_var_refs;
|
|
|
|
|
|
|
|
m_attributes = aText.m_attributes;
|
|
|
|
m_pos = aText.m_pos;
|
2025-02-11 12:55:33 +00:00
|
|
|
m_visible = aText.m_visible;
|
2022-01-04 23:00:00 +00:00
|
|
|
|
2023-05-27 16:30:12 +01:00
|
|
|
m_render_cache_font = aText.m_render_cache_font;
|
2022-01-04 23:00:00 +00:00
|
|
|
m_render_cache_text = aText.m_render_cache_text;
|
|
|
|
m_render_cache_angle = aText.m_render_cache_angle;
|
2023-05-27 16:30:12 +01:00
|
|
|
m_render_cache_offset = aText.m_render_cache_offset;
|
2022-01-04 23:00:00 +00:00
|
|
|
|
|
|
|
m_render_cache.clear();
|
|
|
|
|
|
|
|
for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aText.m_render_cache )
|
|
|
|
{
|
2023-04-17 15:15:29 +01:00
|
|
|
if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
|
|
|
|
else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_render_cache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
2025-01-14 12:24:04 +00:00
|
|
|
m_bbox_cache = aText.m_bbox_cache;
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2024-12-27 18:58:55 +00:00
|
|
|
m_unresolvedFontName = aText.m_unresolvedFontName;
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-11-26 20:53:04 -05:00
|
|
|
void EDA_TEXT::Serialize( google::protobuf::Any &aContainer ) const
|
|
|
|
{
|
|
|
|
using namespace kiapi::common;
|
|
|
|
types::Text text;
|
|
|
|
|
|
|
|
text.set_text( GetText().ToStdString() );
|
|
|
|
text.set_hyperlink( GetHyperlink().ToStdString() );
|
2024-11-30 17:21:52 -05:00
|
|
|
PackVector2( *text.mutable_position(), GetTextPos() );
|
2024-11-26 20:53:04 -05:00
|
|
|
|
|
|
|
types::TextAttributes* attrs = text.mutable_attributes();
|
|
|
|
|
|
|
|
if( GetFont() )
|
|
|
|
attrs->set_font_name( GetFont()->GetName().ToStdString() );
|
|
|
|
|
|
|
|
attrs->set_horizontal_alignment(
|
|
|
|
ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
|
|
|
|
|
|
|
|
attrs->set_vertical_alignment(
|
|
|
|
ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
|
|
|
|
|
|
|
|
attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
|
|
|
|
attrs->set_line_spacing( GetLineSpacing() );
|
|
|
|
attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
|
|
|
|
attrs->set_italic( IsItalic() );
|
|
|
|
attrs->set_bold( IsBold() );
|
|
|
|
attrs->set_underlined( GetAttributes().m_Underlined );
|
2025-02-20 17:41:04 +00:00
|
|
|
attrs->set_visible( true );
|
2024-11-26 20:53:04 -05:00
|
|
|
attrs->set_mirrored( IsMirrored() );
|
|
|
|
attrs->set_multiline( IsMultilineAllowed() );
|
|
|
|
attrs->set_keep_upright( IsKeepUpright() );
|
2024-11-30 17:21:52 -05:00
|
|
|
PackVector2( *attrs->mutable_size(), GetTextSize() );
|
2024-11-26 20:53:04 -05:00
|
|
|
|
|
|
|
aContainer.PackFrom( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDA_TEXT::Deserialize( const google::protobuf::Any &aContainer )
|
|
|
|
{
|
|
|
|
using namespace kiapi::common;
|
|
|
|
types::Text text;
|
|
|
|
|
|
|
|
if( !aContainer.UnpackTo( &text ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
|
|
|
|
SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
|
2024-11-30 17:21:52 -05:00
|
|
|
SetTextPos( UnpackVector2( text.position() ) );
|
2024-11-26 20:53:04 -05:00
|
|
|
|
|
|
|
if( text.has_attributes() )
|
|
|
|
{
|
|
|
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
|
|
|
|
|
|
|
attrs.m_Bold = text.attributes().bold();
|
|
|
|
attrs.m_Italic = text.attributes().italic();
|
|
|
|
attrs.m_Underlined = text.attributes().underlined();
|
|
|
|
attrs.m_Mirrored = text.attributes().mirrored();
|
|
|
|
attrs.m_Multiline = text.attributes().multiline();
|
|
|
|
attrs.m_KeepUpright = text.attributes().keep_upright();
|
2024-11-30 17:21:52 -05:00
|
|
|
attrs.m_Size = UnpackVector2( text.attributes().size() );
|
2024-11-26 20:53:04 -05:00
|
|
|
|
|
|
|
if( !text.attributes().font_name().empty() )
|
|
|
|
{
|
|
|
|
attrs.m_Font = KIFONT::FONT::GetFont(
|
|
|
|
wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
|
|
|
|
attrs.m_Italic );
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
|
|
|
|
attrs.m_LineSpacing = text.attributes().line_spacing();
|
|
|
|
attrs.m_StrokeWidth = text.attributes().stroke_width().value_nm();
|
|
|
|
attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
|
|
|
|
text.attributes().horizontal_alignment() );
|
|
|
|
|
|
|
|
attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
|
|
|
|
text.attributes().vertical_alignment() );
|
|
|
|
|
|
|
|
SetAttributes( attrs );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-25 00:14:25 -04:00
|
|
|
void EDA_TEXT::SetText( const wxString& aText )
|
|
|
|
{
|
2019-08-01 18:10:25 -06:00
|
|
|
m_text = aText;
|
2021-06-13 12:11:01 +01:00
|
|
|
cacheShownText();
|
2019-04-25 00:14:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-27 19:57:14 +01:00
|
|
|
void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
|
|
|
|
{
|
|
|
|
m_text = aSrc.m_text;
|
2023-08-07 23:21:58 +01:00
|
|
|
cacheShownText();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetTextThickness( int aWidth )
|
|
|
|
{
|
|
|
|
m_attributes.m_StrokeWidth = aWidth;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetTextAngle( const EDA_ANGLE& aAngle )
|
|
|
|
{
|
|
|
|
m_attributes.m_Angle = aAngle;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetItalic( bool aItalic )
|
2024-08-27 23:06:32 +01:00
|
|
|
{
|
|
|
|
if( m_attributes.m_Italic != aItalic )
|
|
|
|
{
|
|
|
|
const KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font || font->IsStroke() )
|
|
|
|
{
|
|
|
|
// For stroke fonts, just need to set the attribute.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For outline fonts, italic-ness is determined by the font itself.
|
|
|
|
SetFont( KIFONT::FONT::GetFont( font->GetName(), IsBold(), aItalic ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetItalicFlag( aItalic );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EDA_TEXT::SetItalicFlag( bool aItalic )
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
|
|
|
m_attributes.m_Italic = aItalic;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetBold( bool aBold )
|
2024-02-25 17:28:05 +00:00
|
|
|
{
|
|
|
|
if( m_attributes.m_Bold != aBold )
|
|
|
|
{
|
2024-08-27 23:06:32 +01:00
|
|
|
const KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font || font->IsStroke() )
|
|
|
|
{
|
|
|
|
// For stroke fonts, boldness is determined by the pen size.
|
|
|
|
const int size = std::min( m_attributes.m_Size.x, m_attributes.m_Size.y );
|
|
|
|
|
|
|
|
if( aBold )
|
2024-11-13 02:14:19 +00:00
|
|
|
{
|
|
|
|
m_attributes.m_StoredStrokeWidth = m_attributes.m_StrokeWidth;
|
2024-08-27 23:06:32 +01:00
|
|
|
m_attributes.m_StrokeWidth = GetPenSizeForBold( size );
|
2024-11-13 02:14:19 +00:00
|
|
|
}
|
2024-08-27 23:06:32 +01:00
|
|
|
else
|
2024-11-13 02:14:19 +00:00
|
|
|
{
|
2025-01-12 11:27:18 -05:00
|
|
|
// Restore the original stroke width from `m_StoredStrokeWidth` if it was
|
|
|
|
// previously stored, resetting the width after unbolding.
|
2024-11-13 02:14:19 +00:00
|
|
|
if( m_attributes.m_StoredStrokeWidth )
|
|
|
|
m_attributes.m_StrokeWidth = m_attributes.m_StoredStrokeWidth;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_attributes.m_StrokeWidth = GetPenSizeForNormal( size );
|
2025-01-12 11:27:18 -05:00
|
|
|
// Sets `m_StrokeWidth` to the normal pen size and stores it in
|
|
|
|
// `m_StoredStrokeWidth` as the default, but only if the bold option was
|
|
|
|
// applied before this feature was implemented.
|
2024-11-13 02:14:19 +00:00
|
|
|
m_attributes.m_StoredStrokeWidth = m_attributes.m_StrokeWidth;
|
|
|
|
}
|
|
|
|
}
|
2024-08-27 23:06:32 +01:00
|
|
|
}
|
2024-02-25 17:28:05 +00:00
|
|
|
else
|
2024-08-27 23:06:32 +01:00
|
|
|
{
|
|
|
|
// For outline fonts, boldness is determined by the font itself.
|
|
|
|
SetFont( KIFONT::FONT::GetFont( font->GetName(), aBold, IsItalic() ) );
|
|
|
|
}
|
2024-02-25 17:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetBoldFlag( aBold );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetBoldFlag( bool aBold )
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
|
|
|
m_attributes.m_Bold = aBold;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetVisible( bool aVisible )
|
|
|
|
{
|
2025-02-11 12:55:33 +00:00
|
|
|
m_visible = aVisible;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetMirrored( bool isMirrored )
|
|
|
|
{
|
|
|
|
m_attributes.m_Mirrored = isMirrored;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetMultilineAllowed( bool aAllow )
|
|
|
|
{
|
|
|
|
m_attributes.m_Multiline = aAllow;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetHorizJustify( GR_TEXT_H_ALIGN_T aType )
|
|
|
|
{
|
|
|
|
m_attributes.m_Halign = aType;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetVertJustify( GR_TEXT_V_ALIGN_T aType )
|
|
|
|
{
|
|
|
|
m_attributes.m_Valign = aType;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetKeepUpright( bool aKeepUpright )
|
|
|
|
{
|
|
|
|
m_attributes.m_KeepUpright = aKeepUpright;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2019-09-27 19:57:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-07 17:09:53 +01:00
|
|
|
void EDA_TEXT::SetAttributes( const EDA_TEXT& aSrc, bool aSetPosition )
|
2016-04-19 20:35:47 +02:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
m_attributes = aSrc.m_attributes;
|
2023-09-07 17:09:53 +01:00
|
|
|
|
|
|
|
if( aSetPosition )
|
|
|
|
m_pos = aSrc.m_pos;
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2017-01-23 14:30:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-01 18:10:25 -06:00
|
|
|
void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
|
|
|
|
{
|
|
|
|
std::swap( m_text, aTradingPartner.m_text );
|
2023-08-07 23:21:58 +01:00
|
|
|
cacheShownText();
|
2019-08-01 18:10:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
void EDA_TEXT::SwapAttributes( EDA_TEXT& aTradingPartner )
|
2017-01-23 14:30:11 -06:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
std::swap( m_attributes, aTradingPartner.m_attributes );
|
|
|
|
std::swap( m_pos, aTradingPartner.m_pos );
|
2022-01-04 23:00:00 +00:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
|
|
|
aTradingPartner.ClearRenderCache();
|
|
|
|
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
|
|
|
aTradingPartner.ClearBoundingBoxCache();
|
2016-04-19 20:35:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-03 22:30:43 +01:00
|
|
|
int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultPenWidth ) const
|
2020-04-13 20:55:27 +01:00
|
|
|
{
|
2022-06-03 22:30:43 +01:00
|
|
|
int penWidth = GetTextThickness();
|
2020-04-13 20:55:27 +01:00
|
|
|
|
2022-06-03 22:30:43 +01:00
|
|
|
if( penWidth <= 1 )
|
2020-04-14 13:25:00 +01:00
|
|
|
{
|
2022-06-03 22:30:43 +01:00
|
|
|
penWidth = aDefaultPenWidth;
|
2020-04-30 08:59:43 +02:00
|
|
|
|
2020-04-14 13:25:00 +01:00
|
|
|
if( IsBold() )
|
2022-06-03 22:30:43 +01:00
|
|
|
penWidth = GetPenSizeForBold( GetTextWidth() );
|
|
|
|
else if( penWidth <= 1 )
|
|
|
|
penWidth = GetPenSizeForNormal( GetTextWidth() );
|
2020-04-14 13:25:00 +01:00
|
|
|
}
|
2020-04-13 20:55:27 +01:00
|
|
|
|
|
|
|
// Clip pen size for small texts:
|
2025-01-12 11:27:18 -05:00
|
|
|
penWidth = ClampTextPenSize( penWidth, GetTextSize() );
|
2020-04-13 20:55:27 +01:00
|
|
|
|
2022-06-03 22:30:43 +01:00
|
|
|
return penWidth;
|
2020-04-13 20:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-04 22:40:38 -04:00
|
|
|
bool EDA_TEXT::Replace( const EDA_SEARCH_DATA& aSearchData )
|
2019-08-01 18:10:25 -06:00
|
|
|
{
|
2020-04-18 12:04:52 +01:00
|
|
|
bool retval = EDA_ITEM::Replace( aSearchData, m_text );
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2021-06-13 12:11:01 +01:00
|
|
|
cacheShownText();
|
2020-04-18 12:04:52 +01:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2020-04-18 12:04:52 +01:00
|
|
|
return retval;
|
2019-08-01 18:10:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void EDA_TEXT::SetFont( KIFONT::FONT* aFont )
|
|
|
|
{
|
|
|
|
m_attributes.m_Font = aFont;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-12-27 18:58:55 +00:00
|
|
|
bool EDA_TEXT::ResolveFont( const std::vector<wxString>* aEmbeddedFonts )
|
2024-12-24 20:06:06 +00:00
|
|
|
{
|
2024-12-27 18:58:55 +00:00
|
|
|
if( !m_unresolvedFontName.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_attributes.m_Font = KIFONT::FONT::GetFont( m_unresolvedFontName, IsBold(), IsItalic(),
|
|
|
|
aEmbeddedFonts );
|
|
|
|
|
|
|
|
if( !m_render_cache.empty() )
|
|
|
|
m_render_cache_font = m_attributes.m_Font;
|
|
|
|
|
|
|
|
m_unresolvedFontName = wxEmptyString;
|
|
|
|
return true;
|
|
|
|
}
|
2024-12-24 20:06:06 +00:00
|
|
|
|
2024-12-27 18:58:55 +00:00
|
|
|
return false;
|
2024-12-24 20:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
void EDA_TEXT::SetLineSpacing( double aLineSpacing )
|
|
|
|
{
|
|
|
|
m_attributes.m_LineSpacing = aLineSpacing;
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-07 16:46:27 +00:00
|
|
|
void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
2024-02-07 16:46:27 +00:00
|
|
|
// Plotting uses unityScale and independently scales the text. If we clamp here we'll
|
|
|
|
// clamp to *really* small values.
|
|
|
|
if( m_IuScale.get().IU_PER_MM == unityScale.IU_PER_MM )
|
|
|
|
aEnforceMinTextSize = false;
|
2023-06-12 22:33:55 +01:00
|
|
|
|
2024-02-07 16:46:27 +00:00
|
|
|
if( aEnforceMinTextSize )
|
|
|
|
{
|
2024-03-23 13:15:31 +00:00
|
|
|
int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
|
|
|
|
int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
|
2023-06-12 22:33:55 +01:00
|
|
|
|
2024-10-09 21:27:58 -06:00
|
|
|
aNewSize = VECTOR2I( std::clamp( aNewSize.x, min, max ),
|
|
|
|
std::clamp( aNewSize.y, min, max ) );
|
2023-06-12 22:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_attributes.m_Size = aNewSize;
|
2023-06-03 16:59:00 +01:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetTextWidth( int aWidth )
|
|
|
|
{
|
2024-03-23 13:15:31 +00:00
|
|
|
int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
|
|
|
|
int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
|
2023-06-03 16:59:00 +01:00
|
|
|
|
2024-10-09 21:27:58 -06:00
|
|
|
m_attributes.m_Size.x = std::clamp( aWidth, min, max );
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetTextHeight( int aHeight )
|
|
|
|
{
|
2024-03-23 13:15:31 +00:00
|
|
|
int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
|
|
|
|
int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
|
2023-06-03 16:59:00 +01:00
|
|
|
|
2024-10-09 21:27:58 -06:00
|
|
|
m_attributes.m_Size.y = std::clamp( aHeight, min, max );
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetTextPos( const VECTOR2I& aPoint )
|
|
|
|
{
|
|
|
|
Offset( VECTOR2I( aPoint.x - m_pos.x, aPoint.y - m_pos.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetTextX( int aX )
|
|
|
|
{
|
|
|
|
Offset( VECTOR2I( aX - m_pos.x, 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetTextY( int aY )
|
|
|
|
{
|
|
|
|
Offset( VECTOR2I( 0, aY - m_pos.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::Offset( const VECTOR2I& aOffset )
|
|
|
|
{
|
2023-05-26 23:03:14 +01:00
|
|
|
if( aOffset.x == 0 && aOffset.y == 0 )
|
|
|
|
return;
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
m_pos += aOffset;
|
|
|
|
|
|
|
|
for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_render_cache )
|
2023-04-17 15:15:29 +01:00
|
|
|
{
|
|
|
|
if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
|
|
|
|
outline->Move( aOffset );
|
|
|
|
else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
|
|
|
|
glyph = stroke->Transform( { 1.0, 1.0 }, aOffset, 0, ANGLE_0, false, { 0, 0 } );
|
|
|
|
}
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::Empty()
|
|
|
|
{
|
|
|
|
m_text.Empty();
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-13 12:11:01 +01:00
|
|
|
void EDA_TEXT::cacheShownText()
|
|
|
|
{
|
2022-02-20 18:55:55 +00:00
|
|
|
if( m_text.IsEmpty() )
|
2021-06-13 12:11:01 +01:00
|
|
|
{
|
|
|
|
m_shown_text = wxEmptyString;
|
|
|
|
m_shown_text_has_text_var_refs = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_shown_text = UnescapeString( m_text );
|
|
|
|
m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
|
|
|
|
}
|
2022-01-04 23:00:00 +00:00
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
ClearRenderCache();
|
2025-01-14 12:24:04 +00:00
|
|
|
ClearBoundingBoxCache();
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 21:32:10 +01:00
|
|
|
KIFONT::FONT* EDA_TEXT::getDrawFont() const
|
2022-01-07 00:47:23 +00:00
|
|
|
{
|
|
|
|
KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-06 20:20:53 +01:00
|
|
|
const KIFONT::METRICS& EDA_TEXT::getFontMetrics() const
|
|
|
|
{
|
|
|
|
return KIFONT::METRICS::Default();
|
|
|
|
}
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
|
|
|
|
void EDA_TEXT::ClearRenderCache()
|
|
|
|
{
|
|
|
|
m_render_cache.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::ClearBoundingBoxCache()
|
|
|
|
{
|
2025-01-14 12:24:04 +00:00
|
|
|
m_bbox_cache.clear();
|
2022-01-07 17:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
2022-10-22 21:32:10 +01:00
|
|
|
EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
|
|
|
|
const VECTOR2I& aOffset ) const
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
2023-05-26 23:03:14 +01:00
|
|
|
if( aFont->IsOutline() )
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
|
|
|
EDA_ANGLE resolvedAngle = GetDrawRotation();
|
|
|
|
|
|
|
|
if( m_render_cache.empty()
|
2023-05-27 16:30:12 +01:00
|
|
|
|| m_render_cache_font != aFont
|
2022-01-04 23:00:00 +00:00
|
|
|
|| m_render_cache_text != forResolvedText
|
2022-04-25 23:22:45 +01:00
|
|
|
|| m_render_cache_angle != resolvedAngle
|
|
|
|
|| m_render_cache_offset != aOffset )
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
|
|
|
m_render_cache.clear();
|
|
|
|
|
2023-05-27 16:30:12 +01:00
|
|
|
const KIFONT::OUTLINE_FONT* font = static_cast<const KIFONT::OUTLINE_FONT*>( aFont );
|
|
|
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
2022-01-04 23:00:00 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
attrs.m_Angle = resolvedAngle;
|
|
|
|
|
2023-05-05 14:21:56 +01:00
|
|
|
font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
|
2023-08-06 20:20:53 +01:00
|
|
|
attrs, getFontMetrics() );
|
2023-05-27 16:30:12 +01:00
|
|
|
m_render_cache_font = aFont;
|
2022-01-04 23:00:00 +00:00
|
|
|
m_render_cache_angle = resolvedAngle;
|
|
|
|
m_render_cache_text = forResolvedText;
|
2022-04-25 23:22:45 +01:00
|
|
|
m_render_cache_offset = aOffset;
|
2022-01-04 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &m_render_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-21 11:30:53 +01:00
|
|
|
void EDA_TEXT::SetupRenderCache( const wxString& aResolvedText, const KIFONT::FONT* aFont,
|
|
|
|
const EDA_ANGLE& aAngle, const VECTOR2I& aOffset )
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
|
|
|
m_render_cache_text = aResolvedText;
|
2024-05-21 11:30:53 +01:00
|
|
|
m_render_cache_font = aFont;
|
2022-01-04 23:00:00 +00:00
|
|
|
m_render_cache_angle = aAngle;
|
2024-05-21 11:30:53 +01:00
|
|
|
m_render_cache_offset = aOffset;
|
2022-01-04 23:00:00 +00:00
|
|
|
m_render_cache.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly )
|
|
|
|
{
|
|
|
|
m_render_cache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( aPoly ) );
|
2024-05-21 11:30:53 +01:00
|
|
|
static_cast<KIFONT::OUTLINE_GLYPH*>( m_render_cache.back().get() )->CacheTriangulation();
|
2021-06-13 12:11:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-03 17:03:35 -06:00
|
|
|
int EDA_TEXT::GetInterline() const
|
2013-10-25 14:16:18 +02:00
|
|
|
{
|
2023-08-06 20:20:53 +01:00
|
|
|
return KiROUND( getDrawFont()->GetInterline( GetTextHeight(), getFontMetrics() ) );
|
2013-10-25 14:16:18 +02:00
|
|
|
}
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2017-01-23 14:30:11 -06:00
|
|
|
|
2024-04-27 13:47:56 +01:00
|
|
|
BOX2I EDA_TEXT::GetTextBox( int aLine ) const
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
VECTOR2I drawPos = GetDrawPos();
|
|
|
|
|
2025-01-14 12:24:04 +00:00
|
|
|
auto cache_it = m_bbox_cache.find( aLine );
|
|
|
|
|
|
|
|
if( cache_it != m_bbox_cache.end() && cache_it->second.m_pos == drawPos )
|
|
|
|
return cache_it->second.m_bbox;
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2023-05-27 22:00:21 +01:00
|
|
|
BOX2I bbox;
|
|
|
|
wxArrayString strings;
|
|
|
|
wxString text = GetShownText( true );
|
|
|
|
int thickness = GetEffectiveTextPenWidth();
|
|
|
|
|
|
|
|
if( IsMultilineAllowed() )
|
|
|
|
{
|
|
|
|
wxStringSplit( text, strings, '\n' );
|
|
|
|
|
|
|
|
if( strings.GetCount() ) // GetCount() == 0 for void strings with multilines allowed
|
|
|
|
{
|
|
|
|
if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
|
|
|
|
text = strings.Item( aLine );
|
|
|
|
else
|
|
|
|
text = strings.Item( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate the H and V size
|
|
|
|
KIFONT::FONT* font = getDrawFont();
|
|
|
|
VECTOR2D fontSize( GetTextSize() );
|
|
|
|
bool bold = IsBold();
|
|
|
|
bool italic = IsItalic();
|
2023-08-06 20:20:53 +01:00
|
|
|
VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
|
|
|
|
getFontMetrics() );
|
2023-05-27 22:00:21 +01:00
|
|
|
int overbarOffset = 0;
|
|
|
|
|
|
|
|
// Creates bounding box (rectangle) for horizontal, left and top justified text. The
|
|
|
|
// bounding box will be moved later according to the actual text options
|
|
|
|
VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
|
|
|
|
VECTOR2I pos = drawPos;
|
2023-08-06 20:20:53 +01:00
|
|
|
int fudgeFactor = KiROUND( extents.y * 0.17 );
|
2023-05-27 22:00:21 +01:00
|
|
|
|
2023-05-27 23:41:43 +01:00
|
|
|
if( font->IsStroke() )
|
|
|
|
textsize.y += fudgeFactor;
|
|
|
|
|
2023-05-27 22:00:21 +01:00
|
|
|
if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
|
2023-08-06 20:20:53 +01:00
|
|
|
pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
|
2023-05-27 22:00:21 +01:00
|
|
|
|
|
|
|
if( text.Contains( wxT( "~{" ) ) )
|
2023-05-27 23:41:43 +01:00
|
|
|
overbarOffset = extents.y / 6;
|
2023-05-27 22:00:21 +01:00
|
|
|
|
|
|
|
bbox.SetOrigin( pos );
|
|
|
|
|
|
|
|
// for multiline texts and aLine < 0, merge all rectangles (aLine == -1 signals all lines)
|
2023-05-27 23:41:43 +01:00
|
|
|
if( IsMultilineAllowed() && aLine < 0 && strings.GetCount() > 1 )
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2023-05-27 22:00:21 +01:00
|
|
|
for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
text = strings.Item( ii );
|
2023-08-06 20:20:53 +01:00
|
|
|
extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
|
|
|
|
getFontMetrics() );
|
2023-05-27 22:00:21 +01:00
|
|
|
textsize.x = std::max( textsize.x, extents.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
// interline spacing is only *between* lines, so total height is the height of the first
|
|
|
|
// line plus the interline distance (with interline spacing) for all subsequent lines
|
2025-01-12 11:27:18 -05:00
|
|
|
textsize.y += KiROUND( ( strings.GetCount() - 1 )
|
|
|
|
* font->GetInterline( fontSize.y, getFontMetrics() ) );
|
2023-05-27 22:00:21 +01:00
|
|
|
}
|
|
|
|
|
2023-05-27 23:41:43 +01:00
|
|
|
textsize.y += overbarOffset;
|
|
|
|
|
2023-05-27 22:00:21 +01:00
|
|
|
bbox.SetSize( textsize );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point the rectangle origin is the text origin (m_Pos). This is correct only for
|
|
|
|
* left and top justified, non-mirrored, non-overbarred texts. Recalculate for all others.
|
|
|
|
*/
|
|
|
|
int italicOffset = IsItalic() ? KiROUND( fontSize.y * ITALIC_TILT ) : 0;
|
|
|
|
|
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
|
|
|
if( IsMirrored() )
|
|
|
|
bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
|
2025-01-12 11:27:18 -05:00
|
|
|
|
2023-05-27 22:00:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER:
|
|
|
|
bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) / 2 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
|
|
|
if( !IsMirrored() )
|
|
|
|
bbox.SetX( bbox.GetX() - ( bbox.GetWidth() - italicOffset ) );
|
|
|
|
break;
|
2024-02-16 12:54:28 +00:00
|
|
|
|
|
|
|
case GR_TEXT_H_ALIGN_INDETERMINATE:
|
|
|
|
wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
|
|
|
|
break;
|
2023-05-27 22:00:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( GetVertJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_V_ALIGN_TOP:
|
2023-05-28 18:17:24 +01:00
|
|
|
bbox.Offset( 0, -fudgeFactor );
|
2023-05-27 22:00:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER:
|
2023-05-27 23:41:43 +01:00
|
|
|
bbox.SetY( bbox.GetY() - bbox.GetHeight() / 2 );
|
2023-05-27 22:00:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM:
|
2023-05-27 23:41:43 +01:00
|
|
|
bbox.SetY( bbox.GetY() - bbox.GetHeight() );
|
2023-05-28 18:17:24 +01:00
|
|
|
bbox.Offset( 0, fudgeFactor );
|
2023-05-27 22:00:21 +01:00
|
|
|
break;
|
2024-02-16 12:54:28 +00:00
|
|
|
|
|
|
|
case GR_TEXT_V_ALIGN_INDETERMINATE:
|
|
|
|
wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
|
|
|
|
break;
|
2013-10-25 14:16:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-31 17:17:14 +01:00
|
|
|
bbox.Normalize(); // Make h and v sizes always >= 0
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2025-01-14 12:24:04 +00:00
|
|
|
m_bbox_cache[ aLine ] = { drawPos, bbox };
|
2022-01-07 17:42:43 +00:00
|
|
|
|
2022-08-31 17:17:14 +01:00
|
|
|
return bbox;
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 01:04:08 -05:00
|
|
|
bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2024-09-10 08:42:54 +01:00
|
|
|
const BOX2I rect = GetTextBox().GetInflated( aAccuracy );
|
|
|
|
const VECTOR2I location = GetRotated( aPoint, GetDrawPos(), -GetDrawRotation() );
|
2012-06-10 20:47:15 -04:00
|
|
|
return rect.Contains( location );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 10:33:46 +01:00
|
|
|
bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2024-09-10 08:42:54 +01:00
|
|
|
const BOX2I rect = aRect.GetInflated( aAccuracy );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
|
|
|
if( aContains )
|
2020-04-14 13:25:00 +01:00
|
|
|
return rect.Contains( GetTextBox() );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
return rect.Intersects( GetTextBox(), GetDrawRotation() );
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 01:04:08 -05:00
|
|
|
void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
|
2021-07-26 13:28:37 -04:00
|
|
|
const COLOR4D& aColor, OUTLINE_MODE aFillMode )
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2017-01-23 14:30:11 -06:00
|
|
|
if( IsMultilineAllowed() )
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2022-01-01 01:04:08 -05:00
|
|
|
std::vector<VECTOR2I> positions;
|
2015-01-15 21:01:53 +01:00
|
|
|
wxArrayString strings;
|
2023-05-05 14:21:56 +01:00
|
|
|
wxStringSplit( GetShownText( true ), strings, '\n' );
|
2017-01-23 14:30:11 -06:00
|
|
|
|
2015-01-15 21:01:53 +01:00
|
|
|
positions.reserve( strings.Count() );
|
2013-11-16 20:31:07 -05:00
|
|
|
|
2022-12-11 13:32:37 +00:00
|
|
|
GetLinePositions( positions, (int) strings.Count() );
|
2013-11-16 20:31:07 -05:00
|
|
|
|
2015-01-15 21:01:53 +01:00
|
|
|
for( unsigned ii = 0; ii < strings.Count(); ii++ )
|
2020-04-14 13:25:00 +01:00
|
|
|
printOneLineOfText( aSettings, aOffset, aColor, aFillMode, strings[ii], positions[ii] );
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
|
|
|
else
|
2020-04-14 13:25:00 +01:00
|
|
|
{
|
2023-05-05 14:21:56 +01:00
|
|
|
printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
|
|
|
|
GetDrawPos() );
|
2020-04-14 13:25:00 +01:00
|
|
|
}
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 01:04:08 -05:00
|
|
|
void EDA_TEXT::GetLinePositions( std::vector<VECTOR2I>& aPositions, int aLineCount ) const
|
2013-11-29 09:13:43 +01:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
VECTOR2I pos = GetDrawPos(); // Position of first line of the multiline text according
|
2022-01-01 01:04:08 -05:00
|
|
|
// to the center of the multiline text block
|
2013-11-29 09:13:43 +01:00
|
|
|
|
2022-01-01 01:04:08 -05:00
|
|
|
VECTOR2I offset; // Offset to next line.
|
2013-11-29 09:13:43 +01:00
|
|
|
|
|
|
|
offset.y = GetInterline();
|
|
|
|
|
|
|
|
if( aLineCount > 1 )
|
|
|
|
{
|
2017-01-23 14:30:11 -06:00
|
|
|
switch( GetVertJustify() )
|
2013-11-29 09:13:43 +01:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_TOP:
|
2013-11-29 09:13:43 +01:00
|
|
|
break;
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_CENTER:
|
2013-11-29 09:13:43 +01:00
|
|
|
pos.y -= ( aLineCount - 1 ) * offset.y / 2;
|
|
|
|
break;
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM:
|
2013-11-29 09:13:43 +01:00
|
|
|
pos.y -= ( aLineCount - 1 ) * offset.y;
|
|
|
|
break;
|
2024-02-16 12:54:28 +00:00
|
|
|
|
|
|
|
case GR_TEXT_V_ALIGN_INDETERMINATE:
|
|
|
|
wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
|
|
|
|
break;
|
2013-11-29 09:13:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 17:31:40 +00:00
|
|
|
// Rotate the position of the first line around the center of the multiline text block
|
2022-01-30 10:52:52 +00:00
|
|
|
RotatePoint( pos, GetDrawPos(), GetDrawRotation() );
|
2014-04-25 18:49:32 +02:00
|
|
|
|
2013-11-29 09:13:43 +01:00
|
|
|
// Rotate the offset lines to increase happened in the right direction
|
2022-01-30 10:52:52 +00:00
|
|
|
RotatePoint( offset, GetDrawRotation() );
|
2013-11-29 09:13:43 +01:00
|
|
|
|
|
|
|
for( int ii = 0; ii < aLineCount; ii++ )
|
|
|
|
{
|
2022-01-01 01:04:08 -05:00
|
|
|
aPositions.push_back( (VECTOR2I) pos );
|
2013-11-29 09:13:43 +01:00
|
|
|
pos += offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 17:31:40 +00:00
|
|
|
|
2021-12-29 16:30:11 -05:00
|
|
|
void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
|
2021-06-08 10:09:24 -04:00
|
|
|
const COLOR4D& aColor, OUTLINE_MODE aFillMode,
|
2021-12-29 16:30:11 -05:00
|
|
|
const wxString& aText, const VECTOR2I& aPos )
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2020-04-14 13:25:00 +01:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2022-06-18 09:30:54 +02:00
|
|
|
int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
|
|
|
if( aFillMode == SKETCH )
|
2020-04-14 13:25:00 +01:00
|
|
|
penWidth = -penWidth;
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2021-12-29 16:30:11 -05:00
|
|
|
VECTOR2I size = GetTextSize();
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2017-01-23 14:30:11 -06:00
|
|
|
if( IsMirrored() )
|
2012-06-10 20:47:15 -04:00
|
|
|
size.x = -size.x;
|
|
|
|
|
2022-10-22 21:32:10 +01:00
|
|
|
KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
|
2023-08-06 20:20:53 +01:00
|
|
|
GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-27 11:03:35 +00:00
|
|
|
wxString EDA_TEXT::GetTextStyleName() const
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
|
|
|
int style = 0;
|
|
|
|
|
2017-01-23 14:30:11 -06:00
|
|
|
if( IsItalic() )
|
2012-06-10 20:47:15 -04:00
|
|
|
style = 1;
|
|
|
|
|
2017-01-23 14:30:11 -06:00
|
|
|
if( IsBold() )
|
2012-06-10 20:47:15 -04:00
|
|
|
style += 2;
|
|
|
|
|
|
|
|
wxString stylemsg[4] = {
|
|
|
|
_("Normal"),
|
|
|
|
_("Italic"),
|
|
|
|
_("Bold"),
|
|
|
|
_("Bold+Italic")
|
|
|
|
};
|
|
|
|
|
|
|
|
return stylemsg[style];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 17:31:40 +00:00
|
|
|
wxString EDA_TEXT::GetFontName() const
|
|
|
|
{
|
|
|
|
if( GetFont() )
|
2022-04-26 18:52:53 +01:00
|
|
|
return GetFont()->GetName();
|
2021-12-29 17:31:40 +00:00
|
|
|
else
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-01 00:38:43 +00:00
|
|
|
int EDA_TEXT::GetFontIndex() const
|
|
|
|
{
|
|
|
|
if( !GetFont() )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if( GetFont()->GetName() == KICAD_FONT_NAME )
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
std::vector<std::string> fontNames;
|
|
|
|
Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < (int) fontNames.size(); ++ii )
|
|
|
|
{
|
|
|
|
if( fontNames[ii] == GetFont()->GetName() )
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_TEXT::SetFontIndex( int aIdx )
|
|
|
|
{
|
|
|
|
if( aIdx == -1 )
|
|
|
|
{
|
|
|
|
SetFont( nullptr );
|
|
|
|
}
|
|
|
|
else if( aIdx == -2 )
|
|
|
|
{
|
|
|
|
SetFont( KIFONT::FONT::GetFont( wxEmptyString, IsBold(), IsItalic() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<std::string> fontNames;
|
|
|
|
Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
|
|
|
|
|
2023-12-22 18:34:26 -05:00
|
|
|
if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
|
|
|
|
SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
|
|
|
|
else
|
|
|
|
SetFont( nullptr );
|
2023-11-01 00:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-10 20:47:15 -04:00
|
|
|
bool EDA_TEXT::IsDefaultFormatting() const
|
|
|
|
{
|
2025-02-11 12:55:33 +00:00
|
|
|
return ( !IsMirrored()
|
2021-12-28 22:13:54 +00:00
|
|
|
&& GetHorizJustify() == GR_TEXT_H_ALIGN_CENTER
|
|
|
|
&& GetVertJustify() == GR_TEXT_V_ALIGN_CENTER
|
2020-04-14 13:25:00 +01:00
|
|
|
&& GetTextThickness() == 0
|
2021-03-06 10:27:41 +01:00
|
|
|
&& !IsItalic()
|
|
|
|
&& !IsBold()
|
|
|
|
&& !IsMultilineAllowed()
|
2021-12-29 17:31:40 +00:00
|
|
|
&& GetFontName().IsEmpty()
|
2017-01-23 14:30:11 -06:00
|
|
|
);
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
|
|
|
|
2017-01-27 15:44:41 -06:00
|
|
|
|
2024-11-27 18:12:53 +00:00
|
|
|
void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aControlBits ) const
|
2012-06-10 20:47:15 -04:00
|
|
|
{
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(effects" );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(font" );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2022-04-26 18:52:53 +01:00
|
|
|
if( GetFont() && !GetFont()->GetName().IsEmpty() )
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(face %s)", aFormatter->Quotew( GetFont()->NameAsToken() ).c_str() );
|
2022-01-03 01:17:42 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
// Text size
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(size %s %s)",
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_UNIT_UTILS::FormatInternalUnits( m_IuScale, GetTextHeight() ).c_str(),
|
|
|
|
EDA_UNIT_UTILS::FormatInternalUnits( m_IuScale, GetTextWidth() ).c_str() );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2022-01-03 01:17:42 +00:00
|
|
|
if( GetLineSpacing() != 1.0 )
|
|
|
|
{
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(line_spacing %s)",
|
2022-09-16 23:35:16 -04:00
|
|
|
FormatDouble2Str( GetLineSpacing() ).c_str() );
|
2022-01-03 01:17:42 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 19:50:45 +01:00
|
|
|
if( GetTextThickness() )
|
2021-09-27 10:34:32 +01:00
|
|
|
{
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(thickness %s)",
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_UNIT_UTILS::FormatInternalUnits( m_IuScale, GetTextThickness() ).c_str() );
|
2021-09-27 10:34:32 +01:00
|
|
|
}
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2020-12-20 19:50:45 +01:00
|
|
|
if( IsBold() )
|
2024-11-27 18:12:53 +00:00
|
|
|
KICAD_FORMAT::FormatBool( aFormatter, "bold", true );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2020-12-20 19:50:45 +01:00
|
|
|
if( IsItalic() )
|
2024-11-27 18:12:53 +00:00
|
|
|
KICAD_FORMAT::FormatBool( aFormatter, "italic", true );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2024-07-14 20:45:40 +02:00
|
|
|
if( !( aControlBits & CTL_OMIT_COLOR ) && GetTextColor() != COLOR4D::UNSPECIFIED )
|
2022-03-31 19:43:08 +01:00
|
|
|
{
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(color %d %d %d %s)",
|
2022-03-31 19:43:08 +01:00
|
|
|
KiROUND( GetTextColor().r * 255.0 ),
|
|
|
|
KiROUND( GetTextColor().g * 255.0 ),
|
|
|
|
KiROUND( GetTextColor().b * 255.0 ),
|
2022-09-16 23:35:16 -04:00
|
|
|
FormatDouble2Str( GetTextColor().a ).c_str() );
|
2022-03-31 19:43:08 +01:00
|
|
|
}
|
|
|
|
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( ")"); // (font
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( IsMirrored() || GetHorizJustify() != GR_TEXT_H_ALIGN_CENTER
|
|
|
|
|| GetVertJustify() != GR_TEXT_V_ALIGN_CENTER )
|
2020-12-20 19:50:45 +01:00
|
|
|
{
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(justify");
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( GetHorizJustify() != GR_TEXT_H_ALIGN_CENTER )
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ? " left" : " right" );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( GetVertJustify() != GR_TEXT_V_ALIGN_CENTER )
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( GetVertJustify() == GR_TEXT_V_ALIGN_TOP ? " top" : " bottom" );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2020-12-20 19:50:45 +01:00
|
|
|
if( IsMirrored() )
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( " mirror" );
|
2021-06-08 10:09:24 -04:00
|
|
|
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( ")" ); // (justify
|
2020-12-20 19:50:45 +01:00
|
|
|
}
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2024-07-14 20:45:40 +02:00
|
|
|
if( !( aControlBits & CTL_OMIT_HYPERLINK ) && HasHyperlink() )
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( "(href %s)", aFormatter->Quotew( GetHyperlink() ).c_str() );
|
2012-06-10 20:47:15 -04:00
|
|
|
|
2024-11-27 18:12:53 +00:00
|
|
|
aFormatter->Print( ")" ); // (effects
|
2012-06-10 20:47:15 -04:00
|
|
|
}
|
2014-08-13 17:47:02 +02:00
|
|
|
|
2020-02-02 19:40:14 +01:00
|
|
|
|
2022-03-09 11:22:05 +01:00
|
|
|
std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
|
2023-10-03 14:35:46 +01:00
|
|
|
const BOX2I& aBBox,
|
|
|
|
const EDA_ANGLE& aAngle ) const
|
2020-07-15 18:22:56 +02:00
|
|
|
{
|
2020-10-31 15:13:30 -04:00
|
|
|
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
|
2022-01-10 14:03:53 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
2022-10-22 21:32:10 +01:00
|
|
|
KIFONT::FONT* font = getDrawFont();
|
2022-01-10 01:53:01 +00:00
|
|
|
int penWidth = GetEffectiveTextPenWidth();
|
2023-05-26 23:03:14 +01:00
|
|
|
wxString shownText( GetShownText( true ) );
|
|
|
|
VECTOR2I drawPos = GetDrawPos();
|
2022-03-08 13:16:39 +00:00
|
|
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
2022-03-12 10:53:20 +00:00
|
|
|
|
2023-05-26 23:03:14 +01:00
|
|
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
|
|
|
|
|
2023-10-03 14:35:46 +01:00
|
|
|
if( aBBox.GetWidth() )
|
2023-05-26 23:03:14 +01:00
|
|
|
{
|
2023-10-03 14:35:46 +01:00
|
|
|
drawPos = aBBox.GetCenter();
|
|
|
|
attrs.m_Halign = GR_TEXT_H_ALIGN_CENTER;
|
|
|
|
attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER;
|
|
|
|
attrs.m_Angle = aAngle;
|
2023-05-26 23:03:14 +01:00
|
|
|
}
|
2022-03-12 10:53:20 +00:00
|
|
|
else
|
2023-05-26 23:03:14 +01:00
|
|
|
{
|
2023-10-03 20:53:52 +01:00
|
|
|
attrs.m_Angle = GetDrawRotation();
|
|
|
|
|
|
|
|
if( font->IsOutline() )
|
|
|
|
cache = GetRenderCache( font, shownText, VECTOR2I() );
|
2023-05-26 23:03:14 +01:00
|
|
|
}
|
2020-07-15 18:22:56 +02:00
|
|
|
|
2022-03-08 13:16:39 +00:00
|
|
|
if( aTriangulate )
|
2022-02-25 04:44:59 -08:00
|
|
|
{
|
2022-03-08 13:16:39 +00:00
|
|
|
CALLBACK_GAL callback_gal(
|
|
|
|
empty_opts,
|
|
|
|
// Stroke callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
|
|
|
{
|
|
|
|
shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
|
|
|
|
},
|
|
|
|
// Triangulation callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
|
|
|
{
|
|
|
|
SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
|
|
|
|
|
|
|
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
|
|
|
triShape->Append( point.x, point.y );
|
|
|
|
|
|
|
|
shape->AddShape( triShape );
|
|
|
|
} );
|
|
|
|
|
2023-05-26 23:03:14 +01:00
|
|
|
if( cache )
|
|
|
|
callback_gal.DrawGlyphs( *cache );
|
|
|
|
else
|
2023-08-06 20:20:53 +01:00
|
|
|
font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
|
2022-03-08 13:16:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CALLBACK_GAL callback_gal(
|
|
|
|
empty_opts,
|
|
|
|
// Stroke callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
|
|
|
{
|
|
|
|
shape->AddShape( new SHAPE_SEGMENT( aPt1, aPt2, penWidth ) );
|
|
|
|
},
|
|
|
|
// Outline callback
|
2022-02-25 04:44:59 -08:00
|
|
|
[&]( const SHAPE_LINE_CHAIN& aPoly )
|
|
|
|
{
|
|
|
|
shape->AddShape( aPoly.Clone() );
|
|
|
|
} );
|
|
|
|
|
2023-05-26 23:03:14 +01:00
|
|
|
if( cache )
|
|
|
|
callback_gal.DrawGlyphs( *cache );
|
|
|
|
else
|
2023-08-06 20:20:53 +01:00
|
|
|
font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
|
2022-03-08 13:16:39 +00:00
|
|
|
}
|
2020-07-15 18:22:56 +02:00
|
|
|
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-14 21:03:32 +01:00
|
|
|
int EDA_TEXT::Compare( const EDA_TEXT* aOther ) const
|
|
|
|
{
|
2023-03-29 12:53:28 -04:00
|
|
|
wxCHECK( aOther, 1 );
|
2021-11-29 15:04:36 +00:00
|
|
|
|
2023-03-29 12:53:28 -04:00
|
|
|
int val = m_attributes.Compare( aOther->m_attributes );
|
2021-07-14 21:03:32 +01:00
|
|
|
|
2023-03-29 12:53:28 -04:00
|
|
|
if( val != 0 )
|
|
|
|
return val;
|
2021-07-14 21:03:32 +01:00
|
|
|
|
2023-03-29 12:53:28 -04:00
|
|
|
if( m_pos.x != aOther->m_pos.x )
|
|
|
|
return m_pos.x - aOther->m_pos.x;
|
2021-07-14 21:03:32 +01:00
|
|
|
|
2023-03-29 12:53:28 -04:00
|
|
|
if( m_pos.y != aOther->m_pos.y )
|
|
|
|
return m_pos.y - aOther->m_pos.y;
|
2021-07-14 21:03:32 +01:00
|
|
|
|
2023-03-29 12:53:28 -04:00
|
|
|
val = GetFontName().Cmp( aOther->GetFontName() );
|
2021-12-29 17:31:40 +00:00
|
|
|
|
|
|
|
if( val != 0 )
|
|
|
|
return val;
|
|
|
|
|
2021-07-14 21:03:32 +01:00
|
|
|
return m_text.Cmp( aOther->m_text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-14 15:52:53 +02:00
|
|
|
bool EDA_TEXT::ValidateHyperlink( const wxString& aURL )
|
|
|
|
{
|
2022-08-27 22:45:19 +01:00
|
|
|
if( aURL.IsEmpty() || IsGotoPageHref( aURL ) )
|
|
|
|
return true;
|
2022-05-14 15:52:53 +02:00
|
|
|
|
2022-08-27 22:45:19 +01:00
|
|
|
wxURI uri;
|
|
|
|
|
2024-05-06 12:21:56 -07:00
|
|
|
return( uri.Create( aURL ) && uri.HasScheme() );
|
2022-07-03 16:19:55 +01:00
|
|
|
}
|
|
|
|
|
2023-09-14 14:39:42 -07:00
|
|
|
double EDA_TEXT::Levenshtein( const EDA_TEXT& aOther ) const
|
|
|
|
{
|
|
|
|
// Compute the Levenshtein distance between the two strings
|
|
|
|
const wxString& str1 = GetText();
|
|
|
|
const wxString& str2 = aOther.GetText();
|
|
|
|
|
|
|
|
int m = str1.length();
|
|
|
|
int n = str2.length();
|
|
|
|
|
|
|
|
if( n == 0 || m == 0 )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
// Create a matrix to store the distance values
|
|
|
|
std::vector<std::vector<int>> distance(m + 1, std::vector<int>(n + 1));
|
|
|
|
|
|
|
|
// Initialize the matrix
|
|
|
|
for( int i = 0; i <= m; i++ )
|
|
|
|
distance[i][0] = i;
|
|
|
|
for( int j = 0; j <= n; j++ )
|
|
|
|
distance[0][j] = j;
|
|
|
|
|
|
|
|
// Calculate the distance
|
|
|
|
for( int i = 1; i <= m; i++ )
|
|
|
|
{
|
|
|
|
for( int j = 1; j <= n; j++ )
|
|
|
|
{
|
|
|
|
if( str1[i - 1] == str2[j - 1] )
|
|
|
|
{
|
|
|
|
distance[i][j] = distance[i - 1][j - 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
distance[i][j] = std::min( { distance[i - 1][j], distance[i][j - 1],
|
|
|
|
distance[i - 1][j - 1] } ) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate similarity score
|
|
|
|
int maxLen = std::max( m, n );
|
|
|
|
double similarity = 1.0 - ( static_cast<double>( distance[m][n] ) / maxLen );
|
|
|
|
|
|
|
|
return similarity;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double EDA_TEXT::Similarity( const EDA_TEXT& aOther ) const
|
|
|
|
{
|
|
|
|
double retval = 1.0;
|
|
|
|
|
|
|
|
if( !( m_attributes == aOther.m_attributes ) )
|
|
|
|
retval *= 0.9;
|
|
|
|
|
|
|
|
if( m_pos != aOther.m_pos )
|
|
|
|
retval *= 0.9;
|
|
|
|
|
|
|
|
retval *= Levenshtein( aOther );
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2022-07-03 16:19:55 +01:00
|
|
|
|
2022-08-27 19:14:57 +01:00
|
|
|
bool EDA_TEXT::IsGotoPageHref( const wxString& aHref, wxString* aDestination )
|
2022-07-03 16:19:55 +01:00
|
|
|
{
|
2022-08-27 19:14:57 +01:00
|
|
|
return aHref.StartsWith( wxT( "#" ), aDestination );
|
2022-07-03 16:19:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-27 19:14:57 +01:00
|
|
|
wxString EDA_TEXT::GotoPageHref( const wxString& aDestination )
|
2022-07-03 16:19:55 +01:00
|
|
|
{
|
2022-08-27 19:14:57 +01:00
|
|
|
return wxT( "#" ) + aDestination;
|
2022-05-14 15:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-04 15:28:34 -04:00
|
|
|
std::ostream& operator<<( std::ostream& aStream, const EDA_TEXT& aText )
|
|
|
|
{
|
|
|
|
aStream << aText.GetText();
|
|
|
|
|
|
|
|
return aStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-02 19:40:14 +01:00
|
|
|
static struct EDA_TEXT_DESC
|
|
|
|
{
|
|
|
|
EDA_TEXT_DESC()
|
|
|
|
{
|
2024-05-07 16:08:47 -07:00
|
|
|
// These are defined in SCH_FIELD as well but initialization order is
|
|
|
|
// not defined, so this needs to be conditional. Defining in both
|
|
|
|
// places leads to duplicate symbols.
|
|
|
|
auto& h_inst = ENUM_MAP<GR_TEXT_H_ALIGN_T>::Instance();
|
|
|
|
|
|
|
|
if( h_inst.Choices().GetCount() == 0)
|
|
|
|
{
|
|
|
|
h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
|
|
|
|
h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
|
|
|
|
h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& v_inst = ENUM_MAP<GR_TEXT_V_ALIGN_T>::Instance();
|
|
|
|
|
|
|
|
if( v_inst.Choices().GetCount() == 0)
|
|
|
|
{
|
|
|
|
v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
|
|
|
|
v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
|
|
|
|
v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
|
|
|
|
}
|
2020-02-02 19:40:14 +01:00
|
|
|
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( EDA_TEXT );
|
2022-11-27 22:40:14 -05:00
|
|
|
|
2022-12-02 21:33:21 -05:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, double>( _HKI( "Orientation" ),
|
|
|
|
&EDA_TEXT::SetTextAngleDegrees, &EDA_TEXT::GetTextAngleDegrees,
|
|
|
|
PROPERTY_DISPLAY::PT_DEGREE ) );
|
|
|
|
|
2024-02-28 17:50:51 +00:00
|
|
|
const wxString textProps = _HKI( "Text Properties" );
|
2022-11-27 22:40:14 -05:00
|
|
|
|
2020-10-16 16:51:24 +01:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Text" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetText, &EDA_TEXT::GetText ),
|
|
|
|
textProps );
|
2023-11-01 00:38:43 +00:00
|
|
|
|
2024-01-24 14:51:41 +00:00
|
|
|
// This must be a PROPERTY_ENUM to get a choice list.
|
|
|
|
// SCH_ and PCB_PROPERTIES_PANEL::updateFontList() fill in the enum values.
|
2023-11-01 00:38:43 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, int>( _HKI( "Font" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetFontIndex, &EDA_TEXT::GetFontIndex ),
|
|
|
|
textProps )
|
|
|
|
.SetIsHiddenFromRulesEditor();
|
2023-11-01 00:38:43 +00:00
|
|
|
|
2020-10-16 16:51:24 +01:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Thickness" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetTextThickness, &EDA_TEXT::GetTextThickness,
|
|
|
|
PROPERTY_DISPLAY::PT_SIZE ),
|
|
|
|
textProps );
|
2020-10-16 16:51:24 +01:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Italic" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetItalic,
|
|
|
|
&EDA_TEXT::IsItalic ),
|
|
|
|
textProps );
|
2020-10-16 16:51:24 +01:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Bold" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetBold, &EDA_TEXT::IsBold ),
|
|
|
|
textProps );
|
2020-10-16 16:51:24 +01:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Mirrored" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetMirrored, &EDA_TEXT::IsMirrored ),
|
|
|
|
textProps );
|
2025-04-05 22:09:41 +01:00
|
|
|
|
|
|
|
auto isField =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( aItem ) )
|
|
|
|
return item->Type() == SCH_FIELD_T || item->Type() == PCB_FIELD_T;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, bool>( _HKI( "Visible" ),
|
|
|
|
&EDA_TEXT::SetVisible, &EDA_TEXT::IsVisible ),
|
|
|
|
textProps )
|
|
|
|
.SetAvailableFunc( isField );
|
|
|
|
|
2020-10-16 16:51:24 +01:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Width" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetTextWidth, &EDA_TEXT::GetTextWidth,
|
|
|
|
PROPERTY_DISPLAY::PT_SIZE ),
|
|
|
|
textProps );
|
2023-03-04 12:13:12 -05:00
|
|
|
|
2020-10-16 16:51:24 +01:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetTextHeight, &EDA_TEXT::GetTextHeight,
|
|
|
|
PROPERTY_DISPLAY::PT_SIZE ),
|
|
|
|
textProps );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, GR_TEXT_H_ALIGN_T>(
|
|
|
|
_HKI( "Horizontal Justification" ),
|
|
|
|
&EDA_TEXT::SetHorizJustify, &EDA_TEXT::GetHorizJustify ),
|
|
|
|
textProps );
|
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT, GR_TEXT_V_ALIGN_T>(
|
|
|
|
_HKI( "Vertical Justification" ),
|
|
|
|
&EDA_TEXT::SetVertJustify, &EDA_TEXT::GetVertJustify ),
|
|
|
|
textProps );
|
2023-11-01 00:38:43 +00:00
|
|
|
|
2024-02-05 01:09:34 -05:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, COLOR4D>( _HKI( "Color" ),
|
|
|
|
&EDA_TEXT::SetTextColor, &EDA_TEXT::GetTextColor ),
|
|
|
|
textProps );
|
|
|
|
|
2023-11-01 00:38:43 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<EDA_TEXT, wxString>( _HKI( "Hyperlink" ),
|
2024-01-18 16:08:18 +00:00
|
|
|
&EDA_TEXT::SetHyperlink, &EDA_TEXT::GetHyperlink ),
|
|
|
|
textProps );
|
2020-02-02 19:40:14 +01:00
|
|
|
}
|
|
|
|
} _EDA_TEXT_DESC;
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
ENUM_TO_WXANY( GR_TEXT_H_ALIGN_T )
|
|
|
|
ENUM_TO_WXANY( GR_TEXT_V_ALIGN_T )
|