Пример #1
0
        public static CssLength AsLength(this WebDom.CssCodeValueExpression value)
        {
            if (value.EvaluatedAs != WebDom.CssValueEvaluatedAs.Length)
            {
                //length from number
                switch (value.Hint)
                {
                case WebDom.CssValueHint.Number:
                {
                    if (value is WebDom.CssCodePrimitiveExpression)
                    {
                        WebDom.CssCodePrimitiveExpression prim = (WebDom.CssCodePrimitiveExpression)value;
                        CssLength len = new CssLength(value.AsNumber(), GetCssUnit(prim.Unit));
                        value.SetCssLength(len, WebDom.CssValueEvaluatedAs.Length);
                        return(len);
                    }
                    else
                    {
                        CssLength len = CssLength.MakePixelLength(value.AsNumber());
                        value.SetCssLength(len, WebDom.CssValueEvaluatedAs.Length);
                        return(len);
                    }
                }

                default:
                {
                    CssLength len = TranslateLength(value.ToString());
                    value.SetCssLength(len, WebDom.CssValueEvaluatedAs.Length);
                    return(len);
                }
                }
            }
            return(value.GetCacheCssLength());
        }
Пример #2
0
 private static CssLength TranslateLength(CssLength len)
 {
     if (len.HasError)
     {
         //if unknown unit number
         return(CssLength.MakePixelLength(len.Number));
     }
     return(len);
 }
Пример #3
0
        /// <summary>
        /// Converts an HTML length into a Css length
        /// </summary>
        /// <param name="htmlLength"></param>
        /// <returns></returns>
        public static CssLength TranslateLength(string htmlLength)
        {
            CssLength len = ParseGenericLength(htmlLength);

            if (len.HasError)
            {
                return(CssLength.MakePixelLength(0));
            }
            return(len);
        }
Пример #4
0
        static CssLength SetLineHeight(this CssBox box, CssLength len)
        {
            //2014,2015,
            //from www.w3c.org/wiki/Css/Properties/line-height

            //line height in <percentage> :
            //The computed value if the property is percentage multiplied by the
            //element's computed font size.
            return(CssLength.MakePixelLength(
                       CssValueParser.ConvertToPx(len, box.GetEmHeight(), box)));
        }