From 330f36250dbbf77ef013cef879f2d616a4feda09 Mon Sep 17 00:00:00 2001 From: Kathy Date: Mon, 13 Jul 2015 11:37:56 +0000 Subject: [PATCH] If font is not proportional, set default font to VESymbFix to be used in pdf generation code (without this, the default was set to Helvetica) If 1st character output for chunk, in a table cell, is a hard space (or various other special characters), set font to default (VESymbFix) font. (For HLP) --- PROMS/Volian.Print.Library/Grid2Pdf.cs | 14 +++++- PROMS/Volian.Print.Library/Rtf2iTextSharp.cs | 45 ++++++++++++++------ 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/PROMS/Volian.Print.Library/Grid2Pdf.cs b/PROMS/Volian.Print.Library/Grid2Pdf.cs index d82530a2..3a19cfae 100644 --- a/PROMS/Volian.Print.Library/Grid2Pdf.cs +++ b/PROMS/Volian.Print.Library/Grid2Pdf.cs @@ -403,7 +403,16 @@ namespace Volian.Print.Library DisplayText dt = new DisplayText(MyFlexGrid.GetMyItemInfo(), str, false); str = dt.StartText; str = PreProcessRTF(w, str); - iTextSharp.text.Paragraph myPara = RtfToParagraph(str); + + // If the font is not proportional, pass the symbol font through to RtfToParagraph. It is needed + // in underlying code to set the chunk's font if the first character of a cell is a hardspace. Without + // this, pdfs were using the Helvetica font, which is a default itextsharp font. + ItemInfo ii = MyFlexGrid.GetMyItemInfo(); + iTextSharp.text.Font ff = null; + if (!ii.FormatStepData.Font.FontIsProportional()) + ff = Volian.Svg.Library.VolianPdf.GetFont("VESymbFix", (int)ii.FormatStepData.Font.Size, (int)ii.FormatStepData.Font.WindowsFont.Style); + iTextSharp.text.Paragraph myPara = RtfToParagraph(str, ff); + myColumnText1.SetSimpleColumn(0, 0, w-2, MyContentByte.PdfDocument.PageSize.Top); // Padding = 4 if (str.Contains(@"\'05")) { @@ -648,10 +657,11 @@ namespace Volian.Print.Library str = _StatRTB.Rtf; return str; } - public static iTextSharp.text.Paragraph RtfToParagraph(string rtf) + public static iTextSharp.text.Paragraph RtfToParagraph(string rtf, iTextSharp.text.Font mySymFont) { IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtf); Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc); + rtf2IText.DefaultFont = mySymFont; iTextSharp.text.Paragraph para = rtf2IText.Convert(); para.SetLeading(_SixLinesPerInch, 0); return para; diff --git a/PROMS/Volian.Print.Library/Rtf2iTextSharp.cs b/PROMS/Volian.Print.Library/Rtf2iTextSharp.cs index f1a752dc..84a63d8b 100644 --- a/PROMS/Volian.Print.Library/Rtf2iTextSharp.cs +++ b/PROMS/Volian.Print.Library/Rtf2iTextSharp.cs @@ -106,6 +106,18 @@ namespace Volian.Print.Library private IRtfDocument _RtfDoc; private Paragraph _MyParagraph = new Paragraph(); private iTextSharp.text.Font _MyFont; + + // Allow for definition of a default font: if the font is not proportional, this gets set. + // It is needed to set the chunk's font if the first character of a cell is a hardspace (or various + // other special cases (see its use below). Without this, pdfs were using the Helvetica font, + // which is a default itextsharp font (this was causing a problem for HLP, their pdfs could not + // contain a Helvetica font when putting them in their production environment). + private iTextSharp.text.Font _DefaultFont; + public iTextSharp.text.Font DefaultFont + { + get { return _DefaultFont; } + set { _DefaultFont = value; } + } // public Rtf2iTextSharp(IRtfDocument rtfDoc, Document doc, PdfWriter writer) public Rtf2iTextSharp(IRtfDocument rtfDoc) { @@ -149,40 +161,49 @@ namespace Volian.Print.Library } //_MyParagraph.Add(string.Format("<{0}>", visualBreak.BreakKind.ToString())); } + private void AddChunk(string str, iTextSharp.text.Font font) + { + if (font == null) + _MyParagraph.Add(new Chunk(str)); + else + _MyParagraph.Add(new Chunk(str, font)); + } protected override void DoVisitSpecial(IRtfVisualSpecialChar visualSpecialChar) { //_MyParagraph.Add(string.Format("", visualSpecialChar.CharKind.ToString())); + iTextSharp.text.Font activeFont = _MyFont ?? DefaultFont; switch (visualSpecialChar.CharKind) { case RtfVisualSpecialCharKind.Bullet: - _MyParagraph.Add(new Chunk("\u2022")); + AddChunk("\u2022", activeFont); break; case RtfVisualSpecialCharKind.EmDash: - _MyParagraph.Add(new Chunk("\u2014")); + AddChunk("\u2014", activeFont); break; case RtfVisualSpecialCharKind.EmSpace: - _MyParagraph.Add(new Chunk("\u2003")); + AddChunk("\u2003", activeFont); break; case RtfVisualSpecialCharKind.EnDash: - _MyParagraph.Add(new Chunk("\u2013")); + AddChunk("\u2013", activeFont); break; case RtfVisualSpecialCharKind.EnSpace: - _MyParagraph.Add(new Chunk(" ")); + AddChunk(" ", activeFont); break; case RtfVisualSpecialCharKind.LeftDoubleQuote: - _MyParagraph.Add(new Chunk("\u201C")); + AddChunk("\u201C", activeFont); break; case RtfVisualSpecialCharKind.LeftSingleQuote: - _MyParagraph.Add(new Chunk("\u2018")); + AddChunk("\u2018", activeFont); break; case RtfVisualSpecialCharKind.NonBreakingHyphen: - _MyParagraph.Add(new Chunk("\u2011")); + AddChunk("\u2011", activeFont); break; case RtfVisualSpecialCharKind.NonBreakingSpace: - _MyParagraph.Add(new Chunk("\u00A0")); + //iTextSharp.text.Font font = Volian.Svg.Library.VolianPdf.GetFont(sdf); + AddChunk("\u00A0", activeFont); break; case RtfVisualSpecialCharKind.OptionalHyphen: - _MyParagraph.Add(new Chunk("\u00AD")); + AddChunk("\u00AD", activeFont); break; case RtfVisualSpecialCharKind.ParagraphNumberBegin: break; @@ -191,10 +212,10 @@ namespace Volian.Print.Library case RtfVisualSpecialCharKind.QmSpace: break; case RtfVisualSpecialCharKind.RightDoubleQuote: - _MyParagraph.Add(new Chunk("\u201D")); + AddChunk("\u201D", activeFont); break; case RtfVisualSpecialCharKind.RightSingleQuote: - _MyParagraph.Add(new Chunk("\u2019")); + AddChunk("\u2019", activeFont); break; case RtfVisualSpecialCharKind.Tabulator: break;