// Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
//
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System.Drawing;
using SharpMap.Api.Enums;
using SharpMap.Api.Layers;
namespace SharpMap.Styles
{
///
/// Defines a style used for rendering labels
///
public class LabelStyle : Style, ILabelStyle
{
///
/// Initializes a new LabelStyle
///
public LabelStyle()
{
Font = new Font("Times New Roman", 12f);
Offset = new PointF(0, 0);
CollisionDetection = false;
CollisionBuffer = new Size(0, 0);
ForeColor = Color.Black;
HorizontalAlignment = HorizontalAlignmentEnum.Center;
VerticalAlignment = VerticalAlignmentEnum.Middle;
}
protected LabelStyle(LabelStyle another) : base(another)
{
Font = (Font) another.Font.Clone();
Offset = another.Offset;
CollisionDetection = another.CollisionDetection;
CollisionBuffer = another.CollisionBuffer;
ForeColor = another.ForeColor;
if (another.BackColor != null && another.BackColor is SolidBrush)
{
BackColor = new SolidBrush((another.BackColor as SolidBrush).Color);
}
if (another.Halo != null)
{
Halo = new Pen(another.Halo.Color, another.Halo.Width);
}
Offset = another.Offset;
HorizontalAlignment = another.HorizontalAlignment;
VerticalAlignment = another.VerticalAlignment;
}
///
/// Label Font
///
public Font Font { get; set; }
///
/// Font color
///
public Color ForeColor { get; set; }
///
/// The background color of the label. Set to transparent brush or null if background isn't needed
///
public Brush BackColor { get; set; }
///
/// Creates a halo around the text
///
public Pen Halo { get; set; }
///
/// Specifies relative position of labels with respect to objects label point
///
public PointF Offset { get; set; }
///
/// Gets or sets whether Collision Detection is enabled for the labels.
/// If set to true, label collision will be tested.
///
public bool CollisionDetection { get; set; }
///
/// Distance around label where collision buffer is active
///
public SizeF CollisionBuffer { get; set; }
///
/// The horisontal alignment of the text in relation to the labelpoint
///
public HorizontalAlignmentEnum HorizontalAlignment { get; set; }
///
/// The horisontal alignment of the text in relation to the labelpoint
///
public VerticalAlignmentEnum VerticalAlignment { get; set; }
public override object Clone()
{
return new LabelStyle(this);
}
}
}