Skip to content

SvgDocument.Ppi not works as expect (2 problems) #1146

Open
@lucaslynn

Description

@lucaslynn

let me show these problems by code and image:

SVG File

<svg width="100mm" height="35mm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 175">
    <rect x="0" y="0" width="500" height="175" fill="white" stroke="#000000" stroke-width="2" />
    <g fill="#000000">
        <text x="250" y="26" font-size="24" font-weight="500" dominant-baseline="middle" text-anchor="middle">Meterial Pakage Label</text>
        <text x="19" y="44" dy="16" font-size="16">Meterial: 101004117</text>
        <text x="290" y="44" dy="16" font-size="16">Quantity: 30.000 PC</text>
        <text x="19" y="72" dy="16" font-size="16">Lot: 2402050001</text>
        <text x="290" y="72" dy="16" font-size="16">Order: 490130186</text>
        <text x="19" y="100" dy="16" font-size="16">Name: XXXXXXXXXXXXXXXXXXXXXXX</text>
    </g>
</svg>

C# Code

SvgDocument svgDocument = SvgDocument.Open(this.SVGPath).FixImageSize();
svgDocument.ShapeRendering = SvgShapeRendering.Auto;
svgDocument.Ppi = 150;

//Draw on A4 paper
Bitmap bmp = new Bitmap(4960, 7015);
bmp.SetResolution(600, 600);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);

svgDocument.Draw(g);
g.Flush();
bmp.Save("D:\\1.bmp");

First Problem :Text layout Error

150 PPI
image

250 PPI
image

350 PPI
image

600 PPI
image

Second Problem :Image size(maybe it's not a bug)
When we setsolution for Bitmap object, the meaning is keeping physical size (cm / mm / inch) . Graphics should auto-resize drawing objects to fit the resolution. but SvgDocument.Ppi changes the physical size. In other words, SvgDocument convert between physical-unit and pixel always on 96 PPI.

150 PPI
image

250 PPI
image

350 PPI
image

600 PPI
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions