The CSSPrimitiveValue interface represents a single CSS value.

This interface may be used to determine the value of a specific style property currently set in a block or to set a specific style property explicitly within the block. An instance of this interface might be obtained from the getPropertyCSSValue method of the CSSStyleDeclaration interface. A CSSPrimitiveValue object only occurs in a context of a CSS property.

Conversions are allowed between absolute values (from millimeters to centimeters, from degrees to radians, and so on) but not between relative values. (For example, a pixel value cannot be converted to a centimeter value.) Percentage values can't be converted since they are relative to the parent value (or another property value). There is one exception for color percentage values: since a color percentage value is relative to the range 0-255, a color percentage value can be converted to a number; (see also the RGBColor interface).

Inheritance: CssValue, ICssPrimitiveValue
Beispiel #1
0
 private void SetPrimitiveValues(string red, string green, string blue, string alpha)
 {
     _red   = new CssPrimitiveColorValue(red, false);
     _green = new CssPrimitiveColorValue(green, false);
     _blue  = new CssPrimitiveColorValue(blue, false);
     _alpha = new CssPrimitiveColorValue(alpha, false);
 }
Beispiel #2
0
 private void SetPrimitiveValues(int red, int green, int blue, int alpha)
 {
     _red   = new CssPrimitiveColorValue(red, false);
     _green = new CssPrimitiveColorValue(green, false);
     _blue  = new CssPrimitiveColorValue(blue, false);
     _alpha = new CssPrimitiveColorValue(alpha, false);
 }
 public CssAbsPrimitiveValue(CssPrimitiveValue cssValue, string propertyName, 
     XmlElement element)
 {
     _cssValue     = cssValue;
     _propertyName = propertyName;
     _element      = element;
 }
Beispiel #4
0
        /// <summary>
        /// Detects what kind of value cssText contains and returns an instance of the correct CssValue class
        /// </summary>
        /// <param name="cssText">The text to parse for a CSS value</param>
        /// <param name="readOnly">Specifies if this instance is read-only</param>
        /// <returns>The correct type of CSS value</returns>
        static public CssValue GetCssValue(string cssText, bool readOnly)
        {
            if (cssText == "inherit")
            {
                // inherit
                return(new CssValue(CssValueType.Inherit, cssText, readOnly));
            }
            else
            {
                Match match = reCssPrimitiveValue.Match(cssText);
                if (match.Success)
                {
                    // single primitive value
                    return(CssPrimitiveValue.Create(match, readOnly));
                }

                match = reCssValueList.Match(cssText);
                if (match.Success)
                {
                    // list of primitive values
                    throw new NotImplementedException("Value lists not implemented");
                }
                else
                {
                    // custom value
                    return(new CssValue(CssValueType.Custom, cssText, readOnly));
                }
            }
        }
 public CssAbsPrimitiveValue(CssPrimitiveValue cssValue, string propertyName,
                             XmlElement element)
 {
     _cssValue     = cssValue;
     _propertyName = propertyName;
     _element      = element;
 }
Beispiel #6
0
        public void TestInheritEm()
        {
            CssStyleDeclaration csd       = getStyles("<a />", "root{font-size:18px} a{inher:3em}", "a");
            CssPrimitiveValue   primValue = csd.GetPropertyCssValue("inher") as CssPrimitiveValue;

            Assert.AreEqual(54, primValue.GetFloatValue(CssPrimitiveType.Px));
        }
Beispiel #7
0
        /// <summary>
        /// Constructs a new Rect
        /// </summary>
        /// <param name="s">The string to parse that contains the Rect structure</param>
        /// <param name="readOnly">Specifies if the Rect should be read-only</param>
        public CssRect(string rectString, bool readOnly)
        {
            this.readOnly = readOnly;

            if (rectString == null)
            {
                rectString = string.Empty;
            }

            // remove leading and trailing whitespace
            // NOTE: Need to check if .NET whitespace = SVG (XML) whitespace
            rectString = rectString.Trim();

            if (rectString.Length > 0)
            {
                string[] parts = rectString.Split(' ');
                if (parts.Length != 4)
                {
                    parts = _delim.Split(rectString);
                }
                if (parts.Length == 4)
                {
                    _top    = new CssPrimitiveLengthValue(parts[0], readOnly);
                    _right  = new CssPrimitiveLengthValue(parts[1], readOnly);
                    _bottom = new CssPrimitiveLengthValue(parts[2], readOnly);
                    _left   = new CssPrimitiveLengthValue(parts[3], readOnly);
                }
                else
                {
                    throw new DomException(DomExceptionType.SyntaxErr);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Constructs a new Rect
        /// </summary>
        /// <param name="s">The string to parse that contains the Rect structure</param>
        /// <param name="readOnly">Specifies if the Rect should be read-only</param>
        public CssRect(string rectString, bool readOnly)
        {
            this.readOnly = readOnly;

            if (rectString == null)
            {
                rectString = String.Empty;
            }

            // remove leading and trailing whitespace
            // NOTE: Need to check if .NET whitespace = SVG (XML) whitespace
            rectString = rectString.Trim();

            if (rectString.Length > 0)
            {
                string[] parts = rectString.Split(' ');
                if (parts.Length != 4)
                {
                    parts = delim.Split(rectString);
                }
                if (parts.Length == 4)
                {
                    _top    = new CssPrimitiveLengthValue(parts[0], readOnly);
                    _right  = new CssPrimitiveLengthValue(parts[1], readOnly);
                    _bottom = new CssPrimitiveLengthValue(parts[2], readOnly);
                    _left   = new CssPrimitiveLengthValue(parts[3], readOnly);
                }
                else
                {
                    throw new DomException(DomExceptionType.SyntaxErr);
                }
            }
        }
Beispiel #9
0
        public void TestRectValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[1]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("rect");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("rect");

            Assert.AreEqual("rect(10cm 23px 45px 89px)", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.Rect, primValue.PrimitiveType);
            IRect rect = primValue.GetRectValue();

            ICssPrimitiveValue rectValue = rect.Top;

            Assert.AreEqual(100, rectValue.GetFloatValue(CssPrimitiveType.Mm));
            Assert.AreEqual(CssPrimitiveType.Cm, rectValue.PrimitiveType);

            rectValue = rect.Right;
            Assert.AreEqual(23, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);

            rectValue = rect.Bottom;
            Assert.AreEqual(45, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);

            rectValue = rect.Left;
            Assert.AreEqual(89, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);
        }
 public void TestAbsoluteRgb()
 {
     color = new CssPrimitiveRgbValue("rgb( 100  ,	123,15)", false);
             RgbColor rgbColor = (RgbColor)color.GetRgbColorValue();
             Assert.AreEqual(100, rgbColor.Red.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(123, rgbColor.Green.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(15, rgbColor.Blue.GetFloatValue(CssPrimitiveType.Number));
 }
Beispiel #11
0
        private void SetPrimitiveValues(ColorRGBA color, string alpha)
        {
            SetPrimitiveValues(color);

            if (!string.IsNullOrWhiteSpace(alpha))
            {
                _alpha = new CssPrimitiveColorValue(alpha, false);
            }
        }
Beispiel #12
0
        private void SetPrimitiveValues(ColorRGBA color)
        {
            _red   = new CssPrimitiveColorValue(color.R, false);
            _green = new CssPrimitiveColorValue(color.G, false);
            _blue  = new CssPrimitiveColorValue(color.B, false);

            if (color.A >= 0)
            {
                _alpha = new CssPrimitiveColorValue(color.A, false);
            }
        }
Beispiel #13
0
        public void TestColorRgbPercValue()
        {
            CssPrimitiveValue primValue = (CssPrimitiveValue)colorRules.GetPropertyCssValue("rgbperc");

            Assert.AreEqual("rgb(59,115,171)", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.RgbColor, primValue.PrimitiveType);
            RgbColor color = (RgbColor)primValue.GetRgbColorValue();

            Assert.AreEqual(0.23 * 255, color.Red.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(0.45 * 255, color.Green.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(0.67 * 255, color.Blue.GetFloatValue(CssPrimitiveType.Number));
        }
Beispiel #14
0
        public void TestColorRgbAbsValue()
        {
            CssPrimitiveValue primValue = (CssPrimitiveValue)colorRules.GetPropertyCssValue("rgbabs");

            Assert.AreEqual("rgb(45,78,98)", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.RgbColor, primValue.PrimitiveType);
            RgbColor color = (RgbColor)primValue.GetRgbColorValue();

            Assert.AreEqual(45, color.Red.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(78, color.Green.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(98, color.Blue.GetFloatValue(CssPrimitiveType.Number));
        }
Beispiel #15
0
        public void TestColorShortHexValue()
        {
            CssPrimitiveValue primValue = (CssPrimitiveValue)colorRules.GetPropertyCssValue("shorthex");

            Assert.AreEqual("rgb(17,34,51)", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.RgbColor, primValue.PrimitiveType);
            RgbColor color = (RgbColor)primValue.GetRgbColorValue();

            Assert.AreEqual(17, color.Red.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(34, color.Green.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(51, color.Blue.GetFloatValue(CssPrimitiveType.Number));
        }
Beispiel #16
0
        public void TestFloatPcValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("float-pc");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-pc");

            Assert.AreEqual("10pc", primValue.CssText, "CssText");
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType, "CssValueType");
            Assert.AreEqual(CssPrimitiveType.Pc, primValue.PrimitiveType, "PrimitiveType");
            Assert.AreEqual(10, primValue.GetFloatValue(CssPrimitiveType.Pc), "To PC");
        }
Beispiel #17
0
        public void TestFloatInValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("float-in");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-in");

            Assert.AreEqual("10in", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.In, primValue.PrimitiveType);
            Assert.AreEqual(10, primValue.GetFloatValue(CssPrimitiveType.In));
        }
 public CssAbsPrimitiveValue(CssPrimitiveValue cssValue, string propertyName, XmlElement element)
 {
     if (cssValue == null)
     {
         throw new ArgumentNullException(nameof(cssValue));
     }
     if (element == null)
     {
         throw new ArgumentNullException(nameof(element));
     }
     _cssValue     = cssValue;
     _propertyName = propertyName;
     _element      = element;
 }
Beispiel #19
0
        public void TestFloatPxValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("float-px");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-px");

            Assert.AreEqual("12px", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.Px, primValue.PrimitiveType);
            double res = primValue.GetFloatValue(CssPrimitiveType.Px);

            Assert.AreEqual(12, res);
        }
Beispiel #20
0
        public void TestFloatUnitlessValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("float-unitless");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-unitless");

            Assert.AreEqual("67", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.Number, primValue.PrimitiveType);
            double res = primValue.GetFloatValue(CssPrimitiveType.Number);

            Assert.AreEqual(67, res);
        }
Beispiel #21
0
        public void TestStringValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[1]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("string");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("string");

            Assert.AreEqual("\"a string\"", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.String, primValue.PrimitiveType);
            string str = primValue.GetStringValue();

            Assert.AreEqual("a string", str);
        }
Beispiel #22
0
        public void TestFloatPtValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("float-pt");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-pt");

            Assert.AreEqual("10pt", primValue.CssText, "CssText");
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType, "CssValueType");
            Assert.AreEqual(CssPrimitiveType.Pt, primValue.PrimitiveType, "PrimitiveType");
            Assert.AreEqual(10, primValue.GetFloatValue(CssPrimitiveType.Pt), "To PC");
            Assert.AreEqual(10 / 72D * 2.54D, primValue.GetFloatValue(CssPrimitiveType.Cm), "To CM");
            Assert.AreEqual(100 / 72D * 2.54D, primValue.GetFloatValue(CssPrimitiveType.Mm), "To MM");
            Assert.AreEqual(10 / 72D, primValue.GetFloatValue(CssPrimitiveType.In), "To IN");
            Assert.AreEqual(10 / 12D, primValue.GetFloatValue(CssPrimitiveType.Pc), "To PT");
        }
Beispiel #23
0
        public void TestColorLongHexValue()
        {
            CssValue val = (CssValue)colorRules.GetPropertyCssValue("longhex");

            Assert.IsTrue(val is CssPrimitiveValue, "1");
            CssPrimitiveValue primValue = (CssPrimitiveValue)colorRules.GetPropertyCssValue("longhex");

            Assert.AreEqual("rgb(101,67,33)", primValue.CssText, "2");
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType, "3");
            Assert.AreEqual(CssPrimitiveType.RgbColor, primValue.PrimitiveType, "4");
            RgbColor color = (RgbColor)primValue.GetRgbColorValue();

            Assert.AreEqual(101, color.Red.GetFloatValue(CssPrimitiveType.Number), "5");
            Assert.AreEqual(67, color.Green.GetFloatValue(CssPrimitiveType.Number), "6");
            Assert.AreEqual(33, color.Blue.GetFloatValue(CssPrimitiveType.Number), "7");
            Assert.AreEqual(ColorTranslator.FromHtml("#654321"), color.GdiColor, "8");
        }
Beispiel #24
0
        /// <summary>
        /// Constructs a new Rect
        /// </summary>
        /// <param name="s">The string to parse that contains the Rect structure</param>
        /// <param name="readOnly">Specifies if the Rect should be read-only</param>
        public Rect(string s, bool readOnly)
        {
            this.readOnly = readOnly;

            string[] parts = s.Split(new char[]{' '});
            if(parts.Length == 4)
            {
                _top = new CssPrimitiveLengthValue(parts[0], readOnly);
                _right = new CssPrimitiveLengthValue(parts[1], readOnly);
                _bottom = new CssPrimitiveLengthValue(parts[2], readOnly);
                _left = new CssPrimitiveLengthValue(parts[3], readOnly);
            }
            else
            {
                throw new DomException(DomExceptionType.SyntaxErr);
            }
        }
Beispiel #25
0
        public void TestColorNameValue()
        {
            CssPrimitiveValue primValue = (CssPrimitiveValue)colorRules.GetPropertyCssValue("name");

            Assert.AreEqual("rgb(60,179,113)", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.RgbColor, primValue.PrimitiveType);
            RgbColor color = (RgbColor)primValue.GetRgbColorValue();

            Assert.AreEqual(60, color.Red.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(179, color.Green.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(113, color.Blue.GetFloatValue(CssPrimitiveType.Number));

            primValue = (CssPrimitiveValue)colorRules.GetPropertyCssValue("grey-name");
            color     = (RgbColor)primValue.GetRgbColorValue();
            Assert.AreEqual(119, color.Red.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(136, color.Green.GetFloatValue(CssPrimitiveType.Number));
            Assert.AreEqual(153, color.Blue.GetFloatValue(CssPrimitiveType.Number));
        }
    public void TestCssNames()
    {
        Hashtable table = new Hashtable();
                table.Add("maroon", "#800000");
                table.Add("red", "#ff0000");
                table.Add("orange", "#ffA500");
                table.Add("yellow", "#ffff00");
                table.Add("olive", "#808000");
                table.Add("purple", "#800080");
                table.Add("fuchsia", "#ff00ff");
                table.Add("white", "#ffffff");
                table.Add("lime", "#00ff00");
                table.Add("green", "#008000");
                table.Add("navy", "#000080");
                table.Add("blue", "#0000ff");
                table.Add("aqua", "#00ffff");
                table.Add("teal", "#008080");
                table.Add("black", "#000000");
                table.Add("silver", "#c0c0c0");
                table.Add("gray", "#808080");

                IEnumerator colorEnum = table.Keys.GetEnumerator();
                while(colorEnum.MoveNext())
                {
                    string name = (string)colorEnum.Current;
                    string hexColor = (string)table[name];

                    color = new CssPrimitiveRgbValue(name, false);
                    CssPrimitiveRgbValue color2 = new CssPrimitiveRgbValue(hexColor, false);

                    RgbColor rgbColor = (RgbColor)color.GetRgbColorValue();
                    RgbColor rgbColor2 = (RgbColor)color2.GetRgbColorValue();

                    Assert.AreEqual(rgbColor2.Red.GetFloatValue(CssPrimitiveType.Number), rgbColor.Red.GetFloatValue(CssPrimitiveType.Number), name + " red");
                    Assert.AreEqual(rgbColor2.Green.GetFloatValue(CssPrimitiveType.Number), rgbColor.Green.GetFloatValue(CssPrimitiveType.Number), name + " green");
                    Assert.AreEqual(rgbColor2.Blue.GetFloatValue(CssPrimitiveType.Number), rgbColor.Blue.GetFloatValue(CssPrimitiveType.Number), name + " blue");
                }
    }
Beispiel #27
0
        /// <summary>
        /// Detects what kind of value cssText contains and returns an instance of the correct CssValue class
        /// </summary>
        /// <param name="cssText">The text to parse for a CSS value</param>
        /// <param name="readOnly">Specifies if this instance is read-only</param>
        /// <returns>The correct type of CSS value</returns>
        public static CssValue GetCssValue(string cssText, bool readOnly)
        {
            if (string.Equals(cssText, "inherit", StringComparison.OrdinalIgnoreCase))
            {
                // inherit
                return(new CssValue(CssValueType.Inherit, cssText, readOnly));
            }
            Match match = _reCssPrimitiveValue.Match(cssText);

            if (match.Success)
            {
                // single primitive value
                return(CssPrimitiveValue.Create(match, readOnly));
            }

            match = _reCssValueList.Match(cssText);
            if (match.Success)
            {
                // list of primitive values
                throw new NotImplementedException("Value lists not implemented");
            }
            // custom value
            return(new CssValue(CssValueType.Custom, cssText, readOnly));
        }
        public CssAbsPrimitiveLengthValue(CssPrimitiveValue cssValue, string propertyName, XmlElement element)
        {
            if (cssValue.PrimitiveType == CssPrimitiveType.Ident)
            {
                // this is primarily to deal with font sizes.
                float absSize;
                switch (cssValue.GetStringValue())
                {
                case "xx-small":
                    absSize = 6F;
                    break;

                case "x-small":
                    absSize = 7.5F;
                    break;

                case "small":
                    absSize = 8.88F;
                    break;

                case "large":
                    absSize = 12F;
                    break;

                case "x-large":
                    absSize = 15F;
                    break;

                case "xx-large":
                    absSize = 20F;
                    break;

                case "larger":
                case "smaller":
                    float parSize;
                    if (_parentElement != null)
                    {
                        CssStyleDeclaration csd          = (CssStyleDeclaration)_ownerDocument.GetComputedStyle(_parentElement, string.Empty);
                        CssPrimitiveValue   cssPrimValue = csd.GetPropertyCssValue("font-size") as CssPrimitiveValue;

                        // no default font-size set => use 10px
                        if (cssPrimValue == null)
                        {
                            parSize = 10;
                        }
                        else
                        {
                            parSize = (float)cssPrimValue.GetFloatValue(CssPrimitiveType.Px);
                        }
                    }
                    else
                    {
                        parSize = 10;
                    }
                    if (cssValue.GetStringValue() == "smaller")
                    {
                        absSize = parSize / 1.2F;
                    }
                    else
                    {
                        absSize = parSize * 1.2F;
                    }
                    break;

                default:
                    absSize = 10F;
                    break;
                }
                SetFloatValue(absSize);
                SetPrimitiveType(CssPrimitiveType.Px);
            }
            else
            {
                SetFloatValue(cssValue.GetFloatValue(cssValue.PrimitiveType));
                SetPrimitiveType(cssValue.PrimitiveType);
            }
            _propertyName = propertyName;
            _element      = element;
        }
Beispiel #29
0
 private void SetPrimitiveValues(Color color)
 {
     _red   = new CssPrimitiveColorValue(color.R, false);
     _green = new CssPrimitiveColorValue(color.G, false);
     _blue  = new CssPrimitiveColorValue(color.B, false);
 }
 public void TestPercentageRgb()
 {
     color = new CssPrimitiveRgbValue("rgb(50%,	12%, 100%)", false);
             RgbColor rgbColor = (RgbColor)color.GetRgbColorValue();
             Assert.AreEqual(255*0.5, rgbColor.Red.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(255*0.12, rgbColor.Green.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(255, rgbColor.Blue.GetFloatValue(CssPrimitiveType.Number));
 }
 public void TestShortHex()
 {
     color = new CssPrimitiveRgbValue("  #C8f", false);
             RgbColor rgbColor = (RgbColor)color.GetRgbColorValue();
             Assert.AreEqual(204, rgbColor.Red.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(136, rgbColor.Green.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(255, rgbColor.Blue.GetFloatValue(CssPrimitiveType.Number));
 }
Beispiel #32
0
 private void SetPrimitiveValues(string red, string green, string blue)
 {
     _red   = new CssPrimitiveColorValue(red, false);
     _green = new CssPrimitiveColorValue(green, false);
     _blue  = new CssPrimitiveColorValue(blue, false);
 }
Beispiel #33
0
 private void SetPrimitiveValues(int red, int green, int blue)
 {
     _red   = new CssPrimitiveColorValue(red, false);
     _green = new CssPrimitiveColorValue(green, false);
     _blue  = new CssPrimitiveColorValue(blue, false);
 }
Beispiel #34
0
 private void SetPrimitiveValues(Color color)
 {
     _red   = new CssPrimitiveColorValue(color.R, false);
     _green = new CssPrimitiveColorValue(color.G, false);
     _blue  = new CssPrimitiveColorValue(color.B, false);
 }
 public void TestHex()
 {
     color = new CssPrimitiveRgbValue("#12C2a4  ", false);
             RgbColor rgbColor = (RgbColor)color.GetRgbColorValue();
             Assert.AreEqual(18, rgbColor.Red.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(194, rgbColor.Green.GetFloatValue(CssPrimitiveType.Number));
             Assert.AreEqual(164, rgbColor.Blue.GetFloatValue(CssPrimitiveType.Number));
 }
        public CssAbsPrimitiveLengthValue(CssPrimitiveValue cssValue, string propertyName, XmlElement element)
        {
            if (cssValue.PrimitiveType == CssPrimitiveType.Ident)
            {
                // this is primarily to deal with font sizes.
                float absSize;
                switch (cssValue.GetStringValue())
                {
                    case "xx-small":
                        absSize = 6F;
                        break;
                    case "x-small":
                        absSize = 7.5F;
                        break;
                    case "small":
                        absSize = 8.88F;
                        break;
                    case "large":
                        absSize = 12F;
                        break;
                    case "x-large":
                        absSize = 15F;
                        break;
                    case "xx-large":
                        absSize = 20F;
                        break;
                    case "larger":
                    case "smaller":
                        float parSize;
                        if(_parentElement != null)
                        {
                            CssStyleDeclaration csd = (CssStyleDeclaration)_ownerDocument.GetComputedStyle(_parentElement, String.Empty);
                            CssPrimitiveValue cssPrimValue = csd.GetPropertyCssValue("font-size") as CssPrimitiveValue;

                            // no default font-size set => use 10px
                            if(cssPrimValue == null)
                            {
                                parSize = 10;
                            }
                            else
                            {
                                parSize = (float)cssPrimValue.GetFloatValue(CssPrimitiveType.Px);
                            }
                        }
                        else
                        {
                            parSize = 10;
                        }
                        if(cssValue.GetStringValue() == "smaller") absSize = parSize / 1.2F;
                        else absSize = parSize * 1.2F;
                        break;
                    default:
                        absSize = 10F;
                        break;
                }
                SetFloatValue(absSize);
                SetPrimitiveType(CssPrimitiveType.Px);
            }
            else
            {
                SetFloatValue(cssValue.GetFloatValue(cssValue.PrimitiveType));
                SetPrimitiveType(cssValue.PrimitiveType);
            }
            _propertyName = propertyName;
            _element = element;
        }