KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gr_text.cpp File Reference
#include <gr_basic.h>
#include <plotters/plotter.h>
#include <trigo.h>
#include <math/util.h>
#include <font/font.h>
#include <callback_gal.h>

Go to the source code of this file.

Functions

int GetPenSizeForBold (int aTextSize)
 
int GetPenSizeForDemiBold (int aTextSize)
 
int GetPenSizeForBold (const wxSize &aTextSize)
 
int GetPenSizeForDemiBold (const wxSize &aTextSize)
 
int GetPenSizeForNormal (int aTextSize)
 
int GetPenSizeForNormal (const wxSize &aTextSize)
 
int ClampTextPenSize (int aPenSize, int aSize, bool aStrict)
 Pen width should not allow characters to become cluttered up in their own fatness.
 
float ClampTextPenSize (float aPenSize, int aSize, bool aStrict)
 
int ClampTextPenSize (int aPenSize, const VECTOR2I &aSize, bool aStrict)
 
int GRTextWidth (const wxString &aText, KIFONT::FONT *aFont, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS &aFontMetrics)
 
void GRPrintText (wxDC *aDC, const VECTOR2I &aPos, const 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, const KIFONT::METRICS &aFontMetrics)
 Print a graphic text through wxDC.
 

Function Documentation

◆ ClampTextPenSize() [1/3]

float ClampTextPenSize ( float  aPenSize,
int  aSize,
bool  aStrict 
)

Definition at line 81 of file gr_text.cpp.

References scale.

◆ ClampTextPenSize() [2/3]

int ClampTextPenSize ( int  aPenSize,
const VECTOR2I aSize,
bool  aStrict 
)

Definition at line 90 of file gr_text.cpp.

References std::abs(), ClampTextPenSize(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ ClampTextPenSize() [3/3]

int ClampTextPenSize ( int  aPenSize,
int  aSize,
bool  aStrict = false 
)

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%.

Parameters
aPenSizethe pen size to clamp.
aSizethe char size (height or width, or its wxSize).
aBoldtrue if text accept bold pen size.
Returns
the max pen size allowed.

Definition at line 72 of file gr_text.cpp.

References KiROUND(), and scale.

Referenced by ClampTextPenSize(), KIGFX::SCH_PAINTER::draw(), EDA_TEXT::GetEffectiveTextPenWidth(), DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES::Validate(), and DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Validate().

◆ GetPenSizeForBold() [1/2]

int GetPenSizeForBold ( const wxSize &  aTextSize)

Definition at line 48 of file gr_text.cpp.

References GetPenSizeForBold().

◆ GetPenSizeForBold() [2/2]

◆ GetPenSizeForDemiBold() [1/2]

int GetPenSizeForDemiBold ( const wxSize &  aTextSize)

Definition at line 54 of file gr_text.cpp.

References GetPenSizeForDemiBold().

◆ GetPenSizeForDemiBold() [2/2]

int GetPenSizeForDemiBold ( int  aTextSize)
Parameters
aTextSizethe char size (height or width).
Returns
the "best" value for a pen size to draw/plot a demibold text.

Definition at line 42 of file gr_text.cpp.

References KiROUND().

Referenced by KIGFX::SCH_PAINTER::draw(), and GetPenSizeForDemiBold().

◆ GetPenSizeForNormal() [1/2]

int GetPenSizeForNormal ( const wxSize &  aTextSize)

Definition at line 66 of file gr_text.cpp.

References GetPenSizeForNormal().

◆ GetPenSizeForNormal() [2/2]

◆ GRPrintText()

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,
const KIFONT::METRICS aFontMetrics 
)

Print a graphic text through wxDC.

Parameters
aDCis the current Device Context.
aPosis the text position (according to h_justify, v_justify).
aColoris the text color.
aTextis the text to draw.
aOrientis the angle.
aSizeis the text size (size.x or size.y can be < 0 for mirrored texts).
aH_justifyis the horizontal justification (Left, center, right).
aV_justifyis the vertical justification (bottom, center, top).
aWidthis 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.
aItalicis the true to simulate an italic font.
aBolduse true to use a bold font. Useful only with default width value (aWidth = 0).
aFontis the font to use, or nullptr for the KiCad stroke font

Definition at line 109 of file gr_text.cpp.

References KIFONT::FONT::Draw(), KIFONT::FONT::GetFont(), GetPenSizeForBold(), GetPenSizeForNormal(), GRClosedPoly(), GRCSegm(), GRLine(), TEXT_ATTRIBUTES::m_Angle, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SCH_FIELD::Print(), SCH_TEXT::Print(), EDA_TEXT::printOneLineOfText(), SCH_PIN::printPinElectricalTypeName(), and SCH_PIN::printPinTexts().

◆ GRTextWidth()

int GRTextWidth ( const wxString &  aText,
KIFONT::FONT aFont,
const VECTOR2I aSize,
int  aThickness,
bool  aBold,
bool  aItalic,
const KIFONT::METRICS aFontMetrics 
)
Returns
the X size of the graphic text.

Definition at line 98 of file gr_text.cpp.

References KIFONT::FONT::GetFont(), KiROUND(), KIFONT::FONT::StringBoundaryLimits(), and VECTOR2< T >::x.

Referenced by SVG_PLOTTER::Text(), and ROUTER_STATUS_VIEW_ITEM::ViewDraw().