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

[BUG] DrawText does render to random locations #2973

Closed
1 task done
nd1012 opened this issue Aug 16, 2024 · 1 comment
Closed
1 task done

[BUG] DrawText does render to random locations #2973

nd1012 opened this issue Aug 16, 2024 · 1 comment
Labels

Comments

@nd1012
Copy link

nd1012 commented Aug 16, 2024

Description

SKCanvas.DrawText seems to render text wild. Currently I do my first steps with SkiaSharp 2.88.8 (from NuGet) - but I'm pretty sure that the behavior of my example code must be a bug - or am I doing it wrong?

Code

            using SKPaint paint = new()
            {
                IsAntialias = true,
                Color = SKColors.Black,
                TextSize = 40
            };
            using SKSurface surface = SKSurface.Create(new SKImageInfo(150, 50));
            surface.Canvas.Clear(SKColors.White);
            surface.Canvas.Save();
            float x = 10;
            foreach (char c in "test12")
            {
                surface.Canvas.Translate(x, 10);
                surface.Canvas.DrawText(c.ToString(), 0, 28, paint);
                surface.Canvas.Restore();
                x += 20;
            }
            using SKImage img = surface.Snapshot();
            using SKData data = img.Encode(SKEncodedImageFormat.Png, 100);
            File.WriteAllBytes("test2.png", data.Span.ToArray());

Expected Behavior

I expect all characters to be rendered at the fixed base line and the correct X coordinate, and I expect no character to disappear.

Actual Behavior

The first 2 characters seem to be rendered correctly, while character 3 is lower than expected and at the wrong X coordinate, and all following characters disappear completely.

Version of SkiaSharp

Other (Please indicate in the description)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

  • Windows 11

Devices

  • Desktop computer

Relevant Screenshots

test2

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nd1012
Copy link
Author

nd1012 commented Aug 17, 2024

After reading details about Save and Restore it's clear that I'll have to call another Save after a Restore, if Restore is going to be called again. Sorry for the noise...

@nd1012 nd1012 closed this as completed Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant