public void Paint(Painter p) { using (VgPaintArgsPool.Borrow(p, out var paintArgs)) { paintArgs._currentTx = _currentTx; _vgVisElem.Paint(paintArgs); } }
public void Paint(Painter p) { using (Tools.More.BorrowVgPaintArgs(p, out var paintArgs)) { paintArgs._currentTx = _currentTx; _vgVisElem.Paint(paintArgs); } }
protected override void RenderClientContent(DrawBoard d, UpdateArea updateArea) { using (Tools.More.BorrowVgPaintArgs(d.GetPainter(), out var paintArgs)) { _renderVx.Paint(paintArgs); } //d.FillRectangle(Color.Blue, 0, 0, 50, 50); }
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; PixelFarm.CpuBlit.VertexProcessing.Q1RectD 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 (Tools.BorrowAggPainter(memBitmap, out var p)) using (Tools.More.BorrowVgPaintArgs(p, out var 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); }
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); }
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 (Tools.More.BorrowVgPaintArgs(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 (Tools.More.BorrowVgPaintArgs(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)); } }
public static void ParseAndRenderSvg(PixelFarm.Drawing.SvgBmpBuilderReq req) { //---------- //copy from HtmlRenderer's SvgViewer demo //---------- var docBuilder = new VgDocBuilder(); var parser = new SvgParser(docBuilder); TextSnapshot textSnapshot = new TextSnapshot(req.SvgContent.ToString()); parser.ParseDocument(textSnapshot); VgVisualDocBuilder builder = new VgVisualDocBuilder(); VgVisualElement vgVisElem = builder.CreateVgVisualDoc(docBuilder.ResultDocument, _vgDocHost).VgRootElem; PixelFarm.CpuBlit.VertexProcessing.Q1RectD bounds = vgVisElem.GetRectBounds(); float actualXOffset = (float)-bounds.Left; float actualYOffset = (float)-bounds.Bottom; //original svg width, height int bmpW = (int)Math.Round(bounds.Width); int bmpH = (int)Math.Round(bounds.Height); if (bmpW == 0 || bmpH == 0) { return; } //scale svg to specific size float scale_w = req.ExpectedWidth / bmpW; //at this point, we have 2 options //1) create bitmap with original svg size and scale it down to expected size //2) scale svg to expected size and create a bitmap //we choose 2) int new_w = (int)Math.Round(bmpW * scale_w); int new_h = (int)Math.Round(bmpH * scale_w); MemBitmap memBitmap = new MemBitmap(new_w, new_h); using (Tools.BorrowAggPainter(memBitmap, out var p)) using (Tools.More.BorrowVgPaintArgs(p, out VgPaintArgs paintArgs)) { //pass by Affine tx = Affine.NewScaling(scale_w); paintArgs._currentTx = tx; float orgX = p.OriginX; float orgY = p.OriginY; p.SetOrigin(actualXOffset * scale_w, actualYOffset * scale_w); p.Clear(req.DefaultBgColor); p.FillColor = PixelFarm.Drawing.Color.Black; double prevStrokeW = p.StrokeWidth; vgVisElem.Paint(paintArgs); p.StrokeWidth = prevStrokeW; //restore p.SetOrigin(orgX, orgY); //restore } #if DEBUG //memBitmap.SaveImage("svg.png"); #endif req.Output = memBitmap; }