using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
|
namespace Eventech.DynPicture.Model
|
{
|
/// <summary>
|
/// 文本图片信息
|
/// </summary>
|
public class PictureTextInfo : IPictureBaseInfo, ICloneable
|
{
|
public PictureTextInfo() { }
|
public PictureTextInfo(PictureTextInfo rhs)
|
{
|
#region base
|
this.ID = rhs.ID;
|
this.Name = rhs.Name;
|
this.AllowEdit = rhs.AllowEdit;
|
this.InfoType = rhs.InfoType;
|
this.Level = rhs.Level;
|
this.Description = rhs.Description;
|
this.Tag = rhs.Tag;
|
#endregion
|
|
this.Point = rhs.Point;
|
|
#region font
|
this.FontName = rhs.FontName;
|
this.FontSize = rhs.FontSize;
|
this.FontColor = rhs.FontColor;
|
this.IsBold = rhs.IsBold;
|
this.IsItalic = rhs.IsItalic;
|
this.Angle = rhs.Angle;
|
#endregion
|
|
#region textBox
|
this.TextBoxBorderVisible = rhs.TextBoxBorderVisible;
|
this.TextBoxBorderWidth = rhs.TextBoxBorderWidth;
|
this.TextBoxBorderColor = rhs.TextBoxBorderColor;
|
this.TextBoxBackgroundTransparent = rhs.TextBoxBackgroundTransparent;
|
this.TextBoxBackgroundColor = rhs.TextBoxBackgroundColor;
|
this.TextBoxWidth = rhs.TextBoxWidth;
|
this.TextBoxHeight = rhs.TextBoxHeight;
|
this.HAlignment = rhs.HAlignment;
|
#endregion
|
|
#region text
|
this.TextType = rhs.TextType;
|
this.DefaultText = rhs.DefaultText;
|
this.Text = rhs.Text;
|
this.TextFormat = rhs.TextFormat;
|
this.ScaleX = rhs.ScaleX;
|
this.ScaleY = rhs.ScaleY;
|
#endregion
|
|
}
|
|
#region 图片信息基础属性
|
|
/// <summary>
|
/// 唯一标识
|
/// </summary>
|
public long ID { get; set; }
|
|
/// <summary>
|
/// 名称
|
/// </summary>
|
public string Name { get; set; }
|
|
/// <summary>
|
/// 是否允许修改
|
/// </summary>
|
public bool AllowEdit { get; set; }
|
|
/// <summary>
|
/// 获取图片信息类型
|
/// </summary>
|
public ePictureInfoType InfoType
|
{
|
get { return _infoType; }
|
private set { _infoType = value; }
|
}
|
private ePictureInfoType _infoType = ePictureInfoType.Text;
|
|
/// <summary>
|
/// 图层
|
/// </summary>
|
public int Level { get; set; }
|
|
/// <summary>
|
/// 描述
|
/// </summary>
|
public virtual string Description { get; set; }
|
|
/// <summary>
|
/// 标签
|
/// </summary>
|
public virtual string Tag { get; set; }
|
|
#endregion
|
|
/// <summary>
|
/// 坐标点
|
/// </summary>
|
public PointF Point { get; set; }
|
|
/// <summary>
|
/// 点牟定方式
|
/// </summary>
|
public ePointAnchor PointAnchor
|
{
|
get { return _pointAnchor; }
|
set { _pointAnchor = value; }
|
}
|
private ePointAnchor _pointAnchor = XmlConfigInfo.ConfigInfo.PointAnchor;
|
|
#region font
|
/// <summary>
|
/// 字体名称
|
/// </summary>
|
public string FontName
|
{
|
get { return _fontName; }
|
set { _fontName = value; }
|
}
|
private string _fontName = XmlConfigInfo.ConfigInfo.FontName;
|
|
/// <summary>
|
/// 字体大小
|
/// </summary>
|
public float FontSize
|
{
|
get { return _fontSize; }
|
set { _fontSize = value; }
|
}
|
private float _fontSize = XmlConfigInfo.ConfigInfo.FontSize;
|
|
/// <summary>
|
/// 字体颜色
|
/// </summary>
|
public Color FontColor
|
{
|
get { return _fontColor; }
|
set { _fontColor = value; }
|
}
|
private Color _fontColor = XmlConfigInfo.ConfigInfo.FontColor;
|
|
/// <summary>
|
/// 是否加粗
|
/// </summary>
|
public bool IsBold
|
{
|
get { return _isBold; }
|
set { _isBold = value; }
|
}
|
private bool _isBold = XmlConfigInfo.ConfigInfo.IsBold;
|
|
/// <summary>
|
/// 是否倾斜
|
/// </summary>
|
public bool IsItalic
|
{
|
get { return _isItalic; }
|
set { _isItalic = value; }
|
}
|
private bool _isItalic = XmlConfigInfo.ConfigInfo.IsItalic;
|
|
/// <summary>
|
/// 旋转角度
|
/// </summary>
|
public float Angle
|
{
|
get { return _angle; }
|
set { _angle = value; }
|
}
|
private float _angle = XmlConfigInfo.ConfigInfo.TextAngle;
|
|
#endregion
|
|
#region textBox
|
|
/// <summary>
|
/// 文本框是否可见
|
/// </summary>
|
public bool TextBoxBorderVisible
|
{
|
get { return _textBoxBorderVisible; }
|
set { _textBoxBorderVisible = value; }
|
}
|
private bool _textBoxBorderVisible;
|
|
/// <summary>
|
/// 文本边框宽度
|
/// </summary>
|
public float TextBoxBorderWidth
|
{
|
get { return _textBoxBorderWidth; }
|
set { _textBoxBorderWidth = value; }
|
}
|
private float _textBoxBorderWidth = XmlConfigInfo.ConfigInfo.TextBoxBorderWidth;
|
|
/// <summary>
|
/// 文本边框颜色
|
/// </summary>
|
public Color TextBoxBorderColor
|
{
|
get { return _textBoxBorderColor; }
|
set { _textBoxBorderColor = value; }
|
}
|
private Color _textBoxBorderColor = XmlConfigInfo.ConfigInfo.TextBoxBorderColor;
|
|
/// <summary>
|
/// 背景色是否透明
|
/// </summary>
|
public bool TextBoxBackgroundTransparent
|
{
|
get { return _textBoxBackgroundTransparent; }
|
set { _textBoxBackgroundTransparent = value; }
|
}
|
private bool _textBoxBackgroundTransparent = XmlConfigInfo.ConfigInfo.TextBoxBackgroundTransparent;
|
|
/// <summary>
|
/// 背景颜色
|
/// </summary>
|
public Color TextBoxBackgroundColor
|
{
|
get { return _textBoxBackgroundColor; }
|
set { _textBoxBackgroundColor = value; }
|
}
|
private Color _textBoxBackgroundColor = XmlConfigInfo.ConfigInfo.TextBoxBackgroundColor;
|
|
/// <summary>
|
/// 文本框宽度
|
/// </summary>
|
public float TextBoxWidth
|
{
|
get { return _textBoxWidth; }
|
set { _textBoxWidth = value; }
|
}
|
private float _textBoxWidth = XmlConfigInfo.ConfigInfo.TextBoxWidth;
|
|
/// <summary>
|
/// 文本框高度
|
/// </summary>
|
public float TextBoxHeight
|
{
|
get { return _textBoxHeight; }
|
set { _textBoxHeight = value; }
|
}
|
private float _textBoxHeight = XmlConfigInfo.ConfigInfo.TextBoxHeight;
|
|
|
/// <summary>
|
/// 文字在文本框中的对齐方式(默认Center)
|
/// </summary>
|
public StringAlignment HAlignment
|
{
|
get { return _halignment; }
|
set { _halignment = value; }
|
}
|
private StringAlignment _halignment = XmlConfigInfo.ConfigInfo.TextHAlignment;
|
|
/// <summary>
|
/// 文字在文本框中的对齐方式(默认Center)
|
/// </summary>
|
public StringAlignment VAlignment
|
{
|
get { return _valignment; }
|
set { _valignment = value; }
|
}
|
private StringAlignment _valignment = XmlConfigInfo.ConfigInfo.TextVAlignment;
|
|
#endregion
|
|
#region 文本
|
|
/// <summary>
|
/// 文本类型
|
/// </summary>
|
public eTextType TextType
|
{
|
get { return _textType; }
|
set { _textType = value; }
|
}
|
private eTextType _textType = eTextType.Text;
|
|
/// <summary>
|
/// 默认文本
|
/// </summary>
|
public string DefaultText { get; set; }
|
|
/// <summary>
|
/// 文本
|
/// </summary>
|
public string Text { get; set; }
|
|
/// <summary>
|
/// 文本格式
|
/// </summary>
|
public string TextFormat { get; set; }
|
|
/// <summary>
|
/// X方向文本缩放比例
|
/// </summary>
|
public float ScaleX
|
{
|
get { return _scalex; }
|
set { _scalex = value; }
|
}
|
private float _scalex = 1f;
|
|
/// <summary>
|
/// Y方向文本缩放比例
|
/// </summary>
|
public float ScaleY
|
{
|
get { return _scaley; }
|
set { _scaley = value; }
|
}
|
private float _scaley = 1f;
|
|
/// <summary>
|
/// 显示文本
|
/// </summary>
|
public virtual string DisplayText
|
{
|
get
|
{
|
if (string.IsNullOrEmpty(this.Text))
|
return this.DefaultText;
|
var dispText = this.Text;
|
switch (this.TextType)
|
{
|
case eTextType.Text:
|
dispText = this.Text;
|
if (!string.IsNullOrEmpty(this.TextFormat))
|
{
|
dispText = string.Format(this.TextFormat,dispText);
|
}
|
break;
|
case eTextType.Numeric:
|
if (!string.IsNullOrEmpty(this.TextFormat))
|
dispText = Convert.ToDouble(this.Text).ToString(this.TextFormat);
|
break;
|
case eTextType.DateTime:
|
if (!string.IsNullOrEmpty(this.TextFormat))
|
dispText = Convert.ToDateTime(this.Text).ToString(this.TextFormat);
|
break;
|
default: dispText = this.Text; break;
|
}
|
return dispText;
|
}
|
}
|
#endregion
|
|
#region Clone
|
/// <summary>
|
///
|
/// </summary>
|
/// <returns></returns>
|
public PictureTextInfo Clone()
|
{
|
return new PictureTextInfo(this);
|
}
|
object ICloneable.Clone()
|
{
|
return this.Clone();
|
}
|
|
#endregion Clone
|
|
/// <summary>
|
/// 获取坐标信息
|
/// </summary>
|
/// <param name="g"></param>
|
/// <returns></returns>
|
public ImageInfoCoordinate GetCoordinate(Graphics g)
|
{
|
string dispText = this.DisplayText;
|
SizeF size;
|
if (string.IsNullOrEmpty(dispText))
|
{
|
if (this.TextBoxWidth <= 0 || this.TextBoxHeight <= 0)
|
return null;
|
size = new SizeF(this.TextBoxWidth, this.TextBoxHeight);
|
}
|
else
|
{
|
var fontStyle = FontStyle.Regular;
|
if (IsBold)
|
fontStyle = fontStyle | FontStyle.Bold;
|
if (IsItalic)
|
fontStyle = fontStyle | FontStyle.Italic;
|
using (var f = new Font(this.FontName, this.FontSize, fontStyle))
|
{
|
size = g.MeasureString(dispText, f);
|
}
|
if (this.TextBoxWidth > size.Width)
|
size.Width = this.TextBoxWidth;
|
if (this.TextBoxHeight > size.Height)
|
size.Height = this.TextBoxHeight;
|
}
|
|
var h = StringAlignment.Near;
|
var v = StringAlignment.Near;
|
switch (this.PointAnchor)
|
{
|
case ePointAnchor.TopLeft: break;
|
case ePointAnchor.TopMiddle: h = StringAlignment.Center; break;
|
case ePointAnchor.TopRight: h = StringAlignment.Far; break;
|
case ePointAnchor.CenterLeft: v = StringAlignment.Center; break;
|
case ePointAnchor.CenterMiddle: v = StringAlignment.Center; h = StringAlignment.Center; break;
|
case ePointAnchor.CenterRight: v = StringAlignment.Center; h = StringAlignment.Far; break;
|
case ePointAnchor.BottonLeft: v = StringAlignment.Far; break;
|
case ePointAnchor.BottonMiddle: v = StringAlignment.Far; h = StringAlignment.Center; break;
|
case ePointAnchor.BottomRight: v = StringAlignment.Far; h = StringAlignment.Far; break;
|
default: break;
|
}
|
|
|
return new ImageInfoCoordinate(this.Point, this.Angle, size, h, v);
|
}
|
|
/// <summary>
|
/// 绘制信息(用DisplayText)
|
/// </summary>
|
/// <param name="g"></param>
|
/// <param name="coordinate"></param>
|
public void DrawInfo(Graphics g, ImageInfoCoordinate coordinate)
|
{
|
var dispText= this.DisplayText;
|
if (string.IsNullOrEmpty(dispText))
|
return;
|
var points = new PointF[] { coordinate.AfterLeftTop, coordinate.AfterRightTop, coordinate.AfterRightBottom, coordinate.AfterLeftBottom };
|
if (this.TextBoxBorderVisible)
|
{
|
using (var pen = new Pen(this.TextBoxBorderColor, this.TextBoxBorderWidth))
|
{
|
g.DrawPolygon(pen, points);
|
}
|
}
|
if (!this.TextBoxBackgroundTransparent)
|
{
|
using (var b = new SolidBrush(this.TextBoxBackgroundColor))
|
{
|
g.FillPolygon(b, points);
|
}
|
}
|
var fontStyle = FontStyle.Regular;
|
if (IsBold)
|
fontStyle = fontStyle | FontStyle.Bold;
|
if (IsItalic)
|
fontStyle = fontStyle | FontStyle.Italic;
|
|
using (var f = new Font(this.FontName, this.FontSize, fontStyle))
|
{
|
g.DrawString(dispText, coordinate, f, this.FontColor, this.ScaleX, this.ScaleY, this.HAlignment, this.VAlignment);
|
}
|
}
|
|
|
/// <summary>
|
/// 用Text绘制
|
/// </summary>
|
/// <param name="g"></param>
|
/// <param name="coordinate"></param>
|
public void DrawInfo2(Graphics g, ImageInfoCoordinate coordinate)
|
{
|
var dispText = this.Text;
|
if (dispText== null)
|
dispText = "";
|
var points = new PointF[] { coordinate.AfterLeftTop, coordinate.AfterRightTop, coordinate.AfterRightBottom, coordinate.AfterLeftBottom };
|
if (this.TextBoxBorderVisible)
|
{
|
using (var pen = new Pen(this.TextBoxBorderColor, this.TextBoxBorderWidth))
|
{
|
g.DrawPolygon(pen, points);
|
}
|
}
|
if (!this.TextBoxBackgroundTransparent)
|
{
|
using (var b = new SolidBrush(this.TextBoxBackgroundColor))
|
{
|
g.FillPolygon(b, points);
|
}
|
}
|
var fontStyle = FontStyle.Regular;
|
if (IsBold)
|
fontStyle = fontStyle | FontStyle.Bold;
|
if (IsItalic)
|
fontStyle = fontStyle | FontStyle.Italic;
|
|
using (var f = new Font(this.FontName, this.FontSize, fontStyle))
|
{
|
g.DrawString(dispText, coordinate, f, this.FontColor, this.ScaleX, this.ScaleY, this.HAlignment, this.VAlignment);
|
}
|
}
|
|
|
|
|
|
/// <summary>
|
/// 绘制高亮外观
|
/// </summary>
|
/// <param name="g"></param>
|
/// <param name="coordinate"></param>
|
/// <param name="func"></param>
|
public void DrawHighlightAppearance(Graphics g, ImageInfoCoordinate coordinate, Func<PointF, PointF> func)
|
{
|
var points = new PointF[5];
|
points[0] = func(coordinate.AfterLeftTop);
|
points[1] = func(coordinate.AfterRightTop);
|
points[2] = func(coordinate.AfterRightBottom);
|
points[3] = func(coordinate.AfterLeftBottom);
|
points[4] = points[0];
|
using (var pen = new Pen(XmlConfigInfo.ConfigInfo.HighlightBorderColor, XmlConfigInfo.ConfigInfo.HighlightBorderWidth))
|
{
|
g.DrawLines(pen, points);
|
}
|
}
|
|
public void IncreaseAxisValue(eAxis axis, float value)
|
{
|
switch (axis)
|
{
|
case eAxis.X: this.Point = new PointF(this.Point.X + value, this.Point.Y); break;
|
case eAxis.Y: this.Point = new PointF(this.Point.X, this.Point.Y + value); break;
|
default: break;
|
}
|
}
|
|
|
}
|
}
|