Example #1
0
        /// <summary>
        /// Loads a bitmap font from a file containing font data in XML format.
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
        /// <exception cref="FileNotFoundException">Thrown when the requested file is not present.</exception>
        /// <param name="fileName">Name of the file to load.</param>
        /// <returns>
        /// A <see cref="BitmapFont"/> containing the loaded data.
        /// </returns>
        public static BitmapFont LoadFontFromXmlFile(string fileName)
        {
            BitmapFont font;

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(string.Format("Cannot find file '{0}'", fileName), fileName);
            }

            font = new BitmapFont();

            using (Stream stream = File.OpenRead(fileName))
            {
                font.LoadXml(stream);
            }

            QualifyResourcePaths(font, Path.GetDirectoryName(fileName));

            return(font);
        }