Fix the RTF for grid cells so that Text is set to use a Text font rather than a Symbol font.
Added some debug code for testing the function above. After the code was finished, the debug code was commented-out.
This commit is contained in:
parent
948161603a
commit
30c7c16cd0
@ -759,6 +759,7 @@ namespace Volian.Print.Library
|
|||||||
}
|
}
|
||||||
public static iTextSharp.text.Paragraph RtfToParagraph(string rtf, iTextSharp.text.Font mySymFont)
|
public static iTextSharp.text.Paragraph RtfToParagraph(string rtf, iTextSharp.text.Font mySymFont)
|
||||||
{
|
{
|
||||||
|
rtf=FixRTFToPrint(rtf);
|
||||||
IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtf);
|
IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtf);
|
||||||
Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc);
|
Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc);
|
||||||
rtf2IText.DefaultFont = mySymFont;
|
rtf2IText.DefaultFont = mySymFont;
|
||||||
@ -766,6 +767,38 @@ namespace Volian.Print.Library
|
|||||||
para.SetLeading(_SixLinesPerInch, 0);
|
para.SetLeading(_SixLinesPerInch, 0);
|
||||||
return para;
|
return para;
|
||||||
}
|
}
|
||||||
|
// The text font used in FixRTFToPrint for grid
|
||||||
|
public static System.Drawing.Font DefaultFont = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Fix RTF so that text uses the Text font rather than the Symbol font.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rtf"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static string FixRTFToPrint(string rtf)
|
||||||
|
{
|
||||||
|
// Only do this if the text contains symbols.
|
||||||
|
if (rtf.Contains("VESymbFix"))
|
||||||
|
{
|
||||||
|
System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox();
|
||||||
|
rtb.Rtf = rtf;
|
||||||
|
bool changed = false;
|
||||||
|
// Look at one character at a time
|
||||||
|
for (int i = 0; i < rtb.TextLength; i++)
|
||||||
|
{
|
||||||
|
rtb.Select(i, 1);
|
||||||
|
// If the character is a printable character set the font to the text font
|
||||||
|
if (rtb.SelectionFont.FontFamily.Name == "VESymbFix" && rtb.SelectedText[0] > ' ' && rtb.SelectedText[0] <= '\xFF')
|
||||||
|
{
|
||||||
|
//use bolding underline italics from local font
|
||||||
|
System.Drawing.Font fnt = rtb.SelectionFont;
|
||||||
|
rtb.SelectionFont = new System.Drawing.Font(DefaultFont, fnt.Style);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) return rtb.Rtf;
|
||||||
|
}
|
||||||
|
return rtf;
|
||||||
|
}
|
||||||
private static float _SixLinesPerInch = 12; // twips
|
private static float _SixLinesPerInch = 12; // twips
|
||||||
#endregion
|
#endregion
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
@ -242,8 +242,27 @@ namespace Volian.Print.Library
|
|||||||
if (c > '\x7F' && c != '\xA0' && c != '\xB0') return true;
|
if (c > '\x7F' && c != '\xA0' && c != '\xB0') return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// The funcction below was used for the first few lines of DoVisitText which have been commented-out
|
||||||
|
//private object FixText(string str)
|
||||||
|
//{
|
||||||
|
// StringBuilder sb = new StringBuilder();
|
||||||
|
// foreach (char c in str)
|
||||||
|
// if (c < ' ' || c > '\xFF')
|
||||||
|
// sb.Append(string.Format("[{0}]", (int)c));
|
||||||
|
// else
|
||||||
|
// sb.Append(c);
|
||||||
|
// return sb.ToString();
|
||||||
|
//}
|
||||||
protected override void DoVisitText(IRtfVisualText visualText)
|
protected override void DoVisitText(IRtfVisualText visualText)
|
||||||
{
|
{
|
||||||
|
//Code to find text (non-symbol) being output with a symbol font
|
||||||
|
//if(visualText.Format.Font.Name=="VESymbFix" && visualText.Text.Length > 1)
|
||||||
|
//{
|
||||||
|
// string s = visualText.Text;
|
||||||
|
// s=s.Replace("a","").Replace("b","");
|
||||||
|
// if(s!=visualText.Text)
|
||||||
|
// Console.WriteLine("{0}-{1}-{2}-{3}", visualText.Format.Font.Name, (int)(visualText.Text[0]),visualText.Text.Length,FixText(visualText.Text));
|
||||||
|
//}
|
||||||
int profileDepth = ProfileTimer.Push(">>>> DoVisitText");
|
int profileDepth = ProfileTimer.Push(">>>> DoVisitText");
|
||||||
if (visualText.Format.IsHidden)
|
if (visualText.Format.IsHidden)
|
||||||
{
|
{
|
||||||
@ -294,7 +313,6 @@ namespace Volian.Print.Library
|
|||||||
}
|
}
|
||||||
ProfileTimer.Pop(profileDepth);
|
ProfileTimer.Pop(profileDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdjustChunk(IRtfVisualText visualText, iTextSharp.text.Font font, Chunk chk)
|
private void AdjustChunk(IRtfVisualText visualText, iTextSharp.text.Font font, Chunk chk)
|
||||||
{
|
{
|
||||||
if (visualText.Format.BackgroundColor.AsDrawingColor.ToArgb() != System.Drawing.Color.White.ToArgb())
|
if (visualText.Format.BackgroundColor.AsDrawingColor.ToArgb() != System.Drawing.Color.White.ToArgb())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user