ResetAlignment() public method

public ResetAlignment ( ) : void
return void
        private void addList(List list, float left, float right, int alignment)
        {
            PdfChunk  chunk;
            PdfChunk  overflow;
            ArrayList allActions = new ArrayList();

            ProcessActions(list, null, allActions);
            int aCounter = 0;

            foreach (IElement ele in list.Items)
            {
                switch (ele.Type)
                {
                case LISTITEM:
                    ListItem item = (ListItem)ele;
                    _line          = new PdfLine(left + item.IndentationLeft, right, alignment, item.Leading);
                    _line.ListItem = item;
                    foreach (Chunk c in item.Chunks)
                    {
                        chunk = new PdfChunk(c, (PdfAction)(allActions[aCounter++]));
                        while ((overflow = _line.Add(chunk)) != null)
                        {
                            addLine(_line);
                            _line = new PdfLine(left + item.IndentationLeft, right, alignment, item.Leading);
                            chunk = overflow;
                        }
                        _line.ResetAlignment();
                        addLine(_line);
                        _line = new PdfLine(left + item.IndentationLeft, right, alignment, _leading);
                    }
                    break;

                case LIST:
                    List sublist = (List)ele;
                    addList(sublist, left + sublist.IndentationLeft, right, alignment);
                    break;
                }
            }
        }
Esempio n. 2
0
        // constructors
        /**
         * Constructs a <CODE>PdfCell</CODE>-object.
         *
         * @param   cell        the original <CODE>Cell</CODE>
         * @param   rownumber   the number of the <CODE>Row</CODE> the <CODE>Cell</CODE> was in.
         * @param   left        the left border of the <CODE>PdfCell</CODE>
         * @param   right       the right border of the <CODE>PdfCell</CODE>
         * @param   top         the top border of the <CODE>PdfCell</CODE>
         * @param   cellspacing the cellspacing of the <CODE>Table</CODE>
         * @param   cellpadding the cellpadding of the <CODE>Table</CODE>
         */
        public PdfCell(Cell cell, int rownumber, float left, float right, float top, float cellspacing, float cellpadding)
            : base(left, top, right, top)
        {
            // copying the other Rectangle attributes from class Cell
            CloneNonPositionParameters(cell);
            this.cellpadding = cellpadding;
            this.cellspacing = cellspacing;
            this.verticalAlignment = cell.VerticalAlignment;
            this.useAscender = cell.UseAscender;
            this.useDescender = cell.UseDescender;
            this.useBorderPadding = cell.UseBorderPadding;

            // initialisation of some parameters
            PdfChunk chunk;
            PdfChunk overflow;
            lines = new ArrayList();
            images = new ArrayList();
            leading = cell.Leading;
            int alignment = cell.HorizontalAlignment;
            left += cellspacing + cellpadding;
            right -= cellspacing + cellpadding;

            left += GetBorderWidthInside(LEFT_BORDER);
            right -= GetBorderWidthInside(RIGHT_BORDER);
            contentHeight = 0;
            rowspan = cell.Rowspan;

            ArrayList allActions;
            int aCounter;
            // we loop over all the elements of the cell
            foreach (IElement ele in cell.Elements) {
                switch (ele.Type) {
                    case Element.JPEG:
                    case Element.IMGRAW:
                    case Element.IMGTEMPLATE:
                        AddImage((Image)ele, left, right, 0.4f * leading, alignment);
                        break;
                        // if the element is a list
                    case Element.LIST:
                        if (line != null && line.Size > 0) {
                            line.ResetAlignment();
                            AddLine(line);
                        }
                        allActions = new ArrayList();
                        ProcessActions(ele, null, allActions);
                        aCounter = 0;
                        // we loop over all the listitems
                        foreach (ListItem item in ((List)ele).Items) {
                            line = new PdfLine(left + item.IndentationLeft, right, alignment, item.Leading);
                            line.ListItem = item;
                            foreach (Chunk c in item.Chunks) {
                                chunk = new PdfChunk(c, (PdfAction)(allActions[aCounter++]));
                                while ((overflow = line.Add(chunk)) != null) {
                                    AddLine(line);
                                    line = new PdfLine(left + item.IndentationLeft, right, alignment, item.Leading);
                                    chunk = overflow;
                                }
                                line.ResetAlignment();
                                AddLine(line);
                                line = new PdfLine(left + item.IndentationLeft, right, alignment, leading);
                            }
                        }
                        line = new PdfLine(left, right, alignment, leading);
                        break;
                        // if the element is something else
                    default:
                        allActions = new ArrayList();
                        ProcessActions(ele, null, allActions);
                        aCounter = 0;

                        float currentLineLeading = leading;
                        float currentLeft = left;
                        float currentRight = right;
                        if (ele is Phrase) {
                            currentLineLeading = ((Phrase) ele).Leading;
                        }
                        if (ele is Paragraph) {
                            Paragraph p = (Paragraph) ele;
                            currentLeft += p.IndentationLeft;
                            currentRight -= p.IndentationRight;
                        }
                        if (line == null) {
                            line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                        }
                        // we loop over the chunks
                        ArrayList chunks = ele.Chunks;
                        if (chunks.Count == 0) {
                            AddLine(line); // add empty line - all cells need some lines even if they are empty
                            line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                        }
                        else {
                            foreach (Chunk c in chunks) {
                                chunk = new PdfChunk(c, (PdfAction)allActions[aCounter++]);
                                while ((overflow = line.Add(chunk)) != null) {
                                    AddLine(line);
                                    line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                                    chunk = overflow;
                                }
                            }
                        }
                        // if the element is a paragraph, section or chapter, we reset the alignment and add the line
                        switch (ele.Type) {
                            case Element.PARAGRAPH:
                            case Element.SECTION:
                            case Element.CHAPTER:
                                line.ResetAlignment();
                                FlushCurrentLine();
                                break;
                        }
                        break;
                }
            }
            FlushCurrentLine();
            if (lines.Count > cell.MaxLines) {
                while (lines.Count > cell.MaxLines) {
                    RemoveLine(lines.Count - 1);
                }
                if (cell.MaxLines > 0) {
                    String more = cell.ShowTruncation;
                    if (more != null && more.Length > 0) {
                        // Denote that the content has been truncated
                        lastLine = (PdfLine) lines[lines.Count - 1];
                        if (lastLine.Size >= 0) {
                            PdfChunk lastChunk = lastLine.GetChunk(lastLine.Size - 1);
                            float moreWidth = new PdfChunk(more, lastChunk).Width;
                            while (lastChunk.ToString().Length > 0 && lastChunk.Width + moreWidth > right - left) {
                                // Remove characters to leave room for the 'more' indicator
                                lastChunk.Value = lastChunk.ToString().Substring(0, lastChunk.Length - 1);
                            }
                            lastChunk.Value = lastChunk.ToString() + more;
                        } else {
                            lastLine.Add(new PdfChunk(new Chunk(more), null));
                        }
                    }
                }
            }
            // we set some additional parameters
            if (useDescender && lastLine != null) {
                contentHeight -= lastLine.Descender;
            }

            // adjust first line height so that it touches the top
            if (lines.Count > 0) {
                firstLine = (PdfLine) lines[0];
                float firstLineRealHeight = FirstLineRealHeight;
                contentHeight -= firstLine.Height;
                firstLine.height = firstLineRealHeight;
                contentHeight += firstLineRealHeight;
            }

            float newBottom = top - contentHeight - (2f * Cellpadding) - (2f * Cellspacing);
            newBottom -= GetBorderWidthInside(TOP_BORDER) + GetBorderWidthInside(BOTTOM_BORDER);
            Bottom = newBottom;

            this.rownumber = rownumber;
        }
        /// <summary>
        /// constructors
        /// </summary>

        /// <summary>
        /// Constructs a  PdfCell -object.
        /// </summary>
        /// <param name="cell">the original  Cell </param>
        /// <param name="rownumber">the number of the  Row  the  Cell  was in.</param>
        /// <param name="left">the left border of the  PdfCell </param>
        /// <param name="right">the right border of the  PdfCell </param>
        /// <param name="top">the top border of the  PdfCell </param>
        /// <param name="cellspacing">the cellspacing of the  Table </param>
        /// <param name="cellpadding">the cellpadding of the  Table </param>

        public PdfCell(Cell cell, int rownumber, float left, float right, float top, float cellspacing, float cellpadding) : base(left, top, right, top)
        {
            // copying the other Rectangle attributes from class Cell
            CloneNonPositionParameters(cell);
            _cellpadding       = cellpadding;
            _cellspacing       = cellspacing;
            _verticalAlignment = cell.VerticalAlignment;
            _useAscender       = cell.UseAscender;
            _useDescender      = cell.UseDescender;
            _useBorderPadding  = cell.UseBorderPadding;

            // initialisation of some parameters
            PdfChunk chunk;
            PdfChunk overflow;

            _lines   = new ArrayList();
            _images  = new ArrayList();
            _leading = cell.Leading;
            int alignment = cell.HorizontalAlignment;

            left  += cellspacing + cellpadding;
            right -= cellspacing + cellpadding;

            left          += getBorderWidthInside(LEFT_BORDER);
            right         -= getBorderWidthInside(RIGHT_BORDER);
            _contentHeight = 0;
            _rowspan       = cell.Rowspan;

            ArrayList allActions;
            int       aCounter;

            // we loop over all the elements of the cell
            foreach (IElement ele in cell.Elements)
            {
                switch (ele.Type)
                {
                case JPEG:
                case JPEG2000:
                case JBIG2:
                case IMGRAW:
                case IMGTEMPLATE:
                    addImage((Image)ele, left, right, 0.4f * _leading, alignment);
                    break;

                // if the element is a list
                case LIST:
                    if (_line != null && _line.Size > 0)
                    {
                        _line.ResetAlignment();
                        addLine(_line);
                    }
                    // we loop over all the listitems
                    addList((List)ele, left, right, alignment);
                    _line = new PdfLine(left, right, alignment, _leading);
                    break;

                // if the element is something else
                default:
                    allActions = new ArrayList();
                    ProcessActions(ele, null, allActions);
                    aCounter = 0;

                    float currentLineLeading = _leading;
                    float currentLeft        = left;
                    float currentRight       = right;
                    if (ele is Phrase)
                    {
                        currentLineLeading = ((Phrase)ele).Leading;
                    }
                    if (ele is Paragraph)
                    {
                        Paragraph p = (Paragraph)ele;
                        currentLeft  += p.IndentationLeft;
                        currentRight -= p.IndentationRight;
                    }
                    if (_line == null)
                    {
                        _line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                    }
                    // we loop over the chunks
                    ArrayList chunks = ele.Chunks;
                    if (chunks.Count == 0)
                    {
                        addLine(_line);     // add empty line - all cells need some lines even if they are empty
                        _line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                    }
                    else
                    {
                        foreach (Chunk c in chunks)
                        {
                            chunk = new PdfChunk(c, (PdfAction)allActions[aCounter++]);
                            while ((overflow = _line.Add(chunk)) != null)
                            {
                                addLine(_line);
                                _line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                                chunk = overflow;
                            }
                        }
                    }
                    // if the element is a paragraph, section or chapter, we reset the alignment and add the line
                    switch (ele.Type)
                    {
                    case PARAGRAPH:
                    case SECTION:
                    case CHAPTER:
                        _line.ResetAlignment();
                        flushCurrentLine();
                        break;
                    }
                    break;
                }
            }
            flushCurrentLine();
            if (_lines.Count > cell.MaxLines)
            {
                while (_lines.Count > cell.MaxLines)
                {
                    removeLine(_lines.Count - 1);
                }
                if (cell.MaxLines > 0)
                {
                    string more = cell.ShowTruncation;
                    if (!string.IsNullOrEmpty(more))
                    {
                        // Denote that the content has been truncated
                        _lastLine = (PdfLine)_lines[_lines.Count - 1];
                        if (_lastLine.Size >= 0)
                        {
                            PdfChunk lastChunk = _lastLine.GetChunk(_lastLine.Size - 1);
                            float    moreWidth = new PdfChunk(more, lastChunk).Width;
                            while (lastChunk.ToString().Length > 0 && lastChunk.Width + moreWidth > right - left)
                            {
                                // Remove characters to leave room for the 'more' indicator
                                lastChunk.Value = lastChunk.ToString().Substring(0, lastChunk.Length - 1);
                            }
                            lastChunk.Value = lastChunk + more;
                        }
                        else
                        {
                            _lastLine.Add(new PdfChunk(new Chunk(more), null));
                        }
                    }
                }
            }
            // we set some additional parameters
            if (_useDescender && _lastLine != null)
            {
                _contentHeight -= _lastLine.Descender;
            }

            // adjust first line height so that it touches the top
            if (_lines.Count > 0)
            {
                _firstLine = (PdfLine)_lines[0];
                float firstLineRealHeight = FirstLineRealHeight;
                _contentHeight   -= _firstLine.Height;
                _firstLine.height = firstLineRealHeight;
                _contentHeight   += firstLineRealHeight;
            }

            float newBottom = top - _contentHeight - (2f * Cellpadding) - (2f * Cellspacing);

            newBottom -= getBorderWidthInside(TOP_BORDER) + getBorderWidthInside(BOTTOM_BORDER);
            Bottom     = newBottom;

            _rownumber = rownumber;
        }
Esempio n. 4
0
 private void AddList(List list, float left, float right, int alignment) {
     PdfChunk chunk;
     PdfChunk overflow;
     ArrayList allActions = new ArrayList();
     ProcessActions(list, null, allActions);
     int aCounter = 0;
     foreach (IElement ele in list.Items) {
         switch (ele.Type) {
             case Element.LISTITEM:
                 ListItem item = (ListItem)ele;
                 line = new PdfLine(left + item.IndentationLeft, right, alignment, item.Leading);
                 line.ListItem = item;
                 foreach (Chunk c in item.Chunks) {
                     chunk = new PdfChunk(c, (PdfAction)(allActions[aCounter++]));
                     while ((overflow = line.Add(chunk)) != null) { 
                         AddLine(line);
                         line = new PdfLine(left + item.IndentationLeft, right, alignment, item.Leading);
                         chunk = overflow;
                     }
                     line.ResetAlignment();
                     AddLine(line);
                     line = new PdfLine(left + item.IndentationLeft, right, alignment, leading);
                 }
                 break;
             case Element.LIST:
                 List sublist = (List)ele;
                 AddList(sublist, left + sublist.IndentationLeft, right, alignment);
                 break;
         }
     }
 }