/// <summary>
        ///     Parses text formatting.
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        private PowerPraiseSongFormatting.FontFormatting ParseTextFormatting(XmlElement elem,
                                                                             PowerPraiseSongFormatting.FontFormatting defaultValue)
        {
            var f = defaultValue;

            if (elem != null)
            {
                // Parse font
                var nameElement   = elem["name"];
                var sizeElement   = elem["size"];
                var boldElement   = elem["bold"];
                var italicElement = elem["italic"];
                if (nameElement != null && sizeElement != null && boldElement != null && italicElement != null)
                {
                    int fontSize;
                    int.TryParse(sizeElement.InnerText, out fontSize);
                    f.Font = new Font(
                        nameElement.InnerText,
                        fontSize > 0 ? fontSize : f.Font.Size,
                        (FontStyle)
                        ((int)(boldElement.InnerText == "true" ? FontStyle.Bold : FontStyle.Regular) +
                         (int)(italicElement.InnerText == "true" ? FontStyle.Italic : FontStyle.Regular))
                        );
                }

                // Parse color
                var colorElement = elem["color"];
                int colorNumber;
                if (colorElement != null && int.TryParse(colorElement.InnerText, out colorNumber))
                {
                    f.Color = PowerPraiseFileUtil.ConvertColor(colorNumber);
                }

                // Parse outline width
                var outlineElement = elem["outline"];
                int outlineSize;
                if (outlineElement != null && int.TryParse(outlineElement.InnerText, out outlineSize))
                {
                    f.OutlineWidth = outlineSize;
                }

                // Parse shadow width
                var shadowElement = elem["shadow"];
                int shadowDistance;
                if (shadowElement != null && int.TryParse(shadowElement.InnerText, out shadowDistance))
                {
                    f.ShadowDistance = shadowDistance;
                }
            }
            return(f);
        }
示例#2
0
 private void ApplyFormatting(XmlDocument xmlDoc, XmlElement elem, string key,
                              PowerPraiseSongFormatting.FontFormatting f)
 {
     elem.AppendChild(xmlDoc.CreateElement(key));
     elem[key].AppendChild(xmlDoc.CreateElement("name"));
     elem[key]["name"].InnerText = f.Font.Name;
     elem[key].AppendChild(xmlDoc.CreateElement("size"));
     elem[key]["size"].InnerText = ((int)f.Font.Size).ToString();
     elem[key].AppendChild(xmlDoc.CreateElement("bold"));
     elem[key]["bold"].InnerText = (f.Font.Bold).ToString().ToLower();
     elem[key].AppendChild(xmlDoc.CreateElement("italic"));
     elem[key]["italic"].InnerText = (f.Font.Italic).ToString().ToLower();
     elem[key].AppendChild(xmlDoc.CreateElement("color"));
     elem[key]["color"].InnerText = PowerPraiseFileUtil.ConvertColor(f.Color).ToString();
     elem[key].AppendChild(xmlDoc.CreateElement("outline"));
     elem[key]["outline"].InnerText = f.OutlineWidth.ToString();
     elem[key].AppendChild(xmlDoc.CreateElement("shadow"));
     elem[key]["shadow"].InnerText = f.ShadowDistance.ToString();
 }