KiCad PCB EDA Suite
gr_text.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2009-2014 Jerry Jacobs
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef GR_TEXT_H
26#define GR_TEXT_H
27
28#include <eda_item.h>
30
31namespace KIGFX
32{
33 class COLOR4D;
34}
35
42#define MIN_TEXT_SIZE 5
43
44/* Absolute minimum dimension in pixel to draw a text as text or a line
45 * When a text height is smaller than MIN_DRAWABLE_TEXT_SIZE,
46 * it is drawn, but like a line by the draw text function
47*/
48#define MIN_DRAWABLE_TEXT_SIZE 3
49
50class PLOTTER;
51
63int Clamp_Text_PenSize( int aPenSize, int aSize, bool aStrict = false );
64float Clamp_Text_PenSize( float aPenSize, int aSize, bool aStrict = false );
65int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aStrict = false );
66
71int GetPenSizeForBold( int aTextSize );
72int GetPenSizeForBold( const wxSize& aTextSize );
73
78int GetPenSizeForNormal( int aTextSize );
79int GetPenSizeForNormal( const wxSize& aTextSize );
80
81inline void InferBold( TEXT_ATTRIBUTES* aAttrs )
82{
83 int penSize( aAttrs->m_StrokeWidth );
84 wxSize textSize( aAttrs->m_Size.x, aAttrs->m_Size.y );
85
86 aAttrs->m_Bold = abs( penSize - GetPenSizeForBold( textSize ) )
87 < abs( penSize - GetPenSizeForNormal( textSize ) );
88}
89
90
97inline int GetKnockoutTextMargin( const VECTOR2I& aSize, int aThickness )
98{
99 return std::max( KiROUND( aThickness / 2 ), KiROUND( aSize.y / 7.0 ) );
100}
101
102
108int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize,
109 int aThickness, bool aBold, bool aItalic );
110
129void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const KIGFX::COLOR4D& aColor,
130 const wxString& aText, const EDA_ANGLE& aOrient, const VECTOR2I& aSize,
131 enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify,
132 int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont );
133
134
135#endif /* GR_TEXT_H */
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:110
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aStrict=false)
Pen width should not allow characters to become cluttered up in their own fatness.
Definition: gr_text.cpp:75
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
void InferBold(TEXT_ATTRIBUTES *aAttrs)
Definition: gr_text.h:81
int GraphicTextWidth(const wxString &aText, KIFONT::FONT *aFont, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic)
The full X size is GraphicTextWidth + the thickness of graphic lines.
Definition: gr_text.cpp:101
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:52
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)
Print a graphic text through wxDC.
Definition: gr_text.cpp:129
int GetKnockoutTextMargin(const VECTOR2I &aSize, int aThickness)
Returns the margin for knocking out text.
Definition: gr_text.h:97
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:412
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85