Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new
        /// <see cref="TableTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public TableTagWorker(IElementNode element, ProcessorContext context)
        {
            String str   = element.GetStyles().Get(CssConstants.DIRECTION);
            bool   isRtl = "rtl".Equals(str);

            tableWrapper    = new TableWrapper(isRtl);
            parentTagWorker = context.GetState().Empty() ? null : context.GetState().Top();
            if (parentTagWorker is iText.Html2pdf.Attach.Impl.Tags.TableTagWorker)
            {
                ((iText.Html2pdf.Attach.Impl.Tags.TableTagWorker)parentTagWorker).ApplyColStyles();
            }
            else
            {
                colgroupsHelper = new WaitingColgroupsHelper(element);
            }
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;
        }
Ejemplo n.º 2
0
 /// <summary>Gets the column widths.</summary>
 /// <param name="colgroups">the colgroups helper class</param>
 /// <returns>the column widths</returns>
 private UnitValue[] GetColWidths(WaitingColgroupsHelper colgroups)
 {
     UnitValue[] colWidths = new UnitValue[numberOfColumns];
     if (colgroups == null)
     {
         for (int i = 0; i < numberOfColumns; i++)
         {
             colWidths[i] = null;
         }
     }
     else
     {
         for (int i = 0; i < numberOfColumns; i++)
         {
             colWidths[i] = colgroups.GetColWrapper(i) != null?colgroups.GetColWrapper(i).GetWidth() : null;
         }
     }
     return(colWidths);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders all the rows to a
        /// <see cref="iText.Layout.Element.Table"/>
        /// object.
        /// </summary>
        /// <param name="colgroupsHelper">the colgroups helper class</param>
        /// <returns>the table</returns>
        public virtual Table ToTable(WaitingColgroupsHelper colgroupsHelper)
        {
            Table table;

            if (numberOfColumns > 0)
            {
                table = new Table(GetColWidths(colgroupsHelper));
            }
            else
            {
                // if table is empty, create empty table with single column
                table = new Table(1);
            }
            AccessiblePropHelper.TrySetLangAttribute(table, lang);
            if (headerRows != null)
            {
                for (int i = 0; i < headerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(headerRows[i]);
                    }
                    for (int j = 0; j < headerRows[i].Count; j++)
                    {
                        Cell       cell       = headerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (headerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddHeaderCell(cell);
                    }
                    if (i != headerRows.Count - 1)
                    {
                        table.GetHeader().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetHeader(), headerLang);
            }
            if (footerRows != null)
            {
                for (int i = 0; i < footerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(footerRows[i]);
                    }
                    for (int j = 0; j < footerRows[i].Count; j++)
                    {
                        Cell       cell       = footerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (footerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddFooterCell(cell);
                    }
                    if (i != footerRows.Count - 1)
                    {
                        table.GetFooter().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetFooter(), footerLang);
            }
            if (rows != null)
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(rows[i]);
                    }
                    for (int j = 0; j < rows[i].Count; j++)
                    {
                        table.AddCell(rows[i][j].cell);
                    }
                    if (i != rows.Count - 1)
                    {
                        table.StartNewRow();
                    }
                }
            }
            if (caption != null)
            {
                table.SetCaption(caption);
            }
            return(table);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Renders all the rows to a
        /// <see cref="iText.Layout.Element.Table"/>
        /// object.
        /// </summary>
        /// <param name="colgroupsHelper">the colgroups helper class</param>
        /// <returns>the table</returns>
        public virtual Table ToTable(WaitingColgroupsHelper colgroupsHelper)
        {
            Table table;

            if (numberOfColumns > 0)
            {
                table = new Table(GetColWidths(colgroupsHelper));
            }
            else
            {
                // if table is empty, create empty table with single column
                table = new Table(1);
            }
            if (headerRows != null)
            {
                for (int i = 0; i < headerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(headerRows[i]);
                    }
                    for (int j = 0; j < headerRows[i].Count; j++)
                    {
                        table.AddHeaderCell(headerRows[i][j].cell);
                    }
                    if (i != headerRows.Count - 1)
                    {
                        table.GetHeader().StartNewRow();
                    }
                }
            }
            if (footerRows != null)
            {
                for (int i = 0; i < footerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(footerRows[i]);
                    }
                    for (int j = 0; j < footerRows[i].Count; j++)
                    {
                        table.AddFooterCell(footerRows[i][j].cell);
                    }
                    if (i != footerRows.Count - 1)
                    {
                        table.GetFooter().StartNewRow();
                    }
                }
            }
            if (rows != null)
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(rows[i]);
                    }
                    for (int j = 0; j < rows[i].Count; j++)
                    {
                        table.AddCell(rows[i][j].cell);
                    }
                    if (i != rows.Count - 1)
                    {
                        table.StartNewRow();
                    }
                }
            }
            if (caption != null)
            {
                table.SetCaption(caption);
            }
            return(table);
        }