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

FitArea, FitWidth, FitHeight don't work for SVG images #852

Open
Codesigntr opened this issue Apr 23, 2024 · 7 comments
Open

FitArea, FitWidth, FitHeight don't work for SVG images #852

Codesigntr opened this issue Apr 23, 2024 · 7 comments

Comments

@Codesigntr
Copy link

Hello,

I use the following code to load SVG image and set it to fit the container size.

row.RelativeItem().DebugArea().Column(column =>
{
    column.Item().Height(40, Unit.Point).Svg(SvgImage.FromFile("wwwroot/logo.svg")).FitArea();
});

I couldn't make the logo to fit container height. Do i miss a detail?

Thanks in advance...

@jaguarxii
Copy link

I found that too, some SVGs seems to be misinterpreted and the "width" or "height" are not applied, also the fitarea, fitwidth and fitheight functions are not working.

I still do not figure it out what is wrong in those svg files, attached a sample

living_error

as a workaround I "cleaned" the SVG files using this online tool SVGOMG

@Codesigntr
Copy link
Author

Codesigntr commented Apr 24, 2024

Turning the option "Prefer viewBox to width/height" on solved the problem.
Thank you very much.

@MarcinZiabek
Copy link
Member

Thank you for the feedback and reporting this problem 😄

I have investigated the issue and applied several enhancements to how SVG images are scaled, especially when relative (%) or physical (mm, in, cm) units are used.

Would you please test the newest 2024.3.2 version with your original logo? https://github.com/QuestPDF/QuestPDF/releases/tag/2024.3.2

@jaguarxii
Copy link

Hi Marc, thanks for the update

The svg fitting in the release 2024.3.2 works under certain conditions:

if you only set "width" the image fits, there is no need to use "fit<area, width, height>" methods.
if you only set "height" without "fit<area, width, height>" throws an exception.
if you set "width" and "height" without "fit<area, width, height>" throws an exception.

the testing image is the one in my previous comment

@Codesigntr
Copy link
Author

Codesigntr commented Apr 29, 2024

Hi Marcin,

Same as here :(

Thank you.

@MarcinZiabek
Copy link
Member

This outcome is expected in specific scenarios. By default, every image uses the FitWidth scaling option. When you provide too little vertical space, the layout exception is thrown. Would you please try the FitArea option, which is likely the safest one?

In the meantime, I will investigate the possibility of automatically detecting certain layout constraints and applying appropriate scaling behavior. For example, if the image is a child of the Height element, it should use the FitHeight strategy, and when it is a child of both Width and Height elements, it should use the FitArea strategy by default.

It has a chance to significantly improve the developer experience and library predictiveness.

@MarcinZiabek
Copy link
Member

The 2024.3.3 release introduces the mechanism mentioned in my previous message. It will work only in specific scenarios. In other cases, I recommend using the FitArea option as the safest one, yet not always desired.

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

No branches or pull requests

3 participants