mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
remove @ from ScannedTextBox.run
This commit is contained in:
parent
f7cc49c30f
commit
2865ab4e29
4 changed files with 41 additions and 42 deletions
|
@ -87,7 +87,7 @@ pub struct SolidColorDisplayItem<E> {
|
|||
/// Renders text.
|
||||
pub struct TextDisplayItem<E> {
|
||||
base: BaseDisplayItem<E>,
|
||||
text_run: ~TextRun,
|
||||
text_run: Arc<~TextRun>,
|
||||
range: Range,
|
||||
color: Color,
|
||||
}
|
||||
|
@ -142,7 +142,8 @@ impl<E> DisplayItem<E> {
|
|||
debug!("Drawing text at {:?}.", text.base.bounds);
|
||||
|
||||
// FIXME(pcwalton): Allocating? Why?
|
||||
let font = render_context.font_ctx.get_font_by_descriptor(&text.text_run.font_descriptor).unwrap();
|
||||
let text_run = text.text_run.get();
|
||||
let font = render_context.font_ctx.get_font_by_descriptor(&text_run.font_descriptor).unwrap();
|
||||
|
||||
let font_metrics = font.with_borrow( |font| {
|
||||
font.metrics.clone()
|
||||
|
@ -151,7 +152,7 @@ impl<E> DisplayItem<E> {
|
|||
let baseline_origin = Point2D(origin.x, origin.y + font_metrics.ascent);
|
||||
font.with_mut_borrow( |font| {
|
||||
font.draw_text_into_context(render_context,
|
||||
&text.text_run,
|
||||
text.text_run.get(),
|
||||
&text.range,
|
||||
baseline_origin,
|
||||
text.color);
|
||||
|
@ -162,18 +163,18 @@ impl<E> DisplayItem<E> {
|
|||
let strikeout_size = font_metrics.strikeout_size;
|
||||
let strikeout_offset = font_metrics.strikeout_offset;
|
||||
|
||||
if text.text_run.decoration.underline {
|
||||
if text_run.decoration.underline {
|
||||
let underline_y = baseline_origin.y - underline_offset;
|
||||
let underline_bounds = Rect(Point2D(baseline_origin.x, underline_y),
|
||||
Size2D(width, underline_size));
|
||||
render_context.draw_solid_color(&underline_bounds, text.color);
|
||||
}
|
||||
if text.text_run.decoration.overline {
|
||||
if text_run.decoration.overline {
|
||||
let overline_bounds = Rect(Point2D(baseline_origin.x, origin.y),
|
||||
Size2D(width, underline_size));
|
||||
render_context.draw_solid_color(&overline_bounds, text.color);
|
||||
}
|
||||
if text.text_run.decoration.line_through {
|
||||
if text_run.decoration.line_through {
|
||||
let strikeout_y = baseline_origin.y - strikeout_offset;
|
||||
let strikeout_bounds = Rect(Point2D(baseline_origin.x, strikeout_y),
|
||||
Size2D(width, strikeout_size));
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! The `Box` type, which represents the leaves of the layout tree.
|
||||
|
||||
use extra::url::Url;
|
||||
use extra::arc::MutexArc;
|
||||
use extra::arc::{MutexArc,Arc};
|
||||
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
|
||||
use gfx::color::rgb;
|
||||
use gfx::display_list::{BaseDisplayItem, BorderDisplayItem, BorderDisplayItemClass};
|
||||
|
@ -160,7 +160,7 @@ impl ImageBoxInfo {
|
|||
/// object.
|
||||
pub struct ScannedTextBoxInfo {
|
||||
/// The text run that this represents.
|
||||
run: @TextRun,
|
||||
run: Arc<~TextRun>,
|
||||
|
||||
/// The range within the above text run that this represents.
|
||||
range: Range,
|
||||
|
@ -168,7 +168,7 @@ pub struct ScannedTextBoxInfo {
|
|||
|
||||
impl ScannedTextBoxInfo {
|
||||
/// Creates the information specific to a scanned text box from a range and a text run.
|
||||
pub fn new(run: @TextRun, range: Range) -> ScannedTextBoxInfo {
|
||||
pub fn new(run: Arc<~TextRun>, range: Range) -> ScannedTextBoxInfo {
|
||||
ScannedTextBoxInfo {
|
||||
run: run,
|
||||
range: range,
|
||||
|
@ -630,15 +630,7 @@ impl Box {
|
|||
|
||||
// Create the text box.
|
||||
do list.with_mut_ref |list| {
|
||||
// FIXME(pcwalton): Allocation? Why?!
|
||||
let run = ~TextRun {
|
||||
text: text_box.run.text.clone(),
|
||||
font_descriptor: text_box.run.font_descriptor.clone(),
|
||||
font_metrics: text_box.run.font_metrics.clone(),
|
||||
font_style: text_box.run.font_style.clone(),
|
||||
decoration: text_box.run.decoration.clone(),
|
||||
glyphs: text_box.run.glyphs.clone()
|
||||
};
|
||||
let run = text_box.run.clone();
|
||||
let text_display_item = ~TextDisplayItem {
|
||||
base: BaseDisplayItem {
|
||||
bounds: absolute_box_bounds,
|
||||
|
@ -677,7 +669,7 @@ impl Box {
|
|||
// Draw a rectangle representing the baselines.
|
||||
//
|
||||
// TODO(Issue #221): Create and use a Line display item for the baseline.
|
||||
let ascent = text_box.run.metrics_for_range(
|
||||
let ascent = text_box.run.get().metrics_for_range(
|
||||
&text_box.range).ascent;
|
||||
let baseline = Rect(absolute_box_bounds.origin + Point2D(Au(0), ascent),
|
||||
Size2D(absolute_box_bounds.size.width, Au(0)));
|
||||
|
@ -790,11 +782,12 @@ impl Box {
|
|||
}
|
||||
ScannedTextBox(ref text_box_info) => {
|
||||
let range = &text_box_info.range;
|
||||
let min_line_width = text_box_info.run.min_width_for_range(range);
|
||||
let text_run = text_box_info.run.get();
|
||||
let min_line_width = text_run.min_width_for_range(range);
|
||||
|
||||
let mut max_line_width = Au::new(0);
|
||||
for line_range in text_box_info.run.iter_natural_lines_for_range(range) {
|
||||
let line_metrics = text_box_info.run.metrics_for_range(&line_range);
|
||||
for line_range in text_run.iter_natural_lines_for_range(range) {
|
||||
let line_metrics = text_run.metrics_for_range(&line_range);
|
||||
max_line_width = Au::max(max_line_width, line_metrics.advance_width);
|
||||
}
|
||||
|
||||
|
@ -824,7 +817,7 @@ impl Box {
|
|||
}
|
||||
ScannedTextBox(ref text_box_info) => {
|
||||
// Compute the height based on the line-height and font size.
|
||||
let (range, run) = (&text_box_info.range, &text_box_info.run);
|
||||
let (range, run) = (&text_box_info.range, &text_box_info.run.get());
|
||||
let text_bounds = run.metrics_for_range(range).bounding_box;
|
||||
let em_size = text_bounds.size.height;
|
||||
self.calculate_line_height(em_size)
|
||||
|
@ -846,11 +839,12 @@ impl Box {
|
|||
|
||||
debug!("split_to_width: splitting text box (strlen={:u}, range={}, \
|
||||
avail_width={})",
|
||||
text_box_info.run.text.get().len(),
|
||||
text_box_info.run.get().text.get().len(),
|
||||
text_box_info.range,
|
||||
max_width);
|
||||
|
||||
for (glyphs, offset, slice_range) in text_box_info.run.iter_slices_for_range(
|
||||
let text_run = text_box_info.run.get();
|
||||
for (glyphs, offset, slice_range) in text_run.iter_slices_for_range(
|
||||
&text_box_info.range) {
|
||||
debug!("split_to_width: considering slice (offset={}, range={}, \
|
||||
remain_width={})",
|
||||
|
@ -858,7 +852,7 @@ impl Box {
|
|||
slice_range,
|
||||
remaining_width);
|
||||
|
||||
let metrics = text_box_info.run.metrics_for_slice(glyphs, &slice_range);
|
||||
let metrics = text_run.metrics_for_slice(glyphs, &slice_range);
|
||||
let advance = metrics.advance_width;
|
||||
|
||||
let should_continue;
|
||||
|
@ -909,20 +903,23 @@ impl Box {
|
|||
}
|
||||
|
||||
let left_box = if left_range.length() > 0 {
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run, left_range);
|
||||
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range);
|
||||
let new_size = text_box_info.run.get().
|
||||
metrics_for_range(&left_range).bounding_box.size;
|
||||
let new_text_box = @Box::new(self.node, ScannedTextBox(new_text_box_info));
|
||||
let new_metrics = new_text_box_info.run.metrics_for_range(&left_range);
|
||||
new_text_box.set_size(new_metrics.bounding_box.size);
|
||||
new_text_box.set_size(new_size);
|
||||
Some(new_text_box)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let right_box = right_range.map_default(None, |range: Range| {
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run, range);
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), range);
|
||||
let new_size = text_box_info.run.get().
|
||||
metrics_for_range(&range).bounding_box.size;
|
||||
let new_text_box = @Box::new(self.node, ScannedTextBox(new_text_box_info));
|
||||
let new_metrics = new_text_box_info.run.metrics_for_range(&range);
|
||||
new_text_box.set_size(new_metrics.bounding_box.size);
|
||||
new_text_box.set_size(new_size);
|
||||
Some(new_text_box)
|
||||
});
|
||||
|
||||
|
@ -975,7 +972,7 @@ impl Box {
|
|||
/// Cleans up all the memory associated with this box.
|
||||
pub fn teardown(&self) {
|
||||
match self.specific {
|
||||
ScannedTextBox(ref text_box_info) => text_box_info.run.teardown(),
|
||||
ScannedTextBox(ref text_box_info) => text_box_info.run.get().teardown(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -702,7 +702,7 @@ impl Flow for InlineFlow {
|
|||
},
|
||||
ScannedTextBox(ref text_box) => {
|
||||
let range = &text_box.range;
|
||||
let run = &text_box.run;
|
||||
let run = text_box.run.get();
|
||||
|
||||
// Compute the height based on the line-height and font size
|
||||
let text_bounds = run.metrics_for_range(range).bounding_box;
|
||||
|
@ -711,7 +711,7 @@ impl Flow for InlineFlow {
|
|||
|
||||
// Find the top and bottom of the content area.
|
||||
// Those are used in text-top and text-bottom value of 'vertical-align'
|
||||
let text_ascent = text_box.run.font_metrics.ascent;
|
||||
let text_ascent = run.font_metrics.ascent;
|
||||
|
||||
// Offset from the top of the box is 1/2 of the leading + ascent
|
||||
let text_offset = text_ascent + (line_height - em_size).scale_by(0.5);
|
||||
|
|
|
@ -11,6 +11,7 @@ use layout::flow::Flow;
|
|||
use gfx::text::text_run::TextRun;
|
||||
use gfx::text::util::{CompressWhitespaceNewline, transform_text};
|
||||
use std::vec;
|
||||
use extra::arc::Arc;
|
||||
use servo_util::range::Range;
|
||||
|
||||
/// A stack-allocated object for scanning an inline flow into `TextRun`-containing `TextBox`es.
|
||||
|
@ -125,14 +126,14 @@ impl TextRunScanner {
|
|||
// font group fonts. This is probably achieved by creating the font group above
|
||||
// and then letting `FontGroup` decide which `Font` to stick into the text run.
|
||||
let fontgroup = ctx.font_ctx.get_resolved_font_for_style(&font_style);
|
||||
let run = @fontgroup.with_borrow(|fg| fg.create_textrun(transformed_text.clone(), decoration));
|
||||
let run = Arc::new(~fontgroup.with_borrow(|fg| fg.create_textrun(transformed_text.clone(), decoration)));
|
||||
|
||||
debug!("TextRunScanner: pushing single text box in range: {} ({})",
|
||||
self.clump,
|
||||
*text);
|
||||
let range = Range::new(0, run.char_len());
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(run, range);
|
||||
let new_metrics = run.metrics_for_range(&range);
|
||||
let range = Range::new(0, run.get().char_len());
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(run.clone(), range);
|
||||
let new_metrics = run.get().metrics_for_range(&range);
|
||||
let new_box = @old_box.transform(new_metrics.bounding_box.size,
|
||||
ScannedTextBox(new_text_box_info));
|
||||
out_boxes.push(new_box)
|
||||
|
@ -190,7 +191,7 @@ impl TextRunScanner {
|
|||
let run = if clump.length() != 0 && run_str.len() > 0 {
|
||||
fontgroup.with_borrow( |fg| {
|
||||
fg.fonts[0].with_mut_borrow( |font| {
|
||||
Some(@TextRun::new(font, run_str.clone(), decoration))
|
||||
Some(Arc::new(~TextRun::new(font, run_str.clone(), decoration)))
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
@ -208,8 +209,8 @@ impl TextRunScanner {
|
|||
continue
|
||||
}
|
||||
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(run.unwrap(), range);
|
||||
let new_metrics = new_text_box_info.run.metrics_for_range(&range);
|
||||
let new_text_box_info = ScannedTextBoxInfo::new(run.get_ref().clone(), range);
|
||||
let new_metrics = new_text_box_info.run.get().metrics_for_range(&range);
|
||||
let new_box = @in_boxes[i].transform(new_metrics.bounding_box.size,
|
||||
ScannedTextBox(new_text_box_info));
|
||||
out_boxes.push(new_box)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue