Ejemplo n.º 1
0
        protected void ImplSetAttribute(DomAttribute attr)
        {
            //handle some attribute
            //special for some attributes

            switch ((WellknownName)attr.LocalNameIndex)
            {
            case WellknownName.Style:
            {
                //TODO: parse and evaluate style here
                //****
                WebDom.Parser.CssParser miniCssParser = CssParserPool.GetFreeParser();
                //parse and evaluate the ruleset
                CssRuleSet parsedRuleSet = miniCssParser.ParseCssPropertyDeclarationList(attr.Value.ToCharArray());

                Css.BoxSpec spec = null;
                if (this.ParentNode != null)
                {
                    spec = ((HtmlElement)this.ParentNode).Spec;
                }
                foreach (WebDom.CssPropertyDeclaration propDecl in parsedRuleSet.GetAssignmentIter())
                {
                    SpecSetter.AssignPropertyValue(
                        _boxSpec,
                        spec,
                        propDecl);
                }
                CssParserPool.ReleaseParser(ref miniCssParser);
            }
            break;
            }
        }
Ejemplo n.º 2
0
        public override void SetAttribute(DomAttribute attr)
        {
            base.SetAttribute(attr); //to base
            //----------------------

            switch ((WellknownName)attr.LocalNameIndex)
            {
            case WellknownName.Src:
            {
                switch (this.WellknownElementName)
                {
                case WellKnownDomNodeName.img:
                {
                    if (_principalBox != null)
                    {
                        CssBoxImage boxImg = (CssBoxImage)_principalBox;
                        boxImg.ImageBinder = new ImageBinder(attr.Value);
                        boxImg.InvalidateGraphics();
                    }
                }
                break;
                }
            }
            break;

            case WellknownName.Style:
            {
                //TODO: parse and evaluate style here
                //****
                WebDom.Parser.CssParser miniCssParser = CssParserPool.GetFreeParser();
                //parse and evaluate the ruleset
                CssRuleSet parsedRuleSet = miniCssParser.ParseCssPropertyDeclarationList(attr.Value.ToCharArray());

                Css.BoxSpec spec = null;
                if (this.ParentNode != null)
                {
                    spec = ((HtmlElement)this.ParentNode).Spec;
                }
                foreach (WebDom.CssPropertyDeclaration propDecl in parsedRuleSet.GetAssignmentIter())
                {
                    SpecSetter.AssignPropertyValue(
                        _boxSpec,
                        spec,
                        propDecl);
                }
                CssParserPool.ReleaseParser(ref miniCssParser);
            }
            break;
            }
        }
Ejemplo n.º 3
0
        void ApplyStyleSheetForSingleHtmlElement(
            HtmlElement element,
            BoxSpec parentSpec,
            TopDownActiveCssTemplate activeCssTemplate)
        {
            BoxSpec curSpec = element.Spec;

            BoxSpec.InheritStyles(curSpec, parentSpec);
            //--------------------------------
            string classValue = null;

            if (element.HasAttributeClass)
            {
                classValue = element.AttrClassValue;
            }
            //--------------------------------
            //1. apply style
            activeCssTemplate.ApplyCacheTemplate(element.LocalName,
                                                 classValue,//class
                                                 curSpec,
                                                 parentSpec);
            //-------------------------------------------------------------------
            //2. specific id
            if (element.HasAttributeElementId)
            {
                // element.ElementId;
                activeCssTemplate.ApplyActiveTemplateForSpecificElementId(element);
            }
            //3. some html translate attributes

            if (element.WellknownElementName != WellKnownDomNodeName.svg)
            {
                //translate svg attributes
                AssignStylesFromTranslatedAttributesHTML5(element);
            }
            else
            {
                AssignSvgAttributes(element);
            }
            //-------------------------------------------------------------------
            //4. style attribute value
            //'style' object of this element
            if (!element.IsStyleEvaluated)
            {
                CssRuleSet parsedRuleSet = null;
                string     attrStyleValue;
                if (element.TryGetAttribute(WellknownName.Style, out attrStyleValue))
                {
                    //parse and evaluate the ruleset
                    parsedRuleSet = _miniCssParser.ParseCssPropertyDeclarationList(attrStyleValue.ToCharArray());
                    foreach (WebDom.CssPropertyDeclaration propDecl in parsedRuleSet.GetAssignmentIter())
                    {
                        SpecSetter.AssignPropertyValue(
                            curSpec,
                            parentSpec,
                            propDecl);
                    }
                }
                else
                {
                }
                //----------------------------------------------------------------
                element.IsStyleEvaluated = true;
                element.ElementRuleSet   = parsedRuleSet;
            }
            else
            {
                var elemRuleSet = element.ElementRuleSet;
                if (elemRuleSet != null)
                {
                    if (curSpec.IsFreezed)
                    {
                        curSpec.Defreeze();
                        //var newspec = new BoxSpec();
                        //BoxSpec.CloneAllStyles(newspec, curSpec);
                        //curSpec = newspec;
                        //element.Spec = curSpec;
                    }

                    foreach (WebDom.CssPropertyDeclaration propDecl in elemRuleSet.GetAssignmentIter())
                    {
                        SpecSetter.AssignPropertyValue(
                            curSpec,
                            parentSpec,
                            propDecl);
                    }
                }
            }
            //=====================
            curSpec.Freeze(); //***
            //=====================
        }
Ejemplo n.º 4
0
            void ParseStyle(SvgVisualSpec spec, string cssStyle)
            {
                if (!String.IsNullOrEmpty(cssStyle))
                {
#if DEBUG
                    s_dbugIdCount++;
#endif
                    //***
                    CssRuleSet cssRuleSet = _ownerParser._cssParser.ParseCssPropertyDeclarationList(cssStyle.ToCharArray());

                    foreach (CssPropertyDeclaration propDecl in cssRuleSet.GetAssignmentIter())
                    {
                        switch (propDecl.UnknownRawName)
                        {
                        default:
                            break;

                        case "fill":
                        {
                            int valueCount = propDecl.ValueCount;
                            //1
                            string value = propDecl.GetPropertyValue(0).ToString();
                            if (value != "none")
                            {
                                spec.FillColor = ConvToActualColor(CssValueParser2.GetActualColor(value));
                            }
                        }
                        break;

                        case "fill-opacity":
                        {
                            //TODO:
                            //adjust fill opacity
                        }
                        break;

                        case "stroke-width":
                        {
                            int valueCount = propDecl.ValueCount;
                            //1
                            string value = propDecl.GetPropertyValue(0).ToString();

                            spec.StrokeWidth = UserMapUtil.ParseGenericLength(value);
                        }
                        break;

                        case "stroke":
                        {
                            //TODO:
                            //if (attr.Value != "none")
                            //{
                            //    spec.StrokeColor = ConvToActualColor(CssValueParser2.GetActualColor(attr.Value));
                            //}
                        }
                        break;

                        case "stroke-linecap":
                            //set line-cap and line join again
                            //TODO:
                            break;

                        case "stroke-linejoin":
                            //TODO:
                            break;

                        case "stroke-miterlimit":
                            //TODO:
                            break;

                        case "stroke-opacity":
                            //TODO:
                            break;

                        case "transform":
                        {
                            ////parse trans
                            //ParseTransform(attr.Value, spec);
                        }
                        break;
                        }
                    }
                }
            }