コード例 #1
0
 /// <summary>
 /// Used to find matching style rules in the cascading order
 /// </summary>
 /// <param name="elt">The element to find styles for</param>
 /// <param name="pseudoElt">The pseudo-element to find styles for</param>
 /// <param name="ml">The medialist that the document is using</param>
 /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param>
 internal void GetStylesForElement(XmlElement elt, string pseudoElt, CssCollectedStyleDeclaration csd, MediaList ml)
 {
     foreach (StyleSheet ss in _styleSheets)
     {
         ss.GetStylesForElement(elt, pseudoElt, ml, csd);
     }
 }
コード例 #2
0
        public override ICssStyleDeclaration GetComputedStyle(string pseudoElt)
        {
            SvgDocument ownerDoc = this.OwnerDocument;

            if (_isImported && _importDocument != null && _importNode != null)
            {
                ownerDoc = (SvgDocument)_importDocument;
            }

            if (_cachedCSD == null)
            {
                CssCollectedStyleDeclaration csd = (CssCollectedStyleDeclaration)base.GetComputedStyle(pseudoElt);

                var propNames = ownerDoc.CssPropertyProfile.GetAllPropertyNames();

                IEnumerator <string> cssPropNames = propNames.GetEnumerator();
                while (cssPropNames.MoveNext())
                {
                    string   cssPropName = cssPropNames.Current;
                    CssValue cssValue    = (CssValue)GetPresentationAttribute(cssPropName);
                    if (cssValue != null)
                    {
                        csd.CollectProperty(cssPropName, 0, cssValue,
                                            CssStyleSheetType.NonCssPresentationalHints, string.Empty);
                    }
                }

                _cachedCSD = csd;
            }
            return(_cachedCSD);
        }
コード例 #3
0
    protected override CssStyleDeclaration getCSD()
    {
        CssCollectedStyleDeclaration csd = new CssCollectedStyleDeclaration(getElm());

        csd.CollectProperty("foo", 1, _getCssValue("bar"), CssStyleSheetType.Author, String.Empty);
        csd.CollectProperty("length", 1, _getCssValue("23cm"), CssStyleSheetType.Author, "important");
        return(csd);
    }
コード例 #4
0
    public void CollectOverrideImportant1()
    {
        XmlElement elm = getElm();
        CssCollectedStyleDeclaration csd = new CssCollectedStyleDeclaration(elm);

        csd.CollectProperty("foo", 100, _getCssValue("value1"), CssStyleSheetType.Author, "");
        csd.CollectProperty("foo", 1, _getCssValue("value2"), CssStyleSheetType.Author, "important");
        Assert.AreEqual("foo:value2 !important;", csd.CssText);
    }
コード例 #5
0
    public void TestExsFontSize()
    {
        CssCollectedStyleDeclaration csd = new CssCollectedStyleDeclaration(getElm());

        csd.CollectProperty("font-size", 1, CssValue.GetCssValue("2ex", false), CssStyleSheetType.Author, "");

        CssPrimitiveValue cssPrimValue = csd.GetPropertyCssValue("font-size") as CssPrimitiveValue;

        Assert.AreEqual(10, cssPrimValue.GetFloatValue(CssPrimitiveType.Px));
    }
コード例 #6
0
    public void TestEmsNotFontSize()
    {
        CssCollectedStyleDeclaration csd = new CssCollectedStyleDeclaration(getElm());

        csd.CollectProperty("notFontSize", 1, CssValue.GetCssValue("2em", false), CssStyleSheetType.Author, "");

        CssPrimitiveValue cssPrimValue = csd.GetPropertyCssValue("notFontSize") as CssPrimitiveValue;

        Assert.AreEqual(typeof(CssAbsPrimitiveLengthValue), cssPrimValue.GetType());
        Assert.AreEqual(20, cssPrimValue.GetFloatValue(CssPrimitiveType.Px));
    }
コード例 #7
0
    public void Collect()
    {
        XmlElement elm = getElm();
        CssCollectedStyleDeclaration csd = new CssCollectedStyleDeclaration(elm);

        Assert.AreEqual(0, csd.Length);
        csd.CollectProperty("foo", 1, _getCssValue("12px"), CssStyleSheetType.Author, "important");
        Assert.AreEqual(1, csd.Length);
        Assert.AreEqual("foo:12px !important;", csd.CssText);

        csd.CollectProperty("bar", 1, _getCssValue("test"), CssStyleSheetType.Author, "");
        Assert.AreEqual(2, csd.Length);
        Assert.AreEqual("foo:12px !important;bar:test;", csd.CssText);
    }
コード例 #8
0
    public void TestFuncAttr()
    {
        XmlElement elm = getElm();

        elm.SetAttribute("kalle", "", "roffe");
        CssCollectedStyleDeclaration csd = new CssCollectedStyleDeclaration(elm);

        csd.CollectProperty("foo", 1, CssValue.GetCssValue("attr(kalle)", false), CssStyleSheetType.Author, "");

        CssPrimitiveValue cssPrimValue = csd.GetPropertyCssValue("foo") as CssPrimitiveValue;

        Assert.IsNotNull(cssPrimValue);
        Assert.AreEqual("roffe", cssPrimValue.GetStringValue());
    }
コード例 #9
0
        public override ICssStyleDeclaration GetComputedStyle(string pseudoElt)
        {
            if (cachedCSD == null)
            {
                CssCollectedStyleDeclaration csd = (CssCollectedStyleDeclaration)base.GetComputedStyle(pseudoElt);

                IEnumerator cssPropNames = OwnerDocument.CssPropertyProfile.GetAllPropertyNames().GetEnumerator();
                while (cssPropNames.MoveNext())
                {
                    string   cssPropName = (string)cssPropNames.Current;
                    CssValue cssValue    = (CssValue)GetPresentationAttribute(cssPropName);
                    if (cssValue != null)
                    {
                        csd.CollectProperty(cssPropName, 0, cssValue, CssStyleSheetType.NonCssPresentationalHints, String.Empty);
                    }
                }

                cachedCSD = csd;
            }
            return(cachedCSD);
        }
コード例 #10
0
 /// <summary>
 /// Used to find matching style rules in the cascading order
 /// </summary>
 /// <param name="elt">The element to find styles for</param>
 /// <param name="pseudoElt">The pseudo-element to find styles for</param>
 /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param>
 public void GetStylesForElement(XmlElement elt, string pseudoElt, CssCollectedStyleDeclaration csd)
 {
     GetStylesForElement(elt, pseudoElt, csd, _cssXmlDoc.Media);
 }
コード例 #11
0
ファイル: StyleSheet.cs プロジェクト: naver/protonow
 /// <summary>
 /// Used to find matching style rules in the cascading order
 /// </summary>
 /// <param name="elt">The element to find styles for</param>
 /// <param name="pseudoElt">The pseudo-element to find styles for</param>
 /// <param name="ml">The medialist that the document is using</param>
 /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param>
 protected internal virtual void GetStylesForElement(XmlElement elt, string pseudoElt,
                                                     MediaList ml, CssCollectedStyleDeclaration csd)
 {
 }
コード例 #12
0
ファイル: SVGWidgetViewModel.cs プロジェクト: naver/protonow
        private void setNodeFillColor(ISvgElement targetNode, Color fillColor, string property)
        {
            string szRGB = null, szOpacity = null, szNodeopacity = null;

            if (targetNode.RenderingHint == SvgRenderingHint.Text || targetNode.RenderingHint == SvgRenderingHint.Shape)
            {
                szRGB = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue(property);


                //Special handling: if fill color is white and it is inner node, don't change it.
                //add id for svgs in Social/Gesture/Style BG. need to check svg if load new svg folder.
                if (string.IsNullOrEmpty(szRGB) || (szRGB == "rgb(255,255,255)" && !string.IsNullOrEmpty((targetNode as SvgElement).Id)))
                {
                    return;
                }

                //Get RGB Color
                SvgPaint paint = new SvgPaint(szRGB);
                if (paint.RgbColor == null)
                {
                    return;
                }
            }

            //Set RGB Color
            CssCollectedStyleDeclaration All = (targetNode as SvgElement).GetComputedStyle("") as CssCollectedStyleDeclaration;
            CssStyleSheetType            origin = All.GetPropertyOrigin(property);

            switch (origin)
            {
            //For those default fill color is black,and has no this attribute.Add and set it.
            case CssStyleSheetType.Unknown:
            case CssStyleSheetType.NonCssPresentationalHints:
            {
                string value = string.Format("rgb({0},{1},{2})", fillColor.R, fillColor.G, fillColor.B);
                targetNode.SetAttribute(property, value);
                break;
            }

            case CssStyleSheetType.Inline:
            {
                string value = string.Format("rgb({0},{1},{2})", fillColor.R, fillColor.G, fillColor.B);
                SvgStyleableElement styleNode = targetNode as SvgStyleableElement;
                styleNode.Style.SetProperty(property, value, string.Empty);
                targetNode.SetAttribute("style", styleNode.Style.CssText);
                break;
            }

            case CssStyleSheetType.Author:
            {
                break;
            }
            }

            //Set Alpha value
            szOpacity     = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue(property + @"-opacity");
            szNodeopacity = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue("opacity");
            if (szNodeopacity == null && szOpacity == null)
            {
                if (fillColor.A == 255)
                {
                    return;
                }

                string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255));
                targetNode.SetAttribute(property + @"-opacity", value);
            }
            else
            {
                string Oproperty = null;
                if (szNodeopacity != null && szNodeopacity.Length > 0)
                {
                    Oproperty = "opacity";
                }
                else
                {
                    Oproperty = property + @"-opacity";
                }


                origin = All.GetPropertyOrigin(Oproperty);
                switch (origin)
                {
                case CssStyleSheetType.NonCssPresentationalHints:
                {
                    string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255));
                    targetNode.SetAttribute(Oproperty, value);
                    break;
                }

                case CssStyleSheetType.Unknown:
                {
                    string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255));
                    targetNode.SetAttribute(Oproperty, value);
                    break;
                }

                case CssStyleSheetType.Inline:
                {
                    string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255));
                    SvgStyleableElement styleNode = targetNode as SvgStyleableElement;
                    styleNode.Style.SetProperty(Oproperty, value, string.Empty);
                    targetNode.SetAttribute("style", styleNode.Style.CssText);
                    break;
                }

                case CssStyleSheetType.Author:
                {
                    break;
                }
                }
            }
        }