コード例 #1
0
ファイル: SpriteShape.cs プロジェクト: BiDuc/PixelFarm
        public void Paint(Painter p, Bilinear tx)
        {
            //in this version, I can't apply bilinear tx to current tx matrix

            using (VgPaintArgsPool.Borrow(p, out var paintArgs))
            {
                paintArgs.PaintVisitHandler = (vxs, painterA) =>
                {
                    //use external painter handler
                    //draw only outline with its fill-color.
                    Drawing.Painter m_painter     = painterA.P;
                    Drawing.Color   prevFillColor = m_painter.FillColor;

                    m_painter.FillColor = m_painter.FillColor;

                    using (VxsTemp.Borrow(out var v1))
                    {
                        tx.TransformToVxs(vxs, v1);
                        m_painter.Fill(v1);
                    }
                    m_painter.FillColor = prevFillColor;
                };
                _vgVisElem.Paint(paintArgs);
            }
        }
コード例 #2
0
ファイル: SpriteShape.cs プロジェクト: BiDuc/PixelFarm
 public void Paint(Painter p)
 {
     using (VgPaintArgsPool.Borrow(p, out var paintArgs))
     {
         paintArgs._currentTx = _currentTx;
         _vgVisElem.Paint(paintArgs);
     }
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: zwcloud/Typography
        MemBitmap ParseAndRenderSvg(System.Text.StringBuilder svgContent)
        {
            //----------
            //copy from HtmlRenderer's SvgViewer demo
            //----------
            var          docBuilder   = new VgDocBuilder();
            var          parser       = new SvgParser(docBuilder);
            TextSnapshot textSnapshot = new TextSnapshot(svgContent.ToString());

            parser.ParseDocument(textSnapshot);

            VgVisualDocBuilder builder   = new VgVisualDocBuilder();
            VgVisualElement    vgVisElem = builder.CreateVgVisualDoc(docBuilder.ResultDocument, _vgDocHost).VgRootElem;
            RectD bounds        = vgVisElem.GetRectBounds();
            float actualXOffset = (float)-bounds.Left;
            float actualYOffset = (float)-bounds.Bottom;

            int bmpW = (int)Math.Round(bounds.Width);
            int bmpH = (int)Math.Round(bounds.Height);

            if (bmpW == 0 || bmpH == 0)
            {
                return(null);
            }
            MemBitmap memBitmap = new MemBitmap(bmpW, bmpH);

            using (AggPainterPool.Borrow(memBitmap, out AggPainter p))
                using (VgPaintArgsPool.Borrow(p, out VgPaintArgs paintArgs))
                {
                    float orgX = p.OriginX;
                    float orgY = p.OriginY;
                    p.SetOrigin(actualXOffset, actualYOffset);

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

                    p.FillColor = PixelFarm.Drawing.Color.Black;

                    double prevStrokeW = p.StrokeWidth;

                    vgVisElem.Paint(paintArgs);

                    p.StrokeWidth = prevStrokeW; //restore

                    p.SetOrigin(orgX, orgY);     //restore
                }

            return(memBitmap);
        }
コード例 #4
0
        PixelFarm.CpuBlit.MemBitmap CreateBitmap(VgVisualElement renderVx, int reqW, int reqH)
        {
            PixelFarm.CpuBlit.RectD bound = renderVx.GetRectBounds();
            //create
            PixelFarm.CpuBlit.MemBitmap backingBmp = new PixelFarm.CpuBlit.MemBitmap((int)bound.Width + 10, (int)bound.Height + 10);
#if DEBUG
            backingBmp._dbugNote = "renderVx";
#endif
            //PixelFarm.CpuBlit.AggPainter painter = PixelFarm.CpuBlit.AggPainter.Create(backingBmp);

            using (PixelFarm.CpuBlit.AggPainterPool.Borrow(backingBmp, out PixelFarm.CpuBlit.AggPainter painter))
                using (VgPaintArgsPool.Borrow(painter, out VgPaintArgs paintArgs))
                {
                    double prevStrokeW = painter.StrokeWidth;

                    renderVx.Paint(paintArgs);
                    painter.StrokeWidth = prevStrokeW;//restore
                }

            return(backingBmp);
        }
コード例 #5
0
ファイル: SpriteShape.cs プロジェクト: BiDuc/PixelFarm
 public void Paint(Painter p, ICoordTransformer tx)
 {
     //TODO: implement this...
     //use prefix command for render vx
     //------
     using (VgPaintArgsPool.Borrow(p, out var paintArgs))
     {
         paintArgs._currentTx        = tx;
         paintArgs.PaintVisitHandler = (vxs, arg) =>
         {
             //use external painter handler
             //draw only outline with its fill-color.
             Drawing.Painter m_painter     = arg.P;
             Drawing.Color   prevFillColor = m_painter.FillColor;
             m_painter.FillColor = m_painter.FillColor;
             m_painter.Fill(vxs);
             m_painter.FillColor = prevFillColor;
         };
         _vgVisElem.Paint(paintArgs);
     }
 }
コード例 #6
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();
                }
            }
        }
コード例 #7
0
        protected override void PaintImp(PaintVisitor p)
        {
#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif
            DrawBoard drawBoard = p.InnerDrawBoard;

            if (DisableBmpCache)
            {
                PixelFarm.CpuBlit.AggPainter painter = drawBoard.GetPainter() as PixelFarm.CpuBlit.AggPainter;
                if (painter == null)
                {
                    return;
                }
                //TODO: review here
                //temp fix
                if (s_openfontTextService == null)
                {
                    s_openfontTextService = new OpenFontTextService();
                }

                //painter.CurrentFont = new RequestFont("tahoma", 14);
                //var textPrinter = new PixelFarm.Drawing.Fonts.VxsTextPrinter(painter, s_openfontTextService);
                //painter.TextPrinter = textPrinter;
                //painter.Clear(Color.White);
                //
                double prevStrokeW = painter.StrokeWidth;
                //Color fillColor = painter.FillColor;
                //painter.StrokeWidth = 1;//default
                //painter.FillColor = Color.Black;

                using (VgPaintArgsPool.Borrow(painter, out var paintArgs))
                {
                    if (_vgVisualElem.CoordTx != null)
                    {
                    }
                    _vgVisualElem.Paint(paintArgs);
                }


                painter.StrokeWidth = prevStrokeW;//restore
                //painter.FillColor = fillColor;////restore

                return;
            }


            if (_vgVisualElem.HasBitmapSnapshot)
            {
                Image backimg = _vgVisualElem.BackingImage;
                drawBoard.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
            }
            else
            {
                PixelFarm.CpuBlit.RectD bound = _vgVisualElem.GetRectBounds();
                //create
                PixelFarm.CpuBlit.MemBitmap backimg = new PixelFarm.CpuBlit.MemBitmap((int)bound.Width + 10, (int)bound.Height + 10);
#if DEBUG
                backimg._dbugNote = "cssBoxSvgRoot";
#endif
                PixelFarm.CpuBlit.AggPainter painter = PixelFarm.CpuBlit.AggPainter.Create(backimg);
                //TODO: review here
                //temp fix
                if (s_openfontTextService == null)
                {
                    s_openfontTextService = new OpenFontTextService();
                }


                //
                double prevStrokeW = painter.StrokeWidth;

                using (VgPaintArgsPool.Borrow(painter, out VgPaintArgs paintArgs))
                {
                    if (_vgVisualElem.CoordTx != null)
                    {
                    }
                    _vgVisualElem.Paint(paintArgs);
                }

                painter.StrokeWidth = prevStrokeW;//restore
                //painter.FillColor = fillColor;////restore
#if DEBUG
                //test
                //PixelFarm.CpuBlit.Imaging.PngImageWriter.dbugSaveToPngFile(backimg, "d:\\WImageTest\\subimg1.png");
#endif
                _vgVisualElem.SetBitmapSnapshot(backimg, true);
                drawBoard.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
            }
        }