Skip to content
New issue

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

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

Already on GitHub? # to your account

Couldn't get Img32.Fmt.SVG to open the image in native size as suggested by the help #9

Closed
idw-git opened this issue Oct 4, 2022 · 2 comments

Comments

@idw-git
Copy link

idw-git commented Oct 4, 2022

Hey Angus, me again, here's what your help for Img32.Fmt.SVG says:

If you need an image rendered at the SVG image's native size, then make sure the TImage32 object is empty (ie zero width and height) before calling its load method.

Unfortunately I couldn't get this to work as announced, the image was always created in (defaultSvgWidth, defaultSvgHeight). After taking a look at your code I figured out that there couldn't be a proper solution unless checking for both the img32 object and the viewbox being empty, so here's the code I'm now using on lines 395/396 in Img32.Fmt.SVG:

  if **r.IsEmpty and** img32.IsEmpty then
    img32.SetSize(defaultSvgWidth, defaultSvgHeight);

I hope I didn't get anything wrong, if so please correct me ...

				Michael

--
PGP Key ID (RSA 2048): 0xC45D831B
IERenderer's Home https://www.pmpgp.de/renderer/History.htm
S/MIME Fingerprint: 94C6B471 0C623088 A5B27701 742B8666 3B7E657C

@AngusJohnson
Copy link
Owner

    img32.BeginUpdate;
    try
      if img32.IsEmpty and not r.IsEmpty then
        img32.SetSize(Round(r.Width), Round(r.Height))
      else if not r.IsEmpty then
      begin
        //then scale the SVG to fit image
        w := r.Width;
        h := r.Height;
        sx := img32.Width / w;
        sy := img32.Height / h;
        if sy < sx then sx := sy;
        if not(SameValue(sx, 1, 0.00001)) then
        begin
          w := w * sx;
          h := h * sx;
        end;
        img32.SetSize(Round(w), Round(h));
      end
      else
        img32.SetSize(defaultSvgWidth, defaultSvgHeight);

      //draw the SVG image to fit inside the canvas
      DrawImage(img32, True);
    finally
      img32.EndUpdate;
    end;

AngusJohnson added a commit that referenced this issue Oct 5, 2022
SVG images were not being loaded in their native sizes with TImage32 was empty. (#9)
@idw-git
Copy link
Author

idw-git commented Oct 5, 2022

Thanks Angus, I tested the code with my live sample and it works properly.

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

No branches or pull requests

2 participants