Fix for auto TOC grouping logic (B2016-200) and for line spacing consistency (B2016-205)

This commit is contained in:
John Jenko 2016-09-12 18:47:05 +00:00
parent ae4d9fa4b1
commit 6a737a961d

View File

@ -1093,7 +1093,7 @@ namespace Volian.Print.Library
//ItemInfo procItem = ItemInfo.Get(myProcedure.ItemID); //ItemInfo procItem = ItemInfo.Get(myProcedure.ItemID);
ItemInfo procItem = myProcedure; ItemInfo procItem = myProcedure;
lastyLocation = 0; lastyLocation = 0;
AddSectionToTOC(tocSection, procItem, tOfC, cb, yTopMargin, 0); AddSectionToTOC(tocSection, procItem, tOfC, cb, yTopMargin, 0, false); // add all of the marked sections and sub-sections to the table of contents
if (textLayer != null) cb.EndLayer(); if (textLayer != null) cb.EndLayer();
NewPage(); NewPage();
//_MyLog.InfoFormat("NewPage 4 {0}", cb.PdfWriter.CurrentPageNumber); //_MyLog.InfoFormat("NewPage 4 {0}", cb.PdfWriter.CurrentPageNumber);
@ -1119,7 +1119,7 @@ namespace Volian.Print.Library
_RtfSB.Append("}"); _RtfSB.Append("}");
return _RtfSB.ToString(); return _RtfSB.ToString();
} }
private float AddSectionToTOC(SectionInfo tocSection, ItemInfo ii, TableOfContentsData tOfC, PdfContentByte cb, float yPageStart, float yLocation) private float AddSectionToTOC(SectionInfo tocSection, ItemInfo ii, TableOfContentsData tOfC, PdfContentByte cb, float yPageStart, float yLocation, bool didSubSecLineSpacing)
{ {
// The following adjustments are for WCN1: // The following adjustments are for WCN1:
// for xAdjNumber: 6 is for 1 char less in 16bit (\promsnt\exe\print\tabocont.c, method 'howMany'. // for xAdjNumber: 6 is for 1 char less in 16bit (\promsnt\exe\print\tabocont.c, method 'howMany'.
@ -1140,12 +1140,39 @@ namespace Volian.Print.Library
string lastTOCGroupHeading = ""; string lastTOCGroupHeading = "";
if (ii.Sections != null) if (ii.Sections != null)
{ {
int sectCnt = 0; // keep count of which section/sub-section we are processing
bool doSubY = false;
foreach (SectionInfo mySection in ii.Sections) foreach (SectionInfo mySection in ii.Sections)
{ {
sectCnt++;
SectionConfig sc = mySection.MyConfig as SectionConfig; SectionConfig sc = mySection.MyConfig as SectionConfig;
if ((mySection.MyDocStyle != null && mySection.MyDocStyle.IncludeInTOC && (sc == null || sc.Section_TOC != "Y")) if ((mySection.MyDocStyle != null && mySection.MyDocStyle.IncludeInTOC && (sc == null || sc.Section_TOC != "Y"))
|| ((mySection.MyDocStyle == null || !mySection.MyDocStyle.IncludeInTOC) && (sc != null && sc.Section_TOC == "Y"))) || ((mySection.MyDocStyle == null || !mySection.MyDocStyle.IncludeInTOC) && (sc != null && sc.Section_TOC == "Y")))
{ {
// 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;
}
// check what level the plant wants the auto ToC indented:
int tofCNumLevels = tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCNumLevels ?? 0;
if (tofCNumLevels > 0 && level > tofCNumLevels) return yLocation;
int startIndentAfterLevel = tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCStartIndentAfterLevel ?? 2; //
//level = level <= 2 ? 0 : level - 2; // no indenting until third level
level = level <= startIndentAfterLevel ? 0 : level - startIndentAfterLevel;
float indentOffset = (level * (secTitlePos - secNumPos));
if (didSubSecLineSpacing && sectCnt == 1 && indentOffset > 0) // processing first sub-section and we are indenting B2016-205
{
// processed last sub-section so use the main section line spacing (most times is double spaced)
yLocation -= (float)(tOfC.TofCLineSpacingSub ?? 1) * vlnPrintObject.SixLinesPerInch;
yLocation += (float)(tOfC.TofCLineSpacing ?? 1) * vlnPrintObject.SixLinesPerInch;
}
// The Group Title logic was added for V.C. Summer and Farley(new writer guide format) // The Group Title logic was added for V.C. Summer and Farley(new writer guide format)
// It allows the user to enter a Table of Contents Grouping Title on the Section Property (under automation) // It allows the user to enter a Table of Contents Grouping Title on the Section Property (under automation)
// The grouping title will print if the same title wasn't last printed // The grouping title will print if the same title wasn't last printed
@ -1158,7 +1185,7 @@ namespace Volian.Print.Library
string rtfGrpingText = GetRtfToC(tocGrpHeading, tOfC, grpingFont); string rtfGrpingText = GetRtfToC(tocGrpHeading, tOfC, grpingFont);
Paragraph myparagraphtc = vlnPrintObject.RtfToParagraph(rtfGrpingText); Paragraph myparagraphtc = vlnPrintObject.RtfToParagraph(rtfGrpingText);
float w = secPagePos - 6; float w = secPagePos - 6;
if (yLocation > 0) yLocation += vlnPrintObject.SixLinesPerInch; // for two blank line between last TOC title and the new grouping title //if (yLocation > 0) yLocation += vlnPrintObject.SixLinesPerInch;// commented out for B2016-200 // for two blank line between last TOC title and the new grouping title
float rtnval = Rtf2Pdf.TextAt(cb, myparagraphtc, leftMargin + secNumPos, yPageStart - yLocation, w, height, "", yBottomMargin); float rtnval = Rtf2Pdf.TextAt(cb, myparagraphtc, leftMargin + secNumPos, yPageStart - yLocation, w, height, "", yBottomMargin);
if (rtnval == 0) // couldn't fit, flags need for a page break. if (rtnval == 0) // couldn't fit, flags need for a page break.
{ {
@ -1167,6 +1194,7 @@ namespace Volian.Print.Library
yLocation = lastyLocation = 0; yLocation = lastyLocation = 0;
rtnval = Rtf2Pdf.TextAt(cb, myparagraphtc, leftMargin + secNumPos, yPageStart - yLocation, w, height, "", yBottomMargin); rtnval = Rtf2Pdf.TextAt(cb, myparagraphtc, leftMargin + secNumPos, yPageStart - yLocation, w, height, "", yBottomMargin);
} }
yLocation += vlnPrintObject.SixLinesPerInch; // for two blank line between last TOC title and the new grouping title - added for B2016-200
int lnaftergroup = ((tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCLineSpacingSub ?? 0) > 0) ? 1 : 2; int lnaftergroup = ((tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCLineSpacingSub ?? 0) > 0) ? 1 : 2;
yLocation += (lnaftergroup * vlnPrintObject.SixLinesPerInch); // new line yLocation += (lnaftergroup * vlnPrintObject.SixLinesPerInch); // new line
} }
@ -1194,24 +1222,6 @@ namespace Volian.Print.Library
float numwidth = width; float numwidth = width;
Rtf2Pdf.Offset = new PointF(0, 2.5F); Rtf2Pdf.Offset = new PointF(0, 2.5F);
// 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;
}
// check what level the plant wants the auto ToC indented:
int tofCNumLevels = tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCNumLevels ?? 0;
if (tofCNumLevels > 0 && level > tofCNumLevels) return yLocation;
int startIndentAfterLevel = tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCStartIndentAfterLevel ?? 2; //
//level = level <= 2 ? 0 : level - 2; // no indenting until third level
level = level <= startIndentAfterLevel ? 0 : level - startIndentAfterLevel;
float indentOffset = (level * (secTitlePos - secNumPos));
// 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 + indentOffset + (level * 6); float adjSecTitlePos = secTitlePos + indentOffset + (level * 6);
@ -1333,15 +1343,28 @@ namespace Volian.Print.Library
} }
//If the format wants single spacing within subsections (2nd level and lower), then need to figure out //If the format wants single spacing within subsections (2nd level and lower), then need to figure out
// spacing (vcb1 table of contents) // spacing (vcb1 table of contents)
bool dosuby = (((tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCLineSpacingSub ?? 1) > 0) //bool dosuby = (((tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCLineSpacingSub ?? 1) > 0)
&& (mySection.MyParent.IsSection && ((mySection.Sections != null && mySection.Sections.Count > 0) || (level > 0 && mySection.NextItem != null)))) // && (mySection.MyParent.IsSection && ((mySection.Sections != null && mySection.Sections.Count > 0) || (level > 0 && mySection.NextItem != null))))
// || didGrp;
doSubY = (((tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCLineSpacingSub ?? 1) > 0)
&& (mySection.MyParent.IsSection && (/* mySection.Sections == null && */ sectCnt < ii.Sections.Count))) // B2016-205
|| didGrp; || didGrp;
if (dosuby) if (doSubY)
yLocation += (float)(tOfC.TofCLineSpacingSub ?? 1) * vlnPrintObject.SixLinesPerInch; yLocation += (float)(tOfC.TofCLineSpacingSub ?? 1) * vlnPrintObject.SixLinesPerInch;
else else
yLocation += (float)(tOfC.TofCLineSpacing ?? 1) * vlnPrintObject.SixLinesPerInch; yLocation += (float)(tOfC.TofCLineSpacing ?? 1) * vlnPrintObject.SixLinesPerInch;
} }
yLocation = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation); float savYLoc = yLocation;
yLocation = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation, doSubY);
if (savYLoc == yLocation) // nothing was outputted i.e. the subsections are not included on the TOC // B2016-205
{
if (doSubY && sectCnt == ii.Sections.Count)
{
// processed last sub-section so use the main section line spacing (most times is double spaced)
yLocation -= (float)(tOfC.TofCLineSpacingSub ?? 1) * vlnPrintObject.SixLinesPerInch;
yLocation += (float)(tOfC.TofCLineSpacing ?? 1) * vlnPrintObject.SixLinesPerInch;
}
}
} }
} }
return yLocation; return yLocation;