Exemplo n.º 1
0
        void CreateAndRenderCombined(Graphics2D graphics2D, VertexStoreSnap ps1, VertexStoreSnap ps2)
        {
            PathWriter combined = null;

            switch (this.OpOption)
            {
            case OperationOption.OR:
                combined = CombinePaths(ps1, ps2, ClipType.ctUnion);
                break;

            case OperationOption.AND:
                combined = CombinePaths(ps1, ps2, ClipType.ctIntersection);
                break;

            case OperationOption.XOR:
                combined = CombinePaths(ps1, ps2, ClipType.ctXor);
                break;

            case OperationOption.A_B:
                combined = CombinePaths(ps1, ps2, ClipType.ctDifference);
                break;

            case OperationOption.B_A:
                combined = CombinePaths(ps2, ps1, ClipType.ctDifference);
                break;
            }

            if (combined != null)
            {
                graphics2D.Render(combined.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0.5f, 0.0f, 0f, 0.5f));
            }
        }
Exemplo n.º 2
0
        void DrawC(PixelFarm.Agg.AggPainter aggPainter)
        {
            aggPainter.Clear(PixelFarm.Drawing.Color.White);
            //--------------------------
            aggPainter.StrokeColor = PixelFarm.Drawing.Color.Black;
            aggPainter.StrokeWidth = 2.0f;

            if (lineDashGen == null)
            {
                //create line dash gen
                lineDashGen = new LineDashGenerator();
                lineDashGen.SetDashPattern(4, 2, 2, 2);
            }

            aggPainter.LineDashGen = lineDashGen;
            //
            VertexStore vxs    = new VertexStore();
            PathWriter  writer = new PathWriter(vxs);

            writer.MoveTo(20, 10);
            writer.LineTo(60, 10);
            writer.LineTo(20, 200);
            writer.LineTo(20, 0);



            //writer.MoveTo(20, 100);
            //writer.LineTo(20, 15);
            //writer.CloseFigure();

            aggPainter.Draw(vxs);
            aggPainter.LineDashGen = null;
        }
Exemplo n.º 3
0
        public void WriteSubElements(XmlWriter writer, Group group)
        {
            foreach (Element child in group.Children)
            {
                switch (child)
                {
                case var _ when child is Keyboard:
                    throw new InvalidDataException("Keyboard is not a valid child type.");

                case Key key when child is Key:
                    var keyWriter = new KeyWriter {
                        GenerationOptions = GenerationOptions
                    };
                    keyWriter.Write(writer, key);
                    break;

                case Spacer spacer when child is Spacer:
                    var spacerWriter = new SpacerWriter {
                        GenerationOptions = GenerationOptions
                    };
                    spacerWriter.Write(writer, spacer);
                    break;

                case Stack stack when child is Stack:
                    var stackWriter = new StackWriter {
                        GenerationOptions = GenerationOptions
                    };
                    stackWriter.Write(writer, stack);
                    break;

                case Models.Path.Path path when child is Models.Path.Path:
                    var pathWriter = new PathWriter {
                        GenerationOptions = GenerationOptions
                    };
                    pathWriter.Write(writer, path);
                    break;

                case Circle circle when child is Circle:
                    var holeWriter = new CircleWriter {
                        GenerationOptions = GenerationOptions
                    };
                    holeWriter.Write(writer, circle);
                    break;

                case Text text when child is Text:
                    var textWriter = new TextWriter {
                        GenerationOptions = GenerationOptions
                    };
                    textWriter.Write(writer, text);
                    break;

                case Group subGroup when child is Group:
                    Write(writer, subGroup);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        void DrawD(PixelFarm.Drawing.Painter painter)
        {
            PathWriter ps = new PathWriter();

            painter.Clear(PixelFarm.Drawing.Color.White);
            painter.StrokeColor = PixelFarm.Drawing.Color.Red;
            //p.Line(10, 10, 50, 10);
            //p.Line(50, 10, 50, 50);
            //p.Line(50, 50, 10, 50);
            //p.Line(50, 10, 10, 10);

            ps.Clear();
            ps.MoveTo(10, 10);
            ps.LineTo(50, 10);
            ps.LineTo(50, 50);
            ps.LineTo(10, 50);
            ps.CloseFigure();
            //
            //ps.MoveTo(15, 15);
            //ps.LineTo(15, 45);
            //ps.LineTo(45, 45);
            //ps.LineTo(45, 15);
            //ps.CloseFigure();
            //
            //p.Fill(ps.Vxs, PixelFarm.Drawing.Color.Black);
            painter.Draw(ps.Vxs, PixelFarm.Drawing.Color.Red);
        }
Exemplo n.º 6
0
 public void MakeVxs(PathWriter pathWriter)
 {
     pathWriter.MoveTo(_bounds.Left, _bounds.Bottom);
     pathWriter.LineTo(_bounds.Right, _bounds.Bottom);
     pathWriter.LineTo(_bounds.Right, _bounds.Top);
     pathWriter.LineTo(_bounds.Left, _bounds.Top);
     pathWriter.CloseFigure();
 }
Exemplo n.º 7
0
        private void WriteSwitchCutoutPath(XmlWriter writer, Key key)
        {
            var pathWriter = new PathWriter {
                GenerationOptions = GenerationOptions
            };

            pathWriter.Write(writer, _switchPath);
        }
Exemplo n.º 8
0
        static PathWriter CombinePaths(VertexStoreSnap a, VertexStoreSnap b, ClipType clipType)
        {
            List <List <IntPoint> > aPolys = CreatePolygons(a);
            List <List <IntPoint> > bPolys = CreatePolygons(b);

            Clipper clipper = new Clipper();

            clipper.AddPaths(aPolys, PolyType.ptSubject, true);
            clipper.AddPaths(bPolys, PolyType.ptClip, true);

            List <List <IntPoint> > intersectedPolys = new List <List <IntPoint> >();

            clipper.Execute(clipType, intersectedPolys);

            PathWriter output = new PathWriter();

            foreach (List <IntPoint> polygon in intersectedPolys)
            {
                bool first = true;
                int  j     = polygon.Count;

                if (j > 0)
                {
                    //first one
                    IntPoint point = polygon[0];

                    output.MoveTo(point.X / 1000.0, point.Y / 1000.0);

                    //next ...
                    if (j > 1)
                    {
                        for (int i = 1; i < j; ++i)
                        {
                            point = polygon[i];
                            output.LineTo(point.X / 1000.0, point.Y / 1000.0);
                        }
                    }
                }
                //foreach (IntPoint point in polygon)
                //{
                //    if (first)
                //    {
                //        output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo);
                //        first = false;
                //    }
                //    else
                //    {
                //        output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo);
                //    }
                //}

                output.CloseFigure();
            }


            output.Stop();
            return(output);
        }
Exemplo n.º 9
0
        static public int LoadLionData(PathWriter path, Drawing.Color[] colors, int[] path_idx)
        {
            // Parse the lion and then detect its bounding
            // box and arrange polygons orientations (make all polygons
            // oriented clockwise or counterclockwise)

            int npaths = 0;

            string[] splitOnNL = g_lion.Split('\n');
            foreach (string line in splitOnNL)
            {
                int newColor;
                if (line.Length > 0 &&
                    line[0] != 'M' &&
                    Int32.TryParse(line, NumberStyles.HexNumber, null, out newColor))
                {
                    // New color. Every new color creates new path in the path object.
                    path.CloseFigure();
                    path.EndGroup();
                    colors[npaths]   = Drawing.Color.CreatRGB8Packed((int)newColor);
                    path_idx[npaths] = path.StartFigure();
                    npaths++;
                }
                else
                {
                    bool     startedPoly  = false;
                    string[] splitOnSpace = line.Split(' ');
                    for (int i = 0; i < splitOnSpace.Length; i++)
                    {
                        string[] splitOnComma = splitOnSpace[i].Split(',');
                        if (splitOnComma.Length > 1)
                        {
                            double x = 0.0;
                            double y = 0.0;
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                            if (!startedPoly)
                            {
                                startedPoly = true;
                                path.CloseFigure();
                                path.EndGroup();

                                path.MoveTo(x, y);
                            }
                            else
                            {
                                path.LineTo(x, y);
                            }
                        }
                    }
                }
            }

            //path.ArrangeOrientationsAll(ShapePath.FlagsAndCommand.FlagCW);

            VertexHelper.ArrangeOrientationsAll(path.Vxs, true);
            return(npaths);
        }
Exemplo n.º 10
0
        public static void WriteSmoothCurve4(this PathWriter pw, IVector2dProvider points, bool closedShape)
        {
            int coordCount = points.CoordCount;

            switch (coordCount)
            {
            case 0:
            case 1: return;

            case 2:
            {
                points.GetCoord(0, out double x, out double y);
                pw.MoveTo(x, y);
                points.GetCoord(1, out x, out y);
                pw.LineTo(x, y);
            }
            break;

            case 3:
            {
                points.GetCoord(0, out double x0, out double y0);
                points.GetCoord(1, out double x1, out double y1);
                points.GetCoord(2, out double x2, out double y2);
                pw.MoveTo(x0, y0);
                pw.Curve3(x1, y1, x2, y2);        //***, we have 3 points, so we use Curve3
                if (closedShape)
                {
                    pw.SmoothCurve3(x0, y0);
                }
            }
            break;

            default:
            {
                points.GetCoord(0, out double x0, out double y0);
                points.GetCoord(1, out double x1, out double y1);
                points.GetCoord(2, out double x2, out double y2);
                points.GetCoord(3, out double x3, out double y3);
                pw.MoveTo(x0, y0);
                pw.Curve4(x1, y1, x2, y2, x3, y3);

                for (int i = 4; i < coordCount - 1;)
                {
                    points.GetCoord(i, out x2, out y2);
                    points.GetCoord(i + 1, out x3, out y3);
                    pw.SmoothCurve4(x2, y2, x3, y3);
                    i += 2;
                }
                if (closedShape)
                {
                    pw.SmoothCurve4(x3, y3, x0, y0);
                }
            }
            break;
            }
        }
Exemplo n.º 11
0
        public override void Draw(Painter p)
        {
            //specific for agg

            if (p is PixelFarm.Agg.AggPainter)
            {
                var p2 = (PixelFarm.Agg.AggPainter)p;
                AggRenderSurface   aggsx      = p2.RenderSurface;
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;


                var widgetsSubImage = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());
                aggsx.UseSubPixelRendering = false;
                PixelBlenderBGRA normalBlender = new PixelBlenderBGRA();
                PixelBlenderBGRA gammaBlender  = new PixelBlenderBGRA(); //TODO: revisit, and fix this again
                gammaBlender.GammaValue  = this.GammaValue;
                gammaBlender.EnableGamma = true;
                var            rasterGamma         = new SubImageRW(widgetsSubImage, gammaBlender);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);

                ScanlineUnpacked8 sl = new ScanlineUnpacked8();
                int size_mul         = (int)this.PixelSize;
                CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, aggsx.DestActualImage);
                rasterizer.Reset();
                rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
                rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
                rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
                ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //----------------------------------------
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap;
                aggsx.UseSubPixelRendering = false;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                rasterizer.ResetGamma(new GammaNone());
                aggsx.UseSubPixelRendering = false;
                //----------------------------------------
                PathWriter ps = new PathWriter();
                ps.Clear();
                ps.MoveTo(m_x[0], m_y[0]);
                ps.LineTo(m_x[1], m_y[1]);
                ps.LineTo(m_x[2], m_y[2]);
                ps.LineTo(m_x[0], m_y[0]);
                //----------------------------------------
                //Stroke stroke = new Stroke(ps);
                //stroke.Width = 2;
                //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs()));

                VectorToolBox.GetFreeVxs(out var v1);
                rasterizer.AddPath(stroke.MakeVxs(ps.Vxs, v1));
                VectorToolBox.ReleaseVxs(ref v1);
                //----------------------------------------

                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
            }
        }
Exemplo n.º 12
0
 public VertexStore MakeVxs(VertexStore output)
 {
     PathWriter m_LinesToDraw = new PathWriter(output);
     m_LinesToDraw.Clear();
     m_LinesToDraw.MoveTo(bounds.Left, bounds.Bottom);
     m_LinesToDraw.LineTo(bounds.Right, bounds.Bottom);
     m_LinesToDraw.LineTo(bounds.Right, bounds.Top);
     m_LinesToDraw.LineTo(bounds.Left, bounds.Top);
     m_LinesToDraw.CloseFigure();
     return m_LinesToDraw.Vxs;
 }
Exemplo n.º 13
0
        public void OnDraw(Graphics2D graphics2D)
        {
            var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            graphics2D.UseSubPixelRendering = false;

            IPixelBlender NormalBlender = new PixelBlenderBGRA();
            IPixelBlender GammaBlender  = new PixelBlenderGammaBGRA(this.GammaValue);
            var           rasterGamma   = new ChildImage(widgetsSubImage, GammaBlender);


            ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
            ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);

            clippingProxyNormal.Clear(ColorRGBA.White);
            var rasterizer = graphics2D.ScanlineRasterizer;

            ScanlineUnpacked8 sl = new ScanlineUnpacked8();

            int size_mul = (int)this.PixelSize;

            CustomScanlineRasToBmp_EnlargedV3 ren_en = new CustomScanlineRasToBmp_EnlargedV3(size_mul, graphics2D.DestActualImage);

            rasterizer.Reset();
            rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
            rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
            rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
            ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);

            //----------------------------------------
            ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;

            graphics2D.UseSubPixelRendering = true;
            sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);
            rasterizer.ResetGamma(new GammaNone());
            graphics2D.UseSubPixelRendering = false;
            //----------------------------------------
            PathWriter ps = new PathWriter();

            ps.Clear();
            ps.MoveTo(m_x[0], m_y[0]);
            ps.LineTo(m_x[1], m_y[1]);
            ps.LineTo(m_x[2], m_y[2]);
            ps.LineTo(m_x[0], m_y[0]);
            //----------------------------------------
            //Stroke stroke = new Stroke(ps);
            //stroke.Width = 2;
            //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs()));
            rasterizer.AddPath(StrokeHelp.MakeVxs(ps.Vxs, 2));
            //----------------------------------------

            sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200));
        }
Exemplo n.º 14
0
        public VertexStore MakeVxs(VertexStore output)
        {
            PathWriter m_LinesToDraw = new PathWriter(output);

            m_LinesToDraw.Clear();
            m_LinesToDraw.MoveTo(bounds.Left, bounds.Bottom);
            m_LinesToDraw.LineTo(bounds.Right, bounds.Bottom);
            m_LinesToDraw.LineTo(bounds.Right, bounds.Top);
            m_LinesToDraw.LineTo(bounds.Left, bounds.Top);
            m_LinesToDraw.CloseFigure();
            return(m_LinesToDraw.Vxs);
        }
Exemplo n.º 15
0
 public static void UnsafeDirectSetData(SpriteShape lion,
                                        int numPaths,
                                        PathWriter pathStore,
                                        ColorRGBA[] colors,
                                        int[] pathIndice)
 {
     lion.path          = pathStore;
     lion.colors        = colors;
     lion.pathIndexList = pathIndice;
     lion.numPaths      = numPaths;
     lion.UpdateBoundingRect();
 }
Exemplo n.º 16
0
        //-----------------------------------------------------------------------------------------

        public static void WriteSmoothCurve3(this PathWriter pw, IVector2dProvider points, bool closedShape)
        {
            int coordCount = points.CoordCount;

            switch (coordCount)
            {
            case 0:
            case 1: return;

            case 2:
            {
                points.GetCoord(0, out double x, out double y);
                pw.MoveTo(x, y);
                points.GetCoord(1, out x, out y);
                pw.LineTo(x, y);
            }
            break;

            case 3:
            {
                points.GetCoord(0, out double x0, out double y0);
                points.GetCoord(1, out double x1, out double y1);
                points.GetCoord(2, out double x2, out double y2);
                pw.MoveTo(x0, y0);
                pw.Curve3(x1, y1, x2, y2);
                if (closedShape)
                {
                    pw.SmoothCurve3(x0, y0);
                }
            }
            break;

            default:
            {
                points.GetCoord(0, out double x0, out double y0);
                points.GetCoord(1, out double x1, out double y1);
                points.GetCoord(2, out double x2, out double y2);
                pw.MoveTo(x0, y0);
                pw.Curve3(x1, y1, x2, y2);
                for (int i = 3; i < coordCount; ++i)
                {
                    points.GetCoord(i, out double x, out double y);
                    pw.SmoothCurve3(x, y);
                }
                if (closedShape)
                {
                    pw.SmoothCurve3(x0, y0);
                }
            }
            break;
            }
        }
Exemplo n.º 17
0
        public override void Draw(CanvasPainter p)
        {
            //specific for agg

            if (p is PixelFarm.Agg.AggCanvasPainter)
            {
                var        p2 = (PixelFarm.Agg.AggCanvasPainter)p;
                Graphics2D gx = p2.Graphics;
                var        widgetsSubImage = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
                gx.UseSubPixelRendering = false;
                IPixelBlender  NormalBlender       = new PixelBlenderBGRA();
                IPixelBlender  GammaBlender        = new PixelBlenderGammaBGRA(this.GammaValue);
                var            rasterGamma         = new ChildImage(widgetsSubImage, GammaBlender);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);
                var rasterizer       = gx.ScanlineRasterizer;
                ScanlineUnpacked8 sl = new ScanlineUnpacked8();
                int size_mul         = (int)this.PixelSize;
                CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, gx.DestActualImage);
                rasterizer.Reset();
                rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
                rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
                rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
                ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //----------------------------------------
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
                gx.UseSubPixelRendering = true;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                rasterizer.ResetGamma(new GammaNone());
                gx.UseSubPixelRendering = false;
                //----------------------------------------
                PathWriter ps = new PathWriter();
                ps.Clear();
                ps.MoveTo(m_x[0], m_y[0]);
                ps.LineTo(m_x[1], m_y[1]);
                ps.LineTo(m_x[2], m_y[2]);
                ps.LineTo(m_x[0], m_y[0]);
                //----------------------------------------
                //Stroke stroke = new Stroke(ps);
                //stroke.Width = 2;
                //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs()));
                var v1 = GetFreeVxs();
                rasterizer.AddPath(stroke.MakeVxs(ps.Vxs, v1));
                ReleaseVxs(ref v1);
                //----------------------------------------

                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
            }
        }
Exemplo n.º 18
0
        public static void WritePolylines(this PathWriter pw, double[] points)
        {
            int j = points.Length;

            if (j >= 4)
            {
                pw.MoveTo(points[0], points[1]);
                for (int i = 2; i < j;)
                {
                    pw.LineTo(points[i], points[i + 1]);
                    i += 2;
                }
            }
        }
Exemplo n.º 19
0
        //-----------------------------------------------------------------------------------------
        public static void WritePolygon(this PathWriter pw, IVector2dProvider points)
        {
            int count = points.CoordCount;

            if (count > 1)
            {
                points.GetCoord(0, out double x, out double y);
                pw.MoveTo(x, y);
                for (int i = 1; i < count; ++i)
                {
                    pw.LineTo(x, y);
                }
                pw.CloseFigure();
            }
        }
Exemplo n.º 20
0
        public static void WritePolygon(this PathWriter pw, float[] points)
        {
            int j = points.Length;

            if (j >= 4)
            {
                pw.MoveTo(points[0], points[1]);
                for (int i = 2; i < j;)
                {
                    pw.LineTo(points[i], points[i + 1]);
                    i += 2;
                }
                pw.CloseFigure();
            }
        }
Exemplo n.º 21
0
        void DrawE(PixelFarm.Drawing.Painter painter)
        {
            PathWriter ps = new PathWriter();

            painter.Clear(PixelFarm.Drawing.Color.White);
            painter.StrokeColor = PixelFarm.Drawing.Color.Red;


            //p.Line(10, 10, 50, 10);
            //p.Line(50, 10, 50, 50);
            //p.Line(50, 50, 10, 50);
            //p.Line(50, 10, 10, 10);

            ps.Clear();
            //ps.MoveTo(10, 10);
            //ps.LineTo(50, 10);
            //ps.LineTo(50, 50);

            //ps.MoveTo(10, 10);
            //ps.LineTo(50, 10);
            //ps.LineTo(10, 20);

            ps.MoveTo(150, 10);
            ps.LineTo(110, 10);
            ps.LineTo(150, 20);

            //ps.MoveTo(50, 50);
            //ps.LineTo(40, 50);
            //ps.LineTo(80, 70);


            //ps.CloseFigure();

            //p.Fill(ps.Vxs, PixelFarm.Drawing.Color.Black);
            VertexStore output = new VertexStore();
            StrokeGen2  gen2   = new StrokeGen2();

            gen2.LineCapStyle    = LineCap.Butt;
            gen2.LineJoinStyle   = LineJoin.Miter;
            gen2.HalfStrokeWidth = 7;//
            gen2.Generate(ps.Vxs, output);
            //-----------------------------------------------------

            painter.Fill(output, PixelFarm.Drawing.Color.Red);
            painter.StrokeWidth = 1f;
            painter.Draw(ps.Vxs, PixelFarm.Drawing.Color.Black);
        }
Exemplo n.º 22
0
        public void OnDraw(Graphics2D graphics2D)
        {
            var childImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            //IRecieveBlenderByte rasterBlender = new BlenderBGRA();
            var rasterGamma = new ChildImage(childImage, new PixelBlenderGammaBGRA(this.GammaValue));

            ClipProxyImage clippingProxyNormal = new ClipProxyImage(childImage);
            ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);

            clippingProxyNormal.Clear(ColorRGBA.White);

            var rasterizer = graphics2D.ScanlineRasterizer;
            var sl         = new ScanlineUnpacked8();


            int size_mul = this.PixelSize;

            CustomScanlineRasToBmp_EnlargedV2 sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, graphics2D.DestActualImage);

            rasterizer.Reset();
            rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
            rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
            rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);

            sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);


            ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;

            sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black);

            //-----------------------------------------------------------------------------------------------------------
            rasterizer.ResetGamma(new GammaNone());

            PathWriter ps = new PathWriter();

            ps.Clear();
            ps.MoveTo(m_x[0], m_y[0]);
            ps.LineTo(m_x[1], m_y[1]);
            ps.LineTo(m_x[2], m_y[2]);
            ps.LineTo(m_x[0], m_y[0]);

            rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs));
            sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200));
        }
Exemplo n.º 23
0
        private AggregateManager(
            ListResultStorage storage,
            List <StorageSection>?sections,
            FindCommandOptions options)
        {
            Storage  = storage;
            Sections = sections;
            Options  = options;

            if (ShouldLog(Verbosity.Minimal))
            {
                PathWriter = new PathWriter(
                    pathColors: Colors.Matched_Path,
                    relativePath: Options.DisplayRelativePath,
                    indent: "  ");
            }
        }
Exemplo n.º 24
0
        public static void MakeVxs(this Ellipse ellipse, PathWriter writer)
        {
            //1. moveto
            writer.MoveTo(ellipse.originX + ellipse.radiusX, ellipse.originY);
            //2.
            //
            int    numSteps     = ellipse.NumSteps;
            double anglePerStep = MathHelper.Tau / numSteps;
            double angle        = 0;


            double orgX = ellipse.originX;
            double orgY = ellipse.originY;
            double radX = ellipse.radiusX;
            double radY = ellipse.radiusY;

            if (ellipse._cw)
            {
                for (int i = 1; i < numSteps; i++)
                {
                    angle += anglePerStep;
                    writer.LineTo(
                        orgX + Math.Cos(MathHelper.Tau - angle) * radX,
                        orgY + Math.Sin(MathHelper.Tau - angle) * radY);
                }
            }
            else
            {
                for (int i = 1; i < numSteps; i++)
                {
                    angle += anglePerStep;
                    writer.LineTo(
                        orgX + Math.Cos(angle) * radX,
                        orgY + Math.Sin(angle) * radY);
                }
            }


            //3.
            //output.AddCloseFigure((int)EndVertexOrientation.CCW, 0);
            writer.CloseFigure();
            //4.
            //add no more?
        }
Exemplo n.º 25
0
        public override void MouseUp(int x, int y)
        {
            if (currentBrushPath != null)
            {
                currentBrushPath.GetSmooth();
                switch (currentBrushPath.BrushMode)
                {
                case SmoothBrushMode.CutBrush:
                {
                    if (myBrushPathList.Count > 0)
                    {
                        //1. remove
                        myBrushPathList.RemoveAt(myBrushPathList.Count - 1);
                        //

                        if (myBrushPathList.Count > 0)
                        {
                            var lastPath = myBrushPathList[myBrushPathList.Count - 1];

                            //do path clip***

                            PathWriter result = CombinePaths(
                                new VertexStoreSnap(lastPath.vxs),
                                new VertexStoreSnap(currentBrushPath.vxs),
                                ClipType.ctDifference);

                            myBrushPathList.RemoveAt(myBrushPathList.Count - 1);

                            MyBrushPath newBrushPath = new MyBrushPath();
                            newBrushPath.BrushMode   = lastPath.BrushMode;
                            newBrushPath.StrokeColor = lastPath.StrokeColor;
                            newBrushPath.FillColor   = lastPath.FillColor;
                            newBrushPath.vxs         = result.Vxs;
                            myBrushPathList.Add(newBrushPath);
                        }
                    }
                } break;
                }
                currentBrushPath = null;
            }

            base.MouseUp(x, y);
        }
 public static void Load(PathWriter vertexSource, string pathAndFileName)
 {
     //vertexSource.Clear();
     //var vxs = vertexSource.Vxs;
     //string[] allLines = File.ReadAllLines(pathAndFileName);
     //foreach (string line in allLines)
     //{
     //    string[] elements = line.Split(',');
     //    double x = double.Parse(elements[0]);
     //    double y = double.Parse(elements[1]);
     //    VertexCmd flagsAndCommand = (VertexCmd)System.Enum.Parse(typeof(VertexCmd), elements[2].Trim());
     //    int len = elements.Length;
     //    for (int i = 3; i < len; i++)
     //    {
     //        flagsAndCommand |= (VertexCmd)System.Enum.Parse(typeof(VertexCmd), elements[i].Trim());
     //    }
     //    vxs.AddVertex(x, y, flagsAndCommand);
     //}
 }
Exemplo n.º 27
0
        public override void Draw(Painter p)
        {
            //this specific for agg
            if (p is AggPainter)
            {
                AggPainter       p2     = (AggPainter)p;
                AggRenderSurface aggsx  = p2.RenderSurface;
                SubImageRW       subImg = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());

                //TODO: review here again
                PixelBlenderBGRA blenderWithGamma = new PixelBlenderBGRA();

                SubImageRW     rasterGamma         = new SubImageRW(subImg, blenderWithGamma);
                ClipProxyImage clippingProxyNormal = new ClipProxyImage(subImg);
                ClipProxyImage clippingProxyGamma  = new ClipProxyImage(rasterGamma);
                clippingProxyNormal.Clear(Color.White);
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                var sl             = new ScanlineUnpacked8();
                int size_mul       = this.PixelSize;
                var sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, aggsx.DestActualImage);
                rasterizer.Reset();
                rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul);
                rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul);
                rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul);
                sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black);
                //-----------------------------------------------------------------------------------------------------------
                rasterizer.ResetGamma(new GammaNone());
                PathWriter ps = new PathWriter();
                ps.Clear();
                ps.MoveTo(m_x[0], m_y[0]);
                ps.LineTo(m_x[1], m_y[1]);
                ps.LineTo(m_x[2], m_y[2]);
                ps.LineTo(m_x[0], m_y[0]);

                VectorToolBox.GetFreeVxs(out var v1);
                rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs, v1));
                sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160));
                VectorToolBox.ReleaseVxs(ref v1);
            }
        }
Exemplo n.º 28
0
        void Draw(PixelFarm.Agg.AggPainter aggPainter)
        {
            aggPainter.Clear(PixelFarm.Drawing.Color.White);
            //--------------------------
            aggPainter.StrokeColor = PixelFarm.Drawing.Color.Black;
            aggPainter.StrokeWidth = 30.0f;

            //
            VertexStore vxs    = new VertexStore();
            PathWriter  writer = new PathWriter(vxs);

            writer.MoveTo(20, 0);
            writer.LineTo(100, 100);
            writer.LineTo(20, 200);

            aggPainter.LineJoin = this.LineJoin;
            aggPainter.LineCap  = this.LineCap;
            //
            aggPainter.Draw(vxs);
        }
Exemplo n.º 29
0
        public Lines()
        {
            _orgVxs = new VertexStore();
            PathWriter writer   = new PathWriter(_orgVxs);
            int        y_offset = 20;

            writer.MoveTo(120, y_offset + 0);
            writer.LineTo(200, y_offset + 100);
            writer.LineTo(120, y_offset + 200);
            //---------------------
            //our agg has built-in stroke-generator tool
            //so when we call Draw() from the Vxs => a new stroke path is created from the original input vxs

            //---------------------

            //but we can generate stroke before send it
            //by use another stroke gnernator

            UpdateStroke();
        }
Exemplo n.º 30
0
        protected override IEnumerable <TextFile> ProcessTemplate(Template template, OdcmObject odcmObject)
        {
            var host = GetCustomHost(template, odcmObject);

            var templateContent = File.ReadAllText(host.TemplateFile);
            var output          = Engine.ProcessTemplate(templateContent, host);

            if (host.Errors != null && host.Errors.HasErrors)
            {
                var errors = LogErrors(host, template);
                throw new InvalidOperationException(errors);
            }

            var filePath = PathWriter.WritePath(template, string.Format("{0}{1}{2}",
                                                                        Prefix,
                                                                        host.Model.EntityContainer.Name,
                                                                        odcmObject == null ? template.Name : odcmObject.Name)
                                                );

            return(new TextFile(filePath, output).ToIEnumerable());
        }
Exemplo n.º 31
0
        void make_arrows(PathWriter ps)
        {
            ps.Clear();
            ps.MoveTo(1330.599999999999909, 1282.399999999999864);
            ps.LineTo(1377.400000000000091, 1282.399999999999864);
            ps.LineTo(1361.799999999999955, 1298.000000000000000);
            ps.LineTo(1393.000000000000000, 1313.599999999999909);
            ps.LineTo(1361.799999999999955, 1344.799999999999955);
            ps.LineTo(1346.200000000000045, 1313.599999999999909);
            ps.LineTo(1330.599999999999909, 1329.200000000000045);
            ps.CloseFigure();

            ps.MoveTo(1330.599999999999909, 1266.799999999999955);
            ps.LineTo(1377.400000000000091, 1266.799999999999955);
            ps.LineTo(1361.799999999999955, 1251.200000000000045);
            ps.LineTo(1393.000000000000000, 1235.599999999999909);
            ps.LineTo(1361.799999999999955, 1204.399999999999864);
            ps.LineTo(1346.200000000000045, 1235.599999999999909);
            ps.LineTo(1330.599999999999909, 1220.000000000000000);
            ps.CloseFigure();

            ps.MoveTo(1315.000000000000000, 1282.399999999999864);
            ps.LineTo(1315.000000000000000, 1329.200000000000045);
            ps.LineTo(1299.400000000000091, 1313.599999999999909);
            ps.LineTo(1283.799999999999955, 1344.799999999999955);
            ps.LineTo(1252.599999999999909, 1313.599999999999909);
            ps.LineTo(1283.799999999999955, 1298.000000000000000);
            ps.LineTo(1268.200000000000045, 1282.399999999999864);
            ps.CloseFigure();

            ps.MoveTo(1268.200000000000045, 1266.799999999999955);
            ps.LineTo(1315.000000000000000, 1266.799999999999955);
            ps.LineTo(1315.000000000000000, 1220.000000000000000);
            ps.LineTo(1299.400000000000091, 1235.599999999999909);
            ps.LineTo(1283.799999999999955, 1204.399999999999864);
            ps.LineTo(1252.599999999999909, 1235.599999999999909);
            ps.LineTo(1283.799999999999955, 1251.200000000000045);
            ps.CloseFigure();
        }