Skip to content
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

Consistency in Scaling #3

Closed
Reputeless opened this issue Jul 25, 2020 · 6 comments
Closed

Consistency in Scaling #3

Reputeless opened this issue Jul 25, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@Reputeless
Copy link
Contributor

Hi, @sammycage.

When I changed documentWidth and documentHeight in the svg2png example as follows, the image content was cropped in some cases.

        double documentWidth = document.documentWidth() * 0.5;
        double documentHeight = document.documentHeight() * 0.5;

scaled:

image

cropped:

image

Is there a consistent way to scale the content to fit the lunasvg::Bitmap size without cropping?

svgren has a option to request a size, and it works as I expect.
https://github.com/igagis/svgren/blob/ca45437ab6b89430c8336404889b00bc5f0147ef/src/svgren/render.hpp#L12-L27

Here are the test files.

@sammycage sammycage added the enhancement New feature or request label Jul 26, 2020
@sammycage
Copy link
Owner

Added but not tested : 7c0ddbf.

@Reputeless
Copy link
Contributor Author

I tried the latest code d60fbc7 with the following modification:

double documentWidth = document.documentWidth() * 0.5;
double documentHeight = document.documentHeight() * 0.5;

It works fine for car.svg, but now the content of the 3.072.svg is scaled down incorrectly.

car.svg

svg_1

3.072.svg

svg_2

@sammycage
Copy link
Owner

The problem is that viewBox is not specified in these file. But i am currently working on a way to specify the viewBox without modifying the content of the file. Like this.

...

SVGView view(document.getBbox());

document.render(bitmap, view, dpi, bgColor);
...

@sammycage
Copy link
Owner

Added : aed8047

@Reputeless
Copy link
Contributor Author

Now it works fine! Thank you.

image

image

@sammycage
Copy link
Owner

sammycage commented Jul 30, 2020

Added renderToBitmap : fc6eaff

SVGDocument document;
document.loadFromFile("filename.svg");
Bitmap bitmap = document.renderToBitmap();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants