2012-06-11 00:47:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <drawtxt.h>
|
2014-08-13 15:47:02 +00:00
|
|
|
#include <macros.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <trigo.h> // RotatePoint
|
|
|
|
#include <class_drawpanel.h> // EDA_DRAW_PANEL
|
|
|
|
|
|
|
|
// Conversion to application internal units defined at build time.
|
|
|
|
#if defined( PCBNEW )
|
2013-06-29 09:52:22 +00:00
|
|
|
#include <class_board_item.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#elif defined( EESCHEMA )
|
2013-06-29 09:52:22 +00:00
|
|
|
#include <sch_item_struct.h>
|
2013-05-21 07:18:25 +00:00
|
|
|
#elif defined( GERBVIEW )
|
2013-06-29 09:52:22 +00:00
|
|
|
#elif defined( PL_EDITOR )
|
|
|
|
#include <base_units.h>
|
|
|
|
#define FMT_IU Double2Str
|
2012-06-11 00:47:15 +00:00
|
|
|
#else
|
|
|
|
#error "Cannot resolve units formatting due to no definition of EESCHEMA or PCBNEW."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
EDA_TEXT::EDA_TEXT( const wxString& text )
|
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
m_Size.x = m_Size.y = Mils2iu( DEFAULT_SIZE_TEXT ); // Width and height of font.
|
2012-06-11 00:47:15 +00:00
|
|
|
m_Orient = 0; // Rotation angle in 0.1 degrees.
|
|
|
|
m_Attributs = 0;
|
|
|
|
m_Mirror = false; // display mirror if true
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_CENTER; // Default horizontal justification is centered.
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER; // Default vertical justification is centered.
|
|
|
|
m_Thickness = 0; // thickness
|
|
|
|
m_Italic = false; // true = italic shape.
|
|
|
|
m_Bold = false;
|
|
|
|
m_MultilineAllowed = false; // Set to true for multiline text.
|
|
|
|
m_Text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText )
|
|
|
|
{
|
|
|
|
m_Pos = aText.m_Pos;
|
|
|
|
m_Size = aText.m_Size;
|
|
|
|
m_Orient = aText.m_Orient;
|
|
|
|
m_Attributs = aText.m_Attributs;
|
|
|
|
m_Mirror = aText.m_Mirror;
|
|
|
|
m_HJustify = aText.m_HJustify;
|
|
|
|
m_VJustify = aText.m_VJustify;
|
|
|
|
m_Thickness = aText.m_Thickness;
|
|
|
|
m_Italic = aText.m_Italic;
|
|
|
|
m_Bold = aText.m_Bold;
|
|
|
|
m_MultilineAllowed = aText.m_MultilineAllowed;
|
|
|
|
m_Text = aText.m_Text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_TEXT::~EDA_TEXT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EDA_TEXT::LenSize( const wxString& aLine ) const
|
|
|
|
{
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
return GraphicTextWidth( aLine, m_Size.x, m_Italic, m_Bold );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
|
|
|
|
wxString EDA_TEXT::ShortenedShownText() const
|
|
|
|
{
|
|
|
|
wxString tmp = GetShownText();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-25 12:16:18 +00:00
|
|
|
/**
|
|
|
|
* Function GetInterline
|
|
|
|
* return the distance between 2 text lines
|
|
|
|
* has meaning only for multiline texts
|
|
|
|
*/
|
|
|
|
int EDA_TEXT::GetInterline( int aTextThickness ) const
|
|
|
|
{
|
|
|
|
int thickness = aTextThickness <= 0 ? m_Thickness : aTextThickness;
|
|
|
|
return (( m_Size.y * 14 ) / 10) + thickness;
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const
|
|
|
|
{
|
|
|
|
EDA_RECT rect;
|
|
|
|
wxPoint pos;
|
|
|
|
wxArrayString* list = NULL;
|
2014-09-13 18:15:45 +00:00
|
|
|
wxString text = GetShownText();
|
2012-06-11 00:47:15 +00:00
|
|
|
int thickness = ( aThickness < 0 ) ? m_Thickness : aThickness;
|
2013-10-25 12:16:18 +00:00
|
|
|
int linecount = 1;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
if( m_MultilineAllowed )
|
|
|
|
{
|
2014-09-13 18:15:45 +00:00
|
|
|
list = wxStringSplit( text, '\n' );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
if ( list->GetCount() ) // GetCount() == 0 for void strings
|
|
|
|
{
|
|
|
|
if( aLine >= 0 && (aLine < (int)list->GetCount()) )
|
|
|
|
text = list->Item( aLine );
|
|
|
|
else
|
|
|
|
text = list->Item( 0 );
|
2013-10-25 12:16:18 +00:00
|
|
|
|
|
|
|
linecount = list->GetCount();
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate the H and V size
|
|
|
|
int dx = LenSize( text );
|
2013-10-25 12:16:18 +00:00
|
|
|
int dy = GetInterline( aThickness );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
// Creates bounding box (rectangle) for an horizontal text
|
2012-06-11 00:47:15 +00:00
|
|
|
wxSize textsize = wxSize( dx, dy );
|
|
|
|
|
|
|
|
if( aInvertY )
|
|
|
|
rect.SetOrigin( m_Pos.x, -m_Pos.y );
|
|
|
|
else
|
|
|
|
rect.SetOrigin( m_Pos );
|
|
|
|
|
|
|
|
// extra dy interval for letters like j and y and ]
|
|
|
|
int extra_dy = dy - m_Size.y;
|
|
|
|
rect.Move( wxPoint( 0, -extra_dy / 2 ) ); // move origin by the half extra interval
|
|
|
|
|
|
|
|
// for multiline texts and aLine < 0, merge all rectangles
|
|
|
|
if( m_MultilineAllowed && list && aLine < 0 )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 1; ii < list->GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
text = list->Item( ii );
|
|
|
|
dx = LenSize( text );
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete list;
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
switch( m_HJustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT:
|
|
|
|
if( m_Mirror )
|
|
|
|
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:
|
|
|
|
if( !m_Mirror )
|
|
|
|
rect.SetX( rect.GetX() - rect.GetWidth() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dy = m_Size.y + thickness;
|
|
|
|
|
|
|
|
switch( m_VJustify )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
switch( m_VJustify )
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
yoffset = linecount * GetInterline( aThickness );
|
|
|
|
rect.SetY( rect.GetY() - yoffset );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
rect.Inflate( thickness / 2 );
|
|
|
|
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 );
|
|
|
|
RotatePoint( &location, m_Pos, -m_Orient );
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
|
|
|
|
return rect.Intersects( GetTextBox( -1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
void EDA_TEXT::Draw( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
2012-09-01 13:38:27 +00:00
|
|
|
EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode,
|
2012-06-11 00:47:15 +00:00
|
|
|
EDA_DRAW_MODE_T aFillMode, EDA_COLOR_T aAnchor_color )
|
|
|
|
{
|
|
|
|
if( m_MultilineAllowed )
|
|
|
|
{
|
2013-11-29 08:13:43 +00:00
|
|
|
std::vector<wxPoint> positions;
|
2014-09-13 18:15:45 +00:00
|
|
|
wxArrayString* list = wxStringSplit( GetShownText(), '\n' );
|
2013-11-29 08:13:43 +00:00
|
|
|
positions.reserve( list->Count() );
|
2013-11-17 01:31:07 +00:00
|
|
|
|
2013-11-29 08:13:43 +00:00
|
|
|
GetPositionsOfLinesOfMultilineText(positions, list->Count() );
|
2013-11-17 01:31:07 +00:00
|
|
|
|
2013-11-29 08:13:43 +00:00
|
|
|
for( unsigned ii = 0; ii < list->Count(); ii++ )
|
2013-10-25 12:16:18 +00:00
|
|
|
{
|
2013-11-29 08:13:43 +00:00
|
|
|
wxString& txt = list->Item( ii );
|
2013-06-29 09:52:22 +00:00
|
|
|
drawOneLineOfText( aClipBox, aDC, aOffset, aColor,
|
2013-11-29 08:13:43 +00:00
|
|
|
aDrawMode, aFillMode, txt, positions[ii] );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete (list);
|
|
|
|
}
|
|
|
|
else
|
2013-06-29 09:52:22 +00:00
|
|
|
drawOneLineOfText( aClipBox, aDC, aOffset, aColor,
|
2014-09-13 18:15:45 +00:00
|
|
|
aDrawMode, aFillMode, GetShownText(), m_Pos );
|
2013-10-25 12:16:18 +00:00
|
|
|
|
|
|
|
// Draw text anchor, if requested
|
|
|
|
if( aAnchor_color != UNSPECIFIED_COLOR )
|
|
|
|
{
|
|
|
|
GRDrawAnchor( aClipBox, aDC,
|
|
|
|
m_Pos.x + aOffset.x, m_Pos.y + aOffset.y,
|
|
|
|
DIM_ANCRE_TEXTE, aAnchor_color );
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
wxPoint pos = m_Pos; // Position of first line of the
|
|
|
|
// multiline text according to
|
|
|
|
// the center of the multiline text block
|
|
|
|
|
|
|
|
wxPoint offset; // Offset to next line.
|
|
|
|
|
|
|
|
offset.y = GetInterline();
|
|
|
|
|
|
|
|
if( aLineCount > 1 )
|
|
|
|
{
|
|
|
|
switch( m_VJustify )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
RotatePoint( &pos, m_Pos, m_Orient );
|
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
|
|
|
|
RotatePoint( &offset, m_Orient );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < aLineCount; ii++ )
|
|
|
|
{
|
|
|
|
aPositions.push_back( pos );
|
|
|
|
pos += offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
void EDA_TEXT::drawOneLineOfText( EDA_RECT* aClipBox, wxDC* aDC,
|
2012-06-11 00:47:15 +00:00
|
|
|
const wxPoint& aOffset, EDA_COLOR_T aColor,
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aFillMode,
|
2014-09-13 18:15:45 +00:00
|
|
|
const wxString& aText, const wxPoint &aPos )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
int width = m_Thickness;
|
|
|
|
|
|
|
|
if( aFillMode == LINE )
|
|
|
|
width = 0;
|
|
|
|
|
2013-07-25 18:58:46 +00:00
|
|
|
if( aDrawMode != UNSPECIFIED_DRAWMODE )
|
2012-06-11 00:47:15 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
|
|
|
if( aFillMode == SKETCH )
|
|
|
|
width = -width;
|
|
|
|
|
|
|
|
wxSize size = m_Size;
|
|
|
|
|
|
|
|
if( m_Mirror )
|
|
|
|
size.x = -size.x;
|
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicText( aClipBox, aDC, aOffset + aPos, aColor, aText, m_Orient, size,
|
2012-06-11 00:47:15 +00:00
|
|
|
m_HJustify, m_VJustify, width, m_Italic, m_Bold );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString EDA_TEXT::GetTextStyleName()
|
|
|
|
{
|
|
|
|
int style = 0;
|
|
|
|
|
|
|
|
if( m_Italic )
|
|
|
|
style = 1;
|
|
|
|
|
|
|
|
if( m_Bold )
|
|
|
|
style += 2;
|
|
|
|
|
|
|
|
wxString stylemsg[4] = {
|
|
|
|
_("Normal"),
|
|
|
|
_("Italic"),
|
|
|
|
_("Bold"),
|
|
|
|
_("Bold+Italic")
|
|
|
|
};
|
|
|
|
|
|
|
|
return stylemsg[style];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDA_TEXT::IsDefaultFormatting() const
|
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
return ( ( m_Size.x == Mils2iu( DEFAULT_SIZE_TEXT ) )
|
|
|
|
&& ( m_Size.y == Mils2iu( DEFAULT_SIZE_TEXT ) )
|
2012-06-11 00:47:15 +00:00
|
|
|
&& ( m_Attributs == 0 )
|
|
|
|
&& ( m_Mirror == false )
|
|
|
|
&& ( m_HJustify == GR_TEXT_HJUSTIFY_CENTER )
|
|
|
|
&& ( m_VJustify == GR_TEXT_VJUSTIFY_CENTER )
|
|
|
|
&& ( m_Thickness == 0 )
|
|
|
|
&& ( m_Italic == false )
|
|
|
|
&& ( m_Bold == false )
|
|
|
|
&& ( m_MultilineAllowed == false ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
|
|
|
|
throw( IO_ERROR )
|
|
|
|
{
|
2013-05-21 07:18:25 +00:00
|
|
|
#ifndef GERBVIEW // Gerbview does not use EDA_TEXT::Format
|
|
|
|
// and does not define FMT_IU, used here
|
|
|
|
// however this function should exist
|
2012-06-11 00:47:15 +00:00
|
|
|
if( !IsDefaultFormatting() )
|
|
|
|
{
|
2012-06-24 01:19:41 +00:00
|
|
|
aFormatter->Print( aNestLevel+1, "(effects" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( ( m_Size.x != Mils2iu( DEFAULT_SIZE_TEXT ) )
|
2013-03-20 14:50:12 +00:00
|
|
|
|| ( m_Size.y != Mils2iu( DEFAULT_SIZE_TEXT ) )
|
|
|
|
|| ( m_Thickness != 0 ) || m_Bold || m_Italic )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2012-06-24 01:19:41 +00:00
|
|
|
aFormatter->Print( 0, " (font" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
// Add font support here at some point in the future.
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( ( m_Size.x != Mils2iu( DEFAULT_SIZE_TEXT ) )
|
|
|
|
|| ( m_Size.y != Mils2iu( DEFAULT_SIZE_TEXT ) ) )
|
2012-06-11 00:47:15 +00:00
|
|
|
aFormatter->Print( 0, " (size %s %s)", FMT_IU( m_Size.GetHeight() ).c_str(),
|
|
|
|
FMT_IU( m_Size.GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
if( m_Thickness != 0 )
|
|
|
|
aFormatter->Print( 0, " (thickness %s)", FMT_IU( GetThickness() ).c_str() );
|
|
|
|
|
|
|
|
if( m_Bold )
|
|
|
|
aFormatter->Print( 0, " bold" );
|
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
if( IsItalic() )
|
2012-06-11 00:47:15 +00:00
|
|
|
aFormatter->Print( 0, " italic" );
|
|
|
|
|
2012-06-24 01:19:41 +00:00
|
|
|
aFormatter->Print( 0, ")");
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Mirror || ( m_HJustify != GR_TEXT_HJUSTIFY_CENTER )
|
|
|
|
|| ( m_VJustify != GR_TEXT_VJUSTIFY_CENTER ) )
|
|
|
|
{
|
2012-06-24 01:19:41 +00:00
|
|
|
aFormatter->Print( 0, " (justify");
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
if( m_HJustify != GR_TEXT_HJUSTIFY_CENTER )
|
|
|
|
aFormatter->Print( 0, (m_HJustify == GR_TEXT_HJUSTIFY_LEFT) ? " left" : " right" );
|
|
|
|
|
|
|
|
if( m_VJustify != GR_TEXT_VJUSTIFY_CENTER )
|
|
|
|
aFormatter->Print( 0, (m_VJustify == GR_TEXT_VJUSTIFY_TOP) ? " top" : " bottom" );
|
|
|
|
|
|
|
|
if( m_Mirror )
|
|
|
|
aFormatter->Print( 0, " mirror" );
|
|
|
|
|
2012-06-24 01:19:41 +00:00
|
|
|
aFormatter->Print( 0, ")" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// As of now the only place this is used is in Eeschema to hide or show the text.
|
|
|
|
if( m_Attributs )
|
2012-06-24 01:19:41 +00:00
|
|
|
aFormatter->Print( 0, " hide" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-24 01:19:41 +00:00
|
|
|
aFormatter->Print( 0, ")\n" );
|
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
|
|
|
|
// we are using DrawGraphicText to create the segments.
|
|
|
|
// and therefore a call-back function is needed
|
|
|
|
static std::vector<wxPoint>* s_cornerBuffer;
|
|
|
|
|
|
|
|
// This is a call back function, used by DrawGraphicText to put each segment in buffer
|
|
|
|
static void addTextSegmToBuffer( int x0, int y0, int xf, int yf )
|
|
|
|
{
|
|
|
|
s_cornerBuffer->push_back( wxPoint( x0, y0 ) );
|
|
|
|
s_cornerBuffer->push_back( wxPoint( xf, yf ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EDA_TEXT::TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuffer ) const
|
|
|
|
{
|
|
|
|
wxSize size = GetSize();
|
|
|
|
|
|
|
|
if( IsMirrored() )
|
|
|
|
NEGATE( size.x );
|
|
|
|
|
|
|
|
s_cornerBuffer = &aCornerBuffer;
|
|
|
|
EDA_COLOR_T color = BLACK; // not actually used, but needed by DrawGraphicText
|
|
|
|
|
|
|
|
if( IsMultilineAllowed() )
|
|
|
|
{
|
2014-09-13 18:15:45 +00:00
|
|
|
wxArrayString* list = wxStringSplit( GetShownText(), '\n' );
|
2014-08-13 15:47:02 +00:00
|
|
|
std::vector<wxPoint> positions;
|
|
|
|
positions.reserve( list->Count() );
|
|
|
|
GetPositionsOfLinesOfMultilineText( positions, list->Count() );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < list->Count(); ii++ )
|
|
|
|
{
|
|
|
|
wxString txt = list->Item( ii );
|
|
|
|
DrawGraphicText( NULL, NULL, positions[ii], color,
|
|
|
|
txt, GetOrientation(), size,
|
|
|
|
GetHorizJustify(), GetVertJustify(),
|
|
|
|
GetThickness(), IsItalic(),
|
|
|
|
true, addTextSegmToBuffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete list;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DrawGraphicText( NULL, NULL, GetTextPosition(), color,
|
|
|
|
GetText(), GetOrientation(), size,
|
|
|
|
GetHorizJustify(), GetVertJustify(),
|
|
|
|
GetThickness(), IsItalic(),
|
|
|
|
true, addTextSegmToBuffer );
|
|
|
|
}
|
|
|
|
}
|