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

0.14.0 "Fit To" c-bindings equivalent in 0.44.0 #860

Open
clicketyclackety opened this issue Dec 13, 2024 · 3 comments
Open

0.14.0 "Fit To" c-bindings equivalent in 0.44.0 #860

clicketyclackety opened this issue Dec 13, 2024 · 3 comments

Comments

@clicketyclackety
Copy link

clicketyclackety commented Dec 13, 2024

Previously we have used the following code in the c bindings

var fitTo = new DrawingUtilitiesPInvokes.resvg_fit_to();

fitTo._fitToType = 1;
fitTo._value = (float)width;

DrawingUtilitiesPInvokes.resvg_render(renderTree, fitto, (uint)width, (uint)height, pBytes);

But now in 0.44.0, the Fit To zoom does not exist anymore. I've tried using some transform code and using the Bounds, but not managed to replicate the icons as they were. Can anyone offer any assistance in replicating this functionality? I would very much like to update our dependency to 0.44.0

DrawingUtilitiesPInvokes.resvg_transform transform = DrawingUtilitiesPInvokes.resvg_transform_identity();

float fWidth = width;
float fHeight = height;

// Ensures the scaling is correct
DrawingUtilitiesPInvokes.resvg_rect svgBounds = new DrawingUtilitiesPInvokes.resvg_rect();
if (DrawingUtilitiesPInvokes.resvg_get_image_bbox(renderTree, ref svgBounds))
{
  float maxSize = Math.Max(fWidth, fHeight);
  float maxBoundsSize = Math.Max(svgBounds.width, svgBounds.height);
  float scale = maxSize / maxBoundsSize;

  transform = new DrawingUtilitiesPInvokes.resvg_transform()
  {
    a = scale,
    b = 0,
    c = 0,
    d = scale,
    e = -svgBounds.x * scale
    f = -svgBounds.y * scale
  };
}

GCHandle pinnedArray = GCHandle.Alloc(pixmap, GCHandleType.Pinned);
IntPtr pBytes = pinnedArray.AddrOfPinnedObject();

DrawingUtilitiesPInvokes.resvg_render(renderTree, transform, (uint)width, (uint)height, pBytes);
@RazrFalcon
Copy link
Collaborator

v0.14 was long time ago. Can you explain what behavior do you want? Preferably with images.

@clicketyclackety
Copy link
Author

Thanks for getting back to me so quickly @RazrFalcon,

image

Our software has panels and toolbars which allow customization with an SVG of any size. This is what it currently looks like using 0.14.0

0.14.0 (current)

image

Using 0.44.0 (with an identity transform)

image

Using 0.44.0 (with my above transform calculation code)

image

Looks good, a bit more zoomed in than before? Some others do not look good however, as below;

image

I would like our software to render the icons identically with 0.14.0 and 0.44.0, so I need an accurate way to replicate the FitTo using a transform (as far as I can see)

@RazrFalcon
Copy link
Collaborator

Can you share a single SVG icon of yours? Or at least the first element of it, i.e. the <svg ... one.

Also, FitTo was removed in 0.33.0, so you can try 0.32 for now.

Overall, it's hard to say what is wrong. For starters, you should use resvg_get_image_size instead of resvg_get_image_bbox. This should help.
And use only width for scale calculation instead of width or height.

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

2 participants