Example #1
0
        /**
         * Imports the rows and settings from the Table into this
         * RtfTable.
         *
         * @param table The source Table
         */
        private void ImportTable(Table table)
        {
            this.rows = new ArrayList();
            this.tableWidthPercent  = table.Width;
            this.proportionalWidths = table.ProportionalWidths;
            this.cellPadding        = (float)(table.Cellpadding * TWIPS_FACTOR);
            this.cellSpacing        = (float)(table.Cellspacing * TWIPS_FACTOR);
            this.borders            = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.Border, table.BorderWidth, table.BorderColor);
            this.alignment          = table.Alignment;

            int i = 0;

            foreach (Row row in table)
            {
                this.rows.Add(new RtfRow(this.document, this, row, i));
                i++;
            }
            for (i = 0; i < this.rows.Count; i++)
            {
                ((RtfRow)this.rows[i]).HandleCellSpanning();
                ((RtfRow)this.rows[i]).CleanRow();
            }
            this.headerRows     = table.LastHeaderRow;
            this.cellsFitToPage = table.CellsFitPage;
            this.tableFitToPage = table.TableFitsPage;
            if (!float.IsNaN(table.Offset))
            {
                this.offset = (int)(table.Offset * 2);
            }
        }
Example #2
0
 /**
  * Merge this cell into the parent cell.
  *
  * @param mergeParent The RtfCell to merge with
  */
 protected internal void SetCellMergeChild(RtfCell mergeParent)
 {
     this.mergeType         = MERGE_VERT_CHILD;
     this.cellWidth         = mergeParent.GetCellWidth();
     this.cellRight         = mergeParent.GetCellRight();
     this.cellPadding       = mergeParent.GetCellpadding();
     this.borders           = mergeParent.GetBorders();
     this.verticalAlignment = mergeParent.VerticalAlignment;
     this.backgroundColor   = mergeParent.GetRtfBackgroundColor();
 }
Example #3
0
 /**
  * Constructs a RtfBorderGroup based on another RtfBorderGroup.
  *
  * @param doc The RtfDocument this RtfBorderGroup belongs to
  * @param borderType The type of borders this RtfBorderGroup contains
  * @param borderGroup The RtfBorderGroup to use as a base
  */
 protected internal RtfBorderGroup(RtfDocument doc, int borderType, RtfBorderGroup borderGroup) : base(doc)
 {
     this.borders    = new Hashtable();
     this.borderType = borderType;
     if (borderGroup != null)
     {
         foreach (DictionaryEntry entry in borderGroup.GetBorders())
         {
             int       borderPos = (int)entry.Key;
             RtfBorder border    = (RtfBorder)entry.Value;
             this.borders[borderPos] = new RtfBorder(this.document, this.borderType, border);
         }
     }
 }
Example #4
0
        /**
         * Writes the row definition/settings.
         *
         * @param result The <code>Stream</code> to write the definitions to.
         */
        private void WriteRowDefinition(Stream result)
        {
            byte[] t;
            result.Write(ROW_BEGIN, 0, ROW_BEGIN.Length);
            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);
            if (this.parentTable.GetCellsFitToPage())
            {
                result.Write(ROW_KEEP_TOGETHER, 0, ROW_KEEP_TOGETHER.Length);
            }
            if (this.rowNumber <= this.parentTable.GetHeaderRows())
            {
                result.Write(ROW_HEADER_ROW, 0, ROW_HEADER_ROW.Length);
            }
            switch (this.parentTable.GetAlignment())
            {
            case Element.ALIGN_LEFT:
                result.Write(ROW_ALIGN_LEFT, 0, ROW_ALIGN_LEFT.Length);
                break;

            case Element.ALIGN_RIGHT:
                result.Write(ROW_ALIGN_RIGHT, 0, ROW_ALIGN_RIGHT.Length);
                break;

            case Element.ALIGN_CENTER:
                result.Write(ROW_ALIGN_CENTER, 0, ROW_ALIGN_CENTER.Length);
                break;

            case Element.ALIGN_JUSTIFIED:
            case Element.ALIGN_JUSTIFIED_ALL:
                result.Write(ROW_ALIGN_JUSTIFIED, 0, ROW_ALIGN_JUSTIFIED.Length);
                break;
            }
            result.Write(ROW_GRAPH, 0, ROW_GRAPH.Length);

            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);
                result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
                result.Write(ROW_CELL_SPACING_LEFT_STYLE, 0, ROW_CELL_SPACING_LEFT_STYLE.Length);
                result.Write(ROW_CELL_SPACING_TOP, 0, ROW_CELL_SPACING_TOP.Length);
                result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
                result.Write(ROW_CELL_SPACING_TOP_STYLE, 0, ROW_CELL_SPACING_TOP_STYLE.Length);
                result.Write(ROW_CELL_SPACING_RIGHT, 0, ROW_CELL_SPACING_RIGHT.Length);
                result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
                result.Write(ROW_CELL_SPACING_RIGHT_STYLE, 0, ROW_CELL_SPACING_RIGHT_STYLE.Length);
                result.Write(ROW_CELL_SPACING_BOTTOM, 0, ROW_CELL_SPACING_BOTTOM.Length);
                result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
                result.Write(ROW_CELL_SPACING_BOTTOM_STYLE, 0, ROW_CELL_SPACING_BOTTOM_STYLE.Length);
            }

            result.Write(ROW_CELL_PADDING_LEFT, 0, ROW_CELL_PADDING_LEFT.Length);
            result.Write(t = IntToByteArray((int)(this.parentTable.GetCellPadding() / 2)), 0, t.Length);
            result.Write(ROW_CELL_PADDING_RIGHT, 0, ROW_CELL_PADDING_RIGHT.Length);
            result.Write(t = IntToByteArray((int)(this.parentTable.GetCellPadding() / 2)), 0, t.Length);
            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);

            this.document.OutputDebugLinebreak(result);

            for (int i = 0; i < this.cells.Count; i++)
            {
                RtfCell rtfCell = (RtfCell)this.cells[i];
                rtfCell.WriteDefinition(result);
            }
        }
Example #5
0
 /**
  * Set the borders of this RtfCell
  *
  * @param borderGroup The RtfBorderGroup to use as borders
  */
 public void SetBorders(RtfBorderGroup borderGroup)
 {
     this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, borderGroup);
 }
Example #6
0
        /**
         * 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();
                //          }
            }
        }
Example #7
0
        /**
         * Imports the Cell properties into the RtfCell
         *
         * @param cell The Cell to import
         */
        private void ImportCell(Cell cell)
        {
            this.content = new ArrayList();

            if (cell == null)
            {
                this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.GetParentTable().GetBorders());
                return;
            }

            this.colspan = cell.Colspan;
            this.rowspan = cell.Rowspan;
            if (cell.Rowspan > 1)
            {
                this.mergeType = MERGE_VERT_PARENT;
            }
            if (cell is RtfCell)
            {
                this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, ((RtfCell)cell).GetBorders());
            }
            else
            {
                this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor);
            }
            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);
            }

            this.cellPadding = (int)this.parentRow.GetParentTable().GetCellPadding();

            Paragraph container = null;

            foreach (IElement element in cell.Elements)
            {
                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
                    {
                        if (container != null)
                        {
                            IRtfBasicElement[] 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;
                        }

                        IRtfBasicElement[] rtfElements2 = this.document.GetMapper().MapElement(element);
                        for (int i = 0; i < rtfElements2.Length; i++)
                        {
                            rtfElements2[i].SetInTable(true);
                            this.content.Add(rtfElements2[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) {
                }
            }
        }
Example #8
0
 /**
  * Constructs a RtfCell based upon an Element
  *
  * @param element The Element to base the RtfCell on
  * @throws BadElementException If the Element is not valid
  */
 public RtfCell(IElement element) : base(element)
 {
     this.borders      = new RtfBorderGroup();
     verticalAlignment = Element.ALIGN_MIDDLE;
 }