/// <summary> /// Creates a TrueTypeFont from XML. /// </summary> /// <param name="xElement">An XElement that contains the XML representation of the TrueTypeFont.</param> /// <param name="system">The MiyagiSystem.</param> /// <returns> /// The newly created TrueTypeFont or null if the XML file is invalid. /// </returns> public static TrueTypeFont CreateFromXml(XElement xElement, MiyagiSystem system) { TrueTypeFont retValue; var xv = new XmlValidator(); if (xv.ValidateAgainstInternalSchema(xElement, "TrueTypeFont")) { // create the TrueTypeFont using the Name attribute retValue = new TrueTypeFont(xElement.Attribute("Name").Value) { FileName = (string)xElement.Element("FileName"), FontStyle = xElement.Element("FontStyle").Value.ParseEnum <SD.FontStyle>(), Resolution = (int)xElement.Element("Resolution"), Size = (int)xElement.Element("Size"), TabSize = xElement.Element("TabSize") != null ? (int)xElement.Element("TabSize") : 3, Tracking = xElement.Element("Tracking") != null ? (int)xElement.Element("Tracking") : 0, }; var leading = xElement.Element("Leading"); if (leading != null) { retValue.Leading = (int)leading; } var spaceWidth = xElement.Element("SpaceWidth"); if (spaceWidth != null) { retValue.SpaceWidth = (int)spaceWidth; } // get CodePoints IList <Range> codePoints; if (xElement.Element("CodePoints") == null) { codePoints = DefaultCodePoints; } else { codePoints = new List <Range>( from codePointNode in xElement.Descendants("CodePoint") let codePoint = new Range( (int)codePointNode.Element("First"), (int)codePointNode.Element("Last")) select codePoint); } retValue.codePoints = codePoints; CreateFont(system, retValue); } else { throw new XmlException("Invalid font XElement"); } return(retValue); }
/// <summary> /// Creates a Skin from XML. /// </summary> /// <param name="xElement">An XElement that contains the XML representation of the Skin.</param> /// <param name="system">The MiyagiSystem.</param> /// <returns> /// The newly created Skin or null if the XML file is invalid. /// </returns> public static Skin CreateFromXml(XElement xElement, MiyagiSystem system) { Skin retValue = null; var xv = new XmlValidator(); if (xv.ValidateAgainstInternalSchema(xElement, "Skin")) { // create the skin using the Name attribute retValue = new Skin(xElement.Attribute("Name").Value) { SubSkins = new TextureCollection( from subSkinNode in xElement.Descendants("SubSkin") select new KeyValuePair <string, Texture>( subSkinNode.Attribute("Name").Value, Texture.CreateFromXml(subSkinNode, system))) }; } return(retValue); }
/// <summary> /// Creates a ImageFont from XML. /// </summary> /// <param name="xElement">An XElement that contains the XML representation of the ImageFont.</param> /// <param name="system">The MiyagiSystem.</param> /// <returns>The newly created ImageFont or null if the XML file is invalid.</returns> public static ImageFont CreateFromXml(XElement xElement, MiyagiSystem system) { ImageFont retValue = null; var xv = new XmlValidator(); if (xv.ValidateAgainstInternalSchema(xElement, "ImageFont")) { // create the ImageFont using the Name attribute retValue = new ImageFont(xElement.Attribute("Name").Value) { FileName = (string)xElement.Element("FileName"), TabSize = xElement.Element("TabSize") != null ? (int)xElement.Element("TabSize") : 3, Tracking = xElement.Element("Tracking") != null ? (int)xElement.Element("Tracking") : 0, GlyphCoordinates = GetGlyphCoordinates(xElement) }; var leading = xElement.Element("Leading"); if (leading != null) { retValue.Leading = (int)leading; } var spaceWidth = xElement.Element("SpaceWidth"); if (leading != null) { retValue.SpaceWidth = (int)spaceWidth; } retValue.CreateFont(system); } else { throw new XmlException("Invalid font XElement"); } return(retValue); }