Exemplo n.º 1
0
        /// <summary>
        /// Convert Html regular font-size to OpenXml font value (expressed in point).
        /// </summary>
        public static Unit ConvertToFontSize(string htmlSize)
        {
            if (htmlSize == null)
            {
                return(Unit.Empty);
            }
            switch (htmlSize.ToLowerInvariant())
            {
            case "1":
            case "xx-small": return(new Unit(UnitMetric.Point, 10));

            case "2":
            case "x-small": return(new Unit(UnitMetric.Point, 15));

            case "3":
            case "small": return(new Unit(UnitMetric.Point, 20));

            case "4":
            case "medium": return(new Unit(UnitMetric.Point, 27));

            case "5":
            case "large": return(new Unit(UnitMetric.Point, 36));

            case "6":
            case "x-large": return(new Unit(UnitMetric.Point, 48));

            case "7":
            case "xx-large": return(new Unit(UnitMetric.Point, 72));

            default:
                // the font-size is specified in positive half-points
                Unit unit = Unit.Parse(htmlSize);
                if (!unit.IsValid || unit.Value <= 0)
                {
                    return(Unit.Empty);
                }

                // this is a rough conversion to support some percent size, considering 100% = 11 pt
                if (unit.Type == UnitMetric.Percent)
                {
                    unit = new Unit(UnitMetric.Point, unit.Value * 0.11);
                }
                return(unit);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse the margin style attribute.
        /// </summary>
        /// <remarks>
        /// The margin property can have from one to four values.
        /// <b>margin:25px 50px 75px 100px;</b>
        /// top margin is 25px
        /// right margin is 50px
        /// bottom margin is 75px
        /// left margin is 100px
        ///
        /// <b>margin:25px 50px 75px;</b>
        /// top margin is 25px
        /// right and left margins are 50px
        /// bottom margin is 75px
        ///
        /// <b>margin:25px 50px;</b>
        /// top and bottom margins are 25px
        /// right and left margins are 50px
        ///
        /// <b>margin:25px;</b>
        /// all four margins are 25px
        /// </remarks>
        public static Margin Parse(String str)
        {
            if (str == null)
            {
                return(new Margin());
            }

            String[] parts = str.Split(HttpUtility.WhiteSpaces);
            switch (parts.Length)
            {
            case 1:
            {
                Unit all = Unit.Parse(parts[0]);
                return(new Margin(all, all, all, all));
            }

            case 2:
            {
                Unit u1 = Unit.Parse(parts[0]);
                Unit u2 = Unit.Parse(parts[1]);
                return(new Margin(u1, u2, u1, u2));
            }

            case 3:
            {
                Unit u1 = Unit.Parse(parts[0]);
                Unit u2 = Unit.Parse(parts[1]);
                Unit u3 = Unit.Parse(parts[2]);
                return(new Margin(u1, u2, u3, u2));
            }

            case 4:
            {
                Unit u1 = Unit.Parse(parts[0]);
                Unit u2 = Unit.Parse(parts[1]);
                Unit u3 = Unit.Parse(parts[2]);
                Unit u4 = Unit.Parse(parts[3]);
                return(new Margin(u1, u2, u3, u4));
            }
            }

            return(new Margin());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets an attribute representing an unit: 120px, 10pt, 5em, 20%, ...
 /// </summary>
 /// <returns>If the attribute is misformed, the <see cref="Unit.IsValid"/> property is set to false.</returns>
 public Unit GetAsUnit(String name)
 {
     return(Unit.Parse(this[name]));
 }