KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIFONT::FONT Class Referenceabstract

FONT is an abstract base class for both outline and stroke fonts. More...

#include <font.h>

Inheritance diagram for KIFONT::FONT:
KIFONT::OUTLINE_FONT KIFONT::STROKE_FONT

Public Member Functions

 FONT ()
 
virtual ~FONT ()
 
virtual bool IsStroke () const
 
virtual bool IsOutline () const
 
virtual bool IsBold () const
 
virtual bool IsItalic () const
 
const wxString & GetName () const
 
const char * NameAsToken () const
 
void Draw (KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttrs) const
 Draw a string. More...
 
void Draw (KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttributes) const
 
VECTOR2I StringBoundaryLimits (const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic) const
 Compute the boundary limits of aText (the bounding box of all shapes). More...
 
void LinebreakText (wxString &aText, int aColumnWidth, const VECTOR2I &aGlyphSize, int aThickness, bool aBold, bool aItalic) const
 Insert
characters into text to ensure that no lines are wider than aColumnWidth. More...
 
virtual double ComputeOverbarVerticalPosition (double aGlyphHeight) const =0
 Compute the vertical position of an overbar. More...
 
virtual double ComputeUnderlineVerticalPosition (double aGlyphHeight) const =0
 Compute the vertical position of an underline. More...
 
virtual double GetInterline (double aGlyphHeight, double aLineSpacing=1.0) const =0
 Compute the distance (interline) between 2 lines of text (for multiline texts). More...
 
virtual VECTOR2I GetTextAsGlyphs (BOX2I *aBBox, std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aSize, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin, TEXT_STYLE_FLAGS aTextStyle) const =0
 Convert text string to an array of GLYPHs. More...
 

Static Public Member Functions

static FONTGetFont (const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
 
static bool IsStroke (const wxString &aFontName)
 

Protected Member Functions

unsigned linesCount (const wxString &aText) const
 Returns number of lines for a given text. More...
 
void drawSingleLineText (KIGFX::GAL *aGal, BOX2I *aBoundingBox, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin, bool aItalic, bool aUnderline) const
 Draws a single line of text. More...
 
VECTOR2I boundingBoxSingleLine (BOX2I *aBBox, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aSize, bool aItalic) const
 Computes the bounding box for a single line of text. More...
 
void getLinePositions (const wxString &aText, const VECTOR2I &aPosition, wxArrayString &aTextLines, std::vector< VECTOR2I > &aPositions, std::vector< VECTOR2I > &aExtents, const TEXT_ATTRIBUTES &aAttrs) const
 
VECTOR2I drawMarkup (BOX2I *aBoundingBox, std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin, TEXT_STYLE_FLAGS aTextStyle) const
 
void wordbreakMarkup (std::vector< std::pair< wxString, int > > *aWords, const wxString &aText, const VECTOR2I &aSize, TEXT_STYLE_FLAGS aTextStyle) const
 Factor that determines the pitch between 2 lines. More...
 

Protected Attributes

wxString m_fontName
 Font name. More...
 
wxString m_fontFileName
 Font file name. More...
 

Static Protected Attributes

static constexpr double INTERLINE_PITCH_RATIO = 1.61
 

Static Private Member Functions

static FONTgetDefaultFont ()
 

Static Private Attributes

static FONTs_defaultFont = nullptr
 
static std::map< std::tuple< wxString, bool, bool >, FONT * > s_fontMap
 

Detailed Description

FONT is an abstract base class for both outline and stroke fonts.

Definition at line 104 of file font.h.

Constructor & Destructor Documentation

◆ FONT()

FONT::FONT ( )
explicit

Definition at line 123 of file font.cpp.

◆ ~FONT()

virtual KIFONT::FONT::~FONT ( )
inlinevirtual

Definition at line 109 of file font.h.

Member Function Documentation

◆ boundingBoxSingleLine()

VECTOR2I FONT::boundingBoxSingleLine ( BOX2I aBBox,
const wxString &  aText,
const VECTOR2I aPosition,
const VECTOR2I aSize,
bool  aItalic 
) const
protected

Computes the bounding box for a single line of text.

Multiline texts should be split before using the function.

Parameters
aBBoxis an optional pointer to be filled with the bounding box.
aTextis the text to be drawn.
aPositionis text position.
aSizeis the cap-height and em-width of the text.
Returns
new cursor position

Definition at line 443 of file font.cpp.

References ANGLE_0, and drawMarkup().

Referenced by getLinePositions().

◆ ComputeOverbarVerticalPosition()

virtual double KIFONT::FONT::ComputeOverbarVerticalPosition ( double  aGlyphHeight) const
pure virtual

Compute the vertical position of an overbar.

This is the distance between the text baseline and the overbar.

Implemented in KIFONT::OUTLINE_FONT, and KIFONT::STROKE_FONT.

Referenced by drawMarkup().

◆ ComputeUnderlineVerticalPosition()

virtual double KIFONT::FONT::ComputeUnderlineVerticalPosition ( double  aGlyphHeight) const
pure virtual

Compute the vertical position of an underline.

This is the distance between the text baseline and the underline.

Implemented in KIFONT::OUTLINE_FONT, and KIFONT::STROKE_FONT.

Referenced by drawMarkup().

◆ Draw() [1/2]

void KIFONT::FONT::Draw ( KIGFX::GAL aGal,
const wxString &  aText,
const VECTOR2I aPosition,
const TEXT_ATTRIBUTES aAttributes 
) const
inline

Definition at line 137 of file font.h.

References Draw().

◆ Draw() [2/2]

void FONT::Draw ( KIGFX::GAL aGal,
const wxString &  aText,
const VECTOR2I aPosition,
const VECTOR2I aCursor,
const TEXT_ATTRIBUTES aAttrs 
) const

Draw a string.

Parameters
aGalis the graphics context.
aTextis the text to be drawn.
aPositionis the text position in world coordinates.
aCursoris the current text position (for multiple text blocks within a single text object, such as a run of superscript characters)
aAttrsare the styling attributes of the text, including its rotation
aGal
aTextis the text to be drawn.
aPositionis the text object position in world coordinates.
aCursoris the current text position (for multiple text blocks within a single text object, such as a run of superscript characters)
aAttrsare the styling attributes of the text, including its rotation

Definition at line 238 of file font.cpp.

References drawSingleLineText(), getLinePositions(), TEXT_ATTRIBUTES::m_Angle, TEXT_ATTRIBUTES::m_Italic, TEXT_ATTRIBUTES::m_Mirrored, TEXT_ATTRIBUTES::m_Size, TEXT_ATTRIBUTES::m_StrokeWidth, TEXT_ATTRIBUTES::m_Underlined, and KIGFX::GAL::SetLineWidth().

Referenced by BOARD_ADAPTER::addText(), KIGFX::GAL::BitmapText(), KIGFX::DS_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), Draw(), KIGFX::PREVIEW::DrawTextNextToCursor(), drawTicksAlongLine(), EDA_TEXT::GetEffectiveTextShape(), GRPrintText(), KIGFX::SCH_PAINTER::knockoutText(), PLOTTER::PlotText(), KIGFX::SCH_PAINTER::strokeText(), KIGFX::PCB_PAINTER::strokeText(), PLOTTER::Text(), PCB_TEXT::TransformTextToPolySet(), and PCB_TEXTBOX::TransformTextToPolySet().

◆ drawMarkup()

VECTOR2I FONT::drawMarkup ( BOX2I aBoundingBox,
std::vector< std::unique_ptr< GLYPH > > *  aGlyphs,
const wxString &  aText,
const VECTOR2I aPosition,
const VECTOR2I aSize,
const EDA_ANGLE aAngle,
bool  aMirror,
const VECTOR2I aOrigin,
TEXT_STYLE_FLAGS  aTextStyle 
) const
protected

◆ drawSingleLineText()

void FONT::drawSingleLineText ( KIGFX::GAL aGal,
BOX2I aBoundingBox,
const wxString &  aText,
const VECTOR2I aPosition,
const VECTOR2I aSize,
const EDA_ANGLE aAngle,
bool  aMirror,
const VECTOR2I aOrigin,
bool  aItalic,
bool  aUnderline 
) const
protected

Draws a single line of text.

Multiline texts should be split before using the function.

Parameters
aGalis a pointer to the graphics abstraction layer, or nullptr (nothing is drawn)
aBBoxis an optional pointer to be filled with the bounding box.
aTextis the text to be drawn.
aPositionis text position.
aSizeis the cap-height and em-width of the text
aAngleis text angle.
aMirroris true if text should be drawn mirrored, false otherwise.
aOriginis the point around which the text should be rotated, mirrored, etc.
Returns
new cursor position in non-rotated, non-mirrored coordinates

Definition at line 388 of file font.cpp.

References KIGFX::GAL::DrawGlyphs(), and drawMarkup().

Referenced by Draw().

◆ getDefaultFont()

FONT * FONT::getDefaultFont ( )
staticprivate

Definition at line 128 of file font.cpp.

References KIFONT::STROKE_FONT::LoadFont(), and s_defaultFont.

Referenced by GetFont().

◆ GetFont()

FONT * FONT::GetFont ( const wxString &  aFontName = wxEmptyString,
bool  aBold = false,
bool  aItalic = false 
)
static

Definition at line 137 of file font.cpp.

References getDefaultFont(), KICAD_FONT_NAME, KIFONT::OUTLINE_FONT::LoadFont(), and s_fontMap.

Referenced by LABEL_MANAGER::Add(), BOARD_ADAPTER::addText(), KIGFX::GAL::BitmapText(), BOOST_AUTO_TEST_CASE(), KIGFX::SCH_PAINTER::boxText(), KIGFX::DS_PAINTER::draw(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), KIGFX::PREVIEW::DrawTextNextToCursor(), drawTicksAlongLine(), LIB_PIN::GetBoundingBox(), EDA_TEXT::getDrawFont(), LIB_FIELD::getDrawFont(), LIB_TEXT::getDrawFont(), LIB_TEXTBOX::getDrawFont(), SCH_FIELD::getDrawFont(), SCH_TEXT::getDrawFont(), SCH_TEXTBOX::getDrawFont(), KIGFX::SCH_PAINTER::getFont(), FONT_CHOICE::GetFontSelection(), SCH_FIELD::GetRenderCache(), LIB_TEXTBOX::GetShownText(), SCH_TEXTBOX::GetShownText(), GraphicTextWidth(), GRPrintText(), KIGFX::SCH_PAINTER::knockoutText(), PCB_PARSER::parseEDA_TEXT(), SCH_SEXPR_PARSER::parseEDA_TEXT(), DRAWING_SHEET_PARSER::parseText(), SCH_FIELD::Plot(), SCH_LABEL_BASE::Plot(), SCH_TEXT::Plot(), SCH_TEXTBOX::Plot(), LIB_FIELD::Plot(), LIB_TEXT::Plot(), LIB_TEXTBOX::Plot(), PlotDrawingSheet(), BRDITEMS_PLOTTER::PlotPcbText(), LIB_PIN::PlotPinTexts(), PLOTTER::PlotText(), SCH_FIELD::Print(), LIB_FIELD::print(), LIB_TEXT::print(), LIB_TEXTBOX::print(), SCH_TEXT::Print(), EDA_TEXT::printOneLineOfText(), LIB_PIN::printPinElectricalTypeName(), LIB_PIN::printPinTexts(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DRC_TEST_PROVIDER_TEXT_DIMS::Run(), FIELDS_GRID_TABLE< T >::SetValue(), KIGFX::SCH_PAINTER::strokeText(), KIGFX::PCB_PAINTER::strokeText(), PLOTTER::Text(), and PDF_PLOTTER::Text().

◆ GetInterline()

virtual double KIFONT::FONT::GetInterline ( double  aGlyphHeight,
double  aLineSpacing = 1.0 
) const
pure virtual

Compute the distance (interline) between 2 lines of text (for multiline texts).

This is the distance between baselines, not the space between line bounding boxes.

Implemented in KIFONT::STROKE_FONT, and KIFONT::OUTLINE_FONT.

Referenced by getLinePositions(), and EDA_TEXT::GetTextBox().

◆ getLinePositions()

◆ GetName()

const wxString & KIFONT::FONT::GetName ( ) const
inline

◆ GetTextAsGlyphs()

virtual VECTOR2I KIFONT::FONT::GetTextAsGlyphs ( BOX2I aBBox,
std::vector< std::unique_ptr< GLYPH > > *  aGlyphs,
const wxString &  aText,
const VECTOR2I aSize,
const VECTOR2I aPosition,
const EDA_ANGLE aAngle,
bool  aMirror,
const VECTOR2I aOrigin,
TEXT_STYLE_FLAGS  aTextStyle 
) const
pure virtual

Convert text string to an array of GLYPHs.

Parameters
aBBoxpointer to a BOX2I that will set to the bounding box, or nullptr
aGlyphsstorage for the returned GLYPHs
aTexttext to convert to polygon/polyline
aSizeis the cap-height and em-width of the text
aPositionposition of text (cursor position before this text)
aAngletext angle
aMirroris true if text should be drawn mirrored, false otherwise.
aOriginis the point around which the text should be rotated, mirrored, etc.
aTextStyletext style flags
Returns
text cursor position after this text

Implemented in KIFONT::OUTLINE_FONT, and KIFONT::STROKE_FONT.

Referenced by drawMarkup(), LinebreakText(), and wordbreakMarkup().

◆ IsBold()

virtual bool KIFONT::FONT::IsBold ( ) const
inlinevirtual

Reimplemented in KIFONT::OUTLINE_FONT.

Definition at line 114 of file font.h.

Referenced by operator<<().

◆ IsItalic()

virtual bool KIFONT::FONT::IsItalic ( ) const
inlinevirtual

Reimplemented in KIFONT::OUTLINE_FONT.

Definition at line 115 of file font.h.

Referenced by operator<<().

◆ IsOutline()

◆ IsStroke() [1/2]

◆ IsStroke() [2/2]

bool FONT::IsStroke ( const wxString &  aFontName)
static

Definition at line 158 of file font.cpp.

References _, and KICAD_FONT_NAME.

◆ LinebreakText()

void FONT::LinebreakText ( wxString &  aText,
int  aColumnWidth,
const VECTOR2I aGlyphSize,
int  aThickness,
bool  aBold,
bool  aItalic 
) const

Insert
characters into text to ensure that no lines are wider than aColumnWidth.

Definition at line 567 of file font.cpp.

References ANGLE_0, GetTextAsGlyphs(), wordbreakMarkup(), wxStringSplit(), and VECTOR2< T >::x.

Referenced by LIB_TEXTBOX::GetShownText(), PCB_TEXTBOX::GetShownText(), and SCH_TEXTBOX::GetShownText().

◆ linesCount()

unsigned KIFONT::FONT::linesCount ( const wxString &  aText) const
inlineprotected

Returns number of lines for a given text.

Parameters
aTextis the text to be checked.
Returns
unsigned - The number of lines in aText.

Definition at line 202 of file font.h.

◆ NameAsToken()

const char * KIFONT::FONT::NameAsToken ( ) const
inline

Definition at line 122 of file font.h.

References GetName().

Referenced by DS_DATA_MODEL_IO::format().

◆ StringBoundaryLimits()

VECTOR2I FONT::StringBoundaryLimits ( const wxString &  aText,
const VECTOR2I aSize,
int  aThickness,
bool  aBold,
bool  aItalic 
) const

Compute the boundary limits of aText (the bounding box of all shapes).

Returns
a VECTOR2I giving the width and height of text.

Definition at line 413 of file font.cpp.

References ANGLE_0, boundingBox(), drawMarkup(), BOX2< Vec >::GetSize(), BOX2< Vec >::Inflate(), IsOutline(), IsStroke(), and KiROUND().

Referenced by LABEL_MANAGER::Add(), KIGFX::SCH_PAINTER::boxText(), EDA_TEXT::GetTextBox(), GraphicTextWidth(), PDF_PLOTTER::Text(), and LIB_PIN::validateExtentsCache().

◆ wordbreakMarkup()

void FONT::wordbreakMarkup ( std::vector< std::pair< wxString, int > > *  aWords,
const wxString &  aText,
const VECTOR2I aSize,
TEXT_STYLE_FLAGS  aTextStyle 
) const
protected

Factor that determines the pitch between 2 lines.

Definition at line 546 of file font.cpp.

References MARKUP::MARKUP_PARSER::Parse(), TO_UTF8, and wordbreakMarkup().

Referenced by LinebreakText(), and wordbreakMarkup().

Member Data Documentation

◆ INTERLINE_PITCH_RATIO

constexpr double KIFONT::FONT::INTERLINE_PITCH_RATIO = 1.61
staticconstexprprotected

◆ m_fontFileName

wxString KIFONT::FONT::m_fontFileName
protected

Font file name.

Definition at line 263 of file font.h.

Referenced by KIFONT::STROKE_FONT::loadNewStrokeFont().

◆ m_fontName

wxString KIFONT::FONT::m_fontName
protected

Font name.

Definition at line 262 of file font.h.

Referenced by GetName(), and KIFONT::STROKE_FONT::loadNewStrokeFont().

◆ s_defaultFont

FONT * FONT::s_defaultFont = nullptr
staticprivate

Definition at line 266 of file font.h.

Referenced by getDefaultFont().

◆ s_fontMap

std::map< std::tuple< wxString, bool, bool >, FONT * > FONT::s_fontMap
staticprivate

Definition at line 268 of file font.h.

Referenced by GetFont().


The documentation for this class was generated from the following files: