//============================================================= /// <summary> /// recalculate margin /// </summary> /// <param name="margin">marin side</param> /// <param name="cbWidth">width of containging block</param> /// <returns></returns> float RecalculateMargin(CssLength margin, float cbWidth) { //www.w3.org/TR/CSS2/box.html#margin-properties if (margin.IsAuto) { return(0); } return(CssLengthExt.ConvertToPx(margin, cbWidth, this)); }
/// <summary> /// recalculate padding /// </summary> /// <param name="padding"></param> /// <param name="cbWidth"></param> /// <returns></returns> float RecalculatePadding(CssLength padding, float cbWidth) { //www.w3.org/TR/CSS2/box.html#padding-properties if (padding.IsAuto) { return(0); } return(CssLengthExt.ConvertToPx(padding, cbWidth, this)); }
public void ReEvaluateFont(IHtmlTextService txtsx, float parentFontSize) { _resolvedFont1 = txtsx.ResolveFont(_reqFont = _myspec.GetFont(parentFontSize)); if (_myspec.WordSpacing.IsNormalWordSpacing) { //use normal spacing _actualWordSpacing = _resolvedFont1.WhitespaceWidth;//use pre-rounding (int) or exact scaled value ??? } else { //TODO: review here,*** //additional to original whitespacing or REPLACE with the new value _actualWordSpacing = _resolvedFont1.WhitespaceWidth +//use pre-rounding (int) or exact scaled value ??? CssLengthExt.ConvertToPx(_myspec.WordSpacing, 1, this); } }
/// <summary> /// evaluate computed value /// </summary> internal void ReEvaluateComputedValues(IHtmlTextService iFonts, CssBox containingBlock) { //depend on parent //1. fonts if (this.ParentBox != null) { if (this.ParentBox.ResolvedFont == null) { //TODO: review this ... WHY? //SIZE in point unit or pixel??? ReEvaluateFont(iFonts, containingBlock._resolvedFont1.SizeInPoints); } else { ReEvaluateFont(iFonts, this.ParentBox._resolvedFont1.SizeInPoints); } //2. actual word spacing //_actualWordSpacing = this.NoEms(this.InitSpec.LineHeight); //3. font size //len = len.ConvertEmToPoints(parentBox.ActualFont.SizeInPoints); } else { ReEvaluateFont(iFonts, containingBlock._resolvedFont1.SizeInPoints); //_actualFont = this.Spec.GetFont(containingBlock.Spec); } //----------------------------------------------------------------------- float cbWidth = containingBlock.VisualWidth; int tmpBoxCompactFlags = _boxCompactFlags; _boxCompactFlags |= BoxFlags.LAY_EVAL_COMPUTE_VALUES; //www.w3.org/TR/CSS2/box.html#margin-properties //w3c: margin applies to all elements except elements table display type //other than table-caption,table and inline table CssDisplay cssDisplay = this.CssDisplay; BoxSpec spec = _myspec; switch (cssDisplay) { case CssDisplay.None: { return; } case CssDisplay.TableCell: case CssDisplay.TableColumn: case CssDisplay.TableColumnGroup: case CssDisplay.TableFooterGroup: case CssDisplay.TableHeaderGroup: case CssDisplay.TableRow: case CssDisplay.TableRowGroup: { //no margin } break; default: { //if (__aa_dbugId == 5) //{ // int a = spec.__aa_dbugId; //} _actualMarginLeft = RecalculateMargin(spec.MarginLeft, cbWidth); _actualMarginTop = RecalculateMargin(spec.MarginTop, cbWidth); _actualMarginRight = RecalculateMargin(spec.MarginRight, cbWidth); _actualMarginBottom = RecalculateMargin(spec.MarginBottom, cbWidth); } break; } //www.w3.org/TR/CSS2/box.html#padding-properties switch (cssDisplay) { case CssDisplay.TableRowGroup: case CssDisplay.TableHeaderGroup: case CssDisplay.TableFooterGroup: case CssDisplay.TableRow: case CssDisplay.TableColumnGroup: case CssDisplay.TableColumn: { //no padding } break; default: { //----------------------------------------------------------------------- //padding _actualPaddingLeft = RecalculatePadding(spec.PaddingLeft, cbWidth); _actualPaddingTop = RecalculatePadding(spec.PaddingTop, cbWidth); _actualPaddingRight = RecalculatePadding(spec.PaddingRight, cbWidth); _actualPaddingBottom = RecalculatePadding(spec.PaddingBottom, cbWidth); } break; } //----------------------------------------------------------------------- //borders float a1, a2, a3, a4; _actualBorderLeftWidth = a1 = (spec.BorderLeftStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderLeftWidth, this); _actualBorderTopWidth = a2 = (spec.BorderTopStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderTopWidth, this); _actualBorderRightWidth = a3 = (spec.BorderRightStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderRightWidth, this); _actualBorderBottomWidth = a4 = (spec.BorderBottomStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderBottomWidth, this); //--------------------------------------------------------------------------- _borderLeftVisible = a1 > 0 && spec.BorderLeftStyle >= CssBorderStyle.Visible; _borderTopVisible = a2 > 0 && spec.BorderTopStyle >= CssBorderStyle.Visible; _borderRightVisible = a3 > 0 && spec.BorderRightStyle >= CssBorderStyle.Visible; _borderBottomVisble = a4 > 0 && spec.BorderBottomStyle >= CssBorderStyle.Visible; //extension *** if (a1 + a2 + a3 + a4 > 0) { //css 2.1 border can't be nagative values tmpBoxCompactFlags |= BoxFlags.HAS_SOME_VISIBLE_BORDER; } else { tmpBoxCompactFlags &= ~BoxFlags.HAS_SOME_VISIBLE_BORDER; } //--------------------------------------------------------------------------- _actualCornerNE = a1 = CssLengthExt.ConvertToPx(spec.CornerNERadius, 0, this); _actualCornerNW = a2 = CssLengthExt.ConvertToPx(spec.CornerNWRadius, 0, this); _actualCornerSE = a3 = CssLengthExt.ConvertToPx(spec.CornerSERadius, 0, this); _actualCornerSW = a4 = CssLengthExt.ConvertToPx(spec.CornerSWRadius, 0, this); if ((a1 + a2 + a3 + a4) > 0) { //evaluate tmpBoxCompactFlags |= BoxFlags.HAS_ROUND_CORNER; } else { tmpBoxCompactFlags &= ~BoxFlags.HAS_ROUND_CORNER; } //--------------------------------------------------------------------------- //evaluate bg if (BackgroundGradient != Color.Transparent || (ActualBackgroundColor.A > 0)) { tmpBoxCompactFlags |= BoxFlags.HAS_VISIBLE_BG; } else { tmpBoxCompactFlags &= ~BoxFlags.HAS_VISIBLE_BG; } if (spec.WordSpacing.IsNormalWordSpacing) { _actualWordSpacing = iFonts.MeasureWhitespace(_reqFont); } else { _actualWordSpacing = iFonts.MeasureWhitespace(_reqFont) + CssLengthExt.ConvertToPx(spec.WordSpacing, 1, this); } //---------------------------------------------- _boxCompactFlags = tmpBoxCompactFlags; //---------------------------------------------- //text indent _actualTextIndent = CssLengthExt.ConvertToPx(spec.TextIndent, containingBlock.VisualWidth, this); _actualBorderSpacingHorizontal = spec.BorderSpacingHorizontal.Number; _actualBorderSpacingVertical = spec.BorderSpacingVertical.Number; //----------------------- //_actualLineHeight = 0.9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this); //expected width expected height //_expectedWidth = CssValueParser.ParseLength(Width, cbWidth, this); //_expectedHight = CssValueParser.ParseLength(Height, containingBlock.SizeHeight, this); ////---------------------------------------------- //www.w3.org/TR/CSS2/visudet.html#line-height //line height, //percent value of line height : // is refer to font size of the element itself //if (this.LineHeight.Number > 0) //{ // _actualLineHeight = .9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this); //} //else //{ // _actualLineHeight = .9f * (this.GetEmHeight()); //} if (_myspec.HasBoxShadow) { //temp fix here //TODO: review move shadow to external decoration object/box if (_decorator == null) { _decorator = new CssBoxDecorator(); } _decorator.HBoxShadowOffset = (int)CssLengthExt.ConvertToPx(spec.BoxShadowHOffset, 0, this); _decorator.VBoxShadowOffset = (int)CssLengthExt.ConvertToPx(spec.BoxShadowVOffset, 0, this); _decorator.Color = spec.BoxShadowColor; } else { _decorator = null; } }