Пример #1
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (myvxs == null)
            {
                var transform = Affine.NewMatix(
                    AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                    AffinePlan.Scale(spriteScale, spriteScale),
                    AffinePlan.Rotate(angle + Math.PI),
                    AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                    AffinePlan.Translate(Width / 2, Height / 2)
                    );
                //create vertextStore again from origiinal path
                myvxs = transform.TransformToVxs(lionShape.Path.Vxs);
            }
            //---------------------------------------------------------------------------------------------
            {
                int         j        = lionShape.NumPaths;
                int[]       pathList = lionShape.PathIndexList;
                ColorRGBA[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;

                for (int i = 0; i < j; ++i)
                {
                    graphics2D.Render(new VertexStoreSnap(myvxs, pathList[i]), colors[i]);
                }
            }
            //---------------------------------------------------------------------------------------------
        }
        static Affine CreateAffine(double destX, double destY,
                                   double hotspotOffsetX, double hotSpotOffsetY,
                                   double scaleX, double scaleY,
                                   double angleRad)
        {
            AffinePlan[] plans = new AffinePlan[4];
            int          i     = 0;

            if (hotspotOffsetX != 0.0f || hotSpotOffsetY != 0.0f)
            {
                plans[i] = AffinePlan.Translate(-hotspotOffsetX, -hotSpotOffsetY);
                i++;
            }

            if (scaleX != 1 || scaleY != 1)
            {
                plans[i] = AffinePlan.Scale(scaleX, scaleY);
                i++;
            }

            if (angleRad != 0)
            {
                plans[i] = AffinePlan.Rotate(angleRad);
                i++;
            }

            if (destX != 0 || destY != 0)
            {
                plans[i] = AffinePlan.Translate(destX, destY);
                i++;
            }
            return(Affine.NewMatix2(plans));
        }
Пример #3
0
        public void Draw(PixelFarm.DrawingGL.CanvasGL2d canvas)
        {
            if (myvxs == null)
            {
                var transform = Affine.NewMatix(
                    AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                    AffinePlan.Scale(spriteScale, spriteScale),
                    AffinePlan.Rotate(angle + Math.PI),
                    AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                    AffinePlan.Translate(Width / 2, Height / 2)
                    );
                myvxs = transform.TransformToVxs(lionShape.Path.Vxs);
            }
            //---------------------------------------------------------------------------------------------
            {
                int         j        = lionShape.NumPaths;
                int[]       pathList = lionShape.PathIndexList;
                ColorRGBA[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;

                for (int i = 0; i < j; ++i)
                {
                    var color = colors[i];
                    //?
                    canvas.FillVxsSnap(
                        new PixelFarm.Drawing.Color(color.alpha, color.blue, color.green, color.red),
                        new VertexStoreSnap(myvxs, pathList[i]));
                }
            }
        }
Пример #4
0
        public override void Render(PixelFarm.Drawing.Painter p)
        {
            if (_currentTx == null)
            {
                _currentTx = Affine.NewMatix(
                    AffinePlan.Translate(-_spriteShape.Center.x, -_spriteShape.Center.y),
                    AffinePlan.Scale(_spriteScale, _spriteScale),
                    AffinePlan.Rotate(_angle + Math.PI),
                    AffinePlan.Skew(_skewX / 1000.0, _skewY / 1000.0),
                    AffinePlan.Translate(Width / 2, Height / 2)
                    );
            }

            if (JustMove)
            {
                float ox = p.OriginX;
                float oy = p.OriginY;

                p.SetOrigin(ox + _posX, oy + _posY);
                _spriteShape.Paint(p);
                p.SetOrigin(ox, oy);
            }
            else
            {
                _spriteShape.Paint(p, _currentTx);
            }
        }
Пример #5
0
        public override void Draw(Graphics2D g)
        {
            int width  = 800;
            int height = 600;

            //clear the image to white
            g.Clear(ColorRGBA.White);
            // draw a circle

            Ellipse ellipsePro = new Ellipse(0, 0, 100, 50);

            for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
            {
                var mat = Affine.NewMatix(
                    AffinePlan.Rotate(MathHelper.DegreesToRadians(angleDegrees)),
                    AffinePlan.Translate(width / 2, 150));

                VertexStore sp1 = mat.TransformToVxs(ellipsePro.MakeVxs());

                g.Render(sp1, ColorRGBA.Yellow);

                //Stroke ellipseOutline = new Stroke(sp1, 3);
                g.Render(StrokeHelp.MakeVxs(sp1, 3), ColorRGBA.Blue);
            }

            // and a little polygon
            PathWriter littlePoly = new PathWriter();

            littlePoly.MoveTo(50, 50);
            littlePoly.LineTo(150, 50);
            littlePoly.LineTo(200, 200);
            littlePoly.LineTo(50, 150);
            littlePoly.LineTo(50, 50);
            g.Render(littlePoly.MakeVertexSnap(), ColorRGBA.Cyan);

            // draw some text
            // draw some text



            var textPrinter = new TextPrinter();

            textPrinter.CurrentFont = SvgFontStore.LoadFont(SvgFontStore.DEFAULT_SVG_FONTNAME, 30);
            //new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);

            VertexStore vxs   = textPrinter.CreateVxs("Printing from a printer".ToCharArray());
            var         affTx = Affine.NewTranslation(width / 2, height / 4 * 3);
            VertexStore s1    = affTx.TransformToVxs(vxs);


            g.Render(s1, ColorRGBA.Black);
            g.Render(StrokeHelp.MakeVxs(s1, 1), ColorRGBA.Red);


            var aff2 = Affine.NewMatix(
                AffinePlan.Rotate(MathHelper.DegreesToRadians(90)),
                AffinePlan.Translate(40, height / 2));

            g.Render(aff2.TransformToVertexSnap(vxs), ColorRGBA.Black);
        }
Пример #6
0
        public BlurWithPainter()
        {
            //m_rbuf2 = new ReferenceImage();
            m_shape_bounds           = new RectD();
            m_shadow_ctrl            = new PolygonEditWidget(4);
            this.FlattenCurveChecked = true;
            this.BlurMethod          = BlurMethod.RecursiveBlur;
            this.BlurRadius          = 15;
            Font svgFont = SvgFontStore.LoadFont("svg-LiberationSansFont", 300);

            m_pathVxs = svgFont.GetGlyph('a').originalVxs;// typeFaceForLargeA.GetGlyphForCharacter('a');
            Affine shape_mtx = Affine.NewMatix(AffinePlan.Translate(150, 100));

            m_pathVxs = shape_mtx.TransformToVxs(m_pathVxs);
            var curveFlattener = new CurveFlattener();

            m_path_2 = new VertexStoreSnap(curveFlattener.MakeVxs(m_pathVxs));
            BoundingRect.GetBoundingRect(m_path_2, ref m_shape_bounds);
            m_shadow_ctrl.SetXN(0, m_shape_bounds.Left);
            m_shadow_ctrl.SetYN(0, m_shape_bounds.Bottom);
            m_shadow_ctrl.SetXN(1, m_shape_bounds.Right);
            m_shadow_ctrl.SetYN(1, m_shape_bounds.Bottom);
            m_shadow_ctrl.SetXN(2, m_shape_bounds.Right);
            m_shadow_ctrl.SetYN(2, m_shape_bounds.Top);
            m_shadow_ctrl.SetXN(3, m_shape_bounds.Left);
            m_shadow_ctrl.SetYN(3, m_shape_bounds.Top);
            m_shadow_ctrl.LineColor = ColorRGBAf.MakeColorRGBA(0f, 0.3f, 0.5f, 0.3f);
        }
Пример #7
0
 public SvgFont(SvgFontFace fontface, int emSizeInPoints)
 {
     this.fontface       = fontface;
     this.emSizeInPoints = emSizeInPoints;
     //------------------------------------
     emSizeInPixels    = (int)(((float)emSizeInPoints / (float)POINTS_PER_INCH) * (float)PIXEL_PER_INCH);
     currentEmScalling = (float)emSizeInPixels / (float)fontface.UnitsPerEm;
     scaleTx           = Affine.NewMatix(AffinePlan.Scale(currentEmScalling));
 }
        static Affine CreateAffine(double destX, double destY)
        {
            AffinePlan plan = new AffinePlan();

            if (destX != 0 || destY != 0)
            {
                plan = AffinePlan.Translate(destX, destY);
            }
            return(Affine.NewMatix(plan));
        }
Пример #9
0
        void DrawWithWinGdi(GdiPlusPainter p)
        {
            int w = 800, h = 600;

            p.Clear(Drawing.Color.White);
            p.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            if (isMaskSliderValueChanged)
            {
                GenerateMaskWithWinGdiPlus(w, h);
            }

            using (System.Drawing.Bitmap background = CreateBackgroundBmp(w, h))
            {
                p.DrawImage(background, 0, 0);
            }

            //draw lion on background
            Affine transform = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(lionScale, lionScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(w / 2, h / 2));

            using (System.Drawing.Bitmap lionBmp = new System.Drawing.Bitmap(w, h))
                using (System.Drawing.Graphics lionGfx = System.Drawing.Graphics.FromImage(lionBmp))
                {
                    //lionGfx.Clear(System.Drawing.Color.White);
                    //int n = lionShape.NumPaths;
                    //int[] indexList = lionShape.PathIndexList;


                    //TODO: review here again
                    throw new NotSupportedException();

                    //Color[] colors = lionShape.Colors;
                    ////var lionVxs = lionShape.Path.Vxs;// transform.TransformToVxs(lionShape.Path.Vxs);

                    //var lionVxs = new VertexStore();
                    //transform.TransformToVxs(lionShape.Vxs, lionVxs);
                    //for (int i = 0; i < n; ++i)
                    //{
                    //    VxsHelper.FillVxsSnap(lionGfx,
                    //        new VertexStoreSnap(lionVxs, indexList[i]),
                    //        colors[i]);
                    //}
                    //using (var mergeBmp = MergeAlphaChannel(lionBmp, a_alphaBmp))
                    //{
                    //    //gx.InternalGraphics.DrawImage(this.a_alphaBmp, new System.Drawing.PointF(0, 0));
                    //    //gx.InternalGraphics.DrawImage(bmp, new System.Drawing.PointF(0, 0));
                    //    p.DrawImage(mergeBmp, 0, 0);
                    //}
                }
        }
Пример #10
0
 public SvgFont(SvgFontFace fontface, string fontName, FontStyle fontStyle, int emSizeInPoints)
 {
     this.fontface       = fontface;
     this.emSizeInPoints = emSizeInPoints;
     this.fontName       = fontName;
     this.fontStyle      = fontStyle;
     //------------------------------------
     emSizeInPixels    = (int)RequestFont.ConvEmSizeInPointsToPixels(emSizeInPoints);
     currentEmScalling = (float)emSizeInPixels / (float)fontface.UnitsPerEm;
     scaleTx           = Affine.NewMatix(AffinePlan.Scale(currentEmScalling));
 }
Пример #11
0
 public override void Draw(CanvasPainter p)
 {
     p.DrawImage(actualImage, 0, 0);
     p.DrawImage(actualImage,
                 AffinePlan.Translate(actualImage.Width * 2, actualImage.Height * 2),
                 AffinePlan.Scale(0.5));
     p.FillColor = Drawing.Color.Blue;
     p.FillRectangle(0, 0, 5, 5);
     p.FillColor = Drawing.Color.Green;
     p.FillRectangle(actualImage.Width, actualImage.Height,
                     actualImage.Width + 5, actualImage.Height + 5);
 }
Пример #12
0
        MemBitmap CreateHalfSize(MemBitmap orgBmp)
        {
            //TODO: ...
            //
            //1. create a new one
            MemBitmap smallBmp = new MemBitmap(orgBmp.Width / 2, orgBmp.Height / 2);

            using (AggPainterPool.Borrow(smallBmp, out var painter))
            {
                painter.DrawImage(orgBmp, AffinePlan.Scale(0.5, 0.5));
            }
            return(smallBmp);
        }
Пример #13
0
        Affine BuildImageBoundsPath(IImageReaderWriter sourceImage,
                                    VertexStore drawImageRectPath,
                                    double destX, double destY,
                                    double hotspotOffsetX, double hotSpotOffsetY,
                                    double scaleX, double scaleY,
                                    double angleRad)
        {
            AffinePlan[] plan = new AffinePlan[4];
            int          i    = 0;

            if (hotspotOffsetX != 0.0f || hotSpotOffsetY != 0.0f)
            {
                plan[i] = AffinePlan.Translate(-hotspotOffsetX, -hotSpotOffsetY);
                i++;
            }

            if (scaleX != 1 || scaleY != 1)
            {
                plan[i] = AffinePlan.Scale(scaleX, scaleY);
                i++;
            }

            if (angleRad != 0)
            {
                plan[i] = AffinePlan.Rotate(angleRad);
                i++;
            }

            if (destX != 0 || destY != 0)
            {
                plan[i] = AffinePlan.Translate(destX, destY);
                i++;
            }


            int srcW = sourceImage.Width;
            int srcH = sourceImage.Height;

            drawImageRectPath.Clear();
            drawImageRectPath.AddMoveTo(0, 0);
            drawImageRectPath.AddLineTo(srcW, 0);
            drawImageRectPath.AddLineTo(srcW, srcH);
            drawImageRectPath.AddLineTo(0, srcH);
            drawImageRectPath.AddCloseFigure();


            return(Affine.NewMatix(plan));
        }
Пример #14
0
        public override void Draw(Graphics2D g)
        {
            CanvasPainter painter = new CanvasPainter(g);

            painter.DrawImage(actualImage, 0, 0);

            painter.DrawImage(actualImage,
                              AffinePlan.Translate(actualImage.Width * 2, actualImage.Height * 2),
                              AffinePlan.Scale(0.5));


            painter.FillColor = ColorRGBA.Blue;
            painter.FillRectangle(0, 0, 5, 5);
            painter.FillColor = ColorRGBA.Green;
            painter.FillRectangle(actualImage.Width, actualImage.Height,
                                  actualImage.Width + 5, actualImage.Height + 5);
        }
Пример #15
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            if (myvxs == null)
            {
                var transform = Affine.NewMatix(
                    AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                    AffinePlan.Scale(spriteScale, spriteScale),
                    AffinePlan.Rotate(angle + Math.PI),
                    AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                    AffinePlan.Translate(Width / 2, Height / 2)
                    );
                //create vertextStore again from original path
                myvxs = new VertexStore();

                transform.TransformToVxs(lionShape.Vxs, myvxs);

                if (AutoFlipY)
                {
                    //flip the lion
                    PixelFarm.Agg.Transform.Affine aff = PixelFarm.Agg.Transform.Affine.NewMatix(
                        PixelFarm.Agg.Transform.AffinePlan.Scale(-1, -1),
                        PixelFarm.Agg.Transform.AffinePlan.Translate(0, 600));
                    //
                    var v2 = new VertexStore();
                    myvxs = transform.TransformToVxs(myvxs, v2);
                }
            }
            //---------------------------------------------------------------------------------------------
            {
                int             j        = lionShape.NumPaths;
                int[]           pathList = lionShape.PathIndexList;
                Drawing.Color[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;
                for (int i = 0; i < j; ++i)
                {
                    p.FillColor = colors[i];
                    p.Fill(new VertexStoreSnap(myvxs, pathList[i]));
                }
            }
            //test
            if (SharpenRadius > 0)
            {
                //p.DoFilter(new RectInt(0, p.Height, p.Width, 0), 2);
                //PixelFarm.Agg.Imaging.SharpenFilterARGB.Sharpen()
            }
        }
        static Affine BuildImageBoundsPath(
            int srcW, int srcH,
            double destX, double destY, VertexStore outputDestImgRect)
        {
            AffinePlan plan = new AffinePlan();

            if (destX != 0 || destY != 0)
            {
                plan = AffinePlan.Translate(destX, destY);
            }

            outputDestImgRect.Clear();
            outputDestImgRect.AddMoveTo(0, 0);
            outputDestImgRect.AddLineTo(srcW, 0);
            outputDestImgRect.AddLineTo(srcW, srcH);
            outputDestImgRect.AddLineTo(0, srcH);
            outputDestImgRect.AddCloseFigure();
            return(Affine.NewMatix(plan));
        }
        static Affine BuildImageBoundsPath(
            int srcW, int srcH,
            double destX, double destY,
            double hotspotOffsetX, double hotSpotOffsetY,
            double scaleX, double scaleY,
            double angleRad,
            VertexStore outputDestImgRect)
        {
            AffinePlan[] plans = new AffinePlan[4];
            int          i     = 0;

            if (hotspotOffsetX != 0.0f || hotSpotOffsetY != 0.0f)
            {
                plans[i] = AffinePlan.Translate(-hotspotOffsetX, -hotSpotOffsetY);
                i++;
            }

            if (scaleX != 1 || scaleY != 1)
            {
                plans[i] = AffinePlan.Scale(scaleX, scaleY);
                i++;
            }

            if (angleRad != 0)
            {
                plans[i] = AffinePlan.Rotate(angleRad);
                i++;
            }

            if (destX != 0 || destY != 0)
            {
                plans[i] = AffinePlan.Translate(destX, destY);
                i++;
            }

            outputDestImgRect.Clear();
            outputDestImgRect.AddMoveTo(0, 0);
            outputDestImgRect.AddLineTo(srcW, 0);
            outputDestImgRect.AddLineTo(srcW, srcH);
            outputDestImgRect.AddLineTo(0, srcH);
            outputDestImgRect.AddCloseFigure();
            return(Affine.NewMatix(plans));
        }
Пример #18
0
        Affine BuildImageBoundsPath(
            int srcW, int srcH,
            VertexStore drawImageRectPath,
            double destX, double destY)
        {
            AffinePlan plan = new AffinePlan();

            if (destX != 0 || destY != 0)
            {
                plan = AffinePlan.Translate(destX, destY);
            }

            drawImageRectPath.Clear();
            drawImageRectPath.AddMoveTo(0, 0);
            drawImageRectPath.AddLineTo(srcW, 0);
            drawImageRectPath.AddLineTo(srcW, srcH);
            drawImageRectPath.AddLineTo(0, srcH);
            drawImageRectPath.AddCloseFigure();
            return(Affine.NewMatix(plan));
        }
Пример #19
0
        Affine BuildImageBoundsPath(IImageReaderWriter sourceImage,
                                    VertexStore drawImageRectPath,
                                    double destX, double destY)
        {
            AffinePlan plan = new AffinePlan();

            if (destX != 0 || destY != 0)
            {
                plan = AffinePlan.Translate(destX, destY);
            }
            int srcW = sourceImage.Width;
            int srcH = sourceImage.Height;

            drawImageRectPath.Clear();
            drawImageRectPath.AddMoveTo(0, 0);
            drawImageRectPath.AddLineTo(srcW, 0);
            drawImageRectPath.AddLineTo(srcW, srcH);
            drawImageRectPath.AddLineTo(0, srcH);
            drawImageRectPath.AddCloseFigure();

            return(Affine.NewMatix(plan));
        }
Пример #20
0
        public override void Draw(CanvasPainter p)
        {
            if (p is GdiPlusCanvasPainter)
            {
                DrawWithWinGdi((GdiPlusCanvasPainter)p);
                return;
            }
            AggCanvasPainter p2 = (AggCanvasPainter)p;
            Graphics2D       gx = p2.Graphics;
            var widgetsSubImage = gx.DestImage;
            var scline          = gx.ScanlinePacked8;
            int width           = (int)widgetsSubImage.Width;
            int height          = (int)widgetsSubImage.Height;

            //change value ***
            if (isMaskSliderValueChanged)
            {
                generate_alpha_mask(gx.ScanlineRasToDestBitmap, gx.ScanlinePacked8, gx.ScanlineRasterizer, width, height);
                this.isMaskSliderValueChanged = false;
            }
            var rasterizer = gx.ScanlineRasterizer;

            rasterizer.SetClipBox(0, 0, width, height);
            //alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1);

            PixelFarm.Agg.Imaging.AlphaMaskAdaptor imageAlphaMaskAdaptor = new PixelFarm.Agg.Imaging.AlphaMaskAdaptor(widgetsSubImage, alphaMask);
            ClipProxyImage alphaMaskClippingProxy = new ClipProxyImage(imageAlphaMaskAdaptor);
            ClipProxyImage clippingProxy          = new ClipProxyImage(widgetsSubImage);
            ////Affine transform = Affine.NewIdentity();
            ////transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            ////transform *= Affine.NewScaling(lionScale, lionScale);
            ////transform *= Affine.NewRotation(angle + Math.PI);
            ////transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            ////transform *= Affine.NewTranslation(Width / 2, Height / 2);
            Affine transform = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(lionScale, lionScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            clippingProxy.Clear(Drawing.Color.White);
            ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
            // draw a background to show how the mask is working better
            int rect_w = 30;
            var v1     = GetFreeVxs();

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0);
                        rect.NormalizeRadius();
                        // Drawing as an outline
                        rasterizer.AddPath(rect.MakeVxs(v1));
                        v1.Clear();
                        sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, scline, Drawing.Color.Make(.9f, .9f, .9f));
                    }
                }
            }
            ReleaseVxs(ref v1);
            ////int x, y;
            //// Render the lion
            ////VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);

            ////var vxlist = new System.Collections.Generic.List<VertexData>();
            ////trans.DoTransform(vxlist);

            var tmpVxs1 = new VertexStore();

            transform.TransformToVxs(lionShape.Path.Vxs, tmpVxs1);

            sclineRasToBmp.RenderSolidAllPaths(alphaMaskClippingProxy,
                                               rasterizer,
                                               scline,
                                               tmpVxs1,
                                               lionShape.Colors,
                                               lionShape.PathIndexList,
                                               lionShape.NumPaths);
            ///*
            //// Render random Bresenham lines and markers
            //agg::renderer_markers<amask_ren_type> m(r);
            //for(i = 0; i < 50; i++)
            //{
            //    m.line_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));
            //    m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));

            //    m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height),
            //           m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height));

            //    m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5,
            //             agg::marker_e(randGenerator.Next() % agg::end_of_markers));
            //}


            //// Render random anti-aliased lines
            //double w = 5.0;
            //agg::line_profile_aa profile;
            //profile.width(w);

            //typedef agg::renderer_outline_aa<amask_ren_type> renderer_type;
            //renderer_type ren(r, profile);

            //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
            //rasterizer_type ras(ren);
            //ras.round_cap(true);

            //for(i = 0; i < 50; i++)
            //{
            //    ren.Color = agg::rgba8(randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         //255));
            //                         (randGenerator.Next() & 0x7F) + 0x7F);
            //    ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.render(false);
            //}


            //// Render random circles with gradient
            //typedef agg::gradient_linear_color<color_type> grad_color;
            //typedef agg::gradient_circle grad_func;
            //typedef agg::span_interpolator_linear<> interpolator_type;
            //typedef agg::span_gradient<color_type,
            //                          interpolator_type,
            //                          grad_func,
            //                          grad_color> span_grad_type;

            //agg::trans_affine grm;
            //grad_func grf;
            //grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0));
            //agg::ellipse ell;
            //agg::span_allocator<color_type> sa;
            //interpolator_type inter(grm);
            //span_grad_type sg(inter, grf, grc, 0, 10);
            //agg::renderer_scanline_aa<amask_ren_type,
            //                          agg::span_allocator<color_type>,
            //                          span_grad_type> rg(r, sa, sg);
            //for(i = 0; i < 50; i++)
            //{
            //    x = randGenerator.Next() % width;
            //    y = randGenerator.Next() % height;
            //    double r = randGenerator.Next() % 10 + 5;
            //    grm.reset();
            //    grm *= agg::trans_affine_scaling(r / 10.0);
            //    grm *= agg::trans_affine_translation(x, y);
            //    grm.invert();
            //    grc.colors(agg::rgba8(255, 255, 255, 0),
            //               agg::rgba8(randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          255));
            //    sg.color_function(grc);
            //    ell.init(x, y, r, r, 32);
            //    g_rasterizer.add_path(ell);
            //    agg::render_scanlines(g_rasterizer, g_scanline, rg);
            //}
            // */
            ////m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy);
        }
 public override void Init()
 {
     //actualImage2 = LoadImage(RootDemoPath.Path + "\\plain01.png");
     actualImage = LoadImage(RootDemoPath.Path + "\\02.jpg");
     affinePlans = new AffinePlan[] { AffinePlan.Translate(50, 50) };
 }
Пример #22
0
        public override void Render(PixelFarm.Drawing.Painter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-_spriteShape.Center.x, -_spriteShape.Center.y),
                AffinePlan.Scale(_spriteScale, _spriteScale),
                AffinePlan.Rotate(_angle + Math.PI),
                AffinePlan.Skew(_skewX / 1000.0, _skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggPainter;

            if (p1 == null)
            {
                //TODO: review here
                _spriteShape.Paint(p, affTx);
                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //var vxs = GetFreeVxs();
                //affTx.TransformToVxs(lionShape.Vxs, vxs);
                //p.StrokeWidth = 1;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.StrokeColor = colors[i];
                //    p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i]));

                //}
                ////not agg
                //Release(ref vxs);
                //return; //**
            }


            if (UseBitmapExt)
            {
                p.RenderQuality = Drawing.RenderQuality.Fast;
                p.Clear(Drawing.Color.White);
                p.StrokeWidth = 1;

                //-------------------------
                _spriteShape.DrawOutline(p);
            }
            else
            {
                p.RenderQuality = Drawing.RenderQuality.HighQuality;
            }


            //-----------------------
            AggRenderSurface aggsx = p1.RenderSurface;
            //-----------------------
            //TODO: make this reusable ...
            //
            SubBitmapBlender widgetsSubImage    = BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect());
            SubBitmapBlender clippedSubImage    = new SubBitmapBlender(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage   imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);

            AggPainter aggPainter = (AggPainter)p;

            if (RenderAsScanline)
            {
                //a low-level example, expose scanline rasterizer

                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);

                //lionShape.ApplyTransform(affTx);
                //---------------------

                using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                {
                    paintArgs._currentTx        = affTx;
                    paintArgs.PaintVisitHandler = (vxs, painterA) =>
                    {
                        //use external painter handler
                        //draw only outline with its fill-color.
                        rasterizer.Reset();
                        rasterizer.AddPath(vxs);
                        aggsx.BitmapRasterizer.RenderWithColor(
                            imageClippingProxy, rasterizer,
                            aggsx.ScanlinePacked8,
                            aggPainter.FillColor); //draw line with external drawing handler
                    };

                    _spriteShape.Paint(paintArgs);
                }

                //----------------------------
                //lionShape.ResetTransform();
            }
            else
            {
                if (UseBuiltInAggOutlineAATech)
                {
                    aggPainter.StrokeWidth       = 1;
                    aggPainter.LineRenderingTech = AggPainter.LineRenderingTechnique.OutlineAARenderer;

                    //------
                    using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                    {
                        paintArgs._currentTx        = affTx;
                        paintArgs.PaintVisitHandler = (vxs, painterA) =>
                        {
                            //use external painter handler
                            //draw only outline with its fill-color.
                            Drawing.Painter m_painter       = paintArgs.P;
                            Drawing.Color   prevStrokeColor = m_painter.StrokeColor;
                            m_painter.StrokeColor = m_painter.FillColor;
                            m_painter.Draw(vxs);
                            m_painter.StrokeColor = prevStrokeColor;
                        };
                        _spriteShape.Paint(paintArgs);
                    }
                }
                else
                {
                    //low-level implementation
                    aggPainter.StrokeWidth = 1;

                    //-------------------------
                    //Draw with LineProfile:
                    //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone()); //with gamma

                    LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null);
                    OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                    outlineRenderer.SetClipBox(0, 0, this.Width, this.Height);

                    OutlineAARasterizer rasterizer = new OutlineAARasterizer(outlineRenderer);
                    rasterizer.LineJoin = (RenderAccurateJoins ?
                                           OutlineAARasterizer.OutlineJoin.AccurateJoin
                        : OutlineAARasterizer.OutlineJoin.Round);
                    rasterizer.RoundCap = true;

                    //lionShape.ApplyTransform(affTx);
                    //----------------------------
                    using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                    {
                        paintArgs._currentTx        = affTx;
                        paintArgs.PaintVisitHandler = (vxs, painterA) =>
                        {
                            //use external painter handler
                            //draw only outline with its fill-color.
                            rasterizer.RenderVertexSnap(
                                vxs,
                                painterA.P.FillColor);
                        };

                        _spriteShape.Paint(paintArgs);
                    }

                    //----------------------------
                    //lionShape.ResetTransform();
                }
            }
        }
Пример #23
0
        VgVisualElement CreatePolyline(VgVisualElement parentNode, SvgPolylineSpec polylineSpec)
        {
            VgVisualElement vgPolyline = new VgVisualElement(WellknownSvgElementName.Polyline, polylineSpec, _vgVisualDoc);

            PointF[] points = polylineSpec.Points;
            int      j      = points.Length;

            if (j > 1)
            {
                using (VxsTemp.Borrow(out var v1))
                {
                    PointF p = points[0];
                    v1.AddMoveTo(p.X, p.Y);
                    for (int i = 1; i < j; ++i)
                    {
                        p = points[i];
                        v1.AddLineTo(p.X, p.Y);
                    }
                    vgPolyline.VxsPath = v1.CreateTrim();
                }
                AssignAttributes(polylineSpec);

                //--------------------------------------------------------------------
                ResolveMarkers(vgPolyline, polylineSpec);
                if (vgPolyline._pathMarkers != null)
                {
                    //create primary instance plan for this polyline
                    VgPathVisualMarkers pathMarkers = vgPolyline._pathMarkers;
                    pathMarkers.AllPoints = points;

                    //start, mid, end
                    if (pathMarkers.StartMarker != null)
                    {
                        //turn marker to the start direction
                        PointF p0 = points[0];
                        PointF p1 = points[1];
                        //find rotation angle
                        double        rotateRad  = Math.Atan2(p0.Y - p1.Y, p0.X - p1.X);
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.StartMarker._visualSpec;

                        //create local-transformation matrix
                        pathMarkers.StartMarkerPos    = new PointF(p0.X, p0.Y);
                        pathMarkers.StartMarkerAffine = Affine.NewMatix(
                            AffinePlan.Translate(-markerSpec.RefX.Number, -markerSpec.RefY.Number), //move to the ref point
                            AffinePlan.Rotate(rotateRad)                                            //rotate
                            );
                    }
                    //-------------------------------
                    if (pathMarkers.MidMarker != null)
                    {
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.StartMarker._visualSpec;
                        pathMarkers.MidMarkerAffine = Affine.NewTranslation(-markerSpec.RefX.Number, -markerSpec.RefY.Number);
                    }
                    //-------------------------------
                    if (pathMarkers.EndMarker != null)
                    {
                        //turn marker to the start direction
                        PointF p0 = points[j - 2]; //before the last one
                        PointF p1 = points[j - 1]; //the last one
                                                   //find rotation angle
                        double        rotateRad  = Math.Atan2(p1.Y - p0.Y, p1.X - p0.X);
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.EndMarker._visualSpec;


                        //create local-transformation matrix
                        pathMarkers.EndMarkerPos    = new PointF(p1.X, p1.Y);
                        pathMarkers.EndMarkerAffine = Affine.NewMatix(
                            AffinePlan.Translate(-markerSpec.RefX.Number, -markerSpec.RefY.Number), //move to the ref point
                            AffinePlan.Rotate(rotateRad)                                            //rotate
                            );
                    }
                }
            }
            return(vgPolyline);
        }
Пример #24
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            //freeze to bitmap ?

            if (vxStorage == null)
            {
                var transform = Affine.NewMatix(
                    AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                    AffinePlan.Scale(spriteScale, spriteScale),
                    AffinePlan.Rotate(angle + Math.PI),
                    AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                    AffinePlan.Translate(Width / 2, Height / 2)
                    );

                //convert
                //System.Collections.Generic.List<VertexData> list = new System.Collections.Generic.List<VertexData>();
                vxStorage = transform.TransformToVxs(lionShape.Path.Vxs);
                //transformedPathStorage = new VertexSourceApplyTransform(lionShape.Path, transform);
                //transformedPathStorage.DoTransform(list);

                //vxStorage = new VertexStorage(list);
            }

            //-----------------------------------------------------------------------------------
            {
                int         j        = lionShape.NumPaths;
                int[]       pathList = lionShape.PathIndexList;
                ColorRGBA[] colors   = lionShape.Colors;
                for (int i = 0; i < j; ++i)
                {
                    graphics2D.Render(new VertexStoreSnap(vxStorage, pathList[i]), colors[i]);
                }
            }
            //-----------------------------------------------------------------------------------



            if (!IsFreezed)
            {
                //var destImage = graphics2D.DestImage;
                //var buffer = destImage.GetBuffer();
                //var w = destImage.Width;
                //var h = destImage.Height;

                ////snap to bmp
                //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h);
                //BitmapHelper.CopyToWindowsBitmap(buffer, 0,
                //    destImage.StrideInBytes(),
                //    destImage.Height,
                //    destImage.BitDepth,
                //    bmp, new RectangleInt(0, 0, w, h));

                //bmp.Save("d:\\WImageTest\\01.bmp");

                //this.Freeze();
                //var bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, w, h),
                //     System.Drawing.Imaging.ImageLockMode.ReadWrite,
                //     System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }
            base.OnDraw(graphics2D);
        }
Пример #25
0
        void render_gpc(Graphics2D graphics2D)
        {
            switch (this.PolygonSet)
            {
            case PolygonExampleSet.TwoSimplePaths:
            {
                //------------------------------------
                // Two simple paths
                //
                PathWriter ps1 = new PathWriter();
                PathWriter ps2 = new PathWriter();

                double x = m_x - Width / 2 + 100;
                double y = m_y - Height / 2 + 100;
                ps1.MoveTo(x + 140, y + 145);
                ps1.LineTo(x + 225, y + 44);
                ps1.LineTo(x + 296, y + 219);
                ps1.CloseFigure();

                ps1.LineTo(x + 226, y + 289);
                ps1.LineTo(x + 82, y + 292);

                ps1.MoveTo(x + 220, y + 222);
                ps1.LineTo(x + 363, y + 249);
                ps1.LineTo(x + 265, y + 331);

                ps1.MoveTo(x + 242, y + 243);
                ps1.LineTo(x + 268, y + 309);
                ps1.LineTo(x + 325, y + 261);

                ps1.MoveTo(x + 259, y + 259);
                ps1.LineTo(x + 273, y + 288);
                ps1.LineTo(x + 298, y + 266);

                ps2.MoveTo(100 + 32, 100 + 77);
                ps2.LineTo(100 + 473, 100 + 263);
                ps2.LineTo(100 + 351, 100 + 290);
                ps2.LineTo(100 + 354, 100 + 374);

                graphics2D.Render(ps1.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f));
                graphics2D.Render(ps2.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f));

                CreateAndRenderCombined(graphics2D, ps1.MakeVertexSnap(), ps2.MakeVertexSnap());
            }
            break;

            case PolygonExampleSet.CloseStroke:
            {
                //------------------------------------
                // Closed stroke
                //
                PathWriter ps1    = new PathWriter();
                PathWriter ps2    = new PathWriter();
                Stroke     stroke = new Stroke(1);

                stroke.Width = 10;
                double x = m_x - Width / 2 + 100;
                double y = m_y - Height / 2 + 100;

                //-----------------------------------------
                ps1.MoveTo(x + 140, y + 145);
                ps1.LineTo(x + 225, y + 44);
                ps1.LineTo(x + 296, y + 219);
                ps1.CloseFigure();

                ps1.LineTo(x + 226, y + 289);
                ps1.LineTo(x + 82, y + 292);

                ps1.MoveTo(x + 220 - 50, y + 222);
                ps1.LineTo(x + 265 - 50, y + 331);
                ps1.LineTo(x + 363 - 50, y + 249);
                ps1.CloseFigureCCW();
                //-----------------------------------------


                ps2.MoveTo(100 + 32, 100 + 77);
                ps2.LineTo(100 + 473, 100 + 263);
                ps2.LineTo(100 + 351, 100 + 290);
                ps2.LineTo(100 + 354, 100 + 374);
                ps2.CloseFigure();

                graphics2D.Render(ps1.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f));


                var vxs = ps2.Vxs;
                graphics2D.Render(stroke.MakeVxs(vxs), ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f));
                CreateAndRenderCombined(graphics2D, ps1.MakeVertexSnap(), new VertexStoreSnap(vxs));
            }
            break;


            case PolygonExampleSet.GBAndArrow:
            {
                //------------------------------------
                // Great Britain and Arrows
                //
                PathWriter gb_poly = new PathWriter();
                PathWriter arrows  = new PathWriter();
                PixelFarm.Agg.Sample_PolygonClipping.GreatBritanPathStorage.Make(gb_poly);

                make_arrows(arrows);

                //Affine mtx1 = Affine.NewIdentity();
                //mtx1 *= Affine.NewTranslation(-1150, -1150);
                //mtx1 *= Affine.NewScaling(2.0);
                Affine mtx1 = Affine.NewMatix(
                    AffinePlan.Translate(-1150, -1150),
                    AffinePlan.Scale(2)
                    );



                //Affine.NewIdentity();
                //mtx2 = mtx1;
                //mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2);
                Affine mtx2 = mtx1 * Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2);

                //VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);
                //VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx2);
                var trans_gb_poly = mtx1.TransformToVxs(gb_poly.Vxs);
                var trans_arrows  = mtx2.TransformToVxs(arrows.Vxs);

                graphics2D.Render(trans_gb_poly, ColorRGBAf.MakeColorRGBA(0.5f, 0.5f, 0f, 0.1f));

                //stroke_gb_poly.Width = 0.1;
                graphics2D.Render(new Stroke(0.1).MakeVxs(trans_gb_poly), ColorRGBAf.MakeColorRGBA(0, 0, 0));
                graphics2D.Render(trans_arrows, ColorRGBAf.MakeColorRGBA(0f, 0.5f, 0.5f, 0.1f));

                CreateAndRenderCombined(graphics2D, new VertexStoreSnap(trans_gb_poly), new VertexStoreSnap(trans_arrows));
            }
            break;

            case PolygonExampleSet.GBAndSpiral:
            {
                //------------------------------------
                // Great Britain and a Spiral
                //
                spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0);


                PathWriter gb_poly = new PathWriter();
                PixelFarm.Agg.Sample_PolygonClipping.GreatBritanPathStorage.Make(gb_poly);

                Affine mtx = Affine.NewMatix(
                    AffinePlan.Translate(-1150, -1150),
                    AffinePlan.Scale(2));


                VertexStore s1 = mtx.TransformToVxs(gb_poly.Vxs);
                graphics2D.Render(s1, ColorRGBAf.MakeColorRGBA(0.5f, 0.5f, 0f, 0.1f));
                graphics2D.Render(new Stroke(0.1).MakeVxs(s1), ColorRGBA.Black);
                var stroke_vxs = new Stroke(15).MakeVxs(sp.MakeVxs());
                graphics2D.Render(stroke_vxs, ColorRGBAf.MakeColorRGBA(0.0f, 0.5f, 0.5f, 0.1f));

                CreateAndRenderCombined(graphics2D, new VertexStoreSnap(s1), new VertexStoreSnap(stroke_vxs));
            }
            break;

            case PolygonExampleSet.SprialAndGlyph:
            {
                //------------------------------------
                // Spiral and glyph
                //
                spiral sp     = new spiral(m_x, m_y, 10, 150, 30, 0.0);
                Stroke stroke = new Stroke(15);


                PathWriter glyph = new PathWriter();
                glyph.MoveTo(28.47, 6.45);
                glyph.Curve3(21.58, 1.12, 19.82, 0.29);
                glyph.Curve3(17.19, -0.93, 14.21, -0.93);
                glyph.Curve3(9.57, -0.93, 6.57, 2.25);
                glyph.Curve3(3.56, 5.42, 3.56, 10.60);
                glyph.Curve3(3.56, 13.87, 5.03, 16.26);
                glyph.Curve3(7.03, 19.58, 11.99, 22.51);
                glyph.Curve3(16.94, 25.44, 28.47, 29.64);
                glyph.LineTo(28.47, 31.40);
                glyph.Curve3(28.47, 38.09, 26.34, 40.58);
                glyph.Curve3(24.22, 43.07, 20.17, 43.07);
                glyph.Curve3(17.09, 43.07, 15.28, 41.41);
                glyph.Curve3(13.43, 39.75, 13.43, 37.60);
                glyph.LineTo(13.53, 34.77);
                glyph.Curve3(13.53, 32.52, 12.38, 31.30);
                glyph.Curve3(11.23, 30.08, 9.38, 30.08);
                glyph.Curve3(7.57, 30.08, 6.42, 31.35);
                glyph.Curve3(5.27, 32.62, 5.27, 34.81);
                glyph.Curve3(5.27, 39.01, 9.57, 42.53);
                glyph.Curve3(13.87, 46.04, 21.63, 46.04);
                glyph.Curve3(27.59, 46.04, 31.40, 44.04);
                glyph.Curve3(34.28, 42.53, 35.64, 39.31);
                glyph.Curve3(36.52, 37.21, 36.52, 30.71);
                glyph.LineTo(36.52, 15.53);
                glyph.Curve3(36.52, 9.13, 36.77, 7.69);
                glyph.Curve3(37.01, 6.25, 37.57, 5.76);
                glyph.Curve3(38.13, 5.27, 38.87, 5.27);
                glyph.Curve3(39.65, 5.27, 40.23, 5.62);
                glyph.Curve3(41.26, 6.25, 44.19, 9.18);
                glyph.LineTo(44.19, 6.45);
                glyph.Curve3(38.72, -0.88, 33.74, -0.88);
                glyph.Curve3(31.35, -0.88, 29.93, 0.78);
                glyph.Curve3(28.52, 2.44, 28.47, 6.45);
                glyph.CloseFigure();

                glyph.MoveTo(28.47, 9.62);
                glyph.LineTo(28.47, 26.66);
                glyph.Curve3(21.09, 23.73, 18.95, 22.51);
                glyph.Curve3(15.09, 20.36, 13.43, 18.02);
                glyph.Curve3(11.77, 15.67, 11.77, 12.89);
                glyph.Curve3(11.77, 9.38, 13.87, 7.06);
                glyph.Curve3(15.97, 4.74, 18.70, 4.74);
                glyph.Curve3(22.41, 4.74, 28.47, 9.62);
                glyph.CloseFigure();

                //Affine mtx = Affine.NewIdentity();
                //mtx *= Affine.NewScaling(4.0);
                //mtx *= Affine.NewTranslation(220, 200);
                Affine mtx = Affine.NewMatix(
                    AffinePlan.Scale(4),
                    AffinePlan.Translate(220, 200));

                var t_glyph = mtx.TransformToVertexSnap(glyph.Vxs);

                CurveFlattener curveFlattener = new CurveFlattener();

                var sp1 = stroke.MakeVxs(sp.MakeVxs());

                var curveVxs = curveFlattener.MakeVxs(t_glyph);

                CreateAndRenderCombined(graphics2D, new VertexStoreSnap(sp1), new VertexStoreSnap(curveVxs));

                graphics2D.Render(stroke.MakeVxs(sp1), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f));

                graphics2D.Render(curveVxs, ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f));
            }
            break;
            }
        }
Пример #26
0
        public override void Draw(Painter p)
        {
            if (UseBitmapExt)
            {
                p.RenderQuality = RenderQualtity.Fast;
            }
            else
            {
                p.RenderQuality = RenderQualtity.HighQuality;
            }



            p.Clear(Drawing.Color.White);

            p.UseSubPixelLcdEffect = false;
            //string teststr = "ABCDE pqyt 1230";
            //p.FillColor = Color.Black;
            //p.CurrentFont = new RequestFont("tahoma", 10);
            //p.StrokeColor = Color.Red;

            p.RenderQuality = RenderQualtity.Fast;
            //
            //---red reference line--
            p.DrawLine(0, 400, 800, 400);
            p.DrawLine(0, 400, 800, 500); //test oblique line

            //p.DrawString(teststr, 300, 400);
            //
            p.DrawRect(0.5, 400, 40, 40);
            //

            p.FillColor   = Color.Yellow;
            p.StrokeColor = Color.Blue;

            p.FillEllipse(100.5, 400, 40, 60);
            p.DrawEllipse(50.5, 400, 40, 60);

            //---red reference line--
            p.StrokeColor = Color.Red;
            p.DrawLine(0, 500, 800, 500);

            p.StrokeColor = Color.Blue;
            p.FillColor   = Color.Yellow;
            p.FillRect(0.5, 500, 40, 40);
            //---red reference line--


            //p.DrawImage(lionImg, 0, 0); //reference at 0,0
            p.DrawImage(lionImg, 300, 0);

            int _imgW = lionImg.Width;
            int _imgH = lionImg.Height;

            p.RenderQuality = RenderQualtity.Fast;
            p.DrawImage(lionImg,
                        //move to center of the image (hotspot x,y)
                        AffinePlan.Translate(-_imgW / 2, -_imgH / 2),
                        AffinePlan.Rotate(AggMath.deg2rad(45)),
                        AffinePlan.Scale(0.75, 0.75),
                        //move to target
                        AffinePlan.Translate(400, 200));
        }
Пример #27
0
        public override void Draw(Painter p)
        {
            if (UseBitmapExt)
            {
                p.RenderQuality = RenderQualtity.Fast;
            }
            else
            {
                p.RenderQuality = RenderQualtity.HighQuality;
            }



            int width  = 800;
            int height = 600;

            //clear the image to white
            // draw a circle
            p.Clear(Drawing.Color.White);
            Ellipse ellipseVxsGen = new Ellipse(0, 0, 100, 50);

            for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
            {
                var mat = Affine.NewMatix(
                    AffinePlan.Rotate(MathHelper.DegreesToRadians(angleDegrees)),
                    AffinePlan.Translate(width / 2, 150));


                VectorToolBox.GetFreeVxs(out var v1, out var v2, out var v3);
                mat.TransformToVxs(ellipseVxsGen.MakeVxs(v1), v2);

                p.FillColor = Drawing.Color.Yellow;
                p.Fill(v2);
                //------------------------------------
                //g.Render(sp1, ColorRGBA.Yellow);
                //Stroke ellipseOutline = new Stroke(sp1, 3);
                p.FillColor  = Drawing.Color.Blue;
                stroke.Width = 3;
                p.Fill(stroke.MakeVxs(v2, v3));
                //g.Render(StrokeHelp.MakeVxs(sp1, 3), ColorRGBA.Blue);
                VectorToolBox.ReleaseVxs(ref v1, ref v2, ref v3);
            }

            // and a little polygon
            PathWriter littlePoly = new PathWriter();

            littlePoly.MoveTo(50, 50);
            littlePoly.LineTo(150, 50);
            littlePoly.LineTo(200, 200);
            littlePoly.LineTo(50, 150);
            littlePoly.LineTo(50, 50);
            p.FillColor = Drawing.Color.Blue;
            p.Fill(littlePoly.MakeVertexSnap());


            //----
            //test draw img



            //
            //g.Render(littlePoly.MakeVertexSnap(), ColorRGBA.Cyan);
            // draw some text
            // draw some text

            //var textPrinter = new TextPrinter();
            //textPrinter.CurrentActualFont = svgFontStore.LoadFont(SvgFontStore.DEFAULT_SVG_FONTNAME, 30);
            //new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);

            //VertexStore vxs = textPrinter.CreateVxs("Printing from a printer".ToCharArray());
            //var affTx = Affine.NewTranslation(width / 2, height / 4 * 3);
            //VertexStore s1 = affTx.TransformToVxs(vxs);
            //p.FillColor = Drawing.Color.Black;
            //p.Fill(s1);
            ////g.Render(s1, ColorRGBA.Black);
            //p.FillColor = Drawing.Color.Red;
            //p.Fill(StrokeHelp.MakeVxs(s1, 1));
            ////g.Render(StrokeHelp.MakeVxs(s1, 1), ColorRGBA.Red);
            //var aff2 = Affine.NewMatix(
            //    AffinePlan.Rotate(MathHelper.DegreesToRadians(90)),
            //    AffinePlan.Translate(40, height / 2));
            //p.FillColor = Drawing.Color.Black;
            //p.Fill(aff2.TransformToVertexSnap(vxs));
            ////g.Render(aff2.TransformToVertexSnap(vxs), ColorRGBA.Black);
        }
Пример #28
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            //render
            var            widgetsSubImage    = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            int            width              = widgetsSubImage.Width;
            int            height             = widgetsSubImage.Height;
            int            strokeWidth        = 1;
            var            clippedSubImage    = new ChildImage(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(ColorRGBA.White);
            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(spriteScale, spriteScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            //transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            //transform *= Affine.NewScaling(spriteScale, spriteScale);
            //transform *= Affine.NewRotation(angle + Math.PI);
            //transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            //transform *= Affine.NewTranslation(width / 2, height / 2);


            if (RenderAsScanline)
            {
                var rasterizer = graphics2D.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                Stroke stroke = new Stroke(strokeWidth);
                stroke.LineJoin = LineJoin.Round;
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderSolidAllPaths(
                    imageClippingProxy,
                    rasterizer,
                    graphics2D.ScanlinePacked8,
                    vxs,
                    lionShape.Colors,
                    lionShape.PathIndexList,
                    lionShape.NumPaths);
            }
            else
            {
                double w = strokeWidth * affTx.GetScale();
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(w, new GammaNone());
                OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                OutlineAARasterizer  rasterizer      = new OutlineAARasterizer(outlineRenderer);
                rasterizer.LineJoin = (RenderAccurateJoins ?
                                       OutlineAARasterizer.OutlineJoin.AccurateJoin
                    : OutlineAARasterizer.OutlineJoin.Round);
                rasterizer.RoundCap = true;
                //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);// trans.DoTransformToNewVxStorage();
                int j   = lionShape.NumPaths;
                for (int i = 0; i < j; ++i)
                {
                    rasterizer.RenderVertexSnap(
                        new VertexStoreSnap(vxs,
                                            lionShape.PathIndexList[i]),
                        lionShape.Colors[i]);
                }
            }

            base.OnDraw(graphics2D);
        }
Пример #29
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(spriteScale, spriteScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggPainter;

            if (p1 == null)
            {
                //TODO: review here

                lionShape.Paint(p, affTx);
                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //var vxs = GetFreeVxs();
                //affTx.TransformToVxs(lionShape.Vxs, vxs);
                //p.StrokeWidth = 1;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.StrokeColor = colors[i];
                //    p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i]));

                //}
                ////not agg
                //Release(ref vxs);
                //return; //**
            }


            if (UseBitmapExt)
            {
                p.RenderQuality = Drawing.RenderQualtity.Fast;
                p.Clear(Drawing.Color.White);
                p.StrokeWidth = 1;

                //-------------------------
                lionShape.DrawOutline(p);
            }
            else
            {
                p.RenderQuality = Drawing.RenderQualtity.HighQuality;
            }



            //-----------------------
            AggRenderSurface aggsx = p1.RenderSurface;
            //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            //int width = widgetsSubImage.Width;
            //int height = widgetsSubImage.Height;

            SubImageRW     widgetsSubImage    = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());
            SubImageRW     clippedSubImage    = new SubImageRW(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);


            if (RenderAsScanline)
            {
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                //Stroke stroke = new Stroke(strokeWidth);
                //stroke.LineJoin = LineJoin.Round;
                lionShape.ApplyTransform(affTx);


                DrawAsScanline(imageClippingProxy, aggsx, rasterizer, aggsx.ScanlineRasToDestBitmap);



                lionShape.ResetTransform();
            }
            else
            {
                //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone());
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null);
                OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                OutlineAARasterizer  rasterizer      = new OutlineAARasterizer(outlineRenderer);
                rasterizer.LineJoin = (RenderAccurateJoins ?
                                       OutlineAARasterizer.OutlineJoin.AccurateJoin
                    : OutlineAARasterizer.OutlineJoin.Round);
                rasterizer.RoundCap = true;

                SvgRenderVx renderVx = lionShape.GetRenderVx();

                lionShape.ApplyTransform(affTx);

                DrawWithLineProfile(rasterizer);

                lionShape.ResetTransform();
            }
            base.Draw(p);
        }
Пример #30
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            if (recreatePathAgain)
            {
                recreatePathAgain = false;

                var transform = Affine.NewMatix(
                    AffinePlan.Translate(-_spriteShape.Center.x, -_spriteShape.Center.y),
                    AffinePlan.Scale(spriteScale, spriteScale),
                    AffinePlan.Rotate(angle + Math.PI),
                    AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                    AffinePlan.Translate(Width / 2, Height / 2)
                    );
                //create vertextStore again from original path


                //temp fix
                SvgRenderVx renderVx = _spriteShape.GetRenderVx();
                int         count    = renderVx.SvgVxCount;
                for (int i = 0; i < count; ++i)
                {
                    SvgPart vx = renderVx.GetInnerVx(i);
                    if (vx.Kind != SvgRenderVxKind.Path)
                    {
                        continue;
                    }
                    //Temp fix,
                    //TODO: review here,
                    //permanent transform each part?
                    //or create a copy.
                    vx.RestoreOrg();
                    VertexStore vxvxs  = vx.GetVxs();
                    VertexStore newVxs = new VertexStore();
                    transform.TransformToVxs(vxvxs, newVxs);
                    vx.SetVxs(newVxs);
                }
                _spriteShape.UpdateBounds();

                //if (AutoFlipY)
                //{
                //    //flip the lion
                //    PixelFarm.Agg.Transform.Affine aff = PixelFarm.Agg.Transform.Affine.NewMatix(
                //      PixelFarm.Agg.Transform.AffinePlan.Scale(-1, -1),
                //      PixelFarm.Agg.Transform.AffinePlan.Translate(0, 600));
                //    //
                //    var v2 = new VertexStore();
                //    myvxs = transform.TransformToVxs(myvxs, v2);
                //}
            }
            //---------------------------------------------------------------------------------------------
            {
                float ox = p.OriginX;
                float oy = p.OriginY;
                p.SetOrigin(ox + _posX, oy + _posY);
                _spriteShape.Paint(p);
                //#if DEBUG
                //                RectD bounds = lionShape.Bounds;
                //                bounds.Offset(_posX, _posY);
                //                //draw lion bounds
                //                var savedStrokeColor = p.StrokeColor;
                //                var savedFillColor = p.FillColor;
                //                var savedSmoothMode = p.SmoothingMode;

                //                p.SmoothingMode = SmoothingMode.HighSpeed;
                //                p.StrokeColor = Color.Black;
                //                p.DrawRect(bounds.Left, bounds.Top - bounds.Height, bounds.Width, bounds.Height);

                //                p.StrokeColor = Color.Red;
                //                p.DrawRect(_mouseDownX, _mouseDownY, 4, 4);


                //                //restore
                //                p.SmoothingMode = savedSmoothMode;
                //                p.StrokeColor = savedStrokeColor;
                //                p.FillColor = savedFillColor;


                //#endif

                p.SetOrigin(ox, oy);


                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.FillColor = colors[i];
                //    p.Fill(new VertexStoreSnap(myvxs, pathList[i]));
                //}
            }
            //test
            if (SharpenRadius > 0)
            {
                //p.DoFilter(new RectInt(0, p.Height, p.Width, 0), 2);
                //PixelFarm.Agg.Imaging.SharpenFilterARGB.Sharpen()
            }
        }