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

RichTextRun.End behaves as an inclusive index only when it is the same as the end of the string #412

Open
4 tasks done
EbiseLutica opened this issue Aug 11, 2024 · 1 comment

Comments

@EbiseLutica
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp.Drawing
  • 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

Description

According to the API documentation, RichTextRun.End is recognized as an exclusive end index, meaning the character at this position should not be decorated.

However, when RichTextRun.End is set to length - 1 (the same as the last index of the string), the RichTextRun decorates the entire string. Adding one more character at the end causes it to behave as expected.

Steps to Reproduce

Below is the sample code to reproduce:

using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

var img = new Image<Rgba32>(150, 150);
RichTextOptions GenerateOption(PointF origin) => new(SystemFonts.Get("Arial").CreateFont(24))
{
    Origin = origin,
    TextRuns = new[]
    {
        new RichTextRun { Start = 0, End = 4, Brush = new SolidBrush(Color.Red) }
    }
};

img.Mutate(ctx =>
{
    ctx.Clear(Color.White);
    ctx.DrawText(GenerateOption(new PointF(10, 10)), "abcd", new SolidBrush(Color.Black));
    ctx.DrawText(GenerateOption(new PointF(10, 30)), "abcde", new SolidBrush(Color.Black));
    ctx.DrawText(GenerateOption(new PointF(10, 50)), "abcdef", new SolidBrush(Color.Black));
});

img.SaveAsPng("output.png");

and below is the output file.
output

System Configuration

  • ImageSharp.Drawing version: 2.1.4
  • Other ImageSharp packages and versions: SixLabors.ImageSharp 3.1.5, SixLabors.Fonts 2.0.4
  • Environment (Operating system, version and so on): Windows 11 Home Build 22621
  • .NET Framework version: .NET 8.0.107
  • Additional information:
@JimBobSquarePants
Copy link
Member

Thanks for this. The underlying issue will be in the Fonts library, so I'll transfer this issue to that repository.

@JimBobSquarePants JimBobSquarePants transferred this issue from SixLabors/ImageSharp.Drawing Aug 13, 2024
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