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,18 +1246,26 @@ namespace Volian.Print.Library
if (ImageText == "figure")
{
ImageConfig ic = new ImageConfig(MyItemInfo.MyContent.MyImage);
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);
Width = img.Width;
Height = img.Height;
if (ic != null && ic.Image_Height != 0)
// B2016-277: add a try catch in case of there being 'bad' data in the text field for an image/figure
try
{
Width = ic.Image_Width;
Height = ic.Image_Height;
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);
Width = img.Width;
Height = img.Height;
if (ic != null && ic.Image_Height != 0)
{
Width = ic.Image_Width;
Height = ic.Image_Height;
}
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;
}
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"));
}
else
{
@ -3372,7 +3380,7 @@ namespace Volian.Print.Library
{
int profileDepth2 = ProfileTimer.Push(">>>> Before vlnParagraph.Figure");
string erMsg = null;
if (itemInfo.MyContent.Text != null) // ro image
if (itemInfo.MyContent.Text != null) // ro image
{
ProcedureInfo proc = itemInfo.MyProcedure;
DocVersionInfo dvi = proc.MyDocVersion;
@ -3467,20 +3475,28 @@ namespace Volian.Print.Library
{
ImageText = "figure";
ImageConfig ic = new ImageConfig(MyItemInfo.MyContent.MyImage);
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);
Width = img.Width;
Height = img.Height;
if (ic != null && ic.Image_Height != 0)
// B2016-277: add a try catch in case of there being 'bad' data in the text field for an image/figure
try
{
Width = ic.Image_Width;
Height = ic.Image_Height;
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);
Width = img.Width;
Height = img.Height;
if (ic != null && ic.Image_Height != 0)
{
Width = ic.Image_Width;
Height = ic.Image_Height;
}
yoff = AdjustLocIfLongerRNO(itemInfo, yoff, yoffRightParent);
bool noborder = MyItemInfo.FormatStepData.Type.ToUpper().Contains("BORDERLESS");
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);
}
yoff = AdjustLocIfLongerRNO(itemInfo, yoff, yoffRightParent);
bool noborder = MyItemInfo.FormatStepData.Type.ToUpper().Contains("BORDERLESS");
yoff += (Height + ((noborder ? 2 : 3) * SixLinesPerInch));
CalculateXOffsetGridOrFigure(itemInfo, maxRNO, formatInfo);
}
ProfileTimer.Pop(profileDepth2);
}
@ -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;
}