зеркало из https://github.com/mozilla/gecko-dev.git
servo: Move to rust-geom
Source-Repo: https://github.com/servo/servo Source-Revision: 3084d15a364e7b20d216d0a19e4fbc2557ba7435
This commit is contained in:
Родитель
7825cb5d7b
Коммит
4a3def20a7
|
@ -1,5 +1,6 @@
|
|||
import dom::rcu::{writer_methods};
|
||||
import gfx::geom::{au, size};
|
||||
import gfx::geometry::au;
|
||||
import geom::size::Size2D;
|
||||
import layout::base::layout_data;
|
||||
import util::tree;
|
||||
import dvec::{dvec, extensions};
|
||||
|
@ -50,7 +51,7 @@ class attr {
|
|||
enum element_subclass {
|
||||
es_unknown,
|
||||
es_div,
|
||||
es_img({mut size: size<au>}),
|
||||
es_img({mut size: Size2D<au>}),
|
||||
es_head
|
||||
}
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
type point<A> = { x: A, y: A };
|
||||
type size<A> = { width: A, height: A };
|
||||
type rect<A> = { origin: point<A>, size: size<A> };
|
||||
|
||||
enum au = int;
|
||||
|
||||
impl size for size<int> {
|
||||
fn area() -> int {
|
||||
self.width * self.height
|
||||
}
|
||||
}
|
||||
|
||||
fn point<A:copy>(x: A, y: A) -> point<A> {
|
||||
{x: x, y: y}
|
||||
}
|
||||
|
||||
fn size<A:copy>(w: A, h: A) -> size<A> {
|
||||
{width: w, height: h}
|
||||
}
|
||||
|
||||
fn box<A:copy>(x: A, y: A, w: A, h: A) -> rect<A> {
|
||||
{origin: point(x, y),
|
||||
size: size(w, h)}
|
||||
}
|
||||
|
||||
fn zero_rect_au() -> rect<au> {
|
||||
let z = au(0);
|
||||
{origin: point(z, z), size: zero_size_au()}
|
||||
}
|
||||
|
||||
fn zero_size_au() -> size<au> {
|
||||
{width: au(0), height: au(0)}
|
||||
}
|
||||
|
||||
pure fn px_to_au(i: int) -> au {
|
||||
au(i * 60)
|
||||
}
|
||||
|
||||
pure fn au_to_px(au: au) -> int {
|
||||
*au / 60
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import geom::point::Point2D;
|
||||
import geom::rect::Rect;
|
||||
import geom::size::Size2D;
|
||||
import num::num;
|
||||
|
||||
enum au = int;
|
||||
|
||||
impl au of num for au {
|
||||
fn add(&&other: au) -> au { au(*self + *other) }
|
||||
fn sub(&&other: au) -> au { au(*self - *other) }
|
||||
fn mul(&&other: au) -> au { au(*self * *other) }
|
||||
fn div(&&other: au) -> au { au(*self / *other) }
|
||||
fn modulo(&&other: au) -> au { au(*self % *other) }
|
||||
fn neg() -> au { au(-*self) }
|
||||
|
||||
fn to_int() -> int { *self }
|
||||
fn from_int(n: int) -> au { au(n) }
|
||||
}
|
||||
|
||||
fn box<A:copy num>(x: A, y: A, w: A, h: A) -> Rect<A> {
|
||||
Rect(Point2D(x, y), Size2D(w, h))
|
||||
}
|
||||
|
||||
fn zero_rect_au() -> Rect<au> {
|
||||
let z = au(0);
|
||||
Rect(Point2D(z, z), Size2D(z, z))
|
||||
}
|
||||
|
||||
fn zero_size_au() -> Size2D<au> {
|
||||
Size2D(au(0), au(0))
|
||||
}
|
||||
|
||||
pure fn px_to_au(i: int) -> au {
|
||||
au(i * 60)
|
||||
}
|
||||
|
||||
pure fn au_to_px(au: au) -> int {
|
||||
*au / 60
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import platform::osmain;
|
||||
import geom::*;
|
||||
import geometry::*;
|
||||
import comm::*;
|
||||
import image::base::image;
|
||||
import dl = layout::display_list;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import gfx::geom;
|
||||
import gfx::geom::size;
|
||||
import geom::size::Size2D;
|
||||
import int::num;
|
||||
|
||||
enum format {
|
||||
fo_rgba_8888
|
||||
|
@ -7,7 +7,7 @@ enum format {
|
|||
}
|
||||
|
||||
type image_surface = {
|
||||
size: geom::size<int>,
|
||||
size: Size2D<int>,
|
||||
format: format,
|
||||
buffer: [u8]
|
||||
};
|
||||
|
@ -20,7 +20,7 @@ impl format for format {
|
|||
}
|
||||
}
|
||||
|
||||
fn image_surface(size: geom::size<int>, format: format) -> image_surface {
|
||||
fn image_surface(size: Size2D<int>, format: format) -> image_surface {
|
||||
{
|
||||
size: copy size,
|
||||
format: format,
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
import dom::base::{element, es_div, es_img, node_data, node_kind, node};
|
||||
import dom::rcu;
|
||||
import dom::rcu::reader_methods;
|
||||
import gfx::geom;
|
||||
import gfx::geom::{size, rect, point, au, zero_size_au};
|
||||
import gfx::geometry;
|
||||
import gfx::geometry::{au, zero_size_au};
|
||||
import geom::point::Point2D;
|
||||
import geom::rect::Rect;
|
||||
import geom::size::Size2D;
|
||||
import image::base::image;
|
||||
import /*layout::*/block::block_layout_methods;
|
||||
import /*layout::*/inline::inline_layout_methods;
|
||||
|
@ -15,7 +18,7 @@ import util::tree;
|
|||
enum box_kind {
|
||||
bk_block,
|
||||
bk_inline,
|
||||
bk_intrinsic(@geom::size<au>),
|
||||
bk_intrinsic(@Size2D<au>),
|
||||
bk_text(@text_box)
|
||||
}
|
||||
|
||||
|
@ -32,7 +35,7 @@ class appearance {
|
|||
enum box = {
|
||||
tree: tree::fields<@box>,
|
||||
node: node,
|
||||
mut bounds: geom::rect<au>,
|
||||
mut bounds: Rect<au>,
|
||||
kind: box_kind,
|
||||
appearance: appearance
|
||||
};
|
||||
|
@ -102,7 +105,7 @@ impl layout_methods for @box {
|
|||
}
|
||||
|
||||
#[doc="The trivial reflow routine for instrinsically-sized frames."]
|
||||
fn reflow_intrinsic(size: geom::size<au>) {
|
||||
fn reflow_intrinsic(size: Size2D<au>) {
|
||||
self.bounds.size = copy size;
|
||||
|
||||
#debug["reflow_intrinsic size=%?", copy self.bounds];
|
||||
|
@ -162,7 +165,7 @@ mod test {
|
|||
}
|
||||
*/
|
||||
|
||||
fn flat_bounds(root: @box) -> [geom::rect<au>] {
|
||||
fn flat_bounds(root: @box) -> [Rect<au>] {
|
||||
let mut r = [];
|
||||
for tree::each_child(btree, root) {|c|
|
||||
r += flat_bounds(c);
|
||||
|
@ -175,13 +178,13 @@ mod test {
|
|||
fn do_layout() {
|
||||
let s = scope();
|
||||
|
||||
fn mk_img(size: size<au>) -> ~dom::base::element_subclass {
|
||||
fn mk_img(size: Size2D<au>) -> ~dom::base::element_subclass {
|
||||
~es_img({mut size: size})
|
||||
}
|
||||
|
||||
let n0 = s.new_node(nk_element(element("img", mk_img(size(au(10),au(10))))));
|
||||
let n1 = s.new_node(nk_element(element("img", mk_img(size(au(10),au(10))))));
|
||||
let n2 = s.new_node(nk_element(element("img", mk_img(size(au(10),au(20))))));
|
||||
let n0 = s.new_node(nk_element(element("img", mk_img(Size2D(au(10),au(10))))));
|
||||
let n1 = s.new_node(nk_element(element("img", mk_img(Size2D(au(10),au(10))))));
|
||||
let n2 = s.new_node(nk_element(element("img", mk_img(Size2D(au(10),au(20))))));
|
||||
let n3 = s.new_node(nk_element(element("div", ~es_div)));
|
||||
|
||||
tree::add_child(s, n3, n0);
|
||||
|
@ -200,10 +203,10 @@ mod test {
|
|||
b3.reflow_block(au(100));
|
||||
let fb = flat_bounds(b3);
|
||||
#debug["fb=%?", fb];
|
||||
assert fb == [geom::box(au(0), au(0), au(10), au(10)), // n0
|
||||
geom::box(au(0), au(10), au(10), au(15)), // n1
|
||||
geom::box(au(0), au(25), au(10), au(20)), // n2
|
||||
geom::box(au(0), au(0), au(100), au(45))]; // n3
|
||||
assert fb == [geometry::box(au(0), au(0), au(10), au(10)), // n0
|
||||
geometry::box(au(0), au(10), au(10), au(15)), // n1
|
||||
geometry::box(au(0), au(25), au(10), au(20)), // n2
|
||||
geometry::box(au(0), au(0), au(100), au(45))]; // n3
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#[doc="Block layout."]
|
||||
|
||||
import gfx::geom::au;
|
||||
import geom::point::Point2D;
|
||||
import geom::size::Size2D;
|
||||
import gfx::geometry::au;
|
||||
import /*layout::*/base::*; // FIXME: Can't get around import *; resolve bug.
|
||||
import util::tree;
|
||||
|
||||
|
@ -24,13 +26,13 @@ impl block_layout_methods for @box {
|
|||
for tree::each_child(btree, self) {|c|
|
||||
let mut blk_available_width = available_width;
|
||||
// FIXME subtract borders, margins, etc
|
||||
c.bounds.origin = {x: au(0), y: au(current_height)};
|
||||
c.bounds.origin = Point2D(au(0), au(current_height));
|
||||
c.reflow(blk_available_width);
|
||||
current_height += *c.bounds.size.height;
|
||||
}
|
||||
|
||||
self.bounds.size = {width: available_width, // FIXME
|
||||
height: au(current_height)};
|
||||
// FIXME: Width is wrong in the calculation below.
|
||||
self.bounds.size = Size2D(available_width, au(current_height));
|
||||
|
||||
#debug["reflow_block size=%?", copy self.bounds];
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import dom::base::{element, es_div, es_img, nk_element, nk_text, node};
|
||||
import dom::style::{display_type, di_block, di_inline, di_none};
|
||||
import dom::rcu::reader_methods;
|
||||
import gfx::geom;
|
||||
import gfx::geometry;
|
||||
import /*layout::*/base::{appearance, bk_block, bk_inline, bk_intrinsic};
|
||||
import /*layout::*/base::{bk_text, box, box_kind, btree, node_methods, ntree};
|
||||
import /*layout::*/base::{rd_tree_ops, wr_tree_ops};
|
||||
|
@ -30,7 +30,7 @@ enum ctxt = {
|
|||
fn new_box(n: node, kind: box_kind) -> @box {
|
||||
@box({tree: tree::empty(),
|
||||
node: n,
|
||||
mut bounds: geom::zero_rect_au(),
|
||||
mut bounds: geometry::zero_rect_au(),
|
||||
kind: kind,
|
||||
appearance: appearance() })
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import gfx::geom::*;
|
||||
import gfx::geometry::*;
|
||||
import geom::rect::Rect;
|
||||
import image::base::image;
|
||||
|
||||
enum item_type {
|
||||
|
@ -10,7 +11,7 @@ enum item_type {
|
|||
|
||||
enum display_item = {
|
||||
item_type: item_type,
|
||||
bounds: rect<au>
|
||||
bounds: Rect<au>
|
||||
};
|
||||
|
||||
type display_list = [display_item];
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
import dom::rcu;
|
||||
import dom::rcu::reader_methods;
|
||||
import gfx::geom::au;
|
||||
import geom::point::Point2D;
|
||||
import geom::size::Size2D;
|
||||
import gfx::geometry::au;
|
||||
import /*layout::*/base::*; // FIXME: Can't get around import *; resolve bug.
|
||||
import /*layout::*/style::style::*; // ditto
|
||||
import util::tree;
|
||||
|
@ -21,15 +23,14 @@ impl inline_layout_methods for @box {
|
|||
let mut current_height = 0;
|
||||
for tree::each_child(btree, self) {
|
||||
|kid|
|
||||
kid.bounds.origin = { x: au(x), y: au(y) };
|
||||
kid.bounds.origin = Point2D(au(x), au(y));
|
||||
kid.reflow(au(inline_available_width));
|
||||
inline_available_width -= *kid.bounds.size.width;
|
||||
x += *kid.bounds.size.width;
|
||||
current_height = int::max(current_height, *kid.bounds.size.height);
|
||||
}
|
||||
|
||||
self.bounds.size = { width: available_width,
|
||||
height: au(current_height) };
|
||||
self.bounds.size = Size2D(available_width, au(current_height));
|
||||
|
||||
#debug["reflow_inline size=%?", copy self.bounds];
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ them to be rendered
|
|||
|
||||
import task::*;
|
||||
import comm::*;
|
||||
import gfx::geom::{au, au_to_px, px_to_au, point, box};
|
||||
import gfx::geometry::{au, au_to_px, box, px_to_au};
|
||||
import geom::point::Point2D;
|
||||
import geom::rect::Rect;
|
||||
import gfx::renderer;
|
||||
import dom::base::node;
|
||||
import dom::rcu::scope;
|
||||
|
@ -52,16 +54,18 @@ fn layout(to_renderer: chan<renderer::msg>) -> chan<msg> {
|
|||
|
||||
#[doc="
|
||||
|
||||
Builds a display list for a box and all its children.
|
||||
Args:
|
||||
-box: the box to build the display list for
|
||||
-origin: the coordinates of upper-left corner of the box containing
|
||||
the passed in box.
|
||||
Builds a display list for a box and all its children.
|
||||
|
||||
# Arguments
|
||||
|
||||
* `box` - The box to build the display list for.
|
||||
* `origin` - The coordinates of upper-left corner of the box containing the
|
||||
passed-in box.
|
||||
|
||||
"]
|
||||
fn build_display_list_from_origin(box: @base::box, origin : point<au>)
|
||||
fn build_display_list_from_origin(box: @base::box, origin: Point2D<au>)
|
||||
-> dl::display_list {
|
||||
let box_origin = point(
|
||||
let box_origin = Point2D(
|
||||
px_to_au(au_to_px(origin.x) + au_to_px(box.bounds.origin.x)),
|
||||
px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y)));
|
||||
#debug("Handed origin %?, box has bounds %?, starting with origin %?", origin, copy box.bounds, box_origin);
|
||||
|
@ -78,7 +82,7 @@ fn build_display_list_from_origin(box: @base::box, origin : point<au>)
|
|||
}
|
||||
|
||||
fn build_display_list(box : @base::box) -> dl::display_list {
|
||||
ret build_display_list_from_origin(box, point(au(0), au(0)));
|
||||
ret build_display_list_from_origin(box, Point2D(au(0), au(0)));
|
||||
}
|
||||
|
||||
#[doc="
|
||||
|
@ -89,13 +93,13 @@ Args:
|
|||
-origin: the coordinates of upper-left corner of the passed in box.
|
||||
|
||||
"]
|
||||
fn box_to_display_item(box: @base::box, origin : point<au>)
|
||||
fn box_to_display_item(box: @base::box, origin: Point2D<au>)
|
||||
-> dl::display_item {
|
||||
let mut item;
|
||||
|
||||
#debug("request to display a box from origin %?", origin);
|
||||
|
||||
let bounds = {origin : origin, size : box.bounds.size};
|
||||
let bounds = Rect(origin, copy box.bounds.size);
|
||||
|
||||
alt (box.appearance.background_image, box.appearance.background_color) {
|
||||
(some(image), some(*)) | (some(image), none) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#[doc="Text layout."]
|
||||
|
||||
import gfx::geom::au;
|
||||
import geom::size::Size2D;
|
||||
import gfx::geometry::au;
|
||||
import /*layout::*/base::*; // FIXME: Can't get around import *; resolve bug.
|
||||
import servo_text::text_run::text_run;
|
||||
|
||||
|
@ -26,16 +27,16 @@ impl text_layout_methods for @box {
|
|||
subbox.run = some(copy run);
|
||||
run.shape();
|
||||
|
||||
self.bounds.size = {
|
||||
width:
|
||||
alt vec::last_opt(run.glyphs.get()) {
|
||||
some(glyph) {
|
||||
au(*glyph.pos.offset.x + *glyph.pos.advance.x)
|
||||
}
|
||||
none { au(0) }
|
||||
},
|
||||
height: au(60 * 14)
|
||||
};
|
||||
self.bounds.size =
|
||||
Size2D(alt vec::last_opt(run.glyphs.get()) {
|
||||
some(glyph) {
|
||||
au(*glyph.pos.offset.x + *glyph.pos.advance.x)
|
||||
}
|
||||
none {
|
||||
au(0)
|
||||
}
|
||||
},
|
||||
au(60 * 14));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@ import dom::base::{attr, element, element_subclass, es_div, es_head, es_img};
|
|||
import dom::base::{es_unknown, methods, nk_element, nk_text, rd_tree_ops};
|
||||
import dom::base::{wr_tree_ops};
|
||||
import dom = dom::base;
|
||||
import dvec::extensions;
|
||||
import geom::size::Size2D;
|
||||
import gfx::geometry;
|
||||
import gfx::geometry::au;
|
||||
import parser = parser::lexer::html;
|
||||
import parser::token;
|
||||
import gfx::geom;
|
||||
import dvec::extensions;
|
||||
|
||||
fn link_up_attribute(scope: dom::node_scope, node: dom::node, -key: str,
|
||||
-value: str) {
|
||||
|
@ -22,14 +24,20 @@ fn link_up_attribute(scope: dom::node_scope, node: dom::node, -key: str,
|
|||
alt *element.subclass {
|
||||
es_img(img) if key == "width" {
|
||||
alt int::from_str(value) {
|
||||
none { /* drop on the floor */ }
|
||||
some(s) { img.size.width = geom::px_to_au(s); }
|
||||
none {
|
||||
// Drop on the floor.
|
||||
}
|
||||
some(s) { img.size.width = geometry::px_to_au(s); }
|
||||
}
|
||||
}
|
||||
es_img(img) if key == "height" {
|
||||
alt int::from_str(value) {
|
||||
none { /* drop on the floor */ }
|
||||
some(s) { img.size.height = geom::px_to_au(s); }
|
||||
none {
|
||||
// Drop on the floor.
|
||||
}
|
||||
some(s) {
|
||||
img.size.height = geometry::px_to_au(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
es_div | es_img(*) | es_head | es_unknown {
|
||||
|
@ -48,10 +56,10 @@ fn build_element_subclass(tag_name: str) -> ~element_subclass {
|
|||
alt tag_name {
|
||||
"div" { ret ~es_div; }
|
||||
"img" {
|
||||
ret ~es_img({mut size: {
|
||||
width: geom::px_to_au(100),
|
||||
height: geom::px_to_au(100)
|
||||
}});
|
||||
ret ~es_img({
|
||||
mut size: Size2D(geometry::px_to_au(100),
|
||||
geometry::px_to_au(100))
|
||||
});
|
||||
}
|
||||
"head" { ret ~es_head; }
|
||||
_ { ret ~es_unknown; }
|
||||
|
|
|
@ -11,6 +11,7 @@ use sdl;
|
|||
use azure;
|
||||
use js;
|
||||
use stb_image;
|
||||
use geom;
|
||||
|
||||
mod dom {
|
||||
mod base;
|
||||
|
@ -19,7 +20,7 @@ mod dom {
|
|||
}
|
||||
|
||||
mod gfx {
|
||||
mod geom;
|
||||
mod geometry;
|
||||
mod surface;
|
||||
mod renderer;
|
||||
mod pngsink;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import gfx::geom::{au, point};
|
||||
import gfx::geometry::au;
|
||||
import geom::point::Point2D;
|
||||
|
||||
#[doc="The position of a glyph on the screen."]
|
||||
class glyph_pos {
|
||||
let advance: point<au>;
|
||||
let offset: point<au>;
|
||||
new(advance: point<au>, offset: point<au>) {
|
||||
let advance: Point2D<au>;
|
||||
let offset: Point2D<au>;
|
||||
new(advance: Point2D<au>, offset: Point2D<au>) {
|
||||
self.advance = advance;
|
||||
self.offset = offset;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import libc::{c_uint, c_int, c_void};
|
|||
import font::font;
|
||||
import glyph::{glyph, glyph_pos};
|
||||
import ptr::{null, addr_of, offset};
|
||||
import gfx::geom::{point, px_to_au};
|
||||
import gfx::geometry::{au, px_to_au};
|
||||
import geom::point::Point2D;
|
||||
|
||||
import unsafe::reinterpret_cast;
|
||||
import harfbuzz::{HB_MEMORY_MODE_READONLY,
|
||||
|
@ -130,10 +131,10 @@ crust fn glyph_func(_font: *hb_font_t,
|
|||
}
|
||||
|
||||
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: hb_glyph_position_t) -> glyph_pos {
|
||||
glyph_pos(point(px_to_au(hb_pos.x_advance as int),
|
||||
px_to_au(hb_pos.y_advance as int)),
|
||||
point(px_to_au(hb_pos.x_offset as int),
|
||||
px_to_au(hb_pos.y_offset as int)))
|
||||
glyph_pos(Point2D(px_to_au(hb_pos.x_advance as int),
|
||||
px_to_au(hb_pos.y_advance as int)),
|
||||
Point2D(px_to_au(hb_pos.x_offset as int),
|
||||
px_to_au(hb_pos.y_offset as int)))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Загрузка…
Ссылка в новой задаче