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()); }
private static CssLength TranslateLength(CssLength len) { if (len.HasError) { //if unknown unit number return(CssLength.MakePixelLength(len.Number)); } return(len); }
/// <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); }
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))); }