diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
index 9fb0e1e8da..15b7df2a22 100644
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
@@ -39,8 +39,8 @@
All
-
-
+
+
..\..\ImageSharp.ruleset
diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs
index 876d17aca0..1e87fd0084 100644
--- a/src/ImageSharp.Drawing/Text/DrawText.cs
+++ b/src/ImageSharp.Drawing/Text/DrawText.cs
@@ -181,7 +181,8 @@ namespace ImageSharp
{
ApplyKerning = options.ApplyKerning,
TabWidth = options.TabWidth,
- WrappingWidth = options.WrapTextWidth
+ WrappingWidth = options.WrapTextWidth,
+ Alignment = options.TextAlignment
};
renderer.RenderText(text, style);
diff --git a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs
index 6b09f23951..388b39bcc5 100644
--- a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs
+++ b/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs
@@ -2,9 +2,11 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
-
namespace ImageSharp.Drawing
{
+ using ImageSharp.PixelFormats;
+ using SixLabors.Fonts;
+
///
/// Options for influencing the drawing functions.
///
@@ -15,50 +17,94 @@ namespace ImageSharp.Drawing
///
public static readonly TextGraphicsOptions Default = new TextGraphicsOptions(true);
+ private float? blendPercentage;
+
+ private int? antialiasSubpixelDepth;
+
+ private bool? antialias;
+
+ private bool? applyKerning;
+
+ private float? tabWidth;
+
+ private PixelBlenderMode blenderMode;
+
+ private bool? useImageResolution;
+
+ private float wrapTextWidth;
+
+ private SixLabors.Fonts.TextAlignment? textAlignment;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// If set to true [enable antialiasing].
+ public TextGraphicsOptions(bool enableAntialiasing)
+ {
+ this.applyKerning = true;
+ this.tabWidth = 4;
+ this.useImageResolution = false;
+ this.wrapTextWidth = 0;
+ this.textAlignment = SixLabors.Fonts.TextAlignment.Left;
+
+ this.antialiasSubpixelDepth = 16;
+ this.blenderMode = PixelBlenderMode.Normal;
+ this.blendPercentage = 1;
+ this.antialias = enableAntialiasing;
+ }
+
+ ///
+ /// Gets or sets a value indicating whether antialiasing should be applied.
+ ///
+ public bool Antialias { get => this.antialias ?? true; set => this.antialias = value; }
+
+ ///
+ /// Gets or sets a value indicating the number of subpixels to use while rendering with antialiasing enabled.
+ ///
+ public int AntialiasSubpixelDepth { get => this.antialiasSubpixelDepth ?? 16; set => this.antialiasSubpixelDepth = value; }
+
///
- /// Whether antialiasing should be applied.
+ /// Gets or sets a value indicating the blending percentage to apply to the drawing operation
///
- public bool Antialias;
+ public float BlendPercentage { get => (this.blendPercentage ?? 1).Clamp(0, 1); set => this.blendPercentage = value; }
+
+ // In the future we could expose a PixelBlender directly on here
+ // or some forms of PixelBlender factory for each pixel type. Will need
+ // some API thought post V1.
///
- /// The number of subpixels to use while rendering with antialiasing enabled.
+ /// Gets or sets a value indicating the blending percentage to apply to the drawing operation
///
- public int AntialiasSubpixelDepth;
+ public PixelBlenderMode BlenderMode { get => this.blenderMode; set => this.blenderMode = value; }
///
- /// Whether the text should be drawing with kerning enabled.
+ /// Gets or sets a value indicating whether the text should be drawing with kerning enabled.
///
- public bool ApplyKerning;
+ public bool ApplyKerning { get => this.applyKerning ?? true; set => this.applyKerning = value; }
///
- /// The number of space widths a tab should lock to.
+ /// Gets or sets a value indicating the number of space widths a tab should lock to.
///
- public float TabWidth;
+ public float TabWidth { get => this.tabWidth ?? 4; set => this.tabWidth = value; }
///
- /// Flag weather to use the current image resultion to for point size scaling.
+ /// Gets or sets a value indicating whether to use the current image resultion to for point size scaling.
/// If this is [false] the text renders at 72dpi otherwise it renders at Image resolution
///
- public bool UseImageResolution;
+ public bool UseImageResolution { get => this.useImageResolution ?? false; set => this.useImageResolution = value; }
///
- /// If greater than zero determine the width at which text should wrap.
+ /// Gets or sets a value indicating if greater than zero determine the width at which text should wrap.
///
- public float WrapTextWidth;
+ public float WrapTextWidth { get => this.wrapTextWidth; set => this.wrapTextWidth = value; }
///
- /// Initializes a new instance of the struct.
+ /// Gets or sets a value indicating how to align the text relative to the rendering space.
+ /// If is greater than zero it will align relative to the space
+ /// defined by the location and width, if equals zero, and thus
+ /// wrapping disabled, then the alignment is relative to the drawing location.
///
- /// If set to true [enable antialiasing].
- public TextGraphicsOptions(bool enableAntialiasing)
- {
- this.Antialias = enableAntialiasing;
- this.ApplyKerning = true;
- this.TabWidth = 4;
- this.AntialiasSubpixelDepth = 16;
- this.UseImageResolution = false;
- this.WrapTextWidth = 0;
- }
+ public TextAlignment TextAlignment { get => this.textAlignment ?? TextAlignment.Left; set => this.textAlignment = value; }
///
/// Performs an implicit conversion from to .
@@ -71,7 +117,9 @@ namespace ImageSharp.Drawing
{
return new TextGraphicsOptions(options.Antialias)
{
- AntialiasSubpixelDepth = options.AntialiasSubpixelDepth
+ AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
+ blendPercentage = options.BlendPercentage,
+ blenderMode = options.BlenderMode
};
}
@@ -86,7 +134,9 @@ namespace ImageSharp.Drawing
{
return new GraphicsOptions(options.Antialias)
{
- AntialiasSubpixelDepth = options.AntialiasSubpixelDepth
+ AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
+ BlenderMode = options.BlenderMode,
+ BlendPercentage = options.BlendPercentage
};
}
}