C2021-015: High Level Steps in Table of Contents

C2021-015: Barakah High Level Steps in Table of Contents
This commit is contained in:
2022-02-23 14:46:04 +00:00
parent 9fa8bd5245
commit 1b7bb16e6d
8 changed files with 353 additions and 90 deletions

View File

@@ -1440,6 +1440,7 @@ namespace Volian.Print.Library
{
int sectCnt = 0; // keep count of which section/sub-section we are processing
bool doSubY = false;
int level = 0;
// C2018-004 create meta file for baseline compares
Volian.Base.Library.BaselineMetaFile.WriteLine("TOC Ystart {0} LeftMar {1} ScNmPos {2} ScTtlPos {3} ScPgPos {4}", yPageStart, leftMargin, secNumPos, secTitlePos, secPagePos);
bool inGroup = false;
@@ -1452,7 +1453,7 @@ namespace Volian.Print.Library
{
// 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;
level = 0;
ItemInfo iilvl = mySection as ItemInfo;
while (!iilvl.IsProcedure)
{
@@ -1464,7 +1465,6 @@ namespace Volian.Print.Library
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));
@@ -1660,7 +1660,7 @@ namespace Volian.Print.Library
retval = Rtf2Pdf.TextAt(cb, myparagraphp, leftMargin + secPagePos, yPageStart - yLocation, width, height, "", yBottomMargin);
}
else
AddTemplateTOCPageCounts(tOfC, yLocation, yPageStartAdj, leftMargin, secPagePos, height, mySection);
AddTemplateTOCPageCounts(tOfC, yLocation, yPageStartAdj, leftMargin, secPagePos, height, key);
}
//If the format wants single spacing within subsections (2nd level and lower), then need to figure out
// spacing (vcb1 table of contents)
@@ -1695,6 +1695,11 @@ namespace Volian.Print.Library
}
yLocation += (spc * vlnPrintObject.SixLinesPerInch);
}
// C2021-015: Barakah High Level Steps in Table of Contents - check to see if we need to add the high level steps on
// table of contents for this section, format flag & section has steps:
if (mySection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCAllowHLS &&
mySection.IsStepSection && mySection.Steps != null && mySection.Steps.Count > 0)
yLocation = AddHLSToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation, doSubY, level + 1, adjSecTitlePos);
}
float savYLoc = yLocation;
yLocation = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation, doSubY);
@@ -1706,13 +1711,164 @@ namespace Volian.Print.Library
yLocation -= (float)(tOfC.TofCLineSpacingSub ?? 1) * vlnPrintObject.SixLinesPerInch;
yLocation += (float)(tOfC.TofCLineSpacing ?? 1) * vlnPrintObject.SixLinesPerInch;
}
}
}
}
}
return yLocation;
}
// B2019-172 This will add the RTF font commands around the symbol characters
// This was copied for DisplaySearch and modified - added the FormatData parameter
// C2021-015: Barakah High Level Steps in Table of Contents
private float AddHLSToTOC(SectionInfo tocSection, ItemInfo ii, TableOfContentsData tOfC, PdfContentByte cb, float yPageStart, float yLocation, bool didSubSecLineSpacing, int level, float parTitleXOff)
{
// if section is not in TOC, don't add the HLSs
SectionConfig sc = ii.ActiveSection.MyConfig as SectionConfig;
if (!((ii.ActiveSection.MyDocStyle != null && ii.ActiveSection.MyDocStyle.IncludeInTOC && (sc == null || sc.Section_TOC != "Y"))
|| ((ii.ActiveSection.MyDocStyle == null || !ii.ActiveSection.MyDocStyle.IncludeInTOC) && (sc != null && sc.Section_TOC == "Y"))))
return yLocation;
float xAdjNumber = -6 + 1.2F;
float xAdjTitle = .8F + 1.2F;
float yadj = 0.5F; // tweak to get 16 & 32 bit output to match.
float yPageStartAdj = yPageStart - yadj;
float leftMargin = (float)tocSection.MyDocStyle.Layout.LeftMargin;
float stepNumPos = (float)tOfC.TofCSecNumPos + xAdjNumber;
float stepTitlePos = (float)tOfC.TofCSecTitlePos + xAdjTitle;
float stepPagePos = (float)tOfC.TofCPageNumPos + xAdjNumber;
float height = tOfC.Font.WindowsFont.Size * 1.5F;
// C2018-004 create meta file for baseline compares
Volian.Base.Library.BaselineMetaFile.WriteLine("TOC Ystart {0} LeftMar {1} ScNmPos {2} ScTtlPos {3} ScPgPos {4}", yPageStart, leftMargin, stepNumPos, stepTitlePos, stepPagePos);
int tofCNumLevels = tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCNumLevels ?? 0;
if (tofCNumLevels > 0 && level > tofCNumLevels) return yLocation; // don't go down more than number of levels as defined in format
// figure out whether to indent. If not, set indentOffset to 0, otherwise indent number to where parent's text was (input parTitleXOff)
int startIndentAfterLevel = tocSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCStartIndentAfterLevel ?? 2; //
level = level <= startIndentAfterLevel ? 0 : level - startIndentAfterLevel;
// The parTitleXOff is passed in, it is the xoffset for the title of the section. This is where the number should
// start, if indenting. Without this, the xoffset was not correct:
float indentOffset = level == 0 ? 0 : parTitleXOff;
float numwidth = 0;
foreach (ItemInfo hls in ii.Steps) // Ouput each HLS that has config flag to include it.
{
StepConfig stc = hls.MyConfig as StepConfig;
if (stc != null && stc.Step_IncludeInTOC)
{
float yBottomMargin = yPageStart - (float)tocSection.MyDocStyle.Layout.PageLength + (2 * vlnPrintObject.SixLinesPerInch);
// need to do the step number, title & page number. Page number has to be put on at end after number of page is known, so use a Template.
string tmptxt = hls.MyTab.CleanText;
if (tmptxt == null || tmptxt == "") tmptxt = " "; // if no number set to blanks. Without this, low level printing gets confused
string rtfText = GetRtfToC(tmptxt, tOfC);
Paragraph myparagraphStepNum = vlnPrintObject.RtfToParagraph(rtfText);
float width = 0;
foreach (Chunk chkt in myparagraphStepNum.Chunks)
width += chkt.GetWidthPoint();
if (numwidth == 0) numwidth = width; // keep same xoffset for step text unless overwriting by number (see below)
Rtf2Pdf.Offset = new PointF(0, 2.5F);
// if the starting column of text would be in 'middle of' the number, just put it
// a few spaces after the number. The '182' below represents 2 chars.
float adjStepTitlePos = indentOffset + numwidth + 6;
if (width + indentOffset > adjStepTitlePos)
{
adjStepTitlePos = numwidth + 12 + indentOffset;
numwidth = width;
}
string tocStepTitle = hls.FormattedDisplayText;
tocStepTitle = ConvertSpecialChars(tocStepTitle, ii.ActiveFormat.PlantFormat.FormatData); // B2019-172 process symbol characters
rtfText = GetRtfToC(tocStepTitle, tOfC);
Paragraph myparagraphStepTitle = vlnPrintObject.RtfToParagraph(rtfText);
width = stepPagePos - adjStepTitlePos - ((tOfC.TofCPageNumAlign.ToUpper() == "RIGHT") ? 18 : 6);// B2021-109 proper adjustment of section title width - copied from leader dots lenth calcuation below
float savTitleWid = width;
// Print the step text
float retval = Rtf2Pdf.TextAt(cb, myparagraphStepTitle, leftMargin + ((tOfC.TofCSecNumPos == tOfC.TofCSecTitlePos && tmptxt.Equals(" ")) ? stepNumPos : adjStepTitlePos), yPageStart - yLocation, width, height, "", yBottomMargin);
if (retval == 0) // couldn't fit, flags need for a page break.
{
NewPage();
_MyHelper.ResetSvg(); // needed to reset so that PSNotFirst pagelist justify flag gets used for BGE
yLocation = lastyLocation = 0;
retval = Rtf2Pdf.TextAt(cb, myparagraphStepTitle, leftMargin + adjStepTitlePos, yPageStart - yLocation, width, height, "", yBottomMargin);
}
float ttlRetval = retval;
float savTitleFillWidth = Rtf2Pdf.FillWidth;
// Now do the step number. Retval is the ylocation on page after the text is put out
retval = Rtf2Pdf.TextAt(cb, myparagraphStepNum, leftMargin + indentOffset, yPageStart - yLocation, numwidth * 1.3F, height, "", yBottomMargin);
if (retval != ttlRetval) yLocation += (retval - ttlRetval);
// retval = the minimum (further down the page) between step number & text - accounts for multi line step
retval = Math.Min(retval, ttlRetval);
lastyLocation = retval;
// add a template for the page number:
// if the space character is not null & is not a space, the we've got to put out
// these between the section title & the page number
if (tOfC.TofCSpaceChar != null && tOfC.TofCSpaceChar != "" && tOfC.TofCSpaceChar != " ")
{
width = 0;
foreach (Chunk chkt in myparagraphStepTitle.Chunks)
width += chkt.GetWidthPoint();
// get height - if two lines high, need width of 2nd line for adding
// space characters
float heightTtl = vlnPrintObject.GetHeight(cb, myparagraphStepTitle, string.Empty, savTitleWid, false);
string spaceStr = "";
float startSpace = 0;
// the '6's in the next few code lines & in the 'while' loop below allows the placement of the dots (or other space character)
// to be not too close to section title & page number.
if (heightTtl > vlnPrintObject.SixLinesPerInch)
{
// this title is 2 or more lines, find start of leader dots by determining length of text
// on 2nd line (the savTitleFillWidth is the widest line of the split title)
float secondLineWidth = width - savTitleFillWidth;
startSpace = leftMargin + adjStepTitlePos + secondLineWidth + 6;
}
else
startSpace = leftMargin + adjStepTitlePos + width + 6;
// If the page number is Right justified, need less space characters ('.') so that page number
// doesn't have the last space character overwriting the 1st digit:
int endJust = (tOfC.TofCPageNumAlign.ToUpper() == "RIGHT") ? 18 : 6;
float endSpace = leftMargin + stepPagePos - endJust;
float numSpace = endSpace - startSpace;
rtfText = GetRtfToC(tOfC.TofCSpaceChar, tOfC);
Paragraph tmpmyparagraph = vlnPrintObject.RtfToParagraph(rtfText);
float spacchrwid = 0;
foreach (Chunk chkt in tmpmyparagraph.Chunks)
spacchrwid += chkt.GetWidthPoint();
while (numSpace > 6)
{
spaceStr = spaceStr + tOfC.TofCSpaceChar;
numSpace -= spacchrwid;
}
rtfText = GetRtfToC(spaceStr, tOfC); // out the leader dots
Paragraph myparagraphs = vlnPrintObject.RtfToParagraph(rtfText);
retval = Rtf2Pdf.TextAt(cb, myparagraphs, startSpace, yPageStart - yLocation, endSpace - startSpace, height, "", yBottomMargin);
}
// 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" + hls.ItemID.ToString();
if (ii.IsAutoTOCSection || _MyHelper.MyTOCPageNums.ContainsKey(key))
{
string pnum = _MyHelper.MyTOCPageNums.ContainsKey(key) ? _MyHelper.MyTOCPageNums[key].ToString() : (_MyHelper.CurrentTOCPageNumber + 1).ToString();
rtfText = GetRtfToC(pnum, tOfC);
Paragraph myparagraphp = vlnPrintObject.RtfToParagraph(rtfText);
width = pnum.Length * 6;
retval = Rtf2Pdf.TextAt(cb, myparagraphp, leftMargin + stepPagePos, yPageStart - yLocation, width, height, "", yBottomMargin);
}
else
AddTemplateTOCPageCounts(tOfC, yLocation, yPageStartAdj, leftMargin, stepPagePos, height, key);
float spc = (float)(tOfC.TofCLineSpacing ?? 1);
yLocation += (spc * vlnPrintObject.SixLinesPerInch);
}
}
return yLocation;
}
//B2019-172 This will add the RTF font commands around the symbol characters
// This was copied for DisplaySearch and modified - added the FormatData parameter
private string ConvertSpecialChars(string str, FormatData fmtData)
{
string rtnVal = str;
@@ -1736,9 +1892,8 @@ namespace Volian.Print.Library
return rtnVal;
}
private void AddTemplateTOCPageCounts(TableOfContentsData tOfC, float yLocation, float yPageStartAdj, float leftMargin, float secPagePos, float height, SectionInfo mySection)
private void AddTemplateTOCPageCounts(TableOfContentsData tOfC, float yLocation, float yPageStartAdj, float leftMargin, float secPagePos, float height, string key)
{
string key = "TOC" + mySection.ItemID.ToString();
PdfTemplate tmp = _MyHelper.MyTOCPageCounts.AddToTemplateList(key, _MyHelper.MyPdfWriter, "{TOCPAGE}", tOfC.Font.WindowsFont, (tOfC.TofCPageNumAlign.ToUpper() == "RIGHT") ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT, PrintOverride.TextColor);
_MyHelper.MyPdfContentByte.AddTemplate(tmp, leftMargin + secPagePos, (yPageStartAdj - yLocation) - height / 2);
}

View File

@@ -656,6 +656,26 @@ namespace Volian.Print.Library
}
}
}
else if (MyItemInfo.IsHigh && MyItemInfo.MyDocStyle != null && MyItemInfo.MyDocStyle.IncludeInTOC) // && (MyItemInfo.MyActiveSection.MyConfig as SectionConfig).Section_HLS_on_TOC == "Y")
{
// C2021-015: Barakah High Level Steps in Table of Contents
SectionConfig sc = MyItemInfo.ActiveSection.MyConfig as SectionConfig;
StepConfig stc = MyItemInfo.MyConfig as StepConfig;
if ((sc != null && sc.Section_TOC != "Y") && (stc != null && stc.Step_IncludeInTOC))
{
string tocKey = string.Format("TOC{0}", MyItemInfo.ItemID);
if (MyPageHelper.MyTOCPageCounts.ContainsKey(tocKey))
{
PageCount pc = MyPageHelper.MyTOCPageCounts[tocKey];
if (pc.Total == 0)
{
pc.Total = MyPageHelper.CurrentTOCPageNumber + 1;
pc.DrawTemplates();
}
}
}
}
if (!doprint) return yPageStart;
if (_PartsLeft != null && _PartsLeft.Count > 0) yPageStart = PartsLeft.ToPdf(cb, yPageStart, ref yTopMargin, ref yBottomMargin);
if (_PartsRight != null && _PartsRight.Count > 0) yPageStart = PartsRight.ToPdf(cb, yPageStart, ref yTopMargin, ref yBottomMargin);