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;
}