public void Test_SvgGraphics() { using (MemoryStream stm = new MemoryStream()) { var svg = new SvgGraphics(stm, ExtRectF.CreateBounds(0, 0, 100, 100)); svg.BeginDrawing(); svg.Clear(UIHelper.ConvertColor(Color.Yellow)); svg.BeginEntity(null); svg.DrawLine(10, 10, 50, 10, 1); svg.DrawArc(60, 60, 20, 15, 25, 1); svg.DrawEllipse(10, 10, 30, 30, null, null); svg.DrawRect(50, 50, 20, 20, 2); svg.DrawRoundedRect(80, 80, 10, 10, 3, 1); svg.EndEntity(); svg.FillArc(60, 60, 20, 15, 25); svg.DrawEllipse(10, 10, 30, 30, null, null); svg.FillRect(50, 50, 20, 20); svg.SetColor(UIHelper.ConvertColor(Color.Red)); svg.FillRoundedRect(80, 80, 10, 10, 3); svg.DrawCircleSegment(0, 0, 10, 20, 0, 17, null, null); svg.DrawImage(null, 0, 0, 100, 100); svg.DrawPolygon(new ExtPointF[] {}, null, null); svg.DrawString("x", 10, 10); svg.ResetState(); svg.SaveState(); svg.RestoreState(); svg.Rotate(75); svg.Translate(10, 10); svg.Scale(0.5f, 0.5f); svg.SetClippingRect(0.0f, 0.0f, 10f, 10f); svg.SetFont(null); Assert.Throws(typeof(ArgumentNullException), () => { svg.SetColor(null); }); svg.BeginLines(false); svg.EndLines(); svg.EndDrawing(); } }
public ActionResult Draw(string m, string f) { var str = Encoding.UTF8.GetString(Convert.FromBase64String(m)); var model = JsonConvert.DeserializeObject <BalustradeDrawingModel>(str); var balustrade = CreateBalustradeFromDrawingModel(model); if (f == "pdf") { var fileName = "Drawing_" + balustrade.BalustradeViews[balustrade.CurrentViewIndex].Name; var memStream = new MemoryStream(); using (var doc = balustrade.CreatePdf()) { doc.Info.Title = fileName; doc.Save(memStream); } Response.AddHeader("content-disposition", String.Format("inline; filename={0}.pdf; size={1}", fileName, memStream.Length)); return(new FileStreamResult(memStream, "application/pdf")); } var svgGraphics = new SvgGraphics(); svgGraphics.Clear(Color.White); balustrade.Paint(svgGraphics); return(Json(new { svg = svgGraphics.WriteSVGString(), price = balustrade.SellingPrice, onlineDrawingDiscount = balustrade.BalustradeSystem.OnlineDrawingDiscount, vatPercent = DbSession.CurrentUser()?.DefaultCompany?.VatPercent ?? 0D, withPosts = balustrade.RawBalustradeSections.Any(s => s.Posts.Count > 0) }, JsonRequestBehavior.AllowGet)); }