Skip to content

pixelDensity(2) with SVG creates incorrect viewport in the file #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
processing-bot opened this issue Mar 24, 2023 · 3 comments · May be fixed by #1090
Open

pixelDensity(2) with SVG creates incorrect viewport in the file #693

processing-bot opened this issue Mar 24, 2023 · 3 comments · May be fixed by #1090
Assignees
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@processing-bot
Copy link
Collaborator

In GitLab by @mrbbp on Mar 24, 2023, 09:36

Description

i was playing around with svg export and curve drawing.
I'm working on MacOS with a retina display, therefore i add pixelDensity to improve display.

Expected Behavior

the document should stay in the viewbox

Current Behavior

When we export to svg, there is a glitch on the output file.
there is a transform="scale(2,2)" on the exported shape.
I understand why, but in fact it's useless, because it's vector shape exported.
the document is defined with the right definition (created with size(width, height) in the script)
by adding a transform, it modify the preview and the size of the shape in the viewbox.

Steps to Reproduce

import processing.svg.*;

void setup() {
  size(400,400, SVG, "filename_without_pixeldensity.svg");
  //pixelDensity(2);
}

void draw() {
  circle(width/2,height/2, width/2);
  exit();
}

Your Environment

  • Processing version: 4.2
  • Operating System and OS version: MacOS Ventura 13.2.1
  • Other information: Intel 2018 MBP 13"

Possible Causes / Solutions

Remove the transform="scale(2,2)" on each group of shape
or
adjust the document size (withand height) according to the pixelDensity instruction in the <svg> tag to have a correct preview and document viewbox.

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Ok, though I think I'd recommend just not using pixelDensity() in these cases.

@Stefterv Stefterv added bug Something isn't working good first issue Good for newcomers labels May 8, 2025
@Stefterv Stefterv moved this to To do in Processing Roadmap May 8, 2025
@Stefterv
Copy link
Collaborator

Stefterv commented May 8, 2025

Since we changed the default pixelDensity in 4.4.3 more users are running into this issue: https://discourse.processing.org/t/svg-export-issue-transform-scale-2-2/46350/4

@AhmedMagedC
Copy link

the problem can be easily fixed with setting the correct canvas size in this piece of code
((SVGGraphics2D) g2).setSVGCanvasSize(new Dimension(width * pixelDensity, height * pixelDensity));

can i get this issue assigned to open a pr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
Status: To do
3 participants