aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/text/glyph.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/gfx/text/glyph.rs')
-rw-r--r--components/gfx/text/glyph.rs35
1 files changed, 19 insertions, 16 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()];