[x] I have verified that I am running the latest version of ImageSharp.Drawing
[x] I have verified if the problem exist in both DEBUG and RELEASE mode
[x] 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.
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
Prerequisites
DEBUG
andRELEASE
modeDescription
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 tolength - 1
(the same as the last index of the string), theRichTextRun
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:
and below is the output file.![output](https://github.com/user-attachments/assets/eaee410e-84a3-44d4-9ca2-09990c4f3f75)
System Configuration