diff --git a/text/skia_font.cpp b/text/skia_font.cpp index 0afaf13c1..ee93cf87f 100644 --- a/text/skia_font.cpp +++ b/text/skia_font.cpp @@ -124,9 +124,8 @@ glyph_t SkiaFont::codePointToGlyph(codepoint_t codepoint) const gfx::RectF SkiaFont::getGlyphBounds(glyph_t glyph) const { - float widths; SkRect bounds; - m_skFont.getWidthsBounds(&glyph, 1, &widths, &bounds, nullptr); + m_skFont.getWidthsBounds(&glyph, 1, nullptr, &bounds, nullptr); return os::from_skia(bounds); } diff --git a/text/text_blob.cpp b/text/text_blob.cpp index 2f3c43e17..e08d4c028 100644 --- a/text/text_blob.cpp +++ b/text/text_blob.cpp @@ -11,6 +11,7 @@ #include "text/text_blob.h" #include "gfx/rect.h" +#include "gfx/size.h" #include "text/font.h" #include "text/font_metrics.h" #include "text/sprite_text_blob.h" @@ -65,21 +66,16 @@ gfx::RectF TextBlob::RunInfo::getGlyphBounds(const size_t i) const gfx::RectF bounds = font->getGlyphBounds(glyphs[i]); - // Get bounds of whitespace + // Get bounds of whitespace from a space glyph. if (bounds.isEmpty()) { - FontMetrics metrics; - font->metrics(&metrics); - // avgCharWidth can be 0, so we grab the next most useful thing, the height - bounds.w = metrics.avgCharWidth > 0 ? metrics.avgCharWidth : metrics.xHeight; - bounds.h = 1.0; + auto glyph = font->getGlyphBounds(' '); + bounds.setSize(gfx::SizeF(glyph.w - glyph.x, glyph.h - glyph.y)); } ASSERT(!bounds.isEmpty()); - bounds.offset(positions[i].x, - positions[i].y); + bounds.offset(positions[i]); if (offsets) { - bounds.offset(offsets[i].x, - offsets[i].y); + bounds.offset(offsets[i]); } // Add global "point" offset to the bounds. diff --git a/text/text_blob.h b/text/text_blob.h index 7bb3c6f6b..bbffd0ac3 100644 --- a/text/text_blob.h +++ b/text/text_blob.h @@ -59,12 +59,12 @@ namespace text { class RunHandler { public: - virtual ~RunHandler() { } + virtual ~RunHandler() = default; virtual void commitRunBuffer(RunInfo& info) = 0; }; - TextBlob(const gfx::RectF& bounds) : m_bounds(bounds) { } - virtual ~TextBlob() { } + explicit TextBlob(const gfx::RectF& bounds) : m_bounds(bounds) {} + virtual ~TextBlob() = default; // Returns exact bounds that are required to draw this TextBlob. gfx::RectF bounds();