KiCad PCB EDA Suite
KIFONT::OUTLINE_FONT Class Reference

Class OUTLINE_FONT implements outline font drawing. More...

#include <outline_font.h>

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

Public Member Functions

 OUTLINE_FONT ()
 
bool IsOutline () const override
 
bool IsBold () const override
 
bool IsItalic () const override
 
void SetFakeBold ()
 
void SetFakeItal ()
 
double ComputeOverbarVerticalPosition (double aGlyphHeight) const override
 Compute the vertical position of an overbar. More...
 
double ComputeUnderlineVerticalPosition (double aGlyphHeight) const override
 Compute the vertical position of an underline. More...
 
double GetInterline (double aGlyphHeight=0.0, double aLineSpacing=1.0) const override
 Compute the distance (interline) between 2 lines of text (for multiline texts). More...
 
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. More...
 
void GetLinesAsGlyphs (std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs) const
 
const FT_Face & GetFace () const
 
virtual bool IsStroke () 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...
 

Static Public Member Functions

static wxString FontConfigVersion ()
 
static wxString FreeTypeVersion ()
 
static wxString HarfBuzzVersion ()
 
static wxString FontLibraryVersion ()
 
static OUTLINE_FONTLoadFont (const wxString &aFontFileName, bool aBold, bool aItalic)
 Load an outline font. More...
 
static bool IsStroke (const wxString &aFontName)
 
static FONTGetFont (const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
 

Protected Member Functions

FT_Error loadFace (const wxString &aFontFileName)
 
double getOverbarOffset (int ascender, int height, int thickness) const
 
BOX2I getBoundingBox (const std::vector< std::unique_ptr< GLYPH > > &aGlyphs) const
 
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
 
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.62
 

Private Member Functions

int faceSize (int aSize) const
 
int faceSize () const
 
int subscriptSize (int aSize) const
 
int subscriptSize () const
 

Static Private Member Functions

static FONTgetDefaultFont ()
 

Private Attributes

FT_Face m_face
 
const int m_faceSize
 
bool m_fakeBold
 
bool m_fakeItal
 
std::map< unsigned int, GLYPH_POINTS_LISTm_contourCache
 

Static Private Attributes

static FT_Library m_freeType = nullptr
 
static constexpr double m_outlineFontSizeCompensation = 1.4
 
static constexpr int m_charSizeScaler = 64
 
static constexpr double m_subscriptSuperscriptSize = 0.64
 
static constexpr double m_underlineOffsetScaler = -0.16
 
static constexpr double m_subscriptVerticalOffset = -0.25
 
static constexpr double m_superscriptVerticalOffset = 0.45
 
static FONTs_defaultFont = nullptr
 
static std::map< std::tuple< wxString, bool, bool >, FONT * > s_fontMap
 

Detailed Description

Class OUTLINE_FONT implements outline font drawing.

Definition at line 49 of file outline_font.h.

Constructor & Destructor Documentation

◆ OUTLINE_FONT()

OUTLINE_FONT::OUTLINE_FONT ( )

Definition at line 48 of file outline_font.cpp.

48 :
49 m_face(NULL),
50 m_faceSize( 16 ),
51 m_fakeBold( false ),
52 m_fakeItal( false )
53{
54 if( !m_freeType )
55 FT_Init_FreeType( &m_freeType );
56}
static FT_Library m_freeType
Definition: outline_font.h:138

References m_freeType.

Referenced by LoadFont().

Member Function Documentation

◆ boundingBoxSingleLine()

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

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

304{
305 TEXT_STYLE_FLAGS textStyle = 0;
306
307 if( aItalic )
308 textStyle |= TEXT_STYLE::ITALIC;
309
310 VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, ANGLE_0, false,
311 VECTOR2I(), textStyle );
312
313 return extents;
314}
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
Definition: font.cpp:233
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:423
@ ITALIC
Definition: font.h:46
unsigned int TEXT_STYLE_FLAGS
Definition: font.h:63
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References ANGLE_0, KIFONT::FONT::drawMarkup(), and ITALIC.

Referenced by KIFONT::FONT::getLinePositions().

◆ ComputeOverbarVerticalPosition()

double OUTLINE_FONT::ComputeOverbarVerticalPosition ( double  aGlyphHeight) const
overridevirtual

Compute the vertical position of an overbar.

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

Implements KIFONT::FONT.

Definition at line 142 of file outline_font.cpp.

143{
144 // The overbar on actual text is positioned above the bounding box of the glyphs. However,
145 // that's expensive to calculate so we use an estimation here (as this is only used for
146 // calculating bounding boxes).
147 return aGlyphHeight * m_outlineFontSizeCompensation;
148}
static constexpr double m_outlineFontSizeCompensation
Definition: outline_font.h:153

References m_outlineFontSizeCompensation.

◆ ComputeUnderlineVerticalPosition()

double OUTLINE_FONT::ComputeUnderlineVerticalPosition ( double  aGlyphHeight) const
overridevirtual

Compute the vertical position of an underline.

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

Implements KIFONT::FONT.

Definition at line 155 of file outline_font.cpp.

156{
157 return aGlyphHeight * m_underlineOffsetScaler;
158}
static constexpr double m_underlineOffsetScaler
Definition: outline_font.h:165

References m_underlineOffsetScaler.

◆ Draw() [1/2]

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

Definition at line 137 of file font.h.

139 {
140 Draw( aGal, aText, aPosition, VECTOR2I( 0, 0 ), aAttributes );
141 }
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttrs) const
Draw a string.
Definition: font.cpp:159

References KIFONT::FONT::Draw().

◆ Draw() [2/2]

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

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

161{
162 if( !aGal || aText.empty() )
163 return;
164
165 VECTOR2I position( aPosition - aCursor );
166
167 // Split multiline strings into separate ones and draw them line by line
168 wxArrayString strings_list;
169 std::vector<VECTOR2I> positions;
170 std::vector<VECTOR2I> extents;
171
172 getLinePositions( aText, position, strings_list, positions, extents, aAttrs );
173
174 aGal->SetLineWidth( aAttrs.m_StrokeWidth );
175
176 for( size_t i = 0; i < strings_list.GetCount(); i++ )
177 {
178 drawSingleLineText( aGal, nullptr, strings_list[i], positions[i], aAttrs.m_Size,
179 aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, aAttrs.m_Italic,
180 aAttrs.m_Underlined );
181 }
182}
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.
Definition: font.cpp:246
void getLinePositions(const wxString &aText, const VECTOR2I &aPosition, wxArrayString &aTextLines, std::vector< VECTOR2I > &aPositions, std::vector< VECTOR2I > &aExtents, const TEXT_ATTRIBUTES &aAttrs) const
Definition: font.cpp:94
virtual void SetLineWidth(float aLineWidth)
Set the line width.

References KIFONT::FONT::drawSingleLineText(), KIFONT::FONT::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(), KIFONT::FONT::Draw(), KIGFX::PREVIEW::DrawTextNextToCursor(), drawTicksAlongLine(), EDA_TEXT::GetEffectiveTextShape(), GRPrintText(), BRDITEMS_PLOTTER::PlotPcbText(), KIGFX::SCH_PAINTER::strokeText(), KIGFX::PCB_PAINTER::strokeText(), PLOTTER::Text(), FP_TEXT::TransformTextToPolySet(), FP_TEXTBOX::TransformTextToPolySet(), 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
protectedinherited

Definition at line 233 of file font.cpp.

237{
238 MARKUP::MARKUP_PARSER markupParser( TO_UTF8( aText ) );
239 std::unique_ptr<MARKUP::NODE> root = markupParser.Parse();
240
241 return ::drawMarkup( aBoundingBox, aGlyphs, root, aPosition, this, aSize, aAngle, aMirror,
242 aOrigin, aTextStyle );
243}
VECTOR2I drawMarkup(BOX2I *aBoundingBox, std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const std::unique_ptr< MARKUP::NODE > &aNode, const VECTOR2I &aPosition, const KIFONT::FONT *aFont, const VECTOR2I &aSize, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin, TEXT_STYLE_FLAGS aTextStyle)
Definition: font.cpp:188
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96

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

Referenced by KIFONT::FONT::boundingBoxSingleLine(), KIFONT::FONT::drawSingleLineText(), GetLinesAsGlyphs(), and KIFONT::FONT::StringBoundaryLimits().

◆ 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
protectedinherited

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

250{
251 if( !aGal )
252 return;
253
254 TEXT_STYLE_FLAGS textStyle = 0;
255
256 if( aItalic )
257 textStyle |= TEXT_STYLE::ITALIC;
258
259 if( aUnderline )
260 textStyle |= TEXT_STYLE::UNDERLINE;
261
262 std::vector<std::unique_ptr<GLYPH>> glyphs;
263
264 (void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin,
265 textStyle );
266
267 aGal->DrawGlyphs( glyphs );
268}
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
@ UNDERLINE
Definition: font.h:50

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

Referenced by KIFONT::FONT::Draw().

◆ faceSize() [1/2]

int KIFONT::OUTLINE_FONT::faceSize ( ) const
inlineprivate

Definition at line 171 of file outline_font.h.

171{ return faceSize( m_faceSize ); }
int faceSize() const
Definition: outline_font.h:171

References faceSize(), and m_faceSize.

Referenced by faceSize(), getTextAsGlyphs(), loadFace(), and subscriptSize().

◆ faceSize() [2/2]

int KIFONT::OUTLINE_FONT::faceSize ( int  aSize) const
inlineprivate

Definition at line 167 of file outline_font.h.

168 {
170 };
static constexpr int m_charSizeScaler
Definition: outline_font.h:156

References m_charSizeScaler, and m_outlineFontSizeCompensation.

◆ FontConfigVersion()

wxString OUTLINE_FONT::FontConfigVersion ( )
static

Definition at line 79 of file outline_font.cpp.

80{
82}
static wxString Version()
Definition: fontconfig.cpp:40

References fontconfig::FONTCONFIG::Version().

Referenced by GetVersionInfoData().

◆ FontLibraryVersion()

wxString OUTLINE_FONT::FontLibraryVersion ( )
static

Definition at line 85 of file outline_font.cpp.

86{
87 return wxString::Format( "FreeType %s HarfBuzz %s", FreeTypeVersion(), HarfBuzzVersion() );
88}
static wxString FreeTypeVersion()
static wxString HarfBuzzVersion()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), FreeTypeVersion(), and HarfBuzzVersion().

◆ FreeTypeVersion()

wxString OUTLINE_FONT::FreeTypeVersion ( )
static

Definition at line 59 of file outline_font.cpp.

60{
61 if( !m_freeType )
62 FT_Init_FreeType( &m_freeType );
63
64 FT_Int major = 0;
65 FT_Int minor = 0;
66 FT_Int patch = 0;
67 FT_Library_Version( m_freeType, &major, &minor, &patch );
68
69 return wxString::Format( "%d.%d.%d", major, minor, patch );
70}

References Format(), and m_freeType.

Referenced by FontLibraryVersion(), and GetVersionInfoData().

◆ getBoundingBox()

BOX2I OUTLINE_FONT::getBoundingBox ( const std::vector< std::unique_ptr< GLYPH > > &  aGlyphs) const
protected

Definition at line 199 of file outline_font.cpp.

200{
201 int minX = INT_MAX;
202 int minY = INT_MAX;
203 int maxX = INT_MIN;
204 int maxY = INT_MIN;
205
206 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
207 {
208 BOX2D bbox = glyph->BoundingBox();
209 bbox.Normalize();
210
211 if( minX > bbox.GetX() )
212 minX = bbox.GetX();
213
214 if( minY > bbox.GetY() )
215 minY = bbox.GetY();
216
217 if( maxX < bbox.GetRight() )
218 maxX = bbox.GetRight();
219
220 if( maxY < bbox.GetBottom() )
221 maxY = bbox.GetBottom();
222 }
223
224 BOX2I ret;
225 ret.SetOrigin( minX, minY );
226 ret.SetEnd( maxX, maxY );
227 return ret;
228}
void SetOrigin(const Vec &pos)
Definition: box2.h:202
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:119
coord_type GetY() const
Definition: box2.h:181
coord_type GetX() const
Definition: box2.h:180
coord_type GetRight() const
Definition: box2.h:189
coord_type GetBottom() const
Definition: box2.h:190
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:255

References BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), BOX2< Vec >::Normalize(), BOX2< Vec >::SetEnd(), and BOX2< Vec >::SetOrigin().

◆ getDefaultFont()

FONT * FONT::getDefaultFont ( )
staticprivateinherited

Definition at line 56 of file font.cpp.

57{
58 if( !s_defaultFont )
59 s_defaultFont = STROKE_FONT::LoadFont( wxEmptyString );
60
61 return s_defaultFont;
62}
static FONT * s_defaultFont
Definition: font.h:266
static STROKE_FONT * LoadFont(const wxString &aFontName)
Load a stroke font.
Definition: stroke_font.cpp:72

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

Referenced by KIFONT::FONT::GetFont().

◆ GetFace()

const FT_Face & KIFONT::OUTLINE_FONT::GetFace ( ) const
inline

Definition at line 116 of file outline_font.h.

116{ return m_face; }

References m_face.

Referenced by GetInterline().

◆ GetFont()

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

Definition at line 65 of file font.cpp.

66{
67 if( aFontName.empty() || aFontName.StartsWith( KICAD_FONT_NAME ) )
68 return getDefaultFont();
69
70 std::tuple<wxString, bool, bool> key = { aFontName, aBold, aItalic };
71
72 FONT* font = s_fontMap[key];
73
74 if( !font )
75 font = OUTLINE_FONT::LoadFont( aFontName, aBold, aItalic );
76
77 if( !font )
78 font = getDefaultFont();
79
80 s_fontMap[key] = font;
81
82 return font;
83}
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
static std::map< std::tuple< wxString, bool, bool >, FONT * > s_fontMap
Definition: font.h:268
static FONT * getDefaultFont()
Definition: font.cpp:56
static OUTLINE_FONT * LoadFont(const wxString &aFontFileName, bool aBold, bool aItalic)
Load an outline font.
#define KICAD_FONT_NAME

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

Referenced by LABEL_MANAGER::Add(), BOARD_ADAPTER::addText(), KIGFX::GAL::BitmapText(), 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(), 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::PlotFootprintTextItem(), BRDITEMS_PLOTTER::PlotPcbText(), LIB_PIN::PlotPinTexts(), 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()

double OUTLINE_FONT::GetInterline ( double  aGlyphHeight = 0.0,
double  aLineSpacing = 1.0 
) 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 165 of file outline_font.cpp.

166{
167 double pitch = INTERLINE_PITCH_RATIO;
168
169 if( GetFace()->units_per_EM )
170 pitch = GetFace()->height / GetFace()->units_per_EM;
171
172 double interline = aLineSpacing * aGlyphHeight * pitch * m_outlineFontSizeCompensation;
173
174 // FONT TODO this hack is an attempt to fix interline spacing by eyeballing it
175 static constexpr double interlineHackMultiplier = 1.2;
176 interline *= interlineHackMultiplier;
177
178 return interline;
179}
static constexpr double INTERLINE_PITCH_RATIO
Definition: font.h:256
const FT_Face & GetFace() const
Definition: outline_font.h:116

References GetFace(), KIFONT::FONT::INTERLINE_PITCH_RATIO, and m_outlineFontSizeCompensation.

◆ getLinePositions()

void FONT::getLinePositions ( const wxString &  aText,
const VECTOR2I aPosition,
wxArrayString &  aTextLines,
std::vector< VECTOR2I > &  aPositions,
std::vector< VECTOR2I > &  aExtents,
const TEXT_ATTRIBUTES aAttrs 
) const
protectedinherited

Definition at line 94 of file font.cpp.

97{
98 wxStringSplit( aText, aTextLines, '\n' );
99 int lineCount = aTextLines.Count();
100 aPositions.reserve( lineCount );
101
102 int interline = GetInterline( aAttrs.m_Size.y, aAttrs.m_LineSpacing );
103 int height = 0;
104
105 for( int i = 0; i < lineCount; i++ )
106 {
107 VECTOR2I pos( aPosition.x, aPosition.y + i * interline );
108 VECTOR2I end = boundingBoxSingleLine( nullptr, aTextLines[i], pos, aAttrs.m_Size,
109 aAttrs.m_Italic );
110 VECTOR2I bBox( end - pos );
111
112 aExtents.push_back( bBox );
113
114 if( i == 0 )
115 height += ( aAttrs.m_Size.y * 1.17 ); // 1.17 is a fudge to match 6.0 positioning
116 else
117 height += interline;
118 }
119
120 VECTOR2I offset( 0, 0 );
121 offset.y += aAttrs.m_Size.y;
122
123 switch( aAttrs.m_Valign )
124 {
125 case GR_TEXT_V_ALIGN_TOP: break;
126 case GR_TEXT_V_ALIGN_CENTER: offset.y -= height / 2; break;
127 case GR_TEXT_V_ALIGN_BOTTOM: offset.y -= height; break;
128 }
129
130 for( int i = 0; i < lineCount; i++ )
131 {
132 VECTOR2I lineSize = aExtents.at( i );
133 VECTOR2I lineOffset( offset );
134
135 lineOffset.y += i * interline;
136
137 switch( aAttrs.m_Halign )
138 {
139 case GR_TEXT_H_ALIGN_LEFT: break;
140 case GR_TEXT_H_ALIGN_CENTER: lineOffset.x = -lineSize.x / 2; break;
141 case GR_TEXT_H_ALIGN_RIGHT: lineOffset.x = -lineSize.x; break;
142 }
143
144 aPositions.push_back( aPosition + lineOffset );
145 }
146}
virtual double GetInterline(double aGlyphHeight, double aLineSpacing=1.0) const =0
Compute the distance (interline) between 2 lines of text (for multiline texts).
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.
Definition: font.cpp:301
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP

References KIFONT::FONT::boundingBoxSingleLine(), KIFONT::FONT::GetInterline(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_BOTTOM, GR_TEXT_V_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, TEXT_ATTRIBUTES::m_Halign, TEXT_ATTRIBUTES::m_Italic, TEXT_ATTRIBUTES::m_LineSpacing, TEXT_ATTRIBUTES::m_Size, TEXT_ATTRIBUTES::m_Valign, wxStringSplit(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIFONT::FONT::Draw(), and GetLinesAsGlyphs().

◆ GetLinesAsGlyphs()

void OUTLINE_FONT::GetLinesAsGlyphs ( std::vector< std::unique_ptr< GLYPH > > *  aGlyphs,
const wxString &  aText,
const VECTOR2I aPosition,
const TEXT_ATTRIBUTES aAttrs 
) const

Definition at line 231 of file outline_font.cpp.

234{
235 wxArrayString strings;
236 std::vector<VECTOR2I> positions;
237 std::vector<VECTOR2I> extents;
238 TEXT_STYLE_FLAGS textStyle = 0;
239
240 if( aAttrs.m_Italic )
241 textStyle |= TEXT_STYLE::ITALIC;
242
243 getLinePositions( aText, aPosition, strings, positions, extents, aAttrs );
244
245 for( size_t i = 0; i < strings.GetCount(); i++ )
246 {
247 (void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size,
248 aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle );
249 }
250}

References KIFONT::FONT::drawMarkup(), KIFONT::FONT::getLinePositions(), ITALIC, TEXT_ATTRIBUTES::m_Angle, TEXT_ATTRIBUTES::m_Italic, TEXT_ATTRIBUTES::m_Mirrored, and TEXT_ATTRIBUTES::m_Size.

Referenced by EDA_TEXT::GetRenderCache(), and SCH_FIELD::GetRenderCache().

◆ GetName()

const wxString & KIFONT::FONT::GetName ( void  ) const
inlineinherited

◆ getOverbarOffset()

double OUTLINE_FONT::getOverbarOffset ( int  ascender,
int  height,
int  thickness 
) const
protected

Definition at line 305 of file outline_font.cpp.

306{
307 double thicknessRatio = abs( (double) thickness ) / (double) height;
308 double ascenderRatio = (double) ascender / (double) height;
309
310 if( thicknessRatio < 0.05 )
311 return 0.04;
312 else if( ascenderRatio < 0.78 )
313 return 0.00;
314 else if( ascenderRatio < 0.80 )
315 return -0.03;
316 else
317 return -0.06;
318}
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:412

References std::abs().

Referenced by getTextAsGlyphs().

◆ getTextAsGlyphs()

VECTOR2I OUTLINE_FONT::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
protected

Definition at line 321 of file outline_font.cpp.

326{
327 VECTOR2D glyphSize = aSize;
328 FT_Face face = m_face;
329 double scaler = faceSize();
330
331 if( IsSubscript( aTextStyle ) || IsSuperscript( aTextStyle ) )
332 {
333 scaler = subscriptSize();
334 }
335
336 // set glyph resolution so that FT_Load_Glyph() results are good enough for decomposing
337 FT_Set_Char_Size( face, 0, scaler, GLYPH_RESOLUTION, 0 );
338
339 hb_buffer_t* buf = hb_buffer_create();
340 hb_buffer_add_utf8( buf, UTF8( aText ).c_str(), -1, 0, -1 );
341 hb_buffer_guess_segment_properties( buf ); // guess direction, script, and language based on
342 // contents
343
344 unsigned int glyphCount;
345 hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
346 hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
347
348 hb_font_t* referencedFont = hb_ft_font_create_referenced( face );
349 hb_ft_font_set_funcs( referencedFont );
350 hb_shape( referencedFont, buf, nullptr, 0 );
351
352 VECTOR2D scaleFactor( glyphSize.x / faceSize(), -glyphSize.y / faceSize() );
353 scaleFactor = scaleFactor * m_outlineFontSizeCompensation;
354
355 VECTOR2I cursor( 0, 0 );
356
357 for( unsigned int i = 0; i < glyphCount; i++ )
358 {
359 // Don't process glyphs that were already included in a previous cluster
360 if( i > 0 && glyphInfo[i].cluster == glyphInfo[i-1].cluster )
361 continue;
362
363 if( aGlyphs )
364 {
365 if( m_fakeItal )
366 {
367 FT_Matrix matrix;
368 // Create a 12 degree slant
369 const float angle = ( -M_PI * 12 ) / 180.0f;
370 matrix.xx = (FT_Fixed) ( cos( angle ) * 0x10000L );
371 matrix.xy = (FT_Fixed) ( -sin( angle ) * 0x10000L );
372 matrix.yx = (FT_Fixed) ( 0 * 0x10000L ); // Don't rotate in the y direction
373 matrix.yy = (FT_Fixed) ( 1 * 0x10000L );
374
375 FT_Set_Transform(face, &matrix,0);
376 }
377
378 FT_Load_Glyph( face, glyphInfo[i].codepoint, FT_LOAD_NO_BITMAP );
379
380 if( m_fakeBold )
381 FT_Outline_Embolden( &face->glyph->outline, 1 << 6 );
382
383 // contours is a collection of all outlines in the glyph; for example the 'o' glyph
384 // generally contains 2 contours, one for the glyph outline and one for the hole
385 CONTOURS contours;
386
387 OUTLINE_DECOMPOSER decomposer( face->glyph->outline );
388 decomposer.OutlineToSegments( &contours );
389
390 std::unique_ptr<OUTLINE_GLYPH> glyph = std::make_unique<OUTLINE_GLYPH>();
391 std::vector<SHAPE_LINE_CHAIN> holes;
392
393 for( CONTOUR& c : contours )
394 {
395 GLYPH_POINTS points = c.m_Points;
396 SHAPE_LINE_CHAIN shape;
397
398 for( const VECTOR2D& v : points )
399 {
400 VECTOR2D pt( v + cursor );
401
402 if( IsSubscript( aTextStyle ) )
403 pt.y += m_subscriptVerticalOffset * scaler;
404 else if( IsSuperscript( aTextStyle ) )
405 pt.y += m_superscriptVerticalOffset * scaler;
406
407 pt *= scaleFactor;
408 pt += aPosition;
409
410 if( aMirror )
411 pt.x = aOrigin.x - ( pt.x - aOrigin.x );
412
413 if( !aAngle.IsZero() )
414 RotatePoint( pt, aOrigin, aAngle );
415
416 shape.Append( pt.x, pt.y );
417 }
418
419 shape.SetClosed( true );
420
421 if( contourIsHole( c ) )
422 holes.push_back( std::move( shape ) );
423 else
424 glyph->AddOutline( std::move( shape ) );
425 }
426
427 for( SHAPE_LINE_CHAIN& hole : holes )
428 {
429 if( hole.PointCount() )
430 {
431 for( int ii = 0; ii < glyph->OutlineCount(); ++ii )
432 {
433 if( glyph->Outline( ii ).PointInside( hole.GetPoint( 0 ) ) )
434 {
435 glyph->AddHole( std::move( hole ), ii );
436 break;
437 }
438 }
439 }
440 }
441
442 // FONT TODO we might not want to do Fracture() here;
443 // knockout text (eg. silkscreen labels with a background) will
444 // need to do that after the contours have been turned into holes
445 // and vice versa
446 if( glyph->HasHoles() )
447 glyph->Fracture( SHAPE_POLY_SET::PM_FAST ); // FONT TODO verify aFastMode
448
449 aGlyphs->push_back( std::move( glyph ) );
450 }
451
452 hb_glyph_position_t& pos = glyphPos[i];
453 cursor.x += ( pos.x_advance * GLYPH_SIZE_SCALER );
454 cursor.y += ( pos.y_advance * GLYPH_SIZE_SCALER );
455 }
456
457 int ascender = abs( face->size->metrics.ascender * GLYPH_SIZE_SCALER );
458 int height = abs( face->size->metrics.height * GLYPH_SIZE_SCALER );
459 int descender = abs( face->size->metrics.descender * GLYPH_SIZE_SCALER );
460 VECTOR2I extents( cursor.x * scaleFactor.x, ( ascender + descender ) * abs( scaleFactor.y ) );
461
462 // Font metrics don't include all descenders and diacriticals, so beef them up just a little.
463 extents.y *= 1.05;
464
465 if( IsOverbar( aTextStyle ) )
466 {
467 std::vector<std::unique_ptr<GLYPH>> underscoreGlyphs;
468
469 getTextAsGlyphs( nullptr, &underscoreGlyphs, wxT( "_" ), aSize, { 0, 0 }, ANGLE_0, false,
470 { 0, 0 }, aTextStyle & ~TEXT_STYLE::OVERBAR );
471
472 OUTLINE_GLYPH* underscoreGlyph = static_cast<OUTLINE_GLYPH*>( underscoreGlyphs[0].get() );
473 BOX2I underscoreBBox;
474
475 for( const VECTOR2I& pt : underscoreGlyph->Outline( 0 ).CPoints() )
476 underscoreBBox.Merge( pt );
477
478 int barThickness = underscoreBBox.GetHeight();
479
480 // Shorten the bar a little so its rounded ends don't make it over-long
481 double barTrim = barThickness / 2.0;
482 double barOffset = getOverbarOffset( ascender, height, barThickness / scaleFactor.y );
483
484 VECTOR2I topLeft( aPosition );
485 VECTOR2I topRight( aPosition );
486
487 topLeft.y += ascender * scaleFactor.y * ( 1.0 + barOffset );
488 topRight.y = topLeft.y;
489
490 topLeft.x += barTrim;
491 topRight.x += extents.x - barTrim;
492
493 extents.y *= ( 1.0 + barOffset + barOffset );
494 extents.x += barTrim;
495
496 if( IsItalic() )
497 {
498 topLeft.x += aSize.y * ITALIC_TILT;
499 topRight.x += aSize.y * ITALIC_TILT;
500 extents.x += aSize.y * ITALIC_TILT;
501 }
502
503 if( aMirror )
504 {
505 topLeft.x = aOrigin.x - ( topLeft.x - aOrigin.x );
506 topRight.x = aOrigin.x - ( topRight.x - aOrigin.x );
507 }
508
509 if( !aAngle.IsZero() )
510 {
511 RotatePoint( topLeft, aOrigin, aAngle );
512 RotatePoint( topRight, aOrigin, aAngle );
513 }
514
515 if( aGlyphs )
516 {
517 int maxError = KiROUND( barThickness / 48 );
518 SHAPE_POLY_SET poly;
519
520 TransformOvalToPolygon( poly, topLeft, topRight, barThickness, maxError, ERROR_INSIDE );
521
522 std::unique_ptr<OUTLINE_GLYPH> overbarGlyph = std::make_unique<OUTLINE_GLYPH>( poly );
523 aGlyphs->push_back( std::move( overbarGlyph ) );
524 }
525 }
526
527 hb_buffer_destroy( buf );
528 hb_font_destroy( referencedFont );
529
530 VECTOR2I cursorDisplacement( cursor.x * scaleFactor.x, -cursor.y * scaleFactor.y );
531
532 if( aBBox )
533 aBBox->Merge( aPosition + extents );
534
535 return VECTOR2I( aPosition.x + cursorDisplacement.x, aPosition.y + cursorDisplacement.y );
536}
coord_type GetHeight() const
Definition: box2.h:188
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:588
bool IsZero() const
Definition: eda_angle.h:169
static constexpr double m_superscriptVerticalOffset
Definition: outline_font.h:181
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
bool IsItalic() const override
Definition: outline_font.h:69
double getOverbarOffset(int ascender, int height, int thickness) const
int subscriptSize() const
Definition: outline_font.h:178
static constexpr double m_subscriptVerticalOffset
Definition: outline_font.h:180
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a set of closed polygons.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:71
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
TEXT_STYLE
Definition: font.h:44
@ OVERBAR
Definition: font.h:49
bool IsOverbar(TEXT_STYLE_FLAGS aFlags)
Definition: font.h:90
bool IsSuperscript(TEXT_STYLE_FLAGS aFlags)
Definition: font.h:78
static constexpr double ITALIC_TILT
Tilt factor for italic style (this is the scaling factor on dY relative coordinates to give a tilted ...
Definition: font.h:60
bool IsSubscript(TEXT_STYLE_FLAGS aFlags)
Definition: font.h:84
@ ERROR_INSIDE
constexpr int GLYPH_RESOLUTION
Definition: glyph.h:41
std::vector< CONTOUR > CONTOURS
constexpr double GLYPH_SIZE_SCALER
Definition: glyph.h:42
std::vector< VECTOR2D > GLYPH_POINTS
Definition: glyph.h:110
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static bool contourIsHole(const CONTOUR &c)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
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

References std::abs(), PNS::angle(), ANGLE_0, SHAPE_LINE_CHAIN::Append(), contourIsHole(), cursor, ERROR_INSIDE, faceSize(), BOX2< Vec >::GetHeight(), getOverbarOffset(), getTextAsGlyphs(), KIFONT::GLYPH_RESOLUTION, KIFONT::GLYPH_SIZE_SCALER, IsItalic(), IsOverbar(), IsSubscript(), IsSuperscript(), EDA_ANGLE::IsZero(), ITALIC_TILT, KiROUND(), m_face, m_fakeBold, m_fakeItal, m_outlineFontSizeCompensation, m_subscriptVerticalOffset, m_superscriptVerticalOffset, BOX2< Vec >::Merge(), KIFONT::OUTLINE_DECOMPOSER::OutlineToSegments(), OVERBAR, SHAPE_POLY_SET::PM_FAST, RotatePoint(), SHAPE_LINE_CHAIN::SetClosed(), subscriptSize(), TransformOvalToPolygon(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by getTextAsGlyphs(), and GetTextAsGlyphs().

◆ GetTextAsGlyphs()

VECTOR2I OUTLINE_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 253 of file outline_font.cpp.

258{
259 // HarfBuzz needs further processing to split tab-delimited text into text runs.
260
261 constexpr double TAB_WIDTH = 4 * 0.6;
262
263 VECTOR2I position = aPosition;
264 wxString textRun;
265
266 if( aBBox )
267 {
268 aBBox->SetOrigin( aPosition );
269 aBBox->SetEnd( aPosition );
270 }
271
272 for( wxUniChar c : aText )
273 {
274 // Handle tabs as locked to the nearest 4th column (in space-widths).
275 if( c == '\t' )
276 {
277 if( !textRun.IsEmpty() )
278 {
279 position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle,
280 aMirror, aOrigin, aTextStyle );
281 textRun.clear();
282 }
283
284 int tabWidth = KiROUND( aSize.x * TAB_WIDTH );
285 int currentIntrusion = ( position.x - aOrigin.x ) % tabWidth;
286
287 position.x += tabWidth - currentIntrusion;
288 }
289 else
290 {
291 textRun += c;
292 }
293 }
294
295 if( !textRun.IsEmpty() )
296 {
297 position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle, aMirror,
298 aOrigin, aTextStyle );
299 }
300
301 return position;
302}

References getTextAsGlyphs(), KiROUND(), BOX2< Vec >::SetEnd(), BOX2< Vec >::SetOrigin(), and VECTOR2< T >::x.

◆ HarfBuzzVersion()

wxString OUTLINE_FONT::HarfBuzzVersion ( )
static

Definition at line 73 of file outline_font.cpp.

74{
75 return wxString::FromUTF8( HB_VERSION_STRING );
76}

Referenced by FontLibraryVersion(), and GetVersionInfoData().

◆ IsBold()

bool KIFONT::OUTLINE_FONT::IsBold ( ) const
inlineoverridevirtual

Reimplemented from KIFONT::FONT.

Definition at line 64 of file outline_font.h.

65 {
66 return m_face && ( m_fakeBold || ( m_face->style_flags & FT_STYLE_FLAG_BOLD ) );
67 }

References m_face, and m_fakeBold.

◆ IsItalic()

bool KIFONT::OUTLINE_FONT::IsItalic ( ) const
inlineoverridevirtual

Reimplemented from KIFONT::FONT.

Definition at line 69 of file outline_font.h.

70 {
71 return m_face && ( m_fakeItal || ( m_face->style_flags & FT_STYLE_FLAG_ITALIC ) );
72 }

References m_face, and m_fakeItal.

Referenced by getTextAsGlyphs().

◆ IsOutline()

bool KIFONT::OUTLINE_FONT::IsOutline ( ) const
inlineoverridevirtual

Reimplemented from KIFONT::FONT.

Definition at line 62 of file outline_font.h.

62{ return true; }

◆ IsStroke() [1/2]

◆ IsStroke() [2/2]

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

Definition at line 86 of file font.cpp.

87{
88 // This would need a more complex implementation if we ever support more stroke fonts
89 // than the KiCad Font.
90 return aFontName == _( "Default Font" ) || aFontName == KICAD_FONT_NAME;
91}
#define _(s)

References _, and KICAD_FONT_NAME.

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

Definition at line 423 of file font.cpp.

425{
426 TEXT_STYLE_FLAGS textStyle = 0;
427
428 if( aBold )
429 textStyle |= TEXT_STYLE::BOLD;
430
431 if( aItalic )
432 textStyle |= TEXT_STYLE::ITALIC;
433
434 int spaceWidth = GetTextAsGlyphs( nullptr, nullptr, wxS( " " ), aSize, VECTOR2I(), ANGLE_0,
435 false, VECTOR2I(), textStyle ).x;
436
437 wxArrayString textLines;
438 wxStringSplit( aText, textLines, '\n' );
439
440 aText = wxEmptyString;
441
442 for( size_t ii = 0; ii < textLines.Count(); ++ii )
443 {
444 bool virginLine = true;
445 int lineWidth = 0;
446 std::vector<std::pair<wxString, int>> words;
447
448 wordbreakMarkup( &words, textLines[ii], aSize, textStyle );
449
450 for( size_t jj = 0; jj < words.size(); /* advance in loop */ )
451 {
452 if( virginLine )
453 {
454 // First word is always placed, even when wider than columnWidth.
455 aText += words[jj].first;
456 lineWidth += words[jj].second;
457 jj++;
458
459 virginLine = false;
460 }
461 else if( lineWidth + spaceWidth + words[jj].second < aColumnWidth - aThickness )
462 {
463 aText += " " + words[jj].first;
464 lineWidth += spaceWidth + words[jj].second;
465 jj++;
466 }
467 else
468 {
469 aText += '\n';
470
471 lineWidth = 0;
472 virginLine = true;
473 }
474 }
475
476 // Add the newlines back onto the string
477 if( ii != ( textLines.Count() - 1 ) )
478 aText += '\n';
479 }
480}
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.
Definition: font.cpp:402
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.
@ BOLD
Definition: font.h:45

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

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

◆ linesCount()

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

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.

203 {
204 if( aText.empty() )
205 return 0; // std::count does not work well with empty strings
206 else
207 // aText.end() - 1 is to skip a newline character that is potentially at the end
208 return std::count( aText.begin(), aText.end() - 1, '\n' ) + 1;
209 }

◆ loadFace()

FT_Error OUTLINE_FONT::loadFace ( const wxString &  aFontFileName)
protected

Definition at line 116 of file outline_font.cpp.

117{
118 // TODO: check that going from wxString to char* with UTF-8
119 // conversion for filename makes sense on any/all platforms
120 FT_Error e = FT_New_Face( m_freeType, aFontFileName.mb_str( wxConvUTF8 ), 0, &m_face );
121
122 if( !e )
123 {
124 FT_Select_Charmap( m_face, FT_Encoding::FT_ENCODING_UNICODE );
125 // params:
126 // m_face = handle to face object
127 // 0 = char width in 1/64th of points ( 0 = same as char height )
128 // faceSize() = char height in 1/64th of points
129 // GLYPH_RESOLUTION = horizontal device resolution (288dpi, 4x default)
130 // 0 = vertical device resolution ( 0 = same as horizontal )
131 FT_Set_Char_Size( m_face, 0, faceSize(), GLYPH_RESOLUTION, 0 );
132 }
133
134 return e;
135}

References faceSize(), KIFONT::GLYPH_RESOLUTION, m_face, and m_freeType.

Referenced by LoadFont().

◆ LoadFont()

OUTLINE_FONT * OUTLINE_FONT::LoadFont ( const wxString &  aFontFileName,
bool  aBold,
bool  aItalic 
)
static

Load an outline font.

TrueType (.ttf) and OpenType (.otf) are supported.

Parameters
aFontFileNameis the (platform-specific) fully qualified name of the font file

Definition at line 91 of file outline_font.cpp.

92{
93 OUTLINE_FONT* font = new OUTLINE_FONT();
94
95 wxString fontFile;
96 using fc = fontconfig::FONTCONFIG;
97
98 fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, aBold, aItalic );
99
100 if( retval == fc::FF_RESULT::FF_MISSING_BOLD || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
101 font->SetFakeBold();
102
103 if( retval == fc::FF_RESULT::FF_MISSING_ITAL || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
104 font->SetFakeItal();
105
106 if( retval != fc::FF_RESULT::FF_ERROR )
107 (void) font->loadFace( fontFile );
108
109 font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
110 font->m_fontFileName = fontFile;
111
112 return font;
113}
wxString m_fontFileName
Font file name.
Definition: font.h:263
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:50
FT_Error loadFace(const wxString &aFontFileName)
FONTCONFIG * Fontconfig()
Definition: fontconfig.cpp:52

References Fontconfig(), loadFace(), KIFONT::FONT::m_fontFileName, KIFONT::FONT::m_fontName, OUTLINE_FONT(), SetFakeBold(), and SetFakeItal().

Referenced by KIFONT::FONT::GetFont().

◆ NameAsToken()

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

Definition at line 122 of file font.h.

122{ return GetName().utf8_str().data(); }
const wxString & GetName() const
Definition: font.h:121

References KIFONT::FONT::GetName().

Referenced by DS_DATA_MODEL_IO::format().

◆ SetFakeBold()

void KIFONT::OUTLINE_FONT::SetFakeBold ( )
inline

Definition at line 74 of file outline_font.h.

75 {
76 m_fakeBold = true;
77 }

References m_fakeBold.

Referenced by LoadFont().

◆ SetFakeItal()

void KIFONT::OUTLINE_FONT::SetFakeItal ( )
inline

Definition at line 79 of file outline_font.h.

80 {
81 m_fakeItal = true;
82 }

References m_fakeItal.

Referenced by LoadFont().

◆ StringBoundaryLimits()

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

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

273{
274 // TODO do we need to parse every time - have we already parsed?
276 TEXT_STYLE_FLAGS textStyle = 0;
277
278 if( aBold )
279 textStyle |= TEXT_STYLE::BOLD;
280
281 if( aItalic )
282 textStyle |= TEXT_STYLE::ITALIC;
283
284 (void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, ANGLE_0, false,
285 VECTOR2I(), textStyle );
286
287 if( IsStroke() )
288 {
289 // Inflate by a bit more than thickness/2 to catch diacriticals, descenders, etc.
290 boundingBox.Inflate( KiROUND( aThickness * 1.25 ) );
291 }
292 else if( IsOutline() )
293 {
294 // Outline fonts have thickness built in, and *usually* stay within their ascent/descent
295 }
296
297 return boundingBox.GetSize();
298}
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
const Vec & GetSize() const
Definition: box2.h:179
virtual bool IsStroke() const
Definition: font.h:112
virtual bool IsOutline() const
Definition: font.h:113
BOX2I boundingBox(T aObject)
Used by SHAPE_INDEX to get the bounding box of a generic T object.
Definition: shape_index.h:77

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

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

◆ subscriptSize() [1/2]

int KIFONT::OUTLINE_FONT::subscriptSize ( ) const
inlineprivate

Definition at line 178 of file outline_font.h.

178{ return subscriptSize( m_faceSize ); }

References m_faceSize, and subscriptSize().

Referenced by getTextAsGlyphs(), and subscriptSize().

◆ subscriptSize() [2/2]

int KIFONT::OUTLINE_FONT::subscriptSize ( int  aSize) const
inlineprivate

Definition at line 174 of file outline_font.h.

175 {
176 return KiROUND( faceSize( aSize ) * m_subscriptSuperscriptSize );
177 }
static constexpr double m_subscriptSuperscriptSize
Definition: outline_font.h:163

References faceSize(), KiROUND(), and m_subscriptSuperscriptSize.

◆ wordbreakMarkup()

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

Factor that determines the pitch between 2 lines.

Definition at line 402 of file font.cpp.

404{
405 MARKUP::MARKUP_PARSER markupParser( TO_UTF8( aText ) );
406 std::unique_ptr<MARKUP::NODE> root = markupParser.Parse();
407
408 ::wordbreakMarkup( aWords, root, this, aSize, aTextStyle );
409}

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

Referenced by KIFONT::FONT::LinebreakText(), and KIFONT::FONT::wordbreakMarkup().

Member Data Documentation

◆ INTERLINE_PITCH_RATIO

constexpr double KIFONT::FONT::INTERLINE_PITCH_RATIO = 1.62
staticconstexprprotectedinherited

Definition at line 256 of file font.h.

Referenced by KIFONT::STROKE_FONT::GetInterline(), and GetInterline().

◆ m_charSizeScaler

constexpr int KIFONT::OUTLINE_FONT::m_charSizeScaler = 64
staticconstexprprivate

Definition at line 156 of file outline_font.h.

Referenced by faceSize().

◆ m_contourCache

std::map<unsigned int, GLYPH_POINTS_LIST> KIFONT::OUTLINE_FONT::m_contourCache
private

Definition at line 146 of file outline_font.h.

◆ m_face

FT_Face KIFONT::OUTLINE_FONT::m_face
private

Definition at line 139 of file outline_font.h.

Referenced by GetFace(), getTextAsGlyphs(), IsBold(), IsItalic(), and loadFace().

◆ m_faceSize

const int KIFONT::OUTLINE_FONT::m_faceSize
private

Definition at line 140 of file outline_font.h.

Referenced by faceSize(), and subscriptSize().

◆ m_fakeBold

bool KIFONT::OUTLINE_FONT::m_fakeBold
private

Definition at line 141 of file outline_font.h.

Referenced by getTextAsGlyphs(), IsBold(), and SetFakeBold().

◆ m_fakeItal

bool KIFONT::OUTLINE_FONT::m_fakeItal
private

Definition at line 142 of file outline_font.h.

Referenced by getTextAsGlyphs(), IsItalic(), and SetFakeItal().

◆ m_fontFileName

wxString KIFONT::FONT::m_fontFileName
protectedinherited

Font file name.

Definition at line 263 of file font.h.

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

◆ m_fontName

wxString KIFONT::FONT::m_fontName
protectedinherited

Font name.

Definition at line 262 of file font.h.

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

◆ m_freeType

FT_Library OUTLINE_FONT::m_freeType = nullptr
staticprivate

Definition at line 138 of file outline_font.h.

Referenced by FreeTypeVersion(), loadFace(), and OUTLINE_FONT().

◆ m_outlineFontSizeCompensation

constexpr double KIFONT::OUTLINE_FONT::m_outlineFontSizeCompensation = 1.4
staticconstexprprivate

◆ m_subscriptSuperscriptSize

constexpr double KIFONT::OUTLINE_FONT::m_subscriptSuperscriptSize = 0.64
staticconstexprprivate

Definition at line 163 of file outline_font.h.

Referenced by subscriptSize().

◆ m_subscriptVerticalOffset

constexpr double KIFONT::OUTLINE_FONT::m_subscriptVerticalOffset = -0.25
staticconstexprprivate

Definition at line 180 of file outline_font.h.

Referenced by getTextAsGlyphs().

◆ m_superscriptVerticalOffset

constexpr double KIFONT::OUTLINE_FONT::m_superscriptVerticalOffset = 0.45
staticconstexprprivate

Definition at line 181 of file outline_font.h.

Referenced by getTextAsGlyphs().

◆ m_underlineOffsetScaler

constexpr double KIFONT::OUTLINE_FONT::m_underlineOffsetScaler = -0.16
staticconstexprprivate

Definition at line 165 of file outline_font.h.

Referenced by ComputeUnderlineVerticalPosition().

◆ s_defaultFont

FONT * FONT::s_defaultFont = nullptr
staticprivateinherited

Definition at line 266 of file font.h.

Referenced by KIFONT::FONT::getDefaultFont().

◆ s_fontMap

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

Definition at line 268 of file font.h.

Referenced by KIFONT::FONT::GetFont().


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