AODL.Document.TextDocuments.TextDocument.AddFont C# (CSharp) Method

AddFont() private method

Adds a font to the document. All fonts that you use within your text must be added to the document. The class FontFamilies represent all available fonts.
private AddFont ( string fontname ) : void
fontname string The fontname take it from class FontFamilies.
return void
		private void AddFont(string fontname)
		{
			try
			{
				Assembly ass		= Assembly.GetExecutingAssembly();
				Stream stream		= ass.GetManifestResourceStream("AODL.Resources.OD.fonts.xml");

				XmlDocument fontdoc	= new XmlDocument();
				fontdoc.Load(stream);

				XmlNode exfontnode	= this.XmlDoc.SelectSingleNode(
					"/office:document-content/office:font-face-decls/style:font-face[@style:name='"+fontname+"']", this.NamespaceManager);

				if (exfontnode != null)
					return; //Font exist;

				XmlNode newfontnode	= fontdoc.SelectSingleNode(
					"/office:document-content/office:font-face-decls/style:font-face[@style:name='"+fontname+"']", this.NamespaceManager);

				if (newfontnode != null)
				{
					XmlNode fontsnode	= this.XmlDoc.SelectSingleNode(
						"/office:document-content", this.NamespaceManager);
					if (fontsnode != null)
					{
						foreach(XmlNode xn in fontsnode)
							if (xn.Name == "office:font-face-decls")
						{
							XmlNode node		= this.CreateNode("font-face", "style");
							foreach(XmlAttribute xa in newfontnode.Attributes)
							{
								XmlAttribute xanew	= this.CreateAttribute(xa.LocalName, xa.Prefix);
								xanew.Value			= xa.Value;
								node.Attributes.Append(xanew);
							}
							xn.AppendChild(node);
							break;
						}
					}
				}
			}
			catch(Exception)
			{
				//Should never happen
				throw;
			}
		}