Exemplo n.º 1
0
        /// <summary>
        /// Gets the result of collapsing the vertical margins of the two boxes
        /// </summary>
        /// <param name="prevSibling">the previous box under the same parent</param>
        /// <returns>Resulting top margin</returns>
        private float MarginTopCollapse(CssBoxProperties prevSibling)
        {
            float value;

            if (prevSibling != null)
            {
                value = Math.Max(prevSibling.ActualMarginBottom, ActualMarginTop);
                CollapsedMarginTop = value;
            }
            else if (_parentBox != null && ActualPaddingTop < 0.1 && ActualPaddingBottom < 0.1 && _parentBox.ActualPaddingTop < 0.1 && _parentBox.ActualPaddingBottom < 0.1)
            {
                value = Math.Max(0, ActualMarginTop - Math.Max(_parentBox.ActualMarginTop, _parentBox.CollapsedMarginTop));
            }
            else
            {
                value = ActualMarginTop;
            }

            // fix for hr tag
            if (value < 0.1 && HtmlTag != null && HtmlTag.Name == "hr")
            {
                value = GetEmHeight() * 1.1f;
            }

            return(value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses a border value in CSS style; e.g. 1px, 1, thin, thick, medium
        /// </summary>
        /// <param name="borderValue"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static float GetActualBorderWidth(string borderValue, CssBoxProperties b)
        {
            if (string.IsNullOrEmpty(borderValue))
            {
                return GetActualBorderWidth(CssConstants.Medium, b);
            }

            switch (borderValue)
            {
                case CssConstants.Thin:
                    return 1f;
                case CssConstants.Medium:
                    return 2f;
                case CssConstants.Thick:
                    return 4f;
                default:
                    return Math.Abs(ParseLength(borderValue, 1, b));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the white space width of the specified box
 /// </summary>
 /// <param name="g"></param>
 /// <param name="box"></param>
 /// <returns></returns>
 public static float WhiteSpace(IGraphics g, CssBoxProperties box)
 {
     float w = FontsUtils.MeasureWhitespace(g, box.ActualFont);
     if (!(String.IsNullOrEmpty(box.WordSpacing) || box.WordSpacing == CssConstants.Normal))
     {
         w += CssValueParser.ParseLength(box.WordSpacing, 0, box, true);
     }
     return w;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Parses a length. Lengths are followed by an unit identifier (e.g. 10px, 3.1em)
 /// </summary>
 /// <param name="length">Specified length</param>
 /// <param name="hundredPercent">Equivalent to 100 percent when length is percentage</param>
 /// <param name="fontAdjust">if the length is in pixels and the length is font related it needs to use 72/96 factor</param>
 /// <param name="box"></param>
 /// <returns>the parsed length value with adjustments</returns>
 public static float ParseLength(string length, float hundredPercent, CssBoxProperties box, bool fontAdjust = false)
 {
     return ParseLength(length, hundredPercent, box.GetEmHeight(), fontAdjust, false);
 }
 /// <summary>
 /// Get the border width for the given box border.
 /// </summary>
 private static float GetWidth(Border border, CssBoxProperties box)
 {
     switch (border)
     {
         case Border.Top:
             return box.ActualBorderTopWidth;
         case Border.Right:
             return box.ActualBorderRightWidth;
         case Border.Bottom:
             return box.ActualBorderBottomWidth;
         case Border.Left:
             return box.ActualBorderLeftWidth;
         default:
             throw new ArgumentOutOfRangeException("border");
     }
 }
 /// <summary>
 /// Get the border style for the given box border.
 /// </summary>
 private static string GetStyle(Border border, CssBoxProperties box)
 {
     switch (border)
     {
         case Border.Top:
             return box.BorderTopStyle;
         case Border.Right:
             return box.BorderRightStyle;
         case Border.Bottom:
             return box.BorderBottomStyle;
         case Border.Left:
             return box.BorderLeftStyle;
         default:
             throw new ArgumentOutOfRangeException("border");
     }
 }
 /// <summary>
 /// Get the border color for the given box border.
 /// </summary>
 private static Color GetColor(Border border, CssBoxProperties box, string style)
 {
     switch (border)
     {
         case Border.Top:
             return style == CssConstants.Inset ? Darken(box.ActualBorderTopColor) : box.ActualBorderTopColor;
         case Border.Right:
             return style == CssConstants.Outset ? Darken(box.ActualBorderRightColor) : box.ActualBorderRightColor;
         case Border.Bottom:
             return style == CssConstants.Outset ? Darken(box.ActualBorderBottomColor) : box.ActualBorderBottomColor;
         case Border.Left:
             return style == CssConstants.Inset ? Darken(box.ActualBorderLeftColor) : box.ActualBorderLeftColor;
         default:
             throw new ArgumentOutOfRangeException("border");
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Parses a length. Lengths are followed by an unit identifier (e.g. 10px, 3.1em)
 /// </summary>
 /// <param name="length">Specified length</param>
 /// <param name="hundredPercent">Equivalent to 100 percent when length is percentage</param>
 /// <param name="box"></param>
 /// <param name="defaultUnit"></param>
 /// <returns>the parsed length value with adjustments</returns>
 public static float ParseLength(string length, float hundredPercent, CssBoxProperties box, string defaultUnit)
 {
     return ParseLength(length, hundredPercent, box.GetEmHeight(), defaultUnit, false, false);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the result of collapsing the vertical margins of the two boxes
        /// </summary>
        /// <param name="prevSibling">the previous box under the same parent</param>
        /// <returns>Resulting top margin</returns>
        private float MarginTopCollapse(CssBoxProperties prevSibling)
        {
            float value;
            if (prevSibling != null )
            {
                value = Math.Max(prevSibling.ActualMarginBottom, ActualMarginTop);
                CollapsedMarginTop = value;
            }
            else if (_parentBox != null && ActualPaddingTop < 0.1 && ActualPaddingBottom < 0.1 && _parentBox.ActualPaddingTop < 0.1 && _parentBox.ActualPaddingBottom < 0.1)
            {
                value = Math.Max(0, ActualMarginTop - Math.Max(_parentBox.ActualMarginTop, _parentBox.CollapsedMarginTop));
            }
            else
            {
                value = ActualMarginTop;
            }

            // fix for hr tag
            if (value < 0.1 && HtmlTag != null && HtmlTag.Name == "hr")
            {
                value = GetEmHeight() * 1.1f;
            }

            return value;
        }