iTextSharp.text.pdf.ColumnText.Go C# (CSharp) Метод

Go() защищенный Метод

protected Go ( bool simulate, IElement elementToGo ) : int
simulate bool
elementToGo IElement
Результат int
    protected int Go(bool simulate, IElement elementToGo) {
        if (composite)
            return GoComposite(simulate);
        AddWaitingPhrase();
        if (bidiLine == null)
            return NO_MORE_TEXT;
        descender = 0;
        linesWritten = 0;
        lastX = 0;
        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;
        PdfContentByte text = null;
        firstLineY = float.NaN;
        int localRunDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;
        if (runDirection != PdfWriter.RUN_DIRECTION_DEFAULT)
            localRunDirection = runDirection;
        if (canvas != null) {
            graphics = canvas;
            pdf = canvas.PdfDocument;
            if (pdf.UseSeparateCanvasesForTextAndGraphics)
                text = canvas.Duplicate;
            else
                text = canvas;
        }
        else if (!simulate)
            throw new Exception(MessageLocalization.GetComposedMessage("columntext.go.with.simulate.eq.eq.false.and.text.eq.eq.null"));
        if (!simulate) {
            if (ratio == GLOBAL_SPACE_CHAR_RATIO)
                ratio = text.PdfWriter.SpaceCharRatio;
            else if (ratio < 0.001f)
                ratio = 0.001f;
        }
        if (!rectangularMode) {
            float max = 0;
            foreach (PdfChunk c in bidiLine.chunks) {
                max = Math.Max(max, c.Font.Size);
            }
            currentLeading = fixedLeading + max * multipliedLeading;
        }
        float firstIndent = 0;
        PdfLine line;
        float x1;
        int status = 0;
        if (!simulate && pdf.writer.IsTagged()) {
            if (elementToGo is Paragraph) {
                if (text != null)
                    text.OpenMCBlock(elementToGo);
            }
        }
        while(true) {
            firstIndent = (lastWasNewline ? indent : followingIndent); //
            if (rectangularMode) {
                if (rectangularWidth <= firstIndent + rightIndent) {
                    status = NO_MORE_COLUMN;
                    if (bidiLine.IsEmpty())
                        status |= NO_MORE_TEXT;
                    break;
                }
                if (bidiLine.IsEmpty()) {
                    status = NO_MORE_TEXT;
                    break;
                }
                line = bidiLine.ProcessLine(leftX, rectangularWidth - firstIndent - rightIndent, alignment, localRunDirection, arabicOptions, minY, yLine, descender);
                if (line == null) {
                    status = NO_MORE_TEXT;
                    break;
                }
                float[] maxSize = line.GetMaxSize(fixedLeading, multipliedLeading);
                if (UseAscender && float.IsNaN(firstLineY))
                    currentLeading = line.Ascender;
                else
                    currentLeading = Math.Max(maxSize[0], maxSize[1] - descender);
                if (yLine > maxY || yLine - currentLeading < minY ) {
                    status = NO_MORE_COLUMN;
                    bidiLine.Restore();
                    break;
                }
                yLine -= currentLeading;
                if (!simulate && !dirty) {
                    text.BeginText();
                    dirty = true;
                }
                if (float.IsNaN(firstLineY))
                    firstLineY = yLine;
                UpdateFilledWidth(rectangularWidth - line.WidthLeft);
                x1 = leftX;
            }
            else {
                float yTemp = yLine - currentLeading;
                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;
                }
                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;
                }
                line = bidiLine.ProcessLine(x1, x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection, arabicOptions, minY, yLine, descender);
                if (line == null) {
                    status = NO_MORE_TEXT;
                    yLine = yTemp;
                    break;
                }
            }
            if (!simulate) {
                currentValues[0] = currentFont;
                text.SetTextMatrix(x1 + (line.RTL ? rightIndent : firstIndent) + line.IndentLeft, yLine);
                lastX = pdf.WriteLineToContent(line, text, graphics, currentValues, ratio);
                currentFont = (PdfFont)currentValues[0];
            }
            lastWasNewline = repeatFirstLineIndent && line.NewlineSplit;
            yLine -= line.NewlineSplit ? extraParagraphSpace : 0;
            ++linesWritten;
            descender = line.Descender;
        }
        if (dirty) {
            text.EndText();
            if (!simulate && pdf.writer.IsTagged()) {
                if (elementToGo is Paragraph) {
                    if (text != null && (status & NO_MORE_COLUMN) == 0)
                        text.CloseMCBlock(elementToGo);
                }
            }
            if (canvas != text)
                canvas.Add(text);
        }
        return status;
    }
    

Same methods

ColumnText::Go ( ) : int
ColumnText::Go ( bool simulate ) : int

Usage Example

Пример #1
2
 /** Shows a line of text. Only the first line is written.
  * @param canvas where the text is to be written to
  * @param alignment the alignment. It is not influenced by the run direction
  * @param phrase the <CODE>Phrase</CODE> with the text
  * @param x the x reference position
  * @param y the y reference position
  * @param rotation the rotation to be applied in degrees counterclockwise
  * @param runDirection the run direction
  * @param arabicOptions the options for the arabic shaping
  */    
 public static void ShowTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions) {
     if (alignment != Element.ALIGN_LEFT && alignment != Element.ALIGN_CENTER
         && alignment != Element.ALIGN_RIGHT)
         alignment = Element.ALIGN_LEFT;
     canvas.SaveState();
     ColumnText ct = new ColumnText(canvas);
     float lly = -1;
     float ury = 2;
     float llx;
     float urx;
     switch (alignment) {
         case Element.ALIGN_LEFT:
             llx = 0;
             urx = 20000;
             break;
         case Element.ALIGN_RIGHT:
             llx = -20000;
             urx = 0;
             break;
         default:
             llx = -20000;
             urx = 20000;
             break;
     }
     if (rotation == 0) {
         llx += x;
         lly += y;
         urx += x;
         ury += y;
     }
     else {
         double alpha = rotation * Math.PI / 180.0;
         float cos = (float)Math.Cos(alpha);
         float sin = (float)Math.Sin(alpha);
         canvas.ConcatCTM(cos, sin, -sin, cos, x, y);
     }
     ct.SetSimpleColumn(phrase, llx, lly, urx, ury, 2, alignment);
     if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
         if (alignment == Element.ALIGN_LEFT)
             alignment = Element.ALIGN_RIGHT;
         else if (alignment == Element.ALIGN_RIGHT)
             alignment = Element.ALIGN_LEFT;
     }
     ct.Alignment = alignment;
     ct.ArabicOptions = arabicOptions;
     ct.RunDirection = runDirection;
     ct.Go();
     canvas.RestoreState();
 }
All Usage Examples Of iTextSharp.text.pdf.ColumnText::Go