Skip to content

Commit

Permalink
Don't include stroke in bbox for gradient with opacities on strokes (#49
Browse files Browse the repository at this point in the history
)
  • Loading branch information
LaurenzV authored Nov 29, 2023
1 parent 3571761 commit 5a44b68
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/svg2pdf/src/render/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn create(
render(parent, recursive_mask.clone(), chunk, &mut content, ctx);
}

let parent_svg_bbox = plain_bbox(parent, true);
let parent_svg_bbox = plain_bbox(parent, false);

let actual_rect = match mask.units {
Units::ObjectBoundingBox => mask.rect.bbox_transform(parent_svg_bbox),
Expand Down
16 changes: 6 additions & 10 deletions crates/svg2pdf/src/render/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ fn stroke(
) {
if let Some(stroke) = path.stroke.as_ref() {
let paint = &stroke.paint;
let path_bbox_with_stroke = plain_bbox(node, true);
let path_bbox_without_stroke = plain_bbox(node, false);
let path_bbox = plain_bbox(node, false);
let accumulated_transform = accumulated_transform.pre_concat(path.transform);

content.save_state();
Expand All @@ -124,7 +123,7 @@ fn stroke(
// the whole pattern itself. This is why we need to handle this case differently.
let pattern_name = pattern::create(
p.clone(),
&path_bbox_without_stroke,
&path_bbox,
chunk,
ctx,
accumulated_transform,
Expand All @@ -144,18 +143,15 @@ fn stroke(
Some(stroke.opacity),
);

if let Some(soft_mask) = gradient::create_shading_soft_mask(
paint,
&path_bbox_with_stroke,
chunk,
ctx,
) {
if let Some(soft_mask) =
gradient::create_shading_soft_mask(paint, &path_bbox, chunk, ctx)
{
content.set_parameters(soft_mask.to_pdf_name());
}

let pattern_name = gradient::create_shading_pattern(
paint,
&path_bbox_without_stroke,
&path_bbox,
chunk,
ctx,
&accumulated_transform,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a44b68

Please sign in to comment.