rustfmt

parent 27d01995
......@@ -172,7 +172,8 @@ fn generate_phf_of_svg_attributes() {
writeln!(
&mut file,
"#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]"
).unwrap();
)
.unwrap();
writeln!(&mut file, "pub enum Attribute {{").unwrap();
for &(_, valname) in attribute_defs.iter() {
......@@ -184,7 +185,8 @@ fn generate_phf_of_svg_attributes() {
writeln!(
&mut file,
"static ATTRIBUTES: phf::Map<&'static str, Attribute> = "
).unwrap();
)
.unwrap();
let mut map = phf_codegen::Map::new();
map.phf_path("phf");
......
......@@ -200,7 +200,8 @@ impl Parse for AspectRatio {
p.expect_ident()
.map_err(|_| ValueErrorKind::Parse(ParseError::new("expected identifier")))
.and_then(|ident| parse_fit_mode(ident))
}).unwrap_or(FitMode::default());
})
.unwrap_or(FitMode::default());
parser
.expect_exhausted()
......
......@@ -32,7 +32,8 @@ impl Parse for CoordUnits {
cow.as_ref().to_string(),
))),
),
}).map_err(|_| {
})
.map_err(|_| {
ValueErrorKind::Parse(ParseError::new(
"expected 'userSpaceOnUse' or 'objectBoundingBox'",
))
......
......@@ -152,7 +152,8 @@ impl<'a> DrawingCtx<'a> {
y: 0.0,
width,
height,
}.transform(&affine)
}
.transform(&affine)
.outer();
// scale according to size set by size_func callback
......@@ -597,7 +598,8 @@ impl<'a> DrawingCtx<'a> {
fill_opacity,
&bbox,
current_color,
).and_then(|had_paint_server| {
)
.and_then(|had_paint_server| {
if had_paint_server {
pangocairo::functions::update_layout(&cr, layout);
pangocairo::functions::show_layout(&cr, layout);
......@@ -620,7 +622,8 @@ impl<'a> DrawingCtx<'a> {
stroke_opacity,
&bbox,
&current_color,
).and_then(|had_paint_server| {
)
.and_then(|had_paint_server| {
if had_paint_server {
need_layout_path = true;
}
......@@ -700,7 +703,8 @@ impl<'a> DrawingCtx<'a> {
fill_opacity,
&bbox,
current_color,
).and_then(|had_paint_server| {
)
.and_then(|had_paint_server| {
if had_paint_server {
if values.stroke.0 == PaintServer::None {
cr.fill();
......@@ -710,7 +714,8 @@ impl<'a> DrawingCtx<'a> {
}
Ok(())
}).and_then(|_| {
})
.and_then(|_| {
let stroke_opacity = values.stroke_opacity.0;
paint_server::set_source_paint_server(
......@@ -719,7 +724,8 @@ impl<'a> DrawingCtx<'a> {
&stroke_opacity,
&bbox,
&current_color,
).and_then(|had_paint_server| {
)
.and_then(|had_paint_server| {
if had_paint_server {
cr.stroke();
}
......
......@@ -256,7 +256,8 @@ impl Parse for Operator {
cow.as_ref().to_string(),
))),
),
}).map_err(|_| ValueErrorKind::Value("invalid operator value".to_string()))
})
.map_err(|_| ValueErrorKind::Value("invalid operator value".to_string()))
}
}
......
......@@ -472,7 +472,8 @@ impl FilterContext {
&opacity,
&bbox,
&self.computed_from_node_being_filtered.color.0,
).and_then(|had_paint_server| {
)
.and_then(|had_paint_server| {
if had_paint_server {
cr.paint();
}
......@@ -523,14 +524,16 @@ impl FilterContext {
.and_then(|surface| {
SharedImageSurface::new(surface, SurfaceType::SRgb)
.map_err(FilterError::CairoError)
}).map(FilterInput::StandardInput),
})
.map(FilterInput::StandardInput),
Input::StrokePaint => self
.get_paint_server_surface(draw_ctx, &values.stroke.0, values.stroke_opacity.0)
.map_err(FilterError::CairoError)
.and_then(|surface| {
SharedImageSurface::new(surface, SurfaceType::SRgb)
.map_err(FilterError::CairoError)
}).map(FilterInput::StandardInput),
})
.map(FilterInput::StandardInput),
Input::FilterOutput(ref name) => self
.filter_output(name)
......
......@@ -75,7 +75,8 @@ impl Image {
&surface,
f64::from(ctx.source_graphic().width()),
f64::from(ctx.source_graphic().height()),
).map_err(|e| {
)
.map_err(|e| {
if let RenderingError::Cairo(status) = e {
FilterError::CairoError(status)
} else {
......
......@@ -126,7 +126,8 @@ impl NodeTrait for Primitive {
} else {
None
}
}).unwrap_or(CoordUnits::UserSpaceOnUse);
})
.unwrap_or(CoordUnits::UserSpaceOnUse);
let no_units_allowed = primitiveunits == CoordUnits::ObjectBoundingBox;
let check_units = |length: Length| {
......@@ -292,7 +293,8 @@ pub fn render(
};
(c, linear_rgb)
}).filter_map(|(c, linear_rgb)| {
})
.filter_map(|(c, linear_rgb)| {
let rr = RcRef::new(c)
.try_map(|c| {
// Go through the filter primitives and see if the node is one of them.
......@@ -333,7 +335,8 @@ pub fn render(
turbulence::Turbulence,
);
filter.ok_or(())
}).ok();
})
.ok();
rr.map(|rr| (rr, linear_rgb))
});
......
......@@ -94,7 +94,8 @@ impl NodeTrait for Turbulence {
f64::from(i32::min_value()),
f64::from(i32::max_value()),
) as i32
}).map_err(|err| NodeError::attribute_error(attr, err))?,
})
.map_err(|err| NodeError::attribute_error(attr, err))?,
),
Attribute::StitchTiles => self.stitch_tiles.set(StitchTiles::parse(attr, value)?),
Attribute::Type => self.type_.set(NoiseType::parse(attr, value)?),
......@@ -398,7 +399,8 @@ impl Filter for Turbulence {
g: generate(1),
b: generate(2),
a: generate(3),
}.premultiply();
}
.premultiply();
output_data.set_pixel(output_stride, pixel, x as u32, y as u32);
}
......
......@@ -53,7 +53,8 @@ impl Parse for SpreadMethod {
cow.as_ref().to_string(),
))),
),
}).map_err(|_| {
})
.map_err(|_| {
ValueErrorKind::Parse(ParseError::new("expected 'pad' | 'reflect' | 'repeat'"))
})
}
......@@ -379,7 +380,8 @@ impl Gradient {
}
!in_error
}).for_each(|child| {
})
.for_each(|child| {
child.with_impl(|stop: &NodeStop| {
let cascaded = child.get_cascaded_values();
let values = cascaded.get();
......@@ -444,7 +446,8 @@ fn resolve_gradient(gradient: &Gradient, draw_ctx: &mut DrawingCtx<'_>) -> Gradi
result.resolve_from_fallback(&fallback_grad)
});
Some(())
}).or_else(|| {
})
.or_else(|| {
result.resolve_from_defaults();
Some(())
});
......
......@@ -51,7 +51,8 @@ impl Parse for MarkerUnits {
cow.as_ref().to_string(),
))),
),
}).map_err(|_| {
})
.map_err(|_| {
ValueErrorKind::Parse(ParseError::new(
"expected \"userSpaceOnUse\" or \"strokeWidth\"",
))
......@@ -1261,7 +1262,8 @@ mod directionality_tests {
fn curve_with_12_34_coincident_has_directionality() {
let (v1x, v1y, v2x, v2y) = super::get_segment_directionalities(&curve(
20.0, 40.0, 20.0, 40.0, 60.0, 70.0, 60.0, 70.0,
)).unwrap();
))
.unwrap();
assert_eq!((40.0, 30.0), (v1x, v1y));
assert_eq!((40.0, 30.0), (v2x, v2y));
......@@ -1293,7 +1295,8 @@ mod marker_tests {
v.push((marker_type, x, y, computed_angle));
Ok(())
}
).is_ok()
)
.is_ok()
);
assert_eq!(
......@@ -1329,7 +1332,8 @@ mod marker_tests {
v.push((marker_type, x, y, computed_angle));
Ok(())
}
).is_ok()
)
.is_ok()
);
assert_eq!(
......
......@@ -347,7 +347,8 @@ impl NodeTrait for NodeRect {
value,
LengthDir::Horizontal,
Length::check_nonnegative,
).map(Some)?,
)
.map(Some)?,
),
Attribute::Ry => self.ry.set(
parse_and_validate("ry", value, LengthDir::Vertical, Length::check_nonnegative)
......
......@@ -28,10 +28,12 @@ fn normalize_default(s: &str) -> String {
.map(|ch| match ch {
'\t' => ' ',
c => c,
}).coalesce(|current, next| match (current, next) {
})
.coalesce(|current, next| match (current, next) {
(' ', ' ') => Ok(' '),
(_, _) => Err((current, next)),
}).collect::<String>()
})
.collect::<String>()
}
// From https://www.w3.org/TR/SVG/text.html#WhiteSpace
......@@ -50,7 +52,8 @@ fn normalize_preserve(s: &str) -> String {
'\n' | '\t' => ' ',
c => c,
}).collect()
})
.collect()
}
#[cfg(test)]
......
......@@ -260,7 +260,8 @@ impl NodeTrait for NodeUse {
value,
LengthDir::Horizontal,
Length::check_nonnegative,
).map(Some)?,
)
.map(Some)?,
),
Attribute::Height => self.h.set(
parse_and_validate(
......@@ -268,7 +269,8 @@ impl NodeTrait for NodeUse {
value,
LengthDir::Vertical,
Length::check_nonnegative,
).map(Some)?,
)
.map(Some)?,
),
_ => (),
......
......@@ -196,7 +196,8 @@ mod tests {
let surface = SharedImageSurface::new(
ImageSurface::create(cairo::Format::ARgb32, WIDTH, HEIGHT).unwrap(),
SurfaceType::SRgb,
).unwrap();
)
.unwrap();
// Full image.
let bounds = IRect {
......@@ -273,7 +274,8 @@ mod tests {
let surface = SharedImageSurface::new(
ImageSurface::create(cairo::Format::ARgb32, WIDTH, HEIGHT).unwrap(),
SurfaceType::SRgb,
).unwrap();
)
.unwrap();
let bounds = IRect {
x0: 0,
......
......@@ -642,7 +642,8 @@ impl SharedImageSurface {
stride: self.stride,
ptr: NonNull::new(unsafe {
self.ptr.as_ptr().offset(index as isize * self.stride)
}).unwrap(),
})
.unwrap(),
_marker: PhantomData,
},
)
......@@ -670,7 +671,8 @@ impl SharedImageSurface {
stride: self.stride,
ptr: NonNull::new(unsafe {
self.ptr.as_ptr().offset(index as isize * 4)
}).unwrap(),
})
.unwrap(),
_marker: PhantomData,
},
)
......
......@@ -541,7 +541,8 @@ fn create_pango_layout(
attr_list.insert(
pango::Attribute::new_letter_spacing(to_pango_units(
values.letter_spacing.0.normalize(values, &params),
)).unwrap(),
))
.unwrap(),
);
if values.text_decoration.underline {
......
......@@ -98,7 +98,8 @@ fn parse_matrix_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, Value
let y0 = p.expect_number()?;
Ok((xx, yx, xy, yy, x0, y0))
}).map_err(CssParseError::<()>::basic)
})
.map_err(CssParseError::<()>::basic)
.map_err(|e| ValueErrorKind::from(e))
.and_then(|(xx, yx, xy, yy, x0, y0)| {
let xx = f64::from(finite_f32(xx)?);
......@@ -121,10 +122,12 @@ fn parse_translate_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, Va
.try(|p| -> Result<f32, CssParseError<'_, ()>> {
optional_comma(p);
Ok(p.expect_number()?)
}).unwrap_or(0.0);
})
.unwrap_or(0.0);
Ok((tx, ty))
}).map_err(CssParseError::<()>::basic)
})
.map_err(CssParseError::<()>::basic)
.map_err(|e| ValueErrorKind::from(e))
.and_then(|(tx, ty)| {
let tx = f64::from(finite_f32(tx)?);
......@@ -143,10 +146,12 @@ fn parse_scale_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, ValueE
.try(|p| -> Result<f32, CssParseError<'_, ()>> {
optional_comma(p);
Ok(p.expect_number()?)
}).unwrap_or(x);
})
.unwrap_or(x);
Ok((x, y))
}).map_err(CssParseError::<()>::basic)
})
.map_err(CssParseError::<()>::basic)
.map_err(|e| ValueErrorKind::from(e))
.and_then(|(x, y)| {
let x = f64::from(finite_f32(x)?);
......@@ -170,10 +175,12 @@ fn parse_rotate_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, Value
let ty = p.expect_number()?;
Ok((tx, ty))
}).unwrap_or((0.0, 0.0));
})
.unwrap_or((0.0, 0.0));
Ok((angle, tx, ty))
}).map_err(CssParseError::<()>::basic)
})
.map_err(CssParseError::<()>::basic)
.map_err(|e| ValueErrorKind::from(e))
.and_then(|(angle, tx, ty)| {
let angle = f64::from(finite_f32(angle)?);
......@@ -196,7 +203,8 @@ fn parse_skewx_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, ValueE
.parse_nested_block(|p| {
let a = p.expect_number()?;
Ok(a)
}).map_err(CssParseError::<()>::basic)
})
.map_err(CssParseError::<()>::basic)
.map_err(|e| ValueErrorKind::from(e))
.and_then(|a| {
let a = f64::from(finite_f32(a)?);
......@@ -211,7 +219,8 @@ fn parse_skewy_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, ValueE
.parse_nested_block(|p| {
let a = p.expect_number()?;
Ok(a)
}).map_err(CssParseError::<()>::basic)
})
.map_err(CssParseError::<()>::basic)
.map_err(|e| ValueErrorKind::from(e))
.and_then(|a| {
let a = f64::from(finite_f32(a)?);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment