From 66f7c08e73c39689a723979dcbcc121fbcb82802 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 16 Jun 2012 14:46:10 -0700 Subject: [PATCH] servo: Make text_run immutable Source-Repo: https://github.com/servo/servo Source-Revision: 5af6c891ed30fcc8e0635ae8f7cc6bcf324d591a --- servo/src/servo/layout/text.rs | 9 +++++---- servo/src/servo/text/text_run.rs | 20 +++++--------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/servo/src/servo/layout/text.rs b/servo/src/servo/layout/text.rs index 0c95edbd99f9..fa893cc34194 100644 --- a/servo/src/servo/layout/text.rs +++ b/servo/src/servo/layout/text.rs @@ -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) } diff --git a/servo/src/servo/text/text_run.rs b/servo/src/servo/text/text_run.rs index 75eece7d5891..75a87a70f818 100644 --- a/servo/src/servo/text/text_run.rs +++ b/servo/src/servo/text/text_run.rs @@ -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); } }