This commit is contained in:
Kathy Ruffing 2012-06-26 15:24:20 +00:00
parent 64df0e68b0
commit 1b3df2e536

View File

@ -452,6 +452,20 @@ namespace Volian.Print.Library
pc.Total = _MyHelper.CurrentPageNumber; pc.Total = _MyHelper.CurrentPageNumber;
pc.DrawTemplates(); pc.DrawTemplates();
} }
else
{
// see if this section will be added to the table of content. This is for sections that
// precede tha actual Automated TOC section.
SectionConfig sc = mySection.MyConfig as SectionConfig;
if (sc != null && sc.Section_TOC == "Y")
{
string tockey = "TOC" + mySection.ItemID.ToString();
if (!_MyHelper.MyTOCPageNums.ContainsKey(tockey))
// increment the currentpagenumber by 1 since we haven't hit an
// endpage yet, and that's what increments it to the current page number.
_MyHelper.MyTOCPageNums.Add(tockey, _MyHelper.CurrentPageNumber+1);
}
}
for (int ii = 0; ii < sectPageCount; ii++) for (int ii = 0; ii < sectPageCount; ii++)
{ {
int pageNumber = 1 + ii; int pageNumber = 1 + ii;
@ -546,7 +560,6 @@ namespace Volian.Print.Library
float secTitlePos = (float)tOfC.TofCSecTitlePos + xAdjTitle; float secTitlePos = (float)tOfC.TofCSecTitlePos + xAdjTitle;
float secPagePos = (float)tOfC.TofCPageNumPos + xAdjNumber; float secPagePos = (float)tOfC.TofCPageNumPos + xAdjNumber;
float height = tOfC.Font.WindowsFont.Size * 1.5F; float height = tOfC.Font.WindowsFont.Size * 1.5F;
if (ii.Sections != null) if (ii.Sections != null)
{ {
foreach (SectionInfo mySection in ii.Sections) foreach (SectionInfo mySection in ii.Sections)
@ -556,26 +569,38 @@ namespace Volian.Print.Library
{ {
// need to do the section number, section title & page number. Page number // need to do the section number, section title & page number. Page number
// has to be put on at end after number of page is known, so use a Template. // has to be put on at end after number of page is known, so use a Template.
string rtfText = GetRtfToC(mySection.MyContent.Number, tOfC); string tmptxt = mySection.MyContent.Number == null || mySection.MyContent.Number == "" ? " " : mySection.MyContent.Number;
string rtfText = GetRtfToC(tmptxt, tOfC);
Paragraph myparagraphn = vlnPrintObject.RtfToParagraph(rtfText); Paragraph myparagraphn = vlnPrintObject.RtfToParagraph(rtfText);
float width = 0; float width = 0;
foreach (Chunk chkt in myparagraphn.Chunks) foreach (Chunk chkt in myparagraphn.Chunks)
width += chkt.GetWidthPoint(); width += chkt.GetWidthPoint();
float numwidth = width; float numwidth = width;
float yBottomMargin = Math.Max(0, (float)tocSection.MyDocStyle.Layout.TopMargin - (float)tocSection.MyDocStyle.Layout.PageLength - 2 * vlnPrintObject.SixLinesPerInch); float yBottomMargin = yPageStart - (float)tocSection.MyDocStyle.Layout.PageLength + (2 * vlnPrintObject.SixLinesPerInch);
Rtf2Pdf.Offset = new PointF(0, 2.5F); Rtf2Pdf.Offset = new PointF(0, 2.5F);
float retval = Rtf2Pdf.TextAt(cb, myparagraphn, leftMargin + secNumPos, yPageStart - yLocation, width*1.3F, height, "", yBottomMargin); // for indenting of subsections, count up tree. Only start indenting
// at third level, i.e. not indent on 1.0 and 1.1, but indent on 1.1.1:
int level = 0;
ItemInfo iilvl = mySection as ItemInfo;
while (!iilvl.IsProcedure)
{
level++;
iilvl = iilvl.MyParent;
}
level = level <= 2 ? 0 : level - 2; // no indenting until third level
float indentOffset = (level * (secTitlePos - secNumPos));
float retval = Rtf2Pdf.TextAt(cb, myparagraphn, leftMargin + secNumPos + indentOffset, yPageStart - yLocation, width * 1.3F, height, "", yBottomMargin);
if (retval == 0) // do a newpage, it couldn't fit on current page. if (retval == 0) // do a newpage, it couldn't fit on current page.
{ {
cb.PdfDocument.NewPage(); cb.PdfDocument.NewPage();
yLocation = 0; yLocation = 0;
retval = Rtf2Pdf.TextAt(cb, myparagraphn, leftMargin + secNumPos, yPageStart - yLocation, width*1.3F, height, "", yBottomMargin); retval = Rtf2Pdf.TextAt(cb, myparagraphn, leftMargin + secNumPos + indentOffset, yPageStart - yLocation, width * 1.3F, height, "", yBottomMargin);
} }
// if the starting column of text would be in 'middle of' the number, just put it // if the starting column of text would be in 'middle of' the number, just put it
// a few spaces after the number. The '18' below represents 3 chars. // a few spaces after the number. The '18' below represents 3 chars.
float adjSecTitlePos = secTitlePos; float adjSecTitlePos = secTitlePos + indentOffset + (level * 6);
if (secNumPos + numwidth > secTitlePos) if (secNumPos + numwidth + indentOffset > secTitlePos + indentOffset)
adjSecTitlePos = secNumPos + numwidth + 18 - xAdjTitleIndent; adjSecTitlePos = secNumPos + numwidth + 18 - xAdjTitleIndent + indentOffset;
rtfText = GetRtfToC(mySection.MyContent.Text, tOfC); rtfText = GetRtfToC(mySection.MyContent.Text, tOfC);
Paragraph myparagrapht = vlnPrintObject.RtfToParagraph(rtfText); Paragraph myparagrapht = vlnPrintObject.RtfToParagraph(rtfText);
width = secPagePos - adjSecTitlePos - 6; width = secPagePos - adjSecTitlePos - 6;
@ -585,17 +610,35 @@ namespace Volian.Print.Library
yLocation += (lastyLocation - retval - vlnPrintObject.SixLinesPerInch); yLocation += (lastyLocation - retval - vlnPrintObject.SixLinesPerInch);
lastyLocation = retval; lastyLocation = retval;
// if in the pre-table of content list, just put the page number out as text.
// otherwise, add a template _MyHelper.MyTOCPageCounts
string key = "TOC" + mySection.ItemID.ToString(); string key = "TOC" + mySection.ItemID.ToString();
PdfTemplate tmp = _MyHelper.MyTOCPageCounts.AddToTemplateList(key, _MyHelper.MyPdfWriter, "{TOCPAGE}", tOfC.Font.WindowsFont, Element.ALIGN_LEFT, PrintOverride.TextColor); if (mySection.IsAutoTOCSection || _MyHelper.MyTOCPageNums.ContainsKey(key))
_MyHelper.MyPdfContentByte.AddTemplate(tmp, leftMargin + secPagePos, (yPageStartAdj - yLocation) - height / 2); {
string pnum = _MyHelper.MyTOCPageNums.ContainsKey(key) ? _MyHelper.MyTOCPageNums[key].ToString() : (_MyHelper.CurrentPageNumber+1).ToString();
rtfText = GetRtfToC(pnum, tOfC);
Paragraph myparagraphp = vlnPrintObject.RtfToParagraph(rtfText);
width = pnum.Length * 6;
retval = Rtf2Pdf.TextAt(cb, myparagraphp, leftMargin + secPagePos, yPageStart - yLocation, width, height, "", yBottomMargin);
}
else
AddTemplateTOCPageCounts(tOfC, yLocation, yPageStartAdj, leftMargin, secPagePos, height, mySection);
yLocation += vlnPrintObject.SixLinesPerInch; yLocation += vlnPrintObject.SixLinesPerInch;
yLocation = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation);
} }
yLocation = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation);
} }
} }
return yLocation; return yLocation;
} }
private void AddTemplateTOCPageCounts(TableOfContentsData tOfC, float yLocation, float yPageStartAdj, float leftMargin, float secPagePos, float height, SectionInfo mySection)
{
string key = "TOC" + mySection.ItemID.ToString();
PdfTemplate tmp = _MyHelper.MyTOCPageCounts.AddToTemplateList(key, _MyHelper.MyPdfWriter, "{TOCPAGE}", tOfC.Font.WindowsFont, Element.ALIGN_LEFT, PrintOverride.TextColor);
_MyHelper.MyPdfContentByte.AddTemplate(tmp, leftMargin + secPagePos, (yPageStartAdj - yLocation) - height / 2);
}
private static void PrintTextMessage(PdfContentByte cb, string message, PdfLayer textLayer) private static void PrintTextMessage(PdfContentByte cb, string message, PdfLayer textLayer)
{ {
if (textLayer != null) cb.BeginLayer(textLayer); if (textLayer != null) cb.BeginLayer(textLayer);