Esempio n. 1
0
        /**
         *  Use this method to find out how many vertically stacked cell are needed after call to wrapAroundCellText.
         *
         *  @return the number of vertical cells needed to wrap around the cell text.
         */
        public int GetNumVerCells()
        {
            int numOfVerCells = 1;

            if (this.text == null)
            {
                return(numOfVerCells);
            }

            float effectiveWidth = this.width - (this.leftPadding + this.rightPadding);

            String[]      tokens = TextUtils.SplitTextIntoTokens(this.text, this.font, this.fallbackFont, effectiveWidth);
            StringBuilder buf    = new StringBuilder();

            foreach (String token in tokens)
            {
                if (font.StringWidth(fallbackFont, (buf.ToString() + " " + token).Trim()) > effectiveWidth)
                {
                    numOfVerCells++;
                    buf = new StringBuilder(token);
                }
                else
                {
                    buf.Append(" ");
                    buf.Append(token);
                }
            }

            return(numOfVerCells);
        }
Esempio n. 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];
                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);
                    }
                }
            }

            // Adjust the number of header rows automatically!
            numOfHeaderRows = GetNumHeaderRows();
            rendered        = numOfHeaderRows;

            AddExtraTableRows(tableData2);

            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;
                        float    effectiveWidth = cell.width - (cell.leftPadding + cell.rightPadding);
                        String[] tokens         = TextUtils.SplitTextIntoTokens(
                            cell.text, cell.font, cell.fallbackFont, effectiveWidth);
                        StringBuilder buf = new StringBuilder();
                        foreach (String token in tokens)
                        {
                            if (cell.font.StringWidth(cell.fallbackFont,
                                                      (buf.ToString() + " " + token).Trim()) > effectiveWidth)
                            {
                                tableData2[i + n][j].SetText(buf.ToString().Trim());
                                buf = new StringBuilder(token);
                                n++;
                            }
                            else
                            {
                                buf.Append(" ");
                                buf.Append(token);
                            }
                        }
                        tableData2[i + n][j].SetText(buf.ToString().Trim());
                    }
                    else
                    {
                        tableData2[i][j].SetCompositeTextLine(cell.GetCompositeTextLine());
                    }
                }
            }

            tableData = tableData2;
        }
Esempio n. 3
0
        private float[] DrawText(Page page)
        {
            List <String> list = new List <String>();

            String[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            foreach (String line in lines)
            {
                if (IsCJK(line))
                {
                    StringBuilder buf = new StringBuilder();
                    for (int i = 0; i < line.Length; i++)
                    {
                        Char ch = line[i];
                        if (font.StringWidth(fallbackFont, buf.ToString() + ch) < this.w)
                        {
                            buf.Append(ch);
                        }
                        else
                        {
                            list.Add(buf.ToString());
                            buf.Length = 0;
                            buf.Append(ch);
                        }
                    }
                    String str = buf.ToString().Trim();
                    if (!str.Equals(""))
                    {
                        list.Add(str);
                    }
                }
                else
                {
                    if (font.StringWidth(fallbackFont, line) < this.w)
                    {
                        list.Add(line);
                    }
                    else
                    {
                        StringBuilder buf    = new StringBuilder();
                        String[]      tokens = TextUtils.SplitTextIntoTokens(line, font, fallbackFont, this.w);
                        foreach (String token in tokens)
                        {
                            if (font.StringWidth(fallbackFont, (buf.ToString() + " " + token).Trim()) < this.w)
                            {
                                buf.Append(" " + token);
                            }
                            else
                            {
                                list.Add(buf.ToString().Trim());
                                buf.Length = 0;
                                buf.Append(token);
                            }
                        }
                        String str = buf.ToString().Trim();
                        if (!str.Equals(""))
                        {
                            list.Add(str);
                        }
                    }
                }
            }
            lines = list.ToArray();

            float xText;
            float yText = y + font.ascent;

            for (int i = 0; i < lines.Length; i++)
            {
                if (textAlign == Align.LEFT)
                {
                    xText = x;
                }
                else if (textAlign == Align.RIGHT)
                {
                    xText = (x + this.w) - (font.StringWidth(fallbackFont, lines[i]));
                }
                else if (textAlign == Align.CENTER)
                {
                    xText = x + (this.w - font.StringWidth(fallbackFont, lines[i])) / 2;
                }
                else
                {
                    throw new Exception("Invalid text alignment option.");
                }

                if (page != null)
                {
                    page.DrawString(font, fallbackFont, lines[i], xText, yText);
                }

                if (i < (lines.Length - 1))
                {
                    yText += font.bodyHeight + spaceBetweenLines;
                }
            }

            this.h = (yText - y) + font.descent;
            if (page != null && drawBorder)
            {
                Box box = new Box();
                box.SetLocation(x, y);
                box.SetSize(w, h);
                box.DrawOn(page);
            }

            if (page != null && (uri != null || key != null))
            {
                page.AddAnnotation(new Annotation(
                                       uri,
                                       key, // The destination name
                                       x,
                                       y,
                                       x + w,
                                       y + h,
                                       uriLanguage,
                                       uriAltDescription,
                                       uriActualText));
            }


            return(new float[] { this.x + this.w, this.y + this.h });
        }