iTextSharp.text.pdf.PdfLine.Add C# (CSharp) Метод

Add() приватный Метод

private Add ( PdfChunk chunk ) : PdfChunk
chunk PdfChunk
Результат PdfChunk
        internal PdfChunk Add(PdfChunk chunk)
        {
            // nothing happens if the chunk is null.
            if (chunk == null || chunk.ToString().Equals("")) {
                return null;
            }

            // we split the chunk to be added
            PdfChunk overflow = chunk.Split(width);
            newlineSplit = (chunk.IsNewlineSplit() || overflow == null);
            //        if (chunk.IsNewlineSplit() && alignment == Element.ALIGN_JUSTIFIED)
            //            alignment = Element.ALIGN_LEFT;
            if (chunk.IsTab()) {
                Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB);
                float tabPosition = (float)tab[1];
                bool newline = (bool)tab[2];
                if (newline && tabPosition < originalWidth - width) {
                    return chunk;
                }
                width = originalWidth - tabPosition;
                chunk.AdjustLeft(left);
                AddToLine(chunk);
            }
            else if (chunk.IsTabSpace()) {
                if (line.Count != 0)
                {
                    float module = (float)chunk.GetAttribute(Chunk.TABSPACE);
                    float decrement = module - ((originalWidth - width) % module);
                    if (width < decrement)
                        return chunk;
                    width -= decrement;
                    AddToLine(chunk);
                }
            }
                // if the length of the chunk > 0 we add it to the line
            else if (chunk.Length > 0 || chunk.IsImage()) {
                if (overflow != null)
                    chunk.TrimLastSpace();
                width -= chunk.Width;
                AddToLine(chunk);
            }

                // if the length == 0 and there were no other chunks added to the line yet,
                // we risk to end up in an endless loop trying endlessly to add the same chunk
            else if (line.Count < 1) {
                chunk = overflow;
                overflow = chunk.Truncate(width);
                width -= chunk.Width;
                if (chunk.Length > 0) {
                    AddToLine(chunk);
                    return overflow;
                }
                    // if the chunck couldn't even be truncated, we add everything, so be it
                else {
                    if (overflow != null)
                        AddToLine(chunk);
                    return null;
                }
            }
            else {
                width += ((PdfChunk)(line[line.Count - 1])).TrimLastSpace();
            }
            return overflow;
        }

Usage Example

Пример #1
0
        /**
         * Creates a line from the chunk array.
         * @param width the width of the line
         * @return the line or null if no more chunks
         */
        protected PdfLine createLine(float width)
        {
            if (chunks.Count == 0)
            {
                return(null);
            }
            splittedChunkText   = null;
            currentStandbyChunk = null;
            PdfLine line = new PdfLine(0, width, alignment, 0);
            string  total;

            for (currentChunkMarker = 0; currentChunkMarker < chunks.Count; ++currentChunkMarker)
            {
                PdfChunk original = (PdfChunk)(chunks[currentChunkMarker]);
                total = original.ToString();
                currentStandbyChunk = line.Add(original);
                if (currentStandbyChunk != null)
                {
                    splittedChunkText = original.ToString();
                    original.Value    = total;
                    return(line);
                }
            }
            return(line);
        }
All Usage Examples Of iTextSharp.text.pdf.PdfLine::Add