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)
This commit is contained in:
Kathy Ruffing 2015-07-13 11:37:56 +00:00
parent 00ddf14538
commit 330f36250d
2 changed files with 45 additions and 14 deletions

View File

@ -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;

View File

@ -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("<special {0}>", 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;