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

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

Open
lucaslynn opened this issue Feb 10, 2024 · 0 comments
Open

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

lucaslynn opened this issue Feb 10, 2024 · 0 comments

Comments

@lucaslynn
Copy link

lucaslynn commented Feb 10, 2024

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

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

1 participant