protected override void OnBeginPrint (PrintContext context)
		{
			layout = PangoUtil.CreateLayout (context);
			layout.FontDescription = settings.Font;
			
			layout.FontDescription.Weight = Pango.Weight.Bold;
			layout.SetText (" ");
			int w, h;
			layout.GetSize (out w, out h);
			this.lineHeight = h / Pango.Scale.PangoScale;
			layout.FontDescription.Weight = Pango.Weight.Normal;
			
			SetHeaderFormat (settings.HeaderFormat);
			SetFooterFormat (settings.FooterFormat);
			
			style = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle (null, settings.ColorScheme);
			
			pageWidth = context.PageSetup.GetPageWidth (Unit.Mm);
			pageHeight = context.PageSetup.GetPageHeight (Unit.Mm);
			double contentHeight = pageHeight
				- (headerLines > 0? settings.HeaderPadding : 0) 
				- (footerLines > 0? settings.FooterPadding : 0);
			linesPerPage = (int)(contentHeight / lineHeight) - (headerLines + footerLines);
			totalPages = (int)Math.Ceiling ((double)doc.LineCount / linesPerPage); 
			
			NPages = totalPages;
			
			base.OnBeginPrint (context);
		}
Ejemplo n.º 2
0
        public static void Main(string[] Pages)
        {
            Application.Init();
            var print = new Gtk.PrintOperation();

            print.PrintSettings            = new Gtk.PrintSettings();
            print.PrintSettings.Scale      = 33.75;
            print.PrintSettings.Resolution = 1200;
            print.JobName     = "FeuerwehrCloud Ausdruck";
            print.BeginPrint += (obj2, args) => { print.NPages = Pages.Length; };
            print.DrawPage   += (obj2, args) => {
                try {
                    FeuerwehrCloud.Helper.Logger.WriteLine("|  > [ImagePrinter] *** Page " + args.PageNr.ToString() + " of " + Pages.Length.ToString());
                    var imageBit = default(byte[]);
                    var image    = System.Drawing.Image.FromFile("/tmp/" + Pages[args.PageNr]);
                    using (var memoryStream = new MemoryStream()) {
                        image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                        imageBit = memoryStream.ToArray();
                    }
                    Gtk.PrintContext context = args.Context;
                    try {
                        var pixBuf = new Gdk.Pixbuf(imageBit, image.Width, image.Height);
                        try {
                            Cairo.Context cr = context.CairoContext;
                            cr.MoveTo(0, 0);
                            Gdk.CairoHelper.SetSourcePixbuf(cr, pixBuf, 0, 10);
                            cr.Paint();
                            ((IDisposable)cr).Dispose();
                        } catch (Exception ex4) {
                            FeuerwehrCloud.Helper.Logger.WriteLine("|||  > [ImagePrinter] *** ERROR: " + ex4.ToString());
                        }
                    } catch (Exception ex5) {
                        FeuerwehrCloud.Helper.Logger.WriteLine("|||  > [ImagePrinter] *** ERROR: " + ex5.ToString());
                    }
                } catch (Exception ex3) {
                    FeuerwehrCloud.Helper.Logger.WriteLine("||| > [ImagePrinter] *** ERROR: " + ex3.ToString());
                }
            };
            print.EndPrint += (obj2, args) => { FeuerwehrCloud.Helper.Logger.WriteLine("|  > [ImagePrinter] *** Printing finished "); Application.Quit(); };
            print.Run(Gtk.PrintOperationAction.Print, null);
        }
Ejemplo n.º 3
0
        protected virtual void OnPrintActionActivated(object sender, System.EventArgs e)
        {
            using (PrintContext context = new PrintContext(GdkWindow.Handle))
            {

                printing = new PrintOperation();
                printing.Unit = Unit.Points;
                printing.UseFullPage = false;

                printing.BeginPrint += HandlePrintBeginPrint;
                printing.DrawPage += HandlePrintDrawPage;
                printing.EndPrint += HandlePrintEndPrint;

                printing.Run(PrintOperationAction.PrintDialog, null);
            }
        }
		protected override void OnDrawPage (PrintContext context, int pageNr)
		{
			using (var cr = context.CairoContext) {
				double xPos = 0, yPos = 0;
			
				PrintHeader (cr, context, pageNr, ref xPos, ref yPos);
			
				int startLine = pageNr * linesPerPage;
				int endLine = Math.Min (startLine + linesPerPage - 1, doc.LineCount);
			
				//FIXME: use proper 1-layout-per-line
				for (int i = startLine; i < endLine; i++) {
					var line = doc.GetLine (i + 1);
					if (!settings.UseHighlighting) {
						string text = doc.GetTextAt (line);
						text = text.Replace ("\t", new string (' ', settings.TabSize));
					
						layout.SetText (text);
						cr.MoveTo (xPos, yPos);
						Pango.CairoHelper.ShowLayout (cr, layout);
					
						yPos += lineHeight;
						continue;
					}
					
					var startChunk = doc.SyntaxMode.GetChunks (style, line, line.Offset, line.LengthIncludingDelimiter);
					foreach (Chunk chunk in startChunk) {
						ChunkStyle chunkStyle = chunk != null ? style.GetChunkStyle (chunk) : null;
						string text = doc.GetTextAt (chunk);
						text = text.Replace ("\t", new string (' ', settings.TabSize));
						layout.SetText (text);
					
						var atts = ResetAttributes ();
					
						atts.Insert (new Pango.AttrForeground (chunkStyle.Color.Red, chunkStyle.Color.Green, chunkStyle.Color.Blue));
					
						if (chunkStyle.Bold) {
							atts.Insert (new Pango.AttrWeight (Pango.Weight.Bold));
						}
						if (chunkStyle.Italic) {
							atts.Insert (new Pango.AttrStyle (Pango.Style.Italic));
						}
						if (chunkStyle.Underline) {
							atts.Insert (new Pango.AttrUnderline (Pango.Underline.Single));
						}
					
						cr.MoveTo (xPos, yPos);
						Pango.CairoHelper.ShowLayout (cr, layout);
					
						int wout, hout;
						layout.GetSize (out wout, out hout);
						double w = wout / Pango.Scale.PangoScale;
						
						xPos += w;
					
						if (w > pageWidth)
							break;
					}

					xPos = 0;
					yPos += lineHeight;
				}
			
				PrintFooter (cr, context, pageNr, ref xPos, ref yPos);
			}
		}
		protected override void OnEndPrint (PrintContext context)
		{
			layout.Dispose ();
			layout = null;
			base.OnEndPrint (context);
		}
		void PrintFooter (Cairo.Context cr, PrintContext context, int page, ref double xPos, ref double yPos)
		{
			if (footerLines == 0)
				return;
			
			yPos = pageHeight - (lineHeight * footerLines) - settings.FooterPadding;
			
			if (settings.FooterSeparatorWeight > 0) {
				cr.LineWidth = settings.FooterSeparatorWeight;
				cr.MoveTo (pageWidth / 3, yPos + (settings.FooterPadding / 2));
				cr.LineTo (2 * pageWidth / 3, yPos + (settings.FooterPadding / 2));
				cr.Stroke ();
			}
			
			yPos += settings.FooterPadding;
			
			ResetAttributes ();
			
			layout.SetText (Subst (footerText, page));
			
			int wout, hout;
			layout.GetSize (out wout, out hout);
			double w = wout / Pango.Scale.PangoScale;
			
			cr.MoveTo ((pageWidth - w) / 2, yPos);
			Pango.CairoHelper.ShowLayout (cr, layout);
		}
Ejemplo n.º 7
0
		public static Pango.Layout CreateLayout (PrintContext context)
		{
			var ptr = gtk_print_context_create_pango_layout (context.Handle);
			return ptr == IntPtr.Zero? null : new Pango.Layout (ptr);
		}
Ejemplo n.º 8
0
        protected void OnPrintActionActivated(object sender, System.EventArgs e)
        {
            using (PrintContext context = new PrintContext(GdkWindow.Handle))
            {
                printing = new PrintOperation();
                printing.Unit = Unit.Points;
                printing.UseFullPage = true;
                printing.DefaultPageSetup = new PageSetup();
                printing.DefaultPageSetup.Orientation =
                    report.PageHeightPoints > report.PageWidthPoints ? PageOrientation.Portrait : PageOrientation.Landscape;

                printing.BeginPrint += HandlePrintBeginPrint;
                printing.DrawPage += HandlePrintDrawPage;
                printing.EndPrint += HandlePrintEndPrint;

                printing.Run(PrintOperationAction.PrintDialog, null);
            }
        }