Use text run's font when measuring text run min width.

This commit is contained in:
Brian J. Burg 2012-10-15 17:12:45 -07:00
parent 357905c202
commit 78cfdee5e8
2 changed files with 5 additions and 7 deletions

View file

@ -192,7 +192,7 @@ impl RenderBox : RenderBoxMethods {
* may cause glyphs to be allocated. For now, it's impure because of
* holder.get_image()
*/
fn get_min_width(ctx: &LayoutContext) -> au {
fn get_min_width(_ctx: &LayoutContext) -> au {
match self {
// TODO: this should account for min/pref widths of the
// box element in isolation. That includes
@ -203,7 +203,7 @@ impl RenderBox : RenderBoxMethods {
// TODO: consult CSS 'width', margin, border.
// TODO: If image isn't available, consult 'width'.
ImageBox(_,i) => au::from_px(i.get_size().get_default(Size2D(0,0)).width),
TextBox(_,d) => d.run.min_width_for_range(ctx, d.offset, d.length),
TextBox(_,d) => d.run.min_width_for_range(d.offset, d.length),
UnscannedTextBox(*) => fail ~"Shouldn't see unscanned boxes here."
}
}

View file

@ -49,23 +49,21 @@ trait TextRunMethods {
pure fn glyphs(&self) -> &self/GlyphStore;
pure fn iter_indivisible_pieces_for_range(&self, offset: uint, length: uint, f: fn(uint, uint) -> bool);
fn min_width_for_range(&LayoutContext, offset: uint, length: uint) -> au;
fn min_width_for_range(offset: uint, length: uint) -> au;
fn iter_natural_lines_for_range(&self, offset: uint, length: uint, f: fn(uint, uint) -> bool);
}
impl TextRun : TextRunMethods {
pure fn glyphs(&self) -> &self/GlyphStore { &self.glyphs }
fn min_width_for_range(ctx: &LayoutContext, offset: uint, length: uint) -> au {
fn min_width_for_range(offset: uint, length: uint) -> au {
assert length > 0;
assert offset < self.text.len();
assert offset + length <= self.text.len();
let mut max_piece_width = au(0);
// TODO: use a real font reference
let font = ctx.font_cache.get_test_font();
for self.iter_indivisible_pieces_for_range(offset, length) |piece_offset, piece_len| {
let metrics = font.measure_text(&self, piece_offset, piece_len);
let metrics = self.font.measure_text(&self, piece_offset, piece_len);
if metrics.advance_width > max_piece_width {
max_piece_width = metrics.advance_width;
}