Exemplo n.º 1
0
        /**
         * Outputs the lines to the document. The output can be simulated.
         * @param simulate <CODE>true</CODE> to simulate the writting to the document
         * @return returns the result of the operation. It can be <CODE>NO_MORE_TEXT</CODE>
         * and/or <CODE>NO_MORE_COLUMN</CODE>
         * @throws DocumentException on error
         */
        public int go(bool simulate)
        {
            bool  dirty = false;
            float ratio = spaceCharRatio;

            Object[] currentValues  = new Object[2];
            PdfFont  currentFont    = null;
            float    lastBaseFactor = 0F;

            currentValues[1] = lastBaseFactor;
            PdfDocument    pdf               = null;
            PdfContentByte graphics          = null;
            int            localRunDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;

            if (runDirection != PdfWriter.RUN_DIRECTION_DEFAULT)
            {
                localRunDirection = runDirection;
            }
            if (text != null)
            {
                pdf      = text.PdfDocument;
                graphics = text.Duplicate;
            }
            else if (!simulate)
            {
                throw new Exception("ColumnText.go with simulate==false and text==null.");
            }
            if (!simulate)
            {
                if (ratio == GLOBAL_SPACE_CHAR_RATIO)
                {
                    ratio = text.PdfWriter.SpaceCharRatio;
                }
                else if (ratio < 0.001f)
                {
                    ratio = 0.001f;
                }
            }
            float firstIndent = 0;

            int status = 0;

            if (rectangularWidth > 0)
            {
                for (;;)
                {
                    firstIndent = (lastWasNewline ? indent : followingIndent);
                    if (rectangularWidth <= firstIndent + rightIndent)
                    {
                        status = NO_MORE_COLUMN;
                        if (bidiLine.isEmpty())
                        {
                            status |= NO_MORE_TEXT;
                        }
                        break;
                    }
                    if (bidiLine.isEmpty())
                    {
                        status = NO_MORE_TEXT;
                        break;
                    }
                    float   yTemp   = yLine;
                    PdfLine line    = bidiLine.processLine(rectangularWidth - firstIndent - rightIndent, alignment, localRunDirection);
                    float   maxSize = line.MaxSizeSimple;
                    currentLeading = fixedLeading + maxSize * multipliedLeading;
                    float[] xx = findLimitsTwoLines();
                    if (xx == null)
                    {
                        status = NO_MORE_COLUMN;
                        yLine  = yTemp;
                        bidiLine.restore();
                        break;
                    }
                    float x1 = Math.Max(xx[0], xx[2]);
                    if (!simulate && !dirty)
                    {
                        text.beginText();
                        dirty = true;
                    }
                    if (!simulate)
                    {
                        currentValues[0] = currentFont;
                        text.setTextMatrix(x1 + (line.IsRTL ? rightIndent : firstIndent) + line.IndentLeft, yLine);
                        pdf.writeLineToContent(line, text, graphics, currentValues, ratio);
                        currentFont = (PdfFont)currentValues[0];
                    }
                    lastWasNewline = line.isNewlineSplit();
                    yLine         -= line.isNewlineSplit() ? extraParagraphSpace : 0;
                }
            }
            else
            {
                currentLeading = fixedLeading;
                for (;;)
                {
                    firstIndent = (lastWasNewline ? indent : followingIndent);
                    float   yTemp = yLine;
                    float[] xx    = findLimitsTwoLines();
                    if (xx == null)
                    {
                        status = NO_MORE_COLUMN;
                        if (bidiLine.isEmpty())
                        {
                            status |= NO_MORE_TEXT;
                        }
                        yLine = yTemp;
                        break;
                    }
                    if (bidiLine.isEmpty())
                    {
                        status = NO_MORE_TEXT;
                        yLine  = yTemp;
                        break;
                    }
                    float x1 = Math.Max(xx[0], xx[2]);
                    float x2 = Math.Min(xx[1], xx[3]);
                    if (x2 - x1 <= firstIndent + rightIndent)
                    {
                        continue;
                    }
                    if (!simulate && !dirty)
                    {
                        text.beginText();
                        dirty = true;
                    }
                    PdfLine line = bidiLine.processLine(x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection);
                    if (!simulate)
                    {
                        currentValues[0] = currentFont;
                        text.setTextMatrix(x1 + (line.IsRTL ? rightIndent : firstIndent) + line.IndentLeft, yLine);
                        pdf.writeLineToContent(line, text, graphics, currentValues, ratio);
                        currentFont = (PdfFont)currentValues[0];
                    }
                    lastWasNewline = line.isNewlineSplit();
                    yLine         -= line.isNewlineSplit() ? extraParagraphSpace : 0;
                }
            }
            if (dirty)
            {
                text.endText();
                text.Add(graphics);
            }
            return(status);
        }