From 1b3df2e536f945952365c2a28e709b3cf128c1c2 Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 26 Jun 2012 15:24:20 +0000 Subject: [PATCH] --- PROMS/Volian.Print.Library/PromsPrinter.cs | 65 ++++++++++++++++++---- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/PROMS/Volian.Print.Library/PromsPrinter.cs b/PROMS/Volian.Print.Library/PromsPrinter.cs index 93a19a39..49ba599b 100644 --- a/PROMS/Volian.Print.Library/PromsPrinter.cs +++ b/PROMS/Volian.Print.Library/PromsPrinter.cs @@ -452,6 +452,20 @@ namespace Volian.Print.Library pc.Total = _MyHelper.CurrentPageNumber; 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++) { int pageNumber = 1 + ii; @@ -546,7 +560,6 @@ namespace Volian.Print.Library float secTitlePos = (float)tOfC.TofCSecTitlePos + xAdjTitle; float secPagePos = (float)tOfC.TofCPageNumPos + xAdjNumber; float height = tOfC.Font.WindowsFont.Size * 1.5F; - if (ii.Sections != null) { 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 // 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); float width = 0; foreach (Chunk chkt in myparagraphn.Chunks) width += chkt.GetWidthPoint(); 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); - 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. { cb.PdfDocument.NewPage(); 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 // a few spaces after the number. The '18' below represents 3 chars. - float adjSecTitlePos = secTitlePos; - if (secNumPos + numwidth > secTitlePos) - adjSecTitlePos = secNumPos + numwidth + 18 - xAdjTitleIndent; + float adjSecTitlePos = secTitlePos + indentOffset + (level * 6); + if (secNumPos + numwidth + indentOffset > secTitlePos + indentOffset) + adjSecTitlePos = secNumPos + numwidth + 18 - xAdjTitleIndent + indentOffset; rtfText = GetRtfToC(mySection.MyContent.Text, tOfC); Paragraph myparagrapht = vlnPrintObject.RtfToParagraph(rtfText); width = secPagePos - adjSecTitlePos - 6; @@ -585,17 +610,35 @@ namespace Volian.Print.Library yLocation += (lastyLocation - retval - vlnPrintObject.SixLinesPerInch); 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(); - 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); + if (mySection.IsAutoTOCSection || _MyHelper.MyTOCPageNums.ContainsKey(key)) + { + 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 = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation); } + yLocation = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, 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) { if (textLayer != null) cb.BeginLayer(textLayer);