diff options
Diffstat (limited to 'components/gfx')
-rw-r--r-- | components/gfx/Cargo.toml | 8 | ||||
-rw-r--r-- | components/gfx/buffer_map.rs | 15 | ||||
-rw-r--r-- | components/gfx/display_list/mod.rs | 47 | ||||
-rw-r--r-- | components/gfx/display_list/optimizer.rs | 4 | ||||
-rw-r--r-- | components/gfx/filters.rs | 2 | ||||
-rw-r--r-- | components/gfx/font.rs | 36 | ||||
-rw-r--r-- | components/gfx/font_cache_task.rs | 21 | ||||
-rw-r--r-- | components/gfx/font_template.rs | 2 | ||||
-rw-r--r-- | components/gfx/lib.rs | 13 | ||||
-rw-r--r-- | components/gfx/paint_context.rs | 8 | ||||
-rw-r--r-- | components/gfx/paint_task.rs | 45 | ||||
-rw-r--r-- | components/gfx/platform/freetype/font.rs | 16 | ||||
-rw-r--r-- | components/gfx/platform/freetype/font_context.rs | 4 | ||||
-rw-r--r-- | components/gfx/platform/freetype/font_list.rs | 40 | ||||
-rw-r--r-- | components/gfx/platform/macos/font.rs | 8 | ||||
-rw-r--r-- | components/gfx/platform/macos/font_context.rs | 2 | ||||
-rw-r--r-- | components/gfx/platform/macos/font_list.rs | 4 | ||||
-rw-r--r-- | components/gfx/platform/macos/font_template.rs | 3 | ||||
-rw-r--r-- | components/gfx/text/glyph.rs | 35 | ||||
-rw-r--r-- | components/gfx/text/text_run.rs | 26 | ||||
-rw-r--r-- | components/gfx/text/util.rs | 2 |
21 files changed, 175 insertions, 166 deletions
diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml index dbdd1246897..a0d0c47670f 100644 --- a/components/gfx/Cargo.toml +++ b/components/gfx/Cargo.toml @@ -38,9 +38,6 @@ git = "https://github.com/servo/rust-stb-image" [dependencies.png] git = "https://github.com/servo/rust-png" -[dependencies.url] -git = "https://github.com/servo/rust-url" - [dependencies.harfbuzz] git = "https://github.com/servo/rust-harfbuzz" @@ -62,5 +59,6 @@ git = "https://github.com/servo/rust-core-text" [dependencies.script_traits] path = "../script_traits" -[dependencies.time] -git = "https://github.com/rust-lang/time" +[dependencies] +url = "*" +time = "*"
\ No newline at end of file diff --git a/components/gfx/buffer_map.rs b/components/gfx/buffer_map.rs index 9c1197ec8b2..c33617a7c9e 100644 --- a/components/gfx/buffer_map.rs +++ b/components/gfx/buffer_map.rs @@ -3,12 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::collections::HashMap; -use std::collections::hash_map::{Occupied, Vacant}; +use std::collections::hash_map::Entry::{Occupied, Vacant}; use geom::size::Size2D; use layers::platform::surface::NativePaintingGraphicsContext; use layers::layers::LayerBuffer; -use std::hash::Hash; -use std::hash::sip::SipState; +use std::hash::{Hash, Hasher, Writer}; use std::mem; /// This is a struct used to store buffers when they are not in use. @@ -27,11 +26,11 @@ pub struct BufferMap { } /// A key with which to store buffers. It is based on the size of the buffer. -#[deriving(Eq, Copy)] -struct BufferKey([uint, ..2]); +#[derive(Eq, Copy)] +struct BufferKey([uint; 2]); -impl Hash for BufferKey { - fn hash(&self, state: &mut SipState) { +impl<H: Hasher+Writer> Hash<H> for BufferKey { + fn hash(&self, state: &mut H) { let BufferKey(ref bytes) = *self; bytes.as_slice().hash(state); } @@ -91,7 +90,7 @@ impl BufferMap { entry.into_mut().buffers.push(new_buffer); } Vacant(entry) => { - entry.set(BufferValue { + entry.insert(BufferValue { buffers: vec!(new_buffer), last_action: *counter, }); diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 6ede4546b6b..7bd8187728e 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -38,7 +38,7 @@ use servo_util::geometry::{mod, Au, MAX_RECT, ZERO_RECT}; use servo_util::range::Range; use servo_util::smallvec::{SmallVec, SmallVec8}; use std::fmt; -use std::slice::Items; +use std::slice::Iter; use std::sync::Arc; use style::ComputedValues; use style::computed_values::{border_style, cursor, filter, mix_blend_mode, pointer_events}; @@ -60,7 +60,7 @@ pub static BOX_SHADOW_INFLATION_FACTOR: i32 = 3; /// Because the script task's GC does not trace layout, node data cannot be safely stored in layout /// data structures. Also, layout code tends to be faster when the DOM is not being accessed, for /// locality reasons. Using `OpaqueNode` enforces this invariant. -#[deriving(Clone, PartialEq, Copy)] +#[derive(Clone, PartialEq, Copy)] pub struct OpaqueNode(pub uintptr_t); impl OpaqueNode { @@ -356,7 +356,7 @@ impl StackingContext { result: &mut Vec<DisplayItemMetadata>, topmost_only: bool, mut iterator: I) - where I: Iterator<&'a DisplayItem> { + where I: Iterator<Item=&'a DisplayItem> { for item in iterator { // TODO(pcwalton): Use a precise algorithm here. This will allow us to properly hit // test elements with `border-radius`, for example. @@ -473,7 +473,7 @@ pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id } /// One drawing command in the list. -#[deriving(Clone)] +#[derive(Clone)] pub enum DisplayItem { SolidColorClass(Box<SolidColorDisplayItem>), TextClass(Box<TextDisplayItem>), @@ -485,7 +485,7 @@ pub enum DisplayItem { } /// Information common to all display items. -#[deriving(Clone)] +#[derive(Clone)] pub struct BaseDisplayItem { /// The boundaries of the display item, in layer coordinates. pub bounds: Rect<Au>, @@ -512,7 +512,7 @@ impl BaseDisplayItem { /// A clipping region for a display item. Currently, this can describe rectangles, rounded /// rectangles (for `border-radius`), or arbitrary intersections of the two. Arbitrary transforms /// are not supported because those are handled by the higher-level `StackingContext` abstraction. -#[deriving(Clone, PartialEq, Show)] +#[derive(Clone, PartialEq, Show)] pub struct ClippingRegion { /// The main rectangular region. This does not include any corners. pub main: Rect<Au>, @@ -526,7 +526,7 @@ pub struct ClippingRegion { /// A complex clipping region. These don't as easily admit arbitrary intersection operations, so /// they're stored in a list over to the side. Currently a complex clipping region is just a /// rounded rectangle, but the CSS WGs will probably make us throw more stuff in here eventually. -#[deriving(Clone, PartialEq, Show)] +#[derive(Clone, PartialEq, Show)] pub struct ComplexClippingRegion { /// The boundaries of the rectangle. pub rect: Rect<Au>, @@ -637,7 +637,7 @@ impl ClippingRegion { /// Metadata attached to each display item. This is useful for performing auxiliary tasks with /// the display list involving hit testing: finding the originating DOM node and determining the /// cursor to use when the element is hovered over. -#[deriving(Clone, Copy)] +#[derive(Clone, Copy)] pub struct DisplayItemMetadata { /// The DOM node from which this display item originated. pub node: OpaqueNode, @@ -666,14 +666,14 @@ impl DisplayItemMetadata { } /// Paints a solid color. -#[deriving(Clone)] +#[derive(Clone)] pub struct SolidColorDisplayItem { pub base: BaseDisplayItem, pub color: Color, } /// Paints text. -#[deriving(Clone)] +#[derive(Clone)] pub struct TextDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -691,7 +691,7 @@ pub struct TextDisplayItem { pub orientation: TextOrientation, } -#[deriving(Clone, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq)] pub enum TextOrientation { Upright, SidewaysLeft, @@ -699,7 +699,7 @@ pub enum TextOrientation { } /// Paints an image. -#[deriving(Clone)] +#[derive(Clone)] pub struct ImageDisplayItem { pub base: BaseDisplayItem, pub image: Arc<Box<Image>>, @@ -711,7 +711,7 @@ pub struct ImageDisplayItem { } /// Paints a gradient. -#[deriving(Clone)] +#[derive(Clone)] pub struct GradientDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -727,7 +727,7 @@ pub struct GradientDisplayItem { } /// Paints a border. -#[deriving(Clone)] +#[derive(Clone)] pub struct BorderDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -750,7 +750,7 @@ pub struct BorderDisplayItem { /// Information about the border radii. /// /// TODO(pcwalton): Elliptical radii. -#[deriving(Clone, Default, PartialEq, Show, Copy)] +#[derive(Clone, Default, PartialEq, Show, Copy)] pub struct BorderRadii<T> { pub top_left: T, pub top_right: T, @@ -768,7 +768,7 @@ impl<T> BorderRadii<T> where T: PartialEq + Zero { } /// Paints a line segment. -#[deriving(Clone)] +#[derive(Clone)] pub struct LineDisplayItem { pub base: BaseDisplayItem, @@ -780,7 +780,7 @@ pub struct LineDisplayItem { } /// Paints a box shadow per CSS-BACKGROUNDS. -#[deriving(Clone)] +#[derive(Clone)] pub struct BoxShadowDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -806,10 +806,11 @@ pub struct BoxShadowDisplayItem { pub enum DisplayItemIterator<'a> { Empty, - Parent(dlist::Items<'a,DisplayItem>), + Parent(dlist::Iter<'a,DisplayItem>), } -impl<'a> Iterator<&'a DisplayItem> for DisplayItemIterator<'a> { +impl<'a> Iterator for DisplayItemIterator<'a> { + type Item = &'a DisplayItem; #[inline] fn next(&mut self) -> Option<&'a DisplayItem> { match *self { @@ -836,14 +837,14 @@ impl DisplayItem { } DisplayItem::TextClass(ref text) => { - debug!("Drawing text at {}.", text.base.bounds); + debug!("Drawing text at {:?}.", text.base.bounds); paint_context.draw_text(&**text); } DisplayItem::ImageClass(ref image_item) => { // FIXME(pcwalton): This is a really inefficient way to draw a tiled image; use a // brush instead. - debug!("Drawing image at {}.", image_item.base.bounds); + debug!("Drawing image at {:?}.", image_item.base.bounds); let mut y_offset = Au(0); while y_offset < image_item.base.bounds.size.height { @@ -926,13 +927,13 @@ impl DisplayItem { for _ in range(0, level) { indent.push_str("| ") } - println!("{}+ {}", indent, self); + println!("{}+ {:?}", indent, self); } } impl fmt::Show for DisplayItem { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} @ {} ({:x})", + write!(f, "{} @ {:?} ({:x})", match *self { DisplayItem::SolidColorClass(_) => "SolidColor", DisplayItem::TextClass(_) => "Text", diff --git a/components/gfx/display_list/optimizer.rs b/components/gfx/display_list/optimizer.rs index f9b738a1d73..dddf31c66d7 100644 --- a/components/gfx/display_list/optimizer.rs +++ b/components/gfx/display_list/optimizer.rs @@ -44,7 +44,7 @@ impl DisplayListOptimizer { fn add_in_bounds_display_items<'a,I>(&self, result_list: &mut DList<DisplayItem>, mut display_items: I) - where I: Iterator<&'a DisplayItem> { + where I: Iterator<Item=&'a DisplayItem> { for display_item in display_items { if self.visible_rect.intersects(&display_item.base().bounds) && display_item.base().clip.might_intersect_rect(&self.visible_rect) { @@ -57,7 +57,7 @@ impl DisplayListOptimizer { fn add_in_bounds_stacking_contexts<'a,I>(&self, result_list: &mut DList<Arc<StackingContext>>, mut stacking_contexts: I) - where I: Iterator<&'a Arc<StackingContext>> { + where I: Iterator<Item=&'a Arc<StackingContext>> { for stacking_context in stacking_contexts { let overflow = stacking_context.overflow.translate(&stacking_context.bounds.origin); if self.visible_rect.intersects(&overflow) { diff --git a/components/gfx/filters.rs b/components/gfx/filters.rs index a1cc25d2bd0..948f2cdfc3d 100644 --- a/components/gfx/filters.rs +++ b/components/gfx/filters.rs @@ -9,7 +9,7 @@ use azure::azure_hl::{ColorMatrixAttribute, ColorMatrixInput, CompositeInput, Dr use azure::azure_hl::{FilterNode, FilterType, LinearTransferAttribute, LinearTransferInput}; use azure::azure_hl::{Matrix5x4, TableTransferAttribute, TableTransferInput}; -use std::num::FloatMath; +use std::num::Float; use style::computed_values::filter; /// Creates a filter pipeline from a set of CSS filters. Returns the destination end of the filter diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 653eff5e5f3..cfc79b6248c 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -8,13 +8,13 @@ use std::mem; use std::slice; use std::rc::Rc; use std::cell::RefCell; -use servo_util::cache::{Cache, HashCache}; +use servo_util::cache::HashCache; use servo_util::smallvec::{SmallVec, SmallVec8}; use style::computed_values::{font_variant, font_weight}; use style::style_structs::Font as FontStyle; use std::sync::Arc; -use collections::hash::Hash; +use std::hash::Hash; use platform::font_context::FontContextHandle; use platform::font::{FontHandle, FontTable}; use servo_util::geometry::Au; @@ -66,10 +66,10 @@ impl FontTableTagConversions for FontTableTag { } pub trait FontTableMethods { - fn with_buffer(&self, |*const u8, uint|); + fn with_buffer<F>(&self, F) where F: FnOnce(*const u8, uint); } -#[deriving(Clone, Show)] +#[derive(Clone, Show)] pub struct FontMetrics { pub underline_size: Au, pub underline_offset: Au, @@ -101,7 +101,6 @@ pub struct Font { } bitflags! { - #[deriving(Copy)] flags ShapingFlags: u8 { #[doc="Set if the text is entirely whitespace."] const IS_WHITESPACE_SHAPING_FLAG = 0x01, @@ -113,7 +112,7 @@ bitflags! { } /// Various options that control text shaping. -#[deriving(Clone, Eq, PartialEq, Hash, Copy)] +#[derive(Clone, Eq, PartialEq, Hash, Copy)] pub struct ShapingOptions { /// Spacing to add between each letter. Corresponds to the CSS 2.1 `letter-spacing` property. /// NB: You will probably want to set the `IGNORE_LIGATURES_SHAPING_FLAG` if this is non-null. @@ -125,36 +124,25 @@ pub struct ShapingOptions { } /// An entry in the shape cache. -#[deriving(Clone, Eq, PartialEq, Hash)] +#[derive(Clone, Eq, PartialEq, Hash)] pub struct ShapeCacheEntry { text: String, options: ShapingOptions, } -#[deriving(Clone, Eq, PartialEq, Hash)] -struct ShapeCacheEntryRef<'a> { - text: &'a str, - options: &'a ShapingOptions, -} - -impl<'a> Equiv<ShapeCacheEntry> for ShapeCacheEntryRef<'a> { - fn equiv(&self, other: &ShapeCacheEntry) -> bool { - self.text == other.text.as_slice() && *self.options == other.options - } -} - impl Font { pub fn shape_text(&mut self, text: &str, options: &ShapingOptions) -> Arc<GlyphStore> { self.make_shaper(options); + //FIXME: find the equivalent of Equiv and the old ShapeCacheEntryRef let shaper = &self.shaper; - let lookup_key = ShapeCacheEntryRef { - text: text, - options: options, + let lookup_key = ShapeCacheEntry { + text: text.to_owned(), + options: options.clone(), }; - match self.shape_cache.find_equiv(&lookup_key) { + match self.shape_cache.find(&lookup_key) { None => {} - Some(glyphs) => return (*glyphs).clone(), + Some(glyphs) => return glyphs.clone(), } let mut glyphs = GlyphStore::new(text.chars().count() as int, diff --git a/components/gfx/font_cache_task.rs b/components/gfx/font_cache_task.rs index 5bb3a209d68..ac7648e1821 100644 --- a/components/gfx/font_cache_task.rs +++ b/components/gfx/font_cache_task.rs @@ -12,6 +12,7 @@ use collections::str::Str; use std::borrow::ToOwned; use std::collections::HashMap; use std::sync::Arc; +use std::sync::mpsc::{Sender, Receiver, channel}; use font_template::{FontTemplate, FontTemplateDescriptor}; use platform::font_template::FontTemplateData; use servo_net::resource_task::{ResourceTask, load_whole_resource}; @@ -80,11 +81,15 @@ pub enum Command { Exit(Sender<()>), } +unsafe impl Send for Command {} + /// Reply messages sent from the font cache task to the FontContext caller. pub enum Reply { GetFontTemplateReply(Option<Arc<FontTemplateData>>), } +unsafe impl Send for Reply {} + /// The font cache task itself. It maintains a list of reference counted /// font templates that are currently in use. struct FontCache { @@ -109,7 +114,7 @@ fn add_generic_font(generic_fonts: &mut HashMap<LowercaseString, LowercaseString impl FontCache { fn run(&mut self) { loop { - let msg = self.port.recv(); + let msg = self.port.recv().unwrap(); match msg { Command::GetFontTemplate(family, descriptor, result) => { @@ -138,13 +143,13 @@ impl FontCache { family.add_template(url.to_string().as_slice(), Some(bytes)); }, Err(_) => { - debug!("Failed to load web font: family={} url={}", family_name, url); + debug!("Failed to load web font: family={:?} url={}", family_name, url); } } } Source::Local(ref local_family_name) => { let family = &mut self.web_families[family_name]; - get_variations_for_family(local_family_name.as_slice(), |path| { + get_variations_for_family(local_family_name.as_slice(), |&mut:path| { family.add_template(path.as_slice(), None); }); } @@ -186,7 +191,7 @@ impl FontCache { let s = &mut self.local_families[*family_name]; if s.templates.len() == 0 { - get_variations_for_family(family_name.as_slice(), |path| { + get_variations_for_family(family_name.as_slice(), |&mut:path| { s.add_template(path.as_slice(), None); }); } @@ -244,7 +249,7 @@ impl FontCache { /// The public interface to the font cache task, used exclusively by /// the per-thread/task FontContext structures. -#[deriving(Clone)] +#[derive(Clone)] pub struct FontCacheTask { chan: Sender<Command>, } @@ -253,7 +258,7 @@ impl FontCacheTask { pub fn new(resource_task: ResourceTask) -> FontCacheTask { let (chan, port) = channel(); - spawn_named("FontCacheTask".to_owned(), proc() { + spawn_named("FontCacheTask".to_owned(), move || { // TODO: Allow users to specify these. let mut generic_fonts = HashMap::with_capacity(5); add_generic_font(&mut generic_fonts, "serif", "Times New Roman"); @@ -286,7 +291,7 @@ impl FontCacheTask { let (response_chan, response_port) = channel(); self.chan.send(Command::GetFontTemplate(family, desc, response_chan)); - let reply = response_port.recv(); + let reply = response_port.recv().unwrap(); match reply { Reply::GetFontTemplateReply(data) => { @@ -301,7 +306,7 @@ impl FontCacheTask { let (response_chan, response_port) = channel(); self.chan.send(Command::GetLastResortFontTemplate(desc, response_chan)); - let reply = response_port.recv(); + let reply = response_port.recv().unwrap(); match reply { Reply::GetFontTemplateReply(data) => { diff --git a/components/gfx/font_template.rs b/components/gfx/font_template.rs index 833495d2177..d90df2b3bdb 100644 --- a/components/gfx/font_template.rs +++ b/components/gfx/font_template.rs @@ -15,7 +15,7 @@ use font::FontHandleMethods; /// This is very basic at the moment and needs to be /// expanded or refactored when we support more of the /// font styling parameters. -#[deriving(Clone, Copy)] +#[derive(Clone, Copy)] pub struct FontTemplateDescriptor { pub weight: font_weight::T, pub italic: bool, diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index d90a7185d8a..5f1eae371df 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -2,14 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![feature(globs, macro_rules, phase, unsafe_destructor, default_type_params)] +#![feature(unsafe_destructor, int_uint, plugin, box_syntax)] #![deny(unused_imports)] #![deny(unused_variables)] #![allow(missing_copy_implementations)] +#![allow(unstable)] -#![feature(phase)] -#[phase(plugin, link)] +#[macro_use] extern crate log; extern crate azure; @@ -17,16 +17,15 @@ extern crate collections; extern crate geom; extern crate layers; extern crate libc; -extern crate rustrt; extern crate stb_image; extern crate png; extern crate script_traits; -extern crate serialize; +extern crate "serialize" as rustc_serialize; extern crate unicode; -#[phase(plugin)] +#[no_link] #[plugin] extern crate "plugins" as servo_plugins; extern crate "net" as servo_net; -#[phase(plugin, link)] +#[macro_use] extern crate "util" as servo_util; extern crate "msg" as servo_msg; extern crate style; diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index fc8834c5239..2a4925beb83 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -32,7 +32,7 @@ use servo_util::range::Range; use std::default::Default; use std::f32; use std::mem; -use std::num::{Float, FloatMath}; +use std::num::Float; use std::ptr; use style::computed_values::{border_style, filter, mix_blend_mode}; use std::sync::Arc; @@ -54,7 +54,7 @@ pub struct PaintContext<'a> { pub transient_clip: Option<ClippingRegion>, } -#[deriving(Copy)] +#[derive(Copy)] enum Direction { Top, Left, @@ -62,7 +62,7 @@ enum Direction { Bottom } -#[deriving(Copy)] +#[derive(Copy)] enum DashSize { DottedBorder = 1, DashedBorder = 3 @@ -608,7 +608,7 @@ impl<'a> PaintContext<'a> { let rect = bounds.to_azure_rect(); let draw_opts = DrawOptions::new(1u as AzFloat, 0 as uint16_t); let mut stroke_opts = StrokeOptions::new(0u as AzFloat, 10u as AzFloat); - let mut dash: [AzFloat, ..2] = [0u as AzFloat, 0u as AzFloat]; + let mut dash: [AzFloat; 2] = [0u as AzFloat, 0u as AzFloat]; stroke_opts.set_cap_style(AZ_CAP_BUTT as u8); diff --git a/components/gfx/paint_task.rs b/components/gfx/paint_task.rs index efb1182a795..95909f42e67 100644 --- a/components/gfx/paint_task.rs +++ b/components/gfx/paint_task.rs @@ -31,13 +31,13 @@ use servo_util::smallvec::SmallVec; use servo_util::task::spawn_named_with_send_on_failure; use servo_util::task_state; use servo_util::time::{TimeProfilerChan, TimeProfilerCategory, profile}; -use std::comm::{Receiver, Sender, channel}; use std::mem; -use std::task::TaskBuilder; +use std::thread::Builder; use std::sync::Arc; +use std::sync::mpsc::{Receiver, Sender, channel}; /// Information about a hardware graphics layer that layout sends to the painting task. -#[deriving(Clone)] +#[derive(Clone)] pub struct PaintLayer { /// A per-pipeline ID describing this layer that should be stable across reflows. pub id: LayerId, @@ -74,7 +74,7 @@ pub enum Msg { Exit(Option<Sender<()>>, PipelineExitType), } -#[deriving(Clone)] +#[derive(Clone)] pub struct PaintChan(Sender<Msg>); impl PaintChan { @@ -84,13 +84,12 @@ impl PaintChan { } pub fn send(&self, msg: Msg) { - let &PaintChan(ref chan) = self; - assert!(chan.send_opt(msg).is_ok(), "PaintChan.send: paint port closed") + assert!(self.send_opt(msg).is_ok(), "PaintChan.send: paint port closed") } pub fn send_opt(&self, msg: Msg) -> Result<(), Msg> { let &PaintChan(ref chan) = self; - chan.send_opt(msg) + chan.send(msg).map_err(|e| e.0) } } @@ -132,7 +131,7 @@ macro_rules! native_graphics_context( ($task:expr) => ( $task.native_graphics_context.as_ref().expect("Need a graphics context to do painting") ) -) +); impl<C> PaintTask<C> where C: PaintListener + Send { pub fn create(id: PipelineId, @@ -144,7 +143,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send { time_profiler_chan: TimeProfilerChan, shutdown_chan: Sender<()>) { let ConstellationChan(c) = constellation_chan.clone(); - spawn_named_with_send_on_failure("PaintTask", task_state::PAINT, proc() { + spawn_named_with_send_on_failure("PaintTask", task_state::PAINT, move |:| { { // Ensures that the paint task and graphics context are destroyed before the // shutdown message. @@ -196,7 +195,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send { let mut exit_response_channel : Option<Sender<()>> = None; let mut waiting_for_compositor_buffers_to_exit = false; loop { - match self.port.recv() { + match self.port.recv().unwrap() { Msg::PaintInit(stacking_context) => { self.root_stacking_context = Some(stacking_context.clone()); @@ -226,7 +225,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send { if self.epoch == epoch { self.paint(&mut replies, buffer_requests, scale, layer_id); } else { - debug!("painter epoch mismatch: {} != {}", self.epoch, epoch); + debug!("painter epoch mismatch: {:?} != {:?}", self.epoch, epoch); } } @@ -336,7 +335,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send { mut tiles: Vec<BufferRequest>, scale: f32, layer_id: LayerId) { - profile(TimeProfilerCategory::Painting, None, self.time_profiler_chan.clone(), || { + profile(TimeProfilerCategory::Painting, None, self.time_profiler_chan.clone(), |:| { // Bail out if there is no appropriate stacking context. let stacking_context = if let Some(ref stacking_context) = self.root_stacking_context { match display_list::find_stacking_context_with_layer_id(stacking_context, @@ -360,10 +359,10 @@ impl<C> PaintTask<C> where C: PaintListener + Send { stacking_context.clone(), scale); } - let new_buffers = Vec::from_fn(tile_count, |i| { + let new_buffers = (0..tile_count).map(|&mut :i| { let thread_id = i % self.worker_threads.len(); self.worker_threads[thread_id].get_painted_tile_buffer() - }); + }).collect(); let layer_buffer_set = box LayerBufferSet { buffers: new_buffers, @@ -425,13 +424,13 @@ impl WorkerThreadProxy { } else { opts::get().layout_threads }; - Vec::from_fn(thread_count, |_| { + (0..thread_count).map(|&:_| { let (from_worker_sender, from_worker_receiver) = channel(); let (to_worker_sender, to_worker_receiver) = channel(); let native_graphics_metadata = native_graphics_metadata.clone(); let font_cache_task = font_cache_task.clone(); let time_profiler_chan = time_profiler_chan.clone(); - TaskBuilder::new().spawn(proc() { + Builder::new().spawn(move || { let mut worker_thread = WorkerThread::new(from_worker_sender, to_worker_receiver, native_graphics_metadata, @@ -443,7 +442,7 @@ impl WorkerThreadProxy { receiver: from_worker_receiver, sender: to_worker_sender, } - }) + }).collect() } fn paint_tile(&mut self, @@ -451,17 +450,17 @@ impl WorkerThreadProxy { layer_buffer: Option<Box<LayerBuffer>>, stacking_context: Arc<StackingContext>, scale: f32) { - self.sender.send(MsgToWorkerThread::PaintTile(tile, layer_buffer, stacking_context, scale)) + self.sender.send(MsgToWorkerThread::PaintTile(tile, layer_buffer, stacking_context, scale)).unwrap() } fn get_painted_tile_buffer(&mut self) -> Box<LayerBuffer> { - match self.receiver.recv() { + match self.receiver.recv().unwrap() { MsgFromWorkerThread::PaintedTile(layer_buffer) => layer_buffer, } } fn exit(&mut self) { - self.sender.send(MsgToWorkerThread::Exit) + self.sender.send(MsgToWorkerThread::Exit).unwrap() } } @@ -493,7 +492,7 @@ impl WorkerThread { fn main(&mut self) { loop { - match self.receiver.recv() { + match self.receiver.recv().unwrap() { MsgToWorkerThread::Exit => break, MsgToWorkerThread::PaintTile(tile, layer_buffer, stacking_context, scale) => { let draw_target = self.optimize_and_paint_tile(&tile, stacking_context, scale); @@ -501,7 +500,7 @@ impl WorkerThread { layer_buffer, draw_target, scale); - self.sender.send(MsgFromWorkerThread::PaintedTile(buffer)) + self.sender.send(MsgFromWorkerThread::PaintedTile(buffer)).unwrap() } } } @@ -582,7 +581,7 @@ impl WorkerThread { // GPU painting mode, so that it doesn't have to recreate it. if !opts::get().gpu_painting { let mut buffer = layer_buffer.unwrap(); - draw_target.snapshot().get_data_surface().with_data(|data| { + draw_target.snapshot().get_data_surface().with_data(|&mut:data| { buffer.native_surface.upload(native_graphics_context!(self), data); debug!("painting worker thread uploading to native surface {}", buffer.native_surface.get_id()); diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index f34f158c39d..2e13a4f39aa 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -8,6 +8,7 @@ use font::{FontHandleMethods, FontMetrics, FontTableMethods}; use font::{FontTableTag, FractionalPixel}; use servo_util::geometry::Au; use servo_util::geometry; +use servo_util::str::c_str_to_string; use platform::font_context::FontContextHandle; use text::glyph::GlyphId; use text::util::{float_to_fixed, fixed_to_float}; @@ -25,11 +26,10 @@ use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics, struct_FT_Vector_ use freetype::freetype::{ft_sfnt_os2}; use freetype::tt_os2::TT_OS2; +use libc::c_char; use std::mem; use std::num::Float; use std::ptr; -use std::string::String; - use std::sync::Arc; fn float_to_fixed_ft(f: f64) -> i32 { @@ -43,7 +43,7 @@ fn fixed_to_float_ft(f: i32) -> f64 { pub struct FontTable; impl FontTableMethods for FontTable { - fn with_buffer(&self, _blk: |*const u8, uint|) { + fn with_buffer<F>(&self, _blk: F) where F: FnOnce(*const u8, uint) { panic!() } } @@ -121,10 +121,14 @@ impl FontHandleMethods for FontHandle { self.font_data.clone() } fn family_name(&self) -> String { - unsafe { String::from_raw_buf(&*(*self.face).family_name as *const i8 as *const u8) } + unsafe { + c_str_to_string((*self.face).family_name as *const c_char) + } } fn face_name(&self) -> String { - unsafe { String::from_raw_buf(&*FT_Get_Postscript_Name(self.face) as *const i8 as *const u8) } + unsafe { + c_str_to_string(FT_Get_Postscript_Name(self.face) as *const c_char) + } } fn is_italic(&self) -> bool { unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 } @@ -253,7 +257,7 @@ impl FontHandleMethods for FontHandle { line_gap: height, }; - debug!("Font metrics (@{} pt): {}", geometry::to_pt(em_size), metrics); + debug!("Font metrics (@{} pt): {:?}", geometry::to_pt(em_size), metrics); return metrics; } diff --git a/components/gfx/platform/freetype/font_context.rs b/components/gfx/platform/freetype/font_context.rs index e978cfd48cd..1c58233f0f7 100644 --- a/components/gfx/platform/freetype/font_context.rs +++ b/components/gfx/platform/freetype/font_context.rs @@ -37,12 +37,12 @@ extern fn ft_realloc(_mem: FT_Memory, _cur_size: c_long, new_size: c_long, block } } -#[deriving(Clone)] +#[derive(Clone)] pub struct FreeTypeLibraryHandle { pub ctx: FT_Library, } -#[deriving(Clone)] +#[derive(Clone)] pub struct FontContextHandle { pub ctx: Rc<FreeTypeLibraryHandle>, } diff --git a/components/gfx/platform/freetype/font_list.rs b/components/gfx/platform/freetype/font_list.rs index 31f7bc6aeb1..fbe354556c4 100644 --- a/components/gfx/platform/freetype/font_list.rs +++ b/components/gfx/platform/freetype/font_list.rs @@ -20,17 +20,19 @@ use fontconfig::fontconfig::{ FcObjectSetAdd, FcPatternGetInteger }; +use servo_util::str::c_str_to_string; + use libc; -use libc::c_int; +use libc::{c_int, c_char}; use std::borrow::ToOwned; +use std::ffi::CString; use std::ptr; -use std::string::String; static FC_FAMILY: &'static [u8] = b"family\0"; static FC_FILE: &'static [u8] = b"file\0"; static FC_INDEX: &'static [u8] = b"index\0"; -pub fn get_available_families(callback: |String|) { +pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) { unsafe { let config = FcConfigGetCurrent(); let fontSet = FcConfigGetFonts(config, FcSetSystem); @@ -38,8 +40,8 @@ pub fn get_available_families(callback: |String|) { let font = (*fontSet).fonts.offset(i); let mut family: *mut FcChar8 = ptr::null_mut(); let mut v: c_int = 0; - while FcPatternGetString(*font, FC_FAMILY.as_ptr() as *mut i8, v, &mut family) == FcResultMatch { - let family_name = String::from_raw_buf(family as *const i8 as *const u8); + while FcPatternGetString(*font, FC_FAMILY.as_ptr() as *mut c_char, v, &mut family) == FcResultMatch { + let family_name = c_str_to_string(family as *const c_char); callback(family_name); v += 1; } @@ -47,7 +49,9 @@ pub fn get_available_families(callback: |String|) { } } -pub fn get_variations_for_family(family_name: &str, callback: |String|) { +pub fn get_variations_for_family<F>(family_name: &str, mut callback: F) + where F: FnMut(String) +{ debug!("getting variations for {}", family_name); unsafe { let config = FcConfigGetCurrent(); @@ -55,16 +59,16 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) { let font_set_array_ptr = &mut font_set; let pattern = FcPatternCreate(); assert!(!pattern.is_null()); - let mut family_name_c = family_name.to_c_str(); - let family_name = family_name_c.as_mut_ptr(); - let ok = FcPatternAddString(pattern, FC_FAMILY.as_ptr() as *mut i8, family_name as *mut FcChar8); + let family_name_c = CString::from_slice(family_name.as_bytes()); + let family_name = family_name_c.as_ptr(); + let ok = FcPatternAddString(pattern, FC_FAMILY.as_ptr() as *mut c_char, family_name as *mut FcChar8); assert!(ok != 0); let object_set = FcObjectSetCreate(); assert!(!object_set.is_null()); - FcObjectSetAdd(object_set, FC_FILE.as_ptr() as *mut i8); - FcObjectSetAdd(object_set, FC_INDEX.as_ptr() as *mut i8); + FcObjectSetAdd(object_set, FC_FILE.as_ptr() as *mut c_char); + FcObjectSetAdd(object_set, FC_INDEX.as_ptr() as *mut c_char); let matches = FcFontSetList(config, font_set_array_ptr, 1, pattern, object_set); @@ -73,13 +77,13 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) { for i in range(0, (*matches).nfont as int) { let font = (*matches).fonts.offset(i); let mut file: *mut FcChar8 = ptr::null_mut(); - let file = if FcPatternGetString(*font, FC_FILE.as_ptr() as *mut i8, 0, &mut file) == FcResultMatch { - String::from_raw_buf(file as *const i8 as *const u8) + let file = if FcPatternGetString(*font, FC_FILE.as_ptr() as *mut c_char, 0, &mut file) == FcResultMatch { + c_str_to_string(file as *const c_char) } else { panic!(); }; let mut index: libc::c_int = 0; - let index = if FcPatternGetInteger(*font, FC_INDEX.as_ptr() as *mut i8, 0, &mut index) == FcResultMatch { + let index = if FcPatternGetInteger(*font, FC_INDEX.as_ptr() as *mut c_char, 0, &mut index) == FcResultMatch { index } else { panic!(); @@ -98,8 +102,8 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) { } pub fn get_system_default_family(generic_name: &str) -> Option<String> { - let mut generic_name_c = generic_name.to_c_str(); - let generic_name_ptr = generic_name_c.as_mut_ptr(); + let generic_name_c = CString::from_slice(generic_name.as_bytes()); + let generic_name_ptr = generic_name_c.as_ptr(); unsafe { let pattern = FcNameParse(generic_name_ptr as *mut FcChar8); @@ -112,8 +116,8 @@ pub fn get_system_default_family(generic_name: &str) -> Option<String> { let family_name = if result == FcResultMatch { let mut match_string: *mut FcChar8 = ptr::null_mut(); - FcPatternGetString(family_match, FC_FAMILY.as_ptr() as *mut i8, 0, &mut match_string); - let result = String::from_raw_buf(match_string as *const i8 as *const u8); + FcPatternGetString(family_match, FC_FAMILY.as_ptr() as *mut c_char, 0, &mut match_string); + let result = c_str_to_string(match_string as *const c_char); FcPatternDestroy(family_match); Some(result) } else { diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index 2e3aae29dc7..db168c657e6 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -47,7 +47,7 @@ impl FontTable { } impl FontTableMethods for FontTable { - fn with_buffer(&self, blk: |*const u8, uint|) { + fn with_buffer<F>(&self, blk: F) where F: FnOnce(*const u8, uint) { blk(self.data.bytes().as_ptr(), self.data.len() as uint); } } @@ -112,8 +112,8 @@ impl FontHandleMethods for FontHandle { } fn glyph_index(&self, codepoint: char) -> Option<GlyphId> { - let characters: [UniChar, ..1] = [codepoint as UniChar]; - let mut glyphs: [CGGlyph, ..1] = [0 as CGGlyph]; + let characters: [UniChar; 1] = [codepoint as UniChar]; + let mut glyphs: [CGGlyph; 1] = [0 as CGGlyph]; let count: CFIndex = 1; let result = self.ctfont.get_glyphs_for_characters(&characters[0], @@ -179,7 +179,7 @@ impl FontHandleMethods for FontHandle { average_advance: average_advance, line_gap: Au::from_frac_px(line_gap), }; - debug!("Font metrics (@{} pt): {}", self.ctfont.pt_size() as f64, metrics); + debug!("Font metrics (@{} pt): {:?}", self.ctfont.pt_size() as f64, metrics); return metrics; } diff --git a/components/gfx/platform/macos/font_context.rs b/components/gfx/platform/macos/font_context.rs index e65381c3bbc..e35aadb9910 100644 --- a/components/gfx/platform/macos/font_context.rs +++ b/components/gfx/platform/macos/font_context.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#[deriving(Clone)] +#[derive(Clone)] pub struct FontContextHandle { ctx: () } diff --git a/components/gfx/platform/macos/font_list.rs b/components/gfx/platform/macos/font_list.rs index 832db9d947a..4e327cea1b8 100644 --- a/components/gfx/platform/macos/font_list.rs +++ b/components/gfx/platform/macos/font_list.rs @@ -10,7 +10,7 @@ use core_text; use std::borrow::ToOwned; use std::mem; -pub fn get_available_families(callback: |String|) { +pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) { let family_names = core_text::font_collection::get_family_names(); for strref in family_names.iter() { let family_name_ref: CFStringRef = unsafe { mem::transmute(strref) }; @@ -20,7 +20,7 @@ pub fn get_available_families(callback: |String|) { } } -pub fn get_variations_for_family(family_name: &str, callback: |String|) { +pub fn get_variations_for_family<F>(family_name: &str, mut callback: F) where F: FnMut(String) { debug!("Looking for faces of family: {}", family_name); let family_collection = diff --git a/components/gfx/platform/macos/font_template.rs b/components/gfx/platform/macos/font_template.rs index 9c00c729a20..c6eb84d9746 100644 --- a/components/gfx/platform/macos/font_template.rs +++ b/components/gfx/platform/macos/font_template.rs @@ -18,6 +18,9 @@ pub struct FontTemplateData { pub identifier: String, } +unsafe impl Send for FontTemplateData {} +unsafe impl Sync for FontTemplateData {} + impl FontTemplateData { pub fn new(identifier: &str, font_data: Option<Vec<u8>>) -> FontTemplateData { let ctfont = match font_data { diff --git a/components/gfx/text/glyph.rs b/components/gfx/text/glyph.rs index 312c0692847..be4b2d3c4d4 100644 --- a/components/gfx/text/glyph.rs +++ b/components/gfx/text/glyph.rs @@ -9,8 +9,9 @@ use servo_util::geometry::Au; use std::cmp::{Ordering, PartialOrd}; use std::iter::repeat; -use std::num::NumCast; +use std::num::{ToPrimitive, NumCast}; use std::mem; +use std::ops::{Add, Sub, Mul, Neg, Div, Rem, BitAnd, BitOr, BitXor, Shl, Shr, Not}; use std::u16; use std::vec::Vec; use geom::point::Point2D; @@ -23,7 +24,7 @@ use geom::point::Point2D; /// In the uncommon case (multiple glyphs per unicode character, large glyph index/advance, or /// glyph offsets), we pack the glyph count into GlyphEntry, and store the other glyph information /// in DetailedGlyphStore. -#[deriving(Clone, Show, Copy)] +#[derive(Clone, Show, Copy)] struct GlyphEntry { value: u32, } @@ -88,7 +89,7 @@ impl GlyphEntry { pub type GlyphId = u32; // TODO: unify with bit flags? -#[deriving(PartialEq, Copy)] +#[derive(PartialEq, Copy)] pub enum BreakType { None, Normal, @@ -252,7 +253,7 @@ impl GlyphEntry { // Stores data for a detailed glyph, in the case that several glyphs // correspond to one character, or the glyph's data couldn't be packed. -#[deriving(Clone, Show, Copy)] +#[derive(Clone, Show, Copy)] struct DetailedGlyph { id: GlyphId, // glyph's advance, in the text's direction (RTL or RTL) @@ -271,7 +272,7 @@ impl DetailedGlyph { } } -#[deriving(PartialEq, Clone, Eq, Show, Copy)] +#[derive(PartialEq, Clone, Eq, Show, Copy)] struct DetailedGlyphRecord { // source string offset/GlyphEntry offset in the TextRun entry_offset: CharIndex, @@ -320,7 +321,7 @@ impl<'a> DetailedGlyphStore { detail_offset: self.detail_buffer.len() as int, }; - debug!("Adding entry[off={}] for detailed glyphs: {}", entry_offset, glyphs); + debug!("Adding entry[off={:?}] for detailed glyphs: {:?}", entry_offset, glyphs); /* TODO: don't actually assert this until asserts are compiled in/out based on severity, debug/release, etc. This assertion @@ -340,7 +341,7 @@ impl<'a> DetailedGlyphStore { fn get_detailed_glyphs_for_entry(&'a self, entry_offset: CharIndex, count: u16) -> &'a [DetailedGlyph] { - debug!("Requesting detailed glyphs[n={}] for entry[off={}]", count, entry_offset); + debug!("Requesting detailed glyphs[n={}] for entry[off={:?}]", count, entry_offset); // FIXME: Is this right? --pcwalton // TODO: should fix this somewhere else @@ -412,7 +413,7 @@ impl<'a> DetailedGlyphStore { // This struct is used by GlyphStore clients to provide new glyph data. // It should be allocated on the stack and passed by reference to GlyphStore. -#[deriving(Copy)] +#[derive(Copy)] pub struct GlyphData { id: GlyphId, advance: Au, @@ -445,7 +446,7 @@ impl GlyphData { // through glyphs (either for a particular TextRun offset, or all glyphs). // Rather than eagerly assembling and copying glyph data, it only retrieves // values as they are needed from the GlyphStore, using provided offsets. -#[deriving(Copy)] +#[derive(Copy)] pub enum GlyphInfo<'a> { Simple(&'a GlyphStore, CharIndex), Detail(&'a GlyphStore, CharIndex, u16), @@ -514,7 +515,7 @@ pub struct GlyphStore { } int_range_index! { - #[deriving(Encodable)] + #[derive(RustcEncodable)] #[doc = "An index that refers to a character in a text run. This could \ point to the middle of a glyph."] struct CharIndex(int) @@ -580,11 +581,11 @@ impl<'a> GlyphStore { let entry = match first_glyph_data.is_missing { true => GlyphEntry::missing(glyph_count), false => { - let glyphs_vec = Vec::from_fn(glyph_count as uint, |i| { + let glyphs_vec: Vec<DetailedGlyph> = (0..glyph_count as uint).map(|&:i| { DetailedGlyph::new(data_for_glyphs[i].id, data_for_glyphs[i].advance, data_for_glyphs[i].offset) - }); + }).collect(); self.detail_store.add_detailed_glyphs_for_entry(i, glyphs_vec.as_slice()); GlyphEntry::complex(first_glyph_data.cluster_start, @@ -593,7 +594,7 @@ impl<'a> GlyphStore { } }.adapt_character_flags_of_entry(self.entry_buffer[i.to_uint()]); - debug!("Adding multiple glyphs[idx={}, count={}]: {}", i, glyph_count, entry); + debug!("Adding multiple glyphs[idx={:?}, count={}]: {:?}", i, glyph_count, entry); self.entry_buffer[i.to_uint()] = entry; } @@ -603,7 +604,7 @@ impl<'a> GlyphStore { assert!(i < self.char_len()); let entry = GlyphEntry::complex(cluster_start, ligature_start, 0); - debug!("adding spacer for chracter without associated glyph[idx={}]", i); + debug!("adding spacer for chracter without associated glyph[idx={:?}]", i); self.entry_buffer[i.to_uint()] = entry; } @@ -725,7 +726,9 @@ impl<'a> GlyphIterator<'a> { } } -impl<'a> Iterator<(CharIndex, GlyphInfo<'a>)> for GlyphIterator<'a> { +impl<'a> Iterator for GlyphIterator<'a> { + type Item = (CharIndex, GlyphInfo<'a>); + // I tried to start with something simpler and apply FlatMap, but the // inability to store free variables in the FlatMap struct was problematic. // @@ -740,7 +743,7 @@ impl<'a> Iterator<(CharIndex, GlyphInfo<'a>)> for GlyphIterator<'a> { self.next_glyph_range() } else { // No glyph range. Look at next character. - self.char_range.next().and_then(|i| { + self.char_range.next().and_then(|:i| { self.char_index = i; assert!(i < self.store.char_len()); let entry = self.store.entry_buffer[i.to_uint()]; diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index da5b6f3435e..f98d47fe547 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -9,12 +9,12 @@ use servo_util::geometry::Au; use servo_util::range::Range; use servo_util::vec::{Comparator, FullBinarySearchMethods}; use std::cmp::Ordering; -use std::slice::Items; +use std::slice::Iter; use std::sync::Arc; use text::glyph::{CharIndex, GlyphStore}; /// A single "paragraph" of text in one font size and style. -#[deriving(Clone)] +#[derive(Clone)] pub struct TextRun { pub text: Arc<String>, pub font_template: Arc<FontTemplateData>, @@ -25,7 +25,7 @@ pub struct TextRun { } /// A single series of glyphs within a text run. -#[deriving(Clone)] +#[derive(Clone)] pub struct GlyphRun { /// The glyphs. pub glyph_store: Arc<GlyphStore>, @@ -34,7 +34,7 @@ pub struct GlyphRun { } pub struct NaturalWordSliceIterator<'a> { - glyph_iter: Items<'a, GlyphRun>, + glyph_iter: Iter<'a, GlyphRun>, range: Range<CharIndex>, } @@ -73,7 +73,9 @@ impl<'a> TextRunSlice<'a> { } } -impl<'a> Iterator<TextRunSlice<'a>> for NaturalWordSliceIterator<'a> { +impl<'a> Iterator for NaturalWordSliceIterator<'a> { + type Item = TextRunSlice<'a>; + // inline(always) due to the inefficient rt failures messing up inline heuristics, I think. #[inline(always)] fn next(&mut self) -> Option<TextRunSlice<'a>> { @@ -101,11 +103,13 @@ impl<'a> Iterator<TextRunSlice<'a>> for NaturalWordSliceIterator<'a> { pub struct CharacterSliceIterator<'a> { glyph_run: Option<&'a GlyphRun>, - glyph_run_iter: Items<'a, GlyphRun>, + glyph_run_iter: Iter<'a, GlyphRun>, range: Range<CharIndex>, } -impl<'a> Iterator<TextRunSlice<'a>> for CharacterSliceIterator<'a> { +impl<'a> Iterator for CharacterSliceIterator<'a> { + type Item = TextRunSlice<'a>; + // inline(always) due to the inefficient rt failures messing up inline heuristics, I think. #[inline(always)] fn next(&mut self) -> Option<TextRunSlice<'a>> { @@ -140,7 +144,9 @@ pub struct LineIterator<'a> { slices: NaturalWordSliceIterator<'a>, } -impl<'a> Iterator<Range<CharIndex>> for LineIterator<'a> { +impl<'a> Iterator for LineIterator<'a> { + type Item = Range<CharIndex>; + fn next(&mut self) -> Option<Range<CharIndex>> { // Loop until we hit whitespace and are in a clump. loop { @@ -311,9 +317,9 @@ impl<'a> TextRun { } pub fn min_width_for_range(&self, range: &Range<CharIndex>) -> Au { - debug!("iterating outer range {}", range); + debug!("iterating outer range {:?}", range); self.natural_word_slices_in_range(range).fold(Au(0), |max_piece_width, slice| { - debug!("iterated on {}[{}]", slice.offset, slice.range); + debug!("iterated on {:?}[{:?}]", slice.offset, slice.range); Au::max(max_piece_width, self.advance_for_range(&slice.range)) }) } diff --git a/components/gfx/text/util.rs b/components/gfx/text/util.rs index 24c916a1ba1..4b8f5041143 100644 --- a/components/gfx/text/util.rs +++ b/components/gfx/text/util.rs @@ -4,7 +4,7 @@ use text::glyph::CharIndex; -#[deriving(PartialEq, Eq, Copy)] +#[derive(PartialEq, Eq, Copy)] pub enum CompressionMode { CompressNone, CompressWhitespace, |