You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
342 lines
10 KiB
C#
342 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
#if NET8_0
|
|
#else
|
|
using System.Drawing.Design;
|
|
#endif
|
|
using System.Linq;
|
|
using System.Xml.Serialization;
|
|
using GeoSigma;
|
|
using GeoSigma.SigmaDrawerStyle;
|
|
using GeoSigmaDrawLib;
|
|
using SigmaDrawerStyle;
|
|
|
|
namespace SigmaDrawerElement
|
|
{
|
|
/// <summary>
|
|
/// The drawer text.
|
|
/// </summary>
|
|
[TypeConverter(typeof(PropertySorter))]
|
|
public class DrawerText : ElementBase
|
|
{
|
|
/// <summary>
|
|
/// 属性类别排序
|
|
/// </summary>
|
|
private List<string> categorys = new List<string>() { "基础属性", "文本", "对齐方式", "其他", "杂项" };
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="DrawerText"/> class.
|
|
/// </summary>
|
|
public DrawerText()
|
|
{
|
|
ElementType = DrawElementType.ELEMENT_TEXT;
|
|
}
|
|
/// <summary>
|
|
/// Gets or sets the name.
|
|
/// </summary>
|
|
[XmlAttribute("Name")]
|
|
[Category("基础属性"), DisplayName("名称"), Browsable(false), PropertyOrder(0)]
|
|
public override string Name { get => base.Name; set => base.Name = value; }
|
|
|
|
[Category("文本"), DisplayName("坐标"), PropertyOrder(1)]
|
|
[XmlElement("Coordinate")]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
|
|
public DrawerCoordinateXYZ Coordinate { get; set; } = new DrawerCoordinateXYZ();
|
|
|
|
[XmlIgnore]
|
|
[Category("文本"), DisplayName("文字大小"), PropertyOrder(2)]
|
|
public double Height
|
|
{
|
|
get => Other.Height;
|
|
//set => Other.Height = value;
|
|
set
|
|
{
|
|
if (Math.Abs(this.Height - value) < 1E-5 || value == 0)
|
|
{
|
|
return;
|
|
}
|
|
//if (this.SizeScaleFix == true)
|
|
//{
|
|
if (this.Width == 0 || this.Height == 0)
|
|
{
|
|
this.Other.Height = value;
|
|
return;
|
|
}
|
|
double dFactor = this.Width / this.Height;
|
|
this.Other.Width = value * dFactor;
|
|
this.Other.Height = value;
|
|
//}
|
|
//else
|
|
//{
|
|
// this.Other.Height = value;
|
|
//}
|
|
}
|
|
}
|
|
#region Font
|
|
[Browsable(false)]
|
|
[XmlElement("Font")]
|
|
public LogFont NameFont { get; set; } = LogFont.Default;
|
|
|
|
private Font _TextFont;
|
|
[XmlIgnore]
|
|
[Category("文本"), DisplayName("字体"), PropertyOrder(3)]
|
|
[TypeConverter(typeof(FontPropertyConvert))]
|
|
public Font TextFont
|
|
{
|
|
get
|
|
{
|
|
_TextFont = Font.FromLogFont(NameFont);
|
|
return _TextFont;
|
|
}
|
|
set
|
|
{
|
|
_TextFont = value;
|
|
NameFont = LogFontConverter.convert(_TextFont);
|
|
}
|
|
}
|
|
#endregion
|
|
[Browsable(false)]
|
|
[XmlAttribute("Color")]
|
|
public int ColorRef;
|
|
|
|
[XmlIgnore]
|
|
#if NET8_0
|
|
#else
|
|
[Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))]
|
|
#endif
|
|
[Category("文本"), DisplayName("颜色"), PropertyOrder(4)]
|
|
public Color LineColor
|
|
{
|
|
get
|
|
{
|
|
return ColorTranslator.FromWin32(ColorRef);
|
|
}
|
|
set
|
|
{
|
|
ColorRef = ColorTranslator.ToWin32(value);
|
|
}
|
|
}
|
|
[XmlIgnore]
|
|
[Category("文本"), DisplayName("角度"), PropertyOrder(5)]
|
|
public double Angle
|
|
{
|
|
get => Other.Angle;
|
|
set => Other.Angle = value;
|
|
}
|
|
[XmlIgnore]
|
|
[Category("文本"), DisplayName("文字边框"), PropertyOrder(6)]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BorderTypeConverter))]
|
|
public int BorderType
|
|
{
|
|
get
|
|
{
|
|
return Other.Style & (int)TextStyleFlags.frameAll;
|
|
}
|
|
set
|
|
{
|
|
Other.Style &= ~(int)TextStyleFlags.frameAll;
|
|
Other.Style |= value;
|
|
}
|
|
}
|
|
[Browsable(false)]
|
|
[XmlElement("Other")]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
|
|
public TxOther Other { get; set; } = new TxOther();
|
|
|
|
[XmlIgnore]
|
|
[Category("文本"), DisplayName("文字宽度"), Browsable(false), PropertyOrder(0)]
|
|
public double Width
|
|
{
|
|
get => Other.Width;
|
|
set
|
|
{
|
|
if (Math.Abs(this.Width - value) < 1E-5 || value == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (this.SizeScaleFix == true)
|
|
{
|
|
if (this.Width == 0 || this.Height == 0)
|
|
{
|
|
this.Other.Width = value;
|
|
return;
|
|
}
|
|
double dFactor = this.Height / this.Width;
|
|
this.Other.Height = value * dFactor;
|
|
this.Other.Width = value;
|
|
}
|
|
else
|
|
{
|
|
this.Other.Width = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool sizeScaleFix = true;
|
|
[XmlIgnore]
|
|
[Category("文本"), DisplayName("固定高宽比"), Browsable(false)]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.YesNoConverter))]
|
|
public bool SizeScaleFix
|
|
{
|
|
get => sizeScaleFix;
|
|
set => sizeScaleFix = value;
|
|
}
|
|
|
|
[XmlIgnore]
|
|
[Category("文本"), DisplayName("显示上下标"), Browsable(false)]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.YesNoConverter))]
|
|
public bool Script
|
|
{
|
|
get => Other.Script == 1;
|
|
set => Other.Script = value ? 1 : 0;
|
|
}
|
|
|
|
[XmlIgnore]
|
|
[Category("对齐方式"), DisplayName("水平对齐"), PropertyOrder(6)]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.AlignHorizionMultConverter))]
|
|
public int AlignHorizion
|
|
{
|
|
get
|
|
{
|
|
int nStyle = Other.AlignMul;
|
|
return nStyle;
|
|
//int nStyle = Other.Style & (int)TextStyleFlags.alignAllH;
|
|
//if (nStyle == (int)TextStyleFlags.alignRight)
|
|
//{
|
|
// return (int)TextStyleFlags.alignLeftMult;
|
|
//}
|
|
//else if (nStyle == ((int)TextStyleFlags.alignRight | (int)TextStyleFlags.alignLeftMult))
|
|
//{
|
|
// nStyle = (int)TextStyleFlags.alignLeftMult;
|
|
//}
|
|
//else if (nStyle == ((int)TextStyleFlags.alignRight | (int)TextStyleFlags.alignCenterMult))
|
|
//{
|
|
// nStyle = (int)TextStyleFlags.alignCenterMult;
|
|
//}
|
|
//else if (nStyle == ((int)TextStyleFlags.alignRight | (int)TextStyleFlags.alignRightMult))
|
|
//{
|
|
// nStyle = (int)TextStyleFlags.alignRightMult;
|
|
//}
|
|
//return nStyle;
|
|
}
|
|
set
|
|
{
|
|
Other.Style &= ~(int)TextStyleFlags.alignAllMult;
|
|
Other.Style |= value;
|
|
}
|
|
}
|
|
|
|
[XmlIgnore]
|
|
[Category("对齐方式"), DisplayName("\t\t垂直对齐"),Browsable(false)]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.AlignVerticalConverter))]
|
|
public int AlignVertical
|
|
{
|
|
get
|
|
{
|
|
return Other.Style & (int)TextStyleFlags.alignAllV;
|
|
}
|
|
set
|
|
{
|
|
Other.Style &= ~(int)TextStyleFlags.alignAllV;
|
|
Other.Style |= value;
|
|
}
|
|
}
|
|
#region String
|
|
|
|
public class TxString
|
|
{
|
|
[XmlAttribute]
|
|
public int Line
|
|
{
|
|
get => Items.Count;
|
|
set { } // 这个空 set 不能删除,否则 xml 序列化时将无法生成 Line 属性
|
|
}
|
|
|
|
public class TxsItem
|
|
{
|
|
[XmlAttribute]
|
|
public string Value { get; set; }
|
|
}
|
|
|
|
[Browsable(false)]
|
|
[XmlElement("Item")]
|
|
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseCollectionConverter))]
|
|
public List<TxsItem> Items { get; set; } = new List<TxsItem>();
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Join(string.Empty, Items.Select(r => r.Value));
|
|
}
|
|
}
|
|
|
|
[Category("其他"), DisplayName("内容"), ReadOnly(true)]
|
|
|
|
[XmlElement("String")]
|
|
public TxString String { get; set; } = new TxString();
|
|
|
|
#endregion
|
|
}
|
|
#region Other
|
|
public class TxOther
|
|
{
|
|
[XmlAttribute]
|
|
public double Height { get; set; }
|
|
|
|
[XmlAttribute]
|
|
public double Width { get; set; }
|
|
|
|
[XmlAttribute]
|
|
public double Angle { get; set; }
|
|
|
|
private int style = (int)(TextStyleFlags.alignLeftMult |
|
|
TextStyleFlags.alignBottom |
|
|
TextStyleFlags.frameNull);
|
|
[XmlAttribute]
|
|
public int Style
|
|
{
|
|
get {
|
|
return style;
|
|
}
|
|
set {
|
|
style = value;
|
|
int nPos = style & (int)TextStyleFlags.alignAllPosition;
|
|
if (nPos > 0)
|
|
{
|
|
PositionH = nPos;
|
|
}
|
|
int nAlignH = style & (int)TextStyleFlags.alignAllMult;
|
|
if (nAlignH > 0)
|
|
{
|
|
AlignMul = nAlignH;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 水平对齐
|
|
/// </summary>
|
|
[XmlIgnore]
|
|
public int AlignMul { get; set; } = (int)TextStyleFlags.alignLeftMult;
|
|
private int positionH = (int)TextStyleFlags.alignRight;
|
|
/// <summary>
|
|
/// 水平位置
|
|
/// </summary>
|
|
[XmlIgnore]
|
|
public int PositionH
|
|
{
|
|
get
|
|
{
|
|
return positionH;
|
|
}
|
|
set
|
|
{
|
|
positionH = value;
|
|
}
|
|
}
|
|
|
|
[XmlAttribute]
|
|
public int Script { get; set; }
|
|
}
|
|
#endregion
|
|
}
|