/// <summary> /// Creates a new Font for an image font. /// </summary> /// <param name="system">The MiyagiSystem.</param> /// <param name="name">The name of the ImageFont.</param> /// <param name="fontFileName">The filename of the ImageFont.</param> /// <param name="glyphCoordinates">The glyph coordinates of the ImageFont.</param> /// <returns>The newly created ImageFont.</returns> public static ImageFont Create(MiyagiSystem system, string name, string fontFileName, IDictionary <char, RectangleF> glyphCoordinates) { ImageFont retValue = new ImageFont(name) { FileName = fontFileName, GlyphCoordinates = glyphCoordinates }; retValue.CreateFont(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); }