Use constructor for SplitInfo to reduce code repetition

This commit is contained in:
Brendan Zabarauskas 2014-05-27 11:25:18 -07:00
parent de3b193e92
commit a94805d64a

View file

@ -247,6 +247,15 @@ pub struct SplitInfo {
pub width: Au, pub width: Au,
} }
impl SplitInfo {
fn new(range: Range<CharIndex>, info: &ScannedTextBoxInfo) -> SplitInfo {
SplitInfo {
range: range,
width: info.run.advance_for_range(&range),
}
}
}
/// Data for an unscanned text box. Unscanned text boxes are the results of flow construction that /// Data for an unscanned text box. Unscanned text boxes are the results of flow construction that
/// have not yet had their width determined. /// have not yet had their width determined.
#[deriving(Clone)] #[deriving(Clone)]
@ -1114,17 +1123,11 @@ impl Box {
text_box_info.range.length() - (cur_new_line_pos + CharIndex(1))); text_box_info.range.length() - (cur_new_line_pos + CharIndex(1)));
// Left box is for left text of first founded new-line character. // Left box is for left text of first founded new-line character.
let left_box = SplitInfo { let left_box = SplitInfo::new(left_range, text_box_info);
range: left_range,
width: text_box_info.run.advance_for_range(&left_range),
};
// Right box is for right text of first founded new-line character. // Right box is for right text of first founded new-line character.
let right_box = if right_range.length() > CharIndex(0) { let right_box = if right_range.length() > CharIndex(0) {
Some(SplitInfo { Some(SplitInfo::new(right_range, text_box_info))
range: right_range,
width: text_box_info.run.advance_for_range(&right_range),
})
} else { } else {
None None
}; };
@ -1224,20 +1227,11 @@ impl Box {
None None
} else { } else {
let left = if left_is_some { let left = if left_is_some {
Some(SplitInfo { Some(SplitInfo::new(left_range, text_box_info))
range: left_range,
width: text_box_info.run.advance_for_range(&left_range),
})
} else { } else {
None None
}; };
let right = right_range.map(|right_range| SplitInfo::new(right_range, text_box_info));
let right = right_range.map(|right_range| {
SplitInfo {
range: right_range,
width: text_box_info.run.advance_for_range(&right_range),
}
});
Some((left, right, text_box_info.run.clone())) Some((left, right, text_box_info.run.clone()))
} }