KiCad PCB EDA Suite
Loading...
Searching...
No Matches
font.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 Ola Rinta-Koski
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Font abstract base class
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <list>
28#include <mutex>
29#include <unordered_map>
30
31#include <macros.h>
32#include <string_utils.h>
34#include <font/stroke_font.h>
35#include <font/outline_font.h>
36#include <trigo.h>
37#include <markup_parser.h>
38
39// The "official" name of the Kicad stroke font (always existing)
41#include <wx/tokenzr.h>
42
43// markup_parser.h includes pegtl.hpp which includes windows.h... which leaks #define DrawText
44#undef DrawText
45
46
47using namespace KIFONT;
48
50
51
53{
54 return g_defaultMetrics;
55}
56
57
58FONT* FONT::s_defaultFont = nullptr;
59
60std::map< std::tuple<wxString, bool, bool, bool>, FONT*> FONT::s_fontMap;
61
63{
64public:
65 struct ENTRY
66 {
67 std::string source;
68 std::unique_ptr<MARKUP::NODE> root;
69 };
70
71 MARKUP_CACHE( size_t aMaxSize ) :
72 m_maxSize( aMaxSize )
73 {
74 }
75
76 ENTRY& Put( const wxString& aQuery, ENTRY&& aResult )
77 {
78 auto it = m_cache.find( aQuery );
79
80 m_cacheMru.emplace_front( std::make_pair( aQuery, std::move( aResult ) ) );
81
82 if( it != m_cache.end() )
83 {
84 m_cacheMru.erase( it->second );
85 m_cache.erase( it );
86 }
87
88 m_cache[aQuery] = m_cacheMru.begin();
89
90 if( m_cache.size() > m_maxSize )
91 {
92 auto last = m_cacheMru.end();
93 last--;
94 m_cache.erase( last->first );
95 m_cacheMru.pop_back();
96 }
97
98 return m_cacheMru.begin()->second;
99 }
100
101 ENTRY* Get( const wxString& aQuery )
102 {
103 auto it = m_cache.find( aQuery );
104
105 if( it == m_cache.end() )
106 return nullptr;
107
108 m_cacheMru.splice( m_cacheMru.begin(), m_cacheMru, it->second );
109
110 return &m_cacheMru.begin()->second;
111 }
112
113 void Clear()
114 {
115 m_cacheMru.clear();
116 m_cache.clear();
117 }
118
119private:
120 size_t m_maxSize;
121 std::list<std::pair<wxString, ENTRY>> m_cacheMru;
122 std::unordered_map<wxString, std::list<std::pair<wxString, ENTRY>>::iterator> m_cache;
123};
124
125
127static std::mutex s_markupCacheMutex;
128static std::mutex s_defaultFontMutex;;
129
130
132{
133}
134
135
137{
138 std::lock_guard lock( s_defaultFontMutex );
139
140 if( !s_defaultFont )
141 s_defaultFont = STROKE_FONT::LoadFont( wxEmptyString );
142
143 return s_defaultFont;
144}
145
146
147FONT* FONT::GetFont( const wxString& aFontName, bool aBold, bool aItalic,
148 const std::vector<wxString>* aEmbeddedFiles, bool aForDrawingSheet )
149{
150 if( aFontName.empty() || aFontName.StartsWith( KICAD_FONT_NAME ) )
151 return getDefaultFont();
152
153 std::tuple<wxString, bool, bool, bool> key = { aFontName, aBold, aItalic, aForDrawingSheet };
154
155 FONT* font = nullptr;
156
157 if( s_fontMap.find( key ) != s_fontMap.end() )
158 font = s_fontMap[key];
159
160 if( !font )
161 font = OUTLINE_FONT::LoadFont( aFontName, aBold, aItalic, aEmbeddedFiles,
162 aForDrawingSheet );
163
164 if( !font )
165 font = getDefaultFont();
166
167 s_fontMap[key] = font;
168
169 return font;
170}
171
172
173bool FONT::IsStroke( const wxString& aFontName )
174{
175 // This would need a more complex implementation if we ever support more stroke fonts
176 // than the KiCad Font.
177 return aFontName == _( "Default Font" ) || aFontName == KICAD_FONT_NAME;
178}
179
180
181void FONT::getLinePositions( const wxString& aText, const VECTOR2I& aPosition,
182 wxArrayString& aTextLines, std::vector<VECTOR2I>& aPositions,
183 std::vector<VECTOR2I>& aExtents, const TEXT_ATTRIBUTES& aAttrs,
184 const METRICS& aFontMetrics ) const
185{
186 wxStringSplit( aText, aTextLines, '\n' );
187 int lineCount = aTextLines.Count();
188 aPositions.reserve( lineCount );
189
190 int interline = GetInterline( aAttrs.m_Size.y, aFontMetrics ) * aAttrs.m_LineSpacing;
191 int height = 0;
192
193 for( int i = 0; i < lineCount; i++ )
194 {
195 VECTOR2I pos( aPosition.x, aPosition.y + i * interline );
196 VECTOR2I end = boundingBoxSingleLine( nullptr, aTextLines[i], pos, aAttrs.m_Size,
197 aAttrs.m_Italic, aFontMetrics );
198 VECTOR2I bBox( end - pos );
199
200 aExtents.push_back( bBox );
201
202 if( i == 0 )
203 height += ( aAttrs.m_Size.y * 1.17 ); // 1.17 is a fudge to match 6.0 positioning
204 else
205 height += interline;
206 }
207
208 VECTOR2I offset( 0, 0 );
209 offset.y += aAttrs.m_Size.y;
210
211 if( IsStroke() )
212 {
213 // Fudge factors to match 6.0 positioning
214 offset.x += aAttrs.m_StrokeWidth / 1.52;
215 offset.y -= aAttrs.m_StrokeWidth * 0.052;
216 }
217
218 switch( aAttrs.m_Valign )
219 {
220 case GR_TEXT_V_ALIGN_TOP: break;
221 case GR_TEXT_V_ALIGN_CENTER: offset.y -= height / 2; break;
222 case GR_TEXT_V_ALIGN_BOTTOM: offset.y -= height; break;
224 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
225 break;
226 }
227
228 for( int i = 0; i < lineCount; i++ )
229 {
230 VECTOR2I lineSize = aExtents.at( i );
231 VECTOR2I lineOffset( offset );
232
233 lineOffset.y += i * interline;
234
235 switch( aAttrs.m_Halign )
236 {
237 case GR_TEXT_H_ALIGN_LEFT: break;
238 case GR_TEXT_H_ALIGN_CENTER: lineOffset.x = -lineSize.x / 2; break;
239 case GR_TEXT_H_ALIGN_RIGHT: lineOffset.x = -( lineSize.x + offset.x ); break;
241 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
242 break;
243 }
244
245 aPositions.push_back( aPosition + lineOffset );
246 }
247}
248
249
250void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosition,
251 const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttrs,
252 const METRICS& aFontMetrics ) const
253{
254 if( !aGal || aText.empty() )
255 return;
256
257 VECTOR2I position( aPosition - aCursor );
258
259 // Split multiline strings into separate ones and draw them line by line
260 wxArrayString strings_list;
261 std::vector<VECTOR2I> positions;
262 std::vector<VECTOR2I> extents;
263
264 getLinePositions( aText, position, strings_list, positions, extents, aAttrs, aFontMetrics );
265
266 aGal->SetLineWidth( aAttrs.m_StrokeWidth );
267
268 for( size_t i = 0; i < strings_list.GetCount(); i++ )
269 {
270 drawSingleLineText( aGal, nullptr, strings_list[i], positions[i], aAttrs.m_Size,
271 aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, aAttrs.m_Italic,
272 aAttrs.m_Underlined, aFontMetrics );
273 }
274}
275
276
280VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
281 const MARKUP::NODE* aNode, const VECTOR2I& aPosition,
282 const KIFONT::FONT* aFont, const VECTOR2I& aSize, const EDA_ANGLE& aAngle,
283 bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle,
284 const METRICS& aFontMetrics )
285{
286 VECTOR2I nextPosition = aPosition;
287 bool drawUnderline = false;
288 bool drawOverbar = false;
289
290 if( aNode )
291 {
292 TEXT_STYLE_FLAGS textStyle = aTextStyle;
293
294 if( !aNode->is_root() )
295 {
296 if( aNode->isSubscript() )
297 textStyle |= TEXT_STYLE::SUBSCRIPT;
298 else if( aNode->isSuperscript() )
299 textStyle |= TEXT_STYLE::SUPERSCRIPT;
300
301 if( aNode->isOverbar() )
302 drawOverbar = true;
303
304 if( aNode->has_content() )
305 {
306 BOX2I bbox;
307
308 nextPosition = aFont->GetTextAsGlyphs( &bbox, aGlyphs, aNode->asWxString(), aSize,
309 nextPosition, aAngle, aMirror, aOrigin,
310 textStyle );
311
312 if( aBoundingBox )
313 aBoundingBox->Merge( bbox );
314 }
315 }
316 else if( aTextStyle & TEXT_STYLE::UNDERLINE )
317 {
318 drawUnderline = true;
319 }
320
321 for( const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
322 {
323 nextPosition = drawMarkup( aBoundingBox, aGlyphs, child.get(), nextPosition, aFont,
324 aSize, aAngle, aMirror, aOrigin, textStyle, aFontMetrics );
325 }
326 }
327
328 if( drawUnderline )
329 {
330 // Shorten the bar a little so its rounded ends don't make it over-long
331 double barTrim = aSize.x * 0.1;
332 double barOffset = aFontMetrics.GetUnderlineVerticalPosition( aSize.y );
333
334 VECTOR2D barStart( aPosition.x + barTrim, aPosition.y - barOffset );
335 VECTOR2D barEnd( nextPosition.x - barTrim, nextPosition.y - barOffset );
336
337 if( aGlyphs )
338 {
339 STROKE_GLYPH barGlyph;
340
341 barGlyph.AddPoint( barStart );
342 barGlyph.AddPoint( barEnd );
343 barGlyph.Finalize();
344
345 aGlyphs->push_back( barGlyph.Transform( { 1.0, 1.0 }, { 0, 0 }, false, aAngle, aMirror,
346 aOrigin ) );
347 }
348 }
349
350 if( drawOverbar )
351 {
352 // Shorten the bar a little so its rounded ends don't make it over-long
353 double barTrim = aSize.x * 0.1;
354 double barOffset = aFontMetrics.GetOverbarVerticalPosition( aSize.y );
355
356 VECTOR2D barStart( aPosition.x + barTrim, aPosition.y - barOffset );
357 VECTOR2D barEnd( nextPosition.x - barTrim, nextPosition.y - barOffset );
358
359 if( aGlyphs )
360 {
361 STROKE_GLYPH barGlyph;
362
363 barGlyph.AddPoint( barStart );
364 barGlyph.AddPoint( barEnd );
365 barGlyph.Finalize();
366
367 aGlyphs->push_back( barGlyph.Transform( { 1.0, 1.0 }, { 0, 0 }, false, aAngle, aMirror,
368 aOrigin ) );
369 }
370 }
371
372 return nextPosition;
373}
374
375
376VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
377 const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize,
378 const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin,
379 TEXT_STYLE_FLAGS aTextStyle, const METRICS& aFontMetrics ) const
380{
381 std::lock_guard<std::mutex> lock( s_markupCacheMutex );
382
383 MARKUP_CACHE::ENTRY* markup = s_markupCache.Get( aText );
384
385 if( !markup || !markup->root )
386 {
387 MARKUP_CACHE::ENTRY& cached = s_markupCache.Put( aText, {} );
388
389 cached.source = TO_UTF8( aText );
390 MARKUP::MARKUP_PARSER markupParser( &cached.source );
391 cached.root = markupParser.Parse();
392 markup = &cached;
393 }
394
395 wxASSERT( markup && markup->root );
396
397 return ::drawMarkup( aBoundingBox, aGlyphs, markup->root.get(), aPosition, this, aSize, aAngle,
398 aMirror, aOrigin, aTextStyle, aFontMetrics );
399}
400
401
402void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxString& aText,
403 const VECTOR2I& aPosition, const VECTOR2I& aSize,
404 const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin,
405 bool aItalic, bool aUnderline, const METRICS& aFontMetrics ) const
406{
407 if( !aGal )
408 return;
409
410 TEXT_STYLE_FLAGS textStyle = 0;
411
412 if( aItalic )
413 textStyle |= TEXT_STYLE::ITALIC;
414
415 if( aUnderline )
416 textStyle |= TEXT_STYLE::UNDERLINE;
417
418 std::vector<std::unique_ptr<GLYPH>> glyphs;
419
420 (void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin,
421 textStyle, aFontMetrics );
422
423 aGal->DrawGlyphs( glyphs );
424}
425
426
427VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSize, int aThickness,
428 bool aBold, bool aItalic, const METRICS& aFontMetrics ) const
429{
430 // TODO do we need to parse every time - have we already parsed?
432 TEXT_STYLE_FLAGS textStyle = 0;
433
434 if( aBold )
435 textStyle |= TEXT_STYLE::BOLD;
436
437 if( aItalic )
438 textStyle |= TEXT_STYLE::ITALIC;
439
440 (void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, ANGLE_0, false, VECTOR2I(),
441 textStyle, aFontMetrics );
442
443 if( IsStroke() )
444 {
445 // Inflate by a bit more than thickness/2 to catch diacriticals, descenders, etc.
446 boundingBox.Inflate( KiROUND( aThickness * 1.5 ) );
447 }
448 else if( IsOutline() )
449 {
450 // Outline fonts have thickness built in, and *usually* stay within their ascent/descent
451 }
452
453 return boundingBox.GetSize();
454}
455
456
457VECTOR2I FONT::boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText,
458 const VECTOR2I& aPosition, const VECTOR2I& aSize,
459 bool aItalic, const METRICS& aFontMetrics ) const
460{
461 TEXT_STYLE_FLAGS textStyle = 0;
462
463 if( aItalic )
464 textStyle |= TEXT_STYLE::ITALIC;
465
466 VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, ANGLE_0, false,
467 VECTOR2I(), textStyle, aFontMetrics );
468
469 return extents;
470}
471
472
479void wordbreakMarkup( std::vector<std::pair<wxString, int>>* aWords,
480 const std::unique_ptr<MARKUP::NODE>& aNode, const KIFONT::FONT* aFont,
481 const VECTOR2I& aSize, TEXT_STYLE_FLAGS aTextStyle )
482{
483 TEXT_STYLE_FLAGS textStyle = aTextStyle;
484
485 if( !aNode->is_root() )
486 {
487 wxChar escapeChar = 0;
488
489 if( aNode->isSubscript() )
490 {
491 escapeChar = '_';
492 textStyle = TEXT_STYLE::SUBSCRIPT;
493 }
494 else if( aNode->isSuperscript() )
495 {
496 escapeChar = '^';
497 textStyle = TEXT_STYLE::SUPERSCRIPT;
498 }
499
500 if( aNode->isOverbar() )
501 {
502 escapeChar = '~';
503 textStyle |= TEXT_STYLE::OVERBAR;
504 }
505
506 if( escapeChar )
507 {
508 wxString word = wxString::Format( wxT( "%c{" ), escapeChar );
509 int width = 0;
510
511 if( aNode->has_content() )
512 {
513 VECTOR2I next = aFont->GetTextAsGlyphs( nullptr, nullptr, aNode->asWxString(),
514 aSize, { 0, 0 }, ANGLE_0, false, { 0, 0 },
515 textStyle );
516 word += aNode->asWxString();
517 width += next.x;
518 }
519
520 std::vector<std::pair<wxString, int>> childWords;
521
522 for( const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
523 wordbreakMarkup( &childWords, child, aFont, aSize, textStyle );
524
525 for( const std::pair<wxString, int>& childWord : childWords )
526 {
527 word += childWord.first;
528 width += childWord.second;
529 }
530
531 word += wxT( "}" );
532 aWords->emplace_back( std::make_pair( word, width ) );
533 return;
534 }
535 else
536 {
537 wxString textRun = aNode->asWxString();
538 wxStringTokenizer tokenizer( textRun, " ", wxTOKEN_RET_DELIMS );
539 std::vector<wxString> words;
540
541 while( tokenizer.HasMoreTokens() )
542 words.emplace_back( tokenizer.GetNextToken() );
543
544 for( const wxString& word : words )
545 {
546 wxString chars = word;
547 chars.Trim();
548
549 int w = aFont->GetTextAsGlyphs( nullptr, nullptr, chars, aSize, { 0, 0 },
550 ANGLE_0, false, { 0, 0 }, textStyle ).x;
551
552 aWords->emplace_back( std::make_pair( word, w ) );
553 }
554 }
555 }
556
557 for( const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
558 wordbreakMarkup( aWords, child, aFont, aSize, textStyle );
559}
560
561
562void FONT::wordbreakMarkup( std::vector<std::pair<wxString, int>>* aWords, const wxString& aText,
563 const VECTOR2I& aSize, TEXT_STYLE_FLAGS aTextStyle ) const
564{
565 MARKUP::MARKUP_PARSER markupParser( TO_UTF8( aText ) );
566 std::unique_ptr<MARKUP::NODE> root = markupParser.Parse();
567
568 ::wordbreakMarkup( aWords, root, this, aSize, aTextStyle );
569}
570
571
572void FONT::LinebreakText( wxString& aText, int aColumnWidth, const VECTOR2I& aSize, int aThickness,
573 bool aBold, bool aItalic ) const
574{
575 TEXT_STYLE_FLAGS textStyle = 0;
576
577 if( aBold )
578 textStyle |= TEXT_STYLE::BOLD;
579
580 if( aItalic )
581 textStyle |= TEXT_STYLE::ITALIC;
582
583 int spaceWidth = GetTextAsGlyphs( nullptr, nullptr, wxS( " " ), aSize, VECTOR2I(), ANGLE_0,
584 false, VECTOR2I(), textStyle ).x;
585
586 wxArrayString textLines;
587 wxStringSplit( aText, textLines, '\n' );
588
589 aText = wxEmptyString;
590
591 for( size_t ii = 0; ii < textLines.Count(); ++ii )
592 {
593 std::vector<std::pair<wxString, int>> markup;
594 std::vector<std::pair<wxString, int>> words;
595
596 wordbreakMarkup( &markup, textLines[ii], aSize, textStyle );
597
598 for( const auto& [ run, runWidth ] : markup )
599 {
600 if( !words.empty() && !words.back().first.EndsWith( ' ' ) )
601 {
602 words.back().first += run;
603 words.back().second += runWidth;
604 }
605 else
606 {
607 words.emplace_back( std::make_pair( run, runWidth ) );
608 }
609 }
610
611 bool buryMode = false;
612 int lineWidth = 0;
613 wxString pendingSpaces;
614
615 for( const auto& [ word, wordWidth ] : words )
616 {
617 int pendingSpaceWidth = (int) pendingSpaces.Length() * spaceWidth;
618 bool overflow = lineWidth + pendingSpaceWidth + wordWidth > aColumnWidth - aThickness;
619
620 if( overflow && pendingSpaces.Length() > 0 )
621 {
622 aText += '\n';
623 lineWidth = 0;
624 pendingSpaces = wxEmptyString;
625 pendingSpaceWidth = 0;
626 buryMode = true;
627 }
628
629 if( word == wxS( " " ) )
630 {
631 pendingSpaces += word;
632 }
633 else
634 {
635 if( buryMode )
636 {
637 buryMode = false;
638 }
639 else
640 {
641 aText += pendingSpaces;
642 lineWidth += pendingSpaceWidth;
643 }
644
645 if( word.EndsWith( ' ' ) )
646 {
647 aText += word.Left( word.Length() - 1 );
648 pendingSpaces = wxS( " " );
649 }
650 else
651 {
652 aText += word;
653 pendingSpaces = wxEmptyString;
654 }
655
656 lineWidth += wordWidth;
657 }
658 }
659
660 // Add the newlines back onto the string
661 if( ii != ( textLines.Count() - 1 ) )
662 aText += '\n';
663 }
664}
665
666
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:658
constexpr const SizeVec & GetSize() const
Definition: box2.h:206
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
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.
Definition: font.cpp:457
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition: font.cpp:147
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.
Definition: font.cpp:402
virtual bool IsStroke() const
Definition: font.h:138
static FONT * s_defaultFont
Definition: font.h:294
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
Definition: font.cpp:181
void wordbreakMarkup(std::vector< std::pair< wxString, int > > *aWords, const wxString &aText, const VECTOR2I &aSize, TEXT_STYLE_FLAGS aTextStyle) const
Definition: font.cpp:562
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.
Definition: font.cpp:250
virtual bool IsOutline() const
Definition: font.h:139
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
Definition: font.cpp:376
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).
Definition: font.cpp:427
static std::map< std::tuple< wxString, bool, bool, bool >, FONT * > s_fontMap
Definition: font.h:296
virtual double GetInterline(double aGlyphHeight, const METRICS &aFontMetrics) const =0
Compute the distance (interline) between 2 lines of text (for multiline texts).
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()
Definition: font.cpp:136
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.
Definition: font.cpp:572
double GetUnderlineVerticalPosition(double aGlyphHeight) const
Compute the vertical position of an underline.
Definition: font.h:109
double GetOverbarVerticalPosition(double aGlyphHeight) const
Compute the vertical position of an overbar.
Definition: font.h:100
static const METRICS & Default()
Definition: font.cpp:52
static OUTLINE_FONT * LoadFont(const wxString &aFontFileName, bool aBold, bool aItalic, const std::vector< wxString > *aEmbeddedFiles, bool aForDrawingSheet)
Load an outline font.
static STROKE_FONT * LoadFont(const wxString &aFontName)
Load a stroke font.
Definition: stroke_font.cpp:65
void AddPoint(const VECTOR2D &aPoint)
Definition: glyph.cpp:39
std::unique_ptr< GLYPH > Transform(const VECTOR2D &aGlyphSize, const VECTOR2I &aOffset, double aTilt, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin)
Definition: glyph.cpp:74
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()
std::list< std::pair< wxString, ENTRY > > m_cacheMru
Definition: font.cpp:121
MARKUP_CACHE(size_t aMaxSize)
Definition: font.cpp:71
ENTRY & Put(const wxString &aQuery, ENTRY &&aResult)
Definition: font.cpp:76
void Clear()
Definition: font.cpp:113
size_t m_maxSize
Definition: font.cpp:120
ENTRY * Get(const wxString &aQuery)
Definition: font.cpp:101
std::unordered_map< wxString, std::list< std::pair< wxString, ENTRY > >::iterator > m_cache
Definition: font.cpp:122
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
METRICS g_defaultMetrics
Definition: font.cpp:49
static std::mutex s_markupCacheMutex
Definition: font.cpp:127
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)
Break marked-up text into "words".
Definition: font.cpp:479
static std::mutex s_defaultFontMutex
Definition: font.cpp:128
static MARKUP_CACHE s_markupCache(1024)
VECTOR2I drawMarkup(BOX2I *aBoundingBox, std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const 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, const METRICS &aFontMetrics)
Definition: font.cpp:280
unsigned int TEXT_STYLE_FLAGS
Definition: font.h:64
#define KICAD_FONT_NAME
This file contains miscellaneous commonly used macros and functions.
CITER next(CITER it)
Definition: ptree.cpp:124
BOX2I boundingBox(T aObject, int aLayer)
Used by SHAPE_INDEX to get the bounding box of a generic T object.
Definition: shape_index.h:62
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:403
bool isOverbar() const
Definition: markup_parser.h:48
bool isSuperscript() const
Definition: markup_parser.h:50
wxString asWxString() const
bool isSubscript() const
Definition: markup_parser.h:49
std::unique_ptr< MARKUP::NODE > root
Definition: font.cpp:68
std::string source
Definition: font.cpp:67
VECTOR2I end
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695