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

Diverse problems with text alignment when rendering to EMF #1138

Open
jbartlau opened this issue Jan 30, 2024 · 3 comments
Open

Diverse problems with text alignment when rendering to EMF #1138

jbartlau opened this issue Jan 30, 2024 · 3 comments

Comments

@jbartlau
Copy link

jbartlau commented Jan 30, 2024

Description

When rendering the attached sample file to EMF (source: https://en.m.wikipedia.org/wiki/File:SVG_Test_TextAlign.svg), the result is not as expected in a number of ways. The expected result would be:

image

The actual result however is:

image

The code used to produce the EMF is stripped down to the max and uses all default values:

string emfTempPath = @"c:\temp\EMF_Test_TextAlign.emf";
var svg = SvgDocument.Open(@"c:\temp\SVG_Test_TextAlign.svg");

                
using (Graphics bufferGraphics = Graphics.FromHwndInternal(IntPtr.Zero))
{
    using (var metafile = new Metafile(emfTempPath, bufferGraphics.GetHdc()))
    {
        using (Graphics graphics = Graphics.FromImage(metafile))
        {
            svg.Draw(graphics);
        }
    }
}

Example data

Input SVG:
text-align.svg

Result file as EMF:
EMF_Test_TextAlign.zip

Used Versions

Reproduced with NuGet version 3.4.6

@jbartlau jbartlau changed the title Diverse problems with text alignment Diverse problems with text alignment when rendering to EMF Jan 30, 2024
@jbartlau
Copy link
Author

I figure it may be hard to mimic the behavior in perfect EMFs. However there could be a fallback to rasterized rendering if unrenderable parts are encountered. Unfortunately, even the rasterized output (I tried BMP) has a number of issues for the test file.

@jbartlau
Copy link
Author

jbartlau commented Feb 2, 2024

Probably it's "just" a number of missing features, the most important ones for this test file being:

  • missing support for alignment-baseline
  • missing support for writing-mode
  • missing support for font-variant

@paulushub
Copy link
Contributor

In particular, the font-variant support in GDI/GDI+ is limited.
No easy way out, except parsing the font files to improve support or using a different rendering system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants