Skip to content

Commit

Permalink
Whitespace bounds from space glyph
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaiser committed Aug 22, 2024
1 parent 51e69d7 commit d1dc97d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
3 changes: 1 addition & 2 deletions text/skia_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
17 changes: 7 additions & 10 deletions text/text_blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,21 +66,17 @@ 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.w = glyph.w - glyph.x;
bounds.h = 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.
Expand Down
6 changes: 3 additions & 3 deletions text/text_blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d1dc97d

Please sign in to comment.