mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Avoid unnecessary calculations of the entire run metrics
This commit is contained in:
parent
1f7963e86b
commit
3cf82c7c92
2 changed files with 20 additions and 14 deletions
|
@ -183,6 +183,14 @@ impl<'a> TextRun {
|
|||
true
|
||||
}
|
||||
|
||||
pub fn ascent(&self) -> Au {
|
||||
self.font_metrics.ascent
|
||||
}
|
||||
|
||||
pub fn descent(&self) -> Au {
|
||||
self.font_metrics.descent
|
||||
}
|
||||
|
||||
pub fn advance_for_range(&self, range: &Range<CharIndex>) -> Au {
|
||||
// TODO(Issue #199): alter advance direction for RTL
|
||||
// TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text
|
||||
|
@ -209,8 +217,7 @@ impl<'a> TextRun {
|
|||
debug!("iterating outer range {:?}", range);
|
||||
for (_, offset, slice_range) in self.iter_slices_for_range(range) {
|
||||
debug!("iterated on {:?}[{:?}]", offset, slice_range);
|
||||
let metrics = self.metrics_for_range(&slice_range);
|
||||
max_piece_width = Au::max(max_piece_width, metrics.advance_width);
|
||||
max_piece_width = Au::max(max_piece_width, self.advance_for_range(&slice_range));
|
||||
}
|
||||
max_piece_width
|
||||
}
|
||||
|
|
|
@ -791,7 +791,7 @@ impl Box {
|
|||
display_list.push(BorderDisplayItemClass(border_display_item));
|
||||
|
||||
// Draw a rectangle representing the baselines.
|
||||
let ascent = text_box.run.metrics_for_range(&text_box.range).ascent;
|
||||
let ascent = text_box.run.ascent();
|
||||
let baseline = Rect(absolute_box_bounds.origin + Point2D(Au(0), ascent),
|
||||
Size2D(absolute_box_bounds.size.width, Au(0)));
|
||||
|
||||
|
@ -1216,21 +1216,20 @@ impl Box {
|
|||
|
||||
let left_box = if left_range.length() > CharIndex(0) {
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range);
|
||||
let mut new_metrics = new_text_box_info.run.metrics_for_range(&left_range);
|
||||
new_metrics.bounding_box.size.height = self.border_box.size.height;
|
||||
Some(self.transform(new_metrics.bounding_box.size,
|
||||
ScannedTextBox(new_text_box_info)))
|
||||
let width = new_text_box_info.run.advance_for_range(&left_range);
|
||||
let height = self.border_box.size.height;
|
||||
let size = Size2D(width, height);
|
||||
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let right_box = right_range.map_or(None, |range: Range<CharIndex>| {
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(),
|
||||
range);
|
||||
let mut new_metrics = new_text_box_info.run.metrics_for_range(&range);
|
||||
new_metrics.bounding_box.size.height = self.border_box.size.height;
|
||||
Some(self.transform(new_metrics.bounding_box.size,
|
||||
ScannedTextBox(new_text_box_info)))
|
||||
let right_box = right_range.map_or(None, |right_range: Range<CharIndex>| {
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), right_range);
|
||||
let width = new_text_box_info.run.advance_for_range(&right_range);
|
||||
let height = self.border_box.size.height;
|
||||
let size = Size2D(width, height);
|
||||
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
|
||||
});
|
||||
|
||||
if pieces_processed_count == 1 || left_box.is_none() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue