Make text_run immutable

This commit is contained in:
Brian Anderson 2012-06-16 14:46:10 -07:00
parent 50a0956f1b
commit 5af6c891ed
2 changed files with 10 additions and 19 deletions

View file

@ -4,6 +4,7 @@ import geom::size::Size2D;
import gfx::geometry::au;
import layout::base::*; // FIXME: Can't get around import *; resolve bug.
import servo_text::text_run::text_run;
import servo_text::font::create_test_font;
class text_box {
let text: str;
@ -23,12 +24,12 @@ impl text_layout_methods for @Box {
_ { fail "expected text box in reflow_text!" }
};
let run = text_run(copy subbox.text);
subbox.run = some(copy run);
run.shape();
let font = create_test_font();
let run = text_run(&font, subbox.text);
subbox.run = some(run);
self.bounds.size =
Size2D(alt vec::last_opt(run.glyphs.get()) {
Size2D(alt vec::last_opt(run.glyphs) {
some(glyph) {
au(*glyph.pos.offset.x + *glyph.pos.advance.x)
}

View file

@ -1,24 +1,14 @@
import libc::{c_void};
import text::glyph::glyph;
import font::font;
import glyph::glyph;
import shaper::shape_text;
#[doc="A single, unbroken line of text."]
class text_run {
let text: str;
let mut glyphs: option<[glyph]>;
let glyphs: [glyph];
new(-text: str) {
self.text = text;
self.glyphs = none;
}
#[doc="
Shapes text. This determines the location of each glyph and determines
line break positions.
"]
fn shape() {
let font = font::create_test_font();
self.glyphs = some(shape_text(&font, self.text));
new(font: &font, text: str) {
self.glyphs = shape_text(font, text);
}
}