12 const std::shared_ptr<TypefaceSTB>& typeface_stb,
14 const std::string&
text) {
20 float scale = stbtt_ScaleForMappingEmToPixels(
21 typeface_stb->GetFontInfo(),
24 int ascent, descent, line_gap;
25 stbtt_GetFontVMetrics(typeface_stb->GetFontInfo(), &ascent, &descent,
27 ascent = std::round(ascent *
scale);
28 descent = std::round(descent *
scale);
31 for (
size_t i = 0; i <
text.size(); i++) {
33 stbtt_FindGlyphIndex(typeface_stb->GetFontInfo(),
text[i]);
36 stbtt_GetGlyphBitmapBox(typeface_stb->GetFontInfo(), glyph_index,
scale,
37 scale, &x0, &y0, &x1, &y1);
41 int left_side_bearing;
42 stbtt_GetGlyphHMetrics(typeface_stb->GetFontInfo(), glyph_index,
43 &advance_width, &left_side_bearing);
45 Glyph glyph(glyph_index, Glyph::Type::kPath,
47 run.AddGlyph(glyph, {
x + (left_side_bearing *
scale),
y});
49 if (i + 1 <
text.size()) {
50 int kerning = stbtt_GetCodepointKernAdvance(typeface_stb->GetFontInfo(),
52 x += std::round((advance_width + kerning) *
scale);
56 std::optional<Rect>
result;
57 for (
const auto& glyph_position :
run.GetGlyphPositions()) {
59 glyph_position.position + glyph_position.glyph.bounds.GetOrigin(),
60 glyph_position.glyph.bounds.GetSize());
64 std::vector<TextRun> runs = {
run};
65 return std::make_shared<TextFrame>(
Represents a collection of positioned glyphs from a specific font.