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

Inter Variable rendering incorrectly #369

Closed
sowa705 opened this issue Dec 15, 2023 · 8 comments
Closed

Inter Variable rendering incorrectly #369

sowa705 opened this issue Dec 15, 2023 · 8 comments

Comments

@sowa705
Copy link

sowa705 commented Dec 15, 2023

Hi, i'm trying to render text with the https://rsms.me/inter/ font but the result is not correct.

var fontFamily = fontCollection.Get("Inter Variable");
var font = fontFamily.CreateFont(96, FontStyle.Regular);

var img = new Image<Rgba32>(1960, 180, Rgba32.ParseHex("#FF0000FF"));
img.Mutate(g => {
    var textFont = font;
    var paths = TextBuilder.GenerateGlyphs("Inter variable", new TextOptions(textFont) {
        Origin = new Vector2(980, 90),
        VerticalAlignment = VerticalAlignment.Center,
        HorizontalAlignment = HorizontalAlignment.Center,
        TextAlignment = TextAlignment.Center,
        Font = textFont
    });
    g.Fill(Color.Black, paths);
});

img.Save("test.png");

Resulting image

test

Test environment

SixLabors.Fonts Version="2.0.1"
SixLabors.ImageSharp Version="3.1.1"
SixLabors.ImageSharp.Drawing Version="2.1.0"
OS: Windows 11 x64
Runtime: .NET 8.0.100
@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Dec 15, 2023

Sorry, I thought this was asking for support for the variable output. (I couldn’t see the detail on my phone)

If you use DrawText. It will render properly. There’s something not working with filling path generation for certain glyphs. @tocsoft would you have a clue why this would happen given it should be the same vectors?

@JimBobSquarePants JimBobSquarePants marked this as a duplicate and then as not a duplicate of #5 Dec 15, 2023
@tocsoft
Copy link
Member

tocsoft commented Dec 15, 2023

I don't think that's a bug, the issue is that fonts expect to be rendered with the NoneZero Intersection Rule (which our drawText apis do for you) but the Fill api defaults to the EvenOdd Intersection Rule rule for rasterization.

@tocsoft
Copy link
Member

tocsoft commented Dec 15, 2023

FYI the DrawText APIs will be more efficient (at least for larger pieces text) you should generally only use the TextBuilder.GenerateGlyphs() path building base APIs if you need to transform/mutate vectors themselves.

@JimBobSquarePants
Copy link
Member

Thanks @tocsoft !

@sowa705
Copy link
Author

sowa705 commented Dec 17, 2023

Thanks for help and explanation

@sowa705 sowa705 closed this as completed Dec 17, 2023
@SpaceCheetah
Copy link

Is there a way to detect when a font needs NonZero or not, without visually looking at it? Surely there is somewhere, but I'm not seeing where DrawText deals with that (and for my situation I need transformations at the glyph level).

@SpaceCheetah
Copy link

On closer inspection, it looks like buried deep in RichTextGlyphRenderer it always uses NonZero, unless I'm reading something wrong. Is that just always correct?

@JimBobSquarePants
Copy link
Member

Yeah TrueType and CFF fonts always use NonZero

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

4 participants