Game Development Reference
In-Depth Information
public class SimplePrintDocument : PrintDocument
{
private StringReader inputStream = null;
private string bufferOverflow = null;
private Font printFont = null;
public SimplePrintDocument(StringReader inputStream, Font printFont)
: base()
{
this.inputStream = inputStream;
this.printFont = printFont;
}
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
bufferOverflow = null;
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
// Figure out how many lines can fit within the page boundaries
float linesPerPage = e.MarginBounds.Height /
printFont.GetHeight(e.Graphics);
int lineCount = 0;
// Deal with any remaining overflow lines from a previous page first
while (lineCount < linesPerPage && bufferOverflow != null)
{
float positionY = e.MarginBounds.Top +
(lineCount * printFont.GetHeight(e.Graphics));
lineCount += PrintLine(e, bufferOverflow, positionY);
}
// Now handle the current line buffer
string line = null;
while (lineCount < linesPerPage &&
((line = inputStream.ReadLine()) != null))
{
Search Nedrilad ::




Custom Search