Пример #1
0
        public static float GetActualBorderWidth(string borderValue, CssBox b)
        {
            if (string.IsNullOrEmpty(borderValue))
            {
                return(CssValue.GetActualBorderWidth("medium", b));
            }
            string str  = borderValue;
            string str1 = str;

            if (str != null)
            {
                if (str1 == "thin")
                {
                    return(1f);
                }
                if (str1 == "medium")
                {
                    return(2f);
                }
                if (str1 == "thick")
                {
                    return(4f);
                }
            }
            return(Math.Abs(CssValue.ParseLength(borderValue, 1f, b)));
        }
Пример #2
0
        /// <summary>
        ///     Gets the white space width of the specified box
        /// </summary>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static float WhiteSpace(Graphics g, CssBox b)
        {
            var space   = " .";
            var w       = 0f;
            var onError = 5f;

            var sf = new StringFormat();

            sf.SetMeasurableCharacterRanges(new[] { new CharacterRange(0, 1) });
            var regs = g.MeasureCharacterRanges(space, b.ActualFont,
                                                new RectangleF(0, 0, float.MaxValue, float.MaxValue), sf);

            if (regs == null || regs.Length == 0)
            {
                return(onError);
            }

            w = regs[0].GetBounds(g).Width;

            if (!(string.IsNullOrEmpty(b.WordSpacing) || b.WordSpacing == CssConstants.Normal))
            {
                w += CssValue.ParseLength(b.WordSpacing, 0, b);
            }
            return(w);
        }
Пример #3
0
        public static float WhiteSpace(Graphics g, CssBox b)
        {
            string       str          = " .";
            float        width        = 0f;
            float        single       = 5f;
            StringFormat stringFormat = new StringFormat();

            CharacterRange[] characterRange = new CharacterRange[] { new CharacterRange(0, 1) };
            stringFormat.SetMeasurableCharacterRanges(characterRange);
            Region[] regionArray = g.MeasureCharacterRanges(str, b.ActualFont, new RectangleF(0f, 0f, float.MaxValue, float.MaxValue), stringFormat);
            if (regionArray == null || (int)regionArray.Length == 0)
            {
                return(single);
            }
            width = regionArray[0].GetBounds(g).Width;
            if (!string.IsNullOrEmpty(b.WordSpacing) && !(b.WordSpacing == "normal"))
            {
                width = width + CssValue.ParseLength(b.WordSpacing, 0f, b);
            }
            return(width);
        }
Пример #4
0
 public static float ParseLength(string length, float hundredPercent, CssBox box)
 {
     return(CssValue.ParseLength(length, hundredPercent, box, box.GetEmHeight(), false));
 }