Skip to content

Commit 38ecd48

Browse files
Fix path handling and add basic test
1 parent 89e0c67 commit 38ecd48

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/ImageSharp.Drawing/Processing/Processors/Text/RichTextGlyphRenderer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ protected override void EndGlyph()
309309
renderData.OutlineMap = this.Render(path);
310310
}
311311

312-
this.glyphData[this.currentCacheKey] = renderData;
312+
if (!this.noCache)
313+
{
314+
this.glyphData[this.currentCacheKey] = renderData;
315+
}
313316
}
314317
else
315318
{
@@ -386,7 +389,7 @@ private void AppendDecoration(ref TextDecorationDetails? decoration, Vector2 sta
386389
if (decoration != null)
387390
{
388391
// TODO: This only works well if we are not trying to follow a path.
389-
if (this.path is not null)
392+
if (this.path is null)
390393
{
391394
// Let's try and expand it first.
392395
if (thickness == decoration.Value.Thickness

tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,44 @@ public void DrawRichTextRainbow<TPixel>(
629629

630630
provider.RunValidatingProcessorTest(
631631
x => x.DrawText(textOptions, text, Color.White),
632-
$"RichText-ArabicRainbow-F({fontSize})",
632+
$"RichText-Rainbow-F({fontSize})",
633+
TextDrawingComparer,
634+
appendPixelTypeToFileName: false,
635+
appendSourceFileOrDescription: true);
636+
}
637+
638+
[Theory]
639+
[WithSolidFilledImages(100, 100, nameof(Color.Black), PixelTypes.Rgba32, "M10,90 Q90,90 90,45 Q90,10 50,10 Q10,10 10,40 Q10,70 45,70 Q70,70 75,50", "spiral")]
640+
[WithSolidFilledImages(350, 350, nameof(Color.Black), PixelTypes.Rgba32, "M275 175 A100 100 0 1 1 275 174", "circle")]
641+
[WithSolidFilledImages(120, 120, nameof(Color.Black), PixelTypes.Rgba32, "M50,10 L 90 90 L 10 90 L50 10", "triangle")]
642+
public void CanDrawRichTextAlongPathHorizontal<TPixel>(TestImageProvider<TPixel> provider, string svgPath, string exampleImageKey)
643+
where TPixel : unmanaged, IPixel<TPixel>
644+
{
645+
bool parsed = Path.TryParseSvgPath(svgPath, out IPath path);
646+
Assert.True(parsed);
647+
648+
Font font = CreateFont(TestFonts.OpenSans, 13);
649+
650+
const string text = "Quick brown fox jumps over the lazy dog.";
651+
TextDrawingRun run = new()
652+
{
653+
Start = 0,
654+
End = text.GetGraphemeCount(),
655+
StrikeoutPen = new SolidPen(Color.Red)
656+
};
657+
658+
TextDrawingOptions textOptions = new(font)
659+
{
660+
WrappingLength = path.ComputeLength(),
661+
VerticalAlignment = VerticalAlignment.Bottom,
662+
HorizontalAlignment = HorizontalAlignment.Left,
663+
Path = path,
664+
TextRuns = new[] { run }
665+
};
666+
667+
provider.RunValidatingProcessorTest(
668+
x => x.DrawText(textOptions, text, Color.White),
669+
$"RichText-Path-({exampleImageKey})",
633670
TextDrawingComparer,
634671
appendPixelTypeToFileName: false,
635672
appendSourceFileOrDescription: true);

0 commit comments

Comments
 (0)