Example #1
0
    /// <summary>
    /// Sets the font manager up with the specified <paramref name="resourcesCollection"/>.
    /// This method will load the font defaults (family and size) and the font files from the
    /// resource collection.
    /// </summary>
    public static void Load(IResourceAccessor resourcesCollection)
    {
      Unload();
      string defaultFontFilePath = resourcesCollection.GetResourceFilePath(
          SkinResources.FONTS_DIRECTORY + Path.DirectorySeparatorChar + DEFAULT_FONT_FILE);

      XPathDocument doc = new XPathDocument(defaultFontFilePath);

      XPathNavigator nav = doc.CreateNavigator();
      nav.MoveToChild(XPathNodeType.Element);
      _defaultFontFamily = nav.GetAttribute("FontFamily", string.Empty);
      string defaultFontSize = nav.GetAttribute("FontSize", string.Empty);
      _defaultFontSize = int.Parse(defaultFontSize);

      // Iterate over font family descriptors
      foreach (string descriptorFilePath in resourcesCollection.GetResourceFilePaths(
          "^" + SkinResources.FONTS_DIRECTORY + "\\\\.*\\.desc$").Values)
      {
        doc = new XPathDocument(descriptorFilePath);
        nav = doc.CreateNavigator();
        nav.MoveToChild(XPathNodeType.Element);
        string familyName = nav.GetAttribute("Name", string.Empty);
        if (string.IsNullOrEmpty(familyName))
          throw new ArgumentException("FontManager: Failed to parse family name for font descriptor file '{0}'", descriptorFilePath);
        string ttfFile = nav.GetAttribute("Ttf", string.Empty);
        if (string.IsNullOrEmpty(ttfFile))
          throw new ArgumentException("FontManager: Failed to parse ttf name for font descriptor file '{0}'", descriptorFilePath);

        string fontFilePath = resourcesCollection.GetResourceFilePath(
            SkinResources.FONTS_DIRECTORY + Path.DirectorySeparatorChar + ttfFile);
        FontFamily family = new FontFamily(familyName, fontFilePath);
        _families[familyName] = family;
      }
    }
Example #2
0
        /// <summary>
        /// Sets the font manager up with the specified <paramref name="resourcesCollection"/>.
        /// This method will load the font defaults (family and size) and the font files from the
        /// resource collection.
        /// </summary>
        public static void Load(IResourceAccessor resourcesCollection)
        {
            Unload();
            string defaultFontFilePath = resourcesCollection.GetResourceFilePath(
                SkinResources.FONTS_DIRECTORY + Path.DirectorySeparatorChar + DEFAULT_FONT_FILE);

            XPathDocument doc = new XPathDocument(defaultFontFilePath);

            XPathNavigator nav = doc.CreateNavigator();

            nav.MoveToChild(XPathNodeType.Element);
            _defaultFontFamily = nav.GetAttribute("FontFamily", string.Empty);
            string defaultFontSize = nav.GetAttribute("FontSize", string.Empty);

            _defaultFontSize = int.Parse(defaultFontSize);

            // Iterate over font family descriptors
            foreach (string descriptorFilePath in resourcesCollection.GetResourceFilePaths(
                         "^" + SkinResources.FONTS_DIRECTORY + "\\\\.*\\.desc$").Values)
            {
                doc = new XPathDocument(descriptorFilePath);
                nav = doc.CreateNavigator();
                nav.MoveToChild(XPathNodeType.Element);
                string familyName = nav.GetAttribute("Name", string.Empty);
                if (string.IsNullOrEmpty(familyName))
                {
                    throw new ArgumentException("FontManager: Failed to parse family name for font descriptor file '{0}'", descriptorFilePath);
                }
                string ttfFile = nav.GetAttribute("Ttf", string.Empty);
                if (string.IsNullOrEmpty(ttfFile))
                {
                    throw new ArgumentException("FontManager: Failed to parse ttf name for font descriptor file '{0}'", descriptorFilePath);
                }

                string fontFilePath = resourcesCollection.GetResourceFilePath(
                    SkinResources.FONTS_DIRECTORY + Path.DirectorySeparatorChar + ttfFile);
                FontFamily family = new FontFamily(familyName, fontFilePath);
                _families[familyName] = family;
            }
        }