mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +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
|
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 {
|
pub fn advance_for_range(&self, range: &Range<CharIndex>) -> Au {
|
||||||
// TODO(Issue #199): alter advance direction for RTL
|
// TODO(Issue #199): alter advance direction for RTL
|
||||||
// TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text
|
// 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);
|
debug!("iterating outer range {:?}", range);
|
||||||
for (_, offset, slice_range) in self.iter_slices_for_range(range) {
|
for (_, offset, slice_range) in self.iter_slices_for_range(range) {
|
||||||
debug!("iterated on {:?}[{:?}]", offset, slice_range);
|
debug!("iterated on {:?}[{:?}]", offset, slice_range);
|
||||||
let metrics = self.metrics_for_range(&slice_range);
|
max_piece_width = Au::max(max_piece_width, self.advance_for_range(&slice_range));
|
||||||
max_piece_width = Au::max(max_piece_width, metrics.advance_width);
|
|
||||||
}
|
}
|
||||||
max_piece_width
|
max_piece_width
|
||||||
}
|
}
|
||||||
|
|
|
@ -791,7 +791,7 @@ impl Box {
|
||||||
display_list.push(BorderDisplayItemClass(border_display_item));
|
display_list.push(BorderDisplayItemClass(border_display_item));
|
||||||
|
|
||||||
// Draw a rectangle representing the baselines.
|
// 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),
|
let baseline = Rect(absolute_box_bounds.origin + Point2D(Au(0), ascent),
|
||||||
Size2D(absolute_box_bounds.size.width, Au(0)));
|
Size2D(absolute_box_bounds.size.width, Au(0)));
|
||||||
|
|
||||||
|
@ -1216,21 +1216,20 @@ impl Box {
|
||||||
|
|
||||||
let left_box = if left_range.length() > CharIndex(0) {
|
let left_box = if left_range.length() > CharIndex(0) {
|
||||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range);
|
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);
|
let width = new_text_box_info.run.advance_for_range(&left_range);
|
||||||
new_metrics.bounding_box.size.height = self.border_box.size.height;
|
let height = self.border_box.size.height;
|
||||||
Some(self.transform(new_metrics.bounding_box.size,
|
let size = Size2D(width, height);
|
||||||
ScannedTextBox(new_text_box_info)))
|
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let right_box = right_range.map_or(None, |range: Range<CharIndex>| {
|
let right_box = right_range.map_or(None, |right_range: Range<CharIndex>| {
|
||||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(),
|
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), right_range);
|
||||||
range);
|
let width = new_text_box_info.run.advance_for_range(&right_range);
|
||||||
let mut new_metrics = new_text_box_info.run.metrics_for_range(&range);
|
let height = self.border_box.size.height;
|
||||||
new_metrics.bounding_box.size.height = self.border_box.size.height;
|
let size = Size2D(width, height);
|
||||||
Some(self.transform(new_metrics.bounding_box.size,
|
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
|
||||||
ScannedTextBox(new_text_box_info)))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if pieces_processed_count == 1 || left_box.is_none() {
|
if pieces_processed_count == 1 || left_box.is_none() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue