Verified Commit 7c5ecc40 authored by Jordan Petridis's avatar Jordan Petridis 🌱

Rustfmt: Switch 'indent_style' to 'Block'.

Temporarly switch to sidestep https://github.com/rust-lang-nursery/rustfmt/issues/2496
so people can start using rustfmt and the CI test succed.
parent c78d35a7
unstable_features = true
indent_style = "Visual"
indent_style = "Block"
verbose = false
max_width = 100
comment_width = 100
......@@ -15,6 +15,5 @@ reorder_imports = true
reorder_imported_names = true
reorder_imports_in_group = true
use_field_init_shorthand = true
error_on_line_overflow = false
imports_indent = "Block"
imports_layout = "HorizontalVertical"
\ No newline at end of file
......@@ -177,7 +177,10 @@ fn generate_phf_of_svg_attributes() {
writeln!(&mut file, "}}").unwrap();
writeln!(&mut file, "static ATTRIBUTES: phf::Map<&'static str, Attribute> = ").unwrap();
writeln!(
&mut file,
"static ATTRIBUTES: phf::Map<&'static str, Attribute> = "
).unwrap();
let mut map = phf_codegen::Map::new();
map.phf_path("phf");
......
This diff is collapsed.
......@@ -18,9 +18,10 @@ impl FromStr for Attribute {
}
#[no_mangle]
pub extern "C" fn rsvg_attribute_from_name(raw_name: *const libc::c_char,
out_attr: *mut Attribute)
-> glib_sys::gboolean {
pub extern "C" fn rsvg_attribute_from_name(
raw_name: *const libc::c_char,
out_attr: *mut Attribute,
) -> glib_sys::gboolean {
let name = unsafe { utf8_cstr(raw_name) };
match Attribute::from_str(name) {
......@@ -53,8 +54,10 @@ mod tests {
#[test]
fn c_attribute_from_name() {
let mut a: Attribute = unsafe { mem::uninitialized() };
let res: bool =
from_glib(rsvg_attribute_from_name("width".to_glib_none().0, &mut a as *mut Attribute));
let res: bool = from_glib(rsvg_attribute_from_name(
"width".to_glib_none().0,
&mut a as *mut Attribute,
));
assert!(res);
assert_eq!(a, Attribute::Width);
}
......@@ -62,8 +65,10 @@ mod tests {
#[test]
fn invalid_c_attribute_from_name() {
let mut a: Attribute = unsafe { mem::uninitialized() };
let res: bool = from_glib(rsvg_attribute_from_name("foobar".to_glib_none().0,
&mut a as *mut Attribute));
let res: bool = from_glib(rsvg_attribute_from_name(
"foobar".to_glib_none().0,
&mut a as *mut Attribute,
));
assert!(!res);
}
}
......@@ -21,7 +21,7 @@ impl RsvgBbox {
pub fn is_empty(&self) -> bool {
from_glib(self.virgin) || double_equals(self.rect.width, 0.0)
|| double_equals(self.rect.height, 0.0)
|| double_equals(self.rect.height, 0.0)
}
}
......@@ -49,7 +49,12 @@ pub extern "C" fn rsvg_bbox_insert(raw_dst: *mut RsvgBbox, raw_src: *const RsvgB
}
let (mut xmin, mut ymin, mut xmax, mut ymax) = if !dst.is_virgin() {
(dst.rect.x, dst.rect.y, (dst.rect.x + dst.rect.width), (dst.rect.y + dst.rect.height))
(
dst.rect.x,
dst.rect.y,
(dst.rect.x + dst.rect.width),
(dst.rect.y + dst.rect.height),
)
} else {
(0.0, 0.0, 0.0, 0.0)
};
......@@ -112,7 +117,12 @@ pub extern "C" fn rsvg_bbox_clip(raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbo
}
let (mut xmin, mut ymin, mut xmax, mut ymax) = if !dst.is_virgin() {
((dst.rect.x + dst.rect.width), (dst.rect.y + dst.rect.height), dst.rect.x, dst.rect.y)
(
(dst.rect.x + dst.rect.width),
(dst.rect.y + dst.rect.height),
dst.rect.x,
dst.rect.y,
)
} else {
(0.0, 0.0, 0.0, 0.0)
};
......
......@@ -17,7 +17,9 @@ struct NodeClipPath {
impl NodeClipPath {
fn new() -> NodeClipPath {
NodeClipPath { units: Cell::new(ClipPathUnits::default()), }
NodeClipPath {
units: Cell::new(ClipPathUnits::default()),
}
}
}
......@@ -46,12 +48,15 @@ impl NodeTrait for NodeClipPath {
}
#[no_mangle]
pub extern "C" fn rsvg_node_clip_path_new(_: *const libc::c_char,
raw_parent: *const RsvgNode)
-> *const RsvgNode {
boxed_node_new(NodeType::ClipPath,
raw_parent,
Box::new(NodeClipPath::new()))
pub extern "C" fn rsvg_node_clip_path_new(
_: *const libc::c_char,
raw_parent: *const RsvgNode,
) -> *const RsvgNode {
boxed_node_new(
NodeType::ClipPath,
raw_parent,
Box::new(NodeClipPath::new()),
)
}
#[no_mangle]
......@@ -62,8 +67,8 @@ pub extern "C" fn rsvg_node_clip_path_get_units(raw_node: *const RsvgNode) -> Co
let mut units = ClipPathUnits::default();
node.with_impl(|clip_path: &NodeClipPath| {
units = clip_path.units.get();
});
units = clip_path.units.get();
});
CoordUnits::from(units)
}
......@@ -6,14 +6,18 @@ use state::RsvgState;
use std::rc::*;
type CNodeSetAtts = unsafe extern "C" fn(node: *const RsvgNode,
node_impl: *const RsvgCNodeImpl,
handle: *const RsvgHandle,
pbag: *const PropertyBag);
type CNodeDraw = unsafe extern "C" fn(node: *const RsvgNode,
node_impl: *const RsvgCNodeImpl,
draw_ctx: *const RsvgDrawingCtx,
dominate: i32);
type CNodeSetAtts = unsafe extern "C" fn(
node: *const RsvgNode,
node_impl: *const RsvgCNodeImpl,
handle: *const RsvgHandle,
pbag: *const PropertyBag,
);
type CNodeDraw = unsafe extern "C" fn(
node: *const RsvgNode,
node_impl: *const RsvgCNodeImpl,
draw_ctx: *const RsvgDrawingCtx,
dominate: i32,
);
type CNodeFree = unsafe extern "C" fn(node_impl: *const RsvgCNodeImpl);
struct CNode {
......@@ -25,16 +29,19 @@ struct CNode {
}
impl NodeTrait for CNode {
fn set_atts(&self,
node: &RsvgNode,
handle: *const RsvgHandle,
pbag: &PropertyBag)
-> NodeResult {
fn set_atts(
&self,
node: &RsvgNode,
handle: *const RsvgHandle,
pbag: &PropertyBag,
) -> NodeResult {
unsafe {
(self.set_atts_fn)(node as *const RsvgNode,
self.c_node_impl,
handle,
pbag.ffi());
(self.set_atts_fn)(
node as *const RsvgNode,
self.c_node_impl,
handle,
pbag.ffi(),
);
}
Ok(())
......@@ -42,10 +49,12 @@ impl NodeTrait for CNode {
fn draw(&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
unsafe {
(self.draw_fn)(node as *const RsvgNode,
self.c_node_impl,
draw_ctx,
dominate);
(self.draw_fn)(
node as *const RsvgNode,
self.c_node_impl,
draw_ctx,
dominate,
);
}
}
......@@ -63,26 +72,31 @@ impl Drop for CNode {
}
#[no_mangle]
pub extern "C" fn rsvg_rust_cnode_new(node_type: NodeType,
raw_parent: *const RsvgNode,
state: *mut RsvgState,
c_node_impl: *const RsvgCNodeImpl,
set_atts_fn: CNodeSetAtts,
draw_fn: CNodeDraw,
free_fn: CNodeFree)
-> *const RsvgNode {
pub extern "C" fn rsvg_rust_cnode_new(
node_type: NodeType,
raw_parent: *const RsvgNode,
state: *mut RsvgState,
c_node_impl: *const RsvgCNodeImpl,
set_atts_fn: CNodeSetAtts,
draw_fn: CNodeDraw,
free_fn: CNodeFree,
) -> *const RsvgNode {
assert!(!state.is_null());
assert!(!c_node_impl.is_null());
let cnode = CNode { c_node_impl,
set_atts_fn,
draw_fn,
free_fn, };
let cnode = CNode {
c_node_impl,
set_atts_fn,
draw_fn,
free_fn,
};
box_node(Rc::new(Node::new(node_type,
node_ptr_to_weak(raw_parent),
state,
Box::new(cnode))))
box_node(Rc::new(Node::new(
node_type,
node_ptr_to_weak(raw_parent),
state,
Box::new(cnode),
)))
}
#[no_mangle]
......
......@@ -65,14 +65,17 @@ impl Parse for Color {
type Data = (AllowInherit, AllowCurrentColor);
type Err = AttributeError;
fn parse(s: &str,
(allow_inherit, allow_current_color): (AllowInherit, AllowCurrentColor))
-> Result<Color, AttributeError> {
fn parse(
s: &str,
(allow_inherit, allow_current_color): (AllowInherit, AllowCurrentColor),
) -> Result<Color, AttributeError> {
if s == "inherit" {
if allow_inherit == AllowInherit::Yes {
Ok(Color::Inherit)
} else {
Err(AttributeError::Value("inherit is not allowed here".to_string()))
Err(AttributeError::Value(
"inherit is not allowed here".to_string(),
))
}
} else {
let mut input = cssparser::ParserInput::new(s);
......@@ -81,13 +84,17 @@ impl Parse for Color {
if allow_current_color == AllowCurrentColor::Yes {
Ok(Color::CurrentColor)
} else {
Err(AttributeError::Value("currentColor is not allowed here".to_string()))
Err(AttributeError::Value(
"currentColor is not allowed here".to_string(),
))
}
}
Ok(csscolor) => Ok(Color::from(csscolor)),
_ => Err(AttributeError::Parse(ParseError::new("invalid syntax for color"))),
_ => Err(AttributeError::Parse(ParseError::new(
"invalid syntax for color",
))),
}
}
}
......@@ -96,26 +103,36 @@ impl Parse for Color {
impl Color {
pub fn from_color_spec(spec: &ColorSpec) -> Result<Color, AttributeError> {
match *spec {
ColorSpec { kind: ColorKind::Inherit,
.. } => Ok(Color::Inherit),
ColorSpec { kind: ColorKind::CurrentColor,
.. } => Ok(Color::CurrentColor),
ColorSpec { kind: ColorKind::ARGB,
argb, } => Ok(Color::RGBA(rgba_from_argb(argb))),
ColorSpec { kind: ColorKind::ParseError,
.. } => Err(AttributeError::Parse(ParseError::new("parse error"))),
ColorSpec {
kind: ColorKind::Inherit,
..
} => Ok(Color::Inherit),
ColorSpec {
kind: ColorKind::CurrentColor,
..
} => Ok(Color::CurrentColor),
ColorSpec {
kind: ColorKind::ARGB,
argb,
} => Ok(Color::RGBA(rgba_from_argb(argb))),
ColorSpec {
kind: ColorKind::ParseError,
..
} => Err(AttributeError::Parse(ParseError::new("parse error"))),
}
}
}
fn rgba_from_argb(argb: u32) -> cssparser::RGBA {
cssparser::RGBA::new(((argb & 0x00ff_0000) >> 16) as u8,
((argb & 0x0000_ff00) >> 8) as u8,
(argb & 0x0000_00ff) as u8,
((argb & 0xff00_0000) >> 24) as u8)
cssparser::RGBA::new(
((argb & 0x00ff_0000) >> 16) as u8,
((argb & 0x0000_ff00) >> 8) as u8,
(argb & 0x0000_00ff) as u8,
((argb & 0xff00_0000) >> 24) as u8,
)
}
impl From<cssparser::Color> for Color {
......@@ -136,29 +153,36 @@ impl From<u32> for Color {
impl From<Result<Color, AttributeError>> for ColorSpec {
fn from(result: Result<Color, AttributeError>) -> ColorSpec {
match result {
Ok(Color::Inherit) => ColorSpec { kind: ColorKind::Inherit,
argb: 0, },
Ok(Color::CurrentColor) => ColorSpec { kind: ColorKind::CurrentColor,
argb: 0, },
Ok(Color::RGBA(rgba)) => ColorSpec { kind: ColorKind::ARGB,
argb: (u32::from(rgba.alpha) << 24
| u32::from(rgba.red) << 16
| u32::from(rgba.green) << 8
| u32::from(rgba.blue)), },
_ => ColorSpec { kind: ColorKind::ParseError,
argb: 0, },
Ok(Color::Inherit) => ColorSpec {
kind: ColorKind::Inherit,
argb: 0,
},
Ok(Color::CurrentColor) => ColorSpec {
kind: ColorKind::CurrentColor,
argb: 0,
},
Ok(Color::RGBA(rgba)) => ColorSpec {
kind: ColorKind::ARGB,
argb: (u32::from(rgba.alpha) << 24 | u32::from(rgba.red) << 16
| u32::from(rgba.green) << 8 | u32::from(rgba.blue)),
},
_ => ColorSpec {
kind: ColorKind::ParseError,
argb: 0,
},
}
}
}
#[no_mangle]
pub extern "C" fn rsvg_css_parse_color(string: *const libc::c_char,
allow_inherit: AllowInherit,
allow_current_color: AllowCurrentColor)
-> ColorSpec {
pub extern "C" fn rsvg_css_parse_color(
string: *const libc::c_char,
allow_inherit: AllowInherit,
allow_current_color: AllowCurrentColor,
) -> ColorSpec {
let s = unsafe { utf8_cstr(string) };
ColorSpec::from(Color::parse(s, (allow_inherit, allow_current_color)))
......@@ -171,63 +195,111 @@ mod tests {
fn parse(s: &str) -> ColorSpec {
// ColorSpec::from (Color::parse (s, (AllowInherit::Yes, AllowCurrentColor::Yes)))
rsvg_css_parse_color(s.to_glib_none().0,
AllowInherit::Yes,
AllowCurrentColor::Yes)
rsvg_css_parse_color(
s.to_glib_none().0,
AllowInherit::Yes,
AllowCurrentColor::Yes,
)
}
#[test]
fn parses_hash_hex_colors() {
assert_eq!(parse("#AB10fa20"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0x20ab10fa, });
assert_eq!(parse("#10fa20"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xff10fa20, });
assert_eq!(parse("#abcd"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xddaabbcc, });
assert_eq!(parse("#123"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xff112233, });
assert_eq!(
parse("#AB10fa20"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0x20ab10fa,
}
);
assert_eq!(
parse("#10fa20"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xff10fa20,
}
);
assert_eq!(
parse("#abcd"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xddaabbcc,
}
);
assert_eq!(
parse("#123"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xff112233,
}
);
}
#[test]
fn parses_color_keywords() {
assert_eq!(parse("red"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xffff0000, });
assert_eq!(parse("lime"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xff00ff00, });
assert_eq!(parse("blue"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xff0000ff, });
assert_eq!(
parse("red"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xffff0000,
}
);
assert_eq!(
parse("lime"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xff00ff00,
}
);
assert_eq!(
parse("blue"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xff0000ff,
}
);
}
#[test]
fn parses_color_functions() {
assert_eq!(parse("rgb(255, 0, 0)"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xffff0000, });
assert_eq!(parse("rgb(0, 255, 0)"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xff00ff00, });
assert_eq!(parse("rgb(0, 0, 255)"),
ColorSpec { kind: ColorKind::ARGB,
argb: 0xff0000ff, });
assert_eq!(
parse("rgb(255, 0, 0)"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xffff0000,
}
);
assert_eq!(
parse("rgb(0, 255, 0)"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xff00ff00,
}
);
assert_eq!(
parse("rgb(0, 0, 255)"),
ColorSpec {
kind: ColorKind::ARGB,
argb: 0xff0000ff,
}
);
}
#[test]
fn parses_current_color() {
assert_eq!(parse("currentColor"),
ColorSpec { kind: ColorKind::CurrentColor,
argb: 0, });
assert_eq!(
parse("currentColor"),
ColorSpec {
kind: ColorKind::CurrentColor,
argb: 0,
}
);
}
fn make_error() -> ColorSpec {
ColorSpec { kind: ColorKind::ParseError,
argb: 0, }
ColorSpec {
kind: ColorKind::ParseError,
argb: 0,
}
}
#[test]
......@@ -247,16 +319,24 @@ mod tests {
#[test]
fn yields_error_on_disallowed_current_color() {
assert_eq!(ColorSpec::from(Color::parse("currentColor",
(AllowInherit::Yes, AllowCurrentColor::No))),
make_error());
assert_eq!(
ColorSpec::from(Color::parse(
"currentColor",
(AllowInherit::Yes, AllowCurrentColor::No)
)),
make_error()
);
}
#[test]
fn yields_error_on_disallowed_inherit() {
assert_eq!(ColorSpec::from(Color::parse("inherit",
(AllowInherit::No, AllowCurrentColor::Yes))),
make_error());
assert_eq!(
ColorSpec::from(Color::parse(
"inherit",
(AllowInherit::No, AllowCurrentColor::Yes)
)),
make_error()
);
}
fn test_roundtrip(s: &str) {
......@@ -281,7 +361,9 @@ mod tests {
#[test]
fn from_argb() {
assert_eq!(Color::from(0xaabbccdd),
Color::RGBA(cssparser::RGBA::new(0xbb, 0xcc, 0xdd, 0xaa)));
assert_eq!(
Color::from(0xaabbccdd),
Color::RGBA(cssparser::RGBA::new(0xbb, 0xcc, 0xdd, 0xaa))
);
}
}
......@@ -21,8 +21,9 @@ impl Parse for CoordUnits {
match s {
"userSpaceOnUse" => Ok(CoordUnits::UserSpaceOnUse),
"objectBoundingBox" => Ok(CoordUnits::ObjectBoundingBox),
_ => Err(AttributeError::Parse(ParseError::new("expected 'userSpaceOnUse' or \
'objectBoundingBox'"))),
_ => Err(AttributeError::Parse(ParseError::new(
"expected 'userSpaceOnUse' or 'objectBoundingBox'",
))),
}
}
}
......@@ -78,10 +79,14 @@ mod tests {
#[test]
fn parses_paint_server_units() {
assert_eq!(MyUnits::parse("userSpaceOnUse", ()),
Ok(MyUnits(CoordUnits::UserSpaceOnUse)));
assert_eq!(MyUnits::parse("objectBoundingBox", ()),
Ok(MyUnits(CoordUnits::ObjectBoundingBox)));
assert_eq!(
MyUnits::parse("userSpaceOnUse", ()),
Ok(MyUnits(CoordUnits::UserSpaceOnUse))
);
assert_eq!(
MyUnits::parse("objectBoundingBox", ()),
Ok(MyUnits(CoordUnits::ObjectBoundingBox))
);
}
#[test]
......@@ -91,7 +96,9 @@ mod tests {
#[test]
fn converts_to_coord_units() {
assert_eq!(CoordUnits::from(MyUnits(CoordUnits::ObjectBoundingBox)),
CoordUnits::ObjectBoundingBox);
assert_eq!(
CoordUnits::from(MyUnits(CoordUnits::ObjectBoundingBox)),
CoordUnits::ObjectBoundingBox
);
}
}
......@@ -17,48 +17,61 @@ use state::RsvgState;
pub enum RsvgDrawingCtx {}
extern "C" {
fn rsvg_drawing_ctx_get_dpi(draw_ctx: *const RsvgDrawingCtx,
out_dpi_x: *mut f64,
out_dpi_y: *mut f64);
fn rsvg_drawing_ctx_get_dpi(
draw_ctx: *const RsvgDrawingCtx,
out_dpi_x: *mut f64,
out_dpi_y: *mut f64,
);
fn rsvg_drawing_ctx_get_normalized_font_size(draw_ctx: *const RsvgDrawingCtx) -> f64;
fn rsvg_drawing_ctx_get_view_box_size(draw_ctx: *const RsvgDrawingCtx,
out_x: *mut f64,
out_y: *mut f64);
fn rsvg_drawing_ctx_get_view_box_size(
draw_ctx: *const RsvgDrawingCtx,
out_x: *mut f64,
out_y: *mut f64,
);
fn rsvg_drawing_ctx_push_view_box(draw_ctx: *const RsvgDrawingCtx, width: f64, height: f64);
fn rsvg_drawing_ctx_pop_view_box(draw_ctx: *const RsvgDrawingCtx);
fn rsvg_drawing_ctx_acquire_node(draw_ctx: *const RsvgDrawingCtx,
url: *const libc::c_char)
-> *mut RsvgNode;
fn rsvg_drawing_ctx_acquire_node(
draw_ctx: *const RsvgDrawingCtx,
url: *const libc::c_char,
) -> *mut RsvgNode;
fn rsvg_drawing_ctx_acquire_node_of_type(draw_ctx: *const RsvgDrawingCtx,
url: *const libc::c_char,
node_type: NodeType)
-> *mut RsvgNode;
fn rsvg_drawing_ctx_acquire_node_of_type(
draw_ctx: *const RsvgDrawingCtx,
url: *const libc::c_char,
node_type: NodeType,
) -> *mut RsvgNode;
fn rsvg_drawing_ctx_release_node(draw_ctx: *const RsvgDrawingCtx, node: *mut RsvgNode);
fn rsvg_drawing_ctx_get_current_state_affine(draw_ctx: *const RsvgDrawingCtx) -> cairo::Matrix;
fn rsvg_drawing_ctx_set_current_state_affine(draw_ctx: *const RsvgDrawingCtx,
affine: *const cairo::Matrix);
fn rsvg_drawing_ctx_get_pango_context(draw_ctx: *const RsvgDrawingCtx)
-> *mut pango_sys::PangoContext;
fn rsvg_drawing_ctx_add_clipping_rect(draw_ctx: *const RsvgDrawingCtx,
x: f64,
y: f64,
w: f64,
h: f64);
fn rsvg_drawing_ctx_draw_node_from_stack(draw_ctx: *const RsvgDrawingCtx,
node: *const RsvgNode,
dominate: i32);
fn rsvg_drawing_ctx_set_current_state_affine(
draw_ctx: *const RsvgDrawingCtx,
affine: *const cairo::Matrix,