Commit b115c59d authored by RazrFalcon's avatar RazrFalcon

(usvg) Better groups regrouping.

parent abe1eb66
......@@ -567,7 +567,7 @@ fn calc_region(
let region = utils::path_bbox(&path, None, &region_ts);
let region = region.to_screen_rect().fit_to_rect(canvas_rect);
if region.width == 0 || region.height == 0 {
if !region.is_valid() {
return Err(Error::InvalidRegion);
}
......
......@@ -233,6 +233,11 @@ impl ScreenRect {
pub fn to_rect(&self) -> Rect {
Rect::new(self.x as f64, self.y as f64, self.width as f64, self.height as f64)
}
/// Checks that the rect has a valid size.
pub fn is_valid(&self) -> bool {
self.width > 0 && self.height > 0
}
}
impl fmt::Debug for ScreenRect {
......
......@@ -74,7 +74,8 @@ fn _ungroup_groups(parent: &Node, opt: &Options, groups: &mut Vec<Node>) {
}
// We can ungroup group with opacity only when it has only one child.
if node.has_attribute(AId::Opacity) {
let opacity = node.attributes().get_number_or(AId::Opacity, 1.0);
if opacity.fuzzy_ne(&1.0) {
if node.children().count() != 1 {
continue;
}
......
......@@ -549,3 +549,42 @@ test!(simplify_paths_1, false,
d='M 10 20 L 10 30 Z'/>
</svg>
");
test!(group_with_default_opacity, false,
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'>
<g opacity='1'>
<path d='M 10 20 L 10 30'/>
<path d='M 10 20 L 10 30'/>
</g>
</svg>",
"<svg
xmlns='http://www.w3.org/2000/svg'
width='1'
height='1'
viewBox='0 0 1 1'
preserveAspectRatio='xMidYMid'
xmlns:usvg='https://github.com/RazrFalcon/usvg'
usvg:version='0.4.0'>
<defs/>
<path
fill='#000000'
fill-opacity='1'
fill-rule='nonzero'
stroke='none'
marker-end='none'
marker-mid='none'
marker-start='none'
visibility='visible'
d='M 10 20 L 10 30'/>
<path
fill='#000000'
fill-opacity='1'
fill-rule='nonzero'
stroke='none'
marker-end='none'
marker-mid='none'
marker-start='none'
visibility='visible'
d='M 10 20 L 10 30'/>
</svg>
");
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