KiCad PCB EDA Suite
Loading...
Searching...
No Matches
outline_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 <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <limits>
26#include <harfbuzz/hb.h>
27#include <harfbuzz/hb-ft.h>
28#include <bezier_curves.h>
30#include <font/fontconfig.h>
31#include <font/outline_font.h>
32#include <ft2build.h>
33#include FT_FREETYPE_H
34#include FT_SFNT_NAMES_H
35#include FT_TRUETYPE_TABLES_H
36#include FT_GLYPH_H
37#include FT_BBOX_H
38#include <trigo.h>
39#include <core/utf8.h>
40
41using namespace KIFONT;
42
43
44FT_Library OUTLINE_FONT::m_freeType = nullptr;
46
48 m_face(NULL),
49 m_faceSize( 16 ),
50 m_fakeBold( false ),
51 m_fakeItal( false ),
52 m_forDrawingSheet( false )
53{
54 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
55
56 if( !m_freeType )
57 FT_Init_FreeType( &m_freeType );
58}
59
60
62{
63 TT_OS2* os2 = reinterpret_cast<TT_OS2*>( FT_Get_Sfnt_Table( m_face, FT_SFNT_OS2 ) );
64
65 // If this table isn't present, we can't assume anything
66 if( !os2 )
68
69 // This allows the font to be exported from KiCad
70 if( os2->fsType == FT_FSTYPE_INSTALLABLE_EMBEDDING )
72
73 // We don't support bitmap fonts, so this disables embedding
74 if( os2->fsType & FT_FSTYPE_BITMAP_EMBEDDING_ONLY )
76
77 // This allows us to use the font in KiCad but not export
78 if( os2->fsType & FT_FSTYPE_EDITABLE_EMBEDDING )
80
81 // This is not actually supported by KiCad ATM(2024)
82 if( os2->fsType & FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING )
84
85 // Anything else that is not explicitly enabled we treat as restricted.
87}
88
89
90OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, bool aItalic,
91 const std::vector<wxString>* aEmbeddedFiles,
92 bool aForDrawingSheet )
93{
94 std::unique_ptr<OUTLINE_FONT> font = std::make_unique<OUTLINE_FONT>();
95
96 wxString fontFile;
97 int faceIndex;
98 using fc = fontconfig::FONTCONFIG;
99
100
101 fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, faceIndex, aBold, aItalic,
102 aEmbeddedFiles );
103
104 if( retval == fc::FF_RESULT::FF_ERROR )
105 return nullptr;
106
107 if( retval == fc::FF_RESULT::FF_MISSING_BOLD || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
108 font->SetFakeBold();
109
110 if( retval == fc::FF_RESULT::FF_MISSING_ITAL || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
111 font->SetFakeItal();
112
113 if( font->loadFace( fontFile, faceIndex ) != 0 )
114 return nullptr;
115
116 font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
117 font->m_fontFileName = fontFile;
118 font->m_forDrawingSheet = aForDrawingSheet;
119
120 return font.release();
121}
122
123
124FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName, int aFaceIndex )
125{
126 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
127
128 FT_Error e = FT_New_Face( m_freeType, aFontFileName.mb_str( wxConvUTF8 ), aFaceIndex, &m_face );
129
130 if( !e )
131 {
132 FT_Select_Charmap( m_face, FT_Encoding::FT_ENCODING_UNICODE );
133 // params:
134 // m_face = handle to face object
135 // 0 = char width in 1/64th of points ( 0 = same as char height )
136 // faceSize() = char height in 1/64th of points
137 // GLYPH_RESOLUTION = horizontal device resolution (1152dpi, 16x default)
138 // 0 = vertical device resolution ( 0 = same as horizontal )
139 FT_Set_Char_Size( m_face, 0, faceSize(), GLYPH_RESOLUTION, 0 );
140 }
141
142 return e;
143}
144
145
146double OUTLINE_FONT::GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const
147{
148 double glyphToFontHeight = 1.0;
149
150 if( GetFace()->units_per_EM )
151 glyphToFontHeight = GetFace()->height / GetFace()->units_per_EM;
152
153 return aFontMetrics.GetInterline( aGlyphHeight * glyphToFontHeight );
154}
155
156
157static bool contourIsFilled( const CONTOUR& c )
158{
159 switch( c.m_Orientation )
160 {
161 case FT_ORIENTATION_TRUETYPE: return c.m_Winding == 1;
162 case FT_ORIENTATION_POSTSCRIPT: return c.m_Winding == -1;
163 default: return false;
164 }
165}
166
167
168static bool contourIsHole( const CONTOUR& c )
169{
170 return !contourIsFilled( c );
171}
172
173
174BOX2I OUTLINE_FONT::getBoundingBox( const std::vector<std::unique_ptr<GLYPH>>& aGlyphs ) const
175{
176 int minX = INT_MAX;
177 int minY = INT_MAX;
178 int maxX = INT_MIN;
179 int maxY = INT_MIN;
180
181 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
182 {
183 BOX2D bbox = glyph->BoundingBox();
184 bbox.Normalize();
185
186 if( minX > bbox.GetX() )
187 minX = bbox.GetX();
188
189 if( minY > bbox.GetY() )
190 minY = bbox.GetY();
191
192 if( maxX < bbox.GetRight() )
193 maxX = bbox.GetRight();
194
195 if( maxY < bbox.GetBottom() )
196 maxY = bbox.GetBottom();
197 }
198
199 BOX2I ret;
200 ret.SetOrigin( minX, minY );
201 ret.SetEnd( maxX, maxY );
202 return ret;
203}
204
205
206void OUTLINE_FONT::GetLinesAsGlyphs( std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
207 const wxString& aText, const VECTOR2I& aPosition,
208 const TEXT_ATTRIBUTES& aAttrs,
209 const METRICS& aFontMetrics ) const
210{
211 wxArrayString strings;
212 std::vector<VECTOR2I> positions;
213 std::vector<VECTOR2I> extents;
214 TEXT_STYLE_FLAGS textStyle = 0;
215
216 if( aAttrs.m_Italic )
217 textStyle |= TEXT_STYLE::ITALIC;
218
219 getLinePositions( aText, aPosition, strings, positions, extents, aAttrs, aFontMetrics );
220
221 for( size_t i = 0; i < strings.GetCount(); i++ )
222 {
223 (void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size,
224 aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle, aFontMetrics );
225 }
226}
227
228
229VECTOR2I OUTLINE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
230 const wxString& aText, const VECTOR2I& aSize,
231 const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
232 bool aMirror, const VECTOR2I& aOrigin,
233 TEXT_STYLE_FLAGS aTextStyle ) const
234{
235 // HarfBuzz needs further processing to split tab-delimited text into text runs.
236
237 constexpr double TAB_WIDTH = 4 * 0.6;
238
239 VECTOR2I position = aPosition;
240 wxString textRun;
241
242 if( aBBox )
243 {
244 aBBox->SetOrigin( aPosition );
245 aBBox->SetEnd( aPosition );
246 }
247
248 for( wxUniChar c : aText )
249 {
250 // Handle tabs as locked to the nearest 4th column (in space-widths).
251 if( c == '\t' )
252 {
253 if( !textRun.IsEmpty() )
254 {
255 position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle,
256 aMirror, aOrigin, aTextStyle );
257 textRun.clear();
258 }
259
260 int tabWidth = KiROUND( aSize.x * TAB_WIDTH );
261 int currentIntrusion = ( position.x - aOrigin.x ) % tabWidth;
262
263 position.x += tabWidth - currentIntrusion;
264 }
265 else
266 {
267 textRun += c;
268 }
269 }
270
271 if( !textRun.IsEmpty() )
272 {
273 position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle, aMirror,
274 aOrigin, aTextStyle );
275 }
276
277 return position;
278}
279
280
281VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
282 const wxString& aText, const VECTOR2I& aSize,
283 const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
284 bool aMirror, const VECTOR2I& aOrigin,
285 TEXT_STYLE_FLAGS aTextStyle ) const
286{
287 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
288
289 return getTextAsGlyphsUnlocked( aBBox, aGlyphs, aText, aSize, aPosition, aAngle, aMirror,
290 aOrigin, aTextStyle );
291}
292
293
295 FT_Face face;
296 hb_codepoint_t codepoint;
301 bool mirror;
304
305 bool operator==(const GLYPH_CACHE_KEY& rhs ) const
306 {
307 return face == rhs.face
308 && codepoint == rhs.codepoint
309 && scale == rhs.scale
310 && forDrawingSheet == rhs.forDrawingSheet
311 && fakeItalic == rhs.fakeItalic
312 && fakeBold == rhs.fakeBold
313 && mirror == rhs.mirror
314 && supersub == rhs.supersub
315 && angle == rhs.angle;
316 }
317};
318
319
320namespace std
321{
322 template <>
323 struct hash<GLYPH_CACHE_KEY>
324 {
325 std::size_t operator()( const GLYPH_CACHE_KEY& k ) const
326 {
327 return hash_val( k.face, k.codepoint, k.scale.x, k.scale.y, k.forDrawingSheet,
329 }
330 };
331}
332
333
335 std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
336 const wxString& aText, const VECTOR2I& aSize,
337 const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
338 bool aMirror, const VECTOR2I& aOrigin,
339 TEXT_STYLE_FLAGS aTextStyle ) const
340{
341 VECTOR2D glyphSize = aSize;
342 FT_Face face = m_face;
343 double scaler = faceSize();
344 bool supersub = IsSuperscript( aTextStyle ) || IsSubscript( aTextStyle );
345
346 if( supersub )
347 scaler = subscriptSize();
348
349 // set glyph resolution so that FT_Load_Glyph() results are good enough for decomposing
350 FT_Set_Char_Size( face, 0, scaler, GLYPH_RESOLUTION, 0 );
351
352 hb_buffer_t* buf = hb_buffer_create();
353 hb_buffer_add_utf8( buf, UTF8( aText ).c_str(), -1, 0, -1 );
354 hb_buffer_guess_segment_properties( buf ); // guess direction, script, and language based on
355 // contents
356
357 hb_font_t* referencedFont = hb_ft_font_create_referenced( face );
358 hb_ft_font_set_funcs( referencedFont );
359 hb_shape( referencedFont, buf, nullptr, 0 );
360
361 unsigned int glyphCount;
362 hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
363 hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
364
365 VECTOR2D scaleFactor( glyphSize.x / faceSize(), -glyphSize.y / faceSize() );
366 scaleFactor = scaleFactor * m_outlineFontSizeCompensation;
367
368 VECTOR2I cursor( 0, 0 );
369
370 if( aGlyphs )
371 aGlyphs->reserve( glyphCount );
372
373 // GLYPH_DATA is a collection of all outlines in the glyph; for example the 'o' glyph
374 // generally contains 2 contours, one for the glyph outline and one for the hole
375 static std::unordered_map<GLYPH_CACHE_KEY, GLYPH_DATA> s_glyphCache;
376
377 for( unsigned int i = 0; i < glyphCount; i++ )
378 {
379 // Don't process glyphs that were already included in a previous cluster
380 if( i > 0 && glyphInfo[i].cluster == glyphInfo[i-1].cluster )
381 continue;
382
383 if( aGlyphs )
384 {
385 GLYPH_CACHE_KEY key = { face, glyphInfo[i].codepoint, scaleFactor, m_forDrawingSheet,
386 m_fakeItal, m_fakeBold, aMirror, supersub, aAngle };
387 GLYPH_DATA& glyphData = s_glyphCache[ key ];
388
389 if( glyphData.m_Contours.empty() )
390 {
391 if( m_fakeItal )
392 {
393 FT_Matrix matrix;
394 // Create a 12 degree slant
395 const float angle = (float)( -M_PI * 12.0f ) / 180.0f;
396 matrix.xx = (FT_Fixed) ( cos( angle ) * 0x10000L );
397 matrix.xy = (FT_Fixed) ( -sin( angle ) * 0x10000L );
398 matrix.yx = (FT_Fixed) ( 0 * 0x10000L ); // Don't rotate in the y direction
399 matrix.yy = (FT_Fixed) ( 1 * 0x10000L );
400
401 FT_Set_Transform( face, &matrix, nullptr );
402 }
403
404 FT_Load_Glyph( face, glyphInfo[i].codepoint, FT_LOAD_NO_BITMAP );
405
406 if( m_fakeBold )
407 FT_Outline_Embolden( &face->glyph->outline, 1 << 6 );
408
409 OUTLINE_DECOMPOSER decomposer( face->glyph->outline );
410
411 if( !decomposer.OutlineToSegments( &glyphData.m_Contours ) )
412 {
413 double hb_advance = glyphPos[i].x_advance * GLYPH_SIZE_SCALER;
414 BOX2D tofuBox( { scaler * 0.03, 0.0 },
415 { hb_advance - scaler * 0.02, scaler * 0.72 } );
416
417 glyphData.m_Contours.clear();
418
419 CONTOUR outline;
420 outline.m_Winding = 1;
421 outline.m_Orientation = FT_ORIENTATION_TRUETYPE;
422 outline.m_Points.push_back( tofuBox.GetPosition() );
423 outline.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
424 outline.m_Points.push_back( tofuBox.GetSize() );
425 outline.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
426 glyphData.m_Contours.push_back( outline );
427
428 CONTOUR hole;
429 tofuBox.Move( { scaler * 0.06, scaler * 0.06 } );
430 tofuBox.SetSize( { tofuBox.GetWidth() - scaler * 0.06,
431 tofuBox.GetHeight() - scaler * 0.06 } );
432 hole.m_Winding = 1;
433 hole.m_Orientation = FT_ORIENTATION_NONE;
434 hole.m_Points.push_back( tofuBox.GetPosition() );
435 hole.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
436 hole.m_Points.push_back( tofuBox.GetSize() );
437 hole.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
438 glyphData.m_Contours.push_back( hole );
439 }
440 }
441
442 std::unique_ptr<OUTLINE_GLYPH> glyph = std::make_unique<OUTLINE_GLYPH>();
443 std::vector<SHAPE_LINE_CHAIN> holes;
444
445 for( CONTOUR& c : glyphData.m_Contours )
446 {
447 std::vector<VECTOR2D> points = c.m_Points;
448 SHAPE_LINE_CHAIN shape;
449
450 shape.ReservePoints( points.size() );
451
452 for( const VECTOR2D& v : points )
453 {
454 VECTOR2D pt( v + cursor );
455
456 if( IsSubscript( aTextStyle ) )
457 pt.y += m_subscriptVerticalOffset * scaler;
458 else if( IsSuperscript( aTextStyle ) )
459 pt.y += m_superscriptVerticalOffset * scaler;
460
461 pt *= scaleFactor;
462 pt += aPosition;
463
464 if( aMirror )
465 pt.x = aOrigin.x - ( pt.x - aOrigin.x );
466
467 if( !aAngle.IsZero() )
468 RotatePoint( pt, aOrigin, aAngle );
469
470 shape.Append( pt.x, pt.y );
471 }
472
473 shape.SetClosed( true );
474
475 if( contourIsHole( c ) )
476 holes.push_back( std::move( shape ) );
477 else
478 glyph->AddOutline( std::move( shape ) );
479 }
480
481 for( SHAPE_LINE_CHAIN& hole : holes )
482 {
483 bool added_hole = false;
484
485 if( hole.PointCount() )
486 {
487 for( int ii = 0; ii < glyph->OutlineCount(); ++ii )
488 {
489 if( glyph->Outline( ii ).PointInside( hole.GetPoint( 0 ) ) )
490 {
491 glyph->AddHole( std::move( hole ), ii );
492 added_hole = true;
493 break;
494 }
495 }
496
497 // Some lovely TTF fonts decided that winding didn't matter for outlines that
498 // don't have holes, so holes that don't fit in any outline are added as
499 // outlines.
500 if( !added_hole )
501 glyph->AddOutline( std::move( hole ) );
502 }
503 }
504
505 if( glyphData.m_TriangulationData.empty() )
506 {
507 glyph->CacheTriangulation( false, false );
508 glyphData.m_TriangulationData = glyph->GetTriangulationData();
509 }
510 else
511 {
512 glyph->CacheTriangulation( glyphData.m_TriangulationData );
513 }
514
515 aGlyphs->push_back( std::move( glyph ) );
516 }
517
518 hb_glyph_position_t& pos = glyphPos[i];
519 cursor.x += ( pos.x_advance * GLYPH_SIZE_SCALER );
520 cursor.y += ( pos.y_advance * GLYPH_SIZE_SCALER );
521 }
522
523 int ascender = abs( face->size->metrics.ascender * GLYPH_SIZE_SCALER );
524 int descender = abs( face->size->metrics.descender * GLYPH_SIZE_SCALER );
525 VECTOR2I extents( cursor.x * scaleFactor.x, ( ascender + descender ) * abs( scaleFactor.y ) );
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}
537
538
539#undef OUTLINEFONT_RENDER_AS_PIXELS
540#ifdef OUTLINEFONT_RENDER_AS_PIXELS
541/*
542 * WIP: Eeschema (and PDF output?) should use pixel rendering instead of linear segmentation
543 */
544void OUTLINE_FONT::RenderToOpenGLCanvas( KIGFX::OPENGL_GAL& aGal, const wxString& aString,
545 const VECTOR2D& aGlyphSize, const VECTOR2I& aPosition,
546 const EDA_ANGLE& aOrientation, bool aIsMirrored ) const
547{
548 hb_buffer_t* buf = hb_buffer_create();
549 hb_buffer_add_utf8( buf, UTF8( aString ).c_str(), -1, 0, -1 );
550
551 // guess direction, script, and language based on contents
552 hb_buffer_guess_segment_properties( buf );
553
554 unsigned int glyphCount;
555 hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
556 hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
557
558 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
559
560 hb_font_t* referencedFont = hb_ft_font_create_referenced( m_face );
561
562 hb_ft_font_set_funcs( referencedFont );
563 hb_shape( referencedFont, buf, nullptr, 0 );
564
565 const double mirror_factor = ( aIsMirrored ? 1 : -1 );
566 const double x_scaleFactor = mirror_factor * aGlyphSize.x / mScaler;
567 const double y_scaleFactor = aGlyphSize.y / mScaler;
568
569 hb_position_t cursor_x = 0;
570 hb_position_t cursor_y = 0;
571
572 for( unsigned int i = 0; i < glyphCount; i++ )
573 {
574 hb_glyph_position_t& pos = glyphPos[i];
575 int codepoint = glyphInfo[i].codepoint;
576
577 FT_Error e = FT_Load_Glyph( m_face, codepoint, FT_LOAD_DEFAULT );
578 // TODO handle FT_Load_Glyph error
579
580 FT_Glyph glyph;
581 e = FT_Get_Glyph( m_face->glyph, &glyph );
582 // TODO handle FT_Get_Glyph error
583
584 wxPoint pt( aPosition );
585 pt.x += ( cursor_x >> 6 ) * x_scaleFactor;
586 pt.y += ( cursor_y >> 6 ) * y_scaleFactor;
587
588 cursor_x += pos.x_advance;
589 cursor_y += pos.y_advance;
590 }
591
592 hb_buffer_destroy( buf );
593}
594
595#endif //OUTLINEFONT_RENDER_AS_PIXELS
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:146
constexpr coord_type GetY() const
Definition: box2.h:208
constexpr coord_type GetX() const
Definition: box2.h:207
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 coord_type GetRight() const
Definition: box2.h:217
constexpr void SetEnd(coord_type x, coord_type y)
Definition: box2.h:297
constexpr coord_type GetBottom() const
Definition: box2.h:222
double AsDegrees() const
Definition: eda_angle.h:113
bool IsZero() const
Definition: eda_angle.h:133
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
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
double GetInterline(double aFontHeight) const
Definition: font.h:114
bool OutlineToSegments(std::vector< CONTOUR > *aContours)
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:53
VECTOR2I getTextAsGlyphsUnlocked(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
static std::mutex m_freeTypeMutex
Mutex for freetype access, FT_Library and FT_Face are not thread safe.
Definition: outline_font.h:150
double GetInterline(double aGlyphHeight, const METRICS &aFontMetrics) const override
Compute the distance (interline) between 2 lines of text (for multiline texts).
static FT_Library m_freeType
Definition: outline_font.h:151
BOX2I getBoundingBox(const std::vector< std::unique_ptr< GLYPH > > &aGlyphs) const
FT_Error loadFace(const wxString &aFontFileName, int aFaceIndex)
static constexpr double m_superscriptVerticalOffset
Definition: outline_font.h:198
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
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.
const FT_Face & GetFace() const
Definition: outline_font.h:118
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) const
static OUTLINE_FONT * LoadFont(const wxString &aFontFileName, bool aBold, bool aItalic, const std::vector< wxString > *aEmbeddedFiles, bool aForDrawingSheet)
Load an outline font.
int faceSize() const
Definition: outline_font.h:188
static constexpr double m_outlineFontSizeCompensation
Definition: outline_font.h:169
EMBEDDING_PERMISSION GetEmbeddingPermission() const
int subscriptSize() const
Definition: outline_font.h:195
static constexpr double m_subscriptVerticalOffset
Definition: outline_font.h:197
OpenGL implementation of the Graphics Abstraction Layer.
Definition: opengl_gal.h:71
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 ReservePoints(size_t aSize)
Allocate a number of points all at once (for performance).
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:72
unsigned int TEXT_STYLE_FLAGS
Definition: font.h:64
bool IsSuperscript(TEXT_STYLE_FLAGS aFlags)
Definition: font.h:79
bool IsSubscript(TEXT_STYLE_FLAGS aFlags)
Definition: font.h:85
FONTCONFIG * Fontconfig()
Definition: fontconfig.cpp:104
static constexpr std::size_t hash_val(const Types &... args)
Definition: hash.h:51
constexpr int GLYPH_RESOLUTION
constexpr double GLYPH_SIZE_SCALER
STL namespace.
static bool contourIsHole(const CONTOUR &c)
static bool contourIsFilled(const CONTOUR &c)
const int scale
hb_codepoint_t codepoint
bool operator==(const GLYPH_CACHE_KEY &rhs) const
std::vector< VECTOR2D > m_Points
FT_Orientation m_Orientation
std::vector< CONTOUR > m_Contours
std::vector< std::unique_ptr< SHAPE_POLY_SET::TRIANGULATED_POLYGON > > m_TriangulationData
std::size_t operator()(const GLYPH_CACHE_KEY &k) const
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:229
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695