Represent a formated Text e.g bold, italic, underline etc.
Inheritance: IHtml, IText, ITextContainer, ICloneable
 void Example1()
 {
     //Create new spreadsheet document
     SpreadsheetDocument spreadsheetDocument = new SpreadsheetDocument();
     spreadsheetDocument.New();
     //Create a new table
     Table table = new Table(spreadsheetDocument, "First", "tablefirst");
     //Create a new cell, without any extra styles
     Cell cell = table.CreateCell();
     //Add a paragraph to this cell
     Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(spreadsheetDocument);
     //Create some Formated text
     FormatedText fText = new FormatedText(spreadsheetDocument, "T1", "Some Text");
     //fText.TextStyle.TextProperties.Bold = "bold";
     fText.TextStyle.TextProperties.Underline = LineStyles.dotted;
     //Add formated text
     paragraph.TextContent.Add(fText);
     //Add paragraph to the cell
     cell.Content.Add(paragraph);
     //Insert the cell at row index 2 and column index 3
     //All need rows, columns and cells below the given
     //indexes will be build automatically.
     table.InsertCellAt(2, 3, cell);
     //Insert table into the spreadsheet document
     spreadsheetDocument.TableCollection.Add(table);
     spreadsheetDocument.SaveTo("example1_formated.ods");
 }
Beispiel #2
0
        /// <summary>
        /// Converts the specified formated text.
        /// </summary>
        /// <param name="formatedText">The formated text.</param>
        /// <returns>The chunck object representing this formated text.</returns>
        public static iTextSharp.text.Phrase Convert(AODL.Document.Content.Text.FormatedText formatedText)
        {
            try
            {
                iTextSharp.text.Font font;
                if ((TextStyle)formatedText.Style != null &&
                    ((TextStyle)formatedText.Style).TextProperties != null)
                {
                    font = TextPropertyConverter.GetFont(
                        ((TextStyle)formatedText.Style).TextProperties);
                }
                else
                {
                    font = DefaultDocumentStyles.Instance().DefaultTextFont;
                }

                iTextSharp.text.Phrase phrase = new iTextSharp.text.Phrase("", font);                 // default ctor protected - why ??
                phrase.AddRange(FormatedTextConverter.GetTextContents(formatedText.TextContent, font));

                return(phrase);
            }
            catch (Exception)
            {
                throw;
            }
        }
 protected Paragraph addBold (String text)
 {
     Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
     FormatedText formText = new FormatedText(document, "T1", text);
     formText.TextStyle = BOLD_STYLE;
     paragraph.TextContent.Add(formText);
     document.Content.Add(paragraph);
     return paragraph;
 }
Beispiel #4
0
        /// <summary>
        /// Create a deep clone of this FormatedText object.
        /// </summary>
        /// <remarks>A possible Attached Style wouldn't be cloned!</remarks>
        /// <returns>
        /// A clone of this object.
        /// </returns>
        public object Clone()
        {
            FormatedText formatedTextClone = null;

            if (this.Document != null && this.Node != null)
            {
                TextContentProcessor tcp = new TextContentProcessor();
                formatedTextClone = tcp.CreateFormatedText(
                    this.Document, this.Node.CloneNode(true));
            }

            return(formatedTextClone);
        }
Beispiel #5
0
        /// <summary>
        /// Create a deep clone of this FormatedText object.
        /// </summary>
        /// <remarks>A possible Attached Style wouldn't be cloned!</remarks>
        /// <returns>
        /// A clone of this object.
        /// </returns>
        public object Clone()
        {
            FormatedText formatedTextClone = null;

            if (Document != null && Node != null)
            {
                TextContentProcessor tcp = new TextContentProcessor();
                formatedTextClone = tcp.CreateFormatedText(
                    Document, new XElement(Node));
            }

            return(formatedTextClone);
        }
 protected Paragraph addTitle (String text)
 {
     addNewline ();
     Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
     FormatedText formText = new FormatedText(document, "T1", text);
     formText.TextStyle = BOLD_UNDERLINE_STYLE;
     paragraph.TextContent.Add(formText);
     //paragraph.ParagraphStyle = new ParagraphStyle (document, "foo");
     //paragraph.ParagraphStyle.ParagraphProperties.Alignment = TextAlignments.center.ToString ();
     document.Content.Add(paragraph);
     addNewline ();
     return paragraph;
 }
        public void AddHeader (int rowIdx, String[] values)
        {
            for (int i = 0, max = values.Length; i < max; i++) {
                Cell cell = table.CreateCell ();
                cell.OfficeValueType = "string";

                Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(document);
                FormatedText formText = new FormatedText(document, "T1", values[i]);
                formText.TextStyle = BOLD_STYLE;
                paragraph.TextContent.Add(formText);
                cell.Content.Add(paragraph);

                table.InsertCellAt(rowIdx, i, cell);
            }
        }
		public void ParagraphFormatedText()
		{
			//Create a new text document
			TextDocument document					= new TextDocument();
			document.New();
			//Create a standard paragraph using the ParagraphBuilder
			Paragraph paragraph						= ParagraphBuilder.CreateStandardTextParagraph(document);
			//Add some formated text
			FormatedText formText					= new FormatedText(document, "T1", "Some formated text!");
			formText.TextStyle.TextProperties.Bold	= "bold";
			paragraph.TextContent.Add(formText);
			//Add the paragraph to the document
			document.Content.Add(paragraph);
			//Save empty
			document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"formated.odt");
		}
 void Example15()
 {
     //Create a new text document
     TextDocument document = new TextDocument();
     document.New();
     //Create a standard paragraph using the ParagraphBuilder
     Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
     //Add some formated text
     FormatedText formText = new FormatedText(document, "T1", "Some formated text!");
     formText.TextStyle.TextProperties.Bold = "bold";
     paragraph.TextContent.Add(formText);
     //Add the paragraph to the document
     document.Content.Add(paragraph);
     //Save
     document.SaveTo("example15_formated.odt");
 }
		/// <summary>
		/// Gets the formated text as HTML.
		/// </summary>
		/// <param name="formatedText">The formated text.</param>
		/// <returns></returns>
		public string GetFormatedTextAsHtml(FormatedText formatedText)
		{
			string html					= "<span ";

			try
			{
				if (formatedText.TextContent != null)
				{
					string textStyle	= "";
					if (formatedText.TextStyle != null)
						textStyle		= this.HTMLStyleBuilder.GetTextStyleAsHtml(formatedText.TextStyle.TextProperties);
					if (textStyle.Length > 0)
					{
						html			+= textStyle;						
					}
					else
					{
						//Check again a possible common style
						string commonstyle	= "";
						IStyle iStyle	= formatedText.Document.CommonStyles.GetStyleByName(formatedText.StyleName);
						if (iStyle != null && iStyle is TextStyle)
						{
							commonstyle	= this.HTMLStyleBuilder.GetTextStyleAsHtml(((TextStyle)iStyle).TextProperties);
							if (commonstyle.Length > 0)
								html	+= commonstyle;
						}
					}
					html			+= ">\n";

					string textContent	= this.GetITextCollectionAsHtml(formatedText.TextContent, null);
					if (textContent.Length > 0)
					{
//						textContent		= textContent.Replace("<", "&lt;");
//						textContent		= textContent.Replace(">", "&gt;");
						html			+= textContent;
					}
				}
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to build a HTML string from a FormatedText object.", ex);
			}

			
			if (!html.Equals("<span "))
				html				+= "</span>\n";
			else
				html				= "";

			return html;
		}
		/// <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;
		}
		public void CreateTableFormatedText()
		{
			//Create new spreadsheet document
			_spreadsheetDocument3		= new SpreadsheetDocument();
			_spreadsheetDocument3.Load(AARunMeFirstAndOnce.inPutFolder+@"blank.ods");
			//Create a new table
			Table table					= new Table(_spreadsheetDocument3, "First", "tablefirst");
			table.Rows.Add(new Row(table));
			//Create a new cell, without any extra styles 
			Cell cell								= table.CreateCell();
			cell.OfficeValueType					= "string";
			//Set full border
			//cell.CellStyle.CellProperties.Border	= Border.NormalSolid;			
			//Add a paragraph to this cell
			Paragraph paragraph						= ParagraphBuilder.CreateSpreadsheetParagraph(
				_spreadsheetDocument3);
			//Create some Formated text
			FormatedText fText						= new FormatedText(_spreadsheetDocument3, "T1", "Some Text");
			//fText.TextStyle.TextProperties.Bold		 = "bold";
			fText.TextStyle.TextProperties.Underline = LineStyles.dotted;
			//Add formated text
			paragraph.TextContent.Add(fText);
			//Add paragraph to the cell
			cell.Content.Add(paragraph);
			//Insert the cell at row index 2 and column index 3
			//All need rows, columns and cells below the given
			//indexes will be build automatically.
			table.InsertCellAt(2, 3, cell);
			//Insert table into the spreadsheet document
			_spreadsheetDocument3.TableCollection.Add(table);
			// Test inserted content
			Object insertedText = ((Paragraph)_spreadsheetDocument3.TableCollection[0].Rows[2].Cells[3].Content[0]).TextContent[0];
			Assert.AreEqual(fText, insertedText as FormatedText);
		}
 public void CreateTableFormatedText()
 {
     //Create new spreadsheet document
     SpreadsheetDocument spreadsheetDocument		= new SpreadsheetDocument();
     spreadsheetDocument.New();
     //Create a new table
     Table table					= new Table(spreadsheetDocument, "First", "tablefirst");
     //Create a new cell, without any extra styles
     Cell cell								= table.CreateCell();
     //cell.OfficeValueType					= "string";
     //Set full border
     //cell.CellStyle.CellProperties.Border	= Border.NormalSolid;
     //Add a paragraph to this cell
     Paragraph paragraph						= ParagraphBuilder.CreateSpreadsheetParagraph(
         spreadsheetDocument);
     //Create some Formated text
     FormatedText fText						= new FormatedText(spreadsheetDocument, "T1", "Some Text");
     //fText.TextStyle.TextProperties.Bold		 = "bold";
     fText.TextStyle.TextProperties.Underline = LineStyles.dotted;
     //Add formated text
     paragraph.TextContent.Add(fText);
     //Add paragraph to the cell
     cell.Content.Add(paragraph);
     //Insert the cell at row index 2 and column index 3
     //All need rows, columns and cells below the given
     //indexes will be build automatically.
     table.InsertCellAt(2, 3, cell);
     //Insert table into the spreadsheet document
     spreadsheetDocument.TableCollection.Add(table);
     spreadsheetDocument.SaveTo(AARunMeFirstAndOnce.outPutFolder+"formated.ods");
 }
		public void HeaderAndFooterCreateTest()
		{
			TextDocument document = new TextDocument();
			document.New();
			// get default mast page layout
			TextMasterPage txtMP = document.TextMasterPageCollection.GetDefaultMasterPage();
			// IMPORTANT: activating header and footer usage
			// has to be called before setting there layout properties!
			txtMP.ActivatePageHeaderAndFooter();
			Console.WriteLine(txtMP.TextPageHeader.MarginLeft);
			// set page header layout
//			txtMP.TextPageHeader.MarginLeft = "4cm";
//			// set text page layout
//			txtMP.TextPageLayout.MarginLeft = "6cm";
//			// create a paragraph for the header
			Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
			// add some formated text
			// TODO: FIXME there is a bug with the text styles for header and footer!
			FormatedText formText =  new FormatedText(document, "T1", "Some formated text in the page header ...");
			formText.TextStyle.TextProperties.Bold = "bold";
			paragraph.TextContent.Add(formText);
			// add this paragraph to the page header
			txtMP.TextPageHeader.ContentCollection.Add(paragraph);
			// create a paragraph collection with some text for the document
//			ParagraphCollection pColl = AODL.Document.Content.Text.ParagraphBuilder.CreateParagraphCollection(
//				document,
//				"Some text in here ... \n\n... with a modified master page :)",
//				true,
//				ParagraphBuilder.ParagraphSeperator);
//			// add the paragraphs
//			foreach(AODL.Document.Content.Text.Paragraph p in pColl)
//				document.Content.Add(p);
			// save the document
			document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"text_master_page_1.odt");
		}
        /// <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;
            }
        }