private void OnDrawPage(object obj, Gtk.DrawPageArgs args)
{
PrintContext context = args.Context;
Cairo.Context cr = context.CairoContext;
double width = context.Width;
cr.Rectangle(0, 0, width, headerHeight);
cr.SetSourceRGB(0.8, 0.8, 0.8);
cr.FillPreserve();
cr.SetSourceRGB(0, 0, 0);
cr.LineWidth = 1;
cr.Stroke();
Pango.Layout layout = context.CreatePangoLayout();
Pango.FontDescription desc = Pango.FontDescription.FromString("sans 14");
layout.FontDescription = desc;
layout.SetText(fileName);
layout.Width = (int)width;
layout.Alignment = Pango.Alignment.Center;
int layoutWidth, layoutHeight;
layout.GetSize(out layoutWidth, out layoutHeight);
double textHeight = (double)layoutHeight / (double)pangoScale;
cr.MoveTo(width / 2, (headerHeight - textHeight) / 2);
Pango.CairoHelper.ShowLayout(cr, layout);
string pageStr = String.Format("{0}/{1}", args.PageNr + 1, numPages);
layout.SetText(pageStr);
layout.Alignment = Pango.Alignment.Right;
cr.MoveTo(width - 2, (headerHeight - textHeight) / 2);
Pango.CairoHelper.ShowLayout(cr, layout);
layout = null;
layout = context.CreatePangoLayout();
desc = Pango.FontDescription.FromString("mono");
desc.Size = (int)(fontSize * pangoScale);
layout.FontDescription = desc;
cr.MoveTo(0, headerHeight + headerGap);
int line = args.PageNr * linesPerPage;
for (int i = 0; i < linesPerPage && line < numLines; i++)
{
layout.SetText(lines[line]);
Pango.CairoHelper.ShowLayout(cr, layout);
cr.RelMoveTo(0, fontSize);
line++;
}
(cr as IDisposable).Dispose();
layout = null;
}