Represent the style for a Paragraph object.
Inheritance: AbstractStyle
コード例 #1
0
 void Example8()
 {
     TextDocument document = new TextDocument();
     document.New();
     Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
     paragraph.TextContent.Add(new SimpleText(document, "Some text"));
     Paragraph paragraphClone = (Paragraph)paragraph.Clone();
     ParagraphStyle paragraphStyle = new ParagraphStyle(document, "P1");
     paragraphStyle.TextProperties.Bold = "bold";
     //Add paragraph style to the document,
     //only automaticaly created styles will be added also automaticaly
     document.Styles.Add(paragraphStyle);
     paragraphClone.ParagraphStyle = paragraphStyle;
     //Clone the clone
     Paragraph paragraphClone2 = (Paragraph)paragraphClone.Clone();
     document.Content.Add(paragraph);
     document.Content.Add(paragraphClone);
     document.Content.Add(paragraphClone2);
     document.SaveTo("example8_clonedParagraphs.odt");
 }
コード例 #2
0
		/// <summary>
		/// Gets the mixed content as HTML.
		/// </summary>
		/// <param name="mixedContent">ArrayList of objects. The objects could be
		/// IContent or IText.</param>
		/// <param name="paragraphStyle">The paragraph style.</param>
		/// <returns></returns>
		public string GetMixedContentAsHTML(ArrayList mixedContent, ParagraphStyle paragraphStyle)
		{
			string html					= "";
			int tabStopCnt				= 0;

			try
			{
				if (mixedContent != null)
				{
					foreach(object ob in mixedContent)
					{
						//determine type text content types
						if (ob is SimpleText)
						{
							html			+= this.ReplaceControlNodes(((IText)ob).Node.InnerText);
						}
						else if (ob is FormatedText)
							html			+= this.GetFormatedTextAsHtml(ob as FormatedText);
						else if (ob is WhiteSpace)
							html			+= this.GetWhiteSpacesAsHtml(ob as WhiteSpace);
						else if (ob is TabStop)
						{
							html			+= this.GetTabStopAsHtml(ob as TabStop, tabStopCnt, html, paragraphStyle);
							tabStopCnt++;
						}
						else if (ob is XLink)
							html			+= this.GetXLinkAsHtml(ob as XLink);
						else if (ob is LineBreak)
							html			+= this.GetLineBreakAsHtml();
						else if (ob is UnknownTextContent)
							html			+= this.GetUnknowTextContentAsHtml(ob as UnknownTextContent);
							//determine type
						else if (ob is Table)
							html			+= this.GetTableAsHtml(ob as Table);
						else if (ob is Paragraph)
							html			+= this.GetParagraphAsHtml(ob as Paragraph);
						else if (ob is List)
							html			+= this.GetListAsHtml(ob as List);
						else if (ob is Frame)
							html			+= this.GetDrawFrameAsHtml(ob as Frame);
						else if (ob is Graphic)
							html			+= this.GetGraphicAsHtml(ob as Graphic);
						else if (ob is ListItem)
							html			+= this.GetListItemAsHtml(ob as ListItem);
						else if (ob is Field)
							html			+= this.GetFieldAsHtml(ob as Field);
						else if (ob is ODFControlRef)
							html			+= this.GetODFControlAsHtml(ob as ODFControlRef);
						else if (ob is Header)
							html			+= this.GetHeadingAsHtml(ob as Header);
						else if (ob is UnknownContent)
							html			+= this.GetUnknowContentAsHtml(ob as UnknownContent);
						else
							//this should never happens, because all not implemented elements 
							//are unknwon content
							if (OnWarning != null)
						{
							AODLWarning warning			= new AODLWarning("Finding total unknown content in mixed 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;			
		}
コード例 #3
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;
		}
コード例 #4
0
		/// <summary>
		/// Gets the tab stop as HTML.
		/// Because of the fact that no tabstop html element exist,
		/// AODL will try to simulate this with a the non breaking 
		/// line entity.
		/// </summary>
		/// <param name="tabStop">The tab stop.</param>
		/// <param name="tabStopIndex">The tab stop position from all tabstops from the textcollectio,
		/// where this tabstop belongs to.</param>
		/// <param name="htmlStringBefore">The complete html string before this tabstop.</param>
		/// <param name="paragraphStyle">The paragraph style from the enclosing paragraph.</param>
		/// <returns></returns>
		public string GetTabStopAsHtml(TabStop tabStop, int tabStopIndex, string htmlStringBefore, ParagraphStyle paragraphStyle)
		{
			//simulate a tabstop in html
			string htmlTab				= "&nbsp;&nbsp;&nbsp;&nbsp;";
			string html					= "";

			try
			{
				if (paragraphStyle != null)
					if (paragraphStyle.ParagraphProperties != null)
						if (paragraphStyle.ParagraphProperties.TabStopStyleCollection != null)
							if (paragraphStyle.ParagraphProperties.TabStopStyleCollection.Count-1 <= tabStopIndex)
							{
								TabStopStyle tabStopStyle = paragraphStyle.ParagraphProperties.TabStopStyleCollection[tabStopIndex];
								
								string leadingChar			= "&nbsp;";								
								if (tabStopStyle.LeaderText != null)
									leadingChar				= tabStopStyle.LeaderText;
								
								string[] grabInt			= tabStopStyle.Position.Split('.');
								if (grabInt.Length == 2)
								{
									double position			= Convert.ToDouble(grabInt[0]);
									//expecting that one displaying character will ~ .5cm
									if (htmlStringBefore != null)
									{
										for(int i=0; i<htmlStringBefore.Length; i++)
											position		-= 0.5;
									}
									
									if (position > 0.5)
										for(double i=0; i<position; i+=0.25)
											html			+= leadingChar;
								}
							}
			}
			catch(Exception ex)
			{
				if (OnWarning != null)
				{
					AODLWarning warning			= new AODLWarning("Exception while trying to build a simulated html tabstop.", ex);
					//warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
					//warning.OriginalException	= ex;
					OnWarning(warning);
				}
			}

			if (html.Length == 0)
				html				= htmlTab;

			return html;
		}
コード例 #5
0
 public void TestCloning()
 {
     var document				= new TextDocument();
     document.New();
     var paragraph					= ParagraphBuilder.CreateStandardTextParagraph(document);
     paragraph.TextContent.Add(new SimpleText(document, "Some text"));
     var paragraphClone			= (Paragraph)paragraph.Clone();
     Assert.AreNotSame(paragraph.Node, paragraphClone.Node, "Should be cloned and not equal.");
     Assert.AreEqual(paragraph.TextContent[0].GetType(), paragraphClone.TextContent[0].GetType(), "Should be cloned and equal.");
     var paragraphStyle = new ParagraphStyle(document, "P1") { TextProperties = { Bold = "bold" } };
     //Add paragraph style to the document,
     //only automaticaly created styles will be added also automaticaly
     document.Styles.Add(paragraphStyle);
     paragraphClone.ParagraphStyle		= paragraphStyle;
     //Clone the clone
     var paragraphClone2			= (Paragraph)paragraphClone.Clone();
     Assert.AreNotSame(paragraphClone2.Node, paragraphClone.Node, "Should be cloned and not equal.");
     Assert.AreEqual(paragraphClone2.TextContent[0].GetType(), paragraphClone.TextContent[0].GetType(), "Should be cloned and equal.");
     //Cloning of styles isn't supported!
     Assert.AreSame(paragraphClone2.ParagraphStyle, paragraphClone.ParagraphStyle, "Must be same style object. Styles have to be cloned explicitly.");
     document.Content.Add(paragraph);
     document.Content.Add(paragraphClone);
     document.Content.Add(paragraphClone2);
     document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"clonedParagraphs.odt");
 }
コード例 #6
0
		/// <summary>
		/// Creates the paragraph style.
		/// </summary>
		/// <param name="styleNode">The style node.</param>
		private void CreateParagraphStyle(XmlNode styleNode)
		{
			ParagraphStyle paragraphStyle			= new ParagraphStyle(this._document, styleNode);
			IPropertyCollection pCollection			= new IPropertyCollection();			

			if (styleNode.HasChildNodes)
			{
				foreach(XmlNode node in styleNode.ChildNodes)
				{
					IProperty property			= this.GetProperty(paragraphStyle, node.CloneNode(true));
					if (property != null)
						pCollection.Add(property);

				}
			}

			paragraphStyle.Node.InnerXml		= "";

			foreach(IProperty property in pCollection)
				paragraphStyle.PropertyCollection.Add(property);

			if (!this._common)
				this._document.Styles.Add(paragraphStyle);
			else
				this._document.CommonStyles.Add(paragraphStyle);
		}
コード例 #7
0
		/// <summary>
		/// Gets the paragraph style as HTML.
		/// </summary>
		/// <param name="paragraphStyle">The paragraph style.</param>
		/// <returns></returns>
		public string GetParagraphStyleAsHtml(ParagraphStyle paragraphStyle)
		{
			string style		= "style=\"";

			try
			{
				if (paragraphStyle != null)
				{
					if (paragraphStyle.ParagraphProperties != null)
					{
						if (paragraphStyle.ParagraphProperties.Alignment != null
							&& paragraphStyle.ParagraphProperties.Alignment != "start")
							style	+= "text-align: "+paragraphStyle.ParagraphProperties.Alignment+"; ";
						if (paragraphStyle.ParagraphProperties.MarginLeft != null)
							style	+= "text-indent: "+paragraphStyle.ParagraphProperties.MarginLeft+"; ";
						if (paragraphStyle.ParagraphProperties.LineSpacing != null)
							style	+= "line-height: "+paragraphStyle.ParagraphProperties.LineSpacing+"; ";
						if (paragraphStyle.ParagraphProperties.Border != null 
							&& paragraphStyle.ParagraphProperties.Padding == null)
							style	+= "border-width:1px; border-style:solid; padding: 0.5cm; ";
						if (paragraphStyle.ParagraphProperties.Border != null 
							&& paragraphStyle.ParagraphProperties.Padding != null)
							style	+= "border-width:1px; border-style:solid; padding:"+paragraphStyle.ParagraphProperties.Padding+"; ";
						if (paragraphStyle.ParagraphProperties.BackgroundColor != null)
							style	+= "background-color: "+paragraphStyle.ParagraphProperties.BackgroundColor+"; ";
					}
				}
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to build a HTML style string from a ParagraphStyle.", ex);
			}

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

			return style;
		}
コード例 #8
0
		public void StyleTest()
		{
			// Create a new document
			TextDocument document	= new TextDocument();
			document.New();
			
			// Create a main paragraph
			Paragraph p =new Paragraph(document);
			
			ParagraphStyle ps1 = new ParagraphStyle(document, "style1");
			ps1.Family = "paragraph";
			ps1.TextProperties.FontName = FontFamilies.Arial;
			ps1.TextProperties.FontColor = AODL.Document.Helper.Colors.GetColor(System.Drawing.Color.Blue);
			ps1.TextProperties.Bold = "bold";
			ps1.TextProperties.FontSize = "18pt";
			document.Styles.Add(ps1);
			
			ParagraphStyle ps2 = new ParagraphStyle(document, "style2");
			ps2.Family = "paragraph";
			ps2.TextProperties.FontName = FontFamilies.CourierNew;
			ps2.TextProperties.Italic = "italic";
			ps2.TextProperties.FontSize = "14pt";
			ps2.TextProperties.Underline = "dotted";
			document.Styles.Add(ps2);

			ParagraphStyle ps3 = new ParagraphStyle(document, "style3");
			ps3.Family = "paragraph";
			ps3.TextProperties.FontName = FontFamilies.Wingdings;
			ps3.TextProperties.FontColor = AODL.Document.Helper.Colors.GetColor(System.Drawing.Color.Red);
			ps3.TextProperties.FontSize = "16pt";
			document.Styles.Add(ps3);

			// Create a main form
			ODFForm main_form = new ODFForm(document, "mainform");
			main_form.Method = Method.Get;
			
			// The first button. It doesn't get a focus on click
			ODFButton butt = new ODFButton(main_form, p.Content, "butt1", "0cm", "0mm", "7cm", "1cm");
			butt.TextStyle = ps1;
			butt.Label = "Button one";
			butt.Title = "This button uses Arial font.";
			butt.FocusOnClick = XmlBoolean.False;
			butt.ButtonType = ButtonType.Push;
			main_form.Controls.Add (butt);

			// The second button. It is disabled
			butt = new ODFButton(main_form, p.Content, "butt2", "0cm", "2cm", "7cm", "1cm");
			butt.Label = "Button two";
			butt.Title = "Second button.";
			butt.FocusOnClick = XmlBoolean.True;
			butt.Disabled = XmlBoolean.True;
			butt.TextStyle = ps2;
			main_form.Controls.Add (butt);

			// The third button with "toggle" behaviour
			butt = new ODFButton(main_form, p.Content, "butt3", "0cm", "4cm", "7cm", "1cm");
			butt.Label = "Button three";
			butt.Title = "Third button.";
			butt.Toggle = XmlBoolean.True;
			butt.TextStyle = ps3;
			main_form.Controls.Add (butt);


			
			document.Forms.Add(main_form);
			document.Content.Add(p);

	
			document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"style_test.odt");
			document.Load(AARunMeFirstAndOnce.outPutFolder+"style_test.odt");
			document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"style_test2.odt");
		}
コード例 #9
0
        /// <summary>
        /// Gets the paragraph style as HTML.
        /// </summary>
        /// <param name="paragraphStyle">The paragraph style.</param>
        /// <returns></returns>
        public string GetParagraphStyleAsHtml(ParagraphStyle paragraphStyle)
        {
            string style		= "style=\"";

            try
            {
                if(paragraphStyle != null)
                {
                    if(paragraphStyle.ParagraphProperties != null)
                    {
                        if(paragraphStyle.ParagraphProperties.Alignment != null
                            && paragraphStyle.ParagraphProperties.Alignment != "start")
                            style	+= "text-align: "+paragraphStyle.ParagraphProperties.Alignment+"; ";
                        if(paragraphStyle.ParagraphProperties.MarginLeft != null)
                            style	+= "text-indent: "+paragraphStyle.ParagraphProperties.MarginLeft+"; ";
                        if(paragraphStyle.ParagraphProperties.LineSpacing != null)
                            style	+= "line-height: "+paragraphStyle.ParagraphProperties.LineSpacing+"; ";
                        if(paragraphStyle.ParagraphProperties.Border != null
                            && paragraphStyle.ParagraphProperties.Padding == null)
                            style	+= "border-width:1px; border-style:solid; padding: 0.5cm; ";
                        if(paragraphStyle.ParagraphProperties.Border != null
                            && paragraphStyle.ParagraphProperties.Padding != null)
                            style	+= "border-width:1px; border-style:solid; padding:"+paragraphStyle.ParagraphProperties.Padding+"; ";
                        if(paragraphStyle.ParagraphProperties.BackgroundColor != null)
                            style	+= "background-color: "+paragraphStyle.ParagraphProperties.BackgroundColor+"; ";
                    }
                }
            }
            catch(Exception ex)
            {
                AODLException exception		= new AODLException("Exception while trying to build a HTML style string from a ParagraphStyle.");
                exception.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                exception.OriginalException	= ex;

                if(paragraphStyle != null)
                    if(paragraphStyle.Node != null)
                        exception.Node		= paragraphStyle.Node;

                throw exception;
            }

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

            return style;
        }