📄 helpers.cs
字号:
#region License
/*
This library 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.1 of the License, or (at your option)
any later version.
This library 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 this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#endregion
using System;
using System.Drawing;
namespace daReport
{
/// <summary>
/// A class of static helper functions
/// </summary>
public class Helpers
{
/// <summary>
/// Parses an XmlNode for information and returns a System.Drawing.Font object
/// </summary>
/// <param name="FontNode">XmlNode to parse for information</param>
/// <returns>System.Drawing.Font</returns>
public static System.Drawing.Font ResolveFont(System.Xml.XmlNode FontNode)
{
try
{
System.Drawing.Font ReturnFont;
string fntName = FontNode.Attributes["family"]==null ? "Arial" : FontNode.Attributes["family"].Value;
int fntSize = FontNode.Attributes["size"]==null ? 10 : Convert.ToInt32( FontNode.Attributes["size"].Value );
string fntStyle = FontNode.Attributes["style"]==null ? "Regular" : FontNode.Attributes["style"].Value;
switch (fntStyle)
{
case "Bold Italic":
ReturnFont = new Font(fntName,fntSize,FontStyle.Bold | FontStyle.Italic);
break;
case "Bold":
ReturnFont = new Font(fntName,fntSize,FontStyle.Bold);
break;
case "Italic":
ReturnFont = new Font(fntName,fntSize,FontStyle.Italic);
break;
default :
ReturnFont = new Font(fntName,fntSize,FontStyle.Regular);
break;
}
return ReturnFont;
}
catch (Exception)
{
return new System.Drawing.Font("Arial",8,FontStyle.Regular);
}
}
/// <summary>
/// Converts characters in Text which are valid XML entities to safe strings
/// </summary>
/// <param name="Text">text to be parsed</param>
/// <returns>XML-safe text</returns>
public static string TextSafeForXML(string Text)
{
Text = Text.Replace("&","&"); //& -> &
Text = Text.Replace("'","'"); //' -> '
Text = Text.Replace("\"","""); //" -> "
Text = Text.Replace("<","<"); //< -> <
Text = Text.Replace(">",">"); //> -> >
return Text;
}
/// <summary>
/// Replaces XML-safe strings back to Text which are valid XML entities
/// </summary>
/// <param name="XMLText">text to be parsed</param>
/// <returns>Standard text</returns>
public static string SafeXMLToText(string XMLText)
{
XMLText = XMLText.Replace("&", "&"); //& -> &
XMLText = XMLText.Replace("'", "'"); //' -> '
XMLText = XMLText.Replace(""", "\""); //" -> "
XMLText = XMLText.Replace("<", "<"); //< -> <
XMLText = XMLText.Replace(">", ">"); //> -> >
return XMLText;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -