Skip to content

Commit 4319d93

Browse files
committed
Fix C# 14 SequenceEqual overload resolution issue
Use AsEnumerable() to force LINQ overload instead of span overload in TextRendererTests to avoid C# 14 breaking change warnings.
1 parent 487bfa2 commit 4319d93

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

CreatePdf.NET.Tests/TextRendererTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void RenderGlyph_FillsCorrectPixels()
115115

116116
TextRenderer.RenderGlyph(bitmap, width, glyph, 20, 20, 2);
117117

118-
bitmap.Should().Contain(true, "character 'I' should have visible pixels");
118+
bitmap.Should().Contain(expected: true, "character 'I' should have visible pixels");
119119
}
120120

121121
[Fact]
@@ -198,8 +198,8 @@ public void RenderBitmap_PixelPerfectTest()
198198
var pixels = image.GetPixelMemory().ToArray();
199199

200200
pixels.Chunk(3)
201-
.Should().Contain(rgb => rgb.SequenceEqual(new byte[] { 255, 255, 255 }), "should have white pixels")
202-
.And.Contain(rgb => rgb.SequenceEqual(new byte[] { 0, 0, 0 }), "should have black pixels");
201+
.Should().Contain(rgb => rgb.AsEnumerable().SequenceEqual(new byte[] { 255, 255, 255 }), "should have white pixels")
202+
.And.Contain(rgb => rgb.AsEnumerable().SequenceEqual(new byte[] { 0, 0, 0 }), "should have black pixels");
203203
}
204204

205205
[Fact]

CreatePdf.NET.Tests/TextWrapperTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ public void Measure_CalculatesCorrectWidth()
130130
[Fact]
131131
public void Wrap_RealWorldExample_HandlesCorrectly()
132132
{
133-
const string text = @"This is a real-world example of text that might appear in a PDF document.
134-
It contains multiple sentences, various punctuation marks, and even some numbers like 123.45!";
133+
const string text = """
134+
This is a real-world example of text that might appear in a PDF document.
135+
It contains multiple sentences, various punctuation marks, and even some numbers like 123.45!
136+
""";
135137

136138
var result = TextWrapper.Wrap(text, 14, 400);
137139

CreatePdf.NET/Internal/TextRenderer.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ public static BitmapImage RenderBitmap(ReadOnlySpan<char> text, Dye textDye, Dye
331331

332332
internal static (int Width, int Height) CalculateDimensions(int charCount, int scale)
333333
{
334-
var textWidth = (charCount * (CharWidth + CharSpacing) * scale) - (CharSpacing * scale);
335-
return (Math.Max(textWidth, 0) + (Padding * 2), (CharHeight * scale) + (Padding * 2));
334+
var textWidth = charCount * (CharWidth + CharSpacing) * scale - CharSpacing * scale;
335+
return (Math.Max(textWidth, 0) + Padding * 2, CharHeight * scale + Padding * 2);
336336
}
337337

338338
private static char[] ExtractRenderableChars(ReadOnlySpan<char> text)
@@ -371,7 +371,7 @@ internal static void RenderGlyph(bool[] bitmap, int width, byte[] glyph, int x,
371371
var glyphRow = glyph[row];
372372
for (var col = 0; col < CharWidth; col++)
373373
if ((glyphRow & (1 << (CharWidth - 1 - col))) != 0)
374-
FillPixel(bitmap, width, x + (col * scale), y + (row * scale), scale);
374+
FillPixel(bitmap, width, x + col * scale, y + row * scale, scale);
375375
}
376376
}
377377

@@ -386,8 +386,9 @@ private static void FillPixel(bool[] bitmap, int width, int x, int y, int scale)
386386
var col = x + dx;
387387
if (row < 0 || col < 0 || width <= 0 || row >= height || col >= width)
388388
continue;
389-
var pixelIndex = (row * width) + col;
390-
if (pixelIndex < bitmap.Length) bitmap[pixelIndex] = true;
389+
var pixelIndex = row * width + col;
390+
if (pixelIndex < bitmap.Length)
391+
bitmap[pixelIndex] = true;
391392
}
392393
}
393394
}

0 commit comments

Comments
 (0)