Exemplo n.º 1
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <returns>复制品</returns>
        public XFontValue Clone()
        {
            XFontValue font = new XFontValue();

            font.CopySettings(this);
            return(font);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <returns>复制品</returns>
        object System.ICloneable.Clone()
        {
            XFontValue font = new XFontValue();

            font.CopySettings(this);
            return(font);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 将指定字体对象的设置复制到本对象
 /// </summary>
 /// <param name="SourceFont">来源字体对象</param>
 public void CopySettings(XFontValue SourceFont)
 {
     strName      = SourceFont.strName;
     fSize        = SourceFont.fSize;
     bolBold      = SourceFont.bolBold;
     bolItalic    = SourceFont.bolItalic;
     bolUnderline = SourceFont.bolUnderline;
     bolStrikeout = SourceFont.bolStrikeout;
     _Unit        = SourceFont._Unit;
 }
Exemplo n.º 4
0
 /// <summary>
 /// 修复字体名称
 /// </summary>
 public void FixFontName()
 {
     foreach (ContentStyle style in this)
     {
         XFontValue f = style.Font;
         if (f.FixFontName())
         {
             // 修复错误的字体名称
             style.FontName = f.Name;
         }
     }//foreach
 }
Exemplo n.º 5
0
        /// <summary>
        /// 将字体转换为其他类型
        /// </summary>
        /// <param name="context">参数</param>
        /// <param name="culture">参数</param>
        /// <param name="Value">对象数据</param>
        /// <param name="destinationType">目标数据类型</param>
        /// <returns>转换结果</returns>
        public override object ConvertTo(
            ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture,
            object Value,
            Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }
            if (destinationType == typeof(string))
            {
                XFontValue font = (XFontValue)Value;
                if (font == null)
                {
                    return("错误的类型");
                }
                return(font.ToString());
            }
            if (destinationType == typeof(System.Drawing.Font))
            {
                XFontValue font = (XFontValue)Value;
                return(font.Value);
            }
            if ((destinationType == typeof(InstanceDescriptor)) &&
                (Value is XFontValue))
            {
                XFontValue font = (XFontValue)Value;
                System.Collections.ArrayList list  = new System.Collections.ArrayList();
                System.Collections.ArrayList types = new System.Collections.ArrayList();
                list.Add(font.Name);
                types.Add(typeof(string));
                list.Add(font.Size);
                types.Add(typeof(float));
                if (font.Style != System.Drawing.FontStyle.Regular)
                {
                    list.Add(font.Style);
                    types.Add(typeof(System.Drawing.FontStyle));
                }

                System.Reflection.MemberInfo constructor = typeof(XFontValue).GetConstructor(
                    (Type[])types.ToArray(typeof(Type)));
                if (constructor != null)
                {
                    return(new InstanceDescriptor(constructor, list.ToArray()));
                }
            }
            return(base.ConvertTo(context, culture, Value, destinationType));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 比较两个对象内容是否相同
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns>内容是否相同</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (!(obj is XFontValue))
            {
                return(false);
            }
            XFontValue f = (XFontValue)obj;

            return(f.bolBold == this.bolBold &&
                   f.bolItalic == this.bolItalic &&
                   f.bolStrikeout == this.bolStrikeout &&
                   f.bolUnderline == this.bolUnderline &&
                   f.fSize == this.fSize &&
                   f.strName == this.strName &&
                   f._Unit == this._Unit);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 比较对象和指定字体的设置是否一致
 /// </summary>
 /// <param name="f">字体对象</param>
 /// <returns>是否一致</returns>
 public bool EqualsValue(XFontValue f)
 {
     if (f == null)
     {
         return(false);
     }
     if (this == f)
     {
         return(true);
     }
     if (strName != f.strName)
     {
         return(false);
     }
     if (fSize != f.fSize)
     {
         return(false);
     }
     if (bolBold != f.bolBold)
     {
         return(false);
     }
     if (bolItalic != f.bolItalic)
     {
         return(false);
     }
     if (bolUnderline != f.bolUnderline)
     {
         return(false);
     }
     if (bolStrikeout != f.bolStrikeout)
     {
         return(false);
     }
     if (_Unit != f._Unit)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 8
0
 /// <summary>
 /// 编辑对象数据
 /// </summary>
 /// <param name="context">参数</param>
 /// <param name="provider">参数</param>
 /// <param name="Value">旧数据</param>
 /// <returns>新数据</returns>
 public override object EditValue(
     ITypeDescriptorContext context,
     IServiceProvider provider,
     object Value)
 {
     using (System.Windows.Forms.FontDialog dlg = new System.Windows.Forms.FontDialog())
     {
         dlg.ShowApply = false;
         dlg.ShowColor = false;
         if (Value != null)
         {
             if (Value is System.Drawing.Font)
             {
                 dlg.Font = (System.Drawing.Font)Value;
             }
             else if (Value is XFontValue)
             {
                 dlg.Font = ((XFontValue)Value).Value;
             }
         }
         if (dlg.ShowDialog( ) == System.Windows.Forms.DialogResult.OK)
         {
             Type pt = context.PropertyDescriptor.PropertyType;
             if (pt.Equals(typeof(System.Drawing.Font)))
             {
                 Value = dlg.Font;
             }
             else if (pt.Equals(typeof(XFontValue)))
             {
                 Value = new XFontValue(dlg.Font);
             }
             else
             {
                 Value = dlg.Font;
             }
         }
     }            //if
     return(Value);
 }
Exemplo n.º 9
0
        /// <summary>
        /// 将数据转换为字体对象
        /// </summary>
        /// <param name="context">参数</param>
        /// <param name="culture">参数</param>
        /// <param name="Value">输入的数据</param>
        /// <returns>转换结果</returns>
        public override object ConvertFrom(
            ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture,
            object Value)
        {
            if (Value is System.Drawing.Font)
            {
                return(new XFontValue((System.Drawing.Font)Value));
            }
            if (!(Value is string))
            {
                return(base.ConvertFrom(context, culture, Value));
            }
            string str = ((string)Value).Trim();

            if (str.Length == 0)
            {
                return(null);
            }
            XFontValue font = new XFontValue();

            font.Parse(str);
            return(font);
        }