Exemplo n.º 1
0
        public override void ModifyCTM(object backend, Matrix m)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            Cairo.Matrix t = new Cairo.Matrix(m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY);
            gc.Context.Transform(t);
        }
Exemplo n.º 2
0
        public override Matrix GetCTM(object backend)
        {
            Cairo.Matrix t   = ((CairoContextBackend)backend).Context.Matrix;
            Matrix       ctm = new Matrix(t.Xx, t.Yx, t.Xy, t.Yy, t.X0, t.Y0);

            return(ctm);
        }
 public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
 {
     if (pattern == null || currentScaleFactor != scaleFactor)
     {
         if (pattern != null)
         {
             pattern.Dispose();
         }
         Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame(actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
         using (var imgs = new Cairo.ImageSurface(Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor))) {
             var ic = new Cairo.Context(imgs);
             ic.Scale((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
             Gdk.CairoHelper.SetSourcePixbuf(ic, pb, 0, 0);
             ic.Paint();
             imgs.Flush();
             ((IDisposable)ic).Dispose();
             pattern = new Cairo.SurfacePattern(imgs);
         }
         pattern.Extend = Cairo.Extend.Repeat;
         var cm = new Cairo.Matrix();
         cm.Scale(scaleFactor, scaleFactor);
         pattern.Matrix     = cm;
         currentScaleFactor = scaleFactor;
     }
     return(pattern);
 }
Exemplo n.º 4
0
        public void TranslateTransform(float offsetX, float offsetY)
        {
            Control.Translate(offsetX, offsetY);
            var cairoMatrix = new Cairo.Matrix();

            cairoMatrix.InitTranslate(offsetX, offsetY);
            currentTransform = Cairo.Matrix.Multiply(cairoMatrix, currentTransform);
        }
Exemplo n.º 5
0
        public void ScaleTransform(float scaleX, float scaleY)
        {
            Control.Scale(scaleX, scaleY);
            var cairoMatrix = new Cairo.Matrix();

            cairoMatrix.InitScale(scaleX, scaleY);
            currentTransform = Cairo.Matrix.Multiply(cairoMatrix, currentTransform);
        }
Exemplo n.º 6
0
        public void MultiplyTransform(IMatrix matrix)
        {
            var cairoMatrix = matrix.ToCairo();

            Control.Transform(cairoMatrix);

            currentTransform = Cairo.Matrix.Multiply(cairoMatrix, currentTransform);
        }
Exemplo n.º 7
0
		public void RotateAt (float angle, float centerX, float centerY)
		{
			angle = Conversions.DegreesToRadians (angle);
			var sina = Math.Sin (angle);
			var cosa = Math.Cos (angle);
			var matrix = new Cairo.Matrix (cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa);
			control = Cairo.Matrix.Multiply (matrix, control);
		}
Exemplo n.º 8
0
        public void RotateAt(float angle, float centerX, float centerY)
        {
            angle = Conversions.DegreesToRadians(angle);
            var sina   = Math.Sin(angle);
            var cosa   = Math.Cos(angle);
            var matrix = new Cairo.Matrix(cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa);;

            control = Cairo.Matrix.Multiply(matrix, control);
        }
        public override Matrix GetCTM(object backend)
        {
            var cb = (CairoContextBackend)backend;

            Cairo.Matrix t = cb.Context.Matrix;
            // Adjust CTM X0,Y0 for ContextBackend Origin (ensures that new CTM is Identity Matrix)
            Matrix ctm = new Matrix(t.Xx, t.Yx, t.Xy, t.Yy, t.X0 - cb.Origin.X, t.Y0 - cb.Origin.Y);

            return(ctm);
        }
Exemplo n.º 10
0
        public void RotateTransform(float angle)
        {
            var radians = Conversions.DegreesToRadians(angle);

            Control.Rotate(radians);
            var cairoMatrix = new Cairo.Matrix();

            cairoMatrix.InitRotate(radians);
            currentTransform = Cairo.Matrix.Multiply(cairoMatrix, currentTransform);
        }
Exemplo n.º 11
0
 public void RestoreTransform()
 {
     if (transforms == null || transforms.Count == 0)
     {
         throw new InvalidOperationException("No corresponding SaveTransform");
     }
     ReverseTransform();
     currentTransform = transforms.Pop();
     ApplyTransform();
 }
Exemplo n.º 12
0
        public override Matrix GetCTM(object backend)
        {
            var cb = (CairoContextBackend)backend;

            Cairo.Matrix t = cb.Context.Matrix;

            // Adjust CTM OffsetX, OffsetY for ContextBackend Origin
            Matrix ctm = new Matrix(t.Xx, t.Yx, t.Xy, t.Yy, t.X0 - cb.Origin.X, t.Y0 - cb.Origin.Y);

            return(ctm);
        }
Exemplo n.º 13
0
 public static Cairo.Matrix ToCairoMatrix(this TikzEdt.Parser.TikzMatrix M)
 {
     Cairo.Matrix MM = new Cairo.Matrix(
         M.m[0, 0],
         M.m[0, 1],
         M.m[1, 0],
         M.m[1, 1],
         M.m[0, 2],
         M.m[1, 2]
         );
     return(MM);
 }
Exemplo n.º 14
0
        public override void Draw(Cairo.Context context)
        {
            Cairo.Matrix oldMatrix = context.Matrix;
            double       a         = MinorAxis / _majorAxis;

            context.Translate(0.0, _position.Y * (1 - a));
            context.Scale(1.0, a);
            context.MoveTo(_position.X + _majorAxis, _position.Y);
            context.Arc(_position.X, _position.Y, _majorAxis, 0.0, 2 * Math.PI);
            context.ClosePath();
            //todo change in order to process rotated ellipses (i.e. MajorAxis is collinear with OY)
            context.Matrix = oldMatrix;
        }
Exemplo n.º 15
0
            void SetRenderTransform()
            {
                var scale = Radius.Height / Radius.Width;

                RenderTransform = new Cairo.Matrix(1, 0f, 0f, scale, 0, GradientOrigin.Y - GradientOrigin.Y * scale);
                if (!ReferenceEquals(Transform, null))
                {
                    RenderTransform = Cairo.Matrix.Multiply(Transform, RenderTransform);
                }

                RenderTransformInverse = (Cairo.Matrix)RenderTransform.Clone();
                RenderTransformInverse.Invert();
            }
Exemplo n.º 16
0
        public void SetupWorldToSurfaceTransform(AABB world, Pair <int, int> projection, double swidth, double sheight, bool center)
        {
            _projection = projection;

            double inner_x = swidth * 0.9;
            double inner_y = sheight * 0.9;

            IVector diag         = world.Diagonal;
            IVector world_center = world.Center;

            _world_to_surface = new Cairo.Matrix(1, 0, 0, -1, 0, 0);
            _world_to_surface.Translate(swidth * 0.5, -sheight * 0.5);
            _world_to_surface.Scale(inner_x / diag[_projection.First], inner_y / diag[_projection.Second]);
            if (center)
            {
                _world_to_surface.Translate(-world_center[_projection.First], -world_center[_projection.Second]);
            }
        }
Exemplo n.º 17
0
		public Cairo.Pattern GetPattern (ApplicationContext actx, double scaleFactor)
		{
			if (pattern == null || currentScaleFactor != scaleFactor) {
				if (pattern != null)
					pattern.Dispose ();
				Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame (actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
				using (var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor))) {
					var ic = new Cairo.Context (imgs);
					ic.Scale ((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
					Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
					ic.Paint ();
					imgs.Flush ();
					((IDisposable)ic).Dispose ();
					pattern = new Cairo.SurfacePattern (imgs);
				}
				pattern.Extend = Cairo.Extend.Repeat;
				var cm = new Cairo.Matrix ();
				cm.Scale (scaleFactor, scaleFactor);
				pattern.Matrix = cm;
				currentScaleFactor = scaleFactor;
			}
			return pattern;
		}
Exemplo n.º 18
0
 public static IMatrix ToEto(this Cairo.Matrix matrix)
 {
     return(new MatrixHandler(matrix));
 }
Exemplo n.º 19
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            //base.OnPaint(pe);
            Cairo.Context dc = Gdk.CairoHelper.Create(args.Window);

            // Draw white background
            //Graphics dc = pe.Graphics;
            dc.IdentityMatrix();

            dc.SetSourceRGB(1.0, 1.0, 1.0);
            dc.Rectangle(0, 0, Allocation.Width, Allocation.Height);
            dc.Fill();

            // Draw the raster
            Cairo.Matrix t = TheRasterModel.GetTikzToScreenTransform().ToCairoMatrix();
            //t.Freeze();

            dc.Save();

            dc.LineWidth = 0.01;            // todo: always 1 pixel
            dc.SetSourceRGB(0.7, 0.7, 0.7); // whitesmoke?
            {
                dc.Transform(t);

                TheRasterModel.DrawRaster(
                    (p1, p2) => { dc.MoveTo(p1.X, p1.Y); dc.LineTo(p2.X, p2.Y); dc.Stroke(); },
                    (r1, r2) =>
                {
                    dc.DrawEllipse(0, 0, 2 * r1, 2 * r2);
                });
            }

            dc.Restore();

            // draw unavailable note
            if (TheDisplayModel.IsUnavailable)
            {
                dc.SetSourceRGB(0, 0, 0);
                dc.SelectFontFace("Arial", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
                //StringFormat f = new StringFormat();
                //f.Alignment = StringAlignment.Center;
                //f.LineAlignment = StringAlignment.Center;
                //dc.DrawString("<Unavailable>", new Font("Arial", 16), Brushes.Black, ClientRectangle, f);
                dc.MoveTo(Allocation.Width / 2, Allocation.Height / 2); //todo
                dc.ShowText("<Unavailable>");
            }

            // draw the pdf image
            if (TheDisplayModel.IsImageVisible && TheDisplayModel.Bmp != null)
            {
                Point p = new Point((Allocation.Width - TheDisplayModel.Bmp.Width) / 2, (Allocation.Height - TheDisplayModel.Bmp.Height) / 2);
                //dc.DrawImageUnscaled(TheDisplayModel.Bmp, p);
                dc.SetSource(TheDisplayModel.Bmp, p.X, p.Y);
                //dc.Rectangle(p.X, p.Y, TheDisplayModel.Bmp.Width, TheDisplayModel.Bmp.Height);
                dc.Paint();
            }

            // draw the overlay
            if (ShowOverlay)
            {
                dc.SetSourceRGB(0, 0, 0);
                // draw shapes from parsetree
                foreach (var osv in OSViews)
                {
                    osv.Draw(dc);
                }

                // draw (visible) auxiliary shapes
                foreach (var ps in PreviewShapes.Where(o => o.Visible))
                {
                    ps.Draw(dc);
                }
            }

            // draw adorner(s)
            foreach (var scope in this.OSViews.OfType <OverlayScopeView>().Where(v => v.IsAdornerVisible))
            {
                dc.SetSourceRGB(0.5, 0.5, 0.5);
                dc.LineWidth = 5;
                System.Windows.Rect ShowAt = scope.GetBB(Allocation.Height);
                ShowAt.Inflate(6, 6);

                dc.Rectangle(ShowAt.ToCairoRectangle());  //(PensAndBrushes.AdornerPen, ShowAt.ToRectangleF());
                dc.Stroke();
            }


            // draw the object marker
            if (MarkObject_ShowMarker && MarkObject_Marked != null)
            {
                System.Windows.Rect ShowAt = MarkObject_Marked.GetBB(Allocation.Height);
                ShowAt.Inflate(15, 15);
                //using (Pen p = new Pen(Brushes.Red, 6))
                {
                    dc.SetSourceRGB(1, 0, 0);
                    dc.LineWidth = 6;
                    dc.DrawEllipse(ShowAt);//p,
                }
            }

            ((IDisposable)dc.Target).Dispose();
            ((IDisposable)dc).Dispose();

            return(true);
        }
Exemplo n.º 20
0
		public MatrixHandler (Cairo.Matrix matrix)
		{
			this.control = matrix;
		}
Exemplo n.º 21
0
        public IMatrix Clone()
        {
            var matrix = new Cairo.Matrix(control.Xx, control.Yx, control.Xy, control.Yy, control.X0, control.Y0);

            return(new MatrixHandler(matrix));
        }
Exemplo n.º 22
0
 public void Create()
 {
     control = new Cairo.Matrix();
 }
Exemplo n.º 23
0
        public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination)
        {
            FixupAlpha();
            var context = graphics.Control;

            context.Save();
            context.Rectangle(destination.ToCairo());
            double scalex = 1;
            double scaley = 1;

            if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f)
            {
                scalex = (double)destination.Width / (double)source.Width;
                scaley = (double)destination.Height / (double)source.Height;
                context.Scale(scalex, scaley);
            }
            Cairo.SurfacePattern pattern;
            if (Surface != null)
            {
                // we got a surface (by drawing on the bitmap using Graphics), so use that directly.
                pattern = new Cairo.SurfacePattern(Surface);
                var m = new Cairo.Matrix();
                m.InitTranslate(source.Left - (destination.Left / scalex), source.Top - (destination.Top / scaley));
                pattern.Matrix = m;
                context.SetSource(pattern);
            }
            else
            {
                Gdk.CairoHelper.SetSourcePixbuf(context, Control, (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top);
                pattern = (Cairo.SurfacePattern)context.GetSource();
            }

            pattern.Filter = graphics.ImageInterpolation.ToCairo();
            context.Fill();
            context.Restore();
            pattern.Dispose();

            /*
             * Gdk.Pixbuf pb = Control;
             *
             *
             * if (source.Width != destination.Width || source.Height != destination.Height) {
             *      Gdk.Pixbuf pbDest = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height);
             *      double scalex = (double)(destination.Width) / (double)(source.Width);
             *      double scaley = (double)(destination.Height) / (double)(source.Height);
             *      pb.Scale (pbDest, 0, 0, destination.Width, destination.Height, -(source.X * scalex), -(source.Y * scaley),
             *              scalex, scaley, Gdk.InterpType.Bilinear);
             *      source.Location = new Point (0, 0);
             *      pb = pbDest;
             * }
             * /*
             *
             * pb.RenderToDrawable (graphics.Control, graphics.GC, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0);
             * /*
             *
             * Gdk.Pixmap pm, mask;
             * pb.RenderPixmapAndMask(out pm, out mask, 0);
             * graphics.Drawable.DrawDrawable(graphics.GC, pm, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height);
             * pm.Dispose();
             * mask.Dispose();
             * /*
             *
             * graphics.Drawable.DrawPixbuf(null, pb, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0);
             * /*
             */
            /*if (pb != Control)
             *      pb.Dispose ();*/
        }
Exemplo n.º 24
0
 public static Cairo.Matrix Multiply(Cairo.Matrix a, Cairo.Matrix b)
 {
     throw null;
 }
Exemplo n.º 25
0
 public void Multiply(Cairo.Matrix b)
 {
 }
Exemplo n.º 26
0
        public void Prepend(IMatrix matrix)
        {
            var cairoMatrix = matrix.ControlObject as Cairo.Matrix;

            control = Cairo.Matrix.Multiply(cairoMatrix, control);
        }
Exemplo n.º 27
0
		public void ScaleAt (float scaleX, float scaleY, float centerX, float centerY)
		{
			var matrix = new Cairo.Matrix (scaleX, 0, 0, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY);
			control = Cairo.Matrix.Multiply (matrix, control);
		}
Exemplo n.º 28
0
		public void Prepend (IMatrix matrix)
		{
			var cairoMatrix = matrix.ControlObject as Cairo.Matrix;
			control = Cairo.Matrix.Multiply (cairoMatrix, control);
		}
Exemplo n.º 29
0
		public void Create (float xx, float yx, float xy, float yy, float x0, float y0)
		{
			control = new Cairo.Matrix (xx, yx, xy, yy, x0, y0);
		}
Exemplo n.º 30
0
		public void Create ()
		{
			control = new Cairo.Matrix ();
		}
Exemplo n.º 31
0
 public override void ModifyCTM(object backend, Matrix m)
 {
     CairoContextBackend gc = (CairoContextBackend)backend;
     Cairo.Matrix t = new Cairo.Matrix (m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY);
     gc.Context.Transform (t);
 }
Exemplo n.º 32
0
 public ScaledFont(Cairo.FontFace fontFace, Cairo.Matrix matrix, Cairo.Matrix ctm, Cairo.FontOptions options)
 {
 }
Exemplo n.º 33
0
        public void ScaleAt(float scaleX, float scaleY, float centerX, float centerY)
        {
            var matrix = new Cairo.Matrix(scaleX, 0, 0, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY);

            control = Cairo.Matrix.Multiply(matrix, control);
        }
Exemplo n.º 34
0
 public void GlyphPath(Cairo.Matrix matrix, Cairo.Glyph[] glyphs)
 {
 }
Exemplo n.º 35
0
 public void Create(float xx, float yx, float xy, float yy, float x0, float y0)
 {
     control = new Cairo.Matrix(xx, yx, xy, yy, x0, y0);
 }
Exemplo n.º 36
0
 public void ShowGlyphs(Cairo.Matrix matrix, Cairo.Glyph[] glyphs)
 {
 }
Exemplo n.º 37
0
 public MatrixHandler(Cairo.Matrix matrix)
 {
     this.control = matrix;
 }
Exemplo n.º 38
0
 public void Transform(Cairo.Matrix m)
 {
 }
Exemplo n.º 39
0
		public void Skew (float skewX, float skewY)
		{
			var matrix = new Cairo.Matrix (1, Math.Tan (Conversions.DegreesToRadians (skewX)), Math.Tan (Conversions.DegreesToRadians (skewY)), 1, 0, 0);
			control = Cairo.Matrix.Multiply (matrix, control);
		}
Exemplo n.º 40
0
		public IMatrix Clone ()
		{
			var matrix = new Cairo.Matrix(control.Xx, control.Yx, control.Xy, control.Yy, control.X0, control.Y0);
			return new MatrixHandler (matrix);
		}