2014-10-22 15:51:34 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2014 Jerry Jacobs
|
2022-01-10 01:53:01 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-22 15:51:34 +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
|
|
|
|
*/
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
#ifndef GR_TEXT_H
|
|
|
|
#define GR_TEXT_H
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2021-12-28 22:13:54 +00:00
|
|
|
#include <font/text_attributes.h>
|
|
|
|
|
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class COLOR4D;
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2020-12-19 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Minimum dimension in pixel for drawing/no drawing a text used in Pcbnew to decide to
|
|
|
|
* draw (or not) some texts ( like net names on pads/tracks ).
|
|
|
|
*
|
|
|
|
* When a text height is smaller than MIN_TEXT_SIZE, it is not drawn by Pcbnew.
|
2013-04-11 17:40:20 +00:00
|
|
|
*/
|
2013-04-09 16:00:46 +00:00
|
|
|
#define MIN_TEXT_SIZE 5
|
|
|
|
|
2013-04-11 17:40:20 +00:00
|
|
|
/* Absolute minimum dimension in pixel to draw a text as text or a line
|
|
|
|
* When a text height is smaller than MIN_DRAWABLE_TEXT_SIZE,
|
|
|
|
* it is drawn, but like a line by the draw text function
|
|
|
|
*/
|
|
|
|
#define MIN_DRAWABLE_TEXT_SIZE 3
|
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
class PLOTTER;
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2010-11-12 16:59:16 +00:00
|
|
|
/**
|
2022-09-07 10:05:23 +00:00
|
|
|
* Pen width should not allow characters to become cluttered up in their own fatness. Normal
|
|
|
|
* text is normally around 15% the fontsize, and bold text around 20%. So we set a hard limit
|
|
|
|
* at 25%, and a secondary limit for non-decorative text that must be readable at small sizes
|
|
|
|
* at 18%.
|
2020-12-19 16:00:52 +00:00
|
|
|
*
|
|
|
|
* @param aPenSize the pen size to clamp.
|
|
|
|
* @param aSize the char size (height or width, or its wxSize).
|
|
|
|
* @param aBold true if text accept bold pen size.
|
|
|
|
* @return the max pen size allowed.
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2022-09-07 10:05:23 +00:00
|
|
|
int Clamp_Text_PenSize( int aPenSize, int aSize, bool aStrict = false );
|
|
|
|
float Clamp_Text_PenSize( float aPenSize, int aSize, bool aStrict = false );
|
|
|
|
int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aStrict = false );
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2010-11-12 16:59:16 +00:00
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* @param aTextSize the char size (height or width).
|
|
|
|
* @return the "best" value for a pen size to draw/plot a bold text.
|
2009-05-30 16:06:01 +00:00
|
|
|
*/
|
|
|
|
int GetPenSizeForBold( int aTextSize );
|
2021-12-31 14:07:24 +00:00
|
|
|
int GetPenSizeForBold( const wxSize& aTextSize );
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2020-05-12 14:02:24 +00:00
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* @param aTextSize = the char size (height or width).
|
|
|
|
* @return the "best" value for a pen size to draw/plot a non-bold text.
|
2020-05-12 14:02:24 +00:00
|
|
|
*/
|
|
|
|
int GetPenSizeForNormal( int aTextSize );
|
2021-12-31 14:07:24 +00:00
|
|
|
int GetPenSizeForNormal( const wxSize& aTextSize );
|
2020-05-12 14:02:24 +00:00
|
|
|
|
2022-06-03 17:47:03 +00:00
|
|
|
inline void InferBold( TEXT_ATTRIBUTES* aAttrs )
|
|
|
|
{
|
|
|
|
int penSize( aAttrs->m_StrokeWidth );
|
|
|
|
wxSize textSize( aAttrs->m_Size.x, aAttrs->m_Size.y );
|
|
|
|
|
|
|
|
aAttrs->m_Bold = abs( penSize - GetPenSizeForBold( textSize ) )
|
|
|
|
< abs( penSize - GetPenSizeForNormal( textSize ) );
|
|
|
|
}
|
|
|
|
|
2022-05-20 11:26:17 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-12 17:36:16 +00:00
|
|
|
* Returns the margin for knocking out text.
|
2022-05-20 11:26:17 +00:00
|
|
|
*
|
|
|
|
* Note that this is not a perfect calculation as fonts (especially outline fonts) vary greatly
|
|
|
|
* in how well ascender and descender heights are enforced.
|
|
|
|
*/
|
|
|
|
inline int GetKnockoutTextMargin( const VECTOR2I& aSize, int aThickness )
|
|
|
|
{
|
2022-12-12 17:36:16 +00:00
|
|
|
return std::max( KiROUND( aThickness / 2 ), KiROUND( aSize.y / 7.0 ) );
|
2022-05-20 11:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:59:16 +00:00
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* The full X size is GraphicTextWidth + the thickness of graphic lines.
|
|
|
|
*
|
|
|
|
* @return the X size of the graphic text.
|
2009-05-29 07:29:55 +00:00
|
|
|
*/
|
2021-12-31 14:07:24 +00:00
|
|
|
int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize,
|
2022-01-07 14:49:17 +00:00
|
|
|
int aThickness, bool aBold, bool aItalic );
|
2009-05-28 17:39:40 +00:00
|
|
|
|
2010-11-12 16:59:16 +00:00
|
|
|
/**
|
2022-01-10 01:53:01 +00:00
|
|
|
* Print a graphic text through wxDC.
|
2020-12-19 16:00:52 +00:00
|
|
|
*
|
2022-01-10 01:53:01 +00:00
|
|
|
* @param aDC is the current Device Context.
|
|
|
|
* @param aPos is the text position (according to h_justify, v_justify).
|
|
|
|
* @param aColor is the text color.
|
|
|
|
* @param aText is the text to draw.
|
|
|
|
* @param aOrient is the angle.
|
|
|
|
* @param aSize is the text size (size.x or size.y can be < 0 for mirrored texts).
|
|
|
|
* @param aH_justify is the horizontal justification (Left, center, right).
|
|
|
|
* @param aV_justify is the vertical justification (bottom, center, top).
|
|
|
|
* @param aWidth is the line width (pen width) (use default width if aWidth = 0).
|
|
|
|
* if width < 0 : draw segments in sketch mode, width = abs(width)
|
|
|
|
* Use a value min(aSize.x, aSize.y) / 5 for a bold text.
|
|
|
|
* @param aItalic is the true to simulate an italic font.
|
|
|
|
* @param aBold use true to use a bold font. Useful only with default width value (aWidth = 0).
|
2021-12-29 17:31:40 +00:00
|
|
|
* @param aFont is the font to use, or nullptr for the KiCad stroke font
|
2009-01-19 19:08:42 +00:00
|
|
|
*/
|
2022-01-10 01:53:01 +00:00
|
|
|
void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const KIGFX::COLOR4D& aColor,
|
|
|
|
const wxString& aText, const EDA_ANGLE& aOrient, const VECTOR2I& aSize,
|
|
|
|
enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify,
|
|
|
|
int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont );
|
|
|
|
|
2009-01-19 19:08:42 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
#endif /* GR_TEXT_H */
|