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 // We don't support bitmap fonts, so this disables embedding
70 if( os2->fsType & FT_FSTYPE_BITMAP_EMBEDDING_ONLY )
72
73 // Per the OpenType spec, only bits 0-3 of fsType define the embedding license.
74 // Bits 8-9 (no-subsetting, bitmap-only) are independent modifiers and must be
75 // masked off before checking the embedding permission level.
76 // See: http://freetype.org/freetype2/docs/reference/ft2-information_retrieval.html
77 FT_UShort embeddingBits = os2->fsType & 0x000F;
78
79 // This allows the font to be exported from KiCad
80 if( embeddingBits == FT_FSTYPE_INSTALLABLE_EMBEDDING )
82
83 // This allows us to use the font in KiCad but not export
84 if( embeddingBits & FT_FSTYPE_EDITABLE_EMBEDDING )
86
87 // This is not actually supported by KiCad ATM(2024)
88 if( embeddingBits & FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING )
90
91 // Anything else that is not explicitly enabled we treat as restricted.
93}
94
95
96OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, bool aItalic,
97 const std::vector<wxString>* aEmbeddedFiles,
98 bool aForDrawingSheet )
99{
100 std::unique_ptr<OUTLINE_FONT> font = std::make_unique<OUTLINE_FONT>();
101
102 wxString fontFile;
103 int faceIndex;
104 using fc = fontconfig::FONTCONFIG;
105
106
107 fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, faceIndex, aBold, aItalic,
108 aEmbeddedFiles );
109
110 if( retval == fc::FF_RESULT::FF_ERROR )
111 return nullptr;
112
113 if( retval == fc::FF_RESULT::FF_MISSING_BOLD || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
114 font->SetFakeBold();
115
116 if( retval == fc::FF_RESULT::FF_MISSING_ITAL || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
117 font->SetFakeItal();
118
119 if( font->loadFace( fontFile, faceIndex ) != 0 )
120 return nullptr;
121
122 font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
123 font->m_fontFileName = fontFile;
124 font->m_forDrawingSheet = aForDrawingSheet;
125
126 return font.release();
127}
128
129
130FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName, int aFaceIndex )
131{
132 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
133
134 FT_Error e = FT_New_Face( m_freeType, aFontFileName.mb_str( wxConvUTF8 ), aFaceIndex, &m_face );
135
136 if( !e )
137 {
138 FT_Select_Charmap( m_face, FT_Encoding::FT_ENCODING_UNICODE );
139 // params:
140 // m_face = handle to face object
141 // 0 = char width in 1/64th of points ( 0 = same as char height )
142 // faceSize() = char height in 1/64th of points
143 // GLYPH_RESOLUTION = horizontal device resolution (1152dpi, 16x default)
144 // 0 = vertical device resolution ( 0 = same as horizontal )
145 FT_Set_Char_Size( m_face, 0, faceSize(), GLYPH_RESOLUTION, 0 );
146 }
147
148 return e;
149}
150
151
152double OUTLINE_FONT::GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const
153{
154 double glyphToFontHeight = 1.0;
155
156 if( GetFace()->units_per_EM )
157 glyphToFontHeight = GetFace()->height / GetFace()->units_per_EM;
158
159 return aFontMetrics.GetInterline( aGlyphHeight * glyphToFontHeight );
160}
161
162
163static bool contourIsFilled( const CONTOUR& c )
164{
165 switch( c.m_Orientation )
166 {
167 case FT_ORIENTATION_TRUETYPE: return c.m_Winding == 1;
168 case FT_ORIENTATION_POSTSCRIPT: return c.m_Winding == -1;
169 default: return false;
170 }
171}
172
173
174static bool contourIsHole( const CONTOUR& c )
175{
176 return !contourIsFilled( c );
177}
178
179
180BOX2I OUTLINE_FONT::getBoundingBox( const std::vector<std::unique_ptr<GLYPH>>& aGlyphs ) const
181{
182 int minX = INT_MAX;
183 int minY = INT_MAX;
184 int maxX = INT_MIN;
185 int maxY = INT_MIN;
186
187 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
188 {
189 BOX2D bbox = glyph->BoundingBox();
190 bbox.Normalize();
191
192 if( minX > bbox.GetX() )
193 minX = bbox.GetX();
194
195 if( minY > bbox.GetY() )
196 minY = bbox.GetY();
197
198 if( maxX < bbox.GetRight() )
199 maxX = bbox.GetRight();
200
201 if( maxY < bbox.GetBottom() )
202 maxY = bbox.GetBottom();
203 }
204
205 BOX2I ret;
206 ret.SetOrigin( minX, minY );
207 ret.SetEnd( maxX, maxY );
208 return ret;
209}
210
211
212void OUTLINE_FONT::GetLinesAsGlyphs( std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
213 const wxString& aText, const VECTOR2I& aPosition,
214 const TEXT_ATTRIBUTES& aAttrs,
215 const METRICS& aFontMetrics ) const
216{
217 wxArrayString strings;
218 std::vector<VECTOR2I> positions;
219 std::vector<VECTOR2I> extents;
220 TEXT_STYLE_FLAGS textStyle = 0;
221
222 if( aAttrs.m_Italic )
223 textStyle |= TEXT_STYLE::ITALIC;
224
225 getLinePositions( aText, aPosition, strings, positions, extents, aAttrs, aFontMetrics );
226
227 for( size_t i = 0; i < strings.GetCount(); i++ )
228 {
229 (void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size,
230 aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle, aFontMetrics );
231 }
232}
233
234
235VECTOR2I OUTLINE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
236 const wxString& aText, const VECTOR2I& aSize,
237 const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
238 bool aMirror, const VECTOR2I& aOrigin,
239 TEXT_STYLE_FLAGS aTextStyle ) const
240{
241 // HarfBuzz needs further processing to split tab-delimited text into text runs.
242
243 constexpr double TAB_WIDTH = 4 * 0.6;
244
245 VECTOR2I position = aPosition;
246 wxString textRun;
247
248 if( aBBox )
249 {
250 aBBox->SetOrigin( aPosition );
251 aBBox->SetEnd( aPosition );
252 }
253
254 for( wxUniChar c : aText )
255 {
256 // Handle tabs as locked to the nearest 4th column (in space-widths).
257 if( c == '\t' )
258 {
259 if( !textRun.IsEmpty() )
260 {
261 position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle,
262 aMirror, aOrigin, aTextStyle );
263 textRun.clear();
264 }
265
266 int tabWidth = KiROUND( aSize.x * TAB_WIDTH );
267 int currentIntrusion = ( position.x - aOrigin.x ) % tabWidth;
268
269 position.x += tabWidth - currentIntrusion;
270 }
271 else
272 {
273 textRun += c;
274 }
275 }
276
277 if( !textRun.IsEmpty() )
278 {
279 position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle, aMirror,
280 aOrigin, aTextStyle );
281 }
282
283 return position;
284}
285
286
287VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
288 const wxString& aText, const VECTOR2I& aSize,
289 const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
290 bool aMirror, const VECTOR2I& aOrigin,
291 TEXT_STYLE_FLAGS aTextStyle ) const
292{
293 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
294
295 return getTextAsGlyphsUnlocked( aBBox, aGlyphs, aText, aSize, aPosition, aAngle, aMirror,
296 aOrigin, aTextStyle );
297}
298
299
301 FT_Face face;
302 std::string text;
304
305 bool operator==(const HARFBUZZ_CACHE_KEY& rhs ) const
306 {
307 return face == rhs.face
308 && scaler == rhs.scaler
309 && text == rhs.text;
310 }
311};
312
313
315{
316 std::vector<hb_glyph_info_t> m_GlyphInfo;
317 std::vector<hb_glyph_position_t> m_GlyphPositions;
318 bool m_Initialized = false;
319};
320
321
322namespace std
323{
324 template <>
326 {
327 std::size_t operator()( const HARFBUZZ_CACHE_KEY& k ) const
328 {
329 return hash_val( k.face, k.scaler, k.text );
330 }
331 };
332}
333
334
335static const HARFBUZZ_CACHE_ENTRY& getHarfbuzzShape( FT_Face aFace, const wxString& aText,
336 int aScaler )
337{
338 static std::unordered_map<HARFBUZZ_CACHE_KEY, HARFBUZZ_CACHE_ENTRY> s_harfbuzzCache;
339
340 std::string textUtf8 = UTF8( aText );
341 HARFBUZZ_CACHE_KEY key = { aFace, textUtf8, aScaler };
342
343 HARFBUZZ_CACHE_ENTRY& entry = s_harfbuzzCache[key];
344
345 if( !entry.m_Initialized )
346 {
347 hb_buffer_t* buf = hb_buffer_create();
348 hb_buffer_add_utf8( buf, textUtf8.c_str(), -1, 0, -1 );
349 hb_buffer_guess_segment_properties( buf ); // guess direction, script, and language based on
350 // contents
351
352 hb_font_t* referencedFont = hb_ft_font_create_referenced( aFace );
353
354 hb_shape( referencedFont, buf, nullptr, 0 );
355
356 unsigned int glyphCount;
357 hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
358 hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
359
360 entry.m_GlyphInfo.assign( glyphInfo, glyphInfo + glyphCount );
361 entry.m_GlyphPositions.assign( glyphPos, glyphPos + glyphCount );
362 entry.m_Initialized = true;
363
364 hb_buffer_destroy( buf );
365 hb_font_destroy( referencedFont );
366 }
367
368 return entry;
369}
370
371
373 FT_Face face;
374 hb_codepoint_t codepoint;
379 bool mirror;
382
383 bool operator==(const GLYPH_CACHE_KEY& rhs ) const
384 {
385 return face == rhs.face
386 && codepoint == rhs.codepoint
387 && scale == rhs.scale
389 && fakeItalic == rhs.fakeItalic
390 && fakeBold == rhs.fakeBold
391 && mirror == rhs.mirror
392 && supersub == rhs.supersub
393 && angle == rhs.angle;
394 }
395};
396
397
398namespace std
399{
400 template <>
401 struct hash<GLYPH_CACHE_KEY>
402 {
403 std::size_t operator()( const GLYPH_CACHE_KEY& k ) const
404 {
405 return hash_val( k.face, k.codepoint, k.scale.x, k.scale.y, k.forDrawingSheet,
407 }
408 };
409}
410
411
413 std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
414 const wxString& aText, const VECTOR2I& aSize,
415 const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
416 bool aMirror, const VECTOR2I& aOrigin,
417 TEXT_STYLE_FLAGS aTextStyle ) const
418{
419 VECTOR2D glyphSize = aSize;
420 FT_Face face = m_face;
421 double scaler = faceSize();
422 bool supersub = IsSuperscript( aTextStyle ) || IsSubscript( aTextStyle );
423
424 if( supersub )
425 scaler = subscriptSize();
426
427 // set glyph resolution so that FT_Load_Glyph() results are good enough for decomposing
428 FT_Set_Char_Size( face, 0, scaler, GLYPH_RESOLUTION, 0 );
429
430 const HARFBUZZ_CACHE_ENTRY& hbShape = getHarfbuzzShape( face, aText, scaler );
431
432 unsigned int glyphCount = static_cast<unsigned int>( hbShape.m_GlyphInfo.size() );
433 const hb_glyph_info_t* glyphInfo = hbShape.m_GlyphInfo.data();
434 const hb_glyph_position_t* glyphPos = hbShape.m_GlyphPositions.data();
435
436 VECTOR2D scaleFactor( glyphSize.x / faceSize(), -glyphSize.y / faceSize() );
437 scaleFactor = scaleFactor * m_outlineFontSizeCompensation;
438
439 VECTOR2I cursor( 0, 0 );
440
441 if( aGlyphs )
442 aGlyphs->reserve( glyphCount );
443
444 // GLYPH_DATA is a collection of all outlines in the glyph; for example the 'o' glyph
445 // generally contains 2 contours, one for the glyph outline and one for the hole
446 static std::unordered_map<GLYPH_CACHE_KEY, GLYPH_DATA> s_glyphCache;
447
448 for( unsigned int i = 0; i < glyphCount; i++ )
449 {
450 if( aGlyphs )
451 {
452 GLYPH_CACHE_KEY key = { face, glyphInfo[i].codepoint, scaleFactor, m_forDrawingSheet,
453 m_fakeItal, m_fakeBold, aMirror, supersub, aAngle };
454 GLYPH_DATA& glyphData = s_glyphCache[ key ];
455
456 if( glyphData.m_Contours.empty() )
457 {
458 if( m_fakeItal )
459 {
460 FT_Matrix matrix;
461 // Create a 12 degree slant
462 const float angle = (float)( -M_PI * 12.0f ) / 180.0f;
463 matrix.xx = (FT_Fixed) ( cos( angle ) * 0x10000L );
464 matrix.xy = (FT_Fixed) ( -sin( angle ) * 0x10000L );
465 matrix.yx = (FT_Fixed) ( 0 * 0x10000L ); // Don't rotate in the y direction
466 matrix.yy = (FT_Fixed) ( 1 * 0x10000L );
467
468 FT_Set_Transform( face, &matrix, nullptr );
469 }
470
471 FT_Load_Glyph( face, glyphInfo[i].codepoint, FT_LOAD_NO_BITMAP );
472
473 if( m_fakeBold )
474 FT_Outline_Embolden( &face->glyph->outline, 1 << 6 );
475
476 OUTLINE_DECOMPOSER decomposer( face->glyph->outline );
477
478 if( !decomposer.OutlineToSegments( &glyphData.m_Contours ) )
479 {
480 double hb_advance = glyphPos[i].x_advance * GLYPH_SIZE_SCALER;
481 BOX2D tofuBox( { scaler * 0.03, 0.0 },
482 { hb_advance - scaler * 0.02, scaler * 0.72 } );
483
484 glyphData.m_Contours.clear();
485
486 CONTOUR outline;
487 outline.m_Winding = 1;
488 outline.m_Orientation = FT_ORIENTATION_TRUETYPE;
489 outline.m_Points.push_back( tofuBox.GetPosition() );
490 outline.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
491 outline.m_Points.push_back( tofuBox.GetSize() );
492 outline.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
493 glyphData.m_Contours.push_back( std::move( outline ) );
494
495 CONTOUR hole;
496 tofuBox.Move( { scaler * 0.06, scaler * 0.06 } );
497 tofuBox.SetSize( { tofuBox.GetWidth() - scaler * 0.06,
498 tofuBox.GetHeight() - scaler * 0.06 } );
499 hole.m_Winding = 1;
500 hole.m_Orientation = FT_ORIENTATION_NONE;
501 hole.m_Points.push_back( tofuBox.GetPosition() );
502 hole.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
503 hole.m_Points.push_back( tofuBox.GetSize() );
504 hole.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
505 glyphData.m_Contours.push_back( std::move( hole ) );
506 }
507 }
508
509 std::unique_ptr<OUTLINE_GLYPH> glyph = std::make_unique<OUTLINE_GLYPH>();
510 std::vector<SHAPE_LINE_CHAIN> holes;
511
512 for( CONTOUR& c : glyphData.m_Contours )
513 {
514 std::vector<VECTOR2D> points = c.m_Points;
515 SHAPE_LINE_CHAIN shape;
516
517 shape.ReservePoints( points.size() );
518
519 for( const VECTOR2D& v : points )
520 {
521 VECTOR2D pt( v + cursor );
522
523 if( IsSubscript( aTextStyle ) )
524 pt.y += m_subscriptVerticalOffset * scaler;
525 else if( IsSuperscript( aTextStyle ) )
526 pt.y += m_superscriptVerticalOffset * scaler;
527
528 pt *= scaleFactor;
529 pt += aPosition;
530
531 if( aMirror )
532 pt.x = aOrigin.x - ( pt.x - aOrigin.x );
533
534 if( !aAngle.IsZero() )
535 RotatePoint( pt, aOrigin, aAngle );
536
537 shape.Append( pt.x, pt.y );
538 }
539
540 shape.SetClosed( true );
541
542 if( contourIsHole( c ) )
543 holes.push_back( std::move( shape ) );
544 else
545 glyph->AddOutline( std::move( shape ) );
546 }
547
548 for( SHAPE_LINE_CHAIN& hole : holes )
549 {
550 bool added_hole = false;
551
552 if( hole.PointCount() )
553 {
554 for( int ii = 0; ii < glyph->OutlineCount(); ++ii )
555 {
556 if( glyph->Outline( ii ).PointInside( hole.GetPoint( 0 ) ) )
557 {
558 glyph->AddHole( std::move( hole ), ii );
559 added_hole = true;
560 break;
561 }
562 }
563
564 // Some lovely TTF fonts decided that winding didn't matter for outlines that
565 // don't have holes, so holes that don't fit in any outline are added as
566 // outlines.
567 if( !added_hole )
568 glyph->AddOutline( std::move( hole ) );
569 }
570 }
571
572 if( glyphData.m_TriangulationData.empty() )
573 {
574 glyph->CacheTriangulation( false, false );
575 glyphData.m_TriangulationData = glyph->GetTriangulationData();
576 }
577 else
578 {
579 glyph->CacheTriangulation( glyphData.m_TriangulationData );
580 }
581
582 aGlyphs->push_back( std::move( glyph ) );
583 }
584
585 const hb_glyph_position_t& pos = glyphPos[i];
586 cursor.x += ( pos.x_advance * GLYPH_SIZE_SCALER );
587 cursor.y += ( pos.y_advance * GLYPH_SIZE_SCALER );
588 }
589
590 int ascender = abs( face->size->metrics.ascender * GLYPH_SIZE_SCALER );
591 int descender = abs( face->size->metrics.descender * GLYPH_SIZE_SCALER );
592
593 if( aBBox )
594 {
595 aBBox->Merge( aPosition - VECTOR2I( 0, ascender * abs( scaleFactor.y ) ) );
596 aBBox->Merge( aPosition + VECTOR2I( cursor.x * scaleFactor.x, descender * abs( scaleFactor.y ) ) );
597 }
598
599 return VECTOR2I( aPosition.x + cursor.x * scaleFactor.x, aPosition.y - cursor.y * scaleFactor.y );
600}
601
602
603#undef OUTLINEFONT_RENDER_AS_PIXELS
604#ifdef OUTLINEFONT_RENDER_AS_PIXELS
605/*
606 * WIP: Eeschema (and PDF output?) should use pixel rendering instead of linear segmentation
607 */
608void OUTLINE_FONT::RenderToOpenGLCanvas( KIGFX::OPENGL_GAL& aGal, const wxString& aString,
609 const VECTOR2D& aGlyphSize, const VECTOR2I& aPosition,
610 const EDA_ANGLE& aOrientation, bool aIsMirrored ) const
611{
612 hb_buffer_t* buf = hb_buffer_create();
613 hb_buffer_add_utf8( buf, UTF8( aString ).c_str(), -1, 0, -1 );
614
615 // guess direction, script, and language based on contents
616 hb_buffer_guess_segment_properties( buf );
617
618 unsigned int glyphCount;
619 hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
620 hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
621
622 std::lock_guard<std::mutex> guard( m_freeTypeMutex );
623
624 hb_font_t* referencedFont = hb_ft_font_create_referenced( m_face );
625
626 hb_shape( referencedFont, buf, nullptr, 0 );
627
628 const double mirror_factor = ( aIsMirrored ? 1 : -1 );
629 const double x_scaleFactor = mirror_factor * aGlyphSize.x / mScaler;
630 const double y_scaleFactor = aGlyphSize.y / mScaler;
631
632 hb_position_t cursor_x = 0;
633 hb_position_t cursor_y = 0;
634
635 for( unsigned int i = 0; i < glyphCount; i++ )
636 {
637 const hb_glyph_position_t& pos = glyphPos[i];
638 int codepoint = glyphInfo[i].codepoint;
639
640 FT_Error e = FT_Load_Glyph( m_face, codepoint, FT_LOAD_DEFAULT );
641 // TODO handle FT_Load_Glyph error
642
643 FT_Glyph glyph;
644 e = FT_Get_Glyph( m_face->glyph, &glyph );
645 // TODO handle FT_Get_Glyph error
646
647 wxPoint pt( aPosition );
648 pt.x += ( cursor_x >> 6 ) * x_scaleFactor;
649 pt.y += ( cursor_y >> 6 ) * y_scaleFactor;
650
651 cursor_x += pos.x_advance;
652 cursor_y += pos.y_advance;
653 }
654
655 hb_buffer_destroy( buf );
656}
657
658#endif //OUTLINEFONT_RENDER_AS_PIXELS
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
BOX2< VECTOR2D > BOX2D
Definition box2.h:923
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:116
bool IsZero() const
Definition eda_angle.h:136
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, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) const
Definition font.cpp:392
double GetInterline(double aFontHeight) const
bool OutlineToSegments(std::vector< CONTOUR > *aContours)
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.
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
BOX2I getBoundingBox(const std::vector< std::unique_ptr< GLYPH > > &aGlyphs) const
FT_Error loadFace(const wxString &aFontFileName, int aFaceIndex)
static constexpr double m_superscriptVerticalOffset
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
int faceSize(int aSize) const
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.
static constexpr double m_outlineFontSizeCompensation
EMBEDDING_PERMISSION GetEmbeddingPermission() const
int subscriptSize() const
static constexpr double m_subscriptVerticalOffset
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:71
FF_RESULT FindFont(const wxString &aFontName, wxString &aFontFile, int &aFaceIndex, bool aBold, bool aItalic, const std::vector< wxString > *aEmbeddedFiles=nullptr)
Given a fully-qualified font name ("Times:Bold:Italic") find the closest matching font and return its...
@ ITALIC
Definition font.h:48
unsigned int TEXT_STYLE_FLAGS
Definition font.h:65
bool IsSuperscript(TEXT_STYLE_FLAGS aFlags)
Definition font.h:80
bool IsSubscript(TEXT_STYLE_FLAGS aFlags)
Definition font.h:86
FONTCONFIG * Fontconfig()
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)
static const HARFBUZZ_CACHE_ENTRY & getHarfbuzzShape(FT_Face aFace, const wxString &aText, int aScaler)
hb_codepoint_t codepoint
bool operator==(const GLYPH_CACHE_KEY &rhs) const
std::vector< hb_glyph_info_t > m_GlyphInfo
std::vector< hb_glyph_position_t > m_GlyphPositions
bool m_Initialized
bool operator==(const HARFBUZZ_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
std::size_t operator()(const HARFBUZZ_CACHE_KEY &k) const
#define M_PI
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
VECTOR2< double > VECTOR2D
Definition vector2d.h:694