⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlfontproperty.cs

📁 一个很好用的html编辑器。带源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Threading;

using System.Reflection;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;

namespace Microsoft.ConsultingServices.HtmlEditor
{

	#region HtmlFontSize enumeration

	// Enum used to modify the font size
	public enum HtmlFontSize
	{
		Default	= 0,
		xxSmall	= 1,		// 8 points
		xSmall	= 2,		// 10 points
		Small	= 3,		// 12 points
		Medium	= 4,		// 14 points
		Large	= 5,		// 18 points
		xLarge	= 6,		// 24 points
		xxLarge	= 7			// 36 points

	} //HtmlFontSize

	#endregion

	#region HtmlFontProperty struct

	/// <summary>
	/// Struct used to define a Html Font
	/// Supports Name Size Bold Italic Subscript Superscript Strikeout
	/// Specialized TypeConvertor used for Designer Support
	/// If Name is Empty or Null Struct is consider Null
	/// </summary>
	[Serializable]
	[TypeConverter(typeof(HtmlFontPropertyConverter))]
	public struct HtmlFontProperty
	{
		// properties defined for the Font
		private string			_name;
		private HtmlFontSize	_size;
		private bool			_bold;
		private bool			_italic;
		private bool			_underline;
		private bool			_strikeout;
		private bool			_subscript;
		private bool			_superscript;


		// public property Name
		[Description("The Name of the Font")]
		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		} //Name

		// public property Size
		[Description("The Size of the Font")]
		public HtmlFontSize Size
		{
			get
			{
				return _size;
			}
			set
			{
				_size = value;
			}
		} //Size

		// public property Bold
		[Description("Indicates if the font is Bold")]
		public bool Bold
		{
			get
			{
				return _bold;
			}
			set
			{
				_bold = value;
			}
		} //Bold

		// public property Italic
		[Description("Indicates if the font is Italic")]
		public bool Italic
		{
			get
			{
				return _italic;
			}
			set
			{
				_italic = value;
			}
		} //Italic

		// public property Underline
		[Description("Indicates if the font is Underline")]
		public bool Underline
		{
			get
			{
				return _underline;
			}
			set
			{
				_underline = value;
			}
		} //Underline

		// public property Strikeout
		[Description("Indicates if the font is Strikeout")]
		public bool Strikeout
		{
			get
			{
				return _strikeout;
			}
			set
			{
				_strikeout = value;
			}
		} //Strikeout

		// public property Subscript
		[Description("Indicates if the font is Subscript")]
		public bool Subscript
		{
			get
			{
				return _subscript;
			}
			set 
			{
				_subscript = value;
			}
		} //Subscript

		// public property Superscript
		[Description("Indicates if the font is Superscript")]
		public bool Superscript
		{
			get
			{
				return _superscript;
			}
			set
			{
				_superscript = value;
			}
		} //Superscript


		// Class constructors

		// constrctor for name only
		public HtmlFontProperty(string name)
		{
			_name = name;
			_size = HtmlFontSize.Default;
			_bold = false;
			_italic = false;
			_underline = false;
			_strikeout = false;
			_subscript = false;
			_superscript = false;

		} //HtmlFontProperty

		// constrctor for name and size only
		public HtmlFontProperty(string name, HtmlFontSize size)
		{
			_name = name;
			_size = size;
			_bold = false;
			_italic = false;
			_underline = false;
			_strikeout = false;
			_subscript = false;
			_superscript = false;

		} //HtmlFontProperty

		// constrctor for all standard attributes
		public HtmlFontProperty(string name, HtmlFontSize size, bool bold, bool italic, bool underline)
		{
			_name = name;
			_size = size;
			_bold = bold;
			_italic = italic;
			_underline = underline;
			_strikeout = false;
			_subscript = false;
			_superscript = false;

		} //HtmlFontProperty

		// constrctor for all attributes
		public HtmlFontProperty(string name, HtmlFontSize size, bool bold, bool italic, bool underline, bool strikeout, bool subscript, bool superscript)
		{
			_name = name;
			_size = size;
			_bold = bold;
			_italic = italic;
			_underline = underline;
			_strikeout = strikeout;
			_subscript = subscript;
			_superscript = superscript;

		} //HtmlFontProperty

		// constructor given a system Font
		public HtmlFontProperty(System.Drawing.Font font)
		{
			_name = font.Name;
			_size = HtmlFontConversion.FontSizeToHtml(font.SizeInPoints);
			_bold = font.Bold;
			_italic = font.Italic;
			_underline = font.Underline;
			_strikeout = font.Strikeout;
			_subscript = false;
			_superscript = false;

		} //HtmlFontProperty


		// public method to convert the html into a readable format
		// used by the designer to display the font name
		public override string ToString()
		{
			return string.Format("{0}, {1}", Name, Size);

		} //ToString

		// compares two Html Fonts for equality
		// equality opertors not defined (Design Time issue with override of Equals)
		public static bool IsEqual(HtmlFontProperty font1, HtmlFontProperty font2)
		{
			// assume not equal
			bool equals = false;
			
			// perform the comparsion
			if (HtmlFontProperty.IsNotNull(font1) && HtmlFontProperty.IsNotNull(font2))
			{
				if (font1.Name == font2.Name &&
					font1.Size == font2.Size &&
					font1.Bold == font2.Bold && 
					font1.Italic == font2.Italic &&
					font1.Underline == font2.Underline &&
					font1.Strikeout == font2.Strikeout &&
					font1.Subscript == font2.Subscript &&
					font1.Superscript == font2.Superscript)
				{
					equals = true;
				}
			}
			
			// return the calculated value
			return equals;

		} //IsEquals

		// compares two Html Fonts for equality
		// equality opertors not defined (Design Time issue with override of Equals)
		public static bool IsNotEqual(HtmlFontProperty font1, HtmlFontProperty font2)
		{
			return (!HtmlFontProperty.IsEqual(font1, font2));

		} //IsNotEqual

		// based on a font name being null the font can be assumed to be null
		// default constructor will give a null object
		public static bool IsNull(HtmlFontProperty font)
		{
			return (font.Name == null || font.Name.Trim() == string.Empty);

		} //IsNull

		// based on a font name being null the font can be assumed to be null
		// default constructor will give a null object
		public static bool IsNotNull(HtmlFontProperty font)
		{
			return (!HtmlFontProperty.IsNull(font));

		} //IsNull

	} // HtmlFontProperty

	#endregion

	#region HtmlFontConversion utilities

	/// <summary>
	/// Utility Class to perform Font Attribute conversions
	/// Takes data to and from the expected Html Format
	/// </summary>
	public class HtmlFontConversion
	{

		// return the correct string size description from a HtmlFontSize
		public static string HtmlFontSizeString(HtmlFontSize fontSize)
		{
			// set the size to blank as the default
			// this will ensure font size blanked out if not set
			string size = string.Empty;

			switch (fontSize)
			{
				case HtmlFontSize.xxSmall:
					size = "xx-small";
					break;
				case HtmlFontSize.xSmall:
					size = "x-small";
					break;
				case HtmlFontSize.Small:
					size = "small";
					break;
				case HtmlFontSize.Medium:
					size = "medium";
					break;
				case HtmlFontSize.Large:
					size = "large";
					break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -