Debug Box layout

This commit is contained in:
Rich 2010-06-08 20:30:00 +00:00
parent 2ccc4078ce
commit b46ef2f538

View File

@ -52,7 +52,6 @@ namespace Volian.Print.Library
// Close the document // Close the document
document.Close(); document.Close();
} }
private static void SampleParagraphs(Paragraph para, PdfContentByte cb, float yTop, float width, float x) private static void SampleParagraphs(Paragraph para, PdfContentByte cb, float yTop, float width, float x)
{ {
while (yTop > 0) while (yTop > 0)
@ -79,66 +78,59 @@ namespace Volian.Print.Library
{ {
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;
PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer; PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer;
if (textLayer != null) cb.BeginLayer(textLayer);
float left = x + Offset.X; float left = x + Offset.X;
float top = y + Offset.Y; float top = y + Offset.Y;
float right = left + width; float right = left + width;
float bottom = top - height; float bottom = top - height;
ColumnText myColumnText = new ColumnText(cb); ColumnText myColumnText = new ColumnText(cb);
//myColumnText.SetSimpleColumn(left, top, left + width, top - height); myColumnText.SetSimpleColumn(left, top, left + width,36); // Bottom margin
myColumnText.SetSimpleColumn(left, top, left + width, 36); // Bottom margin
//myColumnText.YLine -= 10;
//float yOff = pp.Font.BaseFont.GetAscentPoint("Almg", pp.Font.Size);
//myColumnText.YLine = -yOff;
myColumnText.AddElement(iParagraph); myColumnText.AddElement(iParagraph);
float pos = myColumnText.YLine; float pos = myColumnText.YLine; // Save the position to be used if the paragraph fits
//myColumnText.UseAscender = true;// Adjusts to the top of the text box.
// go processing it and if it fits, nothing to be processed is in mycolumntext.
int status = myColumnText.Go(true); // Check to see if it will fit on the page. int status = myColumnText.Go(true); // Check to see if it will fit on the page.
if (ColumnText.HasMoreText(status)) if (ColumnText.HasMoreText(status))
return 0;// Won't fit return 0; return 0;// Paragraph won't fit. Return 0;
myColumnText.YLine = pos; // location on page myColumnText.YLine = pos; // restore the location on the page
myColumnText.AddElement(iParagraph); // add in paragraph myColumnText.AddElement(iParagraph); // add in paragraph
myColumnText.Go(false); if (textLayer != null) cb.BeginLayer(textLayer);
//float textHeight = pp.Leading * myColumnText.LinesWritten; myColumnText.Go(false); // Draw the paragraph
//Console.WriteLine("Calculated Bottom {0}, YLine {1}", top - textHeight, myColumnText.YLine);
//BoxText(cb, System.Drawing.Color.BurlyWood, left, top, left + width, top - height);
//BoxText(canvas, System.Drawing.Color.CadetBlue, left, top, left + width, top - textHeight);
if (textLayer != null) cb.EndLayer(); if (textLayer != null) cb.EndLayer();
// Approximate Descent by using Leading divided by 5.
float yDescent = iParagraph.Leading / 5;
// If the BaseFont is available, calculate yAdj on the basis of the Descent
if (iParagraph.Font.BaseFont != null)
yDescent = -iParagraph.Font.BaseFont.GetDescentPoint("Almg", iParagraph.Font.Size);
if (PdfDebug) if (PdfDebug)
DrawPdfDebug(cb, System.Drawing.Color.CadetBlue, left, top, left + width, myColumnText.YLine, debugText); DrawPdfDebug(cb, System.Drawing.Color.CadetBlue, left, top, left + width, myColumnText.YLine, debugText,yDescent);
//Console.WriteLine("Lines = {0}", myColumnText.LinesWritten);
return myColumnText.YLine; return myColumnText.YLine;
} }
private static void DrawPdfDebug(PdfContentByte cb, System.Drawing.Color sysColor, float left, float top, float right, float bottom, string debugText) private static void DrawPdfDebug(PdfContentByte cb, System.Drawing.Color sysColor, float left, float top, float right, float bottom, string debugText, float yDescent)
{ {
float yAdj = 3; // yAdj is dependent on the size of the font and the spacing between lines.
cb.SaveState(); cb.SaveState();
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;
PdfLayer debugLayer = _MyPageHelper == null ? null : _MyPageHelper.DebugLayer; PdfLayer debugLayer = _MyPageHelper == null ? null : _MyPageHelper.DebugLayer;
if (debugLayer != null) cb.BeginLayer(debugLayer); if (debugLayer != null) cb.BeginLayer(debugLayer);
cb.SetColorStroke(new Color(sysColor)); cb.SetColorStroke(new Color(sysColor));
cb.SetLineWidth(.1F); cb.SetLineWidth(.1F);
cb.MoveTo(left, top - yAdj); cb.MoveTo(left, top - yDescent);
cb.LineTo(right, top - yAdj); cb.LineTo(right, top - yDescent);
cb.LineTo(right, bottom - yAdj); cb.LineTo(right, bottom - yDescent);
cb.LineTo(left, bottom - yAdj); cb.LineTo(left, bottom - yDescent);
cb.LineTo(left, top - yAdj); cb.LineTo(left, top - yDescent);
cb.Stroke(); cb.Stroke();
ColumnText ct = new ColumnText(cb); if (debugText != "")
ct.SetSimpleColumn(left, 4 + top - yAdj, right, top - yAdj - 50); {
iTextSharp.text.Font font = FontFactory.GetFont("Arial", 2); ColumnText ct = new ColumnText(cb);
Chunk chk = new Chunk(debugText, font); ct.SetSimpleColumn(left, 4 + top - yDescent, right, top - yDescent - 50);
Phrase ph = new Phrase(chk); iTextSharp.text.Font font = FontFactory.GetFont("Arial", 2);
ct.AddElement(ph); Chunk chk = new Chunk(debugText, font);
cb.SetColorFill(new Color(sysColor)); Phrase ph = new Phrase(chk);
ct.Go(); ct.AddElement(ph);
cb.SetColorFill(new Color(sysColor));
ct.Go();
}
if (debugLayer != null) cb.EndLayer(); if (debugLayer != null) cb.EndLayer();
cb.RestoreState(); cb.RestoreState();
} }
} }
} }