Skip to content

Commit

Permalink
Delete old range, s/MutableRange/Range/g;
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian J. Burg committed Nov 19, 2012
1 parent da17ede commit 2a1e97c
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 110 deletions.
6 changes: 3 additions & 3 deletions src/servo-gfx/display_list.rs
Expand Up @@ -3,7 +3,7 @@ use geometry::Au;
use image::base::Image;
use render_context::RenderContext;
use text::SendableTextRun;
use util::range::MutableRange;
use util::range::Range;

use azure::azure_hl::DrawTarget;
use core::dvec::DVec;
Expand All @@ -27,7 +27,7 @@ pub enum DisplayItem {
// TODO: need to provide spacing data for text run.
// (i.e, to support rendering of CSS 'word-spacing' and 'letter-spacing')
// TODO: don't copy text runs, ever.
Text(DisplayItemData, ~SendableTextRun, MutableRange, Color),
Text(DisplayItemData, ~SendableTextRun, Range, Color),
Image(DisplayItemData, ARC<~image::base::Image>),
Border(DisplayItemData, Au, Color)
}
Expand Down Expand Up @@ -71,7 +71,7 @@ impl DisplayItem {

static pure fn new_Text(bounds: &Rect<Au>,
run: ~SendableTextRun,
range: MutableRange,
range: Range,
color: Color) -> DisplayItem {
Text(DisplayItemData::new(bounds), move run, move range, color)
}
Expand Down
10 changes: 5 additions & 5 deletions src/servo-gfx/font.rs
Expand Up @@ -2,7 +2,7 @@ use color::Color;
use font_context::FontContext;
use geometry::Au;
use render_context::RenderContext;
use util::range::{Range, MutableRange};
use util::range::Range;
use text::glyph::{GlyphStore, GlyphIndex};
use text::{Shaper, TextRun};

Expand Down Expand Up @@ -372,10 +372,10 @@ impl Font {
pub trait FontMethods {
fn draw_text_into_context(rctx: &RenderContext,
run: &TextRun,
range: &MutableRange,
range: &Range,
baseline_origin: Point2D<Au>,
color: Color);
fn measure_text(&TextRun, &const MutableRange) -> RunMetrics;
fn measure_text(&TextRun, &const Range) -> RunMetrics;
fn shape_text(@self, &str) -> GlyphStore;
fn get_descriptor() -> FontDescriptor;

Expand All @@ -388,7 +388,7 @@ pub trait FontMethods {
pub impl Font : FontMethods {
fn draw_text_into_context(rctx: &RenderContext,
run: &TextRun,
range: &const MutableRange,
range: &const Range,
baseline_origin: Point2D<Au>,
color: Color) {
use libc::types::common::c99::{uint16_t, uint32_t};
Expand Down Expand Up @@ -445,7 +445,7 @@ pub impl Font : FontMethods {
ptr::null());
}

fn measure_text(run: &TextRun, range: &const MutableRange) -> RunMetrics {
fn measure_text(run: &TextRun, range: &const Range) -> RunMetrics {
assert range.is_valid_for_string(run.text);

// TODO(Issue #199): alter advance direction for RTL
Expand Down
1 change: 0 additions & 1 deletion src/servo-gfx/render_context.rs
Expand Up @@ -4,7 +4,6 @@ use geometry::Au;
use image::base::Image;
use opts::Opts;
use text::TextRun;
use util::range::Range;

use azure::azure_hl::{AsAzureRect, B8G8R8A8, Color, ColorPattern, DrawOptions};
use azure::azure_hl::{DrawSurfaceOptions, DrawTarget, Linear, StrokeOptions};
Expand Down
8 changes: 4 additions & 4 deletions src/servo-gfx/text/glyph.rs
@@ -1,6 +1,6 @@
use au = geometry;
use au::Au;
use servo_gfx_util::range::MutableRange;
use servo_gfx_util::range::Range;
use servo_gfx_util::vec::*;

use core::cmp::{Ord, Eq};
Expand Down Expand Up @@ -582,13 +582,13 @@ impl GlyphStore {
return true;
}

fn iter_glyphs_for_range(&self, range: &const MutableRange, cb: fn&(uint, GlyphInfo/&) -> bool) {
fn iter_glyphs_for_range(&self, range: &const Range, cb: fn&(uint, GlyphInfo/&) -> bool) {
assert range.begin() < self.entry_buffer.len();
assert range.end() <= self.entry_buffer.len();

for range.eachi |i| {
if !self.iter_glyphs_for_index(i, cb) { break; }
}
if !self.iter_glyphs_for_index(i, cb) { break; }
}
}

fn iter_all_glyphs(cb: fn&(uint, GlyphInfo/&) -> bool) {
Expand Down
6 changes: 3 additions & 3 deletions src/servo-gfx/text/harfbuzz/shaper.rs
Expand Up @@ -13,7 +13,7 @@ use font::{

use glyph::{GlyphStore, GlyphIndex, GlyphData};
use servo_util::range;
use range::MutableRange;
use range::Range;

use core::libc::types::common::c99::int32_t;
use core::libc::{c_uint, c_int, c_void, c_char};
Expand Down Expand Up @@ -250,10 +250,10 @@ pub impl HarfbuzzShaper {
}

// some helpers
let mut glyph_span : MutableRange = range::empty_mut();
let mut glyph_span : Range = 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 : MutableRange = range::empty_mut();
let mut char_byte_span : Range = Range::empty();
let mut y_pos = Au(0);

// main loop over each glyph. each iteration usually processes 1 glyph and 1+ chars.
Expand Down
16 changes: 8 additions & 8 deletions src/servo-gfx/text/text_run.rs
Expand Up @@ -2,7 +2,7 @@ use font_context::FontContext;
use geometry::Au;
use glyph::GlyphStore;
use servo_gfx_font::{Font, FontDescriptor, RunMetrics};
use servo_gfx_util::range::{Range, MutableRange};
use servo_gfx_util::range::Range;

use core::libc::{c_void};
use geom::point::Point2D;
Expand Down Expand Up @@ -60,7 +60,7 @@ impl TextRun {

pure fn glyphs(&self) -> &self/GlyphStore { &self.glyphs }

pure fn range_is_trimmable_whitespace(&self, range: &const MutableRange) -> bool {
pure fn range_is_trimmable_whitespace(&self, range: &const Range) -> bool {
let mut i = range.begin();
while i < range.end() {
// jump i to each new char
Expand All @@ -74,11 +74,11 @@ impl TextRun {
return true;
}

fn metrics_for_range(&self, range: &const MutableRange) -> RunMetrics {
fn metrics_for_range(&self, range: &const Range) -> RunMetrics {
self.font.measure_text(self, range)
}

fn min_width_for_range(&self, range: &const MutableRange) -> Au {
fn min_width_for_range(&self, range: &const Range) -> Au {
assert range.is_valid_for_string(self.text);

let mut max_piece_width = Au(0);
Expand All @@ -89,10 +89,10 @@ impl TextRun {
return max_piece_width;
}

fn iter_natural_lines_for_range(&self, range: &const MutableRange, f: fn(&const MutableRange) -> bool) {
fn iter_natural_lines_for_range(&self, range: &const Range, f: fn(&const Range) -> bool) {
assert range.is_valid_for_string(self.text);

let mut clump = MutableRange::new(range.begin(), 0);
let mut clump = Range::new(range.begin(), 0);
let mut in_clump = false;

// clump non-linebreaks of nonzero length
Expand All @@ -117,10 +117,10 @@ impl TextRun {
}
}

fn iter_indivisible_pieces_for_range(&self, range: &const MutableRange, f: fn(&const MutableRange) -> bool) {
fn iter_indivisible_pieces_for_range(&self, range: &const Range, f: fn(&const Range) -> bool) {
assert range.is_valid_for_string(self.text);

let mut clump = MutableRange::new(range.begin(), 0);
let mut clump = Range::new(range.begin(), 0);
loop {
// find next non-whitespace byte index, then clump all whitespace before it.
match str::find_between(self.text, clump.begin(), range.end(), |c| !char::is_whitespace(c)) {
Expand Down
66 changes: 9 additions & 57 deletions src/servo-gfx/util/range.rs
@@ -1,20 +1,3 @@
pub struct Range {
priv off: u16,
priv len: u16
}

pub pure fn Range(off: uint, len: uint) -> Range {
assert off <= u16::max_value as uint;
assert len <= u16::max_value as uint;

Range {
off: off as u16,
len: len as u16
}
}

pub pure fn empty() -> Range { Range(0,0) }

enum RangeRelation {
OverlapsBegin(/* overlap */ uint),
OverlapsEnd(/* overlap */ uint),
Expand All @@ -25,53 +8,22 @@ enum RangeRelation {
EntirelyAfter
}

pub impl Range {
pub pure fn begin() -> uint { self.off as uint }
pub pure fn length() -> uint { self.len as uint }
pub pure fn end() -> uint { (self.off as uint) + (self.len as uint) }

pub pure fn eachi(cb: fn&(uint) -> bool) {
do uint::range(self.off as uint,
(self.off as uint) + (self.len as uint)) |i| {
cb(i)
}
}

pub pure fn is_valid_for_string(s: &str) -> bool {
self.begin() < s.len() && self.end() <= s.len() && self.length() <= s.len()
}

pub pure fn shift_by(i: int) -> Range {
Range(((self.off as int) + i) as uint, self.len as uint)
}

pub pure fn extend_by(i: int) -> Range {
Range(self.off as uint, ((self.len as int) + i) as uint)
}

pub pure fn adjust_by(off_i: int, len_i: int) -> Range {
Range(((self.off as int) + off_i) as uint, ((self.len as int) + len_i) as uint)
}
}

pub pure fn empty_mut() -> MutableRange { MutableRange::new(0, 0) }

pub struct MutableRange {
pub struct Range {
priv off: uint,
priv len: uint
}

pub impl MutableRange {
static pub pure fn new(off: uint, len: uint) -> MutableRange {
MutableRange { off: off, len: len }
pub impl Range {
static pub pure fn new(off: uint, len: uint) -> Range {
Range { off: off, len: len }
}

static pub pure fn empty() -> MutableRange {
MutableRange::new(0, 0)
static pub pure fn empty() -> Range {
Range::new(0, 0)
}
}

pub impl MutableRange {
pub impl Range {
pure fn begin(&const self) -> uint { self.off }
pure fn length(&const self) -> uint { self.len }
pure fn end(&const self) -> uint { self.off + self.len }
Expand Down Expand Up @@ -112,7 +64,7 @@ pub impl MutableRange {
/// Computes the relationship between two ranges (`self` and `other`),
/// from the point of view of `self`. So, 'EntirelyBefore' means
/// that the `self` range is entirely before `other` range.
pure fn relation_to_range(&const self, other: &const MutableRange) -> RangeRelation {
pure fn relation_to_range(&const self, other: &const Range) -> RangeRelation {
if other.begin() > self.end() {
return EntirelyBefore;
}
Expand Down Expand Up @@ -140,7 +92,7 @@ pub impl MutableRange {
self, other);
}

fn repair_after_coalesced_range(&mut self, other: &const MutableRange) {
fn repair_after_coalesced_range(&mut self, other: &const Range) {
let relation = self.relation_to_range(other);
debug!("repair_after_coalesced_range: possibly repairing range %?", self);
debug!("repair_after_coalesced_range: relation of original range and coalesced range(%?): %?",
Expand Down
14 changes: 7 additions & 7 deletions src/servo/layout/box.rs
Expand Up @@ -189,8 +189,8 @@ impl RenderBox : RenderBoxMethods {

let mut pieces_processed_count : uint = 0;
let mut remaining_width : Au = max_width;
let mut left_range = MutableRange::new(data.range.begin(), 0);
let mut right_range : Option<MutableRange> = None;
let mut left_range = Range::new(data.range.begin(), 0);
let mut right_range : Option<Range> = None;
debug!("split_to_width: splitting text box (strlen=%u, range=%?, avail_width=%?)",
data.run.text.len(), data.range, max_width);
do data.run.iter_indivisible_pieces_for_range(&const data.range) |piece_range| {
Expand Down Expand Up @@ -218,15 +218,15 @@ impl RenderBox : RenderBoxMethods {
// if there are still things after the trimmable whitespace, create right chunk
if piece_range.end() < data.range.end() {
debug!("split_to_width: case=skipping trimmable trailing whitespace, then split remainder");
right_range = Some(MutableRange::new(piece_range.end(),
data.range.end() - piece_range.end()));
right_range = Some(Range::new(piece_range.end(),
data.range.end() - piece_range.end()));
} else {
debug!("split_to_width: case=skipping trimmable trailing whitespace");
}
} else if piece_range.begin() < data.range.end() {
// still things left, create right chunk
right_range = Some(MutableRange::new(piece_range.begin(),
data.range.end() - piece_range.begin()));
right_range = Some(Range::new(piece_range.begin(),
data.range.end() - piece_range.begin()));
debug!("split_to_width: case=splitting remainder with right range=%?",
right_range);
}
Expand All @@ -239,7 +239,7 @@ impl RenderBox : RenderBoxMethods {
Some(layout::text::adapt_textbox_with_range(self.d(), data.run, &const left_range))
} else { None };

let right_box = option::map_default(&right_range, None, |range: &const MutableRange| {
let right_box = option::map_default(&right_range, None, |range: &const Range| {
Some(layout::text::adapt_textbox_with_range(self.d(), data.run, range))
});

Expand Down
4 changes: 2 additions & 2 deletions src/servo/layout/box_builder.rs
Expand Up @@ -12,7 +12,7 @@ use util::tree;

use core::dvec::DVec;
use gfx::image::holder::ImageHolder;
use gfx::util::range::MutableRange;
use gfx::util::range::Range;
use newcss::values::{CSSDisplay, CSSDisplayBlock, CSSDisplayInline, CSSDisplayInlineBlock};
use newcss::values::{CSSDisplayNone, Inherit, Specified};

Expand Down Expand Up @@ -151,7 +151,7 @@ impl BoxGenerator {
self.flow.inline().boxes.push(*spacer);
}
}
let mut node_range: MutableRange = MutableRange::new(self.range_stack.pop(), 0);
let mut node_range: Range = Range::new(self.range_stack.pop(), 0);
node_range.extend_to(self.flow.inline().boxes.len());
assert node_range.length() > 0;

Expand Down
1 change: 0 additions & 1 deletion src/servo/layout/flow.rs
Expand Up @@ -13,7 +13,6 @@ use geom::rect::Rect;
use geom::point::Point2D;
use gfx::display_list::DisplayList;
use gfx::geometry::Au;
use gfx::util::range::{Range, MutableRange};

/** Servo's experimental layout system builds a tree of FlowContexts
and RenderBoxes, and figures out positions and display attributes of
Expand Down

0 comments on commit 2a1e97c

Please sign in to comment.