-//\r
-// System.Drawing.ColorTranslator.cs\r
-//\r
-// (C) 2001 Ximian, Inc. http://www.ximian.com\r
-//\r
-// Dennis Hayes (dennish@raytek.com)\r
-// Inital Implimentation 3/25/2002\r
-// All conversions based on best guess, will improve over time\r
-// \r
-using System;\r
-namespace System.Drawing {\r
+//
+// System.Drawing.ColorTranslator.cs
+//
+// (C) 2001 Ximian, Inc. http://www.ximian.com
+//
+// Dennis Hayes (dennish@raytek.com)
+// Inital Implimentation 3/25/2002
+// All conversions based on best guess, will improve over time
+//
+using System;
+namespace System.Drawing {
public sealed class ColorTranslator{
private ColorTranslator ()
{
}
-\r
- // From converisons\r
- /// <summary>\r
- /// \r
- /// </summary>\r
- /// <param name="HtmlFromColor"></param>\r
- /// <returns></returns>\r
- public static Color FromHtml(string HtmlFromColor){\r
- // If first char is "#"\r
- //convert "#RRGGBB" to int and use Color.FromARGB(int) to create color\r
- // else //it is a color name\r
- //If there is a single digit at the end of the name, remove it.\r
- // Call Color.FromKnownColor(HtmlFromColor) \r
-\r
- //At least some Html strings match .NET Colors,\r
- // so this should work for those colors.\r
- // .NET colors, XWindows colors, and WWWC web colors \r
- // are (according to Charles Pretziod) base the same\r
- //colors, so many shouold work if any do.\r
- if (HtmlFromColor[0] != '#')\r
- {\r
- int length = HtmlFromColor.Length;\r
- for (int i = length - 1; i >= 0; i--)\r
- {\r
- if (!Char.IsDigit (HtmlFromColor[i]))\r
- break;\r
- length--;\r
- }\r
- \r
- return Color.FromName(HtmlFromColor.Substring (0, length));\r
- }\r
- \r
- int pos = 0, index = 0;\r
- int[] rgb = new int[] {0, 0, 0};\r
- \r
- string specifier = HtmlFromColor.Substring (1).ToLower ();\r
- if (specifier.Length != 6)\r
- return Color.Empty;\r
- \r
- foreach (char c in specifier)\r
- {\r
- rgb[index] *= 16;\r
-\r
- if (Char.IsDigit (c))\r
- rgb[index] += Int32.Parse (c.ToString ());\r
- else if (c <= 'f' && c >= 'a')\r
- rgb[index] += 10 + (c - 'a');\r
- else\r
- return Color.Empty;\r
- \r
- pos++;\r
- if ((pos % 2) == 0)\r
- index++;\r
- }\r
-\r
- return Color.FromArgb (rgb[0], rgb[1], rgb[2]);\r
- }\r
- \r
- /// <summary>\r
- /// \r
- /// </summary>\r
- /// <param name="OLEFromColor"></param>\r
- /// <returns></returns>\r
- public static Color FromOle(int OLEFromColor){\r
- //int newcolor;\r
- //TODO: swap RB bytes i.e. AARRGGBB to AABBGGRR\r
- //return Color.FromArgb(newcolor);\r
- return Color.Empty;\r
- }\r
- \r
- /// <summary>\r
- /// \r
- /// </summary>\r
- /// <param name="Win32FromColor"></param>\r
- /// <returns></returns>\r
- public static Color FromWin32(int Win32FromColor){\r
- //int newcolor;\r
- //TODO: swap RB bytes i.e. AARRGGBB to AABBGGRR\r
- //return Color.FromArgb(newcolor);\r
- return Color.Empty;\r
- }\r
-\r
- // To conversions\r
- public static string ToHtml (Color c)\r
- {\r
- if (c.IsEmpty)\r
- return "";\r
-\r
- string result;\r
-\r
- if (c.IsNamedColor)\r
- result = c.Name;\r
- else\r
- result = String.Format ("#{0:X2}{1:X2}{2:X2}", c.R, c.G, c.B);\r
-\r
- return result;\r
- }\r
- /// <summary>\r
- /// converts from BGR to RGB\r
- /// </summary>\r
- /// <param name="OleToColor"></param>\r
- /// <returns></returns>\r
- public static int ToOle(Color FromColor){\r
- // TODO: Swap red and blue(from argb), convert to int(toargb)\r
- // Same as ToWin32\r
- return (Color.FromArgb(FromColor.B,FromColor.G,FromColor.R)).ToArgb();\r
- }\r
-\r
- /// <summary>\r
- /// converts from RGB to BGR\r
- /// </summary>\r
- /// <param name="Win32ToColor"></param>\r
- /// <returns></returns>\r
- public static int ToWin32(Color FromColor){\r
- // TODO: Swap red and blue(from argb), convert to int(toargb)\r
- // Same as ToOle\r
- return (Color.FromArgb(FromColor.B,FromColor.G,FromColor.R)).ToArgb();\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-\r
+
+ // From converisons
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="HtmlFromColor"></param>
+ /// <returns></returns>
+ public static Color FromHtml(string HtmlFromColor){
+ // If first char is "#"
+ //convert "#RRGGBB" to int and use Color.FromARGB(int) to create color
+ // else //it is a color name
+ //If there is a single digit at the end of the name, remove it.
+ // Call Color.FromKnownColor(HtmlFromColor)
+
+ //At least some Html strings match .NET Colors,
+ // so this should work for those colors.
+ // .NET colors, XWindows colors, and WWWC web colors
+ // are (according to Charles Pretziod) base the same
+ //colors, so many shouold work if any do.
+ if (HtmlFromColor[0] != '#')
+ {
+ int length = HtmlFromColor.Length;
+ for (int i = length - 1; i >= 0; i--)
+ {
+ if (!Char.IsDigit (HtmlFromColor[i]))
+ break;
+ length--;
+ }
+
+ return Color.FromName(HtmlFromColor.Substring (0, length));
+ }
+
+ int pos = 0, index = 0;
+ int[] rgb = new int[] {0, 0, 0};
+
+ string specifier = HtmlFromColor.Substring (1).ToLower ();
+ if (specifier.Length != 6)
+ return Color.Empty;
+
+ foreach (char c in specifier)
+ {
+ rgb[index] *= 16;
+
+ if (Char.IsDigit (c))
+ rgb[index] += Int32.Parse (c.ToString ());
+ else if (c <= 'f' && c >= 'a')
+ rgb[index] += 10 + (c - 'a');
+ else
+ return Color.Empty;
+
+ pos++;
+ if ((pos % 2) == 0)
+ index++;
+ }
+
+ return Color.FromArgb (rgb[0], rgb[1], rgb[2]);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="OLEFromColor"></param>
+ /// <returns></returns>
+ public static Color FromOle(int OLEFromColor){
+ //int newcolor;
+ //TODO: swap RB bytes i.e. AARRGGBB to AABBGGRR
+ //return Color.FromArgb(newcolor);
+ return Color.Empty;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="Win32FromColor"></param>
+ /// <returns></returns>
+ public static Color FromWin32(int Win32FromColor){
+ //int newcolor;
+ //TODO: swap RB bytes i.e. AARRGGBB to AABBGGRR
+ //return Color.FromArgb(newcolor);
+ return Color.Empty;
+ }
+
+ // To conversions
+ public static string ToHtml (Color c)
+ {
+ if (c.IsEmpty)
+ return "";
+
+ string result;
+
+ if (c.IsNamedColor)
+ result = c.Name;
+ else
+ result = String.Format ("#{0:X2}{1:X2}{2:X2}", c.R, c.G, c.B);
+
+ return result;
+ }
+ /// <summary>
+ /// converts from BGR to RGB
+ /// </summary>
+ /// <param name="OleToColor"></param>
+ /// <returns></returns>
+ public static int ToOle(Color FromColor){
+ // TODO: Swap red and blue(from argb), convert to int(toargb)
+ // Same as ToWin32
+ return (Color.FromArgb(FromColor.B,FromColor.G,FromColor.R)).ToArgb();
+ }
+
+ /// <summary>
+ /// converts from RGB to BGR
+ /// </summary>
+ /// <param name="Win32ToColor"></param>
+ /// <returns></returns>
+ public static int ToWin32(Color FromColor){
+ // TODO: Swap red and blue(from argb), convert to int(toargb)
+ // Same as ToOle
+ return (Color.FromArgb(FromColor.B,FromColor.G,FromColor.R)).ToArgb();
+ }
+ }
+}
+
+
+
+
-//\r
-// System.Drawing.StringFormat.cs\r
-//\r
-// Authors:\r
-// Dennis Hayes (dennish@Raytek.com)\r
-// Miguel de Icaza (miguel@ximian.com)\r
-// Jordi Mas i Hernandez (jordi@ximian.com)\r
-//\r
-// (C) 2002 Ximian, Inc\r
-// (C) 2003 Novell, Inc.\r
-//\r
-using System;\r
-using System.Drawing.Text;\r
-\r
-namespace System.Drawing\r
-{\r
- /// <summary>\r
- /// Summary description for StringFormat.\r
- /// </summary>\r
- public sealed class StringFormat : MarshalByRefObject, IDisposable, ICloneable\r
- {\r
- private static StringFormat genericDefault;\r
- IntPtr nativeStrFmt = IntPtr.Zero;\r
- int language = GDIPlus.LANG_NEUTRAL;\r
- \r
- public StringFormat() : this (0, GDIPlus.LANG_NEUTRAL)\r
- { \r
- \r
- } \r
- \r
- public StringFormat(StringFormatFlags options, int lang)\r
- {\r
- Status status = GDIPlus.GdipCreateStringFormat (options, lang, out nativeStrFmt); \r
- \r
- if (status != Status.Ok)\r
- throw new ArgumentException ("Could not allocate string format: " + status);\r
- \r
- LineAlignment = StringAlignment.Near;\r
- Alignment = StringAlignment.Near; \r
- language = lang;\r
- }\r
- \r
- internal StringFormat(IntPtr native)\r
- {\r
- nativeStrFmt = native;\r
- }\r
- \r
- ~StringFormat()\r
- { \r
- Dispose ();\r
- }\r
- \r
- public void Dispose()\r
- { \r
- Dispose (true);\r
- System.GC.SuppressFinalize (this);\r
- }\r
-\r
- void Dispose (bool disposing)\r
- {\r
- if (disposing)\r
- GDIPlus.GdipDeleteStringFormat (nativeStrFmt); \r
- }\r
-\r
- public StringFormat (StringFormat source)\r
- { \r
- Status status = GDIPlus.GdipCloneStringFormat (source.NativeObject, out nativeStrFmt);\r
- \r
- if (status != Status.Ok)\r
- throw new ArgumentException ("Could not allocate string format: " + status);\r
- }\r
-\r
- public StringFormat (StringFormatFlags flags)\r
- {\r
- Status status = GDIPlus.GdipCreateStringFormat (flags, GDIPlus.LANG_NEUTRAL, out nativeStrFmt); \r
- \r
- if (status != Status.Ok)\r
- throw new ArgumentException ("Could not allocate string format: " + status);\r
- }\r
- \r
- public StringAlignment Alignment {\r
- get {\r
- StringAlignment align;\r
- GDIPlus.GdipGetStringFormatAlign (nativeStrFmt, out align);\r
- return align;\r
- }\r
-\r
- set { \r
- GDIPlus.GdipSetStringFormatAlign (nativeStrFmt, value); \r
- }\r
- }\r
-\r
- public StringAlignment LineAlignment {\r
- get {\r
- StringAlignment align;\r
- GDIPlus.GdipGetStringFormatLineAlign (nativeStrFmt, out align); \r
- return align;\r
- }\r
-\r
- set { \r
- GDIPlus.GdipSetStringFormatLineAlign (nativeStrFmt, value);\r
- }\r
- }\r
-\r
- public StringFormatFlags FormatFlags {\r
- get { \r
- StringFormatFlags flags; \r
- GDIPlus.GdipGetStringFormatFlags (nativeStrFmt, out flags);\r
- return flags; \r
- }\r
-\r
- set {\r
- GDIPlus.GdipSetStringFormatFlags (nativeStrFmt, value); \r
- }\r
- }\r
-\r
- public HotkeyPrefix HotkeyPrefix {\r
- get { \r
- HotkeyPrefix hotkeyPrefix;\r
- GDIPlus.GdipGetStringFormatHotkeyPrefix (nativeStrFmt, out hotkeyPrefix); \r
- return hotkeyPrefix;\r
- }\r
-\r
- set {\r
- \r
- GDIPlus.GdipSetStringFormatHotkeyPrefix (nativeStrFmt, value);\r
- }\r
- }\r
-\r
-\r
- public StringTrimming Trimming {\r
- get {\r
- StringTrimming trimming;\r
- GDIPlus.GdipGetStringFormatTrimming (nativeStrFmt, out trimming);\r
- return trimming;\r
- }\r
-\r
- set {\r
- GDIPlus.GdipSetStringFormatTrimming (nativeStrFmt, value); \r
- }\r
- }\r
-\r
- public static StringFormat GenericDefault {\r
- get {\r
- IntPtr ptr;\r
- \r
- Status status = GDIPlus.GdipStringFormatGetGenericDefault (out ptr); \r
- \r
- if (status != Status.Ok)\r
- throw new ArgumentException ("Could not allocate string format: " + status);\r
- \r
- return new StringFormat (ptr);\r
- }\r
- }\r
- \r
- \r
- public int DigitSubstitutionLanguage {\r
- get{\r
- return language;\r
- }\r
- }\r
-\r
- \r
- public static StringFormat GenericTypographic {\r
- get {\r
- IntPtr ptr;\r
- \r
- Status status = GDIPlus.GdipStringFormatGetGenericTypographic (out ptr); \r
- \r
- if (status != Status.Ok)\r
- throw new ArgumentException ("Could not allocate string format: " + status);\r
- \r
- return new StringFormat (ptr); \r
- }\r
- }\r
-\r
- public StringDigitSubstitute DigitSubstitutionMethod {\r
- get {\r
- StringDigitSubstitute substitute;\r
- \r
- GDIPlus.GdipGetStringFormatDigitSubstitution(nativeStrFmt, language, out substitute);\r
- return substitute; \r
- }\r
- }\r
-\r
-\r
-\r
- public void SetMeasurableCharacterRanges (CharacterRange [] range)\r
- {\r
-\r
- }\r
- \r
- public object Clone()\r
- {\r
- IntPtr native;\r
- \r
- Status status = GDIPlus.GdipCloneStringFormat (nativeStrFmt, out native); \r
- \r
- if (status != Status.Ok)\r
- throw new ArgumentException ("Could not allocate string format: " + status);\r
- \r
- return new StringFormat (native);\r
- }\r
-\r
- public override string ToString()\r
- {\r
- return "[StringFormat, FormatFlags=" + this.FormatFlags.ToString() + "]";\r
- }\r
- \r
- internal IntPtr NativeObject\r
- { \r
- get{\r
- return nativeStrFmt;\r
- }\r
- set {\r
- nativeStrFmt = value;\r
- }\r
- }\r
-\r
- public void SetTabStops(float firstTabOffset, float[] tabStops)\r
- {\r
- GDIPlus.GdipSetStringFormatTabStops(nativeStrFmt, firstTabOffset, tabStops.Length, tabStops);\r
- }\r
-\r
- public void SetDigitSubstitution(int language, StringDigitSubstitute substitute)\r
- {\r
- GDIPlus.GdipSetStringFormatDigitSubstitution(nativeStrFmt, this.language, substitute);\r
- }\r
-\r
- public float[] GetTabStops(out float firstTabOffset)\r
- {\r
- int count = 0;\r
- firstTabOffset = 0;\r
- \r
- GDIPlus.GdipGetStringFormatTabStopCount(nativeStrFmt, out count); \r
-\r
- float[] tabStops = new float[count]; \r
- \r
- if (count!=0) \r
- GDIPlus.GdipGetStringFormatTabStops(nativeStrFmt, count, out firstTabOffset, tabStops);\r
- \r
- return tabStops; \r
- }\r
-\r
- }\r
-}\r
+//
+// System.Drawing.StringFormat.cs
+//
+// Authors:
+// Dennis Hayes (dennish@Raytek.com)
+// Miguel de Icaza (miguel@ximian.com)
+// Jordi Mas i Hernandez (jordi@ximian.com)
+//
+// (C) 2002 Ximian, Inc
+// (C) 2003 Novell, Inc.
+//
+using System;
+using System.Drawing.Text;
+
+namespace System.Drawing
+{
+ /// <summary>
+ /// Summary description for StringFormat.
+ /// </summary>
+ public sealed class StringFormat : MarshalByRefObject, IDisposable, ICloneable
+ {
+ private static StringFormat genericDefault;
+ IntPtr nativeStrFmt = IntPtr.Zero;
+ int language = GDIPlus.LANG_NEUTRAL;
+
+ public StringFormat() : this (0, GDIPlus.LANG_NEUTRAL)
+ {
+
+ }
+
+ public StringFormat(StringFormatFlags options, int lang)
+ {
+ Status status = GDIPlus.GdipCreateStringFormat (options, lang, out nativeStrFmt);
+
+ if (status != Status.Ok)
+ throw new ArgumentException ("Could not allocate string format: " + status);
+
+ LineAlignment = StringAlignment.Near;
+ Alignment = StringAlignment.Near;
+ language = lang;
+ }
+
+ internal StringFormat(IntPtr native)
+ {
+ nativeStrFmt = native;
+ }
+
+ ~StringFormat()
+ {
+ Dispose ();
+ }
+
+ public void Dispose()
+ {
+ Dispose (true);
+ System.GC.SuppressFinalize (this);
+ }
+
+ void Dispose (bool disposing)
+ {
+ if (disposing)
+ GDIPlus.GdipDeleteStringFormat (nativeStrFmt);
+ }
+
+ public StringFormat (StringFormat source)
+ {
+ Status status = GDIPlus.GdipCloneStringFormat (source.NativeObject, out nativeStrFmt);
+
+ if (status != Status.Ok)
+ throw new ArgumentException ("Could not allocate string format: " + status);
+ }
+
+ public StringFormat (StringFormatFlags flags)
+ {
+ Status status = GDIPlus.GdipCreateStringFormat (flags, GDIPlus.LANG_NEUTRAL, out nativeStrFmt);
+
+ if (status != Status.Ok)
+ throw new ArgumentException ("Could not allocate string format: " + status);
+ }
+
+ public StringAlignment Alignment {
+ get {
+ StringAlignment align;
+ GDIPlus.GdipGetStringFormatAlign (nativeStrFmt, out align);
+ return align;
+ }
+
+ set {
+ GDIPlus.GdipSetStringFormatAlign (nativeStrFmt, value);
+ }
+ }
+
+ public StringAlignment LineAlignment {
+ get {
+ StringAlignment align;
+ GDIPlus.GdipGetStringFormatLineAlign (nativeStrFmt, out align);
+ return align;
+ }
+
+ set {
+ GDIPlus.GdipSetStringFormatLineAlign (nativeStrFmt, value);
+ }
+ }
+
+ public StringFormatFlags FormatFlags {
+ get {
+ StringFormatFlags flags;
+ GDIPlus.GdipGetStringFormatFlags (nativeStrFmt, out flags);
+ return flags;
+ }
+
+ set {
+ GDIPlus.GdipSetStringFormatFlags (nativeStrFmt, value);
+ }
+ }
+
+ public HotkeyPrefix HotkeyPrefix {
+ get {
+ HotkeyPrefix hotkeyPrefix;
+ GDIPlus.GdipGetStringFormatHotkeyPrefix (nativeStrFmt, out hotkeyPrefix);
+ return hotkeyPrefix;
+ }
+
+ set {
+
+ GDIPlus.GdipSetStringFormatHotkeyPrefix (nativeStrFmt, value);
+ }
+ }
+
+
+ public StringTrimming Trimming {
+ get {
+ StringTrimming trimming;
+ GDIPlus.GdipGetStringFormatTrimming (nativeStrFmt, out trimming);
+ return trimming;
+ }
+
+ set {
+ GDIPlus.GdipSetStringFormatTrimming (nativeStrFmt, value);
+ }
+ }
+
+ public static StringFormat GenericDefault {
+ get {
+ IntPtr ptr;
+
+ Status status = GDIPlus.GdipStringFormatGetGenericDefault (out ptr);
+
+ if (status != Status.Ok)
+ throw new ArgumentException ("Could not allocate string format: " + status);
+
+ return new StringFormat (ptr);
+ }
+ }
+
+
+ public int DigitSubstitutionLanguage {
+ get{
+ return language;
+ }
+ }
+
+
+ public static StringFormat GenericTypographic {
+ get {
+ IntPtr ptr;
+
+ Status status = GDIPlus.GdipStringFormatGetGenericTypographic (out ptr);
+
+ if (status != Status.Ok)
+ throw new ArgumentException ("Could not allocate string format: " + status);
+
+ return new StringFormat (ptr);
+ }
+ }
+
+ public StringDigitSubstitute DigitSubstitutionMethod {
+ get {
+ StringDigitSubstitute substitute;
+
+ GDIPlus.GdipGetStringFormatDigitSubstitution(nativeStrFmt, language, out substitute);
+ return substitute;
+ }
+ }
+
+
+
+ public void SetMeasurableCharacterRanges (CharacterRange [] range)
+ {
+
+ }
+
+ public object Clone()
+ {
+ IntPtr native;
+
+ Status status = GDIPlus.GdipCloneStringFormat (nativeStrFmt, out native);
+
+ if (status != Status.Ok)
+ throw new ArgumentException ("Could not allocate string format: " + status);
+
+ return new StringFormat (native);
+ }
+
+ public override string ToString()
+ {
+ return "[StringFormat, FormatFlags=" + this.FormatFlags.ToString() + "]";
+ }
+
+ internal IntPtr NativeObject
+ {
+ get{
+ return nativeStrFmt;
+ }
+ set {
+ nativeStrFmt = value;
+ }
+ }
+
+ public void SetTabStops(float firstTabOffset, float[] tabStops)
+ {
+ GDIPlus.GdipSetStringFormatTabStops(nativeStrFmt, firstTabOffset, tabStops.Length, tabStops);
+ }
+
+ public void SetDigitSubstitution(int language, StringDigitSubstitute substitute)
+ {
+ GDIPlus.GdipSetStringFormatDigitSubstitution(nativeStrFmt, this.language, substitute);
+ }
+
+ public float[] GetTabStops(out float firstTabOffset)
+ {
+ int count = 0;
+ firstTabOffset = 0;
+
+ GDIPlus.GdipGetStringFormatTabStopCount(nativeStrFmt, out count);
+
+ float[] tabStops = new float[count];
+
+ if (count!=0)
+ GDIPlus.GdipGetStringFormatTabStops(nativeStrFmt, count, out firstTabOffset, tabStops);
+
+ return tabStops;
+ }
+
+ }
+}