12 const std::shared_ptr<TypefaceSTB>& typeface_stb,
14 const std::string&
text) {
20 float scale = stbtt_ScaleForMappingEmToPixels(
21 typeface_stb->GetFontInfo(),
25 stbtt_GetFontVMetrics(typeface_stb->GetFontInfo(), &
ascent, &
descent,
33 for (
size_t i = 0;
i <
text.size();
i++) {
35 stbtt_FindGlyphIndex(typeface_stb->GetFontInfo(),
text[
i]);
38 stbtt_GetGlyphBitmapBox(typeface_stb->GetFontInfo(), glyph_index,
scale,
39 scale, &x0, &y0, &x1, &y1);
43 int left_side_bearing;
44 stbtt_GetGlyphHMetrics(typeface_stb->GetFontInfo(), glyph_index,
45 &advance_width, &left_side_bearing);
49 run.AddGlyph(glyph, {
x + (left_side_bearing *
scale),
y});
51 if (
i + 1 <
text.size()) {
52 int kerning = stbtt_GetCodepointKernAdvance(typeface_stb->GetFontInfo(),
58 std::optional<Rect>
result;
59 for (
auto i = 0u;
i <
bounds.size();
i++) {
66 std::vector<TextRun> runs = {
run};
67 return std::make_shared<TextFrame>(
static void round(SkPoint *p)
Describes a typeface along with any modifications to its intrinsic properties.
Represents a collection of positioned glyphs from a specific font.
static constexpr float kPointsToPixels
Optional< SkRect > bounds
std::shared_ptr< TextFrame > MakeTextFrameSTB(const std::shared_ptr< TypefaceSTB > &typeface_stb, Font::Metrics metrics, const std::string &text)
Describes the modifications made to the intrinsic properties of a typeface.
The glyph index in the typeface.
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)