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 (C) 2021-2024 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 if( os2->fsType == FT_FSTYPE_INSTALLABLE_EMBEDDING ) // This allows the font to be exported from KiCad
71
72 if( os2->fsType & FT_FSTYPE_BITMAP_EMBEDDING_ONLY ) // We don't support bitmap fonts, so this disables embedding
74
75 if( os2->fsType & FT_FSTYPE_EDITABLE_EMBEDDING ) // This allows us to use the font in KiCad but not export
77
78 if( os2->fsType & FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING ) // This is not actually supported by KiCad ATM(2024)
80
81 // Anything else that is not explicitly enabled we treat as restricted.
83}
84
85
86OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, bool aItalic,
87 const std::vector<wxString>* aEmbeddedFiles,
88 bool aForDrawingSheet )
89{
90 std::unique_ptr<OUTLINE_FONT> font = std::make_unique<OUTLINE_FONT>();
91
92 wxString fontFile;
93 int faceIndex;
94 using fc = fontconfig::FONTCONFIG;
95
96
97 fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, faceIndex, aBold, aItalic,
98 aEmbeddedFiles );
99
100 if( retval == fc::FF_RESULT::FF_ERROR )
101 return nullptr;
102
103 if( retval == fc::FF_RESULT::FF_MISSING_BOLD || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
104 font->SetFakeBold();
105
106 if( retval == fc::FF_RESULT::FF_MISSING_ITAL || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
107 font->SetFakeItal();
108
109 if( font->loadFace( fontFile, faceIndex ) != 0 )
110 return nullptr;
111
112 font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
113 font->m_fontFileName = fontFile;
114 font->m_forDrawingSheet = aForDrawingSheet;
115
116 return font.release();
117}
118
119
120FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName, int aFaceIndex )
121{
122 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
123
124 FT_Error e = FT_New_Face( m_freeType, aFontFileName.mb_str( wxConvUTF8 ), aFaceIndex, &m_face );
125
126 if( !e )
127 {
128 FT_Select_Charmap( m_face, FT_Encoding::FT_ENCODING_UNICODE );
129 // params:
130 // m_face = handle to face object
131 // 0 = char width in 1/64th of points ( 0 = same as char height )
132 // faceSize() = char height in 1/64th of points
133 // GLYPH_RESOLUTION = horizontal device resolution (1152dpi, 16x default)
134 // 0 = vertical device resolution ( 0 = same as horizontal )
135 FT_Set_Char_Size( m_face, 0, faceSize(), GLYPH_RESOLUTION, 0 );
136 }
137
138 return e;
139}
140
141
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;
297 double scaler;
301 bool mirror;
303
304 bool operator==(const GLYPH_CACHE_KEY& rhs ) const
305 {
306 return face == rhs.face
307 && codepoint == rhs.codepoint
308 && scaler == rhs.scaler
309 && forDrawingSheet == rhs.forDrawingSheet
310 && fakeItalic == rhs.fakeItalic
311 && fakeBold == rhs.fakeBold
312 && mirror == rhs.mirror
313 && angle == rhs.angle;
314 }
315};
316
317namespace std
318{
319 template <>
320 struct hash<GLYPH_CACHE_KEY>
321 {
322 std::size_t operator()( const GLYPH_CACHE_KEY& k ) const
323 {
324 return hash<const void*>()( k.face )
325 ^ hash<unsigned>()( k.codepoint )
326 ^ hash<double>()( k.scaler )
327 ^ hash<double>()( k.forDrawingSheet )
328 ^ hash<int>()( k.fakeItalic )
329 ^ hash<int>()( k.fakeBold )
330 ^ hash<int>()( k.mirror )
331 ^ hash<int>()( k.angle.AsTenthsOfADegree() );
332 }
333 };
334}
335
336
338 std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
339 const wxString& aText, const VECTOR2I& aSize,
340 const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
341 bool aMirror, const VECTOR2I& aOrigin,
342 TEXT_STYLE_FLAGS aTextStyle ) const
343{
344 VECTOR2D glyphSize = aSize;
345 FT_Face face = m_face;
346 double scaler = faceSize();
347
348 if( IsSubscript( aTextStyle ) || IsSuperscript( aTextStyle ) )
349 {
350 scaler = subscriptSize();
351 }
352
353 // set glyph resolution so that FT_Load_Glyph() results are good enough for decomposing
354 FT_Set_Char_Size( face, 0, scaler, GLYPH_RESOLUTION, 0 );
355
356 hb_buffer_t* buf = hb_buffer_create();
357 hb_buffer_add_utf8( buf, UTF8( aText ).c_str(), -1, 0, -1 );
358 hb_buffer_guess_segment_properties( buf ); // guess direction, script, and language based on
359 // contents
360
361 hb_font_t* referencedFont = hb_ft_font_create_referenced( face );
362 hb_ft_font_set_funcs( referencedFont );
363 hb_shape( referencedFont, buf, nullptr, 0 );
364
365 unsigned int glyphCount;
366 hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
367 hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
368
369 VECTOR2D scaleFactor( glyphSize.x / faceSize(), -glyphSize.y / faceSize() );
370 scaleFactor = scaleFactor * m_outlineFontSizeCompensation;
371
372 VECTOR2I cursor( 0, 0 );
373
374 if( aGlyphs )
375 aGlyphs->reserve( glyphCount );
376
377 // GLYPH_DATA is a collection of all outlines in the glyph; for example the 'o' glyph
378 // generally contains 2 contours, one for the glyph outline and one for the hole
379 static std::unordered_map<GLYPH_CACHE_KEY, GLYPH_DATA> s_glyphCache;
380
381 for( unsigned int i = 0; i < glyphCount; i++ )
382 {
383 // Don't process glyphs that were already included in a previous cluster
384 if( i > 0 && glyphInfo[i].cluster == glyphInfo[i-1].cluster )
385 continue;
386
387 if( aGlyphs )
388 {
389 GLYPH_CACHE_KEY key = { face, glyphInfo[i].codepoint, scaler, m_forDrawingSheet,
390 m_fakeItal, m_fakeBold, aMirror, aAngle };
391 GLYPH_DATA& glyphData = s_glyphCache[ key ];
392
393 if( glyphData.m_Contours.empty() )
394 {
395 if( m_fakeItal )
396 {
397 FT_Matrix matrix;
398 // Create a 12 degree slant
399 const float angle = (float)( -M_PI * 12.0f ) / 180.0f;
400 matrix.xx = (FT_Fixed) ( cos( angle ) * 0x10000L );
401 matrix.xy = (FT_Fixed) ( -sin( angle ) * 0x10000L );
402 matrix.yx = (FT_Fixed) ( 0 * 0x10000L ); // Don't rotate in the y direction
403 matrix.yy = (FT_Fixed) ( 1 * 0x10000L );
404
405 FT_Set_Transform( face, &matrix, nullptr );
406 }
407
408 FT_Load_Glyph( face, glyphInfo[i].codepoint, FT_LOAD_NO_BITMAP );
409
410 if( m_fakeBold )
411 FT_Outline_Embolden( &face->glyph->outline, 1 << 6 );
412
413 OUTLINE_DECOMPOSER decomposer( face->glyph->outline );
414
415 if( !decomposer.OutlineToSegments( &glyphData.m_Contours ) )
416 {
417 double hb_advance = glyphPos[i].x_advance * GLYPH_SIZE_SCALER;
418 BOX2D tofuBox( { scaler * 0.03, 0.0 },
419 { hb_advance - scaler * 0.02, scaler * 0.72 } );
420
421 glyphData.m_Contours.clear();
422
423 CONTOUR outline;
424 outline.m_Winding = 1;
425 outline.m_Orientation = FT_ORIENTATION_TRUETYPE;
426 outline.m_Points.push_back( tofuBox.GetPosition() );
427 outline.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
428 outline.m_Points.push_back( tofuBox.GetSize() );
429 outline.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
430 glyphData.m_Contours.push_back( outline );
431
432 CONTOUR hole;
433 tofuBox.Move( { scaler * 0.06, scaler * 0.06 } );
434 tofuBox.SetSize( { tofuBox.GetWidth() - scaler * 0.06,
435 tofuBox.GetHeight() - scaler * 0.06 } );
436 hole.m_Winding = 1;
437 hole.m_Orientation = FT_ORIENTATION_NONE;
438 hole.m_Points.push_back( tofuBox.GetPosition() );
439 hole.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
440 hole.m_Points.push_back( tofuBox.GetSize() );
441 hole.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
442 glyphData.m_Contours.push_back( hole );
443 }
444 }
445
446 std::unique_ptr<OUTLINE_GLYPH> glyph = std::make_unique<OUTLINE_GLYPH>();
447 std::vector<SHAPE_LINE_CHAIN> holes;
448
449 for( CONTOUR& c : glyphData.m_Contours )
450 {
451 std::vector<VECTOR2D> points = c.m_Points;
452 SHAPE_LINE_CHAIN shape;
453
454 shape.ReservePoints( points.size() );
455
456 for( const VECTOR2D& v : points )
457 {
458 VECTOR2D pt( v + cursor );
459
460 if( IsSubscript( aTextStyle ) )
461 pt.y += m_subscriptVerticalOffset * scaler;
462 else if( IsSuperscript( aTextStyle ) )
463 pt.y += m_superscriptVerticalOffset * scaler;
464
465 pt *= scaleFactor;
466 pt += aPosition;
467
468 if( aMirror )
469 pt.x = aOrigin.x - ( pt.x - aOrigin.x );
470
471 if( !aAngle.IsZero() )
472 RotatePoint( pt, aOrigin, aAngle );
473
474 shape.Append( pt.x, pt.y );
475 }
476
477 shape.SetClosed( true );
478
479 if( contourIsHole( c ) )
480 holes.push_back( std::move( shape ) );
481 else
482 glyph->AddOutline( std::move( shape ) );
483 }
484
485 for( SHAPE_LINE_CHAIN& hole : holes )
486 {
487 bool added_hole = false;
488
489 if( hole.PointCount() )
490 {
491 for( int ii = 0; ii < glyph->OutlineCount(); ++ii )
492 {
493 if( glyph->Outline( ii ).PointInside( hole.GetPoint( 0 ) ) )
494 {
495 glyph->AddHole( std::move( hole ), ii );
496 added_hole = true;
497 break;
498 }
499 }
500
501 // Some lovely TTF fonts decided that winding didn't matter for outlines that
502 // don't have holes, so holes that don't fit in any outline are added as outlines
503 if( !added_hole )
504 glyph->AddOutline( std::move( hole ) );
505 }
506 }
507
508 if( glyphData.m_TriangulationData.empty() )
509 {
510 glyph->CacheTriangulation( false, false );
511 glyphData.m_TriangulationData = glyph->GetTriangulationData();
512 }
513 else
514 {
515 glyph->CacheTriangulation( glyphData.m_TriangulationData );
516 }
517
518 aGlyphs->push_back( std::move( glyph ) );
519 }
520
521 hb_glyph_position_t& pos = glyphPos[i];
522 cursor.x += ( pos.x_advance * GLYPH_SIZE_SCALER );
523 cursor.y += ( pos.y_advance * GLYPH_SIZE_SCALER );
524 }
525
526 int ascender = abs( face->size->metrics.ascender * GLYPH_SIZE_SCALER );
527 int descender = abs( face->size->metrics.descender * GLYPH_SIZE_SCALER );
528 VECTOR2I extents( cursor.x * scaleFactor.x, ( ascender + descender ) * abs( scaleFactor.y ) );
529
530 hb_buffer_destroy( buf );
531 hb_font_destroy( referencedFont );
532
533 VECTOR2I cursorDisplacement( cursor.x * scaleFactor.x, -cursor.y * scaleFactor.y );
534
535 if( aBBox )
536 aBBox->Merge( aPosition + extents );
537
538 return VECTOR2I( aPosition.x + cursorDisplacement.x, aPosition.y + cursorDisplacement.y );
539}
540
541
542#undef OUTLINEFONT_RENDER_AS_PIXELS
543#ifdef OUTLINEFONT_RENDER_AS_PIXELS
544/*
545 * WIP: eeschema (and PDF output?) should use pixel rendering instead of linear segmentation
546 */
547void OUTLINE_FONT::RenderToOpenGLCanvas( KIGFX::OPENGL_GAL& aGal, const wxString& aString,
548 const VECTOR2D& aGlyphSize, const VECTOR2I& aPosition,
549 const EDA_ANGLE& aOrientation, bool aIsMirrored ) const
550{
551 hb_buffer_t* buf = hb_buffer_create();
552 hb_buffer_add_utf8( buf, UTF8( aString ).c_str(), -1, 0, -1 );
553 hb_buffer_guess_segment_properties( buf ); // guess direction, script, and language based on contents
554
555 unsigned int glyphCount;
556 hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
557 hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
558
559 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
560
561 hb_font_t* referencedFont = hb_ft_font_create_referenced( m_face );
562
563 hb_ft_font_set_funcs( referencedFont );
564 hb_shape( referencedFont, buf, nullptr, 0 );
565
566 const double mirror_factor = ( aIsMirrored ? 1 : -1 );
567 const double x_scaleFactor = mirror_factor * aGlyphSize.x / mScaler;
568 const double y_scaleFactor = aGlyphSize.y / mScaler;
569
570 hb_position_t cursor_x = 0;
571 hb_position_t cursor_y = 0;
572
573 for( unsigned int i = 0; i < glyphCount; i++ )
574 {
575 hb_glyph_position_t& pos = glyphPos[i];
576 int codepoint = glyphInfo[i].codepoint;
577
578 FT_Error e = FT_Load_Glyph( m_face, codepoint, FT_LOAD_DEFAULT );
579 // TODO handle FT_Load_Glyph error
580
581 FT_Glyph glyph;
582 e = FT_Get_Glyph( m_face->glyph, &glyph );
583 // TODO handle FT_Get_Glyph error
584
585 wxPoint pt( aPosition );
586 pt.x += ( cursor_x >> 6 ) * x_scaleFactor;
587 pt.y += ( cursor_y >> 6 ) * y_scaleFactor;
588
589 cursor_x += pos.x_advance;
590 cursor_y += pos.y_advance;
591 }
592
593 hb_buffer_destroy( buf );
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
int AsTenthsOfADegree() const
Definition: eda_angle.h:115
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:179
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:384
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:148
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:149
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:195
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:116
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:185
static constexpr double m_outlineFontSizeCompensation
Definition: outline_font.h:167
EMBEDDING_PERMISSION GetEmbeddingPermission() const
int subscriptSize() const
Definition: outline_font.h:192
static constexpr double m_subscriptVerticalOffset
Definition: outline_font.h:194
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:100
constexpr int GLYPH_RESOLUTION
constexpr double GLYPH_SIZE_SCALER
STL namespace.
static bool contourIsHole(const CONTOUR &c)
static bool contourIsFilled(const CONTOUR &c)
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:691