KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIFONT::STROKE_FONT Class Reference

Implement a stroke font drawing. More...

#include <stroke_font.h>

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

Public Member Functions

 STROKE_FONT ()
 
bool IsStroke () const override
 
double GetInterline (double aGlyphHeight, const METRICS &aFontMetrics) const override
 Compute the distance (interline) between 2 lines of text (for multiline texts).
 
VECTOR2I GetTextAsGlyphs (BOX2I *aBoundingBox, 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 override
 Convert text string to an array of GLYPHs.
 
unsigned GetGlyphCount () const
 
const STROKE_GLYPHGetGlyph (unsigned aIndex) const
 
const BOX2DGetGlyphBoundingBox (unsigned aIndex) 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 &aAttributes, const METRICS &aFontMetrics) const
 Draw a string.
 
void Draw (KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
 
VECTOR2I StringBoundaryLimits (const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
 Compute the boundary limits of aText (the bounding box of all shapes).
 
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.
 

Static Public Member Functions

static STROKE_FONTLoadFont (const wxString &aFontName)
 Load a stroke font.
 
static bool IsStroke (const wxString &aFontName)
 
static FONTGetFont (const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
 

Protected Member Functions

unsigned linesCount (const wxString &aText) const
 Return number of lines for a given text.
 
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 METRICS &aFontMetrics) const
 Draw a single line of text.
 
VECTOR2I boundingBoxSingleLine (BOX2I *aBBox, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aSize, bool aItalic, const METRICS &aFontMetrics) const
 Compute the bounding box for a single line of text.
 
void getLinePositions (const wxString &aText, const VECTOR2I &aPosition, wxArrayString &aTextLines, std::vector< VECTOR2I > &aPositions, std::vector< VECTOR2I > &aExtents, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) 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 METRICS &aFontMetrics) const
 
void wordbreakMarkup (std::vector< std::pair< wxString, int > > *aWords, const wxString &aText, const VECTOR2I &aSize, TEXT_STYLE_FLAGS aTextStyle) const
 

Protected Attributes

wxString m_fontName
 Font name.
 
wxString m_fontFileName
 Font file name.
 

Private Member Functions

void loadNewStrokeFont (const char *const aNewStrokeFont[], int aNewStrokeFontSize)
 Load the standard KiCad stroke font.
 

Static Private Member Functions

static FONTgetDefaultFont ()
 

Private Attributes

const std::vector< std::shared_ptr< GLYPH > > * m_glyphs
 
const std::vector< BOX2D > * m_glyphBoundingBoxes
 
double m_maxGlyphWidth
 

Static Private Attributes

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

Detailed Description

Implement a stroke font drawing.

A stroke font is composed of lines.

Definition at line 53 of file stroke_font.h.

Constructor & Destructor Documentation

◆ STROKE_FONT()

STROKE_FONT::STROKE_FONT ( )

Definition at line 57 of file stroke_font.cpp.

References m_glyphBoundingBoxes, m_glyphs, and m_maxGlyphWidth.

Referenced by LoadFont().

Member Function Documentation

◆ boundingBoxSingleLine()

VECTOR2I FONT::boundingBoxSingleLine ( BOX2I * aBBox,
const wxString & aText,
const VECTOR2I & aPosition,
const VECTOR2I & aSize,
bool aItalic,
const METRICS & aFontMetrics ) const
protectedinherited

Compute 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 457 of file font.cpp.

References ANGLE_0, drawMarkup(), and ITALIC.

Referenced by getLinePositions().

◆ Draw() [1/2]

void KIFONT::FONT::Draw ( KIGFX::GAL * aGal,
const wxString & aText,
const VECTOR2I & aPosition,
const TEXT_ATTRIBUTES & aAttributes,
const METRICS & aFontMetrics ) const
inlineinherited

Definition at line 166 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 & aAttributes,
const METRICS & aFontMetrics ) const
inherited

◆ 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 METRICS & aFontMetrics ) const
protectedinherited

◆ 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 METRICS & aFontMetrics ) const
protectedinherited

Draw 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 402 of file font.cpp.

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

Referenced by Draw().

◆ getDefaultFont()

FONT * FONT::getDefaultFont ( )
staticprivateinherited

Definition at line 136 of file font.cpp.

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

Referenced by GetFont().

◆ GetFont()

FONT * FONT::GetFont ( const wxString & aFontName = wxEmptyString,
bool aBold = false,
bool aItalic = false,
const std::vector< wxString > * aEmbeddedFiles = nullptr,
bool aForDrawingSheet = false )
staticinherited

Definition at line 147 of file font.cpp.

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

Referenced by LABEL_MANAGER::Add(), BOARD_ADAPTER::addText(), SCH_EASYEDAPRO_PARSER::ApplyFontStyle(), KIGFX::GAL::BitmapText(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), KIGFX::boxText(), ALTIUM_PCB::ConvertTexts6ToEdaTextSettings(), EDA_TEXT::Deserialize(), PCB_TEXTBOX::Deserialize(), KIGFX::DS_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), KIGFX::SCH_PAINTER::draw(), KIGFX::SCH_PAINTER::draw(), KIGFX::SCH_PAINTER::draw(), KIGFX::PREVIEW::ANGLE_ITEM::drawPreviewShape(), KIGFX::PREVIEW::DrawTextNextToCursor(), drawTicksAlongLine(), EDA_TEXT::GetDrawFont(), SCH_FIELD::GetDrawFont(), SCH_TEXT::GetDrawFont(), SCH_TEXTBOX::GetDrawFont(), KIGFX::SCH_PAINTER::getFont(), FONT_CHOICE::GetFontSelection(), PIN_LAYOUT_CACHE::GetPinNumberInfo(), GRPrintText(), GRTextWidth(), KIGFX::knockoutText(), PCB_IO_EASYEDAPRO_PARSER::ParseBoard(), SCH_EASYEDA_PARSER::ParseSchematic(), SCH_EASYEDA_PARSER::ParseSymbolShapes(), DRAWING_SHEET_PARSER::parseText(), PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(), SCH_PIN::PlotPinTexts(), PLOTTER::PlotText(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), PIN_LAYOUT_CACHE::recomputeCaches(), EDA_TEXT::ResolveFont(), EDA_TEXT::SetBold(), EDA_TEXT::SetFontProp(), EDA_TEXT::SetItalic(), FIELDS_GRID_TABLE::SetValue(), KIGFX::PCB_PAINTER::strokeText(), KIGFX::strokeText(), PDF_PLOTTER::Text(), PLOTTER::Text(), KIGFX::ANCHOR_DEBUG::ViewDraw(), KIGFX::PREVIEW::RULER_ITEM::ViewDraw(), ROUTER_STATUS_VIEW_ITEM::ViewDraw(), and TUNING_STATUS_VIEW_ITEM::ViewDraw().

◆ GetGlyph()

const STROKE_GLYPH * STROKE_FONT::GetGlyph ( unsigned aIndex) const

Definition at line 300 of file stroke_font.cpp.

References m_glyphs.

◆ GetGlyphBoundingBox()

const BOX2D & STROKE_FONT::GetGlyphBoundingBox ( unsigned aIndex) const

Definition at line 309 of file stroke_font.cpp.

References empty(), and m_glyphBoundingBoxes.

◆ GetGlyphCount()

unsigned STROKE_FONT::GetGlyphCount ( ) const

Definition at line 294 of file stroke_font.cpp.

References m_glyphs.

◆ GetInterline()

double STROKE_FONT::GetInterline ( double aGlyphHeight,
const METRICS & aFontMetrics ) const
overridevirtual

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.

Implements KIFONT::FONT.

Definition at line 194 of file stroke_font.cpp.

References KIFONT::METRICS::GetInterline().

◆ getLinePositions()

◆ GetName()

◆ GetTextAsGlyphs()

VECTOR2I STROKE_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
overridevirtual

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

Implements KIFONT::FONT.

Definition at line 202 of file stroke_font.cpp.

References KIFONT::STROKE_GLYPH::BoundingBox(), cursor, BOX2< Vec >::GetEnd(), ITALIC, ITALIC_TILT, KiROUND(), m_glyphBoundingBoxes, m_glyphs, BOX2< Vec >::Normalize(), BOX2< Vec >::SetEnd(), BOX2< Vec >::SetOrigin(), SUBSCRIPT, SUPERSCRIPT, KIFONT::STROKE_GLYPH::Transform(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE().

◆ IsBold()

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

Reimplemented in KIFONT::OUTLINE_FONT.

Definition at line 140 of file font.h.

Referenced by operator<<(), and PDF_PLOTTER::renderWord().

◆ IsItalic()

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

Reimplemented in KIFONT::OUTLINE_FONT.

Definition at line 141 of file font.h.

Referenced by operator<<(), and PDF_PLOTTER::renderWord().

◆ IsOutline()

◆ IsStroke() [1/2]

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

Definition at line 173 of file font.cpp.

References _, and KICAD_FONT_NAME.

◆ IsStroke() [2/2]

bool KIFONT::STROKE_FONT::IsStroke ( ) const
inlineoverridevirtual

Reimplemented from KIFONT::FONT.

Definition at line 58 of file stroke_font.h.

◆ LinebreakText()

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

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

This is a highly simplified line-breaker. KiCad is an EDA tool, not a word processor.

  1. It breaks only on spaces. If you type a word wider than the column width then you get overflow.
  2. It treats runs of formatted text (superscript, subscript, overbar) as single words.
  3. It does not perform justification.

The results of the linebreaking are the addition of
in the text. It is presumed that this function is called on m_shownText (or equivalent) rather than the original source text.

Definition at line 572 of file font.cpp.

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

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

◆ linesCount()

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

Return 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 229 of file font.h.

◆ LoadFont()

STROKE_FONT * STROKE_FONT::LoadFont ( const wxString & aFontName)
static

Load a stroke font.

Parameters
aFontNameis the name of the font. If empty, the standard KiCad stroke font is loaded.

Definition at line 65 of file stroke_font.cpp.

References loadNewStrokeFont(), newstroke_font, newstroke_font_bufsize, and STROKE_FONT().

Referenced by BOOST_AUTO_TEST_CASE(), KIFONT::FONT::getDefaultFont(), LoadStrokeFontUnique(), and PDF_STROKE_FONT_MANAGER::Reset().

◆ loadNewStrokeFont()

void STROKE_FONT::loadNewStrokeFont ( const char *const aNewStrokeFont[],
int aNewStrokeFontSize )
private

Load the standard KiCad stroke font.

Parameters
aNewStrokeFontis the pointer to the font data.
aNewStrokeFontSizeis the size of the font data.

Definition at line 99 of file stroke_font.cpp.

References buildGlyphBoundingBox(), FONT_OFFSET, g_defaultFontGlyphBoundingBoxes, g_defaultFontGlyphs, g_defaultFontInitialized, g_defaultFontLoadMutex, KICAD_FONT_NAME, KIFONT::FONT::m_fontFileName, KIFONT::FONT::m_fontName, m_glyphBoundingBoxes, m_glyphs, m_maxGlyphWidth, STROKE_FONT_SCALE, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadFont().

◆ NameAsToken()

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

Definition at line 150 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 METRICS & aFontMetrics ) const
inherited

◆ wordbreakMarkup()

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

Definition at line 562 of file font.cpp.

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

Referenced by LinebreakText(), and wordbreakMarkup().

Member Data Documentation

◆ m_fontFileName

wxString KIFONT::FONT::m_fontFileName
protectedinherited

Font file name.

Definition at line 291 of file font.h.

Referenced by KIFONT::OUTLINE_FONT::GetFileName(), and KIFONT::STROKE_FONT::loadNewStrokeFont().

◆ m_fontName

wxString KIFONT::FONT::m_fontName
protectedinherited

Font name.

Definition at line 290 of file font.h.

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

◆ m_glyphBoundingBoxes

const std::vector<BOX2D>* KIFONT::STROKE_FONT::m_glyphBoundingBoxes
private

Definition at line 97 of file stroke_font.h.

Referenced by GetGlyphBoundingBox(), GetTextAsGlyphs(), loadNewStrokeFont(), and STROKE_FONT().

◆ m_glyphs

const std::vector<std::shared_ptr<GLYPH> >* KIFONT::STROKE_FONT::m_glyphs
private

◆ m_maxGlyphWidth

double KIFONT::STROKE_FONT::m_maxGlyphWidth
private

Definition at line 98 of file stroke_font.h.

Referenced by loadNewStrokeFont(), and STROKE_FONT().

◆ s_defaultFont

FONT * FONT::s_defaultFont = nullptr
staticprivateinherited

Definition at line 294 of file font.h.

Referenced by getDefaultFont().

◆ s_fontMap

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

Definition at line 296 of file font.h.

Referenced by GetFont().


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