B2016-277: don’t crash on bad data in text field for a figure

This commit is contained in:
Kathy Ruffing 2016-12-07 13:57:49 +00:00
parent cc30214d31
commit 929d027394

View File

@ -1246,6 +1246,9 @@ namespace Volian.Print.Library
if (ImageText == "figure")
{
ImageConfig ic = new ImageConfig(MyItemInfo.MyContent.MyImage);
// B2016-277: add a try catch in case of there being 'bad' data in the text field for an image/figure
try
{
byte[] idata = (ic != null && ic.Image_DataSize > 0) ? ROImageInfo.Decompress(MyItemInfo.MyContent.MyImage.Data, ic.Image_DataSize) : MyItemInfo.MyContent.MyImage.Data;
MemoryStream ms = new MemoryStream(idata);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
@ -1259,6 +1262,11 @@ namespace Volian.Print.Library
iTextSharp.text.Image it_image = iTextSharp.text.Image.GetInstance(idata);
retval = Rtf2Pdf.FigureAt(cb, it_image, XOffset + MyItemInfo.FormatStepData.Font.CharsToTwips, yLocation, Width * MyPageHelper.YMultiplier, Height * MyPageHelper.YMultiplier, DebugInfo, yBottomMargin, !MyItemInfo.FormatStepData.Type.Contains("Borderless"));
}
catch
{
retval += SixLinesPerInch;
}
}
else
{
string[] vals = ImageText.Split("\n".ToCharArray());
@ -3467,6 +3475,9 @@ namespace Volian.Print.Library
{
ImageText = "figure";
ImageConfig ic = new ImageConfig(MyItemInfo.MyContent.MyImage);
// B2016-277: add a try catch in case of there being 'bad' data in the text field for an image/figure
try
{
byte[] idata = (ic != null && ic.Image_DataSize > 0) ? ROImageInfo.Decompress(MyItemInfo.MyContent.MyImage.Data, ic.Image_DataSize) : MyItemInfo.MyContent.MyImage.Data;
MemoryStream ms = new MemoryStream(idata);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
@ -3482,6 +3493,11 @@ namespace Volian.Print.Library
yoff += (Height + ((noborder ? 2 : 3) * SixLinesPerInch));
CalculateXOffsetGridOrFigure(itemInfo, maxRNO, formatInfo);
}
catch (Exception ex)
{
_MyLog.WarnFormat("Bad figure content data: item = {0}, {1}", MyItemInfo.ItemID, MyItemInfo.ShortPath);
}
}
ProfileTimer.Pop(profileDepth2);
}
else
@ -5539,8 +5555,8 @@ namespace Volian.Print.Library
{
// B2016-269: if caution/note & not boxed, with tab adjust width based on xoffset of tab
// so text doesn't print out of right border. Commented out to check in another fix. Will be use
//if (!MyItemInfo.MyParent.IsHigh && MyTab!=null && MyTab.YOffset==YOffset)
// Width = (float)formatInfo.MyStepSectionLayoutData.WidT - MyTab.XOffset - mycolT;
//if (!MyItemInfo.MyParent.IsHigh && MyTab != null && MyTab.YOffset == YOffset)
// Width = MyHighLevelParagraph.Width - MyTab.Width - (MyTab.XOffset - MyHighLevelParagraph.XOffset) - 6;
//else
Width = (float)formatInfo.MyStepSectionLayoutData.WidT - 6 - mycolT;
}