Пример #1
0
        public void WrapAroundCellText()
        {
            List <List <Cell> > list = new List <List <Cell> >();

            for (int i = 0; i < this.tableData.Count; i++)
            {
                List <Cell> list2 = this.tableData[i];
                int         num   = 1;
                for (int j = 0; j < list2.Count; j++)
                {
                    Cell cell    = list2[j];
                    int  colSpan = cell.GetColSpan();
                    for (int k = 1; k < colSpan; k++)
                    {
                        Cell cell2 = list2[j + k];
                        cell.SetWidth((double)(cell.GetWidth() + cell2.GetWidth()));
                        cell2.SetWidth(0.0);
                    }
                    int numVerCells = cell.GetNumVerCells(this.padding);
                    if (numVerCells > num)
                    {
                        num = numVerCells;
                    }
                }
                for (int l = 0; l < num; l++)
                {
                    List <Cell> list3 = new List <Cell>();
                    for (int m = 0; m < list2.Count; m++)
                    {
                        Cell cell3 = list2[m];
                        Cell cell4 = new Cell(cell3.GetFont(), "");
                        cell4.SetPoint(cell3.GetPoint());
                        cell4.SetCompositeTextLine(cell3.GetCompositeTextLine());
                        cell4.SetWidth((double)cell3.GetWidth());
                        if (l == 0)
                        {
                            cell4.SetTopPadding(cell3.top_padding);
                        }
                        if (l == num - 1)
                        {
                            cell4.SetBottomPadding(cell3.bottom_padding);
                        }
                        cell4.SetLeftPadding(cell3.left_padding);
                        cell4.SetRightPadding(cell3.right_padding);
                        cell4.SetLineWidth(cell3.GetLineWidth());
                        cell4.SetBgColor(cell3.GetBgColor());
                        cell4.SetPenColor(cell3.GetPenColor());
                        cell4.SetBrushColor(cell3.GetBrushColor());
                        cell4.SetProperties(cell3.GetProperties());
                        if (l == 0)
                        {
                            cell4.SetText(cell3.GetText());
                        }
                        else
                        {
                            if (l > 0)
                            {
                                cell4.SetBorder(65536, false);
                                if (l < num - 1)
                                {
                                    cell4.SetBorder(131072, false);
                                }
                            }
                        }
                        list3.Add(cell4);
                    }
                    list.Add(list3);
                }
            }
            for (int n = 0; n < list.Count; n++)
            {
                List <Cell> list4 = list[n];
                for (int num2 = 0; num2 < list4.Count; num2++)
                {
                    Cell cell5 = list4[num2];
                    if (cell5.text != null)
                    {
                        int           num3          = 0;
                        string[]      array         = Regex.Split(cell5.GetText(), "\\s+");
                        StringBuilder stringBuilder = new StringBuilder();
                        if (array.Length == 1)
                        {
                            stringBuilder.Append(array[0]);
                        }
                        else
                        {
                            for (int num4 = 0; num4 < array.Length; num4++)
                            {
                                string text = array[num4];
                                if (cell5.font.StringWidth(stringBuilder.ToString() + " " + text) > cell5.GetWidth() - (cell5.left_padding + cell5.right_padding + 2f * this.padding))
                                {
                                    list[n + num3][num2].SetText(stringBuilder.ToString());
                                    stringBuilder = new StringBuilder(text);
                                    num3++;
                                }
                                else
                                {
                                    if (num4 > 0)
                                    {
                                        stringBuilder.Append(" ");
                                    }
                                    stringBuilder.Append(text);
                                }
                            }
                        }
                        list[n + num3][num2].SetText(stringBuilder.ToString());
                    }
                }
            }
            this.tableData = list;
        }
Пример #2
0
        /**
         *  Wraps around the text in all cells so it fits the column width.
         *  This method should be called after all calls to SetColumnWidth and AutoAdjustColumnWidths.
         *
         */
        public void WrapAroundCellText()
        {
            List<List<Cell>> tableData2 = new List<List<Cell>>();

            for (int i = 0; i < tableData.Count; i++) {
            List<Cell> row = tableData[i];
            int maxNumVerCells = 1;
            for (int j = 0; j < row.Count; j++) {
                Cell cell = row[j];
                int colspan = cell.GetColSpan();
                for (int n = 1; n < colspan; n++) {
                    Cell next = row[j + n];
                    cell.SetWidth(cell.GetWidth() + next.GetWidth());
                    next.SetWidth(0f);
                }
                int numVerCells = cell.GetNumVerCells();
                if (numVerCells > maxNumVerCells) {
                    maxNumVerCells = numVerCells;
                }
            }

            for (int j = 0; j < maxNumVerCells; j++) {
                List<Cell> row2 = new List<Cell>();
                for (int k = 0; k < row.Count; k++) {
                    Cell cell = row[k];

                    Cell cell2 = new Cell(cell.GetFont(), "");
                    cell2.SetFallbackFont(cell.GetFallbackFont());
                    cell2.SetPoint(cell.GetPoint());
                    cell2.SetCompositeTextLine(cell.GetCompositeTextLine());
                    cell2.SetWidth(cell.GetWidth());
                    if (j == 0) {
                        cell2.SetTopPadding(cell.top_padding);
                    }
                    if (j == (maxNumVerCells - 1)) {
                        cell2.SetBottomPadding(cell.bottom_padding);
                    }
                    cell2.SetLeftPadding(cell.left_padding);
                    cell2.SetRightPadding(cell.right_padding);
                    cell2.SetLineWidth(cell.GetLineWidth());
                    cell2.SetBgColor(cell.GetBgColor());
                    cell2.SetPenColor(cell.GetPenColor());
                    cell2.SetBrushColor(cell.GetBrushColor());
                    cell2.SetProperties(cell.GetProperties());
                    cell2.SetImage(cell.GetImage());

                    if (j == 0) {
                        cell2.SetText(cell.GetText());
                        if (maxNumVerCells > 1) {
                            cell2.SetBorder(Border.BOTTOM, false);
                        }
                    }
                    else {
                        cell2.SetBorder(Border.TOP, false);
                        if (j < (maxNumVerCells - 1)) {
                            cell2.SetBorder(Border.BOTTOM, false);
                        }
                    }
                    row2.Add(cell2);
                }
                tableData2.Add(row2);
            }
            }

            for (int i = 0; i < tableData2.Count; i++) {
            List<Cell> row = tableData2[i];
            for (int j = 0; j < row.Count; j++) {
                Cell cell = row[j];
                if (cell.text != null) {
                    int n = 0;
                    String[] tokens = Regex.Split(cell.GetText(), @"\s+");
                    StringBuilder sb = new StringBuilder();
                    if (tokens.Length == 1) {
                        sb.Append(tokens[0]);
                    }
                    else {
                        for (int k = 0; k < tokens.Length; k++) {
                            String token = tokens[k];
                            if (cell.font.StringWidth(sb.ToString() + " " + token) >
                                    (cell.GetWidth() - (cell.left_padding + cell.right_padding))) {
                                tableData2[i + n][j].SetText(sb.ToString());
                                sb = new StringBuilder(token);
                                n++;
                            }
                            else {
                                if (k > 0) {
                                    sb.Append(" ");
                                }
                                sb.Append(token);
                            }
                        }
                    }
                    tableData2[i + n][j].SetText(sb.ToString());
                }
            }
            }

            tableData = tableData2;
        }
Пример #3
0
        public Point DrawOn(Page page, bool draw)
        {
            float num  = this.x1;
            float num2 = this.y1;

            for (int i = 0; i < this.numOfHeaderRows; i++)
            {
                float       num3 = 0f;
                List <Cell> list = this.tableData[i];
                for (int j = 0; j < list.Count; j++)
                {
                    Cell  cell = list[j];
                    float num4 = cell.GetHeight() + 2f * this.padding;
                    if (num4 > num3)
                    {
                        num3 = num4;
                    }
                    float num5 = cell.GetWidth();
                    for (int k = 1; k < cell.GetColSpan(); k++)
                    {
                        num5 += list[++j].GetWidth();
                    }
                    if (draw)
                    {
                        page.SetBrushColor(cell.GetBrushColor());
                        cell.Paint(page, num, num2, num5, num3, this.padding);
                    }
                    num += num5;
                }
                num   = this.x1;
                num2 += num3;
            }
            for (int l = this.rendered; l < this.tableData.Count; l++)
            {
                float       num3  = 0f;
                List <Cell> list2 = this.tableData[l];
                for (int m = 0; m < list2.Count; m++)
                {
                    Cell  cell2 = list2[m];
                    float num6  = cell2.GetHeight() + 2f * this.padding;
                    if (num6 > num3)
                    {
                        num3 = num6;
                    }
                    float num5 = cell2.GetWidth();
                    for (int n = 1; n < cell2.GetColSpan(); n++)
                    {
                        num5 += list2[++m].GetWidth();
                    }
                    if (draw)
                    {
                        page.SetBrushColor(cell2.GetBrushColor());
                        cell2.Paint(page, num, num2, num5, num3, this.padding);
                    }
                    num += num5;
                }
                num   = this.x1;
                num2 += num3;
                if (l < this.tableData.Count - 1)
                {
                    List <Cell> list3 = this.tableData[l + 1];
                    for (int num7 = 0; num7 < list3.Count; num7++)
                    {
                        Cell  cell3 = list3[num7];
                        float num8  = cell3.GetHeight() + 2f * this.padding;
                        if (num8 > num3)
                        {
                            num3 = num8;
                        }
                    }
                }
                if (num2 + num3 > page.height - this.bottom_margin)
                {
                    if (l == this.tableData.Count - 1)
                    {
                        this.rendered = -1;
                    }
                    else
                    {
                        this.rendered = l + 1;
                        this.numOfPages++;
                    }
                    return(new Point(num, num2));
                }
            }
            this.rendered = -1;
            return(new Point(num, num2));
        }