зеркало из https://github.com/mozilla/gecko-dev.git
servo: Fixed compile errors from new macro syntax
Source-Repo: https://github.com/servo/servo Source-Revision: 8861aba3ec9a75c7d4706655ecdac5ea1c6741f9
This commit is contained in:
Родитель
60737d2ed8
Коммит
3bf95a5dec
|
@ -42,18 +42,17 @@ enum PingMsg {
|
|||
fn join_layout(scope: NodeScope, layout: Layout) {
|
||||
|
||||
if scope.is_reader_forked() {
|
||||
listen { |response_from_layout|
|
||||
listen(|response_from_layout| {
|
||||
layout.send(layout_task::PingMsg(response_from_layout));
|
||||
response_from_layout.recv();
|
||||
}
|
||||
});
|
||||
scope.reader_joined();
|
||||
}
|
||||
}
|
||||
|
||||
#[warn(no_non_implicitly_copyable_typarams)]
|
||||
fn Content(layout: Layout) -> Content {
|
||||
spawn_listener::<ControlMsg> {
|
||||
|from_master|
|
||||
spawn_listener::<ControlMsg>(|from_master| {
|
||||
let scope = NodeScope();
|
||||
let rt = jsrt();
|
||||
loop {
|
||||
|
@ -95,11 +94,10 @@ fn Content(layout: Layout) -> Content {
|
|||
let cx = rt.cx();
|
||||
cx.set_default_options_and_version();
|
||||
cx.set_logging_error_reporter();
|
||||
cx.new_compartment(global_class).chain {
|
||||
|compartment|
|
||||
cx.new_compartment(global_class).chain(|compartment| {
|
||||
compartment.define_functions(debug_fns);
|
||||
cx.evaluate_script(compartment.global_obj, bytes, *filename, 1u)
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,5 +108,5 @@ fn Content(layout: Layout) -> Content {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ impl TreeReadMethods of tree::ReadMethods<Node> for NodeScope {
|
|||
}
|
||||
|
||||
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {
|
||||
self.read(node) { |n| f(n.tree) }
|
||||
self.read(node, |n| f(n.tree))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ impl TreeWriteMethods of tree::WriteMethods<Node> for NodeScope {
|
|||
}
|
||||
|
||||
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {
|
||||
self.write(node) { |n| f(n.tree) }
|
||||
self.write(node, |n| f(n.tree))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class ScopeResource<T:send,A> {
|
|||
self.d = d;
|
||||
}
|
||||
drop unsafe {
|
||||
for self.d.free_list.each { |h| free_handle(h); }
|
||||
for self.d.free_list.each |h| { free_handle(h); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,15 +277,15 @@ mod test {
|
|||
let read_chan = comm::chan(read_port);
|
||||
|
||||
// fire up a reader task
|
||||
for uint::range(0u, iter1) { |i|
|
||||
for uint::range(0u, iter1) |i| {
|
||||
s.reader_forked();
|
||||
let wait_chan = task::spawn_listener {|wait_port|
|
||||
for uint::range(0u, iter2) { |_i|
|
||||
let wait_chan = task::spawn_listener(|wait_port| {
|
||||
for uint::range(0u, iter2) |_i| {
|
||||
comm::send(read_chan, henrietta.read(read_characteristic));
|
||||
comm::send(read_chan, ferdinand.read(read_characteristic));
|
||||
comm::recv(wait_port);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
let hrc = henrietta.read(read_characteristic);
|
||||
assert hrc == (i * iter2);
|
||||
|
@ -293,7 +293,7 @@ mod test {
|
|||
let frc = ferdinand.read(read_characteristic);
|
||||
assert frc == i * iter2;
|
||||
|
||||
for uint::range(0u, iter2) { |_i|
|
||||
for uint::range(0u, iter2) |_i| {
|
||||
assert hrc == comm::recv(read_port);
|
||||
s.write(henrietta, mutate);
|
||||
assert frc == comm::recv(read_port);
|
||||
|
|
|
@ -13,7 +13,7 @@ enum Msg {
|
|||
}
|
||||
|
||||
fn Engine<S: Sink send copy>(sink: S) -> Engine {
|
||||
spawn_listener::<Msg> { |request|
|
||||
spawn_listener::<Msg>(|request| {
|
||||
// The renderer
|
||||
let renderer = Renderer(sink);
|
||||
|
||||
|
@ -37,15 +37,14 @@ fn Engine<S: Sink send copy>(sink: S) -> Engine {
|
|||
ExitMsg(sender) {
|
||||
content.send(content::ExitMsg);
|
||||
layout.send(layout_task::ExitMsg);
|
||||
listen {
|
||||
|response_channel|
|
||||
listen(|response_channel| {
|
||||
renderer.send(renderer::ExitMsg(response_channel));
|
||||
response_channel.recv();
|
||||
}
|
||||
});
|
||||
sender.send(());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -42,8 +42,7 @@ impl PngSink of Sink for chan<Msg> {
|
|||
}
|
||||
|
||||
fn PngSink(output: chan<[u8]>) -> PngSink {
|
||||
spawn_listener::<Msg> { |po|
|
||||
|
||||
spawn_listener::<Msg>(|po| {
|
||||
let cairo_surf = cairo_image_surface_create(
|
||||
CAIRO_FORMAT_ARGB32, 800 as c_int, 600 as c_int
|
||||
);
|
||||
|
@ -68,7 +67,7 @@ fn PngSink(output: chan<[u8]>) -> PngSink {
|
|||
|
||||
AzReleaseDrawTarget(draw_target);
|
||||
cairo_surface_destroy(cairo_surf);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn do_draw(sender: chan<AzDrawTargetRef>,
|
||||
|
@ -76,7 +75,7 @@ fn do_draw(sender: chan<AzDrawTargetRef>,
|
|||
output: chan<[u8]>,
|
||||
cairo_surf: *cairo_surface_t) {
|
||||
|
||||
listen {|data_ch: chan<[u8]>|
|
||||
listen(|data_ch: chan<[u8]>| {
|
||||
|
||||
crust fn write_fn(closure: *c_void,
|
||||
data: *c_uchar,
|
||||
|
@ -112,27 +111,25 @@ fn do_draw(sender: chan<AzDrawTargetRef>,
|
|||
|
||||
// Send the PNG image away
|
||||
output.send(result);
|
||||
}
|
||||
});
|
||||
// Send the next draw target to the renderer
|
||||
sender.send(dt);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sanity_check() {
|
||||
listen {
|
||||
|self_channel|
|
||||
listen(|self_channel| {
|
||||
|
||||
let sink = PngSink(self_channel);
|
||||
let renderer = Renderer(sink);
|
||||
|
||||
let dlist = [];
|
||||
renderer.send(RenderMsg(dlist));
|
||||
listen {
|
||||
|from_renderer|
|
||||
listen(|from_renderer| {
|
||||
renderer.send(renderer::ExitMsg(from_renderer));
|
||||
from_renderer.recv();
|
||||
}
|
||||
});
|
||||
|
||||
sink.send(Exit)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -25,9 +25,8 @@ iface Sink {
|
|||
}
|
||||
|
||||
fn Renderer<S: Sink send copy>(sink: S) -> chan<Msg> {
|
||||
task::spawn_listener::<Msg> {|po|
|
||||
listen {
|
||||
|draw_target_ch|
|
||||
task::spawn_listener::<Msg>(|po| {
|
||||
listen(|draw_target_ch| {
|
||||
#debug("renderer: beginning rendering loop");
|
||||
sink.begin_drawing(draw_target_ch);
|
||||
|
||||
|
@ -48,8 +47,8 @@ fn Renderer<S: Sink send copy>(sink: S) -> chan<Msg> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
impl to_float for u8 {
|
||||
|
@ -58,11 +57,8 @@ impl to_float for u8 {
|
|||
}
|
||||
}
|
||||
|
||||
fn draw_display_list(
|
||||
draw_target: AzDrawTargetRef,
|
||||
display_list: dl::display_list
|
||||
) {
|
||||
for display_list.each {|item|
|
||||
fn draw_display_list(draw_target: AzDrawTargetRef, display_list: dl::display_list) {
|
||||
for display_list.each |item| {
|
||||
#debug["drawing %?", item];
|
||||
|
||||
alt item.item_type {
|
||||
|
@ -121,10 +117,8 @@ fn draw_image(draw_target: AzDrawTargetRef, item: dl::display_item,
|
|||
}
|
||||
|
||||
let stride = image.width * image.depth;
|
||||
for uint::range(0u, image.height) {
|
||||
|y|
|
||||
for uint::range(0u, image.width) {
|
||||
|x|
|
||||
for uint::range(0u, image.height) |y| {
|
||||
for uint::range(0u, image.width) |x| {
|
||||
let color = {
|
||||
r: image.data[y * stride + x * image.depth].to_float()
|
||||
as AzFloat,
|
||||
|
@ -195,7 +189,7 @@ fn draw_text(draw_target: AzDrawTargetRef, item: dl::display_item, text_run: Tex
|
|||
};
|
||||
|
||||
let mut origin = Point2D(bounds.origin.x, bounds.origin.y.add(bounds.size.height));
|
||||
let azglyphs = text_run.glyphs.map { |glyph|
|
||||
let azglyphs = text_run.glyphs.map(|glyph| {
|
||||
let azglyph: AzGlyph = {
|
||||
mIndex: glyph.index as uint32_t,
|
||||
mPosition: {
|
||||
|
@ -206,7 +200,7 @@ fn draw_text(draw_target: AzDrawTargetRef, item: dl::display_item, text_run: Tex
|
|||
origin = Point2D(origin.x.add(glyph.pos.advance.x),
|
||||
origin.y.add(glyph.pos.advance.y));
|
||||
azglyph
|
||||
};
|
||||
});
|
||||
|
||||
let glyphbuf: AzGlyphBuffer = unsafe {{
|
||||
mGlyphs: to_ptr(azglyphs),
|
||||
|
|
|
@ -64,7 +64,7 @@ impl NodeTreeReadMethods of tree::ReadMethods<Node> for NTree {
|
|||
}
|
||||
|
||||
fn with_tree_fields<R>(&&n: Node, f: fn(tree::Tree<Node>) -> R) -> R {
|
||||
n.read { |n| f(n.tree) }
|
||||
n.read(|n| f(n.tree))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,15 +93,16 @@ impl layout_methods_priv for @Box {
|
|||
#[doc="Dumps the box tree, for debugging, with indentation."]
|
||||
fn dump_indent(indent: uint) {
|
||||
let mut s = "";
|
||||
for uint::range(0u, indent) {
|
||||
|_i|
|
||||
for uint::range(0u, indent) |_i| {
|
||||
s += " ";
|
||||
}
|
||||
|
||||
s += #fmt("%?", self.kind);
|
||||
#debug["%s", s];
|
||||
|
||||
for BTree.each_child(self) { |kid| kid.dump_indent(indent + 1u) }
|
||||
for BTree.each_child(self) |kid| {
|
||||
kid.dump_indent(indent + 1u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,15 +136,16 @@ impl PrivateNodeMethods for Node {
|
|||
#[doc="Dumps the node tree, for debugging, with indentation."]
|
||||
fn dump_indent(indent: uint) {
|
||||
let mut s = "";
|
||||
for uint::range(0u, indent) {
|
||||
|_i|
|
||||
for uint::range(0u, indent) |_i| {
|
||||
s += " ";
|
||||
}
|
||||
|
||||
s += #fmt("%?", self.read({ |n| copy n.kind }));
|
||||
s += #fmt("%?", self.read(|n| copy n.kind ));
|
||||
#debug["%s", s];
|
||||
|
||||
for NTree.each_child(self) { |kid| kid.dump_indent(indent + 1u) }
|
||||
for NTree.each_child(self) |kid| {
|
||||
kid.dump_indent(indent + 1u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,7 +181,7 @@ mod test {
|
|||
|
||||
fn flat_bounds(root: @Box) -> [Rect<au>] {
|
||||
let mut r = [];
|
||||
for tree::each_child(BTree, root) {|c|
|
||||
for tree::each_child(BTree, root) |c| {
|
||||
r += flat_bounds(c);
|
||||
}
|
||||
ret r + [copy root.bounds];
|
||||
|
|
|
@ -23,7 +23,7 @@ impl block_layout_methods for @Box {
|
|||
// - and recursively computes the bounds for each child
|
||||
|
||||
let mut current_height = 0;
|
||||
for tree::each_child(BTree, self) {|c|
|
||||
for tree::each_child(BTree, self) |c| {
|
||||
let mut blk_available_width = available_width;
|
||||
// FIXME subtract borders, margins, etc
|
||||
c.bounds.origin = Point2D(au(0), au(current_height));
|
||||
|
|
|
@ -43,8 +43,7 @@ impl methods for ctxt {
|
|||
attribute is 'block'.
|
||||
"]
|
||||
fn construct_boxes_for_block_children() {
|
||||
for NTree.each_child(self.parent_node) {
|
||||
|kid|
|
||||
for NTree.each_child(self.parent_node) |kid| {
|
||||
|
||||
// Create boxes for the child. Get its primary box.
|
||||
let kid_box = kid.construct_boxes();
|
||||
|
@ -91,8 +90,7 @@ impl methods for ctxt {
|
|||
attribute is 'inline'.
|
||||
"]
|
||||
fn construct_boxes_for_inline_children() {
|
||||
for NTree.each_child(self.parent_node) {
|
||||
|kid|
|
||||
for NTree.each_child(self.parent_node) |kid| {
|
||||
|
||||
// Construct boxes for the child. Get its primary box.
|
||||
let kid_box = kid.construct_boxes();
|
||||
|
@ -154,7 +152,7 @@ impl box_builder_priv for Node {
|
|||
size.
|
||||
"]
|
||||
fn determine_box_kind() -> BoxKind {
|
||||
alt self.read({ |n| copy n.kind }) {
|
||||
alt self.read(|n| copy n.kind) {
|
||||
~Text(string) {
|
||||
TextBox(@text_box(copy string))
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ fn build_display_list_from_origin(box: @Box, origin: Point2D<au>)
|
|||
|
||||
let mut list = box_to_display_items(box, box_origin);
|
||||
|
||||
for BTree.each_child(box) {|c|
|
||||
for BTree.each_child(box) |c| {
|
||||
#debug("Recursively building display list with origin %?", box_origin);
|
||||
list += build_display_list_from_origin(c, box_origin);
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ impl inline_layout_methods for @Box {
|
|||
let y = 0;
|
||||
let mut x = 0, inline_available_width = *available_width;
|
||||
let mut current_height = 0;
|
||||
for tree::each_child(BTree, self) {
|
||||
|kid|
|
||||
for tree::each_child(BTree, self) |kid| {
|
||||
kid.bounds.origin = Point2D(au(x), au(y));
|
||||
kid.reflow(au(inline_available_width));
|
||||
inline_available_width -= *kid.bounds.size.width;
|
||||
|
|
|
@ -27,7 +27,7 @@ enum Msg {
|
|||
}
|
||||
|
||||
fn Layout(renderer: Renderer) -> Layout {
|
||||
spawn_listener::<Msg> { |request|
|
||||
spawn_listener::<Msg>(|request| {
|
||||
loop {
|
||||
alt request.recv() {
|
||||
PingMsg(ping_channel) {
|
||||
|
@ -54,5 +54,5 @@ fn Layout(renderer: Renderer) -> Layout {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ import style::style_methods;
|
|||
impl ApplyStyleBoxMethods for @Box {
|
||||
fn apply_style_for_subtree() {
|
||||
self.apply_style();
|
||||
for BTree.each_child(self) {
|
||||
|child|
|
||||
for BTree.each_child(self) |child| {
|
||||
child.apply_style_for_subtree();
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +17,7 @@ impl ApplyStyleBoxMethods for @Box {
|
|||
#[doc="Applies CSS style."]
|
||||
fn apply_style() {
|
||||
// Right now, we only handle images.
|
||||
self.node.read {
|
||||
|node|
|
||||
self.node.read(|node| {
|
||||
alt node.kind {
|
||||
~Element(element) {
|
||||
let style = self.node.get_computed_style();
|
||||
|
@ -32,7 +30,7 @@ impl ApplyStyleBoxMethods for @Box {
|
|||
some(url) {
|
||||
// FIXME: Some sort of BASE HREF support!
|
||||
// FIXME: Parse URLs!
|
||||
// FIXME: Don't load synchronously!
|
||||
// FIXME: Do not load synchronously!
|
||||
#debug("loading image from %s", url);
|
||||
let image = @load(url);
|
||||
self.appearance.background_image = some(image);
|
||||
|
@ -47,7 +45,7 @@ impl ApplyStyleBoxMethods for @Box {
|
|||
}
|
||||
_ { /* Ignore. */ }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ impl priv_matching_methods for Node {
|
|||
alt *sel {
|
||||
Child(_, _) | Descendant(_, _) | Sibling(_, _) { ret false; }
|
||||
Element(tag, attrs) {
|
||||
alt self.read { |n| copy *n.kind } {
|
||||
alt self.read(|n| copy *n.kind) {
|
||||
base::Element(elmt) {
|
||||
if !(tag == "*" || tag == elmt.tag_name) {
|
||||
ret false;
|
||||
|
@ -92,7 +92,7 @@ impl priv_matching_methods for Node {
|
|||
alt *sel {
|
||||
Element(str, atts) { ret self.matches_element(sel); }
|
||||
Child(sel1, sel2) {
|
||||
alt self.read { |n| n.tree.parent } {
|
||||
alt self.read(|n| n.tree.parent) {
|
||||
some(parent) {
|
||||
ret self.matches_element(sel2) &&
|
||||
parent.matches_selector(sel1);
|
||||
|
@ -107,7 +107,7 @@ impl priv_matching_methods for Node {
|
|||
|
||||
//loop over all ancestors to check if they are the person
|
||||
//we should be descended from.
|
||||
let mut cur_parent = alt self.read { |n| n.tree.parent } {
|
||||
let mut cur_parent = alt self.read(|n| n.tree.parent) {
|
||||
some(parent) { parent }
|
||||
none { ret false; }
|
||||
};
|
||||
|
@ -115,7 +115,7 @@ impl priv_matching_methods for Node {
|
|||
loop {
|
||||
if cur_parent.matches_selector(sel1) { ret true; }
|
||||
|
||||
cur_parent = alt cur_parent.read { |n| n.tree.parent } {
|
||||
cur_parent = alt cur_parent.read(|n| n.tree.parent) {
|
||||
some(parent) { parent }
|
||||
none { ret false; }
|
||||
};
|
||||
|
@ -125,13 +125,13 @@ impl priv_matching_methods for Node {
|
|||
if !self.matches_element(sel2) { ret false; }
|
||||
|
||||
// Loop over this node's previous siblings to see if they match.
|
||||
alt self.read { |n| n.tree.prev_sibling } {
|
||||
alt self.read(|n| n.tree.prev_sibling) {
|
||||
some(sib) {
|
||||
let mut cur_sib = sib;
|
||||
loop {
|
||||
if cur_sib.matches_selector(sel1) { ret true; }
|
||||
|
||||
cur_sib = alt cur_sib.read { |n| n.tree.prev_sibling } {
|
||||
cur_sib = alt cur_sib.read(|n| n.tree.prev_sibling) {
|
||||
some(sib) { sib }
|
||||
none { break; }
|
||||
};
|
||||
|
@ -141,13 +141,13 @@ impl priv_matching_methods for Node {
|
|||
}
|
||||
|
||||
// check the rest of the siblings
|
||||
alt self.read { |n| n.tree.next_sibling } {
|
||||
alt self.read(|n| n.tree.next_sibling) {
|
||||
some(sib) {
|
||||
let mut cur_sib = sib;
|
||||
loop {
|
||||
if cur_sib.matches_selector(sel1) { ret true; }
|
||||
|
||||
cur_sib = alt cur_sib.read { |n| n.tree.next_sibling } {
|
||||
cur_sib = alt cur_sib.read(|n| n.tree.next_sibling) {
|
||||
some(sib) { sib }
|
||||
none { break; }
|
||||
};
|
||||
|
@ -165,13 +165,13 @@ impl priv_matching_methods for Node {
|
|||
impl priv_style_methods for Node {
|
||||
#[doc="Update the computed style of an HTML element with a style specified by CSS."]
|
||||
fn update_style(decl : StyleDeclaration) {
|
||||
self.aux() { |layout|
|
||||
self.aux(|layout| {
|
||||
alt decl {
|
||||
Display(dis) { layout.computed_style.display = dis; }
|
||||
BackgroundColor(col) { layout.computed_style.back_color = col; }
|
||||
TextColor(*) | FontSize(*) { /* not supported yet */ }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,18 +184,18 @@ impl matching_methods for Node {
|
|||
// the latest rule takes precedence over the others. So we just overwrite style
|
||||
// information as we go.
|
||||
|
||||
for styles.each { |sty|
|
||||
for styles.each |sty| {
|
||||
let (selectors, decls) = copy *sty;
|
||||
for selectors.each { |sel|
|
||||
for selectors.each |sel| {
|
||||
if self.matches_selector(sel) {
|
||||
for decls.each { |decl|
|
||||
for decls.each |decl| {
|
||||
self.update_style(decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.aux() { |a| #debug["Changed the style to: %?", copy *a.computed_style]; }
|
||||
self.aux(|a| #debug["Changed the style to: %?", copy *a.computed_style]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ impl style_priv for Node {
|
|||
auxiliary box in the RCU model) and populates it with the default style.
|
||||
"]
|
||||
fn initialize_style() {
|
||||
let node_kind = self.read { |n| copy *n.kind };
|
||||
let node_kind = self.read(|n| copy *n.kind);
|
||||
let the_layout_data = @LayoutData({
|
||||
mut computed_style : ~default_style_for_node_kind(node_kind),
|
||||
mut box : none
|
||||
|
@ -55,7 +55,7 @@ impl style_methods for Node {
|
|||
fn initialize_style_for_subtree() {
|
||||
self.initialize_style();
|
||||
|
||||
for NTree.each_child(self) { |kid|
|
||||
for NTree.each_child(self) |kid| {
|
||||
kid.initialize_style_for_subtree();
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ impl style_methods for Node {
|
|||
if !self.has_aux() {
|
||||
fail "get_computed_style() called on a node without a style!";
|
||||
}
|
||||
ret copy *self.aux({ |x| copy x }).computed_style;
|
||||
ret copy *self.aux(|x| copy x).computed_style;
|
||||
}
|
||||
|
||||
#[doc="
|
||||
|
@ -80,18 +80,18 @@ impl style_methods for Node {
|
|||
auxiliary box in the RCU model) with the computed style.
|
||||
"]
|
||||
fn recompute_style_for_subtree(styles : arc<Stylesheet>) {
|
||||
listen { |ack_chan|
|
||||
listen(|ack_chan| {
|
||||
let mut i = 0u;
|
||||
|
||||
// Compute the styles of each of our children in parallel
|
||||
for NTree.each_child(self) { |kid|
|
||||
for NTree.each_child(self) |kid| {
|
||||
i = i + 1u;
|
||||
let new_styles = clone(&styles);
|
||||
|
||||
task::spawn { ||
|
||||
task::spawn(|| {
|
||||
kid.recompute_style_for_subtree(new_styles);
|
||||
ack_chan.send(());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
self.match_css_style(*get(&styles));
|
||||
|
@ -101,6 +101,6 @@ impl style_methods for Node {
|
|||
ack_chan.recv();
|
||||
i = i - 1u;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ fn spawn_css_lexer_task(-filename: ~str) -> port<Token> {
|
|||
let result_port = port();
|
||||
let result_chan = chan(result_port);
|
||||
|
||||
task::spawn {||
|
||||
task::spawn(|| {
|
||||
assert (*copy filename).ends_with(".css");
|
||||
let file_try = io::read_whole_file(*filename);
|
||||
|
||||
|
@ -246,7 +246,7 @@ fn spawn_css_lexer_task(-filename: ~str) -> port<Token> {
|
|||
#debug["Failed to open css sheet %s", *copy filename];
|
||||
result_chan.send(Eof);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
ret result_port;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ enum css_message {
|
|||
#[warn(no_non_implicitly_copyable_typarams)]
|
||||
fn link_up_attribute(scope: NodeScope, node: Node, -key: str, -value: str) {
|
||||
// TODO: Implement atoms so that we don't always perform string comparisons.
|
||||
scope.read(node) {
|
||||
|node_contents|
|
||||
scope.read(node, |node_contents| {
|
||||
alt *node_contents.kind {
|
||||
Element(element) {
|
||||
element.attrs.push(~Attr(copy key, copy value));
|
||||
|
@ -55,7 +54,7 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: str, -value: str) {
|
|||
fail "attempt to link up an attribute to a text node"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn build_element_kind(tag_name: str) -> ~ElementKind {
|
||||
|
@ -95,13 +94,13 @@ fn css_link_listener(to_parent : chan<Stylesheet>, from_parent : port<css_messag
|
|||
let result_port = comm::port();
|
||||
let result_chan = comm::chan(result_port);
|
||||
let filename = copy filename;
|
||||
task::spawn{ ||
|
||||
task::spawn(|| {
|
||||
//TODO: deal with extraneous copies
|
||||
let filename <- copy filename;
|
||||
let css_stream = css_lexer::spawn_css_lexer_task(filename);
|
||||
let mut css_rules = css_builder::build_stylesheet(css_stream);
|
||||
result_chan.send(css_rules);
|
||||
}
|
||||
});
|
||||
result_vec += [result_port];
|
||||
}
|
||||
exit {
|
||||
|
@ -112,10 +111,10 @@ fn css_link_listener(to_parent : chan<Stylesheet>, from_parent : port<css_messag
|
|||
|
||||
let css_rules = [];
|
||||
|
||||
let css_rules = result_vec.foldl(css_rules) { |rules, result_port|
|
||||
let css_rules = result_vec.foldl(css_rules, |rules, result_port| {
|
||||
let new_rules = result_port.recv();
|
||||
rules + new_rules
|
||||
};
|
||||
});
|
||||
|
||||
to_parent.send(css_rules);
|
||||
}
|
||||
|
@ -131,9 +130,9 @@ fn build_dom(scope: NodeScope, stream: port<Token>) -> (Node, port<Stylesheet>)
|
|||
// it along the returned port.
|
||||
let style_port = comm::port();
|
||||
let child_chan = comm::chan(style_port);
|
||||
let style_chan = task::spawn_listener { |child_port|
|
||||
let style_chan = task::spawn_listener(|child_port| {
|
||||
css_link_listener(child_chan, child_port);
|
||||
};
|
||||
});
|
||||
|
||||
loop {
|
||||
let token = stream.recv();
|
||||
|
@ -157,7 +156,7 @@ fn build_dom(scope: NodeScope, stream: port<Token>) -> (Node, port<Stylesheet>)
|
|||
// spec) if we close more tags than we open.
|
||||
parser::SelfCloseTag {
|
||||
//TODO: check for things other than the link tag
|
||||
scope.read(cur_node) { |n|
|
||||
scope.read(cur_node, |n| {
|
||||
alt *n.kind {
|
||||
Element(elmt) if elmt.tag_name == "link" {
|
||||
alt elmt.get_attr("rel") {
|
||||
|
@ -175,7 +174,7 @@ fn build_dom(scope: NodeScope, stream: port<Token>) -> (Node, port<Stylesheet>)
|
|||
}
|
||||
_ { /* fall through*/ }
|
||||
}
|
||||
}
|
||||
});
|
||||
cur_node = scope.get_parent(cur_node).get();
|
||||
}
|
||||
parser::EndTag(_) {
|
||||
|
|
|
@ -166,7 +166,7 @@ fn spawn_html_lexer_task(-filename: ~str) -> port<Token> {
|
|||
let html_chan = chan(html_port);
|
||||
let html_file = copy filename;
|
||||
|
||||
task::spawn {||
|
||||
task::spawn(|| {
|
||||
let filename = copy html_file;
|
||||
assert (copy *filename).ends_with(".html");
|
||||
let file_data = io::read_whole_file(*filename).get();
|
||||
|
@ -180,7 +180,7 @@ fn spawn_html_lexer_task(-filename: ~str) -> port<Token> {
|
|||
html_chan.send(token);
|
||||
if should_break { break; }
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
ret html_port;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ enum Msg {
|
|||
}
|
||||
|
||||
fn OSMain() -> OSMain {
|
||||
on_osmain::<Msg> {|po|
|
||||
platform::runmain {||
|
||||
on_osmain::<Msg>(|po| {
|
||||
platform::runmain(|| {
|
||||
#debug("preparing to enter main loop");
|
||||
mainloop(po);
|
||||
}
|
||||
}
|
||||
mainloop(po);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn mainloop(po: port<Msg>) {
|
||||
|
@ -43,17 +43,15 @@ fn mainloop(po: port<Msg>) {
|
|||
let surfaces = surface_set();
|
||||
|
||||
loop {
|
||||
sdl::event::poll_event {|event|
|
||||
sdl::event::poll_event(|event| {
|
||||
|
||||
alt event {
|
||||
sdl::event::keydown_event(_) {
|
||||
key_handlers.iter {|key_ch|
|
||||
key_ch.send(())
|
||||
}
|
||||
key_handlers.iter(|key_ch| key_ch.send(()))
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Handle messages
|
||||
if po.peek() {
|
||||
|
@ -229,13 +227,9 @@ mod platform {
|
|||
|
||||
mod NSApplication {
|
||||
fn sharedApplication() -> id {
|
||||
let klass = str::as_c_str("NSApplication") { |s|
|
||||
objc::objc_getClass(s)
|
||||
};
|
||||
let klass = str::as_c_str("NSApplication", |s| objc::objc_getClass(s));
|
||||
|
||||
let sel = str::as_c_str("sharedApplication") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
let sel = str::as_c_str("sharedApplication", |s| objc::sel_registerName(s));
|
||||
|
||||
let nsapp = objc::objc_msgSend(klass, sel);
|
||||
#debug("nsapp: %d", (nsapp as int));
|
||||
|
@ -246,120 +240,100 @@ mod platform {
|
|||
|
||||
mod NSAutoreleasePool {
|
||||
fn alloc() -> id {
|
||||
let klass = str::as_c_str("NSAutoreleasePool") { |s|
|
||||
objc::objc_getClass(s)
|
||||
};
|
||||
let sel = str::as_c_str("alloc") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
let klass = str::as_c_str("NSAutoreleasePool", |s| objc::objc_getClass(s));
|
||||
let sel = str::as_c_str("alloc", |s| objc::sel_registerName(s));
|
||||
let pool = objc::objc_msgSend(klass, sel);
|
||||
#debug("autorelease pool: %?", pool);
|
||||
ret pool;
|
||||
}
|
||||
fn init(pool: id) {
|
||||
let sel = str::as_c_str("init") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
let sel = str::as_c_str("init", |s| objc::sel_registerName(s));
|
||||
objc::objc_msgSend(pool, sel);
|
||||
}
|
||||
fn release(pool: id) {
|
||||
let sel = str::as_c_str("release") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
let sel = str::as_c_str("release", |s| objc::sel_registerName(s));
|
||||
objc::objc_msgSend(pool, sel);
|
||||
}
|
||||
}
|
||||
|
||||
mod NSApp {
|
||||
fn setDelegate(nsapp: id, main: id) {
|
||||
#debug("NSApp::setDelegate");
|
||||
let sel = str::as_c_str("setDelegate:") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
cocoa::msgSend1Id(nsapp, sel, main);
|
||||
#debug("NSApp::setDelegate");
|
||||
let sel = str::as_c_str("setDelegate:", |s| objc::sel_registerName(s));
|
||||
cocoa::msgSend1Id(nsapp, sel, main);
|
||||
}
|
||||
|
||||
fn run(nsapp: id) {
|
||||
#debug("NSApp::run");
|
||||
let sel = str::as_c_str("run") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
fn run(nsapp: id) {
|
||||
#debug("NSApp::run");
|
||||
let sel = str::as_c_str("run", |s| objc::sel_registerName(s));
|
||||
objc::objc_msgSend(nsapp, sel);
|
||||
}
|
||||
}
|
||||
|
||||
mod MainObj {
|
||||
crust fn applicationDidFinishLaunching(this: id, _sel: SEL) {
|
||||
#debug("applicationDidFinishLaunching");
|
||||
#debug("applicationDidFinishLaunching");
|
||||
|
||||
let fptr: *fn() = ptr::null();
|
||||
str::as_c_str("fptr") { |name|
|
||||
let outValue = unsafe { unsafe::reinterpret_cast(ptr::addr_of(fptr)) };
|
||||
let fptr: *fn() = ptr::null();
|
||||
str::as_c_str("fptr", |name| {
|
||||
let outValue = unsafe { unsafe::reinterpret_cast(ptr::addr_of(fptr)) };
|
||||
#debug("*fptr %?", outValue);
|
||||
objc::object_getInstanceVariable(this, name, outValue)
|
||||
};
|
||||
});
|
||||
|
||||
#debug("getting osmain fptr: %?", fptr);
|
||||
#debug("getting osmain fptr: %?", fptr);
|
||||
|
||||
unsafe {
|
||||
// FIXME: We probably don't want to run the main routine in a crust function
|
||||
unsafe {
|
||||
// FIXME: We probably don't want to run the main routine in a crust function
|
||||
(*fptr)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create(f: fn()) -> id {
|
||||
let NSObject = str::as_c_str("NSObject") { |s|
|
||||
objc::objc_getClass(s)
|
||||
};
|
||||
let MainObj = str::as_c_str("MainObj") { |s|
|
||||
objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t)
|
||||
};
|
||||
fn create(f: fn()) -> id {
|
||||
let NSObject = str::as_c_str("NSObject", |s| ojc::objc_getClass(s));
|
||||
let MainObj = str::as_c_str("MainObj", |s| {
|
||||
objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t)
|
||||
});
|
||||
|
||||
// Add a field to our class to contain a pointer to a rust closure
|
||||
let res = str::as_c_str("fptr") { |name|
|
||||
str::as_c_str("^i") { |types|
|
||||
let res = str::as_c_str("fptr", |name| {
|
||||
str::as_c_str("^i", |types| {
|
||||
objc::class_addIvar(MainObj, name,
|
||||
sys::size_of::<libc::uintptr_t>() as libc::size_t,
|
||||
16u8, types)
|
||||
}
|
||||
};
|
||||
assert res == true;
|
||||
})
|
||||
});
|
||||
assert res == true;
|
||||
|
||||
let launchfn = str::as_c_str("applicationDidFinishLaunching:") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
let _ = str::as_c_str("@@:") { |types|
|
||||
objc::class_addMethod(MainObj, launchfn, applicationDidFinishLaunching, types)
|
||||
};
|
||||
let launchfn = str::as_c_str("applicationDidFinishLaunching:", |s| {
|
||||
objc::sel_registerName(s)
|
||||
});
|
||||
let _ = str::as_c_str("@@:", |types| {
|
||||
objc::class_addMethod(MainObj, launchfn, applicationDidFinishLaunching, types)
|
||||
});
|
||||
|
||||
objc::objc_registerClassPair(MainObj);
|
||||
objc::objc_registerClassPair(MainObj);
|
||||
|
||||
let sel = str::as_c_str("alloc") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
let mainobj = objc::objc_msgSend(MainObj, sel);
|
||||
let sel = str::as_c_str("alloc", |s| objc::sel_registerName(s));
|
||||
let mainobj = objc::objc_msgSend(MainObj, sel);
|
||||
|
||||
let sel = str::as_c_str("init") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
objc::objc_msgSend(mainobj, sel);
|
||||
let sel = str::as_c_str("init", |s| objc::sel_registerName(s));
|
||||
objc::objc_msgSend(mainobj, sel);
|
||||
|
||||
let fptr = ptr::addr_of(f);
|
||||
str::as_c_str("fptr") { |name|
|
||||
#debug("setting osmain fptr: %?", fptr);
|
||||
let value = unsafe { unsafe::reinterpret_cast(fptr) };
|
||||
#debug("*fptr: %?", value);
|
||||
objc::object_setInstanceVariable(mainobj, name, value)
|
||||
};
|
||||
let fptr = ptr::addr_of(f);
|
||||
str::as_c_str("fptr", |name| {
|
||||
#debug("setting osmain fptr: %?", fptr);
|
||||
let value = unsafe { unsafe::reinterpret_cast(fptr) };
|
||||
#debug("*fptr: %?", value);
|
||||
objc::object_setInstanceVariable(mainobj, name, value)
|
||||
});
|
||||
|
||||
ret mainobj;
|
||||
}
|
||||
fn release(mainobj: id) {
|
||||
let sel = str::as_c_str("release") { |s|
|
||||
objc::sel_registerName(s)
|
||||
};
|
||||
objc::objc_msgSend(mainobj, sel);
|
||||
}
|
||||
ret mainobj;
|
||||
}
|
||||
fn release(mainobj: id) {
|
||||
let sel = str::as_c_str("release", |s| objc::sel_registerName(s));
|
||||
objc::objc_msgSend(mainobj, sel);
|
||||
}
|
||||
}
|
||||
|
||||
fn runmain(f: fn()) {
|
||||
|
|
|
@ -34,23 +34,23 @@ fn run_pipeline_screen(urls: [str]) {
|
|||
let engine = Engine(osmain);
|
||||
|
||||
// Send each file to render then wait for keypress
|
||||
listen { |keypress_from_osmain|
|
||||
listen(|keypress_from_osmain| {
|
||||
osmain.send(AddKeyHandler(keypress_from_osmain));
|
||||
|
||||
for urls.each { |filename|
|
||||
for urls.each |filename| {
|
||||
#debug["master: Sending filename `%s`", filename];
|
||||
engine.send(LoadURLMsg(~copy filename));
|
||||
#debug["master: Waiting for keypress"];
|
||||
keypress_from_osmain.recv();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Shut everything down
|
||||
#debug["master: Shut down"];
|
||||
listen { |exit_response_from_engine|
|
||||
listen(|exit_response_from_engine| {
|
||||
engine.send(engine::ExitMsg(exit_response_from_engine));
|
||||
exit_response_from_engine.recv();
|
||||
}
|
||||
});
|
||||
osmain.send(osmain::Exit);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ fn run_pipeline_png(-url: str, outfile: str) {
|
|||
import result::{ok, err};
|
||||
import io::{writer, buffered_file_writer};
|
||||
|
||||
listen { |pngdata_from_sink|
|
||||
listen(|pngdata_from_sink| {
|
||||
let sink = PngSink(pngdata_from_sink);
|
||||
let engine = Engine(sink);
|
||||
let url = copy url;
|
||||
|
@ -73,10 +73,10 @@ fn run_pipeline_png(-url: str, outfile: str) {
|
|||
}
|
||||
err(e) { fail e }
|
||||
}
|
||||
listen { |exit_response_from_engine|
|
||||
listen(|exit_response_from_engine| {
|
||||
engine.send(engine::ExitMsg(exit_response_from_engine));
|
||||
exit_response_from_engine.recv();
|
||||
}
|
||||
});
|
||||
sink.send(pngsink::Exit);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class Font {
|
|||
let mut glyphs: *cairo_glyph_t = null();
|
||||
let mut num_glyphs = 0 as c_int;
|
||||
|
||||
let status = str::as_c_str(codepoint_str) { |codepoint_buf|
|
||||
let status = str::as_c_str(codepoint_str, |codepoint_buf| {
|
||||
cairo_scaled_font_text_to_glyphs(
|
||||
self.cairo_font,
|
||||
0.0 as c_double, 0.0 as c_double,
|
||||
|
@ -60,7 +60,7 @@ class Font {
|
|||
addr_of(glyphs), addr_of(num_glyphs),
|
||||
null(), null(), null()
|
||||
)
|
||||
};
|
||||
});
|
||||
|
||||
ret if status == CAIRO_STATUS_SUCCESS {
|
||||
|
||||
|
@ -195,13 +195,13 @@ fn get_cairo_face(buf: &~[u8]) -> (*cairo_font_face_t, fn@()) {
|
|||
dtor = fn@(move dtor) { FT_Done_FreeType(library).for_sure(); dtor() };
|
||||
|
||||
let face: FT_Face = null();
|
||||
vec::as_buf(*buf) { |cbuf|
|
||||
vec::as_buf(*buf, |cbuf| {
|
||||
if FT_New_Memory_Face(library, cbuf, (*buf).len() as FT_Long,
|
||||
0 as FT_Long, addr_of(face)).failed() {
|
||||
dtor();
|
||||
fail "unable to create FreeType face";
|
||||
}
|
||||
}
|
||||
});
|
||||
dtor = fn@(move dtor) { FT_Done_Face(face).for_sure(); dtor() };
|
||||
|
||||
let cface = cairo_ft_font_face_create_for_ft_face(face, 0 as c_int);
|
||||
|
@ -236,14 +236,14 @@ fn get_cairo_face(buf: &[u8]) -> (*cairo_font_face_t, fn@()) {
|
|||
|
||||
let mut dtor = fn@() { };
|
||||
|
||||
let fontprov = vec::as_buf(*buf) { |cbuf|
|
||||
let fontprov = vec::as_buf(*buf, |cbuf| {
|
||||
CGDataProviderCreateWithData(
|
||||
null(),
|
||||
unsafe { reinterpret_cast(cbuf) },
|
||||
(*buf).len() as size_t,
|
||||
null()
|
||||
)
|
||||
};
|
||||
});
|
||||
dtor = fn@(move dtor) { CGDataProviderRelease(fontprov); dtor() };
|
||||
|
||||
let cgfont = CGFontCreateWithDataProvider(fontprov);
|
||||
|
@ -296,11 +296,7 @@ fn should_get_glyph_advance() {
|
|||
fn should_be_able_to_create_instances_in_multiple_threads() {
|
||||
#[test];
|
||||
|
||||
iter::repeat(10u) {||
|
||||
task::spawn {||
|
||||
create_test_font();
|
||||
}
|
||||
}
|
||||
iter::repeat(10u, || task::spawn(|| {create_test_font();}));
|
||||
}
|
||||
|
||||
fn get_cairo_face_should_fail_and_not_leak_if_font_cant_be_created() {
|
||||
|
|
|
@ -28,35 +28,35 @@ fn with_test_native_font(f: fn@(nf: &NativeFont)) {
|
|||
#[test]
|
||||
#[ignore(cfg(target_os = "macos"))]
|
||||
fn should_get_glyph_indexes() {
|
||||
with_test_native_font { |font|
|
||||
with_test_native_font(|font| {
|
||||
let idx = font.glyph_index('w');
|
||||
assert idx == some(40u);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(cfg(target_os = "macos"))]
|
||||
fn should_return_none_glyph_index_for_bad_codepoints() {
|
||||
with_test_native_font { |font|
|
||||
with_test_native_font(|font| {
|
||||
let idx = font.glyph_index(0 as char);
|
||||
assert idx == none;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(cfg(target_os = "macos"))]
|
||||
fn should_get_glyph_h_advance() {
|
||||
with_test_native_font { |font|
|
||||
with_test_native_font(|font| {
|
||||
let adv = font.glyph_h_advance(40u);
|
||||
assert adv == some(15);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(cfg(target_os = "macos"))]
|
||||
fn should_return_none_glyph_h_advance_for_bad_codepoints() {
|
||||
with_test_native_font { |font|
|
||||
with_test_native_font(|font| {
|
||||
let adv = font.glyph_h_advance(-1 as uint);
|
||||
assert adv == none;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ class FreeTypeNativeFont/& {
|
|||
fn create(lib: FT_Library, buf: &~[u8]) -> result<FreeTypeNativeFont, ()> {
|
||||
assert lib.is_not_null();
|
||||
let face: FT_Face = null();
|
||||
ret vec_as_buf(*buf) {|cbuf|
|
||||
ret vec_as_buf(*buf, |cbuf| {
|
||||
if FT_New_Memory_Face(lib, cbuf, (*buf).len() as FT_Long,
|
||||
0 as FT_Long, addr_of(face)).succeeded() {
|
||||
// FIXME: These values are placeholders
|
||||
|
@ -78,7 +78,7 @@ fn create(lib: FT_Library, buf: &~[u8]) -> result<FreeTypeNativeFont, ()> {
|
|||
} else {
|
||||
err(())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
impl methods for FT_Error {
|
||||
|
@ -89,11 +89,11 @@ fn with_test_native_font(f: fn@(nf: &NativeFont)) {
|
|||
import font::test_font_bin;
|
||||
import unwrap_result = result::unwrap;
|
||||
|
||||
with_lib { |lib|
|
||||
with_lib(|lib| {
|
||||
let buf = test_font_bin();
|
||||
let font = unwrap_result(create(lib, &buf));
|
||||
f(&font);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn with_lib(f: fn@(FT_Library)) {
|
||||
|
@ -105,8 +105,8 @@ fn with_lib(f: fn@(FT_Library)) {
|
|||
|
||||
#[test]
|
||||
fn create_should_return_err_if_buf_is_bogus() {
|
||||
with_lib { |lib|
|
||||
with_lib(|lib| {
|
||||
let buf = &~[];
|
||||
assert create(lib, buf).is_err();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -49,13 +49,13 @@ class QuartzNativeFont/& {
|
|||
}
|
||||
|
||||
fn create(buf: &[u8]) -> result<QuartzNativeFont, ()> {
|
||||
let fontprov = vec::as_buf(*buf) { |cbuf|
|
||||
let fontprov = vec::as_buf(*buf, |cbuf| {
|
||||
CGDataProviderCreateWithData(
|
||||
null(),
|
||||
unsafe { reinterpret_cast(cbuf) },
|
||||
(*buf).len() as size_t,
|
||||
null())
|
||||
};
|
||||
});
|
||||
// FIXME: Error handling
|
||||
assert fontprov.is_not_null();
|
||||
let cgfont = CGFontCreateWithDataProvider(fontprov);
|
||||
|
|
|
@ -38,13 +38,13 @@ when rendered in a specific font.
|
|||
fn shape_text(font: &Font, text: str) -> [Glyph] unsafe {
|
||||
#debug("shaping text '%s'", text);
|
||||
|
||||
let face_blob = vec::as_buf(*(*font).buf()) { |buf|
|
||||
let face_blob = vec::as_buf(*(*font).buf(), |buf| {
|
||||
hb_blob_create(reinterpret_cast(buf),
|
||||
(*(*font).buf()).len() as c_uint,
|
||||
HB_MEMORY_MODE_READONLY,
|
||||
null(),
|
||||
null())
|
||||
};
|
||||
});
|
||||
|
||||
let hbface = hb_face_create(face_blob, 0 as c_uint);
|
||||
let hbfont = hb_font_create(hbface);
|
||||
|
@ -61,12 +61,12 @@ fn shape_text(font: &Font, text: str) -> [Glyph] unsafe {
|
|||
|
||||
hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
|
||||
|
||||
str::as_c_str(text) { |ctext|
|
||||
str::as_c_str(text, |ctext| {
|
||||
hb_buffer_add_utf8(buffer, ctext,
|
||||
text.len() as c_int,
|
||||
0 as c_uint,
|
||||
text.len() as c_int);
|
||||
}
|
||||
});
|
||||
|
||||
hb_shape(hbfont, buffer, null(), 0 as c_uint);
|
||||
|
||||
|
@ -81,7 +81,7 @@ fn shape_text(font: &Font, text: str) -> [Glyph] unsafe {
|
|||
|
||||
let mut glyphs = [];
|
||||
|
||||
for uint::range(0u, info_len as uint) { |i|
|
||||
for uint::range(0u, info_len as uint) |i| {
|
||||
let info_ = offset(info_, i);
|
||||
let pos = offset(pos, i);
|
||||
let codepoint = (*info_).codepoint as uint;
|
||||
|
@ -147,7 +147,7 @@ fn should_get_glyph_indexes() {
|
|||
|
||||
let font = font::create_test_font();
|
||||
let glyphs = shape_text(font, "firecracker");
|
||||
let idxs = glyphs.map { |glyph| glyph.index };
|
||||
let idxs = glyphs.map(|glyph| glyph.index);
|
||||
assert idxs == [32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u];
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ fn should_get_glyph_h_advance() {
|
|||
|
||||
let font = font::create_test_font();
|
||||
let glyphs = shape_text(font, "firecracker");
|
||||
let actual = glyphs.map { |g| g.pos.advance.x };
|
||||
let expected = [6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7].map { |a| px_to_au(a) };
|
||||
let actual = glyphs.map(|g| g.pos.advance.x);
|
||||
let expected = [6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7].map(|a| px_to_au(a));
|
||||
assert expected == actual;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ class TextRun {
|
|||
let pen_start_x = px_to_au(0);
|
||||
let pen_start_y = height;
|
||||
let pen_start = Point2D(pen_start_x, pen_start_y);
|
||||
let pen_end = self.glyphs.foldl(pen_start) { |cur, glyph|
|
||||
let pen_end = self.glyphs.foldl(pen_start, |cur, glyph| {
|
||||
Point2D(cur.x.add(glyph.pos.offset.x).add(glyph.pos.advance.x),
|
||||
cur.y.add(glyph.pos.offset.y).add(glyph.pos.advance.y))
|
||||
};
|
||||
});
|
||||
ret Size2D(pen_end.x, pen_end.y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ iface WriteMethods<T> {
|
|||
}
|
||||
|
||||
fn each_child<T:copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) {
|
||||
let mut p = ops.with_tree_fields(node) { |f| f.first_child };
|
||||
let mut p = ops.with_tree_fields(node, |f| f.first_child);
|
||||
loop {
|
||||
alt copy p {
|
||||
none { ret; }
|
||||
some(c) {
|
||||
if !f(c) { ret; }
|
||||
p = ops.with_tree_fields(c) { |f| f.next_sibling };
|
||||
p = ops.with_tree_fields(c, |f| f.next_sibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,10 +39,9 @@ fn empty<T>() -> Tree<T> {
|
|||
mut next_sibling: none}
|
||||
}
|
||||
|
||||
fn add_child<T:copy,O:WriteMethods<T>>(
|
||||
ops: O, parent: T, child: T) {
|
||||
fn add_child<T:copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
|
||||
|
||||
ops.with_tree_fields(child) { |child_tf|
|
||||
ops.with_tree_fields(child, |child_tf| {
|
||||
alt child_tf.parent {
|
||||
some(_) { fail "Already has a parent"; }
|
||||
none { child_tf.parent = some(parent); }
|
||||
|
@ -51,28 +50,28 @@ fn add_child<T:copy,O:WriteMethods<T>>(
|
|||
assert child_tf.prev_sibling == none;
|
||||
assert child_tf.next_sibling == none;
|
||||
|
||||
ops.with_tree_fields(parent) { |parent_tf|
|
||||
ops.with_tree_fields(parent, |parent_tf| {
|
||||
alt copy parent_tf.last_child {
|
||||
none {
|
||||
parent_tf.first_child = some(child);
|
||||
}
|
||||
some(lc) {
|
||||
let lc = lc; // satisfy alias checker
|
||||
ops.with_tree_fields(lc) { |lc_tf|
|
||||
ops.with_tree_fields(lc, |lc_tf| {
|
||||
assert lc_tf.next_sibling == none;
|
||||
lc_tf.next_sibling = some(child);
|
||||
}
|
||||
});
|
||||
child_tf.prev_sibling = some(lc);
|
||||
}
|
||||
}
|
||||
|
||||
parent_tf.last_child = some(child);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn get_parent<T:copy,O:ReadMethods<T>>(ops: O, node: T) -> option<T> {
|
||||
ops.with_tree_fields(node) { |tf| tf.parent }
|
||||
ops.with_tree_fields(node, |tf| tf.parent)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -106,7 +105,7 @@ mod test {
|
|||
new_dummy(2u)];
|
||||
let p = new_dummy(3u);
|
||||
|
||||
for vec::each(children) {|c|
|
||||
for vec::each(children) |c| {
|
||||
add_child(dtree, p, c);
|
||||
}
|
||||
|
||||
|
@ -117,7 +116,7 @@ mod test {
|
|||
fn add_child_0() {
|
||||
let {p, children} = parent_with_3_children();
|
||||
let mut i = 0u;
|
||||
for each_child(dtree, p) {|c|
|
||||
for each_child(dtree, p) |c| {
|
||||
assert c.value == i;
|
||||
i += 1u;
|
||||
}
|
||||
|
@ -128,7 +127,7 @@ mod test {
|
|||
fn add_child_break() {
|
||||
let {p, _} = parent_with_3_children();
|
||||
let mut i = 0u;
|
||||
for each_child(dtree, p) {|_c|
|
||||
for each_child(dtree, p) |_c| {
|
||||
i += 1u;
|
||||
break;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче