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

One extra newline is not added when 2 explicit newlines are specified #434

Open
4 tasks done
jez9999 opened this issue Dec 16, 2024 · 5 comments
Open
4 tasks done

Comments

@jez9999
Copy link

jez9999 commented Dec 16, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of Fonts
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Fonts version

2.0.7

Other Six Labors packages and versions

SixLabors.ImageSharp 3.1.6, SixLabors.ImageSharp.Drawing 2.1.4

Environment (Operating system, version and so on)

Windows 10

.NET Framework version

.NET 9

Description

After fix #433, another issue has been created; now, a second explicit newline is not added when it should be. See repro program below.

Steps to Reproduce

internal class Program {
    static void Main(string[] args) {
        Console.WriteLine("Rendering test images...");

        var fontManager = new FontManager();

        Image imgTest3 = new Image<Rgba32>(550, 350, Color.White);
        imgTest3.Mutate(x =>
            x.DrawText(
                new RichTextOptions(fontManager.GetFont("Arial", 60, FontStyle.Regular)) {
                    Origin = new Vector2(50, 20),
                    WrappingLength = 400,
                },
                "- Lorem ipsullll\n\ndolor sit amet\n-consectetur elit",
                Color.Black
            )
        );
        imgTest3.SaveAsPng("c:/development/diff/testImg3.png");
        // ^ incorrect, no extra newline after: - Lorem ipsullll

        Image imgTest4 = new Image<Rgba32>(550, 350, Color.White);
        imgTest4.Mutate(x =>
            x.DrawText(
                new RichTextOptions(fontManager.GetFont("Arial", 60, FontStyle.Regular)) {
                    Origin = new Vector2(50, 20),
                    WrappingLength = 400,
                },
                "- Lorem ipsullll\n\n\ndolor sit amet\n-consectetur elit",
                Color.Black
            )
        );
        imgTest4.SaveAsPng("c:/development/diff/testImg4.png");
        // ^ incorrect, one rather than two extra newlines after: - Lorem ipsullll

        Console.WriteLine("Done.");
    }
}

Images

testImg3
testImg4

@JimBobSquarePants
Copy link
Member

Both are rendering as expected.

The first new line is negated by the wrapping at the final l.

@jez9999
Copy link
Author

jez9999 commented Dec 16, 2024

Yes but in the first case, the second newline should cause a blank line. In the second case, the third newline should cause a second blank line.

The only reason for wrapping text is that there's not enough room to display the text that you need to render. In the first case, there is enough space to display "- Lorem ipsullll". IMHO the error is that ImageSharp thinks that any wrapping is needed here in the first place. Because there's enough space to render that, it shouldn't wrap, and normal processing should apply for "\n\n", which is two newlines = 1 blank line.

@JimBobSquarePants
Copy link
Member

How about you open a PR. It’s midnight here.

@jez9999
Copy link
Author

jez9999 commented Dec 16, 2024

Sure, I might take a look at the code when I'm less busy. But I thought the idea of a bug report was to establish what the actual and intended behaviour was before making changes.

I'm just saying: two newline characters have been explicitly specified. I don't see any circumstance where it makes sense not to render both of them.

@JimBobSquarePants
Copy link
Member

I'm working on this. It's taking a complete rewrite of the line breaking algorithm so might be a few days.

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

2 participants