Skip to content

Commit

Permalink
fix outline offsetting
Browse files Browse the repository at this point in the history
  • Loading branch information
tocsoft committed May 10, 2024
1 parent c8ae268 commit a90adac
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ protected override void EndGlyph()

if (renderData.OutlineMap != null)
{
int offset = (int)((this.currentPen?.StrokeWidth ?? 0) / 2);
this.DrawingOperations.Add(new DrawingOperation
{
RenderLocation = renderLocation,
RenderLocation = renderLocation - new Size(offset, offset),
Map = renderData.OutlineMap,
Brush = this.currentPen?.StrokeFill ?? this.currentBrush!,
RenderPass = RenderOrderOutline
Expand Down
68 changes: 68 additions & 0 deletions tests/ImageSharp.Drawing.Tests/Issues/Issue_330.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;

namespace SixLabors.ImageSharp.Drawing.Tests.Issues;
public class Issue_330
{
[Theory]
[WithSolidFilledImages(2084, 2084, nameof(Color.BlueViolet), PixelTypes.Rgba32)]
public void OffsetTextOutlines<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
FontFamily fontFamily = TestFontUtilities.GetFontFamily(TestFonts.OpenSans);

Font bibfont = fontFamily.CreateFont(600, FontStyle.Bold);
Font namefont = fontFamily.CreateFont(140, FontStyle.Bold);

provider.RunValidatingProcessorTest(p =>
{
p.DrawText(
new RichTextOptions(bibfont)
{
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
TextDirection = TextDirection.LeftToRight,
Origin = new Point(1156, 1024),
},
"9999",
Brushes.Solid(Color.White),
Pens.Solid(Color.Black, 20));

p.DrawText(
new RichTextOptions(namefont)
{
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
TextDirection = TextDirection.LeftToRight,
Origin = new Point(1156, 713),
},
"JOHAN",
Brushes.Solid(Color.White),
Pens.Solid(Color.Black, 5));

p.DrawText(
new RichTextOptions(namefont)
{
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
TextDirection = TextDirection.LeftToRight,
Origin = new Point(1156, 1381),
},
"TIGERTECH",
Brushes.Solid(Color.White),
Pens.Solid(Color.Black, 5));
});
}
}
22 changes: 20 additions & 2 deletions tests/ImageSharp.Drawing.Tests/TestFontUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.Globalization;
using System.Reflection;
using SixLabors.Fonts;
using IOPath = System.IO.Path;
Expand All @@ -19,7 +20,15 @@ public static class TestFontUtilities
/// <param name="size">The font size.</param>
/// <returns>The <see cref="Font"/></returns>
public static Font GetFont(string name, float size)
=> GetFont(new FontCollection(), name, size);
=> GetFontFamily(name).CreateFont(size);

/// <summary>
/// Gets a font family with the given name.
/// </summary>
/// <param name="name">The name of the font.</param>
/// <returns>The <see cref="Font"/></returns>
public static FontFamily GetFontFamily(string name)
=> GetFontFamily(new FontCollection(), name);

/// <summary>
/// Gets a font with the given name and size.
Expand All @@ -29,7 +38,16 @@ public static Font GetFont(string name, float size)
/// <param name="size">The font size.</param>
/// <returns>The <see cref="Font"/></returns>
public static Font GetFont(FontCollection collection, string name, float size)
=> collection.Add(GetPath(name)).CreateFont(size);
=> GetFontFamily(collection, name).CreateFont(size);

/// <summary>
/// Gets a font family with the given name
/// </summary>
/// <param name="collection">The collection to add the font to</param>
/// <param name="name">The name of the font.</param>
/// <returns>The <see cref="Font"/></returns>
public static FontFamily GetFontFamily(FontCollection collection, string name)
=> collection.Add(GetPath(name), CultureInfo.InvariantCulture);

/// <summary>
/// The formats directory.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a90adac

Please sign in to comment.