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 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); }
void DrawWithLineProfile(OutlineAARasterizer rasterizer) { SvgRenderVx renderVx = lionShape.GetRenderVx(); int num_paths = renderVx.SvgVxCount; var renderState = new TempRenderState(); renderState.strokeColor = PixelFarm.Drawing.Color.Black; renderState.strokeWidth = 1; renderState.fillColor = PixelFarm.Drawing.Color.Black; renderState.affineTx = null; for (int i = 0; i < num_paths; ++i) { SvgPart vx = renderVx.GetInnerVx(i); switch (vx.Kind) { case SvgRenderVxKind.BeginGroup: { ////1. save current state before enter new state //p.StackPushUserObject(renderState); ////2. enter new px context //if (vx.HasFillColor) //{ // p.FillColor = renderState.fillColor = vx.FillColor; //} //if (vx.HasStrokeColor) //{ // p.StrokeColor = renderState.strokeColor = vx.StrokeColor; //} //if (vx.HasStrokeWidth) //{ // p.StrokeWidth = renderState.strokeWidth = vx.StrokeWidth; //} //if (vx.AffineTx != null) //{ // //apply this to current tx // if (currentTx != null) // { // currentTx = currentTx * vx.AffineTx; // } // else // { // currentTx = vx.AffineTx; // } // renderState.affineTx = currentTx; //} } break; case SvgRenderVxKind.EndGroup: { ////restore to prev state //renderState = (TempRenderState)p.StackPopUserObject(); //p.FillColor = renderState.fillColor; //p.StrokeColor = renderState.strokeColor; //p.StrokeWidth = renderState.strokeWidth; //currentTx = renderState.affineTx; } break; case SvgRenderVxKind.Path: { //temp rasterizer.RenderVertexSnap( new PixelFarm.Drawing.VertexStoreSnap(vx.GetVxs(), 0), new Drawing.Color(255, 0, 0)); } break; //{ // VertexStore vxs = vx.GetVxs(); // if (vx.HasFillColor) // { // //has specific fill color // if (vx.FillColor.A > 0) // { // if (currentTx == null) // { // p.Fill(vxs, vx.FillColor); // } // else // { // //have some tx // tempVxs.Clear(); // currentTx.TransformToVxs(vxs, tempVxs); // p.Fill(tempVxs, vx.FillColor); // } // } // } // else // { // if (p.FillColor.A > 0) // { // if (currentTx == null) // { // p.Fill(vxs); // } // else // { // //have some tx // tempVxs.Clear(); // currentTx.TransformToVxs(vxs, tempVxs); // p.Fill(tempVxs); // } // } // } // if (p.StrokeWidth > 0) // { // //check if we have a stroke version of this render vx // //if not then request a new one // VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth); // if (vx.HasStrokeColor) // { // //has speciic stroke color // p.StrokeWidth = vx.StrokeWidth; // if (currentTx == null) // { // p.Fill(strokeVxs, vx.StrokeColor); // } // else // { // //have some tx // tempVxs.Clear(); // currentTx.TransformToVxs(strokeVxs, tempVxs); // p.Fill(tempVxs, vx.StrokeColor); // } // } // else if (p.StrokeColor.A > 0) // { // if (currentTx == null) // { // p.Fill(strokeVxs, p.StrokeColor); // } // else // { // tempVxs.Clear(); // currentTx.TransformToVxs(strokeVxs, tempVxs); // p.Fill(tempVxs, p.StrokeColor); // } // } // else // { // } // } // else // { // if (vx.HasStrokeColor) // { // VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth); // p.Fill(strokeVxs); // } // else if (p.StrokeColor.A > 0) // { // VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth); // p.Fill(strokeVxs, p.StrokeColor); // } // } //} break; } } }
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) { 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; int j = lionShape.NumPaths; int[] pathList = lionShape.PathIndexList; Drawing.Color[] colors = lionShape.Colors; p.Clear(Drawing.Color.White); var vxs = GetFreeVxs(); var vxs2 = stroke1.MakeVxs(affTx.TransformToVxs(lionShape.Vxs, vxs), GetFreeVxs()); p.StrokeWidth = 1; for (int i = 0; i < j; ++i) { p.StrokeColor = colors[i]; p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs2, pathList[i])); } //not agg Release(ref vxs); Release(ref vxs2); return; //** } 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) { var rasterizer = aggsx.ScanlineRasterizer; rasterizer.SetClipBox(0, 0, width, height); //Stroke stroke = new Stroke(strokeWidth); //stroke.LineJoin = LineJoin.Round; var vxs = GetFreeVxs(); affTx.TransformToVxs(lionShape.Vxs, vxs); ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap; sclineRasToBmp.RenderSolidAllPaths( imageClippingProxy, rasterizer, aggsx.ScanlinePacked8, vxs, lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); Release(ref vxs); } 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; //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform); var vxs = GetFreeVxs(); affTx.TransformToVxs(lionShape.Vxs, vxs);// trans.DoTransformToNewVxStorage(); int j = lionShape.NumPaths; for (int i = 0; i < j; ++i) { rasterizer.RenderVertexSnap( new PixelFarm.Drawing.VertexStoreSnap(vxs, lionShape.PathIndexList[i]), lionShape.Colors[i]); } Release(ref vxs); } base.Draw(p); }