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