void CreateEndLineCap(VertexStore outputVxs, Vector v0, Vector v1, double edgeWidth) { switch (this.LineCapStyle) { default: throw new NotSupportedException(); case LineCap.Butt: outputVxs.AddLineTo(v0.X, v0.Y); outputVxs.AddLineTo(v1.X, v1.Y); break; case LineCap.Square: { Vector delta = (v1 - v0).Rotate(90).NewLength(edgeWidth); outputVxs.AddLineTo(v0.X + delta.X, v0.Y + delta.Y); outputVxs.AddLineTo(v1.X + delta.X, v1.Y + delta.Y); } break; case LineCap.Round: { capVectors.Clear(); BuildEndCap(v0.X, v0.Y, v1.X, v1.Y, capVectors); int j = capVectors.Count; for (int i = j - 1; i >= 0; --i) { Vector v = capVectors[i]; outputVxs.AddLineTo(v.X, v.Y); } } break; } }
public void GetSmooth() { if (this.isValidSmooth) { return; } this.isValidSmooth = true; //lets smooth it //string str1 = dbugDumpPointsToString(contPoints); //string str2 = dbugDumpPointsToString2(contPoints); //var data2 = CurvePreprocess.RdpReduce(contPoints, 2); var data2 = contPoints; CubicBezier[] cubicBzs = CurveFit.Fit(data2, 8); //PathWriter pWriter = new PathWriter(); //pWriter.StartFigure(); //int j = cubicBzs.Length; //for (int i = 0; i < j; ++i) //{ // CubicBezier bz = cubicBzs[i]; // pWriter.MoveTo(bz.p0.x, bz.p0.y); // pWriter.LineTo(bz.p0.x, bz.p0.y); // pWriter.Curve4(bz.p1.x, bz.p1.y, // bz.p2.x, bz.p2.y, // bz.p3.x, bz.p3.y); //} //pWriter.CloseFigureCCW(); vxs = new VertexStore(); int j = cubicBzs.Length; //1. if (j > 0) { //1st CubicBezier bz0 = cubicBzs[0]; vxs.AddMoveTo(bz0.p0.x, bz0.p0.y); vxs.AddLineTo(bz0.p0.x, bz0.p0.y); vxs.AddP3c(bz0.p1.x, bz0.p1.y); vxs.AddP3c(bz0.p2.x, bz0.p2.y); vxs.AddLineTo(bz0.p3.x, bz0.p3.y); //------------------------------- for (int i = 1; i < j; ++i) //start at 1 { CubicBezier bz = cubicBzs[i]; vxs.AddP3c(bz.p1.x, bz.p1.y); vxs.AddP3c(bz.p2.x, bz.p2.y); vxs.AddLineTo(bz.p3.x, bz.p3.y); } //------------------------------- //close vxs.AddLineTo(bz0.p0.x, bz0.p0.y); } vxs.AddCloseFigure(); PixelFarm.Agg.VertexSource.CurveFlattener cflat = new PixelFarm.Agg.VertexSource.CurveFlattener(); vxs = cflat.MakeVxs(vxs); }
public static void Main() { //TEST //this is low-level scanline rasterizer //1. create vertex store VertexStore vxs = new VertexStore(); vxs.AddMoveTo(10, 10); vxs.AddLineTo(50, 10); vxs.AddLineTo(50, 50); vxs.AddLineTo(10, 50); vxs.AddCloseFigure(); //2. create scanline rasterizer ScanlineRasterizer sclineRas = new ScanlineRasterizer(); sclineRas.AddPath(vxs); //3. create destination bitmap DestBitmapRasterizer destBmpRasterizer = new DestBitmapRasterizer(); //4. create 32bit rgba bitmap blender MyBitmapBlender myBitmapBlender = new MyBitmapBlender(); //5. create output bitmap using (MemBitmap membitmap = new MemBitmap(800, 600)) { //6. attach target bitmap to bitmap blender myBitmapBlender.Attach(membitmap); //7. rasterizer sends the vector content inside sclineRas // to the bitmap blender and destBmpRasterizer.RenderWithColor(myBitmapBlender, //blender+ output sclineRas, //with vectors input inside new ScanlinePacked8(), Color.Red); //8. the content inside membitmap is just color image buffer // you can copy it to other image object (eg SkImage, Gdi+ image etc) //... example ... using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(membitmap.Width, membitmap.Height)) { IntPtr mem_ptr = membitmap.GetRawBufferHead(); System.Drawing.Imaging.BitmapData bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { MemMx.memcpy((byte *)bmpdata.Scan0, (byte *)mem_ptr, membitmap.Width * membitmap.Height * 4); } bmp.UnlockBits(bmpdata); bmp.Save("test01.png"); } } }
static void BuildOrgImgRectVxs(int srcW, int srcH, VertexStore output) { output.Clear(); output.AddMoveTo(0, 0); output.AddLineTo(srcW, 0); output.AddLineTo(srcW, srcH); output.AddLineTo(0, srcH); output.AddCloseFigure(); }
public void MakeSmoothPath() { if (this.isValidSmooth) { return; } this.isValidSmooth = true; //-------- if (contPoints.Count == 0) { return; } //return; //-------- //lets smooth it //string str1 = dbugDumpPointsToString(contPoints); //string str2 = dbugDumpPointsToString2(contPoints); //var data2 = CurvePreprocess.RdpReduce(contPoints, 2); var data2 = contPoints; CubicBezier[] cubicBzs = CurveFit.Fit(data2, 8); vxs = new VertexStore(); int j = cubicBzs.Length; //1. if (j > 0) { //1st CubicBezier bz0 = cubicBzs[0]; vxs.AddMoveTo(bz0.p0.x, bz0.p0.y); vxs.AddLineTo(bz0.p0.x, bz0.p0.y); vxs.AddCurve4To( bz0.p1.x, bz0.p1.y, bz0.p2.x, bz0.p2.y, bz0.p3.x, bz0.p3.y); //------------------------------- for (int i = 1; i < j; ++i) //start at 1 { CubicBezier bz = cubicBzs[i]; vxs.AddCurve4To( bz.p1.x, bz.p1.y, bz.p2.x, bz.p2.y, bz.p3.x, bz.p3.y); } //------------------------------- //close //TODO: we not need this AddLineTo() vxs.AddLineTo(bz0.p0.x, bz0.p0.y); } vxs.AddCloseFigure(); VertexStore v2 = new VertexStore(); cflat.MakeVxs(vxs, v2); vxs = v2; }
public ExampleVxsLineDash2Walker() { using (Tools.BorrowVxs(out var v1)) { v1 = new VertexStore(); v1.AddMoveTo(0, -3); v1.AddLineTo(4, 0); v1.AddLineTo(0, 3); v1.AddCloseFigure(); _vxs = v1.CreateTrim(); } }
public static VertexStore MakeVxs(this Ellipse ellipse, ICoordTransformer tx, VertexStore output) { //1. moveto output.AddMoveTo(ellipse.originX + ellipse.radiusX, ellipse.originY, tx);//** //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; output.AddLineTo( orgX + Math.Cos(MathHelper.Tau - angle) * radX, orgY + Math.Sin(MathHelper.Tau - angle) * radY, tx);//** } } else { for (int i = 1; i < numSteps; i++) { angle += anglePerStep; output.AddLineTo( orgX + Math.Cos(angle) * radX, orgY + Math.Sin(angle) * radY, tx);//** } } //3. output.AddCloseFigure((int)EndVertexOrientation.CCW, 0); //4. output.AddNoMore(); return(output); }
static void CreateInnerBorder(VertexStore vxs, double x0, double y0, double x1, double y1, double w) { //create 'inner border box' of a line a line (x0,y0)=>(x1,y1) PixelFarm.VectorMath.Vector2 vector = new PixelFarm.VectorMath.Vector2(x1 - x0, y1 - y0); //for inner border, we don't extend both endpoint //rotate 270 degree to create a height vector that point 'inside' of the 'rectbox' shape. //the box height= w PixelFarm.VectorMath.Vector2 vdiff = vector.RotateInDegree(270).NewLength(w); vxs.AddMoveTo(x0, y0); vxs.AddLineTo(x1, y1); vxs.AddLineTo(x1 + vdiff.x, y1 + vdiff.y); vxs.AddLineTo(x0 + vdiff.x, y0 + vdiff.y); vxs.AddCloseFigure(); }
public static void CreateBezierVxs4(VertexStore vxs, Vector2 start, Vector2 end, Vector2 control1, Vector2 control2) { var curve = new VectorMath.BezierCurveCubic( start, end, control1, control2); vxs.AddLineTo(start.x, start.y); float eachstep = (float)1 / NSteps; float stepSum = eachstep;//start for (int i = 1; i < NSteps; ++i) { var vector2 = curve.CalculatePoint(stepSum); vxs.AddLineTo(vector2.x, vector2.y); stepSum += eachstep; } vxs.AddLineTo(end.x, end.y); }
public static void CreateBezierVxs4(VertexStore vxs, Vector2 start, Vector2 end, Vector2 control1, Vector2 control2) { var curve = new VectorMath.BezierCurveCubic( start, end, control1, control2); vxs.AddLineTo(start.x, start.y); float eachstep = (float)1 / NSteps; float stepSum = eachstep;//start for (int i = 1; i < NSteps; ++i) { var vector2 = curve.CalculatePoint(stepSum); vxs.AddLineTo(vector2.x, vector2.y); stepSum += eachstep; } vxs.AddLineTo(end.x, end.y); }
public void dbugLine(double x1, double y1, double x2, double y2, Drawing.Color color) { dbug_v1.AddMoveTo(x1, y1); dbug_v1.AddLineTo(x2, y2); //dbug_v1.AddStop(); dbugStroke.MakeVxs(dbug_v1, dbug_v2); Render(dbug_v2, color); dbug_v1.Clear(); dbug_v2.Clear(); }
public static void CreateBezierVxs3(VertexStore vxs, Vector2 start, Vector2 end, Vector2 control1) { var curve = new VectorMath.BezierCurveQuadric( start, end, control1); vxs.AddLineTo(start.x, start.y); float eachstep = (float)1 / NSteps; float stepSum = eachstep;//start for (int i = 1; i < NSteps; ++i) { var vector2 = curve.CalculatePoint(stepSum); vxs.AddLineTo(vector2.x, vector2.y); stepSum += eachstep; } vxs.AddLineTo(end.x, end.y); //------------------------------------------------------ //convert c3 to c4 //Vector2 c4p2, c4p3; //Curve3GetControlPoints(start, control1, end, out c4p2, out c4p3); //CreateBezierVxs4(vxs, start, end, c4p2, c4p3); }
public void MakeVxs(VertexStore vxs) { int contourCount = _contours.Count; for (int i = 0; i < contourCount; ++i) { //each contour RawContour contour = _contours[i]; List <Point> xyCoords = contour._xyCoords; int count = xyCoords.Count; if (count > 1) { if (contour.IsOutside) { Point p = xyCoords[0]; vxs.AddMoveTo(p.X, p.Y); for (int n = 1; n < count; ++n) { p = xyCoords[n]; vxs.AddLineTo(p.X, p.Y); } vxs.AddCloseFigure(); } else { Point p = xyCoords[count - 1]; vxs.AddMoveTo(p.X, p.Y); for (int n = count - 1; n >= 0; --n) { p = xyCoords[n]; vxs.AddLineTo(p.X, p.Y); } vxs.AddCloseFigure(); } } } }
public void MakeLines(VertexStore vxs) { int j = m_points.Count; if (j > 0) { //others for (int i = 1; i < j; i++) { var p = m_points[i]; vxs.AddLineTo(p.x, p.y); } } }
static void CreateOuterBorder(VertexStore vxs, double x0, double y0, double x1, double y1, double w) { //create 'outer border box' of a line (x0,y0)=>(x1,y1) PixelFarm.VectorMath.Vector2 vector = new PixelFarm.VectorMath.Vector2(x1 - x0, y1 - y0); //for outer border, we need to extend both endpoints with len w //this will create overlapped area outside the shape. PixelFarm.VectorMath.Vector2 ext_vec = vector.NewLength(w); x0 -= ext_vec.x; y0 -= ext_vec.y; x1 += ext_vec.x; y1 += ext_vec.y; //rotate 90 degree to create a height vector that point to 'outside' of the 'rectbox' shape. //the box height= w PixelFarm.VectorMath.Vector2 h_vec = vector.RotateInDegree(90).NewLength(w); vxs.AddMoveTo(x0, y0); vxs.AddLineTo(x0 + h_vec.x, y0 + h_vec.y); vxs.AddLineTo(x1 + h_vec.x, y1 + h_vec.y); vxs.AddLineTo(x1, y1); vxs.AddCloseFigure(); }
public static void CreateBezierVxs3(VertexStore vxs, Vector2 start, Vector2 end, Vector2 control1) { var curve = new VectorMath.BezierCurveQuadric( start, end, control1); vxs.AddLineTo(start.x, start.y); float eachstep = (float)1 / NSteps; float stepSum = eachstep;//start for (int i = 1; i < NSteps; ++i) { var vector2 = curve.CalculatePoint(stepSum); vxs.AddLineTo(vector2.x, vector2.y); stepSum += eachstep; } vxs.AddLineTo(end.x, end.y); //------------------------------------------------------ //convert c3 to c4 //Vector2 c4p2, c4p3; //Curve3GetControlPoints(start, control1, end, out c4p2, out c4p3); //CreateBezierVxs4(vxs, start, end, c4p2, c4p3); }
public static void MakeLines(this Curve3Div curve, VertexStore vxs) { ArrayList <Vector2> m_points = curve.GetInternalPoints(); int j = m_points.Count; if (j > 0) { //others for (int i = 1; i < j; i++) { var p = m_points[i]; vxs.AddLineTo(p.x, p.y); } } }
public void MakeRegularPath(float strokeW) { if (this.isValidSmooth) { return; } this.isValidSmooth = true; //-------- if (contPoints.Count == 0) { return; } //SimplifyPaths(); _stroke1.Width = strokeW * 2; _stroke1.LineCap = LineCap.Round; _stroke1.LineJoin = LineJoin.Round; var tmpVxs = new VertexStore(); int j = contPoints.Count; for (int i = 0; i < j; ++i) { //TODO: review here // Vector2 v = contPoints[i]; if (i == 0) { tmpVxs.AddMoveTo(v.x, v.y); } else { tmpVxs.AddLineTo(v.x, v.y); } } //// VertexStore v2 = new VertexStore(); _stroke1.MakeVxs(tmpVxs, v2); vxs = v2; //release vxs to pool }
static void SimpleSolidLine(VertexStore outputVxs, VertexCmd cmd, double x, double y) { //solid switch (cmd) { default: throw new NotSupportedException(); case VertexCmd.MoveTo: outputVxs.AddMoveTo(x, y); break; case VertexCmd.LineTo: outputVxs.AddLineTo(x, y); break; } }
public void Close() { this.vxs = new VertexStore(); int j = contPoints.Count; if (j > 0) { var p = contPoints[0]; vxs.AddMoveTo(p.x, p.y); for (int i = 1; i < j; ++i) { p = contPoints[i]; vxs.AddLineTo(p.x, p.y); } vxs.AddCloseFigure(); } }
void CreateBorder(VertexStore vxs, Vertex2d prev, Vertex2d now, Vertex2d next0, Vertex2d next1) { //now we are on now using (Tools.BorrowVxs(out var vxs1)) { vxs.AddMoveTo(now.x, now.y); //create outer line-join _strokeMath.CreateJoin(vxs1, prev, now, next0); vxs.AppendVertexStore(vxs1); //create inner line join //next outer line join vxs1.Clear();//reuse _strokeMath.CreateJoin(vxs1, now, next0, next1); vxs.AppendVertexStore(vxs1); vxs.AddLineTo(next0.x, next0.y); vxs.AddCloseFigure(); } }
void GetExampleVxs(VertexStore outputVxs) { //counter-clockwise //a triangle //outputVxs.AddMoveTo(10, 20); //outputVxs.AddLineTo(50, 60); //outputVxs.AddLineTo(70, 20); //outputVxs.AddCloseFigure(); //a quad //outputVxs.AddMoveTo(10, 20); //outputVxs.AddLineTo(50, 60); //outputVxs.AddLineTo(70, 20); //outputVxs.AddLineTo(50, 10); //outputVxs.AddCloseFigure(); ////curve4 //outputVxs.AddMoveTo(5, 5); //outputVxs.AddLineTo(50, 60); //outputVxs.AddCurve4To(70, 20, 50, 10, 10, 5); //outputVxs.AddCloseFigure(); //curve3 //outputVxs.AddMoveTo(5, 5); //outputVxs.AddLineTo(50, 60); //outputVxs.AddCurve3To(70, 20, 10, 5); //outputVxs.AddCloseFigure(); //a quad with hole outputVxs.AddMoveTo(10, 20); outputVxs.AddLineTo(50, 60); outputVxs.AddLineTo(70, 20); outputVxs.AddLineTo(50, 10); outputVxs.AddCloseFigure(); outputVxs.AddMoveTo(30, 30); outputVxs.AddLineTo(40, 30); outputVxs.AddLineTo(40, 35); outputVxs.AddLineTo(30, 35); outputVxs.AddCloseFigure(); }
public static void CreateBezierVxs3(VertexStore vxs, double x0, double y0, double x1, double y1, double x2, double y2) { //1. subdiv technique s_curve3Div.Init(x0, y0, x1, y1, x2, y2); ArrayList <Vector2> points = s_curve3Div.GetInternalPoints(); int n = 0; for (int i = points.Length - 1; i >= 0; --i) { Vector2 p = points[n++]; vxs.AddLineTo(p.x, p.y); } //2. old tech -- use incremental //var curve = new VectorMath.BezierCurveQuadric( // new Vector2(x0, y0), // new Vector2(x1, y1), // new Vector2(x2, y2)); //vxs.AddLineTo(x0, y0); //float eachstep = (float)1 / NSteps; //float stepSum = eachstep;//start //for (int i = NSteps - 1; i >= 0; --i) //{ // var vector2 = curve.CalculatePoint(stepSum); // vxs.AddLineTo(vector2.x, vector2.y); // stepSum += eachstep; //} //vxs.AddLineTo(x2, y2); }
static void CreateBezierVxs4(VertexStore vxs, double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3) { //1. subdiv technique s_curve4Div.Init(x0, y0, x1, y1, x2, y2, x3, y3); ArrayList <Vector2> points = s_curve4Div.GetInternalPoints(); int n = 0; for (int i = points.Length - 1; i >= 0; --i) { Vector2 p = points[n++]; vxs.AddLineTo(p.x, p.y); } //---------------------------------------- //2. old tech -- use incremental //var curve = new VectorMath.BezierCurveCubic( // start, end, // control1, control2); //vxs.AddLineTo(start.x, start.y); //float eachstep = (float)1 / NSteps; //float stepSum = eachstep;//start //for (int i = NSteps - 1; i >= 0; --i) //{ // var vector2 = curve.CalculatePoint(stepSum); // vxs.AddLineTo(vector2.x, vector2.y); // stepSum += eachstep; //} //vxs.AddLineTo(end.x, end.y); }
protected override void OnStartDemo(SampleViewport viewport) { SvgPart svgPart = new SvgPart(SvgRenderVxKind.Path); VertexStore vxs = new VertexStore(); vxs.AddMoveTo(100, 20); vxs.AddLineTo(150, 50); vxs.AddLineTo(110, 80); vxs.AddCloseFigure(); //------------------------------------------- svgPart.SetVxsAsOriginal(vxs); svgPart.FillColor = Color.Red; SvgRenderVx svgRenderVx = new SvgRenderVx(new SvgPart[] { svgPart }); svgRenderVx.DisableBackingImage = true; var uiSprite = new UISprite(10, 10); //init size = (10,10), location=(0,0) uiSprite.LoadSvg(svgRenderVx); viewport.AddContent(uiSprite); var spriteEvListener = new GeneralEventListener(); uiSprite.AttachExternalEventListener(spriteEvListener); //box1 = new LayoutFarm.CustomWidgets.SimpleBox(50, 50); //box1.BackColor = Color.Red; //box1.SetLocation(10, 10); ////box1.dbugTag = 1; //SetupActiveBoxProperties(box1); //viewport.AddContent(box1); //-------- rectBoxController.Init(); //polygonController.Visible = false; viewport.AddContent(polygonController); //------------------------------------------- viewport.AddContent(rectBoxController); //foreach (var ui in rectBoxController.GetControllerIter()) //{ // viewport.AddContent(ui); //} spriteEvListener.MouseDown += e1 => { //mousedown on ui sprite polygonController.SetPosition((int)uiSprite.Left, (int)uiSprite.Top); polygonController.SetTargetUISprite(uiSprite); polygonController.UpdateControlPoints(svgPart); }; spriteEvListener.MouseMove += e1 => { if (e1.IsDragging) { //drag event on uisprite int left = (int)uiSprite.Left; int top = (int)uiSprite.Top; int new_left = left + e1.DiffCapturedX; int new_top = top + e1.DiffCapturedY; uiSprite.SetLocation(new_left, new_top); //----- //also update controller position polygonController.SetPosition(new_left, new_top); } }; }
public static void AddLineTo(this VertexStore vxs, double x, double y, ICoordTransformer tx) { tx.Transform(ref x, ref y); vxs.AddLineTo(x, y); }
public void MakeLines(VertexStore vxs) { int j = m_points.Count; if (j > 0) { //others for (int i = 1; i < j; i++) { var p = m_points[i]; vxs.AddLineTo(p.x, p.y); } } }
public void LineTo(double x, double y) { this.latestSVGPathCmd = SvgPathCommand.LineTo; myvxs.AddLineTo(this.lastX = x, this.lastY = y); }
public void LineTo(double x1, double y1) { _latestSVGPathCmd = SvgPathCommand.LineTo; _myvxs.AddLineTo(_latest_x = x1, _latest_y = y1); }
public ShapeBuilder LineTo(double x1, double y1) { _vxs.AddLineTo(x1, y1); return(this); }
public void Append(double x, double y) { _vxs.AddLineTo(x, y); }
public void AddLineTo(LineWalkerMark maker, double x, double y) => _vxs.AddLineTo(x, y);
public void LineTo(double x1, double y1) { this.latestSVGPathCmd = SvgPathCommand.LineTo; myvxs.AddLineTo(this.latest_x = x1, this.latest_y = y1); }