12 const std::shared_ptr<TypefaceSTB>& typeface_stb,
14 const std::string& text) {
20 float scale = stbtt_ScaleForPixelHeight(
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);
49 if (i + 1 < text.size()) {
50 int kerning = stbtt_GetCodepointKernAdvance(typeface_stb->GetFontInfo(),
51 text[i], text[i + 1]);
52 x += std::round((advance_width + kerning) *
scale);
56 std::optional<Rect> result;
59 glyph_position.position + glyph_position.glyph.bounds.GetOrigin(),
60 glyph_position.glyph.bounds.GetSize());
61 result = result.has_value() ? result->Union(glyph_rect) : glyph_rect;
64 std::vector<TextRun> runs = {run};
65 return std::make_shared<TextFrame>(