First round of reducing the font size of supplemental info text if would not normally fit on a page
This commit is contained in:
parent
7f4173af82
commit
8280de55e2
@ -1735,6 +1735,9 @@ namespace Volian.Print.Library
|
||||
myPageHealper.ChangeBarDefinition = MyChangeBarDefinition;
|
||||
float yPageStart = yTopMargin;
|
||||
vlnParagraph._yPageStartForSupInfo = yTopMargin;
|
||||
FindSupInfoLengths(vlnParagraph); // creates a dictionary of the sup info paragraph heights
|
||||
_AdjustForParagraphShrinkage = new Dictionary<float, float>();
|
||||
AdjustSupInfoFontSize(vlnParagraph,cb); // try to shrink the sup info page font to fix on the page
|
||||
vlnParagraph.ToPdf(cb, yPageStart, ref yTopMargin, ref yBottomMargin);
|
||||
try
|
||||
{
|
||||
@ -1749,6 +1752,202 @@ namespace Volian.Print.Library
|
||||
MyContentByte = savMyContentByte;
|
||||
MyReaderHelper = savMyReaderHelper;
|
||||
}
|
||||
#region ShrinkSupInfoGroupAtATime
|
||||
|
||||
/*
|
||||
* Find Groups
|
||||
* Foreach group
|
||||
* while measure group is greater than page length
|
||||
* reduce the size for the group
|
||||
*/
|
||||
private float _Decrement = 2f;
|
||||
private void SupInfoAjustGroupings(vlnParagraph vlnParagraph)
|
||||
{
|
||||
List<List<vlnParagraph>> supInfoGroups = FindSupInfoGroups(vlnParagraph);
|
||||
float pageLength = (float)vlnParagraph.MyItemInfo.MyDocStyle.Layout.PageLength;
|
||||
foreach (List<vlnParagraph> grp in supInfoGroups)
|
||||
{
|
||||
float fontSize = grp[0].IParagraph.Leading; // current font size
|
||||
// reduce the font size by _Decrement until the entire grouping fits on one page
|
||||
while (MeasureLength(grp) > pageLength)
|
||||
{
|
||||
float newFontSize = fontSize - _Decrement;
|
||||
float scaler = newFontSize / fontSize;
|
||||
ReduceGroupFontSize(grp, scaler);
|
||||
fontSize = newFontSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReduceGroupFontSize(List<vlnParagraph> grp, float scaler)
|
||||
{
|
||||
}
|
||||
|
||||
private float MeasureLength(List<vlnParagraph> grp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
private List<List<vlnParagraph>> FindSupInfoGroups(vlnParagraph vlnParagraph)
|
||||
{
|
||||
List<List<vlnParagraph>> supInfoGroups;
|
||||
supInfoGroups = new List<List<vlnParagraph>>();
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenBelow)
|
||||
{
|
||||
SectionInfo supInfoSect = pg.MyItemInfo.MyActiveSection as SectionInfo;
|
||||
if (supInfoSect.StepSectPageBreaksForSupInfo != null && supInfoSect.StepSectPageBreaksForSupInfo.Contains(pg.MyItemInfo.ItemID))
|
||||
supInfoGroups.Add(new List<vlnParagraph>()); // add a grouping since a page break exists
|
||||
supInfoGroups[supInfoGroups.Count - 1].Add(pg); // add paragraph to the last grouping
|
||||
}
|
||||
return supInfoGroups;
|
||||
}
|
||||
#endregion //ShrinkSupInfoGroupAtATime
|
||||
#region ShrinkSupplementInfoTextFont
|
||||
/*
|
||||
* The logic in this region will look a the text that should appear on a supplemental information page
|
||||
* and reduce the size of the text and spacing between paragraphs so that it will fit on the one page.
|
||||
*/
|
||||
private Dictionary<int, float> _SupInfoLengths;
|
||||
static int _LastSupInfoItemID;
|
||||
static float _LastBottom;
|
||||
static float _LastOffset;
|
||||
|
||||
// create a dictionary of Supplemental Info pargraph heights
|
||||
private void FindSupInfoLengths(vlnParagraph vlnParagraph)
|
||||
{
|
||||
_SupInfoLengths = new Dictionary<int,float>();
|
||||
_LastBottom = 0;
|
||||
_LastSupInfoItemID = 0;
|
||||
_LastOffset = 0;
|
||||
FindSupInfoLength(vlnParagraph);
|
||||
if (_LastSupInfoItemID != 0)
|
||||
_SupInfoLengths.Add(_LastSupInfoItemID, _LastBottom);
|
||||
//ShowSupInfoPages(); //debug
|
||||
|
||||
}
|
||||
//private void ShowSupInfoPages() // used for debug
|
||||
//{
|
||||
// foreach (int key in _SupInfoPages.Keys)
|
||||
// Console.WriteLine("SupInfoPage {0} {1}", key, _SupInfoPages[key]);
|
||||
//}
|
||||
|
||||
// add the supplemental info page paragraph length (height) the dictionary
|
||||
private void FindSupInfoLength(vlnParagraph vlnParagraph)
|
||||
{
|
||||
//Console.WriteLine("{0} {1} ybottommost {2} yoffset {3} LastOffSet {4} LastBottom {5} PrefPgBreak {6}", vlnParagraph.MyItemInfo.ItemID, vlnParagraph.MyItemInfo.ShortPath, vlnParagraph.YBottomMost, vlnParagraph.YOffset, _LastOffset, _LastBottom,vlnParagraph.PrefPageBreak);
|
||||
SectionInfo supInfoSect = vlnParagraph.MyItemInfo.MyActiveSection as SectionInfo;
|
||||
if (supInfoSect.StepSectPageBreaksForSupInfo != null && supInfoSect.StepSectPageBreaksForSupInfo.Contains(vlnParagraph.MyItemInfo.ItemID))
|
||||
{
|
||||
if (_LastSupInfoItemID != 0)
|
||||
_SupInfoLengths.Add(_LastSupInfoItemID, _LastBottom + _LastOffset);
|
||||
_LastOffset = 24; // account for the Sup Info header (two lines)
|
||||
_LastBottom = 0;
|
||||
_LastSupInfoItemID = vlnParagraph.MyItemInfo.ItemID;
|
||||
}
|
||||
if (vlnParagraph.YOffset == 0)
|
||||
_LastOffset += _LastBottom + 12f; // the +12 accounts for blank lines between paragraphs
|
||||
_LastBottom = vlnParagraph.YBottomMost;
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenAbove)
|
||||
FindSupInfoLength(pg);
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenBelow)
|
||||
FindSupInfoLength(pg);
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenLeft)
|
||||
FindSupInfoLength(pg);
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenRight)
|
||||
FindSupInfoLength(pg);
|
||||
|
||||
}
|
||||
private Dictionary<float, float> _AdjustForParagraphShrinkage;
|
||||
private float _AdjustSupInfoSize = 0;
|
||||
private void AdjustSupInfoFontSize(vlnParagraph vlnParagraph, PdfContentByte cb)
|
||||
{
|
||||
AdjustSupInfoFontSize(vlnParagraph, cb, 0);
|
||||
}
|
||||
// if there is too much supplemental info text to fit on the page at the normal font,
|
||||
// reduce the size of font so it fits on the page, but only if the reduced font size is still easly readable.
|
||||
private void AdjustSupInfoFontSize(vlnParagraph vlnParagraph, PdfContentByte cb, int level)
|
||||
{
|
||||
if (vlnParagraph.MyItemInfo.ItemID == 62805)
|
||||
Console.WriteLine("stop");
|
||||
if (_SupInfoLengths.ContainsKey(vlnParagraph.MyItemInfo.ItemID))
|
||||
{
|
||||
float hsize = _SupInfoLengths[vlnParagraph.MyItemInfo.ItemID];
|
||||
//if (hsize > 900)
|
||||
// Console.WriteLine("stop");
|
||||
//if (hsize < 504 || hsize > 900) // not bigger than the page and not too big to shrink
|
||||
float hMin = (float)vlnParagraph.MyItemInfo.MyDocStyle.Layout.PageLength;
|
||||
float hMax = 1.75f * hMin;
|
||||
float hMult = (1.0f - .67f) / (hMin - hMax);
|
||||
float hOffSet = 1.0f - (hMult * hMin);
|
||||
if (hsize < hMin)// || hsize > hMax) // not bigger than the page and not too big to shrink
|
||||
_AdjustSupInfoSize = 1f; // don't adjust the font size
|
||||
else
|
||||
_AdjustSupInfoSize = hOffSet + hsize * hMult; // shrink the font size and line spacing
|
||||
//_AdjustSupInfoSize = 1.4447F - hsize * .00088F; // shrink the font size and line spacing
|
||||
}
|
||||
//if (vlnParagraph.PrefPageBreak || vlnParagraph.HasPrefPageBreak)
|
||||
// Console.WriteLine("path {0}, PrePageBeak = {1}, ItemID = {2}", vlnParagraph.MyItemInfo.ShortPath, vlnParagraph.PrefPageBreak, vlnParagraph.MyItemInfo.ItemID);
|
||||
//if (level == 1)
|
||||
// Console.WriteLine("bottom most {0}", vlnParagraph.YBottomMost - vlnParagraph.YOffset);
|
||||
float hBefore = vlnParagraph.Height;
|
||||
SupInfoFixChunks(vlnParagraph);
|
||||
//Console.WriteLine("Orig Font Size {0}", vlnParagraph.IParagraph.Leading);
|
||||
vlnParagraph.IParagraph.Leading = _AdjustSupInfoSize * vlnParagraph.IParagraph.Leading;
|
||||
float hAfter = vlnParagraph.GetParagraphHeight(cb, vlnParagraph.IParagraph, "", vlnParagraph.Width);
|
||||
float hleading = hBefore * _AdjustSupInfoSize;
|
||||
if (vlnParagraph.YOffset == 0)
|
||||
_AdjustForParagraphShrinkage = new Dictionary<float, float>();
|
||||
if (hleading > hAfter +1)
|
||||
{
|
||||
if (!_AdjustForParagraphShrinkage.ContainsKey(vlnParagraph.YOffset))
|
||||
_AdjustForParagraphShrinkage.Add(vlnParagraph.YOffset, hleading - hAfter);
|
||||
//Console.WriteLine("hbefore = {0} hAfter {1} hLeading {2}", hBefore, hAfter, hleading);
|
||||
}
|
||||
vlnParagraph.YOffset = SupInfoFixOffset(vlnParagraph);
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenAbove)
|
||||
AdjustSupInfoFontSize(pg,cb,level +1);
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenBelow)
|
||||
AdjustSupInfoFontSize(pg,cb,level +1);
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenLeft)
|
||||
AdjustSupInfoFontSize(pg,cb,level +1);
|
||||
foreach (vlnParagraph pg in vlnParagraph.ChildrenRight)
|
||||
AdjustSupInfoFontSize(pg,cb,level +1);
|
||||
foreach (vlnPrintObject po in vlnParagraph.PartsAbove)
|
||||
SupInfoFixParts(po);
|
||||
foreach (vlnPrintObject po in vlnParagraph.PartsBelow)
|
||||
SupInfoFixParts(po);
|
||||
foreach (vlnPrintObject po in vlnParagraph.PartsLeft)
|
||||
SupInfoFixParts(po);
|
||||
foreach (vlnPrintObject po in vlnParagraph.PartsRight)
|
||||
SupInfoFixParts(po);
|
||||
}
|
||||
|
||||
// adjust the step tabs
|
||||
private float SupInfoFixOffset( vlnPrintObject vpo)
|
||||
{
|
||||
float fixOffSet = 0;
|
||||
foreach (float off in _AdjustForParagraphShrinkage.Keys)
|
||||
if (off < vpo.YOffset)
|
||||
fixOffSet += _AdjustForParagraphShrinkage[off];
|
||||
return _AdjustSupInfoSize * vpo.YOffset - fixOffSet;
|
||||
}
|
||||
|
||||
// adjust the space between the paragraphs
|
||||
private void SupInfoFixParts(vlnPrintObject po)
|
||||
{
|
||||
foreach (Chunk chk in po.IParagraph.Chunks)
|
||||
chk.Font.Size = _AdjustSupInfoSize * chk.Font.Size;
|
||||
po.IParagraph.Leading = _AdjustSupInfoSize * po.IParagraph.Leading;
|
||||
po.YOffset = SupInfoFixOffset(po);
|
||||
}
|
||||
|
||||
// adjust the font size of the paragraph text
|
||||
private void SupInfoFixChunks(vlnParagraph vlnParagraph)
|
||||
{
|
||||
foreach (Chunk chk in vlnParagraph.IParagraph.Chunks)
|
||||
chk.Font.Size = _AdjustSupInfoSize * chk.Font.Size;
|
||||
}
|
||||
#endregion // ShrinkSupplementInfoTextFont
|
||||
|
||||
public void DoSupInfoPage(PdfContentByte cb, string str, PdfLayer textLayer, VlnSvgPageHelper myPageHelper, int itemid, bool insertBlankPages)
|
||||
{
|
||||
// see if the ID is in the facing page pdf - if so, get the page:
|
||||
|
Loading…
x
Reference in New Issue
Block a user