// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
//
//
// Encapsulates the properties required to add a layer of text to an image.
//
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging
{
#region Using
using System;
using System.Drawing;
#endregion
///
/// Encapsulates the properties required to add a layer of text to an image.
///
public class TextLayer
{
#region Fields
///
/// The color to render the text.
///
private Color textColor = Color.Black;
///
/// The opacity at which to render the text.
///
private int opacity = 100;
///
/// The font style to render the text.
///
private FontStyle fontStyle = FontStyle.Regular;
///
/// The font size to render the text.
///
private int fontSize = 48;
///
/// The position to start creating the text from.
///
private Point position = Point.Empty;
#endregion
#region Properties
///
/// Gets or sets Text.
///
public string Text { get; set; }
///
/// Gets or sets the Color to render the font.
///
/// Defaults to black.
///
///
public Color TextColor
{
get { return this.textColor; }
set { this.textColor = value; }
}
///
/// Gets or sets the name of the font.
///
public string Font { get; set; }
///
/// Gets or sets the size of the font in pixels.
///
/// Defaults to 48 pixels.
///
///
public int FontSize
{
get { return this.fontSize; }
set { this.fontSize = value; }
}
///
/// Gets or sets the FontStyle of the text layer.
///
/// Defaults to regular.
///
///
public FontStyle Style
{
get { return this.fontStyle; }
set { this.fontStyle = value; }
}
///
/// Gets or sets the Opacity of the text layer.
///
public int Opacity
{
get { return this.opacity; }
set { this.opacity = value; }
}
///
/// Gets or sets the Position of the text layer.
///
public Point Position
{
get { return this.position; }
set { this.position = value; }
}
///
/// Gets or sets a value indicating whether a DropShadow should be drawn.
///
public bool DropShadow { get; set; }
#endregion
///
/// Returns a value that indicates whether the specified object is an
/// object that is equivalent to
/// this object.
///
///
/// The object to test.
///
///
/// True if the given object is an object that is equivalent to
/// this object; otherwise, false.
///
public override bool Equals(object obj)
{
TextLayer textLayer = obj as TextLayer;
if (textLayer == null)
{
return false;
}
return this.Text == textLayer.Text
&& this.TextColor == textLayer.TextColor
&& this.Font == textLayer.Font
&& this.FontSize == textLayer.FontSize
&& this.Style == textLayer.Style
&& this.DropShadow == textLayer.DropShadow
&& this.Opacity == textLayer.Opacity
&& this.Position == textLayer.Position;
}
///
/// Returns a hash code value that represents this object.
///
///
/// A hash code that represents this object.
///
public override int GetHashCode()
{
return this.Text.GetHashCode() +
this.TextColor.GetHashCode() +
this.Font.GetHashCode() +
this.FontSize.GetHashCode() +
this.Style.GetHashCode() +
this.DropShadow.GetHashCode() +
this.Opacity.GetHashCode() +
this.Position.GetHashCode();
}
}
}