Esempio n. 1
0
        public void SetUp()
        {
            properties = new Properties();
            properties.Add("font.Arial.height", "13");
            properties.Add("font.Arial.characters", "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ");
            properties.Add("font.Arial.widths", "6, 6, 6, 6, 6, 3, 6, 6, 3, 4, 6, 3, 9, 6, 6, 6, 6, 4, 6, 3, 6, 7, 9, 6, 5, 5, 7, 7, 7, 7, 7, 6, 8, 7, 3, 6, 7, 6, 9, 7, 8, 7, 8, 7, 7, 5, 7, 7, 9, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, ");
            fontDetails = FontDetails.Create("Arial", properties);

        }
Esempio n. 2
0
        /// <summary>
        /// Create an instance of 
        /// <c>FontDetails</c>
        ///  by loading them from the
        /// provided property object.
        /// </summary>
        /// <param name="fontName">the font name.</param>
        /// <param name="fontMetricsProps">the property object holding the details of this
        /// particular font.</param>
        /// <returns>a new FontDetails instance.</returns>
        public static FontDetails Create(String fontName, Properties fontMetricsProps)
        {
            String heightStr = fontMetricsProps[BuildFontHeightProperty(fontName)];
            String widthsStr = fontMetricsProps[BuildFontWidthsProperty(fontName)];
            String CharsStr = fontMetricsProps[BuildFontCharsProperty(fontName)];

            // Ensure that this Is a font we know about
            if (heightStr == null || widthsStr == null || CharsStr == null)
            {
                // We don't know all we need to about this font
                // Since we don't know its sizes, we can't work with it
                throw new ArgumentException("The supplied FontMetrics doesn't know about the font '" + fontName + "', so we can't use it. Please Add it to your font metrics file (see StaticFontMetrics.GetFontDetails");
            }

            int height = int.Parse(heightStr);
            FontDetails d = new FontDetails(fontName, height);
            String[] CharsStrArray = Split(CharsStr, ",", -1);
            String[] widthsStrArray = Split(widthsStr, ",", -1);
            if (CharsStrArray.Length != widthsStrArray.Length)
                throw new Exception("Number of Chars does not number of widths for font " + fontName);
            for (int i = 0; i < widthsStrArray.Length; i++)
            {
                if (CharsStrArray[i].Trim().Length != 0)
                    d.AddChar(CharsStrArray[i].Trim()[0], int.Parse(widthsStrArray[i]));
            }
            return d;
        }