diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 070a461baf6..d1ab9ea2481 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -1093,12 +1093,13 @@ impl Box { } } - /// Split box which includes new-line character. + /// Find the split of a box that includes a new-line character. /// - /// A return value of `None` indicates that the box could not be split. - /// Otherwise the split boxes are returned. The right box is optional due - /// to the possibility of it being whitespace. - pub fn split_by_new_line(&self) -> Option<(Box, Option)> { + /// A return value of `None` indicates that the box is not splittable. + /// Otherwise the split information is returned. The right information is + /// optional due to the possibility of it being whitespace. + pub fn find_split_positions_by_new_line(&self) + -> Option<(SplitInfo, Option, Arc<~TextRun> /* TODO: remove */)> { match self.specific { GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox | TableRowBox | TableWrapperBox => None, @@ -1113,26 +1114,22 @@ impl Box { text_box_info.range.length() - (cur_new_line_pos + CharIndex(1))); // Left box is for left text of first founded new-line character. - let left_box = { - let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range); - let new_metrics = new_text_box_info.run.metrics_for_range(&left_range); - let mut new_box = self.transform(new_metrics.bounding_box.size, ScannedTextBox(new_text_box_info)); - new_box.new_line_pos = vec!(); - new_box + let left_box = SplitInfo { + 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. let right_box = if right_range.length() > CharIndex(0) { - let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), right_range); - let new_metrics = new_text_box_info.run.metrics_for_range(&right_range); - let mut new_box = self.transform(new_metrics.bounding_box.size, ScannedTextBox(new_text_box_info)); - new_box.new_line_pos = new_line_pos; - Some(new_box) + Some(SplitInfo { + range: right_range, + width: text_box_info.run.advance_for_range(&right_range), + }) } else { None }; - Some((left_box, right_box)) + Some((left_box, right_box, text_box_info.run.clone())) } } } diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index cc2c0df5ade..527dcc3e651 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -419,18 +419,35 @@ impl LineboxScanner { fn try_append_to_line_by_new_line(&mut self, in_box: Box) -> bool { if in_box.new_line_pos.len() == 0 { - // In case of box does not include new-line character + debug!("LineboxScanner: Did not find a new-line character, so pushing the box to \ + the line without splitting."); self.push_box_to_line(in_box); true } else { - // In case of box includes new-line character + debug!("LineboxScanner: Found a new-line character, so splitting theline."); match in_box.split_by_new_line() { - Some((left_box, Some(right_box))) => { - self.push_box_to_line(left_box); - self.work_list.push_front(right_box); - }, - Some((left_box, None)) => { - self.push_box_to_line(left_box); + Some((left, right, run)) => { + // TODO: Remove box splitting + let split_box = |split: SplitInfo| { + let info = ScannedTextBoxInfo::new(run.clone(), split.range); + let specific = ScannedTextBox(info); + let size = Size2D(split.width, in_box.border_box.size.height); + in_box.transform(size, specific) + }; + + debug!("LineboxScanner: Pushing the box to the left of the new-line character \ + to the line."); + let mut left = split_box(left); + left.new_line_pos = vec!(); + self.push_box_to_line(left); + + right.map(|right| { + debug!("LineboxScanner: Deferring the box to the right of the new-line \ + character to the line."); + let mut right = split_box(right); + right.new_line_pos = in_box.new_line_pos.clone(); + self.work_list.push_front(right); + }); }, None => { error!("LineboxScanner: This split case makes no sense!")