Example #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);

        }
Example #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;
        }
Example #3
0
 public void AddAll(Properties col) {
     foreach (string itm in col.Keys) {
         _col[itm] = col[itm];
     }
 }
        /**
         * Retrieves the fake font details for a given font.
         * @param font  the font to lookup.
         * @return  the fake font.
         */
        public static FontDetails GetFontDetails(Font font)
        {
            // If we haven't alReady identified out font metrics file,
            //  figure out which one to use and Load it
            if (fontMetricsProps == null)
            {
                Stream metricsIn = null;
                try
                {
                    fontMetricsProps = new Properties();

                    // Check to see if the font metric file was specified
                    //  as a system property
                    String propFileName = null;
                    try
                    {
                        propFileName = ConfigurationSettings.AppSettings["font.metrics.filename"];
                    }
                    catch(Exception e) { }

                    if (propFileName != null)
                    {
                        
                        if (!File.Exists(propFileName))
                            throw new FileNotFoundException("font_metrics.properties not found at path " + Path.GetFullPath(propFileName));
                        metricsIn = new MemoryStream(Resource1.font_metrics);
                    }
                    else
                    {
                        // Use the built-in font metrics file off the classpath
                        metricsIn = new MemoryStream(Resource1.font_metrics);
                        if (metricsIn == null)
                            throw new FileNotFoundException("font_metrics.properties not found in classpath");
                    }
                    fontMetricsProps.Load(metricsIn);
                }
                catch (IOException e)
                {
                    throw new Exception("Could not Load font metrics: " + e.Message);
                }
                finally
                {
                    if (metricsIn != null)
                    {
                        try
                        {
                            metricsIn.Close();
                        }
                        catch (IOException)
                        {
                        
                        }
                    }
                }
            }

            // Grab the base name of the font they've asked about
            String fontName = font.FontFamily.Name;

            // Some fonts support plain/bold/italic/bolditalic variants
            // Others have different font instances for bold etc
            // (eg font.dialog.plain.* vs font.Californian FB Bold.*)
            String fontStyle = "";
            //if(font.IsPlain())  fontStyle += "plain";
            if (font.Bold) fontStyle += "bold";
            if (font.Italic) fontStyle += "italic";

            // Do we have a definition for this font with just the name?
            // If not, Check with the font style Added
            if (fontMetricsProps[FontDetails.BuildFontHeightProperty(fontName)] == null &&
            fontMetricsProps[FontDetails.BuildFontHeightProperty(fontName + "." + fontStyle)] != null)
            {
                // Need to Add on the style to the font name
                fontName += "." + fontStyle;
            }

            // Get the details on this font
            if (fontDetailsMap[fontName] == null)
            {
                FontDetails fontDetails = FontDetails.Create(fontName, fontMetricsProps);
                fontDetailsMap[fontName]= fontDetails;
                return fontDetails;
            }
            else
            {
                return (FontDetails)fontDetailsMap[fontName];
            }

        }