Auto merge of #5571 - jdm:gfx_uint, r=Ms2ger

r? @Ms2ger
This commit is contained in:
bors-servo 2015-04-08 03:06:09 -05:00
commit 83d9ab3ba5
13 changed files with 103 additions and 97 deletions

View file

@ -45,15 +45,15 @@ impl GlyphEntry {
let id_mask = id as u32;
let Au(advance) = advance;
let advance_mask = (advance as u32) << GLYPH_ADVANCE_SHIFT as uint;
let advance_mask = (advance as u32) << GLYPH_ADVANCE_SHIFT;
GlyphEntry::new(id_mask | advance_mask | FLAG_IS_SIMPLE_GLYPH)
}
// Create a GlyphEntry for uncommon case; should be accompanied by
// initialization of the actual DetailedGlyph data in DetailedGlyphStore
fn complex(starts_cluster: bool, starts_ligature: bool, glyph_count: int) -> GlyphEntry {
assert!(glyph_count <= u16::MAX as int);
fn complex(starts_cluster: bool, starts_ligature: bool, glyph_count: usize) -> GlyphEntry {
assert!(glyph_count <= u16::MAX as usize);
debug!("creating complex glyph entry: starts_cluster={}, starts_ligature={}, \
glyph_count={}",
@ -69,17 +69,17 @@ impl GlyphEntry {
if !starts_ligature {
val |= FLAG_NOT_LIGATURE_GROUP_START;
}
val |= (glyph_count as u32) << GLYPH_COUNT_SHIFT as uint;
val |= (glyph_count as u32) << GLYPH_COUNT_SHIFT;
GlyphEntry::new(val)
}
/// Create a GlyphEntry for the case where glyphs couldn't be found for the specified
/// character.
fn missing(glyph_count: int) -> GlyphEntry {
assert!(glyph_count <= u16::MAX as int);
fn missing(glyph_count: usize) -> GlyphEntry {
assert!(glyph_count <= u16::MAX as usize);
GlyphEntry::new((glyph_count as u32) << GLYPH_COUNT_SHIFT as uint)
GlyphEntry::new((glyph_count as u32) << GLYPH_COUNT_SHIFT)
}
}
@ -158,7 +158,7 @@ fn is_simple_glyph_id(id: GlyphId) -> bool {
fn is_simple_advance(advance: Au) -> bool {
match advance.to_u32() {
Some(unsigned_au) =>
(unsigned_au & (GLYPH_ADVANCE_MASK >> GLYPH_ADVANCE_SHIFT as uint)) == unsigned_au,
(unsigned_au & (GLYPH_ADVANCE_MASK >> GLYPH_ADVANCE_SHIFT)) == unsigned_au,
None => false
}
}
@ -171,7 +171,7 @@ impl GlyphEntry {
// getter methods
#[inline(always)]
fn advance(&self) -> Au {
NumCast::from((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT as uint).unwrap()
NumCast::from((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT).unwrap()
}
fn id(&self) -> GlyphId {
@ -201,7 +201,7 @@ impl GlyphEntry {
}
fn can_break_before(&self) -> BreakType {
let flag = ((self.value & FLAG_CAN_BREAK_MASK) >> FLAG_CAN_BREAK_SHIFT as uint) as u8;
let flag = ((self.value & FLAG_CAN_BREAK_MASK) >> FLAG_CAN_BREAK_SHIFT) as u8;
break_flag_to_enum(flag)
}
@ -225,7 +225,7 @@ impl GlyphEntry {
#[inline(always)]
fn set_can_break_before(&self, e: BreakType) -> GlyphEntry {
let flag = (break_enum_to_flag(e) as u32) << FLAG_CAN_BREAK_SHIFT as uint;
let flag = (break_enum_to_flag(e) as u32) << FLAG_CAN_BREAK_SHIFT;
GlyphEntry::new(self.value | flag)
}
@ -233,7 +233,7 @@ impl GlyphEntry {
fn glyph_count(&self) -> u16 {
assert!(!self.is_simple());
((self.value & GLYPH_COUNT_MASK) >> GLYPH_COUNT_SHIFT as uint) as u16
((self.value & GLYPH_COUNT_MASK) >> GLYPH_COUNT_SHIFT) as u16
}
#[inline(always)]
@ -278,7 +278,7 @@ struct DetailedGlyphRecord {
// source string offset/GlyphEntry offset in the TextRun
entry_offset: CharIndex,
// offset into the detailed glyphs buffer
detail_offset: int,
detail_offset: usize,
}
impl PartialOrd for DetailedGlyphRecord {
@ -320,7 +320,7 @@ impl<'a> DetailedGlyphStore {
fn add_detailed_glyphs_for_entry(&mut self, entry_offset: CharIndex, glyphs: &[DetailedGlyph]) {
let entry = DetailedGlyphRecord {
entry_offset: entry_offset,
detail_offset: self.detail_buffer.len() as int,
detail_offset: self.detail_buffer.len(),
};
debug!("Adding entry[off={:?}] for detailed glyphs: {:?}", entry_offset, glyphs);
@ -351,7 +351,7 @@ impl<'a> DetailedGlyphStore {
return &self.detail_buffer[0..0];
}
assert!((count as uint) <= self.detail_buffer.len());
assert!((count as usize) <= self.detail_buffer.len());
assert!(self.lookup_is_sorted);
let key = DetailedGlyphRecord {
@ -362,16 +362,16 @@ impl<'a> DetailedGlyphStore {
let i = (&*self.detail_lookup).binary_search_index(&key)
.expect("Invalid index not found in detailed glyph lookup table!");
assert!(i + (count as uint) <= self.detail_buffer.len());
assert!(i + (count as usize) <= self.detail_buffer.len());
// return a slice into the buffer
&self.detail_buffer[i .. i + count as uint]
&self.detail_buffer[i .. i + count as usize]
}
fn get_detailed_glyph_with_index(&'a self,
entry_offset: CharIndex,
detail_offset: u16)
-> &'a DetailedGlyph {
assert!((detail_offset as uint) <= self.detail_buffer.len());
assert!((detail_offset as usize) <= self.detail_buffer.len());
assert!(self.lookup_is_sorted);
let key = DetailedGlyphRecord {
@ -382,8 +382,8 @@ impl<'a> DetailedGlyphStore {
let i = self.detail_lookup.as_slice().binary_search_index(&key)
.expect("Invalid index not found in detailed glyph lookup table!");
assert!(i + (detail_offset as uint) < self.detail_buffer.len());
&self.detail_buffer[i + (detail_offset as uint)]
assert!(i + (detail_offset as usize) < self.detail_buffer.len());
&self.detail_buffer[i + (detail_offset as usize)]
}
fn ensure_sorted(&mut self) {
@ -528,11 +528,11 @@ int_range_index! {
impl<'a> GlyphStore {
// Initializes the glyph store, but doesn't actually shape anything.
// Use the set_glyph, set_glyphs() methods to store glyph data.
pub fn new(length: int, is_whitespace: bool) -> GlyphStore {
pub fn new(length: usize, is_whitespace: bool) -> GlyphStore {
assert!(length > 0);
GlyphStore {
entry_buffer: repeat(GlyphEntry::initial()).take(length as uint)
entry_buffer: repeat(GlyphEntry::initial()).take(length)
.collect(),
detail_store: DetailedGlyphStore::new(),
is_whitespace: is_whitespace,
@ -591,13 +591,13 @@ impl<'a> GlyphStore {
assert!(i < self.char_len());
assert!(data_for_glyphs.len() > 0);
let glyph_count = data_for_glyphs.len() as int;
let glyph_count = data_for_glyphs.len();
let first_glyph_data = data_for_glyphs[0];
let entry = match first_glyph_data.is_missing {
true => GlyphEntry::missing(glyph_count),
false => {
let glyphs_vec: Vec<DetailedGlyph> = (0..glyph_count as uint).map(|i| {
let glyphs_vec: Vec<DetailedGlyph> = (0..glyph_count).map(|i| {
DetailedGlyph::new(data_for_glyphs[i].id,
data_for_glyphs[i].advance,
data_for_glyphs[i].offset)
@ -730,10 +730,10 @@ impl<'a> GlyphStore {
if entry.is_simple() && entry.char_is_space() {
// FIXME(pcwalton): This can overflow for very large font-sizes.
let advance =
((entry.value & GLYPH_ADVANCE_MASK) >> (GLYPH_ADVANCE_SHIFT as uint)) +
((entry.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT) +
Au::from_frac_px(space).to_u32().unwrap();
entry.value = (entry.value & !GLYPH_ADVANCE_MASK) |
(advance << (GLYPH_ADVANCE_SHIFT as uint));
(advance << GLYPH_ADVANCE_SHIFT);
}
}
}

View file

@ -61,7 +61,7 @@ static KERN: u32 = hb_tag!('k', 'e', 'r', 'n');
static LIGA: u32 = hb_tag!('l', 'i', 'g', 'a');
pub struct ShapedGlyphData {
count: int,
count: usize,
glyph_infos: *mut hb_glyph_info_t,
pos_infos: *mut hb_glyph_position_t,
}
@ -77,16 +77,14 @@ impl ShapedGlyphData {
unsafe {
let mut glyph_count = 0;
let glyph_infos = RUST_hb_buffer_get_glyph_infos(buffer, &mut glyph_count);
let glyph_count = glyph_count as int;
assert!(!glyph_infos.is_null());
let mut pos_count = 0;
let pos_infos = RUST_hb_buffer_get_glyph_positions(buffer, &mut pos_count);
let pos_count = pos_count as int;
assert!(!pos_infos.is_null());
assert!(glyph_count == pos_count);
ShapedGlyphData {
count: glyph_count,
count: glyph_count as usize,
glyph_infos: glyph_infos,
pos_infos: pos_infos,
}
@ -94,26 +92,26 @@ impl ShapedGlyphData {
}
#[inline(always)]
fn byte_offset_of_glyph(&self, i: int) -> int {
fn byte_offset_of_glyph(&self, i: usize) -> u32 {
assert!(i < self.count);
unsafe {
let glyph_info_i = self.glyph_infos.offset(i);
(*glyph_info_i).cluster as int
let glyph_info_i = self.glyph_infos.offset(i as isize);
(*glyph_info_i).cluster
}
}
pub fn len(&self) -> int {
pub fn len(&self) -> usize {
self.count
}
/// Returns shaped glyph data for one glyph, and updates the y-position of the pen.
pub fn get_entry_for_glyph(&self, i: int, y_pos: &mut Au) -> ShapedGlyphEntry {
pub fn get_entry_for_glyph(&self, i: usize, y_pos: &mut Au) -> ShapedGlyphEntry {
assert!(i < self.count);
unsafe {
let glyph_info_i = self.glyph_infos.offset(i);
let pos_info_i = self.pos_infos.offset(i);
let glyph_info_i = self.glyph_infos.offset(i as isize);
let pos_info_i = self.pos_infos.offset(i as isize);
let x_offset = Shaper::fixed_to_float((*pos_info_i).x_offset);
let y_offset = Shaper::fixed_to_float((*pos_info_i).y_offset);
let x_advance = Shaper::fixed_to_float((*pos_info_i).x_advance);
@ -273,8 +271,8 @@ impl Shaper {
buffer: *mut hb_buffer_t) {
let glyph_data = ShapedGlyphData::new(buffer);
let glyph_count = glyph_data.len();
let byte_max = text.len() as int;
let char_max = text.chars().count() as int;
let byte_max = text.len();
let char_max = text.chars().count();
// GlyphStore records are indexed by character, not byte offset.
// so, we must be careful to increment this when saving glyph entries.
@ -296,9 +294,9 @@ impl Shaper {
// fast path: all chars are single-byte.
if byte_max == char_max {
byte_to_glyph = repeat(NO_GLYPH).take(byte_max as uint).collect();
byte_to_glyph = repeat(NO_GLYPH).take(byte_max).collect();
} else {
byte_to_glyph = repeat(CONTINUATION_BYTE).take(byte_max as uint)
byte_to_glyph = repeat(CONTINUATION_BYTE).take(byte_max)
.collect();
for (i, _) in text.char_indices() {
byte_to_glyph[i] = NO_GLYPH;
@ -308,10 +306,10 @@ impl Shaper {
debug!("(glyph idx) -> (text byte offset)");
for i in 0..glyph_data.len() {
// loc refers to a *byte* offset within the utf8 string.
let loc = glyph_data.byte_offset_of_glyph(i);
let loc = glyph_data.byte_offset_of_glyph(i) as usize;
if loc < byte_max {
assert!(byte_to_glyph[loc as uint] != CONTINUATION_BYTE);
byte_to_glyph[loc as uint] = i as i32;
assert!(byte_to_glyph[loc] != CONTINUATION_BYTE);
byte_to_glyph[loc] = i as i32;
} else {
debug!("ERROR: tried to set out of range byte_to_glyph: idx={}, glyph idx={}",
loc,
@ -327,10 +325,10 @@ impl Shaper {
}
// some helpers
let mut glyph_span: Range<int> = Range::empty();
let mut glyph_span: Range<usize> = Range::empty();
// this span contains first byte of first char, to last byte of last char in range.
// so, end() points to first byte of last+1 char, if it's less than byte_max.
let mut char_byte_span: Range<int> = Range::empty();
let mut char_byte_span: Range<usize> = Range::empty();
let mut y_pos = Au(0);
// main loop over each glyph. each iteration usually processes 1 glyph and 1+ chars.
@ -342,33 +340,33 @@ impl Shaper {
debug!("Processing glyph at idx={}", glyph_span.begin());
let char_byte_start = glyph_data.byte_offset_of_glyph(glyph_span.begin());
char_byte_span.reset(char_byte_start, 0);
char_byte_span.reset(char_byte_start as usize, 0);
// find a range of chars corresponding to this glyph, plus
// any trailing chars that do not have associated glyphs.
while char_byte_span.end() < byte_max {
let range = text.char_range_at(char_byte_span.end() as uint);
let range = text.char_range_at(char_byte_span.end());
drop(range.ch);
char_byte_span.extend_to(range.next as int);
char_byte_span.extend_to(range.next);
debug!("Processing char byte span: off={}, len={} for glyph idx={}",
char_byte_span.begin(), char_byte_span.length(), glyph_span.begin());
while char_byte_span.end() != byte_max &&
byte_to_glyph[char_byte_span.end() as uint] == NO_GLYPH {
byte_to_glyph[char_byte_span.end()] == NO_GLYPH {
debug!("Extending char byte span to include byte offset={} with no associated \
glyph", char_byte_span.end());
let range = text.char_range_at(char_byte_span.end() as uint);
let range = text.char_range_at(char_byte_span.end());
drop(range.ch);
char_byte_span.extend_to(range.next as int);
char_byte_span.extend_to(range.next);
}
// extend glyph range to max glyph index covered by char_span,
// in cases where one char made several glyphs and left some unassociated chars.
let mut max_glyph_idx = glyph_span.end();
for i in char_byte_span.each_index() {
if byte_to_glyph[i as uint] > NO_GLYPH {
max_glyph_idx = cmp::max(byte_to_glyph[i as uint] as int + 1, max_glyph_idx);
if byte_to_glyph[i] > NO_GLYPH {
max_glyph_idx = cmp::max(byte_to_glyph[i] as usize + 1, max_glyph_idx);
}
}
@ -392,7 +390,7 @@ impl Shaper {
let mut all_glyphs_are_within_cluster: bool = true;
for j in glyph_span.each_index() {
let loc = glyph_data.byte_offset_of_glyph(j);
if !char_byte_span.contains(loc) {
if !char_byte_span.contains(loc as usize) {
all_glyphs_are_within_cluster = false;
break
}
@ -427,10 +425,10 @@ impl Shaper {
let mut covered_byte_span = char_byte_span.clone();
// extend, clipping at end of text range.
while covered_byte_span.end() < byte_max
&& byte_to_glyph[covered_byte_span.end() as uint] == NO_GLYPH {
let range = text.char_range_at(covered_byte_span.end() as uint);
&& byte_to_glyph[covered_byte_span.end()] == NO_GLYPH {
let range = text.char_range_at(covered_byte_span.end());
drop(range.ch);
covered_byte_span.extend_to(range.next as int);
covered_byte_span.extend_to(range.next);
}
if covered_byte_span.begin() >= byte_max {
@ -456,7 +454,7 @@ impl Shaper {
// NB: When we acquire the ability to handle ligatures that cross word boundaries,
// we'll need to do something special to handle `word-spacing` properly.
let shape = glyph_data.get_entry_for_glyph(glyph_span.begin(), &mut y_pos);
let character = text.char_at(char_byte_span.begin() as uint);
let character = text.char_at(char_byte_span.begin());
let advance = self.advance_for_shaped_glyph(shape.advance, character, options);
let data = GlyphData::new(shape.codepoint,
advance,
@ -486,9 +484,9 @@ impl Shaper {
// set the other chars, who have no glyphs
let mut i = covered_byte_span.begin();
loop {
let range = text.char_range_at(i as uint);
let range = text.char_range_at(i);
drop(range.ch);
i = range.next as int;
i = range.next;
if i >= covered_byte_span.end() { break; }
char_idx = char_idx + CharIndex(1);
glyphs.add_nonglyph_for_char_index(char_idx, false, false);
@ -613,7 +611,7 @@ extern fn get_font_table_func(_: *mut hb_face_t,
let skinny_font_table_ptr: *const FontTable = font_table; // private context
let mut blob: *mut hb_blob_t = ptr::null_mut();
(*skinny_font_table_ptr).with_buffer(|buf: *const u8, len: uint| {
(*skinny_font_table_ptr).with_buffer(|buf: *const u8, len: usize| {
// HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed.
blob = RUST_hb_blob_create(buf as *const c_char,
len as c_uint,

View file

@ -201,7 +201,7 @@ impl<'a> TextRun {
-> Vec<GlyphRun> {
// TODO(Issue #230): do a better job. See Gecko's LineBreaker.
let mut glyphs = vec!();
let (mut byte_i, mut char_i) = (0u, CharIndex(0));
let (mut byte_i, mut char_i) = (0, CharIndex(0));
let mut cur_slice_is_whitespace = false;
let (mut byte_last_boundary, mut char_last_boundary) = (0, CharIndex(0));
while byte_i < text.len() {
@ -330,7 +330,7 @@ impl<'a> TextRun {
}
/// Returns the index of the first glyph run containing the given character index.
fn index_of_first_glyph_run_containing(&self, index: CharIndex) -> Option<uint> {
fn index_of_first_glyph_run_containing(&self, index: CharIndex) -> Option<usize> {
(&**self.glyphs).binary_search_index_by(&index, CharIndexComparator)
}

View file

@ -111,19 +111,19 @@ pub fn transform_text(text: &str,
}
}
pub fn float_to_fixed(before: int, f: f64) -> i32 {
((1i32 << before as uint) as f64 * f) as i32
pub fn float_to_fixed(before: usize, f: f64) -> i32 {
((1i32 << before) as f64 * f) as i32
}
pub fn fixed_to_float(before: int, f: i32) -> f64 {
f as f64 * 1.0f64 / ((1i32 << before as uint) as f64)
pub fn fixed_to_float(before: usize, f: i32) -> f64 {
f as f64 * 1.0f64 / ((1i32 << before) as f64)
}
pub fn fixed_to_rounded_int(before: int, f: i32) -> int {
let half = 1i32 << (before-1) as uint;
pub fn fixed_to_rounded_int(before: isize, f: i32) -> isize {
let half = 1i32 << (before-1) as usize;
if f > 0i32 {
((half + f) >> before as uint) as int
((half + f) >> before) as isize
} else {
-((half - f) >> before as uint) as int
-((half - f) >> before) as isize
}
}