public CairoAdapter(System.Drawing.Graphics graphic) { Surface surface = new Win32Surface(graphic.GetHdc()); this.context = new Context(surface); context.LineWidth = 2; context.Color = new Color(1, 0, 0); }
private void Form1_Shown(object sender, EventArgs e) { Debug.WriteLine("Form1_Shown"); Win32Surface = new Win32Surface(this.CreateGraphics().GetHdc()); FontContext = new Context(Win32Surface); //CRITICAL: Format of Win32Surface and ImageSurface must be identical! ImageSurface = new ImageSurface(Format.Rgb24, ClientSize.Width, ClientSize.Height); BackContext = new Context(ImageSurface); //Clear Surface2 BackContext.SetSourceColor(new Color(1,1,1)); BackContext.Operator = Operator.Source; BackContext.Paint(); BackContext.Operator = Operator.Over; var textFormat = DWriteCairo.CreateTextFormat( "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 32f); Debug.Assert(Math.Abs(textFormat.FontSize - 32f) < 0.0001); const string s = "Hello World"; textLayout = DWriteCairo.CreateTextLayout(s, textFormat, 300, 40); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (System.Drawing.Graphics graphics = e.Graphics) { using (Win32Surface surface = new Win32Surface(graphics.GetHdc())) { using (Context context = new Context(surface)) { context.LineWidth = 2.0; context.SetSourceColor(this.bugColor); context.MoveTo(7.0, 64.0); context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0); context.MoveTo(25.0, 80.0); context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0); context.MoveTo(10.0, 41.0); context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0); context.LineWidth = 1.0; context.MoveTo(1.0, 26.0); context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0); context.LineTo(12.0, 14.0); context.Stroke(); context.MoveTo(30.0, 74.0); context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0); context.LineTo(10.0, 45.0); context.LineTo(10.0, 40.0); context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0); context.Stroke(); } } } }
protected override void OnPaint (PaintEventArgs a) { IntPtr hdc = a.Graphics.GetHdc (); Win32Surface s = new Win32Surface (hdc); Context cr = new Context (s); draw (cr, this.Width, this.Height); a.Graphics.ReleaseHdc (hdc); }
protected override void OnPaint (PaintEventArgs e) { IntPtr hdc = e.Graphics.GetHdc (); // will only work on win32 Win32Surface s = new Win32Surface (hdc); Context cr = new Context (s); Snippets.InvokeSnippet (snips, name, cr, w, h); e.Graphics.ReleaseHdc (hdc); }
public static Cairo.Context CreateContext(Gdk.Drawable drawable) { IntPtr x_drawable = IntPtr.Zero; int x_off = 0, y_off = 0; int x, y, w, h, d; ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d); bool is_gdk_window = drawable is Gdk.Window; if (is_gdk_window) ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable, out x_off, out y_off); Cairo.Surface surface; PlatformID os = Environment.OSVersion.Platform; if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT || os == PlatformID.Win32S || os == PlatformID.WinCE) { Gdk.GC gcc = new Gdk.GC(drawable); IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0); surface = new Win32Surface(windc); gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0); } else { x_drawable = drawable.Handle; IntPtr visual = gdk_drawable_get_visual(x_drawable); IntPtr Xdisplay = gdk_x11_drawable_get_xdisplay(x_drawable); IntPtr Xvisual = gdk_x11_visual_get_xvisual(visual); IntPtr Xdrawable = gdk_x11_drawable_get_xid(x_drawable); surface = new Cairo.XlibSurface(Xdisplay, Xdrawable, Xvisual, w, h); } Cairo.Context g = new Cairo.Context(surface); // this can be safely removed now, just keep it for a bit more //Cairo.Context g = new Cairo.Context ( // gdk_cairo_create (x_drawable )); if (is_gdk_window) g.Translate(-(double)x_off, -(double)y_off); return g; }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (Graphics1 = e.Graphics) using (Surface1 = new Win32Surface(Graphics1.GetHdc())) using (Context1 = new Context(Surface1)) { if (OnPaintAction!=null) { OnPaintAction(Context1); } } }
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable, bool double_buffered) { int x, y, w, h, d; Cairo.Surface surface; bool needs_xlate; ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d); PlatformID os = Environment.OSVersion.Platform; needs_xlate = drawable is Gdk.Window && double_buffered; if (needs_xlate) ((Gdk.Window)drawable).GetInternalPaintInfo (out drawable, out x, out y); if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT || os == PlatformID.Win32S || os == PlatformID.WinCE) { Gdk.GC gcc = new Gdk.GC (drawable); IntPtr windc = gdk_win32_hdc_get (drawable.Handle, gcc.Handle, 0); surface = new Win32Surface (windc); if (double_buffered) gdk_win32_hdc_release (drawable.Handle, gcc.Handle, 0); } else { IntPtr display = gdk_x11_drawable_get_xdisplay (drawable.Handle); IntPtr visual = gdk_drawable_get_visual (drawable.Handle); IntPtr xvisual = gdk_x11_visual_get_xvisual (visual); IntPtr xdrawable = gdk_x11_drawable_get_xid (drawable.Handle); surface = new XlibSurface (display, xdrawable, xvisual, w, h); } Cairo.Context ctx = new Cairo.Context (surface); if (needs_xlate) ctx.Translate (-(double) x, -(double) y); return ctx; }
private void Form1_Shown(object sender, EventArgs e) { Debug.WriteLine("Form1_Shown"); surface = new Win32Surface(this.CreateGraphics().GetHdc()); context = new Context(surface); textFormat = DWriteCairo.CreateTextFormat( "Consolas", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 12); textFormat.TextAlignment = TextAlignment.Center; float left, top, width, height; // get actual size of the text var measureLayout = DWriteCairo.CreateTextLayout(s, textFormat, 4096, 4096); measureLayout.GetRect(out left, out top, out width, out height); measureLayout.Dispose(); // build text context against the size and format textLayout = DWriteCairo.CreateTextLayout(s, textFormat, (int)Math.Ceiling(width), (int)Math.Ceiling(height)); Debug.WriteLine("showing layout"); Path path = DWriteCairo.RenderLayoutToCairoPath(context, textLayout); context.AppendPath(path); context.Fill(); textLayout.GetRect(out left, out top, out width, out height); textRect = new System.Drawing.RectangleF(left, top, width, height); context.Rectangle(left, top, width, height); context.Stroke(); context.GetTarget().Flush(); }
private void saveAsPngToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "PNG|*.png"; dialog.FileName = lastSelected; if (dialog.ShowDialog() == DialogResult.OK) { using (this.Graphics1 = this.CreateGraphics()) using (Surface1 = new Win32Surface(Graphics1.GetHdc())) using (Context1 = new Context(Surface1)) { Surface1.WriteToPng(dialog.FileName); } } }
public void setGraphics(System.Drawing.Graphics g) { Surface surface = new Win32Surface(g.GetHdc()); this.context = new Context(surface); }
public WFCairoGraphics(System.Drawing.Graphics g, int print) { this.g = g; surf = Cairo.Win32Surface.PrintingSurface(g.GetHdc()); cr = new Cairo.Context(surf); }
public WFCairoGraphics(System.Drawing.Graphics g) { this.g = g; System.Drawing.RectangleF cb = g.ClipBounds; surf = new Cairo.Win32Surface(g.GetHdc()); cr = new Cairo.Context(surf); cr.Rectangle(cb.X, cb.Y, cb.Width, cb.Height); cr.Clip(); }