private void OnBeginPrint(object sender, Gtk.BeginPrintArgs args) { Gtk.PrintOperation op = (Gtk.PrintOperation)sender; Gtk.PrintContext context = args.Context; timestamp_footer = CreateTimestampLayout(context); // FIXME: These should be configurable settings later (UI Change) margin_top = CmToPixel(1.5, context.DpiY); margin_left = CmToPixel(1, context.DpiX); margin_right = CmToPixel(1, context.DpiX); margin_bottom = 0; double max_height = Pango.Units.FromPixels((int)context.Height - margin_top - margin_bottom - ComputeFooterHeight(context)); Gtk.TextIter position; Gtk.TextIter end_iter; Buffer.GetBounds(out position, out end_iter); double page_height = 0; bool done = position.Compare(end_iter) >= 0; while (!done) { Gtk.TextIter line_end = position; if (!line_end.EndsLine()) { line_end.ForwardToLineEnd(); } int paragraph_number = position.Line; int indentation; using (Pango.Layout layout = CreateParagraphLayout( context, position, line_end, out indentation)) { Pango.Rectangle ink_rect = Pango.Rectangle.Zero; Pango.Rectangle logical_rect = Pango.Rectangle.Zero; for (int line_in_paragraph = 0; line_in_paragraph < layout.LineCount; line_in_paragraph++) { Pango.LayoutLine line = layout.GetLine(line_in_paragraph); line.GetExtents(ref ink_rect, ref logical_rect); if (page_height + logical_rect.Height >= max_height) { PageBreak page_break = new PageBreak( paragraph_number, line_in_paragraph); page_breaks.Add(page_break); page_height = 0; } page_height += logical_rect.Height; } position.ForwardLine(); done = position.Compare(end_iter) >= 0; } } op.NPages = page_breaks.Count + 1; }
private void Control_BeginPrint(object o, Gtk.BeginPrintArgs args) { if (_control != null && PageCount == -1) { var paperHeight = args.Context.Height; var paperWidth = args.Context.Width; _preferredSize = _control.GetPreferredSize(); #if GTK3 // to draw the widget using Cairo, we need to use an offscreen window var gtkWidget = _control.GetContainerWidget(); _oldParent = gtkWidget.Parent; _offscreenWindow = new Gtk.OffscreenWindow(); _offscreenWindow.Child = gtkWidget; _offscreenWindow.SetSizeRequest((int)Math.Max(_preferredSize.Width, paperWidth), (int)Math.Max(_preferredSize.Height, paperHeight)); _offscreenWindow.ShowAll(); #endif PageCount = (int)Math.Ceiling(_preferredSize.Height / paperHeight); } Callback.OnPrinting(Widget, EventArgs.Empty); }
/// <summary> /// OnBeginPrint - Load up the Document to be printed and analyze it. /// </summary> /// <param name="obj">The Print Operation</param> /// <param name="args">The BeginPrintArgs passed by the Print Operation</param> private void OnBeginPrint(object obj, Gtk.BeginPrintArgs args) { }