public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); int width = (int)widgetsSubImage.Width; int height = (int)widgetsSubImage.Height; ImageBuffer clippedSubImage = new ImageBuffer(); clippedSubImage.Attach(widgetsSubImage, new BlenderBGRA()); ImageClippingProxy imageClippingProxy = new ImageClippingProxy(clippedSubImage); imageClippingProxy.clear(new ColorF(1, 1, 1)); 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); if (renderAsScanlineCheckBox.Checked) { rasterizer.SetVectorClipBox(0, 0, width, height); foreach (var shape in lionShape.Shapes) { Stroke stroke = new Stroke(shape.VertexStorage); stroke.Width = widthSlider.Value; stroke.LineJoin = LineJoin.Round; VertexSourceApplyTransform trans = new VertexSourceApplyTransform(stroke, transform); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); rasterizer.add_path(trans); scanlineRenderer.RenderSolid(imageClippingProxy, rasterizer, scanlineCache, shape.Color); } } else { double w = widthSlider.Value * transform.GetScale(); LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(w, new gamma_none()); OutlineRenderer outlineRenderer = new OutlineRenderer(imageClippingProxy, lineProfile); rasterizer_outline_aa rasterizer = new rasterizer_outline_aa(outlineRenderer); rasterizer.line_join(renderAccurateJoinsCheckBox.Checked ? rasterizer_outline_aa.outline_aa_join_e.outline_miter_accurate_join : rasterizer_outline_aa.outline_aa_join_e.outline_round_join); rasterizer.round_cap(true); foreach (var shape in lionShape.Shapes) { VertexSourceApplyTransform trans = new VertexSourceApplyTransform(shape.VertexStorage, transform); rasterizer.RenderAllPaths(trans, new Color[] { shape.Color }, new int[] { 0 }, 1); } } base.OnDraw(graphics2D); }
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(); } } }
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); }
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); }
public override void Draw(CanvasPainter 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 AggCanvasPainter; if (p1 == null) { int j = lionShape.NumPaths; int[] pathList = lionShape.PathIndexList; Drawing.Color[] colors = lionShape.Colors; //graphics2D.UseSubPixelRendering = true; var vxs = GetFreeVxs(); affTx.TransformToVxs(lionShape.Path.Vxs, vxs); p.StrokeWidth = 1; for (int i = 0; i < j; ++i) { p.StrokeColor = colors[i]; p.Draw(new VertexStoreSnap(vxs, pathList[i])); } //not agg Release(ref vxs); return; //** } Graphics2D graphics2D = p1.Graphics; //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect()); //int width = widgetsSubImage.Width; //int height = widgetsSubImage.Height; var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect()); var clippedSubImage = new ChildImage(widgetsSubImage, new PixelBlenderBGRA()); ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage); imageClippingProxy.Clear(PixelFarm.Drawing.Color.White); if (RenderAsScanline) { var rasterizer = graphics2D.ScanlineRasterizer; rasterizer.SetClipBox(0, 0, width, height); Stroke stroke = new Stroke(strokeWidth); stroke.LineJoin = LineJoin.Round; var vxs = GetFreeVxs(); affTx.TransformToVxs(lionShape.Path.Vxs, vxs); ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap; sclineRasToBmp.RenderSolidAllPaths( imageClippingProxy, rasterizer, graphics2D.ScanlinePacked8, vxs, lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); Release(ref vxs); } 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 = GetFreeVxs(); affTx.TransformToVxs(lionShape.Path.Vxs, 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]); } Release(ref vxs); } base.Draw(p); }