SVG icon indicating copy to clipboard operation
SVG copied to clipboard

svgdoc.Ppi not respected

Open PeterWone opened this issue 6 years ago • 6 comments

According to #313 one can set Ppi after creating an SvgDocument.

  SvgDocument svgDoc = SvgDocument.Open(xmlDoc);
  svgDoc.Ppi = (int)e.Graphics.DpiX;

  ...
  svgDoc.Height = new SvgUnit(SvgUnitType.Millimeter, 20);
  float h = (int) svgDoc.Height;

In my tests the printer device context DpiX value is 600 and this is definitely assigned to Ppi. However, the value returned into h is 75.6.

The correct result is 20 / 25.4 * 600 = 472.441

Working backward from the actual result 20 / 25.4 * dpi = 75.6 w have dpi = 75 / (20 / 25.4) = 96 which is the default dpi.

On this basis I assert that Ppi is not respected.

Rummaging, implicit conversion does this .ToDeviceValue(null, UnitRenderingType.Other, null) and because owner is not supplied ppi is obtained from SvgDocument.PointsPerInch which matches the observed behaviour.

What is the recommended way to do this kind of conversion?

PeterWone avatar May 02 '19 23:05 PeterWone

Explicit conversion with a supplied owner also fails. I found the bug and corrected it, at some point I will do a PR

PeterWone avatar May 03 '19 00:05 PeterWone

@PeterWone - are you still planning to make the PR?

mrbean-bremen avatar Jun 16 '19 17:06 mrbean-bremen

I admit I forgot about it. I will do something about it after work now that you have reminded me.

PeterWone avatar Jun 16 '19 21:06 PeterWone

Thanks :)

mrbean-bremen avatar Jun 17 '19 05:06 mrbean-bremen

@PeterWone Any updates on the PR? If not please show your bug fix here would be helpful to others. Thanks.

sengiv avatar Mar 07 '20 01:03 sengiv

Does anyone has a work around this issue?

MassMessage avatar Nov 08 '21 20:11 MassMessage