2012-06-11 00:47:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-03-11 12:08:34 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-01-29 08:29:49 +00:00
|
|
|
* Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors.
|
2012-06-11 00:47:15 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file eda_text.cpp
|
|
|
|
* @brief Implementation of base KiCad text object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <eda_text.h>
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <eda_rect.h>
|
2014-08-13 15:47:02 +00:00
|
|
|
#include <macros.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <trigo.h> // RotatePoint
|
|
|
|
|
2016-03-25 08:26:11 +00:00
|
|
|
#include <basic_gal.h>
|
2019-01-08 05:42:50 +00:00
|
|
|
#include <base_units.h>
|
2015-05-15 12:49:11 +00:00
|
|
|
#include <convert_to_biu.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2019-06-30 22:06:34 +00:00
|
|
|
// Sadly we store the orientation of hierarchical and global labels using a different
|
|
|
|
// int encoding than that for local labels:
|
|
|
|
// Global Local
|
|
|
|
// Left justified 0 2
|
|
|
|
// Up 1 3
|
|
|
|
// Right justified 2 0
|
|
|
|
// Down 3 1
|
|
|
|
int EDA_TEXT::MapOrientation( KICAD_T labelType, int aOrientation )
|
|
|
|
{
|
|
|
|
if( labelType == SCH_LABEL_T )
|
|
|
|
return aOrientation;
|
|
|
|
|
|
|
|
switch( aOrientation )
|
|
|
|
{
|
|
|
|
case 0: return 2;
|
|
|
|
case 2: return 0;
|
|
|
|
default: return aOrientation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_TEXT_HJUSTIFY_T EDA_TEXT::MapHorizJustify( int aHorizJustify )
|
|
|
|
{
|
|
|
|
wxASSERT( aHorizJustify >= GR_TEXT_HJUSTIFY_LEFT && aHorizJustify <= GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
|
|
|
|
if( aHorizJustify > GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
return GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
|
|
|
|
if( aHorizJustify < GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
return GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
|
|
|
|
return (EDA_TEXT_HJUSTIFY_T) aHorizJustify;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_TEXT_VJUSTIFY_T EDA_TEXT::MapVertJustify( int aVertJustify )
|
|
|
|
{
|
|
|
|
wxASSERT( aVertJustify >= GR_TEXT_VJUSTIFY_TOP && aVertJustify <= GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
|
|
|
|
if( aVertJustify > GR_TEXT_VJUSTIFY_BOTTOM )
|
|
|
|
return GR_TEXT_VJUSTIFY_BOTTOM;
|
|
|
|
|
|
|
|
if( aVertJustify < GR_TEXT_VJUSTIFY_TOP )
|
|
|
|
return GR_TEXT_VJUSTIFY_TOP;
|
|
|
|
|
|
|
|
return (EDA_TEXT_VJUSTIFY_T) aVertJustify;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
EDA_TEXT::EDA_TEXT( const wxString& text ) :
|
2019-08-02 00:10:25 +00:00
|
|
|
m_text( text ),
|
|
|
|
m_e( 1<<TE_VISIBLE )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int sz = Mils2iu( DEFAULT_SIZE_TEXT );
|
|
|
|
SetTextSize( wxSize( sz, sz ) );
|
2019-04-25 04:46:51 +00:00
|
|
|
m_shown_text = UnescapeString( text );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) :
|
2019-08-02 00:10:25 +00:00
|
|
|
m_text( aText.m_text ),
|
|
|
|
m_e( aText.m_e )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
m_shown_text = UnescapeString( m_text );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
EDA_TEXT::~EDA_TEXT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-25 04:14:25 +00:00
|
|
|
void EDA_TEXT::SetText( const wxString& aText )
|
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
m_text = aText;
|
2019-04-25 04:14:25 +00:00
|
|
|
m_shown_text = UnescapeString( aText );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void EDA_TEXT::SetEffects( const EDA_TEXT& aSrc )
|
2016-04-19 18:35:47 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_e = aSrc.m_e;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
|
|
|
|
{
|
|
|
|
std::swap( m_text, aTradingPartner.m_text );
|
|
|
|
std::swap( m_shown_text, aTradingPartner.m_shown_text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
void EDA_TEXT::SwapEffects( EDA_TEXT& aTradingPartner )
|
|
|
|
{
|
|
|
|
std::swap( m_e, aTradingPartner.m_e );
|
2016-04-19 18:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
bool EDA_TEXT::Replace( wxFindReplaceData& aSearchData )
|
|
|
|
{
|
|
|
|
return EDA_ITEM::Replace( aSearchData, m_text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-02 21:51:35 +00:00
|
|
|
int EDA_TEXT::LenSize( const wxString& aLine, int aThickness ) const
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
basic_gal.SetFontItalic( IsItalic() );
|
|
|
|
basic_gal.SetFontBold( IsBold() );
|
2019-08-02 00:10:25 +00:00
|
|
|
basic_gal.SetLineWidth( (float) aThickness );
|
2017-01-23 20:30:11 +00:00
|
|
|
basic_gal.SetGlyphSize( VECTOR2D( GetTextSize() ) );
|
2016-03-25 08:26:11 +00:00
|
|
|
|
|
|
|
VECTOR2D tsize = basic_gal.GetTextLineSize( aLine );
|
|
|
|
|
|
|
|
return KiROUND( tsize.x );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
|
|
|
|
wxString EDA_TEXT::ShortenedShownText() const
|
|
|
|
{
|
|
|
|
wxString tmp = GetShownText();
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
tmp.Replace( wxT( "\n" ), wxT( " " ) );
|
|
|
|
tmp.Replace( wxT( "\r" ), wxT( " " ) );
|
|
|
|
tmp.Replace( wxT( "\t" ), wxT( " " ) );
|
|
|
|
|
|
|
|
if( tmp.Length() > 15 )
|
|
|
|
tmp = tmp.Left( 12 ) + wxT( "..." );
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-03 23:03:35 +00:00
|
|
|
int EDA_TEXT::GetInterline() const
|
2013-10-25 12:16:18 +00:00
|
|
|
{
|
2019-08-03 23:03:35 +00:00
|
|
|
return KiROUND( KIGFX::STROKE_FONT::GetInterline( GetTextHeight() ) );
|
2013-10-25 12:16:18 +00:00
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const
|
|
|
|
{
|
|
|
|
EDA_RECT rect;
|
2015-01-15 20:01:53 +00:00
|
|
|
wxArrayString strings;
|
2014-09-13 18:15:45 +00:00
|
|
|
wxString text = GetShownText();
|
2017-01-23 20:30:11 +00:00
|
|
|
int thickness = ( aThickness < 0 ) ? GetThickness() : aThickness;
|
2013-10-25 12:16:18 +00:00
|
|
|
int linecount = 1;
|
2016-03-23 07:41:47 +00:00
|
|
|
bool hasOverBar = false; // true if the first line of text as an overbar
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMultilineAllowed() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxStringSplit( text, strings, '\n' );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2016-03-11 12:08:34 +00:00
|
|
|
if( strings.GetCount() ) // GetCount() == 0 for void strings
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
if( aLine >= 0 && (aLine < (int)strings.GetCount()) )
|
|
|
|
text = strings.Item( aLine );
|
2012-06-11 00:47:15 +00:00
|
|
|
else
|
2015-01-15 20:01:53 +00:00
|
|
|
text = strings.Item( 0 );
|
2013-10-25 12:16:18 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
linecount = strings.GetCount();
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 07:41:47 +00:00
|
|
|
// Search for overbar symbol. Only text is scanned,
|
|
|
|
// because only this line can change the bounding box
|
|
|
|
for( unsigned ii = 1; ii < text.size(); ii++ )
|
|
|
|
{
|
|
|
|
if( text[ii-1] == '~' && text[ii] != '~' )
|
|
|
|
{
|
|
|
|
hasOverBar = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
// calculate the H and V size
|
2016-03-25 08:26:11 +00:00
|
|
|
int dx = KiROUND( basic_gal.GetStrokeFont().ComputeStringBoundaryLimits(
|
2017-01-23 20:30:11 +00:00
|
|
|
text, VECTOR2D( GetTextSize() ), double( thickness ) ).x );
|
2019-08-03 23:03:35 +00:00
|
|
|
int dy = GetInterline();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2016-03-25 08:26:11 +00:00
|
|
|
// Creates bounding box (rectangle) for an horizontal
|
|
|
|
// and left and top justified text. the bounding box will be moved later
|
2016-03-26 09:08:09 +00:00
|
|
|
// according to the actual text options
|
2012-06-11 00:47:15 +00:00
|
|
|
wxSize textsize = wxSize( dx, dy );
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pos = GetTextPos();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
if( aInvertY )
|
2016-03-26 09:08:09 +00:00
|
|
|
pos.y = -pos.y;
|
2016-03-25 08:26:11 +00:00
|
|
|
|
|
|
|
rect.SetOrigin( pos );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2016-03-11 12:08:34 +00:00
|
|
|
// The bbox vertical size returned by GetInterline( aThickness )
|
|
|
|
// includes letters like j and y and ] + interval between lines.
|
|
|
|
// The interval below the last line is not usefull, and we can use its half value
|
|
|
|
// as vertical margin above the text
|
2017-01-23 20:30:11 +00:00
|
|
|
// the full interval is roughly GetTextHeight() * 0.4 - aThickness/2
|
|
|
|
rect.Move( wxPoint( 0, thickness/4 - KiROUND( GetTextHeight() * 0.22 ) ) );
|
2016-03-23 07:41:47 +00:00
|
|
|
|
|
|
|
if( hasOverBar )
|
2016-03-25 08:26:11 +00:00
|
|
|
{ // A overbar adds an extra size to the text
|
|
|
|
// Height from the base line text of chars like [ or {
|
2017-01-23 20:30:11 +00:00
|
|
|
double curr_height = GetTextHeight() * 1.15;
|
2016-03-23 12:16:27 +00:00
|
|
|
int extra_height = KiROUND(
|
2017-01-23 20:30:11 +00:00
|
|
|
basic_gal.GetStrokeFont().ComputeOverbarVerticalPosition( GetTextHeight(), thickness ) - curr_height );
|
2016-03-25 08:26:11 +00:00
|
|
|
extra_height += thickness/2;
|
2016-03-23 07:41:47 +00:00
|
|
|
textsize.y += extra_height;
|
|
|
|
rect.Move( wxPoint( 0, -extra_height ) );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
// for multiline texts and aLine < 0, merge all rectangles
|
2016-03-11 12:08:34 +00:00
|
|
|
// ( if aLine < 0, we want the full text bounding box )
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMultilineAllowed() && aLine < 0 )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
text = strings.Item( ii );
|
2016-03-25 08:26:11 +00:00
|
|
|
dx = KiROUND( basic_gal.GetStrokeFont().ComputeStringBoundaryLimits(
|
2017-01-23 20:30:11 +00:00
|
|
|
text, VECTOR2D( GetTextSize() ), double( thickness ) ).x );
|
2012-09-22 11:19:37 +00:00
|
|
|
textsize.x = std::max( textsize.x, dx );
|
2012-06-11 00:47:15 +00:00
|
|
|
textsize.y += dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.SetSize( textsize );
|
|
|
|
|
|
|
|
/* Now, calculate the rect origin, according to text justification
|
|
|
|
* At this point the rectangle origin is the text origin (m_Pos).
|
|
|
|
* This is true only for left and top text justified texts (using top to bottom Y axis
|
|
|
|
* orientation). and must be recalculated for others justifications
|
|
|
|
* also, note the V justification is relative to the first line
|
|
|
|
*/
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetHorizJustify() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT:
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMirrored() )
|
2012-06-11 00:47:15 +00:00
|
|
|
rect.SetX( rect.GetX() - rect.GetWidth() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_HJUSTIFY_CENTER:
|
|
|
|
rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
2017-01-23 20:30:11 +00:00
|
|
|
if( !IsMirrored() )
|
2012-06-11 00:47:15 +00:00
|
|
|
rect.SetX( rect.GetX() - rect.GetWidth() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
dy = GetTextHeight() + thickness;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetVertJustify() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_TOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER:
|
2013-10-25 12:16:18 +00:00
|
|
|
rect.SetY( rect.GetY() - ( dy / 2) );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
|
|
|
rect.SetY( rect.GetY() - dy );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-25 12:16:18 +00:00
|
|
|
if( linecount > 1 )
|
|
|
|
{
|
|
|
|
int yoffset;
|
|
|
|
linecount -= 1;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetVertJustify() )
|
2013-10-25 12:16:18 +00:00
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_TOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER:
|
|
|
|
yoffset = linecount * GetInterline() / 2;
|
|
|
|
rect.SetY( rect.GetY() - yoffset );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
2019-08-03 23:03:35 +00:00
|
|
|
yoffset = linecount * GetInterline();
|
2013-10-25 12:16:18 +00:00
|
|
|
rect.SetY( rect.GetY() - yoffset );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
rect.Normalize(); // Make h and v sizes always >= 0
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
EDA_RECT rect = GetTextBox( -1 ); // Get the full text area.
|
|
|
|
wxPoint location = aPoint;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
2017-01-23 20:30:11 +00:00
|
|
|
RotatePoint( &location, GetTextPos(), -GetTextAngle() );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
return rect.Contains( location );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
EDA_RECT rect = aRect;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContains )
|
|
|
|
return rect.Contains( GetTextBox( -1 ) );
|
|
|
|
|
2017-05-06 07:05:05 +00:00
|
|
|
return rect.Intersects( GetTextBox( -1 ), GetTextAngle() );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
void EDA_TEXT::Print( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aFillMode )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMultilineAllowed() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2013-11-29 08:13:43 +00:00
|
|
|
std::vector<wxPoint> positions;
|
2015-01-15 20:01:53 +00:00
|
|
|
wxArrayString strings;
|
|
|
|
wxStringSplit( GetShownText(), strings, '\n' );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
positions.reserve( strings.Count() );
|
2013-11-17 01:31:07 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
GetPositionsOfLinesOfMultilineText( positions, strings.Count() );
|
2013-11-17 01:31:07 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 0; ii < strings.Count(); ii++ )
|
2013-10-25 12:16:18 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString& txt = strings.Item( ii );
|
2019-05-31 12:15:25 +00:00
|
|
|
printOneLineOfText( aDC, aOffset, aColor, aFillMode, txt, positions[ii] );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-05-31 12:15:25 +00:00
|
|
|
printOneLineOfText( aDC, aOffset, aColor, aFillMode, GetShownText(), GetTextPos() );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-29 08:13:43 +00:00
|
|
|
void EDA_TEXT::GetPositionsOfLinesOfMultilineText(
|
2013-12-27 07:24:36 +00:00
|
|
|
std::vector<wxPoint>& aPositions, int aLineCount ) const
|
2013-11-29 08:13:43 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pos = GetTextPos(); // Position of first line of the
|
|
|
|
// multiline text according to
|
|
|
|
// the center of the multiline text block
|
2013-11-29 08:13:43 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint offset; // Offset to next line.
|
2013-11-29 08:13:43 +00:00
|
|
|
|
|
|
|
offset.y = GetInterline();
|
|
|
|
|
|
|
|
if( aLineCount > 1 )
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
switch( GetVertJustify() )
|
2013-11-29 08:13:43 +00:00
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_TOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER:
|
|
|
|
pos.y -= ( aLineCount - 1 ) * offset.y / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
|
|
|
pos.y -= ( aLineCount - 1 ) * offset.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rotate the position of the first line
|
|
|
|
// around the center of the multiline text block
|
2017-01-23 20:30:11 +00:00
|
|
|
RotatePoint( &pos, GetTextPos(), GetTextAngle() );
|
2014-04-25 16:49:32 +00:00
|
|
|
|
2013-11-29 08:13:43 +00:00
|
|
|
// Rotate the offset lines to increase happened in the right direction
|
2017-01-23 20:30:11 +00:00
|
|
|
RotatePoint( &offset, GetTextAngle() );
|
2013-11-29 08:13:43 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < aLineCount; ii++ )
|
|
|
|
{
|
|
|
|
aPositions.push_back( pos );
|
|
|
|
pos += offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
void EDA_TEXT::printOneLineOfText( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor,
|
|
|
|
EDA_DRAW_MODE_T aFillMode, const wxString& aText,
|
|
|
|
const wxPoint &aPos )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int width = GetThickness();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
if( aFillMode == SKETCH )
|
|
|
|
width = -width;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
wxSize size = GetTextSize();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsMirrored() )
|
2012-06-11 00:47:15 +00:00
|
|
|
size.x = -size.x;
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( aDC, aOffset + aPos, aColor, aText, GetTextAngle(), size, GetHorizJustify(),
|
|
|
|
GetVertJustify(), width, IsItalic(), IsBold() );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString EDA_TEXT::GetTextStyleName()
|
|
|
|
{
|
|
|
|
int style = 0;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsItalic() )
|
2012-06-11 00:47:15 +00:00
|
|
|
style = 1;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsBold() )
|
2012-06-11 00:47:15 +00:00
|
|
|
style += 2;
|
|
|
|
|
|
|
|
wxString stylemsg[4] = {
|
|
|
|
_("Normal"),
|
|
|
|
_("Italic"),
|
|
|
|
_("Bold"),
|
|
|
|
_("Bold+Italic")
|
|
|
|
};
|
|
|
|
|
|
|
|
return stylemsg[style];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDA_TEXT::IsDefaultFormatting() const
|
|
|
|
{
|
2017-12-20 22:11:19 +00:00
|
|
|
return ( IsVisible()
|
2017-01-23 20:30:11 +00:00
|
|
|
&& !IsMirrored()
|
|
|
|
&& GetHorizJustify() == GR_TEXT_HJUSTIFY_CENTER
|
|
|
|
&& GetVertJustify() == GR_TEXT_VJUSTIFY_CENTER
|
|
|
|
&& GetThickness() == 0
|
|
|
|
&& !IsItalic()
|
|
|
|
&& !IsBold()
|
|
|
|
&& !IsMultilineAllowed()
|
|
|
|
);
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 21:44:41 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
|
|
|
|
{
|
2013-05-21 07:18:25 +00:00
|
|
|
#ifndef GERBVIEW // Gerbview does not use EDA_TEXT::Format
|
2019-01-08 05:42:50 +00:00
|
|
|
// and does not define FormatInternalUnits, used here
|
2013-05-21 07:18:25 +00:00
|
|
|
// however this function should exist
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
aFormatter->Print( aNestLevel + 1, "(effects" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
// Text size
|
|
|
|
aFormatter->Print( 0, " (font" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
aFormatter->Print( 0, " (size %s %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( GetTextHeight() ).c_str(),
|
|
|
|
FormatInternalUnits( GetTextWidth() ).c_str() );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( GetThickness() )
|
2019-01-08 05:42:50 +00:00
|
|
|
aFormatter->Print( 0, " (thickness %s)", FormatInternalUnits( GetThickness() ).c_str() );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( IsBold() )
|
|
|
|
aFormatter->Print( 0, " bold" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( IsItalic() )
|
|
|
|
aFormatter->Print( 0, " italic" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
aFormatter->Print( 0, ")"); // (font
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( IsMirrored() ||
|
|
|
|
GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER ||
|
|
|
|
GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER )
|
|
|
|
{
|
|
|
|
aFormatter->Print( 0, " (justify");
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER )
|
|
|
|
aFormatter->Print( 0, (GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT) ? " left" : " right" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER )
|
|
|
|
aFormatter->Print( 0, (GetVertJustify() == GR_TEXT_VJUSTIFY_TOP) ? " top" : " bottom" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( IsMirrored() )
|
|
|
|
aFormatter->Print( 0, " mirror" );
|
|
|
|
aFormatter->Print( 0, ")" ); // (justify
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
if( !(aControlBits & CTL_OMIT_HIDE) && !IsVisible() )
|
|
|
|
aFormatter->Print( 0, " hide" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
aFormatter->Print( 0, ")\n" ); // (justify
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2013-05-21 07:18:25 +00:00
|
|
|
#endif
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
2014-08-13 15:47:02 +00:00
|
|
|
|
|
|
|
// Convert the text shape to a list of segment
|
|
|
|
// each segment is stored as 2 wxPoints: its starting point and its ending point
|
2019-05-31 12:15:25 +00:00
|
|
|
// we are using GRText to create the segments and therefore a call-back function is needed
|
2014-08-13 15:47:02 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
// This is a call back function, used by GRText to put each segment in buffer
|
2018-04-06 13:30:52 +00:00
|
|
|
static void addTextSegmToBuffer( int x0, int y0, int xf, int yf, void* aData )
|
2014-08-13 15:47:02 +00:00
|
|
|
{
|
2018-04-06 13:30:52 +00:00
|
|
|
std::vector<wxPoint>* cornerBuffer = static_cast<std::vector<wxPoint>*>( aData );
|
|
|
|
cornerBuffer->push_back( wxPoint( x0, y0 ) );
|
|
|
|
cornerBuffer->push_back( wxPoint( xf, yf ) );
|
2014-08-13 15:47:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2014-08-13 15:47:02 +00:00
|
|
|
void EDA_TEXT::TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuffer ) const
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxSize size = GetTextSize();
|
2014-08-13 15:47:02 +00:00
|
|
|
|
|
|
|
if( IsMirrored() )
|
2015-06-26 13:41:56 +00:00
|
|
|
size.x = -size.x;
|
2014-08-13 15:47:02 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
|
2014-08-13 15:47:02 +00:00
|
|
|
|
|
|
|
if( IsMultilineAllowed() )
|
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxArrayString strings_list;
|
|
|
|
wxStringSplit( GetShownText(), strings_list, wxChar('\n') );
|
2014-08-13 15:47:02 +00:00
|
|
|
std::vector<wxPoint> positions;
|
2015-01-15 20:01:53 +00:00
|
|
|
positions.reserve( strings_list.Count() );
|
|
|
|
GetPositionsOfLinesOfMultilineText( positions,strings_list.Count() );
|
2014-08-13 15:47:02 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
2014-08-13 15:47:02 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString txt = strings_list.Item( ii );
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( NULL, positions[ii], color, txt, GetTextAngle(), size, GetHorizJustify(),
|
|
|
|
GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToBuffer,
|
|
|
|
&aCornerBuffer );
|
2014-08-13 15:47:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( NULL, GetTextPos(), color, GetText(), GetTextAngle(), size, GetHorizJustify(),
|
|
|
|
GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToBuffer,
|
|
|
|
&aCornerBuffer );
|
2014-08-13 15:47:02 +00:00
|
|
|
}
|
|
|
|
}
|