This project has moved and is read-only. For the latest updates, please go here.

Troubles with embegged images

Topics: SVG, SVG# and Parsing, WPF and GDI+ Renderers
Oct 26, 2016 at 6:20 PM
Edited Oct 26, 2016 at 10:29 PM
Hi all,

Sorry for the bad english (in the USSR there was no foreign languages).

I have troubles with embedded images.

Option A:
.svg file with embedded image (created from Corel Draw 13).
The image is transformed by scaling and offset.
  • image is placed into the clip
In this case, scaling applied 1) on our image, and then 2) offset of the clip. Although scaling should not be applied to offset.

Option B:
.svg file with embedded image (created from Corel Draw 18).
Here we have wrong scaling because of default scale for image == SvgPreserveAspectRatioType.XMidYMid

So I made some minor changes in WpfImageRendering.cs, project SharpVectors.Rendering.Wpf:
1) for Option A: added correction of the offset (line 461, function GetAspectRatioTransform)
        if (this.Transform != null)
        {
            if (scaleX != 1.0f && this.Transform.Value.OffsetX != 0.0)
                translateX = translateX + this.Transform.Value.OffsetX * (1 - scaleX);
            if (scaleY != 1.0f && this.Transform.Value.OffsetY != 0.0)
                translateY = translateY + this.Transform.Value.OffsetY * (1 - scaleY);
        }
2) for Option B: check for default scaling (line 130, function Render)
old version:
                            destRect = this.GetBounds(destRect,
                                new Size(imageWidth, imageHeight), aspectRatioType);
new version:
                            if (!aspectRatio.IsDefaultAlign)
                                destRect = this.GetBounds(destRect, new Size(imageWidth, imageHeight), aspectRatioType);
3) Correct minor bag (line 463, function GetAspectRatioTransform). I was not able to test this, but it should be logically.
old version:
        if ((float)translateX >= 0 && (float)translateY >= 0)
new version:
        if ((float)translateX >= 0 || (float)translateY >= 0)
4) Correct minor bag (line 467, function GetAspectRatioTransform). I was not able to test this, but it should be logically
old version:
        if ((float)scaleX != 1.0f && (float)scaleY != 1.0)
new version:
        if ((float)scaleX != 1.0f || (float)scaleY != 1.0)

.svg-samples and corrected WpfImageRendering.cs file (all my changes I mark as //Cacxa) you can find here: https://yadi.sk/d/jG_aF-mOxerkG
Coordinator
Nov 17, 2016 at 1:15 PM
Edited Nov 17, 2016 at 1:25 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion

Hello Cacxa,

I have copied the post to work item. Please can you attach the necessary files to the work item?

Thanks for investigating the issue and providing a solution.
English like any other language is just a means of communication, you do not need to be perfect at it to express yourself and be understood. I understood your post perfectly.

Best regards,
Paul.
Nov 17, 2016 at 3:13 PM
Hello Paul,
I've attached files
Coordinator
Nov 18, 2016 at 1:16 AM

Hello Cacxa,
Thanks so much. I will look into it this weekend.

Best regards,
Paul