From 911e4c71c7007f02ff668adc823c70011d04059c Mon Sep 17 00:00:00 2001 From: psoares33 Date: Sun, 28 Jun 2009 19:35:18 +0000 Subject: [PATCH] Porting update. git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@42 820d3149-562b-4f88-9aa4-a8e61a3485cf --- .../iTextSharp/text/pdf/PdfCopyFieldsImp.cs | 2 +- src/core/iTextSharp/text/rtf/RtfMapper.cs | 11 +- src/core/iTextSharp/text/rtf/RtfWriter2.cs | 42 +- .../text/rtf/document/RtfCodePage.cs | 2 +- .../text/rtf/document/RtfDocument.cs | 11 + .../text/rtf/document/RtfDocumentHeader.cs | 10 + .../text/rtf/document/RtfDocumentSettings.cs | 2 +- .../text/rtf/document/RtfGenerator.cs | 2 +- .../text/rtf/document/RtfInfoGroup.cs | 2 +- .../text/rtf/document/RtfPageSetting.cs | 6 +- .../iTextSharp/text/rtf/graphic/RtfShape.cs | 5 +- src/core/iTextSharp/text/rtf/list/RtfList.cs | 743 ++++++++++-------- .../iTextSharp/text/rtf/list/RtfListItem.cs | 57 +- .../iTextSharp/text/rtf/list/RtfListTable.cs | 77 +- .../text/rtf/parser/RtfImportMappings.cs | 4 +- .../text/rtf/parser/RtfImportMgr.cs | 44 +- .../iTextSharp/text/rtf/parser/RtfParser.cs | 67 +- .../parser/ctrlwords/RtfCtrlWordHandler.cs | 6 +- .../rtf/parser/ctrlwords/RtfCtrlWordMap.cs | 7 +- .../destinations/RtfDestinationDocument.cs | 2 + .../destinations/RtfDestinationListTable.cs | 241 +++++- .../destinations/RtfDestinationShppict.cs | 11 +- .../iTextSharp/text/rtf/style/RtfColorList.cs | 2 +- src/core/iTextSharp/text/rtf/style/RtfFont.cs | 3 + .../iTextSharp/text/rtf/style/RtfFontList.cs | 2 +- .../text/rtf/style/RtfParagraphStyle.cs | 4 +- .../text/rtf/style/RtfStylesheetList.cs | 8 +- .../iTextSharp/text/rtf/table/RtfBorder.cs | 4 +- src/core/iTextSharp/text/rtf/table/RtfCell.cs | 199 ++++- src/core/iTextSharp/text/rtf/table/RtfRow.cs | 55 +- .../iTextSharp/text/rtf/table/RtfTable.cs | 41 + .../iTextSharp/text/rtf/text/RtfParagraph.cs | 4 +- src/core/itextsharp.csproj | 20 + 33 files changed, 1202 insertions(+), 494 deletions(-) diff --git a/src/core/iTextSharp/text/pdf/PdfCopyFieldsImp.cs b/src/core/iTextSharp/text/pdf/PdfCopyFieldsImp.cs index 30e241c..80f5f14 100644 --- a/src/core/iTextSharp/text/pdf/PdfCopyFieldsImp.cs +++ b/src/core/iTextSharp/text/pdf/PdfCopyFieldsImp.cs @@ -495,7 +495,7 @@ namespace iTextSharp.text.pdf { } } - internal void MergeFields() { + internal virtual void MergeFields() { int pageOffset = 0; for (int k = 0; k < fields.Count; ++k) { Hashtable fd = ((AcroFields)fields[k]).Fields; diff --git a/src/core/iTextSharp/text/rtf/RtfMapper.cs b/src/core/iTextSharp/text/rtf/RtfMapper.cs index 0b0d2c0..8ad9280 100644 --- a/src/core/iTextSharp/text/rtf/RtfMapper.cs +++ b/src/core/iTextSharp/text/rtf/RtfMapper.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using iTextSharp.text; +using iTextSharp.text.pdf; using iTextSharp.text.rtf.document; using iTextSharp.text.rtf.field; using iTextSharp.text.rtf.graphic; @@ -104,7 +105,7 @@ namespace iTextSharp.text.rtf { Chunk chunk = (Chunk) element; if (chunk.HasAttributes()) { if (chunk.Attributes.ContainsKey(Chunk.IMAGE)) { - rtfElements.Add(new RtfImage(rtfDoc, (Image) chunk.Attributes[Chunk.IMAGE])); + rtfElements.Add(new RtfImage(rtfDoc, chunk.GetImage())); } else if (chunk.Attributes.ContainsKey(Chunk.NEWPAGE)) { rtfElements.Add(new RtfNewPage(rtfDoc)); } else if (chunk.Attributes.ContainsKey(Chunk.TAB)) { @@ -165,6 +166,14 @@ namespace iTextSharp.text.rtf { rtfElements.Add(new RtfTable(rtfDoc, ((SimpleTable) element).CreateTable())); } break; + case Element.PTABLE: + try { + rtfElements.Add(new RtfTable(rtfDoc, (PdfPTable) element)); + } + catch(InvalidCastException) { + rtfElements.Add(new RtfTable(rtfDoc, ((SimpleTable) element).CreateTable())); + } + break; } return (IRtfBasicElement[]) rtfElements.ToArray(typeof(IRtfBasicElement)); diff --git a/src/core/iTextSharp/text/rtf/RtfWriter2.cs b/src/core/iTextSharp/text/rtf/RtfWriter2.cs index 314d993..1ee05ee 100644 --- a/src/core/iTextSharp/text/rtf/RtfWriter2.cs +++ b/src/core/iTextSharp/text/rtf/RtfWriter2.cs @@ -275,7 +275,7 @@ namespace iTextSharp.text.rtf { if(!this.open) { throw new DocumentException("The document must be open to import RTF documents."); } - RtfParser rtfImport = new RtfParser(); + RtfParser rtfImport = new RtfParser(this.document); if(events != null) { for(int idx=0;idxRtfListTable object. + * + * @return the ListTable object. + * @since 2.1.3 + */ + public RtfListTable GetListTable() { + return this.listTable; + } } } \ No newline at end of file diff --git a/src/core/iTextSharp/text/rtf/document/RtfDocumentSettings.cs b/src/core/iTextSharp/text/rtf/document/RtfDocumentSettings.cs index 28a064e..e9a90a2 100644 --- a/src/core/iTextSharp/text/rtf/document/RtfDocumentSettings.cs +++ b/src/core/iTextSharp/text/rtf/document/RtfDocumentSettings.cs @@ -76,7 +76,7 @@ namespace iTextSharp.text.rtf.document { /** * Whether to output the line breaks that make the rtf document source more readable. */ - private bool outputDebugLineBreaks = true; + private bool outputDebugLineBreaks = false; /** * Whether to always generate soft linebreaks for \n in Chunks. */ diff --git a/src/core/iTextSharp/text/rtf/document/RtfGenerator.cs b/src/core/iTextSharp/text/rtf/document/RtfGenerator.cs index 8f03af8..81124e4 100644 --- a/src/core/iTextSharp/text/rtf/document/RtfGenerator.cs +++ b/src/core/iTextSharp/text/rtf/document/RtfGenerator.cs @@ -86,7 +86,7 @@ namespace iTextSharp.text.rtf.document { byte[] t; result.Write(t = DocWriter.GetISOBytes(Document.Version), 0, t.Length); result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } } } diff --git a/src/core/iTextSharp/text/rtf/document/RtfInfoGroup.cs b/src/core/iTextSharp/text/rtf/document/RtfInfoGroup.cs index 9b0ffd6..aefc3bd 100644 --- a/src/core/iTextSharp/text/rtf/document/RtfInfoGroup.cs +++ b/src/core/iTextSharp/text/rtf/document/RtfInfoGroup.cs @@ -119,7 +119,7 @@ namespace iTextSharp.text.rtf.document { result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } } } \ No newline at end of file diff --git a/src/core/iTextSharp/text/rtf/document/RtfPageSetting.cs b/src/core/iTextSharp/text/rtf/document/RtfPageSetting.cs index 129cd76..acefefb 100644 --- a/src/core/iTextSharp/text/rtf/document/RtfPageSetting.cs +++ b/src/core/iTextSharp/text/rtf/document/RtfPageSetting.cs @@ -177,7 +177,7 @@ namespace iTextSharp.text.rtf.document { result.Write(t = IntToByteArray(marginTop), 0, t.Length); result.Write(MARGIN_BOTTOM, 0, MARGIN_BOTTOM.Length); result.Write(t = IntToByteArray(marginBottom), 0, t.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } /** @@ -193,13 +193,13 @@ namespace iTextSharp.text.rtf.document { result.Write(t = IntToByteArray(pageWidth), 0, t.Length); result.Write(SECTION_PAGE_HEIGHT, 0, SECTION_PAGE_HEIGHT.Length); result.Write(t = IntToByteArray(pageHeight), 0, t.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } else { result.Write(SECTION_PAGE_WIDTH, 0, SECTION_PAGE_WIDTH.Length); result.Write(t = IntToByteArray(pageWidth), 0, t.Length); result.Write(SECTION_PAGE_HEIGHT, 0, SECTION_PAGE_HEIGHT.Length); result.Write(t = IntToByteArray(pageHeight), 0, t.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } result.Write(SECTION_MARGIN_LEFT, 0, SECTION_MARGIN_LEFT.Length); result.Write(t = IntToByteArray(marginLeft), 0, t.Length); diff --git a/src/core/iTextSharp/text/rtf/graphic/RtfShape.cs b/src/core/iTextSharp/text/rtf/graphic/RtfShape.cs index 9e06101..4ae448f 100644 --- a/src/core/iTextSharp/text/rtf/graphic/RtfShape.cs +++ b/src/core/iTextSharp/text/rtf/graphic/RtfShape.cs @@ -257,6 +257,7 @@ namespace iTextSharp.text.rtf.graphic { * @param property The property to set for this RtfShape. */ public void SetProperty(RtfShapeProperty property) { + property.SetRtfDocument(this.doc); this.properties[property.GetName()] = property; } @@ -370,9 +371,7 @@ namespace iTextSharp.text.rtf.graphic { result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length); } result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length); - if (this.doc.GetDocumentSettings().IsOutputDebugLineBreaks()) { - result.WriteByte((byte)'\n'); - } + this.doc.OutputDebugLinebreak(result); result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length); } } diff --git a/src/core/iTextSharp/text/rtf/list/RtfList.cs b/src/core/iTextSharp/text/rtf/list/RtfList.cs index a562634..af44806 100644 --- a/src/core/iTextSharp/text/rtf/list/RtfList.cs +++ b/src/core/iTextSharp/text/rtf/list/RtfList.cs @@ -4,7 +4,7 @@ using System.Collections; using iTextSharp.text; using iTextSharp.text.rtf; using iTextSharp.text.rtf.document; -using ST = iTextSharp.text.rtf.style; +using iTextSharp.text.rtf.style; using iTextSharp.text.rtf.text; using iTextSharp.text.factories; /* @@ -71,313 +71,323 @@ namespace iTextSharp.text.rtf.list { public class RtfList : RtfElement, IRtfExtendedElement { /** - * Constant for list level + * Constant for the list number + * @since 2.1.3 */ - private static byte[] LIST_LEVEL = DocWriter.GetISOBytes("\\listlevel"); + public static readonly byte[] LIST_NUMBER = DocWriter.GetISOBytes("\\ls"); + /** - * Constant for list level style old + * Constant for the list */ - private static byte[] LIST_LEVEL_TYPE = DocWriter.GetISOBytes("\\levelnfc"); + private static readonly byte[] LIST = DocWriter.GetISOBytes("\\list"); /** - * Constant for list level style new + * Constant for the list id + * @since 2.1.3 */ - private static byte[] LIST_LEVEL_TYPE_NEW = DocWriter.GetISOBytes("\\levelnfcn"); + public static readonly byte[] LIST_ID = DocWriter.GetISOBytes("\\listid"); /** - * Constant for list level alignment old + * Constant for the list template id */ - private static byte[] LIST_LEVEL_ALIGNMENT = DocWriter.GetISOBytes("\\leveljc"); + private static readonly byte[] LIST_TEMPLATE_ID = DocWriter.GetISOBytes("\\listtemplateid"); /** - * Constant for list level alignment new + * Constant for the simple list */ - private static byte[] LIST_LEVEL_ALIGNMENT_NEW = DocWriter.GetISOBytes("\\leveljcn"); + private static readonly byte[] LIST_SIMPLE = DocWriter.GetISOBytes("\\listsimple"); /** - * Constant for list level start at + * Constant for the hybrid list */ - private static byte[] LIST_LEVEL_START_AT = DocWriter.GetISOBytes("\\levelstartat"); + private static readonly byte[] LIST_HYBRID = DocWriter.GetISOBytes("\\listhybrid"); /** - * Constant for list level text + * Constant to indicate if the list restarts at each section. Word 7 compatiblity */ - private static byte[] LIST_LEVEL_TEXT = DocWriter.GetISOBytes("\\leveltext"); + private static readonly byte[] LIST_RESTARTHDN = DocWriter.GetISOBytes("\\listrestarthdn"); /** - * Constant for the beginning of the list level numbered style + * Constant for the name of this list */ - private static byte[] LIST_LEVEL_STYLE_NUMBERED_BEGIN = DocWriter.GetISOBytes("\\\'02\\\'"); + private static readonly byte[] LIST_NAME = DocWriter.GetISOBytes("\\listname"); /** - * Constant for the end of the list level numbered style + * Constant for the identifier of the style of this list. Mutually exclusive with \\liststylename */ - private static byte[] LIST_LEVEL_STYLE_NUMBERED_END = DocWriter.GetISOBytes(".;"); + private static readonly byte[] LIST_STYLEID = DocWriter.GetISOBytes("\\liststyleid"); /** - * Constant for the beginning of the list level bulleted style + * Constant for the identifier of the style of this list. Mutually exclusive with \\liststyleid */ - private static byte[] LIST_LEVEL_STYLE_BULLETED_BEGIN = DocWriter.GetISOBytes("\\\'01"); - /** - * Constant for the end of the list level bulleted style - */ - private static byte[] LIST_LEVEL_STYLE_BULLETED_END = DocWriter.GetISOBytes(";"); - /** - * Constant for the beginning of the list level numbers - */ - private static byte[] LIST_LEVEL_NUMBERS_BEGIN = DocWriter.GetISOBytes("\\levelnumbers"); - /** - * Constant for the list level numbers - */ - private static byte[] LIST_LEVEL_NUMBERS_NUMBERED = DocWriter.GetISOBytes("\\\'01"); - /** - * Constant for the end of the list level numbers - */ - private static byte[] LIST_LEVEL_NUMBERS_END = DocWriter.GetISOBytes(";"); - /** - * Constant for the first indentation - */ - private static byte[] LIST_LEVEL_FIRST_INDENT = DocWriter.GetISOBytes("\\fi"); - /** - * Constant for the symbol indentation - */ - private static byte[] LIST_LEVEL_SYMBOL_INDENT = DocWriter.GetISOBytes("\\tx"); + private static readonly byte[] LIST_STYLENAME = DocWriter.GetISOBytes("\\liststylename"); + + // character properties /** * Constant for the list level value + * @since 2.1.3 */ - private static byte[] LIST_LEVEL_NUMBER = DocWriter.GetISOBytes("\\ilvl"); - /** - * Constant for a tab character - */ - private static byte[] TAB = DocWriter.GetISOBytes("\\tab"); + public static readonly byte[] LIST_LEVEL_NUMBER = DocWriter.GetISOBytes("\\ilvl"); + + /** * Constant for the old list text + * @since 2.1.3 */ - private static byte[] LIST_TEXT = DocWriter.GetISOBytes("\\listtext"); + public static readonly byte[] LIST_TEXT = DocWriter.GetISOBytes("\\listtext"); /** * Constant for the old list number end + * @since 2.1.3 */ - private static byte[] LIST_NUMBER_END = DocWriter.GetISOBytes("."); + public static readonly byte[] LIST_NUMBER_END = DocWriter.GetISOBytes("."); + - private const int LIST_TYPE_BULLET = 0; - private const int LIST_TYPE_NUMBERED = 1; - private const int LIST_TYPE_UPPER_LETTERS = 2; - private const int LIST_TYPE_LOWER_LETTERS = 3; - private const int LIST_TYPE_UPPER_ROMAN = 4; - private const int LIST_TYPE_LOWER_ROMAN = 5; + /** + * Constant for a tab character + * @since 2.1.3 + */ + public static readonly byte[] TAB = DocWriter.GetISOBytes("\\tab"); + /** * The subitems of this RtfList */ private ArrayList items; + /** - * The level of this RtfList + * The parent list if there is one. */ - private int listLevel = 0; + private RtfList parentList = null; + /** - * The first indentation of this RtfList + * The list id */ - private int firstIndent = 0; + private int listID = -1; + /** - * The left indentation of this RtfList + * List type of NORMAL - no control word + * @since 2.1.3 */ - private int leftIndent = 0; + public const int LIST_TYPE_NORMAL = 0; /* Normal list type */ + /** - * The right indentation of this RtfList + * List type of listsimple + * @since 2.1.3 */ - private int rightIndent = 0; + public const int LIST_TYPE_SIMPLE = 1; /* Simple list type */ + /** - * The symbol indentation of this RtfList + * List type of listhybrid + * @since 2.1.3 */ - private int symbolIndent = 0; + public const int LIST_TYPE_HYBRID = 2; /* Hybrid list type */ + + /** + * This RtfList type + */ + private int listType = LIST_TYPE_HYBRID; + + /** + * The name of the list if it exists + */ + private String name = null; + /** * The list number of this RtfList */ - private int listNumber = 1; - /** - * Whether this RtfList is numbered - */ - private int listType = LIST_TYPE_BULLET; - /** - * The number to start counting at - */ - private int listStartAt = 1; - /** - * The RtfFont for numbered lists - */ - private ST.RtfFont fontNumber; - /** - * The RtfFont for bulleted lists - */ - private ST.RtfFont fontBullet; - /** - * The alignment of this RtfList - */ - private int alignment = Element.ALIGN_LEFT; + private int listNumber = -1; /** - * The parent List in multi-level lists. + * The RtfList lists managed by this RtfListTable */ - private RtfList parentList = null; + private ArrayList listLevels = null; + + /** - * The text to use as the bullet character + * Constructs an empty RtfList object. + * @since 2.1.3 */ - private String bulletCharacter = "\u00b7"; + public RtfList() : base(null) { + CreateDefaultLevels(); + } + + /** + * Set the document. + * @param doc The RtfDocument + * @since 2.1.3 + */ + public void SetDocument(RtfDocument doc) { + this.document = doc; + // get the list number or create a new one adding it to the table + this.listNumber = document.GetDocumentHeader().GetListNumber(this); + + + } + /** + * Constructs an empty RtfList object. + * @param doc The RtfDocument this RtfList belongs to + * @since 2.1.3 + */ + public RtfList(RtfDocument doc) : base(doc) { + CreateDefaultLevels(); + // get the list number or create a new one adding it to the table + this.listNumber = document.GetDocumentHeader().GetListNumber(this); + + } + /** * Constructs a new RtfList for the specified List. * * @param doc The RtfDocument this RtfList belongs to * @param list The List this RtfList is based on + * @since 2.1.3 */ public RtfList(RtfDocument doc, List list) : base(doc) { + // setup the listlevels + // Then, setup the list data below - this.listNumber = document.GetDocumentHeader().GetListNumber(this); + // setup 1 listlevel if it's a simple list + // setup 9 if it's a regular list + // setup 9 if it's a hybrid list (default) + CreateDefaultLevels(); + + this.items = new ArrayList(); // list content + RtfListLevel ll = (RtfListLevel)this.listLevels[0]; + + // get the list number or create a new one adding it to the table + this.listNumber = document.GetDocumentHeader().GetListNumber(this); - this.items = new ArrayList(); if (list.SymbolIndent > 0 && list.IndentationLeft > 0) { - this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1); - this.leftIndent = (int) ((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR); + ll.SetFirstIndent((int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1)); + ll.SetLeftIndent((int) ((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR)); } else if (list.SymbolIndent > 0) { - this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1); - this.leftIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR); + ll.SetFirstIndent((int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1)); + ll.SetLeftIndent((int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR)); } else if (list.IndentationLeft > 0) { - this.firstIndent = 0; - this.leftIndent = (int) (list.IndentationLeft * RtfElement.TWIPS_FACTOR); + ll.SetFirstIndent(0); + ll.SetLeftIndent((int) (list.IndentationLeft * RtfElement.TWIPS_FACTOR)); } else { - this.firstIndent = 0; - this.leftIndent = 0; + ll.SetFirstIndent(0); + ll.SetLeftIndent(0); } - this.rightIndent = (int) (list.IndentationRight * RtfElement.TWIPS_FACTOR); - this.symbolIndent = (int) ((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR); + ll.SetRightIndent((int) (list.IndentationRight * RtfElement.TWIPS_FACTOR)); + ll.SetSymbolIndent((int) ((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR)); + ll.CorrectIndentation(); + ll.SetTentative(false); + if (list is RomanList) { if (list.Lowercase) { - this.listType = LIST_TYPE_LOWER_ROMAN; + ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_ROMAN); } else { - this.listType = LIST_TYPE_UPPER_ROMAN; + ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_ROMAN); } } else if (list.Numbered) { - this.listType = LIST_TYPE_NUMBERED; + ll.SetListType(RtfListLevel.LIST_TYPE_NUMBERED); } else if (list.Lettered) { if (list.Lowercase) { - this.listType = LIST_TYPE_LOWER_LETTERS; + ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_LETTERS); } else { - this.listType = LIST_TYPE_UPPER_LETTERS; + ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_LETTERS); } - } - this.listStartAt = list.First; - if(this.listStartAt < 1) { - this.listStartAt = 1; + } + else { + // Paragraph p = new Paragraph(); + // p.Add(new Chunk(list.GetPreSymbol()) ); + // p.Add(list.GetSymbol()); + // p.Add(new Chunk(list.GetPostSymbol()) ); + // ll.SetBulletChunk(list.GetSymbol()); + ll.SetBulletCharacter(list.PreSymbol + list.Symbol.Content + list.PostSymbol); + ll.SetListType(RtfListLevel.LIST_TYPE_BULLET); } + // now setup the actual list contents. for (int i = 0; i < list.Items.Count; i++) { try { IElement element = (IElement) list.Items[i]; + if (element.Type == Element.CHUNK) { element = new ListItem((Chunk) element); } if (element is ListItem) { - this.alignment = ((ListItem) element).Alignment; + ll.SetAlignment(((ListItem) element).Alignment); } IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(element); - for(int j = 0; j < rtfElements.Length; j++) { + for (int j = 0; j < rtfElements.Length; j++) { IRtfBasicElement rtfElement = rtfElements[j]; if (rtfElement is RtfList) { - ((RtfList) rtfElement).SetListNumber(listNumber); - ((RtfList) rtfElement).SetListLevel(listLevel + 1); - ((RtfList) rtfElement).SetParent(this); + ((RtfList) rtfElement).SetParentList(this); } else if (rtfElement is RtfListItem) { - ((RtfListItem) rtfElement).SetParent(this); - ((RtfListItem) rtfElement).InheritListSettings(listNumber, listLevel + 1); + ((RtfListItem) rtfElement).SetParent(ll); } + ll.SetFontNumber( new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))) ); + if (list.Symbol != null && list.Symbol.Font != null && !list.Symbol.Content.StartsWith("-") && list.Symbol.Content.Length > 0) { + // only set this to bullet symbol is not default + ll.SetBulletFont( list.Symbol.Font); + ll.SetBulletCharacter(list.Symbol.Content.Substring(0, 1)); + } else + if (list.Symbol != null && list.Symbol.Font != null) { + ll.SetBulletFont(list.Symbol.Font); + + } else { + ll.SetBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0))); + } items.Add(rtfElement); } - } catch (DocumentException ) { + + } catch (DocumentException) { } } - - fontNumber = new ST.RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))); - if (list.Symbol != null && list.Symbol.Font != null && !list.Symbol.Content.StartsWith("-") && list.Symbol.Content.Length > 0) { - // only set this to bullet symbol is not default - this.fontBullet = new ST.RtfFont(document, list.Symbol.Font); - this.bulletCharacter = list.Symbol.Content.Substring(0, 1); - } else { - this.fontBullet = new ST.RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0))); - } - } - - /** - * Write the indentation values for this RtfList. - * - * @param result The OutputStream to write to. - * @throws IOException On i/o errors. - */ - private void WriteIndentation(Stream result) { - byte[] t; - result.Write(LIST_LEVEL_FIRST_INDENT, 0, LIST_LEVEL_FIRST_INDENT.Length); - result.Write(t = IntToByteArray(firstIndent), 0, t.Length); - result.Write(ST.RtfParagraphStyle.INDENT_LEFT, 0, ST.RtfParagraphStyle.INDENT_LEFT.Length); - result.Write(t = IntToByteArray(leftIndent), 0, t.Length); - result.Write(ST.RtfParagraphStyle.INDENT_RIGHT, 0, ST.RtfParagraphStyle.INDENT_RIGHT.Length); - result.Write(t = IntToByteArray(rightIndent), 0, t.Length); } /** * Writes the definition part of this list level + * @param result + * @throws IOException + * @since 2.1.3 */ - public virtual void WriteDefinition(Stream result) { + public void WriteDefinition(Stream result) + { byte[] t; result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); - result.Write(LIST_LEVEL, 0, LIST_LEVEL.Length); - result.Write(LIST_LEVEL_TYPE, 0, LIST_LEVEL_TYPE.Length); + result.Write(LIST, 0, LIST.Length); + result.Write(LIST_TEMPLATE_ID, 0, LIST_TEMPLATE_ID.Length); + result.Write(t = IntToByteArray(document.GetRandomInt()), 0, t.Length); + + int levelsToWrite = -1; + switch (this.listType) { - case LIST_TYPE_BULLET : result.Write(t = IntToByteArray(23), 0, t.Length); break; - case LIST_TYPE_NUMBERED : result.Write(t = IntToByteArray(0), 0, t.Length); break; - case LIST_TYPE_UPPER_LETTERS : result.Write(t = IntToByteArray(3), 0, t.Length); break; - case LIST_TYPE_LOWER_LETTERS : result.Write(t = IntToByteArray(4), 0, t.Length); break; - case LIST_TYPE_UPPER_ROMAN : result.Write(t = IntToByteArray(1), 0, t.Length); break; - case LIST_TYPE_LOWER_ROMAN : result.Write(t = IntToByteArray(2), 0, t.Length); break; + case LIST_TYPE_NORMAL: + levelsToWrite = listLevels.Count; + break; + case LIST_TYPE_SIMPLE: + result.Write(LIST_SIMPLE, 0, LIST_SIMPLE.Length); + result.Write(t = IntToByteArray(1), 0, t.Length); + levelsToWrite = 1; + break; + case LIST_TYPE_HYBRID: + result.Write(LIST_HYBRID, 0, LIST_HYBRID.Length); + levelsToWrite = listLevels.Count; + break; + default: + break; } - result.Write(LIST_LEVEL_TYPE_NEW, 0, LIST_LEVEL_TYPE_NEW.Length); - switch (this.listType) { - case LIST_TYPE_BULLET : result.Write(t = IntToByteArray(23), 0, t.Length); break; - case LIST_TYPE_NUMBERED : result.Write(t = IntToByteArray(0), 0, t.Length); break; - case LIST_TYPE_UPPER_LETTERS : result.Write(t = IntToByteArray(3), 0, t.Length); break; - case LIST_TYPE_LOWER_LETTERS : result.Write(t = IntToByteArray(4), 0, t.Length); break; - case LIST_TYPE_UPPER_ROMAN : result.Write(t = IntToByteArray(1), 0, t.Length); break; - case LIST_TYPE_LOWER_ROMAN : result.Write(t = IntToByteArray(2), 0, t.Length); break; - } - result.Write(LIST_LEVEL_ALIGNMENT, 0, LIST_LEVEL_ALIGNMENT.Length); - result.Write(t = IntToByteArray(0), 0, t.Length); - result.Write(LIST_LEVEL_ALIGNMENT_NEW, 0, LIST_LEVEL_ALIGNMENT_NEW.Length); - result.Write(t = IntToByteArray(0), 0, t.Length); - result.Write(LIST_LEVEL_START_AT, 0, LIST_LEVEL_START_AT.Length); - result.Write(t = IntToByteArray(this.listStartAt), 0, t.Length); - result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); - result.Write(LIST_LEVEL_TEXT, 0, LIST_LEVEL_TEXT.Length); - if (this.listType != LIST_TYPE_BULLET) { - result.Write(LIST_LEVEL_STYLE_NUMBERED_BEGIN, 0, LIST_LEVEL_STYLE_NUMBERED_BEGIN.Length); - if (listLevel < 10) { - result.Write(t = IntToByteArray(0), 0, t.Length); - } - result.Write(t = IntToByteArray(listLevel), 0, t.Length); - result.Write(LIST_LEVEL_STYLE_NUMBERED_END, 0, LIST_LEVEL_STYLE_NUMBERED_END.Length); - } else { - result.Write(LIST_LEVEL_STYLE_BULLETED_BEGIN, 0, LIST_LEVEL_STYLE_BULLETED_BEGIN.Length); - this.document.FilterSpecialChar(result, this.bulletCharacter, false, false); - result.Write(LIST_LEVEL_STYLE_BULLETED_END, 0, LIST_LEVEL_STYLE_BULLETED_END.Length); + this.document.OutputDebugLinebreak(result); + + // TODO: Figure out hybrid because multi-level hybrid does not work. + // Seems hybrid is mixed type all single level - Simple = single level + // SIMPLE1/HYRBID + // 1. Line 1 + // 2. Line 2 + // MULTI-LEVEL LISTS Are Simple0 - 9 levels (0-8) all single digit + // 1. Line 1 + // 1.1. Line 1.1 + // 1.2. Line 1.2 + // 2. Line 2 + + // write the listlevels here + for (int i = 0; i 0) { - result.Write(t = DocWriter.GetISOBytes("\\tx"), 0, t.Length); - result.Write(t = IntToByteArray(this.leftIndent), 0, t.Length); - } - } - - /** - * Writes only the list number and list level number. - * - * @return The list number and list level number of this RtfList. - */ - protected void WriteListNumbers(Stream result) { - byte[] t; - result.Write(RtfListTable.LIST_NUMBER, 0, RtfListTable.LIST_NUMBER.Length); - result.Write(t = IntToByteArray(listNumber), 0, t.Length); - if (listLevel > 0) { - result.Write(LIST_LEVEL_NUMBER, 0, LIST_LEVEL_NUMBER.Length); - result.Write(t = IntToByteArray(listLevel), 0, t.Length); + } } } /** * Writes the content of the RtfList + * @since 2.1.3 */ - public override void WriteContent(Stream result) { - if (this.listLevel == 0) { - CorrectIndentation(); - } - byte[] t; + public override void WriteContent(Stream result) + { if (!this.inTable) { result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); } + int itemNr = 0; + if (items != null) { for (int i = 0; i < items.Count; i++) { - RtfElement rtfElement = (RtfElement) items[i]; - if (rtfElement is RtfListItem) { + + RtfElement thisRtfElement = (RtfElement) items[i]; + //thisRtfElement.WriteContent(result); + if (thisRtfElement is RtfListItem) { itemNr++; - result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); - result.Write(LIST_TEXT, 0, LIST_TEXT.Length); - result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length); - if (this.inTable) { - result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length); + RtfListItem rtfElement = (RtfListItem)thisRtfElement; + RtfListLevel listLevel = rtfElement.GetParent(); + if (listLevel.GetListLevel() == 0) { + CorrectIndentation(); } - result.Write(ST.RtfFontList.FONT_NUMBER, 0, ST.RtfFontList.FONT_NUMBER.Length); - if (this.listType != LIST_TYPE_BULLET) { - result.Write(t = IntToByteArray(fontNumber.GetFontNumber()), 0, t.Length); - } else { - result.Write(t = IntToByteArray(fontBullet.GetFontNumber()), 0, t.Length); - } - WriteIndentation(result); - result.Write(DELIMITER, 0, DELIMITER.Length); - if (this.listType != LIST_TYPE_BULLET) { - switch (this.listType) { - case LIST_TYPE_NUMBERED : result.Write(t = IntToByteArray(itemNr), 0, t.Length); break; - case LIST_TYPE_UPPER_LETTERS : result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetUpperCaseString(itemNr)), 0, t.Length); break; - case LIST_TYPE_LOWER_LETTERS : result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetLowerCaseString(itemNr)), 0, t.Length); break; - case LIST_TYPE_UPPER_ROMAN : result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetUpperCaseString(itemNr)), 0, t.Length); break; - case LIST_TYPE_LOWER_ROMAN : result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetLowerCaseString(itemNr)), 0, t.Length); break; - } - result.Write(LIST_NUMBER_END, 0, LIST_NUMBER_END.Length); - } else { - this.document.FilterSpecialChar(result, this.bulletCharacter, true, false); - } - result.Write(TAB, 0, TAB.Length); - result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); + if (i == 0) { - WriteListBeginning(result); + listLevel.WriteListBeginning(result); WriteListNumbers(result); } + + WriteListTextBlock(result, itemNr, listLevel); + rtfElement.WriteContent(result); - if (i < (items.Count - 1) || !this.inTable || this.listLevel > 0) { + + if (i < (items.Count - 1) || !this.inTable || listLevel.GetListType() > 0) { // TODO Fix no paragraph on last list item in tables result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length); } - result.WriteByte((byte)'\n'); - } else if (rtfElement is RtfList) { - rtfElement.WriteContent(result); - WriteListBeginning(result); + this.document.OutputDebugLinebreak(result); + } else if (thisRtfElement is RtfList) { + ((RtfList)thisRtfElement).WriteContent(result); + // ((RtfList)thisRtfElement).WriteListBeginning(result); WriteListNumbers(result); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } } + } if (!this.inTable) { result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length); } - } - - + } /** - * Gets the list level of this RtfList * - * @return Returns the list level. + * @param result + * @param itemNr + * @param listLevel + * @throws IOException + * @since 2.1.3 */ - public int GetListLevel() { - return listLevel; - } - - /** - * Sets the list level of this RtfList. A list level > 0 will - * unregister this RtfList from the RtfListTable - * - * @param listLevel The list level to set. - */ - public void SetListLevel(int listLevel) { - this.listLevel = listLevel; - if (this.listLevel != 0) { - document.GetDocumentHeader().FreeListNumber(this); - for (int i = 0; i < this.items.Count; i++) { - if (this.items[i] is RtfList) { - ((RtfList) this.items[i]).SetListNumber(this.listNumber); - ((RtfList) this.items[i]).SetListLevel(this.listLevel + 1); - } - } - } else { - this.listNumber = document.GetDocumentHeader().GetListNumber(this); + protected void WriteListTextBlock(Stream result, int itemNr, RtfListLevel listLevel) { + byte[] t; + result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); + result.Write(RtfList.LIST_TEXT, 0, RtfList.LIST_TEXT.Length); + result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length); + if (this.inTable) { + result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length); } - } - - /** - * Sets the parent RtfList of this RtfList - * - * @param parent The parent RtfList to use. - */ - protected internal void SetParent(RtfList parent) { - this.parentList = parent; + result.Write(RtfFontList.FONT_NUMBER, 0, RtfFontList.FONT_NUMBER.Length); + if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET) { + result.Write(t = IntToByteArray(listLevel.GetFontNumber().GetFontNumber()), 0, t.Length); + } else { + result.Write(t = IntToByteArray(listLevel.GetFontBullet().GetFontNumber()), 0, t.Length); + } + listLevel.WriteIndentation(result); + result.Write(DELIMITER, 0, DELIMITER.Length); + if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET) { + switch (listLevel.GetListType()) { + case RtfListLevel.LIST_TYPE_NUMBERED : result.Write(t = IntToByteArray(itemNr), 0, t.Length); break; + case RtfListLevel.LIST_TYPE_UPPER_LETTERS : result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetUpperCaseString(itemNr)), 0, t.Length); break; + case RtfListLevel.LIST_TYPE_LOWER_LETTERS : result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetLowerCaseString(itemNr)), 0, t.Length); break; + case RtfListLevel.LIST_TYPE_UPPER_ROMAN : result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetUpperCaseString(itemNr)), 0, t.Length); break; + case RtfListLevel.LIST_TYPE_LOWER_ROMAN : result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetLowerCaseString(itemNr)), 0, t.Length); break; + } + result.Write(LIST_NUMBER_END, 0, LIST_NUMBER_END.Length); + } else { + this.document.FilterSpecialChar(result, listLevel.GetBulletCharacter(), true, false); + } + result.Write(TAB, 0, TAB.Length); + result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); } + /** + * Writes only the list number and list level number. + * + * @param result The Stream to write to + * @throws IOException On i/o errors. + * @since 2.1.3 + */ + protected void WriteListNumbers(Stream result) { + byte[] t; + result.Write(RtfList.LIST_NUMBER, 0, RtfList.LIST_NUMBER.Length); + result.Write(t = IntToByteArray(listNumber), 0, t.Length); + } + /** + * Create a default set of listlevels + * @since 2.1.3 + */ + protected void CreateDefaultLevels() { + this.listLevels = new ArrayList(); // listlevels + for (int i=0; i<=8; i++) { + // create a list level + RtfListLevel ll = new RtfListLevel(this.document); + ll.SetListType(RtfListLevel.LIST_TYPE_NUMBERED); + ll.SetFirstIndent(0); + ll.SetLeftIndent(0); + ll.SetLevelTextNumber(i); + ll.SetTentative(true); + ll.CorrectIndentation(); + this.listLevels.Add(ll); + } + + } /** * Gets the id of this list * * @return Returns the list number. + * @since 2.1.3 */ public int GetListNumber() { return listNumber; @@ -560,6 +537,7 @@ namespace iTextSharp.text.rtf.list { * Sets the id of this list * * @param listNumber The list number to set. + * @since 2.1.3 */ public void SetListNumber(int listNumber) { this.listNumber = listNumber; @@ -570,12 +548,16 @@ namespace iTextSharp.text.rtf.list { * child elements. * * @param inTable True if this RtfList is in a table, false otherwise + * @since 2.1.3 */ public override void SetInTable(bool inTable) { base.SetInTable(inTable); for (int i = 0; i < this.items.Count; i++) { ((IRtfBasicElement) this.items[i]).SetInTable(inTable); } + for (int i = 0; i < this.listLevels.Count; i++) { + ((RtfListLevel) this.listLevels[i]).SetInTable(inTable); + } } /** @@ -583,6 +565,7 @@ namespace iTextSharp.text.rtf.list { * child elements. * * @param inHeader True if this RtfList is in a header, false otherwise + * @since 2.1.3 */ public override void SetInHeader(bool inHeader) { base.SetInHeader(inHeader); @@ -594,11 +577,13 @@ namespace iTextSharp.text.rtf.list { /** * Correct the indentation of this RtfList by adding left/first line indentation * from the parent RtfList. Also calls correctIndentation on all child RtfLists. + * @since 2.1.3 */ protected internal void CorrectIndentation() { - if (this.parentList != null) { - this.leftIndent = this.leftIndent + this.parentList.GetLeftIndent() + this.parentList.GetFirstIndent(); - } + // TODO: Fix + // if (this.parentList != null) { + // this.leftIndent = this.leftIndent + this.parentList.GetLeftIndent() + this.parentList.GetFirstIndent(); + // } for (int i = 0; i < this.items.Count; i++) { if (this.items[i] is RtfList) { ((RtfList) this.items[i]).CorrectIndentation(); @@ -608,22 +593,94 @@ namespace iTextSharp.text.rtf.list { } } + /** - * Get the left indentation of this RtfList. - * - * @return The left indentation. + * Set the list ID number + * @param id + * @since 2.1.3 */ - private int GetLeftIndent() { - return this.leftIndent; + public void SetID(int id) { + this.listID = id; } - /** - * Get the first line indentation of this RtfList. - * - * @return The first line indentation. + * Get the list ID number + * @return this list id + * @since 2.1.3 */ - private int GetFirstIndent() { - return this.firstIndent; + public int GetID() { + return this.listID; + } + + /** + * @return the listType + * @see RtfList#LIST_TYPE_NORMAL + * @see RtfList#LIST_TYPE_SIMPLE + * @see RtfList#LIST_TYPE_HYBRID + * @since 2.1.3 + */ + public int GetListType() { + return listType; + } + + /** + * @param listType the listType to set + * @see RtfList#LIST_TYPE_NORMAL + * @see RtfList#LIST_TYPE_SIMPLE + * @see RtfList#LIST_TYPE_HYBRID + * @since 2.1.3 + */ + public void SetListType(int listType) { + if (listType == LIST_TYPE_NORMAL || + listType == LIST_TYPE_SIMPLE || + listType == LIST_TYPE_HYBRID ) { + this.listType = listType; + } + else { + throw new ArgumentException("Invalid listType value."); + } + } + + /** + * @return the parentList + * @since 2.1.3 + */ + public RtfList GetParentList() { + return parentList; + } + + /** + * @param parentList the parentList to set + * @since 2.1.3 + */ + public void SetParentList(RtfList parentList) { + this.parentList = parentList; + } + + /** + * @return the name + * @since 2.1.3 + */ + public String GetName() { + return name; + } + + /** + * @param name the name to set + * @since 2.1.3 + */ + public void SetName(String name) { + this.name = name; + } + /** + * @return the list at the index + * @since 2.1.3 + */ + public RtfListLevel GetListLevel(int index) { + if (listLevels != null) { + return (RtfListLevel)this.listLevels[index]; + } + else + return null; } } } \ No newline at end of file diff --git a/src/core/iTextSharp/text/rtf/list/RtfListItem.cs b/src/core/iTextSharp/text/rtf/list/RtfListItem.cs index 801b445..32f0a6d 100644 --- a/src/core/iTextSharp/text/rtf/list/RtfListItem.cs +++ b/src/core/iTextSharp/text/rtf/list/RtfListItem.cs @@ -68,7 +68,7 @@ namespace iTextSharp.text.rtf.list { /** * The RtfList this RtfListItem belongs to. */ - private RtfList parentList = null; + private RtfListLevel parentList = null; /** * Whether this RtfListItem contains further RtfLists. */ @@ -96,6 +96,10 @@ namespace iTextSharp.text.rtf.list { result.Write(RtfParagraphStyle.SPACING_AFTER, 0, RtfParagraphStyle.SPACING_AFTER.Length); result.Write(t = IntToByteArray(this.paragraphStyle.GetSpacingAfter()), 0, t.Length); } + if (this.paragraphStyle.GetLineLeading() > 0) { + result.Write(RtfParagraph.LINE_SPACING, 0, RtfParagraph.LINE_SPACING.Length); + result.Write(t = IntToByteArray(this.paragraphStyle.GetLineLeading()), 0, t.Length); + } for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement) chunks[i]; if (rtfElement is RtfChunk) { @@ -106,22 +110,32 @@ namespace iTextSharp.text.rtf.list { } rtfElement.WriteContent(result); if (rtfElement is RtfList) { - this.parentList.WriteListBeginning(result); - result.Write(t = DocWriter.GetISOBytes("\\tab"), 0, t.Length); + switch (this.parentList.GetLevelFollowValue()) { + case RtfListLevel.LIST_LEVEL_FOLLOW_NOTHING: + break; + case RtfListLevel.LIST_LEVEL_FOLLOW_TAB: + this.parentList.WriteListBeginning(result); + result.Write(RtfList.TAB, 0, RtfList.TAB.Length); + break; + case RtfListLevel.LIST_LEVEL_FOLLOW_SPACE: + this.parentList.WriteListBeginning(result); + result.Write(t = DocWriter.GetISOBytes(" "), 0, t.Length); + break; + } } } } /** * Writes the definition of the first element in this RtfListItem that is - * an instanceof {@link RtfList} to the given stream.
+ * an is {@link RtfList} to the given stream.
* If this item does not contain a {@link RtfList} element nothing is written * and the method returns false. * * @param out destination stream * @return true if a RtfList definition was written, false otherwise * @throws IOException - * @see {@link RtfList#writeDefinition(OutputStream)} + * @see {@link RtfList#writeDefinition(Stream)} */ public bool WriteDefinition(Stream outp) { for (int i = 0; i < chunks.Count; i++) { @@ -135,6 +149,8 @@ namespace iTextSharp.text.rtf.list { return false; } + private int level=0; + /** * Inherit the list settings from the parent list to RtfLists that * are contained in this RtfListItem. @@ -147,8 +163,7 @@ namespace iTextSharp.text.rtf.list { IRtfBasicElement rtfElement = (IRtfBasicElement) chunks[i]; if (rtfElement is RtfList) { ((RtfList) rtfElement).SetListNumber(listNumber); - ((RtfList) rtfElement).SetListLevel(listLevel); - ((RtfList) rtfElement).SetParent(this.parentList); + SetLevel(listLevel); } } } @@ -171,10 +186,20 @@ namespace iTextSharp.text.rtf.list { * * @param parentList The parent RtfList to use. */ - public void SetParent(RtfList parentList) { + public void SetParent(RtfListLevel parentList) { this.parentList = parentList; } + /** + * Set the parent RtfList. + * + * @return The parent RtfList to use. + * @since 2.1.3 + */ + public RtfListLevel GetParent() { + return this.parentList; + } + /** * Gets whether this RtfListItem contains further RtfLists. * @@ -183,5 +208,21 @@ namespace iTextSharp.text.rtf.list { public bool IsContainsInnerList() { return this.containsInnerList; } + + /** + * @return the level + * @since 2.1.3 + */ + public int GetLevel() { + return level; + } + + /** + * @param level the level to set + * @since 2.1.3 + */ + public void SetLevel(int level) { + this.level = level; + } } } \ No newline at end of file diff --git a/src/core/iTextSharp/text/rtf/list/RtfListTable.cs b/src/core/iTextSharp/text/rtf/list/RtfListTable.cs index 9b18a51..6c14dd7 100644 --- a/src/core/iTextSharp/text/rtf/list/RtfListTable.cs +++ b/src/core/iTextSharp/text/rtf/list/RtfListTable.cs @@ -65,31 +65,11 @@ namespace iTextSharp.text.rtf.list { */ public class RtfListTable : RtfElement, IRtfExtendedElement { - /** - * Constant for the list number - */ - protected internal static byte[] LIST_NUMBER = DocWriter.GetISOBytes("\\ls"); /** * Constant for the list table */ private static byte[] LIST_TABLE = DocWriter.GetISOBytes("\\*\\listtable"); /** - * Constant for the list - */ - private static byte[] LIST = DocWriter.GetISOBytes("\\list"); - /** - * Constant for the list template id - */ - private static byte[] LIST_TEMPLATE_ID = DocWriter.GetISOBytes("\\listtemplateid"); - /** - * Constant for the hybrid list - */ - private static byte[] LIST_HYBRID = DocWriter.GetISOBytes("\\listhybrid"); - /** - * Constant for the list id - */ - private static byte[] LIST_ID = DocWriter.GetISOBytes("\\listid"); - /** * Constant for the list override table */ private static byte[] LIST_OVERRIDE_TABLE = DocWriter.GetISOBytes("\\*\\listoverridetable"); @@ -107,6 +87,11 @@ namespace iTextSharp.text.rtf.list { */ private ArrayList lists; + /** + * The RtfPictureList lists managed by this RtfListTable + */ + private ArrayList picturelists; + /** * Constructs a RtfListTable for a RtfDocument * @@ -114,6 +99,7 @@ namespace iTextSharp.text.rtf.list { */ public RtfListTable(RtfDocument doc) : base(doc) { this.lists = new ArrayList(); + this.picturelists = new ArrayList(); } /** @@ -127,44 +113,47 @@ namespace iTextSharp.text.rtf.list { */ public virtual void WriteDefinition(Stream result) { byte[] t; - int[] listIds = new int[lists.Count]; result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(LIST_TABLE, 0, LIST_TABLE.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); + + for (int i = 0; i < picturelists.Count; i++) { + RtfPictureList l = (RtfPictureList)picturelists[i]; + // l.SetID(document.GetRandomInt()); + l.WriteDefinition(result); + this.document.OutputDebugLinebreak(result); + } + for (int i = 0; i < lists.Count; i++) { - result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); - result.Write(LIST, 0, LIST.Length); - result.Write(LIST_TEMPLATE_ID, 0, LIST_TEMPLATE_ID.Length); - result.Write(t = IntToByteArray(document.GetRandomInt()), 0, t.Length); - result.Write(LIST_HYBRID, 0, LIST_HYBRID.Length); - result.WriteByte((byte)'\n'); - RtfList rList = (RtfList)lists[i]; - rList.WriteDefinition(result); - result.Write(LIST_ID, 0, LIST_ID.Length); - listIds[i] = document.GetRandomInt(); - result.Write(t = IntToByteArray(listIds[i]), 0, t.Length); - result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + RtfList l = (RtfList)lists[i]; + l.SetID(document.GetRandomInt()); + l.WriteDefinition(result); + this.document.OutputDebugLinebreak(result); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); + result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(LIST_OVERRIDE_TABLE, 0, LIST_OVERRIDE_TABLE.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); + + // list override index values are 1-based, not 0. + // valid list override index values \ls are 1 to 2000. + // if there are more then 2000 lists, the result is undefined. for (int i = 0; i < lists.Count; i++) { result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(LIST_OVERRIDE, 0, LIST_OVERRIDE.Length); - result.Write(LIST_ID, 0, LIST_ID.Length); - result.Write(t = IntToByteArray(listIds[i]), 0, t.Length); + result.Write(RtfList.LIST_ID, 0, RtfList.LIST_ID.Length); + result.Write(t = IntToByteArray( ((RtfList) lists[i]).GetID() ), 0, t.Length); result.Write(LIST_OVERRIDE_COUNT, 0, LIST_OVERRIDE_COUNT.Length); - result.Write(t = IntToByteArray(0), 0, t.Length); - result.Write(LIST_NUMBER, 0, LIST_NUMBER.Length); - result.Write(t = IntToByteArray(((RtfList) lists[i]).GetListNumber()), 0, t.Length); + result.Write(t = IntToByteArray(0), 0, t.Length); // is this correct? Spec says valid values are 1 or 9. + result.Write(RtfList.LIST_NUMBER, 0, RtfList.LIST_NUMBER.Length); + result.Write(t = IntToByteArray( ((RtfList) lists[i]).GetListNumber()) , 0, t.Length); result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } /** diff --git a/src/core/iTextSharp/text/rtf/parser/RtfImportMappings.cs b/src/core/iTextSharp/text/rtf/parser/RtfImportMappings.cs index 19fb7ae..6728aef 100644 --- a/src/core/iTextSharp/text/rtf/parser/RtfImportMappings.cs +++ b/src/core/iTextSharp/text/rtf/parser/RtfImportMappings.cs @@ -118,7 +118,7 @@ namespace iTextSharp.text.rtf.parser { * @param listNr The List number. * @param list The List. */ - public void AddList(String listNr, Color list) { + public void AddList(String listNr, string list) { this.listMappings[listNr] = list; } /** @@ -127,7 +127,7 @@ namespace iTextSharp.text.rtf.parser { * @param stylesheetListNr The Stylesheet List number. * @param list The StylesheetList. */ - public void AddStylesheetList(String stylesheetListNr, Color list) { + public void AddStylesheetList(String stylesheetListNr, string list) { this.stylesheetListMappings[stylesheetListNr] = list; } diff --git a/src/core/iTextSharp/text/rtf/parser/RtfImportMgr.cs b/src/core/iTextSharp/text/rtf/parser/RtfImportMgr.cs index e5e88bf..39279da 100644 --- a/src/core/iTextSharp/text/rtf/parser/RtfImportMgr.cs +++ b/src/core/iTextSharp/text/rtf/parser/RtfImportMgr.cs @@ -140,13 +140,9 @@ namespace iTextSharp.text.rtf.parser { RtfFont rtfFont = new RtfFont(fontName); if (charset>= 0) rtfFont.SetCharset(charset); - if (rtfFont != null){ - rtfFont.SetRtfDocument(this.rtfDoc); - this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString(); - return true; - } else { - return false; - } + rtfFont.SetRtfDocument(this.rtfDoc); + this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString(); + return true; } /** * Imports a font. The font name is looked up in the RtfDocumentHeader and @@ -163,13 +159,9 @@ namespace iTextSharp.text.rtf.parser { rtfFont.SetCharset(charset); if (fontFamily != null && fontFamily.Length > 0) rtfFont.SetFamily(fontFamily); - if (rtfFont != null){ - rtfFont.SetRtfDocument(this.rtfDoc); - this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString(); - return true; - } else { - return false; - } + rtfFont.SetRtfDocument(this.rtfDoc); + this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString(); + return true; } /** * Performs the mapping from the original font number to the actual @@ -222,16 +214,8 @@ namespace iTextSharp.text.rtf.parser { * Imports a List value. The List number for the List defined * is determined and then the resulting mapping is added. */ - public void ImportList(String listNr, List list) { - RtfList rtfList = new RtfList(this.rtfDoc, list); - - //if(rtfList != null){ - //rtfList.SetRtfDocument(this.rtfDoc); - this.importStylesheetListMapping[listNr] = this.rtfDoc.GetDocumentHeader().GetListNumber(rtfList).ToString(); - // return true; - // } else { - // return false; - // } + public void ImportList(String origListNr, String newListNr) { + this.importListMapping[origListNr] = newListNr; } /** @@ -244,7 +228,7 @@ namespace iTextSharp.text.rtf.parser { if (this.importListMapping.ContainsKey(listNr)) { return (String) this.importListMapping[listNr]; } else { - return "0"; + return null; } } @@ -254,14 +238,8 @@ namespace iTextSharp.text.rtf.parser { */ public bool ImportStylesheetList(String listNr, List listIn) { RtfList rtfList = new RtfList(this.rtfDoc, listIn); - - if (rtfList != null){ - rtfList.SetRtfDocument(this.rtfDoc); - //this.importStylesheetListMapping[listNr] = Integer.ToString(this.rtfDoc.GetDocumentHeader().GetRtfParagraphStyle(styleName)(rtfList)); - return true; - } else { - return false; - } + rtfList.SetRtfDocument(this.rtfDoc); + return true; } /** * Performs the mapping from the original stylesheet number to the actual diff --git a/src/core/iTextSharp/text/rtf/parser/RtfParser.cs b/src/core/iTextSharp/text/rtf/parser/RtfParser.cs index d2b5fb9..29e5da1 100644 --- a/src/core/iTextSharp/text/rtf/parser/RtfParser.cs +++ b/src/core/iTextSharp/text/rtf/parser/RtfParser.cs @@ -79,6 +79,11 @@ namespace iTextSharp.text.rtf.parser { private bool logging = false; private bool logAppend = false; + /** + * The iText element to add the RTF document to. + * @since 2.1.3 + */ + private IElement elem = null; /** * The iText document to add the RTF document to. */ @@ -246,7 +251,7 @@ namespace iTextSharp.text.rtf.parser { /** * Currently a blipuid control word is being parsed. */ - public const int PARSER_IN_BLIPUID = PARSER_IN_DOCUMENT | 0x000013; //18 + public const int PARSER_IN_BLIPUID = PARSER_IN_DOCUMENT | 0x000013; //19 /* other states */ /** @@ -287,6 +292,11 @@ namespace iTextSharp.text.rtf.parser { */ public const int TYPE_CONVERT = 2; + /** + * Conversion type to import a document into an element. i.e. Chapter, Section, Table Cell, etc. + * @since 2.1.4 + */ + public const int TYPE_IMPORT_INTO_ELEMENT = 3; /** * Destination is normal. Text is processed. @@ -438,6 +448,14 @@ namespace iTextSharp.text.rtf.parser { /** The RtfCtrlWordListener. */ private ArrayList listeners = new ArrayList(); + /** + * Constructor + * @param doc + * @since 2.1.3 + */ + public RtfParser(Document doc) { + this.document = doc; + } /* ********* * READER * ***********/ @@ -452,7 +470,33 @@ namespace iTextSharp.text.rtf.parser { */ public void ImportRtfDocument(Stream readerIn, RtfDocument rtfDoc) { if (readerIn == null || rtfDoc == null) return; - this.Init(TYPE_IMPORT_FULL, rtfDoc, readerIn, null); + this.Init(TYPE_IMPORT_FULL, rtfDoc, readerIn, this.document, null); + this.SetCurrentDestination(RtfDestinationMgr.DESTINATION_NULL); + startDate = DateTime.Now; + startTime = startDate.Ticks / 10000L; + this.groupLevel = 0; + try { + this.Tokenise(); + } catch { + } + endDate = DateTime.Now; + endTime = endDate.Ticks / 10000L; + } + + /** + * Imports a complete RTF document into an Element, i.e. Chapter, section, Table Cell, etc. + * + * @param elem The Element the document is to be imported into. + * @param readerIn + * The Reader to read the RTF document from. + * @param rtfDoc + * The RtfDocument to add the imported document to. + * @throws IOException On I/O errors. + * @since 2.1.4 + */ + public void ImportRtfDocumentIntoElement(IElement elem, Stream readerIn, RtfDocument rtfDoc) { + if(readerIn == null || rtfDoc == null || elem == null) return; + this.Init(TYPE_IMPORT_INTO_ELEMENT, rtfDoc, readerIn, this.document, elem); this.SetCurrentDestination(RtfDestinationMgr.DESTINATION_NULL); startDate = DateTime.Now; startTime = startDate.Ticks / 10000L; @@ -480,7 +524,7 @@ namespace iTextSharp.text.rtf.parser { */ public void ConvertRtfDocument(Stream readerIn, Document doc) { if (readerIn == null || doc == null) return; - this.Init(TYPE_CONVERT, null, readerIn, doc); + this.Init(TYPE_CONVERT, null, readerIn, doc, null); this.SetCurrentDestination(RtfDestinationMgr.DESTINATION_DOCUMENT); startDate = DateTime.Now; startTime = startDate.Ticks / 10000L; @@ -505,7 +549,7 @@ namespace iTextSharp.text.rtf.parser { public void ImportRtfFragment(Stream readerIn, RtfDocument rtfDoc, RtfImportMappings importMappings) { //public void ImportRtfFragment2(Reader readerIn, RtfDocument rtfDoc, RtfImportMappings importMappings) throws IOException { if (readerIn == null || rtfDoc == null || importMappings==null) return; - this.Init(TYPE_IMPORT_FRAGMENT, rtfDoc, readerIn, null); + this.Init(TYPE_IMPORT_FRAGMENT, rtfDoc, readerIn, null, null); this.HandleImportMappings(importMappings); this.SetCurrentDestination(RtfDestinationMgr.DESTINATION_DOCUMENT); this.groupLevel = 1; @@ -547,7 +591,7 @@ namespace iTextSharp.text.rtf.parser { * @param readerIn The input stream * @param doc The iText Document */ - private void Init(int type, RtfDocument rtfDoc, Stream readerIn, Document doc) { + private void Init(int type, RtfDocument rtfDoc, Stream readerIn, Document doc, IElement elem) { Init_stats(); // initialize reader to a PushbackReader @@ -556,6 +600,7 @@ namespace iTextSharp.text.rtf.parser { this.conversionType = type; this.rtfDoc = rtfDoc; this.document = doc; + this.elem = elem; this.currentState = new RtfParserState(); this.stackState = new Stack(); this.SetParserState(PARSER_STARTSTOP); @@ -728,7 +773,7 @@ namespace iTextSharp.text.rtf.parser { this.importMgr.ImportColor(colorNr, (Color) importMappings.GetColorMappings()[colorNr]); } foreach (String listNr in importMappings.GetListMappings().Keys) { - this.importMgr.ImportList(listNr, (List) importMappings.GetListMappings()[listNr]); + this.importMgr.ImportList(listNr, (String)importMappings.GetListMappings()[listNr]); } foreach (String stylesheetListNr in importMappings.GetStylesheetListMappings().Keys) { this.importMgr.ImportStylesheetList(stylesheetListNr, (List) importMappings.GetStylesheetListMappings()[stylesheetListNr]); @@ -762,7 +807,7 @@ namespace iTextSharp.text.rtf.parser { this.groupSkippedCount++; } - RtfDestination dest = (RtfDestination)this.GetCurrentDestination(); + RtfDestination dest = this.GetCurrentDestination(); bool handled = false; if (dest != null) { @@ -781,7 +826,7 @@ namespace iTextSharp.text.rtf.parser { // do not set this true until after the state is pushed // otherwise it inserts a { where one does not belong. this.currentState.newGroup = true; - dest = (RtfDestination)this.GetCurrentDestination(); + dest = this.GetCurrentDestination(); if (debugParser) { RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: HandleOpenGroup()"); @@ -834,7 +879,7 @@ namespace iTextSharp.text.rtf.parser { RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: destination=" + this.GetCurrentDestination().ToString()); RtfParser.OutputDebug(this.rtfDoc, groupLevel, ""); } - RtfDestination dest = (RtfDestination)this.GetCurrentDestination(); + RtfDestination dest = this.GetCurrentDestination(); bool handled = false; if (dest != null) { @@ -923,7 +968,7 @@ namespace iTextSharp.text.rtf.parser { bool handled = false; - RtfDestination dest = (RtfDestination)this.GetCurrentDestination(); + RtfDestination dest = this.GetCurrentDestination(); if (dest != null) { handled = dest.HandleCharacter(nextChar); } @@ -1128,7 +1173,7 @@ namespace iTextSharp.text.rtf.parser { // if (groupLevel < 0 && this.IsConvert()) return; //return errStackUnderflow; }// end while (reader.Read(nextChar) != -1) - RtfDestination dest = (RtfDestination)this.GetCurrentDestination(); + RtfDestination dest = this.GetCurrentDestination(); if (dest != null) { dest.CloseDestination(); } diff --git a/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordHandler.cs b/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordHandler.cs index bab6bc3..bae391d 100644 --- a/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordHandler.cs +++ b/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordHandler.cs @@ -229,14 +229,14 @@ namespace iTextSharp.text.rtf.parser.ctrlwords { case RtfCtrlWordType.FLAG: case RtfCtrlWordType.TOGGLE: case RtfCtrlWordType.VALUE: - dest = (RtfDestination)this.rtfParser.GetCurrentDestination(); + dest = this.rtfParser.GetCurrentDestination(); if (dest != null) { handled = dest.HandleControlWord(this.ctrlWordData); } break; case RtfCtrlWordType.SYMBOL: - dest = (RtfDestination)this.rtfParser.GetCurrentDestination(); + dest = this.rtfParser.GetCurrentDestination(); if (dest != null) { String data = null; // if doing an import, then put the control word in the output stream through the character handler @@ -268,7 +268,7 @@ namespace iTextSharp.text.rtf.parser.ctrlwords { } handled = this.rtfParser.SetCurrentDestination(this.ctrlWord); // let destination handle the ctrl word now. - dest = (RtfDestination)this.rtfParser.GetCurrentDestination(); + dest = this.rtfParser.GetCurrentDestination(); if(dest != null) { if(dest.GetNewTokeniserState() == RtfParser.TOKENISER_IGNORE_RESULT) { handled = dest.HandleControlWord(this.ctrlWordData); diff --git a/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordMap.cs b/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordMap.cs index 4d37725..3769548 100644 --- a/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordMap.cs +++ b/src/core/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordMap.cs @@ -806,7 +806,7 @@ namespace iTextSharp.text.rtf.parser.ctrlwords { ctrlWords["levelnfc"] = new RtfCtrlWordHandler(rtfParser, "levelnfc", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["levelnfcn"] = new RtfCtrlWordHandler(rtfParser, "levelnfcn", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["levelnorestart"] = new RtfCtrlWordHandler(rtfParser, "levelnorestart", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); - ctrlWords["levelnumbers"] = new RtfCtrlWordHandler(rtfParser, "levelnumbers", 0, false, RtfCtrlWordType.DESTINATION, "\\", " ", "RtfDestinationNull"); + ctrlWords["levelnumbers"] = new RtfCtrlWordHandler(rtfParser, "levelnumbers", 0, false, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["levelold"] = new RtfCtrlWordHandler(rtfParser, "levelold", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["levelpicture"] = new RtfCtrlWordHandler(rtfParser, "levelpicture", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["levelprev"] = new RtfCtrlWordHandler(rtfParser, "levelprev", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); @@ -833,6 +833,7 @@ namespace iTextSharp.text.rtf.parser.ctrlwords { ctrlWords["lisa"] = new RtfCtrlWordHandler(rtfParser, "lisa", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["lisb"] = new RtfCtrlWordHandler(rtfParser, "lisb", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["list"] = new RtfCtrlWordHandler(rtfParser, "list", 0, false, RtfCtrlWordType.VALUE, "\\", " ", null); + ctrlWords["listlevel"] = new RtfCtrlWordHandler(rtfParser, "listlevel", 0, false, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["listhybrid"] = new RtfCtrlWordHandler(rtfParser, "listhybrid", 0, false, RtfCtrlWordType.FLAG, "\\", " ", null); ctrlWords["listid"] = new RtfCtrlWordHandler(rtfParser, "listid", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["listname"] = new RtfCtrlWordHandler(rtfParser, "listname", 0, false, RtfCtrlWordType.DESTINATION, "\\", " ", "RtfDestinationNull"); @@ -849,7 +850,7 @@ namespace iTextSharp.text.rtf.parser.ctrlwords { ctrlWords["liststylename"] = new RtfCtrlWordHandler(rtfParser, "liststylename", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["listtable"] = new RtfCtrlWordHandler(rtfParser, "listtable", 0, false, RtfCtrlWordType.DESTINATION_EX, "\\*\\", " ", "RtfDestinationListTable"); ctrlWords["listtemplateid"] = new RtfCtrlWordHandler(rtfParser, "listtemplateid", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); - ctrlWords["listtext"] = new RtfCtrlWordHandler(rtfParser, "listtext", 0, false, RtfCtrlWordType.DESTINATION, "\\", " ", "RtfDestinationDocument"); + ctrlWords["listtext"] = new RtfCtrlWordHandler(rtfParser, "listtext", 0, false, RtfCtrlWordType.DESTINATION, "\\", " ", "RtfDestinationNull"); ctrlWords["lnbrkrule"] = new RtfCtrlWordHandler(rtfParser, "lnbrkrule", 0, false, RtfCtrlWordType.FLAG, "\\", " ", null); ctrlWords["lndscpsxn"] = new RtfCtrlWordHandler(rtfParser, "lndscpsxn", 0, false, RtfCtrlWordType.FLAG, "\\", " ", null); ctrlWords["lnongrid"] = new RtfCtrlWordHandler(rtfParser, "lnongrid", 0, false, RtfCtrlWordType.FLAG, "\\", " ", null); @@ -1553,7 +1554,7 @@ namespace iTextSharp.text.rtf.parser.ctrlwords { ctrlWords["shplockanchor"] = new RtfCtrlWordHandler(rtfParser, "shplockanchor", 0, false, RtfCtrlWordType.FLAG, "\\", " ", null); ctrlWords["shppict"] = new RtfCtrlWordHandler(rtfParser, "shppict", 0, false, RtfCtrlWordType.DESTINATION_EX, "\\*\\", " ", "RtfDestinationShppict" );//"RtfDestinationShppict"; ctrlWords["shpright"] = new RtfCtrlWordHandler(rtfParser, "shpright", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); - ctrlWords["shprslt"] = new RtfCtrlWordHandler(rtfParser, "shprslt", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); + ctrlWords["shprslt"] = new RtfCtrlWordHandler(rtfParser, "shprslt", 0, true, RtfCtrlWordType.DESTINATION, "\\", " ", "RtfDestinationNull"); ctrlWords["shptop"] = new RtfCtrlWordHandler(rtfParser, "shptop", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["shptxt"] = new RtfCtrlWordHandler(rtfParser, "shptxt", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); ctrlWords["shpwr"] = new RtfCtrlWordHandler(rtfParser, "shpwr", 0, true, RtfCtrlWordType.VALUE, "\\", " ", null); diff --git a/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationDocument.cs b/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationDocument.cs index 45f2580..bde0806 100644 --- a/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationDocument.cs +++ b/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationDocument.cs @@ -258,6 +258,8 @@ namespace iTextSharp.text.rtf.parser.destinations { if (ctrlWordData.ctrlWord.Equals("trcbpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);} //paragraph border if (ctrlWordData.ctrlWord.Equals("brdrcf")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);} + // map lists + if(ctrlWordData.ctrlWord.Equals("ls")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapListNr(ctrlWordData.param);} } diff --git a/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationListTable.cs b/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationListTable.cs index 7f5b1e9..d495841 100644 --- a/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationListTable.cs +++ b/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationListTable.cs @@ -1,5 +1,6 @@ using System; using iTextSharp.text.rtf.parser; +using iTextSharp.text.rtf.list; using iTextSharp.text.rtf.parser.ctrlwords; /* * $Id: RtfDestinationListTable.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $ @@ -65,6 +66,13 @@ namespace iTextSharp.text.rtf.parser.destinations { */ private RtfImportMgr importHeader = null; + private RtfList newList = null; + + private int currentLevel = -1; + private RtfListLevel currentListLevel = null; + private int currentListMappingNumber = 0; + private int currentSubGroupCount = 0; + public RtfDestinationListTable() : base(null) { } @@ -81,17 +89,242 @@ namespace iTextSharp.text.rtf.parser.destinations { * @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup() */ public override bool HandleOpeningSubGroup() { + this.currentSubGroupCount++; return true; } /* (non-Javadoc) * @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination() */ public override bool CloseDestination() { - // TODO Auto-generated method stub + if (this.newList != null) { + this.rtfParser.GetRtfDocument().Add(this.newList); + } return true; } public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) { bool result = true; + bool skipCtrlWord = false; + + if (this.rtfParser.IsImport()) { + skipCtrlWord = true; + if (ctrlWordData.ctrlWord.Equals("listtable")) { + result = true; + this.currentListMappingNumber = 0; + + } else + /* Picture info for icons/images for lists */ + if (ctrlWordData.ctrlWord.Equals("listpicture"))/* DESTINATION */{ + skipCtrlWord = true; + // this.rtfParser.SetTokeniserStateSkipGroup(); + result = true; + } else + /* list */ + if (ctrlWordData.ctrlWord.Equals("list")) /* DESTINATION */{ + skipCtrlWord = true; + this.newList = new RtfList(this.rtfParser.GetRtfDocument()); + this.newList.SetListType(RtfList.LIST_TYPE_NORMAL); // set default + this.currentLevel = -1; + this.currentListMappingNumber++; + this.currentSubGroupCount = 0; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("listtemplateid")) /* // List item*/ { + // ignore this because it gets regenerated in every document + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("listsimple")) /* // List item*/ { + // is value 0 or 1 + if (ctrlWordData.hasParam && ctrlWordData.param == "1") { + this.newList.SetListType(RtfList.LIST_TYPE_SIMPLE); + } else { + this.newList.SetListType(RtfList.LIST_TYPE_NORMAL); + } + skipCtrlWord = true; + result = true; + // this gets set internally. Don't think it should be imported + } else if (ctrlWordData.ctrlWord.Equals("listhybrid")) /* // List item*/ { + this.newList.SetListType(RtfList.LIST_TYPE_HYBRID); + skipCtrlWord = true; + result = true; + // this gets set internally. Don't think it should be imported + } else if (ctrlWordData.ctrlWord.Equals("listrestarthdn")) /* // List item*/ { + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("listid")) { // List item cannot be between -1 and -5 + // needs to be mapped for imports and is recreated + // we have the new id and the old id. Just add it to the mapping table here. + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("listname"))/* // List item*/ { + this.newList.SetName(ctrlWordData.param); + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("liststyleid"))/* // List item*/ { + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("liststylename"))/* // List item*/ { + skipCtrlWord = true; + result = true; + } else + /* listlevel */ + if (ctrlWordData.ctrlWord.Equals("listlevel")) /* DESTINATION There are 1 or 9 listlevels per list */{ + this.currentLevel++; + this.currentListLevel = this.newList.GetListLevel(this.currentLevel); + this.currentListLevel.SetTentative(false); + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("leveljc")) { // listlevel item justify + // this is the old number. Only use it if the current type is not set + if ( this.currentListLevel.GetAlignment()== RtfListLevel.LIST_TYPE_UNKNOWN) { + switch (ctrlWordData.IntValue()) { + case 0: + this.currentListLevel.SetAlignment(Element.ALIGN_LEFT); + break; + case 1: + this.currentListLevel.SetAlignment(Element.ALIGN_CENTER); + break; + case 2: + this.currentListLevel.SetAlignment(Element.ALIGN_RIGHT); + break; + } + } + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("leveljcn")) { // listlevel item + //justify + // if this exists, use it and it overrides the old setting + switch (ctrlWordData.IntValue()) { + case 0: + this.currentListLevel.SetAlignment(Element.ALIGN_LEFT); + break; + case 1: + this.currentListLevel.SetAlignment(Element.ALIGN_CENTER); + break; + case 2: + this.currentListLevel.SetAlignment(Element.ALIGN_RIGHT); + break; + } + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelstartat")) { + this.currentListLevel.SetListStartAt(ctrlWordData.IntValue()); + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("lvltentative")) { + this.currentListLevel.SetTentative(true); + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelold")) { + // old style. ignore + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelprev")) { + // old style. ignore + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelprevspace")) { + // old style. ignore + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelspace")) { + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelindent")) { + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("leveltext")) {/* FIX */ + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelfollow")) { + this.currentListLevel.SetLevelFollowValue(ctrlWordData.IntValue()); + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levellegal")) { + this.currentListLevel.SetLegal(ctrlWordData.param=="1"?true:false); + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelnorestart")) { + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("chrfmt")) {/* FIX */ + // set an attribute pair + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelpicture")) { + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("li")) { + // set an attribute pair + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("fi")) { + // set an attribute pair + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("jclisttab")) { + // set an attribute pair + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("tx")) { + // set an attribute pair + skipCtrlWord = true; + result = true; + } else + /* number */ + if (ctrlWordData.ctrlWord.Equals("levelnfc")) /* old style */ { + if ( this.currentListLevel.GetListType()== RtfListLevel.LIST_TYPE_UNKNOWN) { + this.currentListLevel.SetListType(ctrlWordData.IntValue()+RtfListLevel.LIST_TYPE_BASE); + } + skipCtrlWord = true; + result = true; + } else if (ctrlWordData.ctrlWord.Equals("levelnfcn")) /* new style takes priority over levelnfc.*/ { + this.currentListLevel.SetListType(ctrlWordData.IntValue()+RtfListLevel.LIST_TYPE_BASE); + skipCtrlWord = true; + result = true; + } else + /* level text */ + if (ctrlWordData.ctrlWord.Equals("leveltemplateid")) { + // ignore. this value is regenerated in each document. + skipCtrlWord = true; + result = true; + } else + /* levelnumber */ + if (ctrlWordData.ctrlWord.Equals("levelnumbers")) { + skipCtrlWord = true; + result = true; + } + } + + if (this.rtfParser.IsConvert()) { + if (ctrlWordData.ctrlWord.Equals("shppict")) { + result = true; + } + if (ctrlWordData.ctrlWord.Equals("nonshppict")) { + skipCtrlWord = true; + this.rtfParser.SetTokeniserStateSkipGroup(); + result = true; + } + } + if (!skipCtrlWord) { + switch (this.rtfParser.GetConversionType()) { + case RtfParser.TYPE_IMPORT_FULL: + // WriteBuffer(); + // WriteText(ctrlWordData.ToString()); + result = true; + break; + case RtfParser.TYPE_IMPORT_FRAGMENT: + // WriteBuffer(); + // WriteText(ctrlWordData.ToString()); + result = true; + break; + case RtfParser.TYPE_CONVERT: + result = true; + break; + default: // error because is should be an import or convert + result = false; + break; + } + } + return result; } @@ -99,7 +332,11 @@ namespace iTextSharp.text.rtf.parser.destinations { * @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd() */ public override bool HandleCloseGroup() { - // TODO Auto-generated method stub + this.currentSubGroupCount--; + if (this.newList != null && this.currentSubGroupCount == 0) { + this.importHeader.ImportList(this.currentListMappingNumber.ToString(), this.newList.GetListNumber().ToString()); + this.rtfParser.GetRtfDocument().Add(this.newList); + } return true; } diff --git a/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationShppict.cs b/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationShppict.cs index 8c112e3..0cfa212 100644 --- a/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationShppict.cs +++ b/src/core/iTextSharp/text/rtf/parser/destinations/RtfDestinationShppict.cs @@ -216,6 +216,10 @@ namespace iTextSharp.text.rtf.parser.destinations { return true; } if (this.rtfParser.IsConvert()) { + if (dataOS != null) { + AddImage(); + dataOS = null; + } } return true; } @@ -243,13 +247,12 @@ namespace iTextSharp.text.rtf.parser.destinations { if (img != null) { img.ScaleAbsolute((float)this.desiredWidth/PIXEL_TWIPS_FACTOR, (float)this.desiredHeight/PIXEL_TWIPS_FACTOR); img.ScaleAbsolute((float)this.width/PIXEL_TWIPS_FACTOR, (float)this.height/PIXEL_TWIPS_FACTOR); - img.ScalePercent((float)this.scaleX, this.scaleY); + img.ScalePercent((float)this.scaleX, (float)this.scaleY); try { if (this.rtfParser.IsImport()) { - RtfDocument rtfDoc = this.rtfParser.GetRtfDocument(); - RtfImage rtfImage = new RtfImage(rtfDoc, img); - rtfDoc.Add(rtfImage); + Document doc = this.rtfParser.GetDocument(); + doc.Add(img); } if (this.rtfParser.IsConvert()) { this.rtfParser.GetDocument().Add(img); diff --git a/src/core/iTextSharp/text/rtf/style/RtfColorList.cs b/src/core/iTextSharp/text/rtf/style/RtfColorList.cs index 4b3b472..ea2fd8a 100644 --- a/src/core/iTextSharp/text/rtf/style/RtfColorList.cs +++ b/src/core/iTextSharp/text/rtf/style/RtfColorList.cs @@ -125,7 +125,7 @@ namespace iTextSharp.text.rtf.style { color.WriteDefinition(result); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } } } \ No newline at end of file diff --git a/src/core/iTextSharp/text/rtf/style/RtfFont.cs b/src/core/iTextSharp/text/rtf/style/RtfFont.cs index 68f4647..0b679b1 100644 --- a/src/core/iTextSharp/text/rtf/style/RtfFont.cs +++ b/src/core/iTextSharp/text/rtf/style/RtfFont.cs @@ -297,6 +297,9 @@ namespace iTextSharp.text.rtf.style { Size = font.Size; SetStyle(font.Style); Color = font.Color; + if(document != null) { + this.fontNumber = document.GetDocumentHeader().GetFontNumber(this); + } } if (Util.EqualsIgnoreCase(this.fontName, "unknown")) { return; diff --git a/src/core/iTextSharp/text/rtf/style/RtfFontList.cs b/src/core/iTextSharp/text/rtf/style/RtfFontList.cs index 786e619..06b3719 100644 --- a/src/core/iTextSharp/text/rtf/style/RtfFontList.cs +++ b/src/core/iTextSharp/text/rtf/style/RtfFontList.cs @@ -141,7 +141,7 @@ namespace iTextSharp.text.rtf.style { result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } } } \ No newline at end of file diff --git a/src/core/iTextSharp/text/rtf/style/RtfParagraphStyle.cs b/src/core/iTextSharp/text/rtf/style/RtfParagraphStyle.cs index 93e946b..8abe182 100644 --- a/src/core/iTextSharp/text/rtf/style/RtfParagraphStyle.cs +++ b/src/core/iTextSharp/text/rtf/style/RtfParagraphStyle.cs @@ -604,9 +604,7 @@ namespace iTextSharp.text.rtf.style { result.Write(t = DocWriter.GetISOBytes(this.styleName), 0, t.Length); result.Write(t = DocWriter.GetISOBytes(";"), 0, t.Length); result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length); - if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) { - result.WriteByte((byte)'\n'); - } + this.document.OutputDebugLinebreak(result); } /** diff --git a/src/core/iTextSharp/text/rtf/style/RtfStylesheetList.cs b/src/core/iTextSharp/text/rtf/style/RtfStylesheetList.cs index 08978d8..44b4af1 100644 --- a/src/core/iTextSharp/text/rtf/style/RtfStylesheetList.cs +++ b/src/core/iTextSharp/text/rtf/style/RtfStylesheetList.cs @@ -96,15 +96,11 @@ namespace iTextSharp.text.rtf.style { result.Write(t = DocWriter.GetISOBytes("{"), 0, t.Length); result.Write(t = DocWriter.GetISOBytes("\\stylesheet"), 0, t.Length); result.Write(t = RtfElement.DELIMITER, 0, t.Length); - if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) { - result.Write(t = DocWriter.GetISOBytes("\n"), 0, t.Length); - } + this.document.OutputDebugLinebreak(result); foreach (RtfParagraphStyle rps in this.styleMap.Values) rps.WriteDefinition(result); result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length); - if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) { - result.WriteByte((byte)'\n'); - } + this.document.OutputDebugLinebreak(result); } } } \ No newline at end of file diff --git a/src/core/iTextSharp/text/rtf/table/RtfBorder.cs b/src/core/iTextSharp/text/rtf/table/RtfBorder.cs index 146132f..652baa2 100644 --- a/src/core/iTextSharp/text/rtf/table/RtfBorder.cs +++ b/src/core/iTextSharp/text/rtf/table/RtfBorder.cs @@ -451,7 +451,7 @@ namespace iTextSharp.text.rtf.table { result.Write(t = IntToByteArray(this.borderWidth), 0, t.Length); result.Write(BORDER_COLOR_NUMBER, 0, BORDER_COLOR_NUMBER.Length); result.Write(t = IntToByteArray(this.borderColor.GetColorNumber()), 0, t.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } else if (this.borderType == CELL_BORDER) { switch (this.borderPosition) { case LEFT_BORDER: @@ -474,7 +474,7 @@ namespace iTextSharp.text.rtf.table { result.Write(t = IntToByteArray(this.borderWidth), 0, t.Length); result.Write(BORDER_COLOR_NUMBER, 0, BORDER_COLOR_NUMBER.Length); result.Write(t = IntToByteArray(this.borderColor.GetColorNumber()), 0, t.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } } diff --git a/src/core/iTextSharp/text/rtf/table/RtfCell.cs b/src/core/iTextSharp/text/rtf/table/RtfCell.cs index c366b9d..f0648f0 100644 --- a/src/core/iTextSharp/text/rtf/table/RtfCell.cs +++ b/src/core/iTextSharp/text/rtf/table/RtfCell.cs @@ -3,6 +3,7 @@ using System.IO; using System.Collections; using System.util; using iTextSharp.text; +using iTextSharp.text.pdf; using iTextSharp.text.rtf; using iTextSharp.text.rtf.document; using iTextSharp.text.rtf.style; @@ -130,6 +131,28 @@ namespace iTextSharp.text.rtf.table { */ private bool deleted = false; + /** + * Whether to use generic padding or individual + * padding values (cellPaddingLeft, cellPaddingTop, cellPaddingBottom, cellPaddingRight) + */ + //private bool usePadding = false; + /* + * Cell padding left + */ + private float cellPaddingLeft = 0; + /* + * Cell padding top + */ + private float cellPaddingTop = 0; + /* + * Cell padding bottom + */ + private float cellPaddingBottom = 0; + /* + * Cell padding right + */ + private float cellPaddingRight = 0; + /** * Constructs an empty RtfCell */ @@ -182,6 +205,19 @@ namespace iTextSharp.text.rtf.table { ImportCell(cell); } + /** + * Constructs a RtfCell based on a Cell. + * + * @param doc The RtfDocument this RtfCell belongs to + * @param row The RtfRow this RtfCell lies in + * @param cell The PdfPCell to base this RtfCell on + * @since 2.1.3 + */ + protected internal RtfCell(RtfDocument doc, RtfRow row, PdfPCell cell) { + this.document = doc; + this.parentRow = row; + ImportCell(cell); + } /** * Imports the Cell properties into the RtfCell * @@ -229,7 +265,7 @@ namespace iTextSharp.text.rtf.table { } else { if (container != null) { IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container); - for(int i = 0; i < rtfElements.Length; i++) { + for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); this.content.Add(rtfElements[i]); } @@ -242,7 +278,7 @@ namespace iTextSharp.text.rtf.table { } IRtfBasicElement[] rtfElements2 = this.document.GetMapper().MapElement(element); - for(int i = 0; i < rtfElements2.Length; i++) { + for (int i = 0; i < rtfElements2.Length; i++) { rtfElements2[i].SetInTable(true); this.content.Add(rtfElements2[i]); } @@ -253,7 +289,7 @@ namespace iTextSharp.text.rtf.table { if (container != null) { try { IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container); - for(int i = 0; i < rtfElements.Length; i++) { + for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); this.content.Add(rtfElements[i]); } @@ -262,6 +298,157 @@ namespace iTextSharp.text.rtf.table { } } + /** + * Imports the Cell properties into the RtfCell + * + * @param cell The PdfPCell to import + * @since 2.1.3 + */ + private void ImportCell(PdfPCell cell) { + this.content = new ArrayList(); + + if (cell == null) { + this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.GetParentTable().GetBorders()); + return; + } + + // padding + this.cellPadding = (int) this.parentRow.GetParentTable().GetCellPadding(); + this.cellPaddingBottom = cell.PaddingBottom; + this.cellPaddingTop = cell.PaddingTop; + this.cellPaddingRight = cell.PaddingRight; + this.cellPaddingLeft = cell.PaddingLeft; + + // BORDERS + this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor); + + // border colors + this.border = cell.Border; + this.borderColor = cell.BorderColor; + this.borderColorBottom = cell.BorderColorBottom; + this.borderColorTop = cell.BorderColorTop; + this.borderColorLeft = cell.BorderColorLeft; + this.borderColorRight = cell.BorderColorRight; + + // border widths + this.borderWidth = cell.BorderWidth; + this.borderWidthBottom = cell.BorderWidthBottom; + this.borderWidthTop = cell.BorderWidthTop; + this.borderWidthLeft = cell.BorderWidthLeft; + this.borderWidthRight = cell.BorderWidthRight; + + + this.colspan = cell.Colspan; + this.rowspan = 1; //cell.GetRowspan(); + // if (cell.GetRowspan() > 1) { + // this.mergeType = MERGE_VERT_PARENT; + // } + + + this.verticalAlignment = cell.VerticalAlignment; + + if (cell.BackgroundColor == null) { + this.backgroundColor = new RtfColor(this.document, 255, 255, 255); + } else { + this.backgroundColor = new RtfColor(this.document, cell.BackgroundColor); + } + + + // does it have column composite info? + ArrayList compositeElements = cell.CompositeElements; + if (compositeElements != null) { + // does it have column info? + Paragraph container = null; + foreach (IElement element in compositeElements) { + try { + // should we wrap it in a paragraph + if (!(element is Paragraph) && !(element is List)) { + if (container != null) { + container.Add(element); + } else { + container = new Paragraph(); + container.Alignment = cell.HorizontalAlignment; + container.Add(element); + } + } else { + IRtfBasicElement[] rtfElements = null; + if (container != null) { + rtfElements = this.document.GetMapper().MapElement(container); + for (int i = 0; i < rtfElements.Length; i++) { + rtfElements[i].SetInTable(true); + this.content.Add(rtfElements[i]); + } + container = null; + } + // if horizontal alignment is undefined overwrite + // with that of enclosing cell + if (element is Paragraph && ((Paragraph) element).Alignment == Element.ALIGN_UNDEFINED) { + ((Paragraph) element).Alignment = cell.HorizontalAlignment; + } + + rtfElements = this.document.GetMapper().MapElement(element); + for (int i = 0; i < rtfElements.Length; i++) { + rtfElements[i].SetInTable(true); + this.content.Add(rtfElements[i]); + } + } + } catch (DocumentException) { + } + } + if (container != null) { + try { + IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container); + for (int i = 0; i < rtfElements.Length; i++) { + rtfElements[i].SetInTable(true); + this.content.Add(rtfElements[i]); + } + } catch (DocumentException) { + } + } + } + + // does it have image info? + + Image img = cell.Image; + if (img != null) { + try { + IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(img); + for (int i = 0; i < rtfElements.Length; i++) { + rtfElements[i].SetInTable(true); + this.content.Add(rtfElements[i]); + } + } catch (DocumentException) { + } + } + // does it have phrase info? + Phrase phrase = cell.Phrase; + if (phrase != null) { + try { + IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(phrase); + for (int i = 0; i < rtfElements.Length; i++) { + rtfElements[i].SetInTable(true); + this.content.Add(rtfElements[i]); + } + } catch (DocumentException) { + } + } + // does it have table info? + PdfPTable table = cell.Table; + if (table != null) { + this.Add(table); + // try { + // RtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(table); + // for (int i = 0; i < rtfElements.length; i++) { + // rtfElements[i].SetInTable(true); + // this.content.Add(rtfElements[i]); + // } + // } catch (DocumentException e) { + // // TODO Auto-generated catch block + // e.PrintStackTrace(); + // } + } + + } /** * Write the cell definition part of this RtfCell * @@ -292,14 +479,14 @@ namespace iTextSharp.text.rtf.table { result.Write(t = DocWriter.GetISOBytes("\\clcbpat"), 0, t.Length); result.Write(t = IntToByteArray(this.backgroundColor.GetColorNumber()), 0, t.Length); } - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); result.Write(t = DocWriter.GetISOBytes("\\clftsWidth3"), 0, t.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); result.Write(t = DocWriter.GetISOBytes("\\clwWidth"), 0, t.Length); result.Write(t = IntToByteArray(this.cellWidth), 0, t.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); if (this.cellPadding > 0) { result.Write(t = DocWriter.GetISOBytes("\\clpadl"), 0, t.Length); diff --git a/src/core/iTextSharp/text/rtf/table/RtfRow.cs b/src/core/iTextSharp/text/rtf/table/RtfRow.cs index 9962a7d..d50fe13 100644 --- a/src/core/iTextSharp/text/rtf/table/RtfRow.cs +++ b/src/core/iTextSharp/text/rtf/table/RtfRow.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Collections; using iTextSharp.text; +using iTextSharp.text.pdf; using iTextSharp.text.rtf; using iTextSharp.text.rtf.document; /* @@ -191,6 +192,21 @@ namespace iTextSharp.text.rtf.table { ImportRow(row); } + /** + * Constructs a RtfRow for a Row. + * + * @param doc The RtfDocument this RtfRow belongs to + * @param rtfTable The RtfTable this RtfRow belongs to + * @param row The Row this RtfRow is based on + * @param rowNumber The number of this row + * @since 2.1.3 + */ + protected internal RtfRow(RtfDocument doc, RtfTable rtfTable, PdfPRow row, int rowNumber) : base(doc) { + this.parentTable = rtfTable; + this.rowNumber = rowNumber; + ImportRow(row); + } + /** * Imports a Row and copies all settings * @@ -215,6 +231,32 @@ namespace iTextSharp.text.rtf.table { } } + /** + * Imports a PdfPRow and copies all settings + * + * @param row The PdfPRow to import + * @since 2.1.3 + */ + private void ImportRow(PdfPRow row) { + this.cells = new ArrayList(); + this.width = this.document.GetDocumentHeader().GetPageSetting().GetPageWidth() - this.document.GetDocumentHeader().GetPageSetting().GetMarginLeft() - this.document.GetDocumentHeader().GetPageSetting().GetMarginRight(); + this.width = (int) (this.width * this.parentTable.GetTableWidthPercent() / 100); + + int cellRight = 0; + int cellWidth = 0; + PdfPCell[] cells = row.GetCells(); + for (int i = 0; i < cells.Length; i++) { + cellWidth = (int) (this.width * this.parentTable.GetProportionalWidths()[i] / 100); + cellRight = cellRight + cellWidth; + + PdfPCell cell = cells[i]; + RtfCell rtfCell = new RtfCell(this.document, this, cell); + rtfCell.SetCellRight(cellRight); + rtfCell.SetCellWidth(cellWidth); + this.cells.Add(rtfCell); + } + } + /** * Performs a second pass over all cells to handle cell row/column spanning. */ @@ -271,12 +313,12 @@ namespace iTextSharp.text.rtf.table { /** * Writes the row definition/settings. * - * @param result The OutputStream to write the definitions to. + * @param result The Stream to write the definitions to. */ private void WriteRowDefinition(Stream result) { byte[] t; result.Write(ROW_BEGIN, 0, ROW_BEGIN.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); result.Write(ROW_WIDTH_STYLE, 0, ROW_WIDTH_STYLE.Length); result.Write(ROW_WIDTH, 0, ROW_WIDTH.Length); result.Write(t = IntToByteArray(this.width), 0, t.Length); @@ -303,7 +345,10 @@ namespace iTextSharp.text.rtf.table { } result.Write(ROW_GRAPH, 0, ROW_GRAPH.Length); - this.parentTable.GetBorders().WriteContent(result); + RtfBorderGroup borders = this.parentTable.GetBorders(); + if (borders != null) { + borders.WriteContent(result); + } if (this.parentTable.GetCellSpacing() > 0) { result.Write(ROW_CELL_SPACING_LEFT, 0, ROW_CELL_SPACING_LEFT.Length); @@ -327,7 +372,7 @@ namespace iTextSharp.text.rtf.table { result.Write(ROW_CELL_PADDING_LEFT_STYLE, 0, ROW_CELL_PADDING_LEFT_STYLE.Length); result.Write(ROW_CELL_PADDING_RIGHT_STYLE, 0, ROW_CELL_PADDING_RIGHT_STYLE.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); for (int i = 0; i < this.cells.Count; i++) { RtfCell rtfCell = (RtfCell) this.cells[i]; @@ -353,7 +398,7 @@ namespace iTextSharp.text.rtf.table { } result.Write(ROW_END, 0, ROW_END.Length); - result.WriteByte((byte)'\n'); + this.document.OutputDebugLinebreak(result); } /** diff --git a/src/core/iTextSharp/text/rtf/table/RtfTable.cs b/src/core/iTextSharp/text/rtf/table/RtfTable.cs index d5bcab3..d432b04 100644 --- a/src/core/iTextSharp/text/rtf/table/RtfTable.cs +++ b/src/core/iTextSharp/text/rtf/table/RtfTable.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Collections; using iTextSharp.text; +using iTextSharp.text.pdf; using iTextSharp.text.rtf; using iTextSharp.text.rtf.document; using iTextSharp.text.rtf.text; @@ -125,6 +126,17 @@ namespace iTextSharp.text.rtf.table { ImportTable(table); } + /** + * Constructs a RtfTable based on a PdfTable for a RtfDocument. + * + * @param doc The RtfDocument this RtfTable belongs to + * @param table The PdfPTable that this RtfTable wraps + * @since 2.1.3 + */ + public RtfTable(RtfDocument doc, PdfPTable table) : base(doc) { + ImportTable(table); + } + /** * Imports the rows and settings from the Table into this * RtfTable. @@ -157,6 +169,35 @@ namespace iTextSharp.text.rtf.table { } } + /** + * Imports the rows and settings from the Table into this + * RtfTable. + * + * @param table The source PdfPTable + * @since 2.1.3 + */ + private void ImportTable(PdfPTable table) { + this.rows = new ArrayList(); + this.tableWidthPercent = table.WidthPercentage; + this.proportionalWidths = table.AbsoluteWidths; + this.cellPadding = (float) (table.SpacingAfter * TWIPS_FACTOR); + this.cellSpacing = (float) (table.SpacingAfter * TWIPS_FACTOR); + this.alignment = table.HorizontalAlignment; + + int i = 0; + foreach (PdfPRow row in table.Rows) { + this.rows.Add(new RtfRow(this.document, this, row, i)); + i++; + } + foreach (RtfRow row in this.rows) { + row.HandleCellSpanning(); + row.CleanRow(); + } + + this.headerRows = table.HeaderRows; + this.cellsFitToPage = table.KeepTogether; + } + /** * Writes the content of this RtfTable */ diff --git a/src/core/iTextSharp/text/rtf/text/RtfParagraph.cs b/src/core/iTextSharp/text/rtf/text/RtfParagraph.cs index 9ba0b1d..92d2a4e 100644 --- a/src/core/iTextSharp/text/rtf/text/RtfParagraph.cs +++ b/src/core/iTextSharp/text/rtf/text/RtfParagraph.cs @@ -152,9 +152,7 @@ namespace iTextSharp.text.rtf.text { if (!inTable) { result.Write(PARAGRAPH, 0, PARAGRAPH.Length); } - if(this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) { - result.WriteByte((byte)'\n'); - } + this.document.OutputDebugLinebreak(result); } /** diff --git a/src/core/itextsharp.csproj b/src/core/itextsharp.csproj index 0a83bac..ec50064 100644 --- a/src/core/itextsharp.csproj +++ b/src/core/itextsharp.csproj @@ -857,6 +857,16 @@ SubType = "Code" BuildAction = "Compile" /> + + + +