2009-03-02 13:43:52 +00:00
|
|
|
/**
|
|
|
|
* Functions to draw and plot text on screen
|
2009-03-28 20:02:34 +00:00
|
|
|
* @file drawtxt.cpp
|
2009-03-02 13:43:52 +00:00
|
|
|
*/
|
2012-06-09 09:38:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <plot_common.h>
|
2012-04-12 21:31:31 +00:00
|
|
|
#include <eda_text.h> // EDA_TEXT_HJUSTIFY_T and EDA_TEXT_VJUSTIFY_T
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <class_base_screen.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <newstroke_font.h>
|
|
|
|
#include <plot_common.h>
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
/* factor used to calculate actual size of shapes from hershey fonts
|
|
|
|
* (could be adjusted depending on the font name)
|
|
|
|
* Its value is choosen in order to have letters like M, P .. vertical size
|
|
|
|
* equal to the vertical char size parameter
|
|
|
|
* Of course some shapes can be bigger or smaller than the vertical char size
|
|
|
|
* parameter
|
2009-05-30 16:06:01 +00:00
|
|
|
*/
|
|
|
|
#define HERSHEY_SCALE_FACTOR 1 / 21.0
|
2013-04-07 11:55:18 +00:00
|
|
|
double s_HersheyScaleFactor = HERSHEY_SCALE_FACTOR;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2013-04-10 19:09:59 +00:00
|
|
|
int OverbarPositionY( int size_v )
|
2012-09-07 19:29:44 +00:00
|
|
|
{
|
2013-04-10 19:09:59 +00:00
|
|
|
return KiROUND( size_v * 1.22 );
|
2012-09-07 19:29:44 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function GetPensizeForBold
|
2009-05-30 16:06:01 +00:00
|
|
|
* @return the "best" value for a pen size to draw/plot a bold text
|
|
|
|
* @param aTextSize = the char size (height or width)
|
|
|
|
*/
|
|
|
|
int GetPenSizeForBold( int aTextSize )
|
|
|
|
{
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
return KiROUND( aTextSize / 5.0 );
|
2009-05-30 16:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Clamp_Text_PenSize
|
2012-09-07 19:29:44 +00:00
|
|
|
* As a rule, pen width should not be >1/4em, otherwise the character
|
2009-05-30 16:06:01 +00:00
|
|
|
* will be cluttered up in its own fatness
|
|
|
|
* so pen width max is aSize/4 for bold text, and aSize/6 for normal text
|
|
|
|
* The "best" pen width is aSize/5 for bold texts,
|
|
|
|
* so the clamp is consistant with bold option.
|
|
|
|
* @param aPenSize = the pen size to clamp
|
|
|
|
* @param aSize the char size (height or width)
|
|
|
|
* @param aBold = true if text accept bold pen size
|
|
|
|
* @return the max pen size allowed
|
|
|
|
*/
|
|
|
|
int Clamp_Text_PenSize( int aPenSize, int aSize, bool aBold )
|
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
int penSize = aPenSize;
|
|
|
|
double scale = aBold ? 4.0 : 6.0;
|
|
|
|
int maxWidth = KiROUND( std::abs( aSize ) / scale );
|
2009-05-30 16:06:01 +00:00
|
|
|
|
|
|
|
if( penSize > maxWidth )
|
|
|
|
penSize = maxWidth;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-30 16:06:01 +00:00
|
|
|
return penSize;
|
|
|
|
}
|
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
|
2009-05-30 16:06:01 +00:00
|
|
|
int Clamp_Text_PenSize( int aPenSize, wxSize aSize, bool aBold )
|
|
|
|
{
|
2012-09-22 11:19:37 +00:00
|
|
|
int size = std::min( std::abs( aSize.x ), std::abs( aSize.y ) );
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2011-03-03 19:08:13 +00:00
|
|
|
return Clamp_Text_PenSize( aPenSize, size, aBold );
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
2009-05-30 16:06:01 +00:00
|
|
|
|
|
|
|
|
2009-05-12 12:12:34 +00:00
|
|
|
/* Functions to draw / plot a string.
|
|
|
|
* texts have only one line.
|
|
|
|
* They can be in italic.
|
|
|
|
* Horizontal and Vertical justification are handled.
|
|
|
|
* Texts can be rotated
|
|
|
|
* substrings between ~ markers can be "negated" (i.e. with an over bar
|
|
|
|
*/
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function NegableTextLength
|
2013-04-03 16:16:26 +00:00
|
|
|
* Return the text length (char count) of a negable string,
|
|
|
|
* excluding the ~ markers
|
|
|
|
*/
|
2009-04-17 12:45:22 +00:00
|
|
|
int NegableTextLength( const wxString& aText )
|
2009-04-06 10:56:17 +00:00
|
|
|
{
|
|
|
|
int char_count = aText.length();
|
2009-04-17 12:45:22 +00:00
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
// Fix the character count, removing the ~ found
|
2009-04-17 12:45:22 +00:00
|
|
|
for( int i = char_count - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
if( aText[i] == '~' )
|
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
// '~~' draw as '~' and count as two chars
|
2013-03-27 20:38:20 +00:00
|
|
|
if( i > 0 && aText[i - 1] == '~' )
|
|
|
|
i--;
|
|
|
|
else
|
|
|
|
char_count--;
|
2009-04-17 12:45:22 +00:00
|
|
|
}
|
2009-04-06 10:56:17 +00:00
|
|
|
}
|
2009-04-17 12:45:22 +00:00
|
|
|
|
2009-04-06 10:56:17 +00:00
|
|
|
return char_count;
|
|
|
|
}
|
|
|
|
|
2009-04-17 12:45:22 +00:00
|
|
|
|
2010-11-12 16:59:16 +00:00
|
|
|
/* Function GetHersheyShapeDescription
|
2009-05-30 16:06:01 +00:00
|
|
|
* return a pointer to the shape corresponding to unicode value AsciiCode
|
|
|
|
* Note we use the same font for Bold and Normal texts
|
2011-09-30 18:15:37 +00:00
|
|
|
* because KiCad handles a variable pen size to do that
|
2009-05-30 16:06:01 +00:00
|
|
|
* that gives better results in XOR draw mode.
|
|
|
|
*/
|
|
|
|
static const char* GetHersheyShapeDescription( int AsciiCode )
|
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
// calculate font length
|
2010-02-19 13:23:58 +00:00
|
|
|
int font_length_max = newstroke_font_bufsize;
|
2010-09-11 16:33:43 +00:00
|
|
|
|
|
|
|
if( AsciiCode >= (32 + font_length_max) )
|
2009-06-18 13:30:52 +00:00
|
|
|
AsciiCode = '?';
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
if( AsciiCode < 32 )
|
2013-04-10 19:09:59 +00:00
|
|
|
AsciiCode = 32; // Clamp control chars
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
AsciiCode -= 32;
|
|
|
|
|
2010-02-01 21:23:27 +00:00
|
|
|
return newstroke_font[AsciiCode];
|
2009-05-28 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
* 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
|
|
|
int GraphicTextWidth( const wxString& aText, int aXSize, bool aItalic, bool aWidth )
|
2009-05-28 17:39:40 +00:00
|
|
|
{
|
|
|
|
int tally = 0;
|
|
|
|
int char_count = aText.length();
|
|
|
|
|
|
|
|
for( int i = 0; i < char_count; i++ )
|
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
int asciiCode = aText[i];
|
2009-05-28 17:39:40 +00:00
|
|
|
|
2013-03-27 20:38:20 +00:00
|
|
|
/* Skip the negation marks
|
|
|
|
* and first '~' char of '~~'
|
2013-04-03 16:16:26 +00:00
|
|
|
* ('~~' draw as '~')
|
|
|
|
*/
|
|
|
|
if( asciiCode == '~' )
|
2009-05-28 17:39:40 +00:00
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
if( i == 0 || aText[i - 1] != '~' )
|
2013-03-27 20:38:20 +00:00
|
|
|
continue;
|
2009-05-28 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
const char* shape_ptr = GetHersheyShapeDescription( asciiCode );
|
|
|
|
// Get metrics
|
|
|
|
int xsta = *shape_ptr++ - 'R';
|
|
|
|
int xsto = *shape_ptr++ - 'R';
|
2013-04-07 11:55:18 +00:00
|
|
|
tally += KiROUND( aXSize * (xsto - xsta) * s_HersheyScaleFactor );
|
2009-05-28 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
// For italic correction, add 1/8 size
|
2009-05-30 16:06:01 +00:00
|
|
|
if( aItalic )
|
2009-05-28 17:39:40 +00:00
|
|
|
{
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
tally += KiROUND( aXSize * 0.125 );
|
2009-05-28 17:39:40 +00:00
|
|
|
}
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
return tally;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
// Helper function for drawing character polylines
|
|
|
|
static void DrawGraphicTextPline( EDA_RECT* aClipBox,
|
|
|
|
wxDC* aDC,
|
|
|
|
EDA_COLOR_T aColor,
|
|
|
|
int aWidth,
|
|
|
|
bool aSketchMode,
|
|
|
|
int point_count,
|
|
|
|
wxPoint* coord,
|
|
|
|
void (* aCallback)( int x0, int y0, int xf, int yf ),
|
|
|
|
PLOTTER* aPlotter )
|
2009-04-06 10:56:17 +00:00
|
|
|
{
|
2010-12-28 11:24:42 +00:00
|
|
|
if( aPlotter )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->MoveTo( coord[0] );
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
for( int ik = 1; ik < point_count; ik++ )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->LineTo( coord[ik] );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2010-09-11 16:33:43 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->PenFinish();
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2010-09-11 16:33:43 +00:00
|
|
|
else if( aCallback )
|
2009-04-06 10:56:17 +00:00
|
|
|
{
|
2009-04-17 12:45:22 +00:00
|
|
|
for( int ik = 0; ik < (point_count - 1); ik++ )
|
|
|
|
{
|
|
|
|
aCallback( coord[ik].x, coord[ik].y,
|
|
|
|
coord[ik + 1].x, coord[ik + 1].y );
|
|
|
|
}
|
2009-04-06 10:56:17 +00:00
|
|
|
}
|
2010-12-28 11:24:42 +00:00
|
|
|
else if( aSketchMode )
|
2009-04-06 10:56:17 +00:00
|
|
|
{
|
2009-04-17 12:45:22 +00:00
|
|
|
for( int ik = 0; ik < (point_count - 1); ik++ )
|
2010-09-11 16:33:43 +00:00
|
|
|
GRCSegm( aClipBox, aDC, coord[ik].x, coord[ik].y,
|
2009-04-17 12:45:22 +00:00
|
|
|
coord[ik + 1].x, coord[ik + 1].y, aWidth, aColor );
|
2009-04-06 10:56:17 +00:00
|
|
|
}
|
|
|
|
else
|
2010-09-11 16:33:43 +00:00
|
|
|
GRPoly( aClipBox, aDC, point_count, coord, 0,
|
2009-04-17 12:45:22 +00:00
|
|
|
aWidth, aColor, aColor );
|
2009-04-06 10:56:17 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 12:45:22 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function DrawGraphicText
|
2008-12-14 19:45:05 +00:00
|
|
|
* Draw a graphic text (like module texts)
|
2013-06-29 09:52:22 +00:00
|
|
|
* @param aClipBox = the clipping rect, or NULL if no clipping
|
2009-01-30 14:11:36 +00:00
|
|
|
* @param aDC = the current Device Context. NULL if draw within a 3D GL Canvas
|
2008-12-16 19:44:57 +00:00
|
|
|
* @param aPos = text position (according to h_justify, v_justify)
|
2012-03-26 23:47:08 +00:00
|
|
|
* @param aColor (enum EDA_COLOR_T) = text color
|
2008-12-14 19:45:05 +00:00
|
|
|
* @param aText = text to draw
|
|
|
|
* @param aOrient = angle in 0.1 degree
|
|
|
|
* @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
|
|
|
|
* @param aH_justify = horizontal justification (Left, center, right)
|
|
|
|
* @param aV_justify = vertical justification (bottom, center, top)
|
2009-05-30 16:06:01 +00:00
|
|
|
* @param aWidth = line width (pen width) (use default width if aWidth = 0)
|
2008-12-16 19:44:57 +00:00
|
|
|
* if width < 0 : draw segments in sketch mode, width = abs(width)
|
2009-05-30 16:06:01 +00:00
|
|
|
* Use a value min(aSize.x, aSize.y) / 5 for a bold text
|
2008-12-16 19:44:57 +00:00
|
|
|
* @param aItalic = true to simulate an italic font
|
2009-05-30 16:06:01 +00:00
|
|
|
* @param aBold = true to use a bold font. Useful only with default width value (aWidth = 0)
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aCallback() = function called (if non null) to draw each segment.
|
|
|
|
* used to draw 3D texts or for plotting, NULL for normal drawings
|
|
|
|
* @param aPlotter = a pointer to a PLOTTER instance, when this function is used to plot
|
|
|
|
* the text. NULL to draw this text.
|
2008-01-19 20:34:10 +00:00
|
|
|
*/
|
2013-06-29 09:52:22 +00:00
|
|
|
void DrawGraphicText( EDA_RECT* aClipBox,
|
2010-09-11 16:33:43 +00:00
|
|
|
wxDC* aDC,
|
|
|
|
const wxPoint& aPos,
|
2012-03-26 23:47:08 +00:00
|
|
|
EDA_COLOR_T aColor,
|
2010-09-11 16:33:43 +00:00
|
|
|
const wxString& aText,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aOrient,
|
2010-09-11 16:33:43 +00:00
|
|
|
const wxSize& aSize,
|
2012-01-03 17:14:17 +00:00
|
|
|
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
|
|
|
enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
2010-09-11 16:33:43 +00:00
|
|
|
int aWidth,
|
|
|
|
bool aItalic,
|
|
|
|
bool aBold,
|
|
|
|
void (* aCallback)( int x0, int y0, int xf, int yf ),
|
2010-12-28 11:24:42 +00:00
|
|
|
PLOTTER* aPlotter )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
int AsciiCode;
|
|
|
|
int x0, y0;
|
|
|
|
int size_h, size_v;
|
|
|
|
unsigned ptr;
|
|
|
|
int dx, dy; // Draw coordinate for segments to draw. also used in some other calculation
|
|
|
|
wxPoint current_char_pos; // Draw coordinates for the current char
|
|
|
|
wxPoint overbar_pos; // Start point for the current overbar
|
|
|
|
int overbar_italic_comp; // Italic compensation for overbar
|
2009-03-28 20:02:34 +00:00
|
|
|
#define BUF_SIZE 100
|
2009-05-28 17:39:40 +00:00
|
|
|
wxPoint coord[BUF_SIZE + 1]; // Buffer coordinate used to draw polylines (one char shape)
|
2013-04-03 16:16:26 +00:00
|
|
|
bool sketch_mode = false;
|
|
|
|
bool italic_reverse = false; // true for mirrored texts with m_Size.x < 0
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
size_h = aSize.x; /* PLEASE NOTE: H is for HORIZONTAL not for HEIGHT */
|
|
|
|
size_v = aSize.y;
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
if( aWidth == 0 && aBold ) // Use default values if aWidth == 0
|
2012-09-22 11:19:37 +00:00
|
|
|
aWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
if( aWidth < 0 )
|
2008-01-19 20:34:10 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
aWidth = -aWidth;
|
2009-03-28 20:02:34 +00:00
|
|
|
sketch_mode = true;
|
2008-01-19 20:34:10 +00:00
|
|
|
}
|
2009-06-02 07:26:49 +00:00
|
|
|
|
|
|
|
#ifdef CLIP_PEN // made by draw and plot functions
|
|
|
|
aWidth = Clamp_Text_PenSize( aWidth, aSize, aBold );
|
|
|
|
#endif
|
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
if( size_h < 0 ) // text is mirrored using size.x < 0 (mirror / Y axis)
|
2009-04-17 12:45:22 +00:00
|
|
|
italic_reverse = true;
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
unsigned char_count = NegableTextLength( aText );
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
if( char_count == 0 )
|
2008-01-19 20:34:10 +00:00
|
|
|
return;
|
|
|
|
|
2009-05-12 12:12:34 +00:00
|
|
|
current_char_pos = aPos;
|
2008-01-19 20:34:10 +00:00
|
|
|
|
* 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
|
|
|
dx = GraphicTextWidth( aText, size_h, aItalic, aWidth );
|
2013-04-03 16:16:26 +00:00
|
|
|
dy = size_v;
|
2009-05-28 17:39:40 +00:00
|
|
|
|
2008-01-19 20:34:10 +00:00
|
|
|
/* Do not draw the text if out of draw area! */
|
2013-06-29 09:52:22 +00:00
|
|
|
if( aClipBox )
|
2008-01-19 20:34:10 +00:00
|
|
|
{
|
|
|
|
int xm, ym, ll, xc, yc;
|
2012-09-22 11:19:37 +00:00
|
|
|
ll = std::abs( dx );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
xc = current_char_pos.x;
|
|
|
|
yc = current_char_pos.y;
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
x0 = aClipBox->GetX() - ll;
|
|
|
|
y0 = aClipBox->GetY() - ll;
|
|
|
|
xm = aClipBox->GetRight() + ll;
|
|
|
|
ym = aClipBox->GetBottom() + ll;
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2008-01-19 20:34:10 +00:00
|
|
|
if( xc < x0 )
|
|
|
|
return;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2008-01-19 20:34:10 +00:00
|
|
|
if( yc < y0 )
|
|
|
|
return;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2008-01-19 20:34:10 +00:00
|
|
|
if( xc > xm )
|
|
|
|
return;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2008-01-19 20:34:10 +00:00
|
|
|
if( yc > ym )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-12 12:12:34 +00:00
|
|
|
/* Compute the position of the first letter of the text
|
|
|
|
* this position is the position of the left bottom point of the letter
|
|
|
|
* this is the same as the text position only for a left and bottom justified text
|
|
|
|
* In others cases, this position must be calculated from the text position ans size
|
2009-05-28 17:39:40 +00:00
|
|
|
*/
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
switch( aH_justify )
|
2008-01-19 20:34:10 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
case GR_TEXT_HJUSTIFY_CENTER:
|
2009-05-12 12:12:34 +00:00
|
|
|
current_char_pos.x -= dx / 2;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
2009-05-12 12:12:34 +00:00
|
|
|
current_char_pos.x -= dx;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
case GR_TEXT_HJUSTIFY_LEFT:
|
|
|
|
break;
|
|
|
|
}
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
switch( aV_justify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER:
|
2009-05-28 17:39:40 +00:00
|
|
|
current_char_pos.y += dy / 2;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
case GR_TEXT_VJUSTIFY_TOP:
|
2010-09-11 16:33:43 +00:00
|
|
|
current_char_pos.y += dy;
|
2009-05-05 17:32:07 +00:00
|
|
|
break;
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
|
|
|
break;
|
2008-01-19 20:34:10 +00:00
|
|
|
}
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-01-30 14:11:36 +00:00
|
|
|
// Note: if aPanel == NULL, we are using a GL Canvas that handle scaling
|
2011-01-30 22:22:38 +00:00
|
|
|
if( aSize.x == 0 )
|
2008-01-19 20:34:10 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
/* if a text size is too small, the text cannot be drawn, and it is drawn as a single
|
|
|
|
* graphic line */
|
2013-04-11 17:40:20 +00:00
|
|
|
if( aDC && ( aDC->LogicalToDeviceYRel( std::abs( aSize.y ) ) < MIN_DRAWABLE_TEXT_SIZE ))
|
2009-04-17 12:45:22 +00:00
|
|
|
{
|
2013-04-10 19:09:59 +00:00
|
|
|
// draw the text as a line always vertically centered
|
2009-05-28 17:39:40 +00:00
|
|
|
wxPoint end( current_char_pos.x + dx, current_char_pos.y );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2009-05-12 12:12:34 +00:00
|
|
|
RotatePoint( ¤t_char_pos, aPos, aOrient );
|
|
|
|
RotatePoint( &end, aPos, aOrient );
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2010-12-28 11:24:42 +00:00
|
|
|
if( aPlotter )
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->MoveTo( current_char_pos );
|
|
|
|
aPlotter->FinishTo( end );
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
|
|
|
else if( aCallback )
|
|
|
|
{
|
2009-05-12 12:12:34 +00:00
|
|
|
aCallback( current_char_pos.x, current_char_pos.y, end.x, end.y );
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
2008-12-16 19:44:57 +00:00
|
|
|
else
|
2013-06-29 09:52:22 +00:00
|
|
|
GRLine( aClipBox, aDC,
|
2009-05-28 17:39:40 +00:00
|
|
|
current_char_pos.x, current_char_pos.y, end.x, end.y, aWidth, aColor );
|
2008-01-19 20:34:10 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
if( aItalic )
|
|
|
|
{
|
2013-04-10 19:09:59 +00:00
|
|
|
overbar_italic_comp = OverbarPositionY( size_v ) / 8;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
if( italic_reverse )
|
|
|
|
{
|
|
|
|
overbar_italic_comp = -overbar_italic_comp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
overbar_italic_comp = 0;
|
2013-04-03 16:16:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
int overbars = 0; // Number of '~' seen (except '~~')
|
|
|
|
ptr = 0; // ptr = text index
|
2009-05-28 17:39:40 +00:00
|
|
|
|
2009-04-06 10:56:17 +00:00
|
|
|
while( ptr < char_count )
|
2008-01-19 20:34:10 +00:00
|
|
|
{
|
2009-05-28 17:39:40 +00:00
|
|
|
if( aText[ptr + overbars] == '~' )
|
2009-04-17 12:45:22 +00:00
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
if( ptr + overbars + 1 < aText.length()
|
|
|
|
&& aText[ptr + overbars + 1] == '~' ) /* '~~' draw as '~' */
|
|
|
|
ptr++; // skip first '~' char and draw second
|
2009-04-17 12:45:22 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
else
|
|
|
|
{
|
2013-04-07 11:55:18 +00:00
|
|
|
// Found an overbar, adjust the pointers
|
2013-03-27 20:38:20 +00:00
|
|
|
overbars++;
|
|
|
|
|
|
|
|
if( overbars & 1 ) // odd overbars count
|
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
// Starting the overbar
|
|
|
|
overbar_pos = current_char_pos;
|
|
|
|
overbar_pos.x += overbar_italic_comp;
|
2013-04-10 19:09:59 +00:00
|
|
|
overbar_pos.y -= OverbarPositionY( size_v );
|
2013-03-27 20:38:20 +00:00
|
|
|
RotatePoint( &overbar_pos, aPos, aOrient );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-03 16:16:26 +00:00
|
|
|
// Ending the overbar
|
|
|
|
coord[0] = overbar_pos;
|
|
|
|
overbar_pos = current_char_pos;
|
|
|
|
overbar_pos.x += overbar_italic_comp;
|
2013-04-10 19:09:59 +00:00
|
|
|
overbar_pos.y -= OverbarPositionY( size_v );
|
2013-03-27 20:38:20 +00:00
|
|
|
RotatePoint( &overbar_pos, aPos, aOrient );
|
|
|
|
coord[1] = overbar_pos;
|
2013-04-03 16:16:26 +00:00
|
|
|
// Plot the overbar segment
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicTextPline( aClipBox, aDC, aColor, aWidth,
|
2013-03-27 20:38:20 +00:00
|
|
|
sketch_mode, 2, coord, aCallback, aPlotter );
|
|
|
|
}
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
continue; // Skip ~ processing
|
2009-05-28 17:39:40 +00:00
|
|
|
}
|
2009-04-17 12:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AsciiCode = aText.GetChar( ptr + overbars );
|
2009-04-13 05:58:11 +00:00
|
|
|
|
2009-05-30 16:06:01 +00:00
|
|
|
const char* ptcar = GetHersheyShapeDescription( AsciiCode );
|
2013-04-03 16:16:26 +00:00
|
|
|
// Get metrics
|
|
|
|
int xsta = *ptcar++ - 'R';
|
|
|
|
int xsto = *ptcar++ - 'R';
|
2009-05-28 17:39:40 +00:00
|
|
|
int point_count = 0;
|
|
|
|
bool endcar = false;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
while( !endcar )
|
2008-01-19 20:34:10 +00:00
|
|
|
{
|
2009-05-28 17:39:40 +00:00
|
|
|
int hc1, hc2;
|
|
|
|
hc1 = *ptcar++;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
if( hc1 )
|
2008-01-19 20:34:10 +00:00
|
|
|
{
|
2009-05-28 17:39:40 +00:00
|
|
|
hc2 = *ptcar++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
// End of character, insert a synthetic pen up:
|
2013-04-07 11:55:18 +00:00
|
|
|
hc1 = ' ';
|
|
|
|
hc2 = 'R';
|
|
|
|
endcar = true;
|
2009-05-28 17:39:40 +00:00
|
|
|
}
|
2013-04-03 16:16:26 +00:00
|
|
|
|
|
|
|
// Do the Hershey decode thing:
|
|
|
|
// coordinates values are coded as <value> + 'R'
|
|
|
|
hc1 -= 'R';
|
|
|
|
hc2 -= 'R';
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
// Pen up request
|
2009-05-28 17:39:40 +00:00
|
|
|
if( hc1 == -50 && hc2 == 0 )
|
|
|
|
{
|
|
|
|
if( point_count )
|
2008-01-19 20:34:10 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
if( aWidth <= 1 )
|
2009-04-17 12:45:22 +00:00
|
|
|
aWidth = 0;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicTextPline( aClipBox, aDC, aColor, aWidth,
|
2009-06-28 16:50:42 +00:00
|
|
|
sketch_mode, point_count, coord,
|
2010-12-28 11:24:42 +00:00
|
|
|
aCallback, aPlotter );
|
2008-01-19 20:34:10 +00:00
|
|
|
}
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
point_count = 0;
|
|
|
|
}
|
|
|
|
else
|
2009-04-17 12:45:22 +00:00
|
|
|
{
|
2009-05-12 12:12:34 +00:00
|
|
|
wxPoint currpoint;
|
2013-04-10 19:09:59 +00:00
|
|
|
hc1 -= xsta; hc2 -= 10; // Align the midpoint
|
2013-04-07 11:55:18 +00:00
|
|
|
hc1 = KiROUND( hc1 * size_h * s_HersheyScaleFactor );
|
|
|
|
hc2 = KiROUND( hc2 * size_v * s_HersheyScaleFactor );
|
2009-04-17 12:45:22 +00:00
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
// To simulate an italic font,
|
|
|
|
// add a x offset depending on the y offset
|
2009-04-17 12:45:22 +00:00
|
|
|
if( aItalic )
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
hc1 -= KiROUND( italic_reverse ? -hc2 / 8.0 : hc2 / 8.0 );
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
currpoint.x = hc1 + current_char_pos.x;
|
|
|
|
currpoint.y = hc2 + current_char_pos.y;
|
2009-04-17 12:45:22 +00:00
|
|
|
|
2009-05-12 12:12:34 +00:00
|
|
|
RotatePoint( &currpoint, aPos, aOrient );
|
|
|
|
coord[point_count] = currpoint;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
if( point_count < BUF_SIZE - 1 )
|
2009-04-17 12:45:22 +00:00
|
|
|
point_count++;
|
2008-01-19 20:34:10 +00:00
|
|
|
}
|
2013-04-03 16:16:26 +00:00
|
|
|
} // end draw 1 char
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-05-12 12:12:34 +00:00
|
|
|
ptr++;
|
2009-05-28 17:39:40 +00:00
|
|
|
|
|
|
|
// Apply the advance width
|
2013-04-07 11:55:18 +00:00
|
|
|
current_char_pos.x += KiROUND( size_h * (xsto - xsta) * s_HersheyScaleFactor );
|
2008-01-19 20:34:10 +00:00
|
|
|
}
|
2009-04-17 12:45:22 +00:00
|
|
|
|
|
|
|
if( overbars % 2 )
|
|
|
|
{
|
2013-04-07 11:55:18 +00:00
|
|
|
// Close the last overbar
|
|
|
|
coord[0] = overbar_pos;
|
|
|
|
overbar_pos = current_char_pos;
|
2013-04-10 19:09:59 +00:00
|
|
|
overbar_pos.y -= OverbarPositionY( size_v );
|
2009-05-12 12:12:34 +00:00
|
|
|
RotatePoint( &overbar_pos, aPos, aOrient );
|
|
|
|
coord[1] = overbar_pos;
|
2013-04-07 11:55:18 +00:00
|
|
|
|
|
|
|
// Plot the overbar segment
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicTextPline( aClipBox, aDC, aColor, aWidth,
|
2010-12-28 11:24:42 +00:00
|
|
|
sketch_mode, 2, coord, aCallback, aPlotter );
|
2009-04-06 10:56:17 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
void DrawGraphicHaloText( EDA_RECT* aClipBox, wxDC * aDC,
|
2013-04-09 17:16:53 +00:00
|
|
|
const wxPoint &aPos,
|
|
|
|
enum EDA_COLOR_T aBgColor,
|
|
|
|
enum EDA_COLOR_T aColor1,
|
|
|
|
enum EDA_COLOR_T aColor2,
|
|
|
|
const wxString &aText,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aOrient,
|
2013-04-09 17:16:53 +00:00
|
|
|
const wxSize &aSize,
|
|
|
|
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
|
|
|
enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
2013-06-29 09:52:22 +00:00
|
|
|
int aWidth, bool aItalic, bool aBold,
|
2013-04-09 17:16:53 +00:00
|
|
|
void (*aCallback)( int x0, int y0, int xf, int yf ),
|
|
|
|
PLOTTER * aPlotter )
|
|
|
|
{
|
|
|
|
// Swap color if contrast would be better
|
2013-06-29 09:52:22 +00:00
|
|
|
if( ColorIsLight( aBgColor ) )
|
|
|
|
{
|
2013-04-09 17:16:53 +00:00
|
|
|
EDA_COLOR_T c = aColor1;
|
|
|
|
aColor1 = aColor2;
|
|
|
|
aColor2 = c;
|
|
|
|
}
|
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicText( aClipBox, aDC, aPos, aColor1, aText, aOrient, aSize,
|
2013-04-11 17:40:20 +00:00
|
|
|
aH_justify, aV_justify, aWidth, aItalic, aBold,
|
2013-04-09 17:16:53 +00:00
|
|
|
aCallback, aPlotter );
|
2013-04-11 17:40:20 +00:00
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicText( aClipBox, aDC, aPos, aColor2, aText, aOrient, aSize,
|
2013-04-11 17:40:20 +00:00
|
|
|
aH_justify, aV_justify, aWidth / 4, aItalic, aBold,
|
2013-04-09 17:16:53 +00:00
|
|
|
aCallback, aPlotter );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function PlotGraphicText
|
2008-12-14 19:45:05 +00:00
|
|
|
* same as DrawGraphicText, but plot graphic text insteed of draw it
|
|
|
|
* @param aPos = text position (according to aH_justify, aV_justify)
|
2012-03-26 23:47:08 +00:00
|
|
|
* @param aColor (enum EDA_COLOR_T) = text color
|
2008-12-14 19:45:05 +00:00
|
|
|
* @param aText = text to draw
|
|
|
|
* @param aOrient = angle in 0.1 degree
|
|
|
|
* @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
|
|
|
|
* @param aH_justify = horizontal justification (Left, center, right)
|
|
|
|
* @param aV_justify = vertical justification (bottom, center, top)
|
2008-12-19 20:40:08 +00:00
|
|
|
* @param aWidth = line width (pen width) (default = 0)
|
|
|
|
* if width < 0 : draw segments in sketch mode, width = abs(width)
|
2009-05-30 16:06:01 +00:00
|
|
|
* Use a value min(aSize.x, aSize.y) / 5 for a bold text
|
2008-12-19 20:40:08 +00:00
|
|
|
* @param aItalic = true to simulate an italic font
|
2009-05-30 16:06:01 +00:00
|
|
|
* @param aBold = true to use a bold font Useful only with default width value (aWidth = 0)
|
2013-12-23 16:25:13 +00:00
|
|
|
* @param aMultilineAllowed = true to plot text as multiline, otherwise single line
|
2008-01-19 20:34:10 +00:00
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void PLOTTER::Text( const wxPoint& aPos,
|
2012-03-26 23:47:08 +00:00
|
|
|
enum EDA_COLOR_T aColor,
|
2010-09-11 16:33:43 +00:00
|
|
|
const wxString& aText,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aOrient,
|
2010-09-11 16:33:43 +00:00
|
|
|
const wxSize& aSize,
|
2012-01-03 17:14:17 +00:00
|
|
|
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
|
|
|
enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
2010-09-11 16:33:43 +00:00
|
|
|
int aWidth,
|
|
|
|
bool aItalic,
|
2013-12-23 16:25:13 +00:00
|
|
|
bool aBold,
|
|
|
|
bool aMultilineAllowed )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-06-09 09:38:58 +00:00
|
|
|
int textPensize = aWidth;
|
|
|
|
|
2013-04-03 16:16:26 +00:00
|
|
|
if( textPensize == 0 && aBold ) // Use default values if aWidth == 0
|
2012-09-22 11:19:37 +00:00
|
|
|
textPensize = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );
|
2009-05-28 17:39:40 +00:00
|
|
|
|
2012-06-09 09:38:58 +00:00
|
|
|
if( textPensize >= 0 )
|
|
|
|
textPensize = Clamp_Text_PenSize( aWidth, aSize, aBold );
|
2009-06-02 07:26:49 +00:00
|
|
|
else
|
2012-06-09 09:38:58 +00:00
|
|
|
textPensize = -Clamp_Text_PenSize( -aWidth, aSize, aBold );
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2012-06-09 09:38:58 +00:00
|
|
|
SetCurrentLineWidth( textPensize );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
if( aColor >= 0 )
|
2012-05-03 18:37:56 +00:00
|
|
|
SetColor( aColor );
|
2008-01-19 20:34:10 +00:00
|
|
|
|
2013-12-23 16:25:13 +00:00
|
|
|
if( aMultilineAllowed )
|
|
|
|
{
|
|
|
|
// EDA_TEXT needs for calculations of the position of every
|
|
|
|
// line according to orientation and justifications
|
2015-01-15 20:01:53 +00:00
|
|
|
wxArrayString strings;
|
2013-12-23 16:25:13 +00:00
|
|
|
EDA_TEXT* multilineText = new EDA_TEXT( aText );
|
|
|
|
multilineText->SetSize( aSize );
|
|
|
|
multilineText->SetTextPosition( aPos );
|
|
|
|
multilineText->SetOrientation( aOrient );
|
|
|
|
multilineText->SetHorizJustify( aH_justify );
|
|
|
|
multilineText->SetVertJustify( aV_justify );
|
|
|
|
multilineText->SetThickness( aWidth );
|
|
|
|
multilineText->SetMultilineAllowed( aMultilineAllowed );
|
|
|
|
|
|
|
|
std::vector<wxPoint> positions;
|
2015-01-15 20:01:53 +00:00
|
|
|
wxStringSplit( aText, strings, '\n' );
|
|
|
|
positions.reserve( strings.Count() );
|
2013-12-23 16:25:13 +00:00
|
|
|
|
|
|
|
multilineText->GetPositionsOfLinesOfMultilineText(
|
2015-01-15 20:01:53 +00:00
|
|
|
positions, strings.Count() );
|
2013-12-23 16:25:13 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 0; ii < strings.Count(); ii++ )
|
2013-12-23 16:25:13 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString& txt = strings.Item( ii );
|
2013-12-23 16:25:13 +00:00
|
|
|
DrawGraphicText( NULL, NULL, positions[ii], aColor, txt,
|
|
|
|
aOrient, aSize,
|
|
|
|
aH_justify, aV_justify,
|
|
|
|
textPensize, aItalic,
|
|
|
|
aBold,
|
|
|
|
NULL,
|
|
|
|
this );
|
|
|
|
}
|
2015-01-15 20:01:53 +00:00
|
|
|
|
2013-12-23 16:25:13 +00:00
|
|
|
delete multilineText;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DrawGraphicText( NULL, NULL, aPos, aColor, aText,
|
|
|
|
aOrient, aSize,
|
|
|
|
aH_justify, aV_justify,
|
|
|
|
textPensize, aItalic,
|
|
|
|
aBold,
|
|
|
|
NULL,
|
|
|
|
this );
|
|
|
|
}
|
2012-06-09 09:38:58 +00:00
|
|
|
|
|
|
|
if( aWidth != textPensize )
|
|
|
|
SetCurrentLineWidth( aWidth );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|