コード例 #1
0
		public void FontUnit_IFormatProviderToString ()
		{
			MyFormatProvider mfp = new MyFormatProvider ();

			FontUnit f1 = new FontUnit (FontSize.Large);
			Assert.AreEqual ("Large", f1.ToString (mfp), "T1");

			f1 = new FontUnit (FontSize.AsUnit);
			Assert.AreEqual ("10pt", f1.ToString (mfp), "T2");

			f1 = new FontUnit (15);
			Assert.AreEqual ("15pt", f1.ToString (mfp), "T3");

			f1 = new FontUnit (null);
			Assert.AreEqual ("", f1.ToString (mfp), "T4");

			f1 = new FontUnit ("");
			Assert.AreEqual ("", f1.ToString (mfp), "T5");

			f1 = new FontUnit (2.5);
			Assert.AreEqual ("2.5pt", f1.ToString (mfp), "T6");

			f1 = new FontUnit (5.0, UnitType.Percentage);
			Assert.AreEqual ("5%", f1.ToString (mfp), "T7");
		}
コード例 #2
0
		public void FontUnitConstructors_Enum12 ()
		{
			FontUnit fu = new FontUnit ("XX-Large");
			Assert.AreEqual (FontSize.XXLarge, fu.Type, "XX-Large");
			Assert.IsTrue (fu.Unit.IsEmpty, "XX-Large.IsEmpty");
			Assert.AreEqual ("XX-Large", fu.ToString (), "XX-Large.ToString");
		}
コード例 #3
0
		public void FontUnitConstructors_Enum14 ()
		{
			FontUnit fu = new FontUnit ("XX-Small");
			Assert.AreEqual (FontSize.XXSmall, fu.Type, "XX-Small");
			Assert.IsTrue (fu.Unit.IsEmpty, "XX-Small.IsEmpty");
			Assert.AreEqual ("XX-Small", fu.ToString (), "XX-Small.ToString");
		}
コード例 #4
0
		public void FontUnitConstructors_Enum3 ()
		{
			FontUnit fu = new FontUnit ("Medium");
			Assert.AreEqual (FontSize.Medium, fu.Type, "Medium");
			Assert.IsTrue (fu.Unit.IsEmpty, "Medium.IsEmpty");
			Assert.AreEqual ("Medium", fu.ToString (), "Medium.ToString");
		}
コード例 #5
0
		public void FontUnitConstructors_Enum5 ()
		{
			FontUnit fu = new FontUnit ("Smaller");
			Assert.AreEqual (FontSize.Smaller, fu.Type, "Smaller");
			Assert.IsTrue (fu.Unit.IsEmpty, "Smaller.IsEmpty");
			Assert.AreEqual ("Smaller", fu.ToString (), "Smaller.ToString");
		}
コード例 #6
0
		public void FontUnitConstructors_Pixel ()
		{
			FontUnit f1 = new FontUnit ("10px");
			Assert.AreEqual (FontSize.AsUnit, f1.Type, "#1");
			Assert.AreEqual (UnitType.Pixel, f1.Unit.Type, "#2");
			Assert.AreEqual (10, f1.Unit.Value, "#3");
			Assert.AreEqual ("10px", f1.ToString (), "#4");
		}
コード例 #7
0
		public void FontUnitConstructors_Point ()
		{
			CultureInfo originalCulture = CultureInfo.CurrentCulture;
			Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
			try {
				FontUnit f1 = new FontUnit ("12,5pt");
				Assert.AreEqual (FontSize.AsUnit, f1.Type, "Type");
				Assert.AreEqual (UnitType.Point, f1.Unit.Type, "Unit.Type");
				Assert.AreEqual (12.5, f1.Unit.Value, "Unit.Value");
				Assert.AreEqual ("12,5pt", f1.ToString (), "ToString");
			} finally {
				// restore original culture
				Thread.CurrentThread.CurrentCulture = originalCulture;
			}
		}
コード例 #8
0
        protected virtual void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            StateBag viewState = ViewState;

            Color c;

            // ForeColor
            if (IsSet(PROP_FORECOLOR))
            {
                c = (Color)viewState["ForeColor"];
                if (!c.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(c));
                }
            }

            // BackColor
            if (IsSet(PROP_BACKCOLOR))
            {
                c = (Color)viewState["BackColor"];
                if (!c.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (IsSet(PROP_BORDERCOLOR))
            {
                c = (Color)viewState["BorderColor"];
                if (!c.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit        bu = this.BorderWidth;

            if (!bu.IsEmpty)
            {
                attributes.Add(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet)
                {
                    if (bu.Value != 0.0)
                    {
                        attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }
            else
            {
                if (bs != BorderStyle.NotSet)
                {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }

            // need to call the property get in case we have font properties from view state and have not
            // created the font object
            FontInfo font = Font;

            // Font.Names
            string[] names = font.Names;
            if (names.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.FontFamily, Style.FormatStringArray(names, ','));
            }

            // Font.Size
            FontUnit fu = font.Size;

            if (fu.IsEmpty == false)
            {
                attributes.Add(HtmlTextWriterStyle.FontSize, fu.ToString(CultureInfo.InvariantCulture));
            }

            // Font.Bold
            if (IsSet(PROP_FONT_BOLD))
            {
                if (font.Bold)
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "bold");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "normal");
                }
            }

            // Font.Italic
            if (IsSet(PROP_FONT_ITALIC))
            {
                if (font.Italic == true)
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "italic");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "normal");
                }
            }

            //
            string textDecoration = String.Empty;

            if (font.Underline)
            {
                textDecoration = "underline";
            }
            if (font.Overline)
            {
                textDecoration += " overline";
            }
            if (font.Strikeout)
            {
                textDecoration += " line-through";
            }
            if (textDecoration.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, textDecoration);
            }
            else
            {
                if (IsSet(PROP_FONT_UNDERLINE) || IsSet(PROP_FONT_OVERLINE) || IsSet(PROP_FONT_STRIKEOUT))
                {
                    attributes.Add(HtmlTextWriterStyle.TextDecoration, "none");
                }
            }

            Unit u;

            // Height
            if (IsSet(PROP_HEIGHT))
            {
                u = (Unit)viewState["Height"];
                if (!u.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (IsSet(PROP_WIDTH))
            {
                u = (Unit)viewState["Width"];
                if (!u.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }
        }
コード例 #9
0
		public void FontUnitConstructors_Em ()
		{
			CultureInfo originalCulture = CultureInfo.CurrentCulture;
			Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
			try {
				FontUnit fu = new FontUnit ("4,5em");
				Assert.AreEqual (FontSize.AsUnit, fu.Type, "#1");
				Assert.AreEqual (UnitType.Em, fu.Unit.Type, "#2");
				Assert.AreEqual (4.5, fu.Unit.Value, "#3");
				Assert.AreEqual ("4,5em", fu.ToString (), "#4");
			} finally {
				// restore original culture
				Thread.CurrentThread.CurrentCulture = originalCulture;
			}
		}
コード例 #10
0
        protected override sealed void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            Debug.Assert(_owner != null);

            StateBag viewState = ViewState;

            Color c;

            // ForeColor
            if (_owner.IsSet(PROP_FORECOLOR))
            {
                c = _owner.ForeColor;
                if (!c.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(c));
                }
            }
            // Not defaulting to black anymore for not entirely satisfying but reasonable reasons (VSWhidbey 356729)

            // need to call the property get in case we have font properties from view state and have not
            // created the font object
            FontInfo font = _owner.Font;

            // Font.Names
            string[] names = font.Names;
            if (names.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.FontFamily, String.Join(",", names));
            }

            // Font.Size
            FontUnit fu = font.Size;

            if (fu.IsEmpty == false)
            {
                attributes.Add(HtmlTextWriterStyle.FontSize, fu.ToString(CultureInfo.InvariantCulture));
            }

            // Font.Bold
            if (_owner.IsSet(PROP_FONT_BOLD))
            {
                if (font.Bold)
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "bold");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "normal");
                }
            }

            // Font.Italic
            if (_owner.IsSet(PROP_FONT_ITALIC))
            {
                if (font.Italic == true)
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "italic");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "normal");
                }
            }

            string textDecoration = String.Empty;

            if (font.Underline)
            {
                textDecoration = "underline";
            }
            if (font.Overline)
            {
                textDecoration += " overline";
            }
            if (font.Strikeout)
            {
                textDecoration += " line-through";
            }
            if (textDecoration.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, textDecoration);
            }
            else
            {
                if (!DoNotRenderDefaults)
                {
                    attributes.Add(HtmlTextWriterStyle.TextDecoration, "none");
                }
            }
            // Removing the border with an inline style if the class name was set
            if (_owner.IsSet(PROP_CSSCLASS))
            {
                attributes.Add(HtmlTextWriterStyle.BorderStyle, "none");
            }
        }
コード例 #11
0
        protected sealed override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            StateBag viewState = base.ViewState;

            if (this._owner.IsSet(4))
            {
                Color foreColor = this._owner.ForeColor;
                if (!foreColor.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(foreColor));
                }
            }
            FontInfo font = this._owner.Font;

            string[] names = font.Names;
            if (names.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.FontFamily, string.Join(",", names));
            }
            FontUnit size = font.Size;

            if (!size.IsEmpty)
            {
                attributes.Add(HtmlTextWriterStyle.FontSize, size.ToString(CultureInfo.InvariantCulture));
            }
            if (this._owner.IsSet(0x800))
            {
                if (font.Bold)
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "bold");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "normal");
                }
            }
            if (this._owner.IsSet(0x1000))
            {
                if (font.Italic)
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "italic");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "normal");
                }
            }
            string str = string.Empty;

            if (font.Underline)
            {
                str = "underline";
            }
            if (font.Overline)
            {
                str = str + " overline";
            }
            if (font.Strikeout)
            {
                str = str + " line-through";
            }
            if (str.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, str);
            }
            else if (!this.DoNotRenderDefaults)
            {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, "none");
            }
            if (this._owner.IsSet(2))
            {
                attributes.Add(HtmlTextWriterStyle.BorderStyle, "none");
            }
        }
コード例 #12
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            MemberInfo field;

            object[] objArray;
            string   str;

            if (!(destinationType == typeof(string)))
            {
                if (!(destinationType == typeof(InstanceDescriptor)) || (value == null))
                {
                    return(base.ConvertTo(context, culture, value, destinationType));
                }
                FontUnit unit = (FontUnit)value;
                field    = null;
                objArray = null;
                if (unit.IsEmpty)
                {
                    field = typeof(FontUnit).GetField("Empty");
                    goto Label_016E;
                }
                if (unit.Type == FontSize.AsUnit)
                {
                    field    = typeof(FontUnit).GetConstructor(new Type[] { typeof(Unit) });
                    objArray = new object[] { unit.Unit };
                    goto Label_016E;
                }
                str = null;
                switch (unit.Type)
                {
                case FontSize.Smaller:
                    str = "Smaller";
                    break;

                case FontSize.Larger:
                    str = "Larger";
                    break;

                case FontSize.XXSmall:
                    str = "XXSmall";
                    break;

                case FontSize.XSmall:
                    str = "XSmall";
                    break;

                case FontSize.Small:
                    str = "Small";
                    break;

                case FontSize.Medium:
                    str = "Medium";
                    break;

                case FontSize.Large:
                    str = "Large";
                    break;

                case FontSize.XLarge:
                    str = "XLarge";
                    break;

                case FontSize.XXLarge:
                    str = "XXLarge";
                    break;
                }
            }
            else
            {
                if (value != null)
                {
                    FontUnit unit2 = (FontUnit)value;
                    if (unit2.Type != FontSize.NotSet)
                    {
                        FontUnit unit3 = (FontUnit)value;
                        return(unit3.ToString(culture));
                    }
                }
                return(string.Empty);
            }
            if (str != null)
            {
                field = typeof(FontUnit).GetField(str);
            }
Label_016E:
            if (field != null)
            {
                return(new InstanceDescriptor(field, objArray));
            }
            return(null);
        }
コード例 #13
0
        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.AddAttributesToRender1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Adds all non-blank style attributes to the HTML output stream to be rendered
        ///       to the client.
        ///    </para>
        /// </devdoc>
        public virtual void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
        {
            StateBag viewState = ViewState;

            // CssClass
            if (IsSet(PROP_CSSCLASS))
            {
                string css = (string)(viewState["CssClass"]);
                if (css.Length > 0)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, css);
                }
            }

            Color c;
            Unit  u;

            // ForeColor
            if (IsSet(PROP_FORECOLOR))
            {
                c = (Color)(viewState["ForeColor"]);;
                if (!c.IsEmpty)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(c));
                }
            }

            // BackColor
            if (IsSet(PROP_BACKCOLOR))
            {
                c = (Color)(viewState["BackColor"]);
                if (!c.IsEmpty)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (IsSet(PROP_BORDERCOLOR))
            {
                c = (Color)(viewState["BorderColor"]);
                if (!c.IsEmpty)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit        bu = this.BorderWidth;

            if (!bu.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet)
                {
                    if (bu.Value != 0.0)
                    {
                        writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, Enum.Format(typeof(BorderStyle), bs, "G"));
                }
            }
            else
            {
                if (bs != BorderStyle.NotSet)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, Enum.Format(typeof(BorderStyle), bs, "G"));
                }
            }

            // need to call the property get in case we have font properties from view state and have not
            // created the font object
            FontInfo font = Font;

            // Font.Names
            string[] names = font.Names;
            if (names.Length > 0)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, Style.FormatStringArray(names, ','));
            }

            // Font.Size
            FontUnit fu = font.Size;

            if (fu.IsEmpty == false)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, fu.ToString(CultureInfo.InvariantCulture));
            }

            // CONSIDER: How do we determine whether to render "normal" for font-weight or font-style?
            //           How do we determine whether to render "none" for text-decoration?

            // Font.Bold
            bool fw = font.Bold;

            if (fw == true)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "bold");
            }
            // Font.Italic
            bool fi = font.Italic;

            if (fi == true)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontStyle, "italic");
            }

            bool   underline = font.Underline;
            bool   overline  = font.Overline;
            bool   strikeout = font.Strikeout;
            string td        = String.Empty;

            // CONSIDER, nikhilko: we need to detect not-set state and write out "none"
            if (underline)
            {
                td = "underline";
            }
            if (overline)
            {
                td += " overline";
            }
            if (strikeout)
            {
                td += " line-through";
            }
            if (td.Length > 0)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, td);
            }


            // Height
            if (IsSet(PROP_HEIGHT))
            {
                u = (Unit)(viewState["Height"]);
                if (u.IsEmpty == false)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (IsSet(PROP_WIDTH))
            {
                u = (Unit)(viewState["Width"]);
                if (u.IsEmpty == false)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }
        }
コード例 #14
0
        protected virtual void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            Color    color;
            Unit     unit3;
            StateBag viewState = this.ViewState;

            if (this.IsSet(4))
            {
                color = (Color)viewState["ForeColor"];
                if (!color.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
                }
            }
            if (this.IsSet(8))
            {
                color = (Color)viewState["BackColor"];
                if (!color.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
                }
            }
            if (this.IsSet(0x10))
            {
                color = (Color)viewState["BorderColor"];
                if (!color.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
                }
            }
            System.Web.UI.WebControls.BorderStyle borderStyle = this.BorderStyle;
            Unit borderWidth = this.BorderWidth;

            if (!borderWidth.IsEmpty)
            {
                attributes.Add(HtmlTextWriterStyle.BorderWidth, borderWidth.ToString(CultureInfo.InvariantCulture));
                if (borderStyle == System.Web.UI.WebControls.BorderStyle.NotSet)
                {
                    if (borderWidth.Value != 0.0)
                    {
                        attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)borderStyle]);
                }
            }
            else if (borderStyle != System.Web.UI.WebControls.BorderStyle.NotSet)
            {
                attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)borderStyle]);
            }
            FontInfo font = this.Font;

            string[] names = font.Names;
            if (names.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.FontFamily, FormatStringArray(names, ','));
            }
            FontUnit size = font.Size;

            if (!size.IsEmpty)
            {
                attributes.Add(HtmlTextWriterStyle.FontSize, size.ToString(CultureInfo.InvariantCulture));
            }
            if (this.IsSet(0x800))
            {
                if (font.Bold)
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "bold");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "normal");
                }
            }
            if (this.IsSet(0x1000))
            {
                if (font.Italic)
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "italic");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "normal");
                }
            }
            string str = string.Empty;

            if (font.Underline)
            {
                str = "underline";
            }
            if (font.Overline)
            {
                str = str + " overline";
            }
            if (font.Strikeout)
            {
                str = str + " line-through";
            }
            if (str.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, str);
            }
            else if ((this.IsSet(0x2000) || this.IsSet(0x4000)) || this.IsSet(0x8000))
            {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, "none");
            }
            if (this.IsSet(0x80))
            {
                unit3 = (Unit)viewState["Height"];
                if (!unit3.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Height, unit3.ToString(CultureInfo.InvariantCulture));
                }
            }
            if (this.IsSet(0x100))
            {
                unit3 = (Unit)viewState["Width"];
                if (!unit3.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Width, unit3.ToString(CultureInfo.InvariantCulture));
                }
            }
        }