Ejemplo n.º 1
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 double 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));
            }
        }
Ejemplo n.º 2
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>
        protected double MarginTopCollapse(CssBoxProperties prevSibling)
        {
            double 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;
        }
Ejemplo n.º 3
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 double ParseLength(string length, double hundredPercent, CssBoxProperties box, string defaultUnit)
 {
     return ParseLength(length, hundredPercent, box.GetEmHeight(), defaultUnit, false, false);
 }
Ejemplo 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 double ParseLength(string length, double hundredPercent, CssBoxProperties box, bool fontAdjust = false)
 {
     return ParseLength(length, hundredPercent, box.GetEmHeight(), null, fontAdjust, false);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Get the border width for the given box border.
 /// </summary>
 private static double 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");
     }
 }
Ejemplo n.º 6
0
 /// <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");
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Get the border color for the given box border.
 /// </summary>
 private static RColor 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");
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the white space width of the specified box
 /// </summary>
 /// <param name="g"></param>
 /// <param name="box"></param>
 /// <returns></returns>
 public static double WhiteSpace(RGraphics g, CssBoxProperties box)
 {
     double w = box.ActualFont.GetWhitespaceWidth(g);
     if (!(String.IsNullOrEmpty(box.WordSpacing) || box.WordSpacing == CssConstants.Normal))
     {
         w += CssValueParser.ParseLength(box.WordSpacing, 0, box, true);
     }
     return w;
 }