MCPcopy Create free account
hub / github.com/SFML/SFML / loadGlyph

Method loadGlyph

src/SFML/Graphics/Font.cpp:528–688  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

526
527////////////////////////////////////////////////////////////
528Glyph Font::loadGlyph(std::uint32_t id, unsigned int characterSize, bool bold, float outlineThickness) const
529{
530 // The glyph to return
531 Glyph glyph;
532
533 // Stop if no font is loaded
534 if (!m_fontHandles)
535 return glyph;
536
537 // Get our FT_Face
538 FT_Face face = m_fontHandles->face;
539 if (!face)
540 return glyph;
541
542 // Set the character size
543 if (!setCurrentSize(characterSize))
544 return glyph;
545
546 // Load the glyph corresponding to the code point
547 FT_Int32 flags = FT_LOAD_TARGET_NORMAL;
548 if (outlineThickness != 0)
549 flags |= FT_LOAD_NO_BITMAP;
550 if (FT_Load_Glyph(face, id, flags) != 0)
551 return glyph;
552
553 // Retrieve the glyph
554 FT_Glyph glyphDesc = nullptr;
555 if (FT_Get_Glyph(face->glyph, &glyphDesc) != 0)
556 return glyph;
557
558 // Apply bold and outline (there is no fallback for outline) if necessary -- first technique using outline (highest quality)
559 const FT_Pos weight = 1 << 6;
560 const bool outline = (glyphDesc->format == FT_GLYPH_FORMAT_OUTLINE);
561 if (outline)
562 {
563 if (bold)
564 {
565 auto* outlineGlyph = reinterpret_cast<FT_OutlineGlyph>(glyphDesc);
566 FT_Outline_Embolden(&outlineGlyph->outline, weight);
567 }
568
569 if (outlineThickness != 0)
570 {
571 FT_Stroker stroker = m_fontHandles->stroker;
572
573 FT_Stroker_Set(stroker,
574 static_cast<FT_Fixed>(outlineThickness * float{1 << 6}),
575 FT_STROKER_LINECAP_ROUND,
576 FT_STROKER_LINEJOIN_ROUND,
577 0);
578 FT_Glyph_Stroke(&glyphDesc, stroker, true);
579 }
580 }
581
582 // Convert the glyph to a bitmap (i.e. rasterize it)
583 // Warning! After this line, do not read any data from glyphDesc directly, use
584 // bitmapGlyph.root to access the FT_Glyph data.
585 FT_Glyph_To_Bitmap(&glyphDesc, FT_RENDER_MODE_NORMAL, nullptr, 1);

Callers

nothing calls this directly

Calls 2

resizeMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected