diff options
Diffstat (limited to 'components/gfx/text')
-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 |
3 files changed, 36 insertions, 27 deletions
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, |