46FONT* FONT::s_defaultFont =
nullptr;
48std::map< std::tuple<wxString, bool, bool>,
FONT*> FONT::s_fontMap;
70 std::tuple<wxString, bool, bool> key = { aFontName, aBold, aItalic };
95 wxArrayString& aTextLines, std::vector<VECTOR2I>& aPositions,
99 int lineCount = aTextLines.Count();
100 aPositions.reserve( lineCount );
105 for(
int i = 0; i < lineCount; i++ )
107 VECTOR2I pos( aPosition.
x, aPosition.
y + i * interline );
112 aExtents.push_back( bBox );
115 height += ( aAttrs.
m_Size.
y * 1.17 );
130 for(
int i = 0; i < lineCount; i++ )
132 VECTOR2I lineSize = aExtents.at( i );
135 lineOffset.
y += i * interline;
144 aPositions.push_back( aPosition + lineOffset );
162 if( !aGal || aText.empty() )
165 VECTOR2I position( aPosition - aCursor );
168 wxArrayString strings_list;
169 std::vector<VECTOR2I> positions;
170 std::vector<VECTOR2I> extents;
172 getLinePositions( aText, position, strings_list, positions, extents, aAttrs );
176 for(
size_t i = 0; i < strings_list.GetCount(); i++ )
189 const std::unique_ptr<MARKUP::NODE>& aNode,
const VECTOR2I& aPosition,
199 if( !aNode->is_root() )
201 if( aNode->isSubscript() )
203 else if( aNode->isSuperscript() )
206 if( aNode->isOverbar() )
209 if( aNode->has_content() )
213 nextPosition = aFont->
GetTextAsGlyphs( &bbox, aGlyphs, aNode->asWxString(), aSize,
214 aPosition, aAngle, aMirror, aOrigin,
218 aBoundingBox->
Merge( bbox );
222 for(
const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
224 nextPosition =
drawMarkup( aBoundingBox, aGlyphs, child, nextPosition, aFont, aSize,
225 aAngle, aMirror, aOrigin, textStyle );
239 std::unique_ptr<MARKUP::NODE> root = markupParser.
Parse();
242 aOrigin, aTextStyle );
249 bool aItalic,
bool aUnderline )
const
262 std::vector<std::unique_ptr<GLYPH>> glyphs;
264 (void)
drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin,
272 bool aBold,
bool aItalic )
const
322 const std::unique_ptr<MARKUP::NODE>& aNode,
const KIFONT::FONT* aFont,
327 if( !aNode->is_root() )
329 wxChar escapeChar = 0;
331 if( aNode->isSubscript() )
336 else if( aNode->isSuperscript() )
342 if( aNode->isOverbar() )
353 if( aNode->has_content() )
356 aSize, { 0, 0 },
ANGLE_0,
false, { 0, 0 },
358 word += aNode->asWxString();
362 std::vector<std::pair<wxString, int>> childWords;
364 for(
const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
367 for(
const std::pair<wxString, int>& childWord : childWords )
369 word += childWord.first;
370 width += childWord.second;
374 aWords->emplace_back( std::make_pair( word, width ) );
379 wxString textRun = aNode->asWxString();
384 if( textRun.EndsWith( wxS(
" " ) ) )
385 words.Add( wxS(
" " ) );
387 for(
size_t ii = 0; ii < words.size(); ++ii )
389 int w = aFont->
GetTextAsGlyphs(
nullptr,
nullptr, words[ii], aSize, { 0, 0 },
390 ANGLE_0,
false, { 0, 0 }, textStyle ).x;
392 aWords->emplace_back( std::make_pair( words[ii], w ) );
397 for(
const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
406 std::unique_ptr<MARKUP::NODE> root = markupParser.
Parse();
424 bool aBold,
bool aItalic )
const
437 wxArrayString textLines;
440 aText = wxEmptyString;
442 for(
size_t ii = 0; ii < textLines.Count(); ++ii )
444 bool virginLine =
true;
446 std::vector<std::pair<wxString, int>> words;
450 for(
size_t jj = 0; jj < words.size(); )
455 aText += words[jj].first;
456 lineWidth += words[jj].second;
461 else if( lineWidth + spaceWidth + words[jj].second < aColumnWidth - aThickness )
463 aText +=
" " + words[jj].first;
464 lineWidth += spaceWidth + words[jj].second;
477 if( ii != ( textLines.Count() - 1 ) )
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
const Vec & GetSize() const
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
FONT is an abstract base class for both outline and stroke fonts.
virtual double GetInterline(double aGlyphHeight, double aLineSpacing=1.0) const =0
Compute the distance (interline) between 2 lines of text (for multiline texts).
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttrs) const
Draw a string.
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.
virtual bool IsStroke() const
static FONT * s_defaultFont
void getLinePositions(const wxString &aText, const VECTOR2I &aPosition, wxArrayString &aTextLines, std::vector< VECTOR2I > &aPositions, std::vector< VECTOR2I > &aExtents, const TEXT_ATTRIBUTES &aAttrs) const
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.
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.
virtual bool IsOutline() 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
static std::map< std::tuple< wxString, bool, bool >, FONT * > s_fontMap
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).
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.
static FONT * getDefaultFont()
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 OUTLINE_FONT * LoadFont(const wxString &aFontFileName, bool aBold, bool aItalic)
Load an outline font.
static STROKE_FONT * LoadFont(const wxString &aFontName)
Load a stroke font.
Abstract interface for drawing on a 2D-surface.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
std::unique_ptr< NODE > Parse()
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
static constexpr EDA_ANGLE & ANGLE_0
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)
void wordbreakMarkup(std::vector< std::pair< wxString, int > > *aWords, const std::unique_ptr< MARKUP::NODE > &aNode, const KIFONT::FONT *aFont, const VECTOR2I &aSize, TEXT_STYLE_FLAGS aTextStyle)
unsigned int TEXT_STYLE_FLAGS
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
BOX2I boundingBox(T aObject)
Used by SHAPE_INDEX to get the bounding box of a generic T object.
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".