示例#1
0
        public void SetPercentSizes()
        {
            if (this.RuleSet.Rules != null)
            {
                foreach (Rule rule in this.RuleSet.Rules)
                {
                    if (rule.ComputedValue != null)
                    {
                        float value = -1f;

                        if (rule.ComputedValue.Unit == Unit.Percent)
                        {
                            value = CSSUnitsConverter.PercentToPx(rule, this);
                        }
                        else if (rule.ComputedValue.Unit == Unit.CalcFunc)
                        {
                            value = CSSCalcFunction.Calculate(rule, this);
                        }

                        if (value != -1f)
                        {
                            if (rule.Property == "width")
                            {
                                this.ComputedStyle.Size.Width = value;
                            }
                            else if (rule.Property == "height")
                            {
                                this.ComputedStyle.Size.Height = value;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public static float ConvertAnyUnitToPixels(Rule rule, DOMElement element)
        {
            CSSValue cssValue = rule.ComputedValue;

            if (cssValue.Unit == Unit.Px)
            {
                return(cssValue.Value);
            }
            else if (cssValue.Unit == Unit.Cm)
            {
                return(CSSUnitsConverter.CmToPX(cssValue.Value));
            }
            else if (cssValue.Unit == Unit.Mm)
            {
                return(CSSUnitsConverter.MmToPX(cssValue.Value));
            }
            else if (cssValue.Unit == Unit.In)
            {
                return(CSSUnitsConverter.InToPX(cssValue.Value));
            }
            else if (cssValue.Unit == Unit.Percent)
            {
                return(CSSUnitsConverter.PercentToPx(rule, element));
            }
            else if (cssValue.Unit == Unit.Pt)
            {
                return(CSSUnitsConverter.PtToPX(cssValue.Value));
            }
            else if (cssValue.Unit == Unit.Em)
            {
                return(CSSUnitsConverter.EmToPx(rule, element));
            }
            else if (cssValue.Unit == Unit.Vh)
            {
                return(CSSUnitsConverter.VhToPx(rule, element));
            }
            else if (cssValue.Unit == Unit.Vw)
            {
                return(CSSUnitsConverter.VwToPx(rule, element));
            }

            return(-1f);
        }