B2017-191 insert a NEWLINE chunk when there are hard returns instead of spaces

This commit is contained in:
John Jenko 2017-08-30 19:34:50 +00:00
parent bb99e9d3c3
commit 6e9a7d046b

View File

@ -148,23 +148,38 @@ namespace Volian.Print.Library
return _MyParagraph; return _MyParagraph;
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private int _lastWasLineBreak = 0; // B2017-191 insert a NewLine when hard returns are used
protected override void DoVisitBreak(IRtfVisualBreak visualBreak) protected override void DoVisitBreak(IRtfVisualBreak visualBreak)
{ {
switch (visualBreak.BreakKind) switch (visualBreak.BreakKind)
{ {
case RtfVisualBreakKind.Line: case RtfVisualBreakKind.Line:
if (_lastWasLineBreak > 0)
{
_MyParagraph.Add(Chunk.NEWLINE);
if (_lastWasLineBreak == 1)
_MyParagraph.Add(Chunk.NEWLINE); // B2017-191 if this is the first hard return add an etra newline to create the first blank line
}
else
{
Chunk ck = HasIndent ? new Chunk("".PadLeft(200)) : new Chunk("".PadLeft(200)); Chunk ck = HasIndent ? new Chunk("".PadLeft(200)) : new Chunk("".PadLeft(200));
_MyParagraph.Add(ck); _MyParagraph.Add(ck);
}
_lastWasLineBreak++; // B2017-191 hard return count
break; break;
case RtfVisualBreakKind.Page: case RtfVisualBreakKind.Page:
_lastWasLineBreak = 0; // B2017-191 reset hard return count
break; break;
case RtfVisualBreakKind.Paragraph: case RtfVisualBreakKind.Paragraph:
Chunk ck1 = HasIndent ? new Chunk("".PadLeft(200)) : Chunk.NEWLINE; Chunk ck1 = HasIndent ? new Chunk("".PadLeft(200)) : Chunk.NEWLINE;
_MyParagraph.Add(ck1); _MyParagraph.Add(ck1);
_lastWasLineBreak = 0; // B2017-191 reset hard return count
break; break;
case RtfVisualBreakKind.Section: case RtfVisualBreakKind.Section:
_lastWasLineBreak = 0; // B2017-191 reset hard return count
break; break;
default: default:
_lastWasLineBreak = 0; // B2017-191 reset hard return count
break; break;
} }
//_MyParagraph.Add(string.Format("<{0}>", visualBreak.BreakKind.ToString())); //_MyParagraph.Add(string.Format("<{0}>", visualBreak.BreakKind.ToString()));
@ -230,6 +245,7 @@ namespace Volian.Print.Library
default: default:
break; break;
} }
_lastWasLineBreak = 0; // B2017-191 reset hard return count
} }
private bool ContainsAllSymbols(string p) private bool ContainsAllSymbols(string p)
{ {
@ -268,6 +284,7 @@ namespace Volian.Print.Library
if (visualText.Format.IsHidden) if (visualText.Format.IsHidden)
{ {
ProfileTimer.Pop(profileDepth); ProfileTimer.Pop(profileDepth);
_lastWasLineBreak = 0; // B2017-191 reset hard return count
return; return;
} }
iTextSharp.text.Font font = Volian.Svg.Library.VolianPdf.GetFont(visualText.Format.Font.Name, visualText.Format.FontSize, iTextSharp.text.Font font = Volian.Svg.Library.VolianPdf.GetFont(visualText.Format.Font.Name, visualText.Format.FontSize,
@ -315,6 +332,7 @@ namespace Volian.Print.Library
ProcessMeans(visualText, visualText.Text, font); ProcessMeans(visualText, visualText.Text, font);
} }
ProfileTimer.Pop(profileDepth); ProfileTimer.Pop(profileDepth);
_lastWasLineBreak = 0; // B2017-191 reset hard return count
} }
/// <summary> /// <summary>
/// Method to process means from text. Draws a line above the content of the range included in the /// Method to process means from text. Draws a line above the content of the range included in the
@ -483,6 +501,7 @@ namespace Volian.Print.Library
//Console.WriteLine("5 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds); //Console.WriteLine("5 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
_MyParagraph.Add(img); _MyParagraph.Add(img);
//Console.WriteLine("6 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds); //Console.WriteLine("6 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
_lastWasLineBreak = 0; // B2017-191 reset hard return count
} // DoVisitImage } // DoVisitImage
} }