AODL.Document.Content.Text.Paragraph.GetHtmlStyleFromGlobalStyles C# (CSharp) Method

GetHtmlStyleFromGlobalStyles() private method

Gets the HTML style from global styles. This isn't supported by AODL yet. But if OpenDocument text documents are loaded, this could be.
private GetHtmlStyleFromGlobalStyles ( ) : string
return string
		private string GetHtmlStyleFromGlobalStyles()
		{
			try
			{
				string style		= "style=\"";

				if (this.Document is AODL.Document.TextDocuments.TextDocument)
				{
					XmlNode styleNode	= ((AODL.Document.TextDocuments.TextDocument)this.Document).DocumentStyles.Styles.SelectSingleNode(
						"//office:styles/style:style[@style:name='"+this.StyleName+"']", this.Document.NamespaceManager);

					if (styleNode == null)
						styleNode	= ((AODL.Document.TextDocuments.TextDocument)this.Document).DocumentStyles.Styles.SelectSingleNode(
							"//office:styles/style:style[@style:name='"+((ParagraphStyle)this.Style).ParentStyle+"']", this.Document.NamespaceManager);

					if (styleNode != null)
					{
						XmlNode paraPropNode	= styleNode.SelectSingleNode("style:paragraph-properties",
							this.Document.NamespaceManager);

						//Last change via parent style
						XmlNode parentNode	= styleNode.SelectSingleNode("@style:parent-style-name",
							this.Document.NamespaceManager);

						XmlNode paraPropNodeP	= null;
						XmlNode parentStyleNode	= null;
						if (parentNode != null)
							if (parentNode.InnerText != null)
							{
								//Console.WriteLine("Parent-Style-Name: {0}", parentNode.InnerText);
								parentStyleNode	= ((AODL.Document.TextDocuments.TextDocument)this.Document).DocumentStyles.Styles.SelectSingleNode(
									"//office:styles/style:style[@style:name='"+parentNode.InnerText+"']", this.Document.NamespaceManager);
							
								if (parentStyleNode != null)
									paraPropNodeP	= parentStyleNode.SelectSingleNode("style:paragraph-properties",
										this.Document.NamespaceManager);
							}
					

						//Check first parent style paragraph properties
						if (paraPropNodeP != null)
						{
							//Console.WriteLine("ParentStyleNode: {0}", parentStyleNode.OuterXml);
							string alignMent	= this.GetGlobalStyleElement(paraPropNodeP, "@fo:text-align");
							if (alignMent != null)
							{ 
								alignMent	= alignMent.ToLower().Replace("end", "right");
								if (alignMent.ToLower() == "center" || alignMent.ToLower() == "right")
									style	+= "text-align: "+alignMent+"; ";
							}

							string lineSpace	= this.GetGlobalStyleElement(paraPropNodeP, "@fo:line-height");
							if (lineSpace != null)
								style	+= "line-height: "+lineSpace+"; ";

							string marginTop	= this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-top");
							if (marginTop != null)
								style	+= "margin-top: "+marginTop+"; ";

							string marginBottom	= this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-bottom");
							if (marginBottom != null)
								style	+= "margin-bottom: "+marginBottom+"; ";

							string marginLeft	= this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-left");
							if (marginLeft != null)
								style	+= "margin-left: "+marginLeft+"; ";

							string marginRight	= this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-right");
							if (marginRight != null)
								style	+= "margin-right: "+marginRight+"; ";
						}
						//Check paragraph properties, maybe parents style is overwritten or extended
						if (paraPropNode != null)
						{
							string alignMent	= this.GetGlobalStyleElement(paraPropNode, "@fo:text-align");
							if (alignMent != null)
							{ 
								alignMent	= alignMent.ToLower().Replace("end", "right");
								if (alignMent.ToLower() == "center" || alignMent.ToLower() == "right")
									style	+= "text-align: "+alignMent+"; ";
							}

							string lineSpace	= this.GetGlobalStyleElement(paraPropNode, "@fo:line-height");
							if (lineSpace != null)
								style	+= "line-height: "+lineSpace+"; ";

							string marginTop	= this.GetGlobalStyleElement(paraPropNode, "@fo:margin-top");
							if (marginTop != null)
								style	+= "margin-top: "+marginTop+"; ";

							string marginBottom	= this.GetGlobalStyleElement(paraPropNode, "@fo:margin-bottom");
							if (marginBottom != null)
								style	+= "margin-bottom: "+marginBottom+"; ";

							string marginLeft	= this.GetGlobalStyleElement(paraPropNode, "@fo:margin-left");
							if (marginLeft != null)
								style	+= "margin-left: "+marginLeft+"; ";

							string marginRight	= this.GetGlobalStyleElement(paraPropNode, "@fo:margin-right");
							if (marginRight != null)
								style	+= "margin-right: "+marginRight+"; ";
						}

						XmlNode textPropNode	= styleNode.SelectSingleNode("style:text-properties",
							this.Document.NamespaceManager);

						XmlNode textPropNodeP	= null;
						if (parentStyleNode != null)
							textPropNodeP		= parentStyleNode.SelectSingleNode("style:text-properties",
								this.Document.NamespaceManager);

						//Check first text properties of parent style
						if (textPropNodeP != null)
						{
							string fontSize		= this.GetGlobalStyleElement(textPropNodeP, "@fo:font-size");
							if (fontSize != null)
								style	+= "font-size: "+FontFamilies.PtToPx(fontSize)+"; ";

							string italic		= this.GetGlobalStyleElement(textPropNodeP, "@fo:font-style");
							if (italic != null)
								style	+= "font-size: italic; ";

							string bold		= this.GetGlobalStyleElement(textPropNodeP, "@fo:font-weight");
							if (bold != null)
								style	+= "font-weight: bold; ";

							string underline = this.GetGlobalStyleElement(textPropNodeP, "@style:text-underline-style");
							if (underline != null)
								style	+= "text-decoration: underline; ";

							string fontName = this.GetGlobalStyleElement(textPropNodeP, "@style:font-name");
							if (fontName != null)
								style	+= "font-family: "+FontFamilies.HtmlFont(fontName)+"; ";

							string color	= this.GetGlobalStyleElement(textPropNodeP, "@fo:color");
							if (color != null)
								style	+= "color: "+color+"; ";
						}
						//Check now text properties of style, maybe some setting are overwritten or extended
						if (textPropNode != null)
						{
							string fontSize		= this.GetGlobalStyleElement(textPropNode, "@fo:font-size");
							if (fontSize != null)
								style	+= "font-size: "+FontFamilies.PtToPx(fontSize)+"; ";

							string italic		= this.GetGlobalStyleElement(textPropNode, "@fo:font-style");
							if (italic != null)
								style	+= "font-size: italic; ";

							string bold		= this.GetGlobalStyleElement(textPropNode, "@fo:font-weight");
							if (bold != null)
								style	+= "font-weight: bold; ";

							string underline = this.GetGlobalStyleElement(textPropNode, "@style:text-underline-style");
							if (underline != null)
								style	+= "text-decoration: underline; ";

							string fontName = this.GetGlobalStyleElement(textPropNode, "@style:font-name");
							if (fontName != null)
								style	+= "font-family: "+FontFamilies.HtmlFont(fontName)+"; ";

							string color	= this.GetGlobalStyleElement(textPropNode, "@fo:color");
							if (color != null)
								style	+= "color: "+color+"; ";
						}
					}
				}

				if (!style.EndsWith("; "))
					style	= "";
				else
					style	+= "\"";

				return style;
			}
			catch(Exception)
			{
				//unhandled, only a paragraph style wouldn't be displayed correct
				//Console.WriteLine("GetHtmlStyleFromGlobalStyles(): {0}", ex.Message);
			}
			
			return "";
		}