コード例 #1
0
		/// <summary>
		/// Gets the text contents.
		/// </summary>
		/// <param name="textCollection">The text collection.</param>
		/// <returns>The content. ArrayList of chunks and phrases.</returns>
		public static ICollection GetTextContents(ITextCollection textCollection, iTextSharp.text.Font font)
		{
			ArrayList contents = new ArrayList();
			foreach(object obj in textCollection)
			{
				if (obj is AODL.Document.Content.Text.FormatedText)
				{
					contents.Add(FormatedTextConverter.Convert(
						obj as AODL.Document.Content.Text.FormatedText));
				}
				else if (obj is AODL.Document.Content.Text.SimpleText)
				{
					contents.Add(SimpleTextConverter.Convert(
						obj as AODL.Document.Content.Text.SimpleText, font));
				}
				else if (obj is AODL.Document.Content.Text.TextControl.TabStop)
				{
					contents.Add(SimpleTextConverter.ConvertTabs(
						obj as AODL.Document.Content.Text.TextControl.TabStop, font));
				}
				else if (obj is AODL.Document.Content.Text.TextControl.WhiteSpace)
				{
					contents.Add(SimpleTextConverter.ConvertWhiteSpaces(
						obj as AODL.Document.Content.Text.TextControl.WhiteSpace, font));
				}
			}
			return contents;
		}
コード例 #2
0
        /// <summary>
        /// Inits the standards.
        /// </summary>
        private void InitStandards()
        {
            TextContent = new ITextCollection();

            TextContent.Inserted += TextContent_Inserted;
            TextContent.Removed  += TextContent_Removed;
        }
コード例 #3
0
        /// <summary>
        /// Builds the text collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static ITextCollection BuildTextCollection(IDocument document, string text)
        {
            string          xmlStartTag   = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ITextCollection txtCollection = new ITextCollection();

            text         = WhiteSpaceHelper.GetWhiteSpaceXml(text);
            text         = text.Replace("\t", "<t/>");
            text         = text.Replace("\n", "<n/>");
            xmlStartTag += "<txt>" + text + "</txt>";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlStartTag);

            XmlNode nodeStart = xmlDoc.DocumentElement;

            if (nodeStart != null)
            {
                if (nodeStart.HasChildNodes)
                {
                    foreach (XmlNode childNode in nodeStart.ChildNodes)
                    {
                        if (childNode.NodeType == XmlNodeType.Text)
                        {
                            txtCollection.Add(new SimpleText(document, childNode.InnerText));
                        }
                        else if (childNode.Name == "ws")
                        {
                            if (childNode.Attributes.Count == 1)
                            {
                                XmlNode nodeCnt = childNode.Attributes.GetNamedItem("id");
                                if (nodeCnt != null)
                                {
                                    txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.InnerText)));
                                }
                            }
                        }
                        else if (childNode.Name == "t")
                        {
                            txtCollection.Add(new TabStop(document));
                        }
                        else if (childNode.Name == "n")
                        {
                            txtCollection.Add(new LineBreak(document));
                        }
                    }
                }
                else
                {
                    txtCollection.Add(new SimpleText(document, text));
                }
            }
            return(txtCollection);
        }
コード例 #4
0
        /// <summary>
        /// Builds the text collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static ITextCollection BuildTextCollection(IDocument document, string text)
        {
            string          xmlStartTag   = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ITextCollection txtCollection = new ITextCollection();

            text         = WhiteSpaceHelper.GetWhiteSpaceXml(text);
            text         = text.Replace("\t", "<t/>");
            text         = text.Replace("\n", "<n/>");
            xmlStartTag += "<txt>" + text + "</txt>";

            XDocument xmlDoc = XDocument.Parse(xmlStartTag);

            XElement nodeStart = xmlDoc.Root;

            if (nodeStart != null)
            {
                if (nodeStart.HasElements)
                {
                    foreach (XNode childNode in nodeStart.Nodes())
                    {
                        if (childNode.NodeType == XmlNodeType.Text)
                        {
                            txtCollection.Add(new SimpleText(document, ((XText)childNode).Value));
                        }
                        else if (((XElement)childNode).Name == "ws")
                        {
                            if (((XElement)childNode).Attributes().Count() == 1)
                            {
                                XAttribute nodeCnt = ((XElement)childNode).Attribute("id");
                                if (nodeCnt != null)
                                {
                                    txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.Value)));
                                }
                            }
                        }
                        else if (((XElement)childNode).Name == "t")
                        {
                            txtCollection.Add(new TabStop(document));
                        }
                        else if (((XElement)childNode).Name == "n")
                        {
                            txtCollection.Add(new LineBreak(document));
                        }
                    }
                }
                else
                {
                    txtCollection.Add(new SimpleText(document, text));
                }
            }
            return(txtCollection);
        }
コード例 #5
0
ファイル: Paragraph.cs プロジェクト: zhaoyin/officeOBA
        /// <summary>
        /// Inits the standards.
        /// </summary>
        private void InitStandards()
        {
            TextContent   = new ITextCollection();
            Content       = new ContentCollection();
            _mixedContent = new List <IContent>();

            if (Document is TextDocument)
            {
                Document.DocumentMetadata.ParagraphCount += 1;
            }

            TextContent.Inserted += TextContent_Inserted;
            Content.Inserted     += Content_Inserted;
            TextContent.Removed  += TextContent_Removed;
            Content.Removed      += Content_Removed;
        }
コード例 #6
0
		/// <summary>
		/// Builds the text collection.
		/// </summary>
		/// <param name="document">The document.</param>
		/// <param name="text">The text.</param>
		/// <returns></returns>
		public static ITextCollection BuildTextCollection(IDocument document, string text)
		{
			string xmlStartTag				= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
			ITextCollection txtCollection	= new ITextCollection();
			text							= WhiteSpaceHelper.GetWhiteSpaceXml(text);
			text							= text.Replace("\t", "<t/>");
			text							= text.Replace("\n", "<n/>");
			xmlStartTag						+= "<txt>"+text+"</txt>";

			XmlDocument xmlDoc				= new XmlDocument();
			xmlDoc.LoadXml(xmlStartTag);

			XmlNode nodeStart				= xmlDoc.DocumentElement;
			if (nodeStart != null)
				if (nodeStart.HasChildNodes)
				{
					foreach(XmlNode childNode in nodeStart.ChildNodes)
					{
						if (childNode.NodeType == XmlNodeType.Text)
							txtCollection.Add(new SimpleText(document, childNode.InnerText));
						else if (childNode.Name == "ws")
						{
							if (childNode.Attributes.Count == 1)
							{
								XmlNode nodeCnt = childNode.Attributes.GetNamedItem("id");
								if (nodeCnt != null)
									txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.InnerText)));
							}
						}
						else if (childNode.Name == "t")
						{
							txtCollection.Add(new TabStop(document));
						}
						else if (childNode.Name == "n")
						{
							txtCollection.Add(new LineBreak(document));
						}
					}
				}
				else
				{
					txtCollection.Add(new SimpleText(document, text));
				}
			return txtCollection;
		}
コード例 #7
0
		/// <summary>
		/// Creates the header.
		/// </summary>
		/// <param name="headernode">The headernode.</param>
		/// <returns></returns>
		public Header CreateHeader(XmlNode headernode)
		{
			try
			{
				if (this._debugMode)
					this.LogNode(headernode, "Log header node before");

				//Create a new Header
				Header header				= new Header(headernode, this._document);
				//Create a ITextCollection
				ITextCollection textColl	= new ITextCollection();
				//Recieve the HeaderStyle
				IStyle headerStyle			= this._document.Styles.GetStyleByName(header.StyleName);

				if (headerStyle != null)
					header.Style			= headerStyle;

				//Create the IText content
				foreach(XmlNode nodeChild in header.Node.ChildNodes)
				{
					TextContentProcessor tcp	= new TextContentProcessor();
					IText iText					= tcp.CreateTextObject(this._document, nodeChild);
					
					if (iText != null)
						textColl.Add(iText);
					else
					{
						this.OnWarning(new AODLWarning("Couldn't create IText object from header child node!.", nodeChild));
					}
				}

				//Remove all
				header.Node.InnerXml		= "";

				foreach(IText iText in textColl)
				{
					if (this._debugMode)
						this.LogNode(iText.Node, "Log IText node read from header");
					header.TextContent.Add(iText);
				}

				return header;
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to create a Header.", ex);
			}
		}
コード例 #8
0
		/// <summary>
		/// Gets the I text collection as HTML.
		/// </summary>
		/// <param name="iTextCollection">The i text collection.</param>
		/// <param name="paragraphStyle">The paragraph style.</param>
		/// <returns></returns>
		public string GetITextCollectionAsHtml(ITextCollection iTextCollection, ParagraphStyle paragraphStyle)
		{
			string html					= "";
			int tabStopCnt				= 0;

			try
			{
				if (iTextCollection != null)
				{
					foreach(IText iText in iTextCollection)
					{
						//determine type
						if (iText is SimpleText)
						{
							string textContent	= iText.Node.InnerText;
							html				+= this.ReplaceControlNodes(textContent);
						}
						else if (iText is FormatedText)
							html			+= this.GetFormatedTextAsHtml(iText as FormatedText);
						else if (iText is WhiteSpace)
							html			+= this.GetWhiteSpacesAsHtml(iText as WhiteSpace);
						else if (iText is TabStop)
						{
							html			+= this.GetTabStopAsHtml(iText as TabStop, tabStopCnt, html, paragraphStyle);
							tabStopCnt++;
						}
						else if (iText is XLink)
							html			+= this.GetXLinkAsHtml(iText as XLink);
						else if (iText is LineBreak)
							html			+= this.GetLineBreakAsHtml();
						else if (iText is UnknownTextContent)
							html			+= this.GetUnknowTextContentAsHtml(iText as UnknownTextContent);
						else
							//this should never happens, because all not implemented elements 
							//are unknwon content
							if (OnWarning != null)
						{
							AODLWarning warning			= new AODLWarning("Finding total unknown text content. This should (could) never happen.");
							//warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
							OnWarning(warning);
						}
					}
				}
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to build a HTML string from an ITextCollection.", ex);
			}

			return html;
		}
コード例 #9
0
ファイル: Header.cs プロジェクト: stuzzicadenti/aodl
        /// <summary>
        /// Inits the standards.
        /// </summary>
        private void InitStandards()
        {
            this.TextContent			= new ITextCollection();

            this.TextContent.Inserted	+=new AODL.Document.Collections.CollectionWithEvents.CollectionChange(TextContent_Inserted);
            this.TextContent.Removed	+=new AODL.Document.Collections.CollectionWithEvents.CollectionChange(TextContent_Removed);
        }
コード例 #10
0
		/// <summary>
		/// Creates the formated text.
		/// </summary>
		/// <param name="document">The document.</param>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		public FormatedText CreateFormatedText(IDocument document, XmlNode node)
		{
			//Create a new FormatedText object
			FormatedText formatedText		= new FormatedText(document, node);
			ITextCollection iTextColl		= new ITextCollection();
			formatedText.Document			= document;
			formatedText.Node				= node;
			//Recieve a TextStyle
			
			IStyle textStyle				= document.Styles.GetStyleByName(formatedText.StyleName);

			if (textStyle != null)
				formatedText.Style			= textStyle;
			//else
			//{
			//	IStyle iStyle				= document.CommonStyles.GetStyleByName(formatedText.StyleName);
			//}
			
			//Ceck for more IText object
			foreach(XmlNode iTextNode in node.ChildNodes)
			{
				IText iText						= this.CreateTextObject(document, iTextNode.CloneNode(true));
				if (iText != null)
				{
					iTextColl.Add(iText);
				}
				else
					iTextColl.Add(new UnknownTextContent(document, iTextNode) as IText);
			}

			formatedText.Node.InnerText			= "";

			foreach(IText iText in iTextColl)
				formatedText.TextContent.Add(iText);

			return formatedText;
		}
コード例 #11
0
		/// <summary>
		/// Creates the X link.
		/// </summary>
		/// <param name="document">The document.</param>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		public XLink CreateXLink(IDocument document, XmlNode node)
		{
			try
			{
				XLink xlink				= new XLink(document);
				xlink.Node				= node.CloneNode(true);
				ITextCollection iTxtCol	= new ITextCollection();

				foreach(XmlNode nodeText in xlink.Node.ChildNodes)
				{
					IText iText			= this.CreateTextObject(xlink.Document, nodeText);
					if (iText != null)
						iTxtCol.Add(iText);
				}

				xlink.Node.InnerXml		= "";

				foreach(IText iText in iTxtCol)
					xlink.TextContent.Add(iText);

				return xlink;
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to create a XLink.", ex);
			}
		}
コード例 #12
0
        /// <summary>
        /// Creates the header.
        /// </summary>
        /// <param name="headernode">The headernode.</param>
        /// <returns></returns>
        public Header CreateHeader(XmlNode headernode)
        {
            try
            {
                #region Old code Todo: delete
                //				XmlNode node			= headernode.SelectSingleNode("//@text:style-name", this._document.NamespaceManager);
                //				if(node != null)
                //				{
                //					if(!node.InnerText.StartsWith("Heading"))
                //					{
                //						//Check if a the referenced paragraphstyle reference a heading as parentstyle
                //						XmlNode stylenode	= this._document.XmlDoc.SelectSingleNode("//style:style[@style:name='"+node.InnerText+"']", this._document.NamespaceManager);
                //						if(stylenode != null)
                //						{
                //							XmlNode parentstyle	= stylenode.SelectSingleNode("@style:parent-style-name",
                //								this._document.NamespaceManager);
                //							if(parentstyle != null)
                //								if(parentstyle.InnerText.StartsWith("Heading"))
                //									headernode.SelectSingleNode("@text:style-name",
                //										this._document.NamespaceManager).InnerText = parentstyle.InnerText;
                //						}
                //					}
                //				}
                #endregion
                if(this._debugMode)
                    this.LogNode(headernode, "Log header node before");

                //Create a new Header
                Header header				= new Header(headernode, this._document);
                //Create a ITextCollection
                ITextCollection textColl	= new ITextCollection();
                //Recieve the HeaderStyle
                IStyle headerStyle			= this._document.Styles.GetStyleByName(header.StyleName);

                if(headerStyle != null)
                    header.Style			= headerStyle;

                //Create the IText content
                foreach(XmlNode nodeChild in header.Node.ChildNodes)
                {
                    TextContentProcessor tcp	= new TextContentProcessor();
                    IText iText					= tcp.CreateTextObject(this._document, nodeChild);

                    if(iText != null)
                        textColl.Add(iText);
                    else
                    {
                        if(this.OnWarning != null)
                        {
                            AODLWarning warning			= new AODLWarning("Couldn't create IText object from header child node!.");
                            warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                            warning.Node				= nodeChild;
                            this.OnWarning(warning);
                        }
                    }
                }

                //Remove all
                header.Node.InnerXml		= "";

                foreach(IText iText in textColl)
                {
                    if(this._debugMode)
                        this.LogNode(iText.Node, "Log IText node read from header");
                    header.TextContent.Add(iText);
                }

                return header;
            }
            catch(Exception ex)
            {
                AODLException exception		= new AODLException("Exception while trying to create a Header.");
                exception.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                exception.Node				= headernode;
                exception.OriginalException	= ex;

                throw exception;
            }

            return null;
        }
コード例 #13
0
        /// <summary>
        /// Creates the X link.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public XLink CreateXLink(IDocument document, XmlNode node)
        {
            try
            {
                XLink xlink				= new XLink(document);
                xlink.Node				= node.CloneNode(true);
                ITextCollection iTxtCol	= new ITextCollection();

                foreach(XmlNode nodeText in xlink.Node.ChildNodes)
                {
                    IText iText			= this.CreateTextObject(xlink.Document, nodeText);
                    if(iText != null)
                        iTxtCol.Add(iText);
                }

                xlink.Node.InnerXml		= "";

                foreach(IText iText in iTxtCol)
                    xlink.TextContent.Add(iText);

                return xlink;
            }
            catch(Exception ex)
            {
                AODLException exception		= new AODLException("Exception while trying to create a XLink.");
                exception.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                exception.Node				= node;
                exception.OriginalException	= ex;

                throw exception;
            }
        }
コード例 #14
0
        /// <summary>
        /// Creates the formated text.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public FormatedText CreateFormatedText(IDocument document, XmlNode node)
        {
            try
            {
                //Create a new FormatedText object
                FormatedText formatedText		= new FormatedText(document, node);
                ITextCollection iTextColl		= new ITextCollection();
                formatedText.Document			= document;
                formatedText.Node				= node;
                //Recieve a TextStyle

                IStyle textStyle				= document.Styles.GetStyleByName(formatedText.StyleName);

                if(textStyle != null)
                    formatedText.Style			= textStyle;
                else
                {
                    IStyle iStyle				= document.CommonStyles.GetStyleByName(formatedText.StyleName);
                    if(iStyle == null)
                    {
                        if(OnWarning != null)
                        {
                            AODLWarning warning			= new AODLWarning("A TextStyle for the FormatedText object wasn't found.");
                            warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                            warning.Node				= node;
                            OnWarning(warning);
                        }
                    }
                }

                //Ceck for more IText object
                foreach(XmlNode iTextNode in node.ChildNodes)
                {
                    IText iText						= this.CreateTextObject(document, iTextNode.CloneNode(true));
                    if(iText != null)
                    {
                        iTextColl.Add(iText);
                    }
                    else
                        iTextColl.Add(new UnknownTextContent(document, iTextNode) as IText);
                }

                formatedText.Node.InnerText			= "";

                foreach(IText iText in iTextColl)
                    formatedText.TextContent.Add(iText);

                return formatedText;
            }
            catch(Exception ex)
            {
                throw;
            }
        }
コード例 #15
0
ファイル: Paragraph.cs プロジェクト: stuzzicadenti/aodl
        /// <summary>
        /// Inits the standards.
        /// </summary>
        private void InitStandards()
        {
            this.TextContent			= new ITextCollection();
            this.Content				= new IContentCollection();
            this._mixedContent			= new ArrayList();

            if(this.Document is AODL.Document.TextDocuments.TextDocument)
                this.Document.DocumentMetadata.ParagraphCount	+= 1;

            this.TextContent.Inserted	+=new AODL.Document.Collections.CollectionWithEvents.CollectionChange(TextContent_Inserted);
            this.Content.Inserted		+=new AODL.Document.Collections.CollectionWithEvents.CollectionChange(Content_Inserted);
            this.TextContent.Removed	+=new AODL.Document.Collections.CollectionWithEvents.CollectionChange(TextContent_Removed);
            this.Content.Removed		+=new AODL.Document.Collections.CollectionWithEvents.CollectionChange(Content_Removed);
        }