mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Don't measure advance zero-length text.
This commit is contained in:
parent
6b7a0a00f8
commit
5e5844a33d
1 changed files with 8 additions and 3 deletions
|
@ -52,14 +52,19 @@ pub trait FontMethods {
|
|||
|
||||
pub impl Font : FontMethods {
|
||||
fn measure_text(run: &TextRun, offset: uint, length: uint) -> RunMetrics {
|
||||
assert offset < run.text.len();
|
||||
assert offset + length <= run.text.len();
|
||||
|
||||
// TODO: alter advance direction for RTL
|
||||
// TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text
|
||||
let mut advance = au(0);
|
||||
do run.glyphs.iter_glyphs_for_range(offset, length) |_i, glyph| {
|
||||
advance += glyph.advance();
|
||||
if length > 0 {
|
||||
do run.glyphs.iter_glyphs_for_range(offset, length) |_i, glyph| {
|
||||
advance += glyph.advance();
|
||||
}
|
||||
}
|
||||
let mut bounds = Rect(Point2D(au(0), -self.metrics.ascent),
|
||||
Size2D(advance, self.metrics.ascent + self.metrics.descent));
|
||||
Size2D(advance, self.metrics.ascent + self.metrics.descent));
|
||||
|
||||
// TODO(Issue #125): support loose and tight bounding boxes; using the
|
||||
// ascent+descent and advance is sometimes too generous and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue