public void Render_Barcode1D() { // Arrange IBarcodeIntCS barcode = Code128.Encode("Wikipedia"); var renderer = new SvgRenderer(); // Act string svg; using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) { renderer.Render(barcode, stream); stream.Position = 0; svg = reader.ReadToEnd(); } // Assert svg.Length.Should().BeGreaterOrEqualTo(0); string expected; using (Stream stream = typeof(SvgRendererTests).Assembly.GetManifestResourceStream("Barcoder.Renderer.Svg.Tests.ExpectedSvgOutput.txt")) using (var reader = new StreamReader(stream)) expected = reader.ReadToEnd().Replace("\r", "").Replace("\n", ""); var actual = svg.Replace("\r", "").Replace("\n", ""); actual.Should().Be(expected); }
/// <summary> /// /// </summary> /// <param name="sourcePath"></param> /// <param name="device"></param> protected override void Render(string sourcePath, IDevice device) { using (SVGDocument document = new SVGDocument(sourcePath)) { var renderer = new SvgRenderer(); renderer.Render(device, document); } }
public void Render_Ean8_IncludeContentAsText() { var renderer = new SvgRenderer(includeEanContentAsText: true); IBarcode barcode = EanEncoder.Encode("1234567"); using Stream stream = File.OpenWrite(@"d:\temp\ean-test.svg"); renderer.Render(barcode, stream); }
protected override void Render(RenderingWorkUnit[] workUnits, ConversionApplicationOptions options, string outputFilePath) { using (var renderer = new SvgRenderer()) using (var device = GetOutputDevice(options, outputFilePath)) { renderer.Render(device, ConversionApplication.DEFAULT_RENDERING_TIMEOUT, workUnits.Cast <SVGDocumentRenderingWorkUnit>().Select(x => x.Data).ToArray()); } }
protected override void Render(RenderingWorkUnit workUnit, ConversionApplicationOptions options, string outputFilePath) { var wi = ((SVGDocumentRenderingWorkUnit)workUnit); using (var renderer = new SvgRenderer()) using (var device = GetOutputDevice(options, outputFilePath)) { renderer.Render(device, wi.Data, ConversionApplication.DEFAULT_RENDERING_TIMEOUT); } }
public void Render_PassNullAsOutputStream_ShouldThrowException() { // Arrange var renderer = new SvgRenderer(); var barcodeMock = new Mock <IBarcode>(); // Act Action action = () => renderer.Render(barcodeMock.Object, null); // Assert action.Should().Throw <ArgumentNullException>() .And.ParamName.Should().Be("outputStream"); }
public void Render_PassNullAsBarcode_ShouldThrowException() { // Arrange var renderer = new SvgRenderer(); var stream = new MemoryStream(); // Act Action action = () => renderer.Render(null, stream); // Assert action.Should().Throw <ArgumentNullException>() .And.ParamName.Should().Be("barcode"); }
public static void Run() { //ExStart: ConvertSVGFilesUsingRenderer string dataDir = RunExamples.GetDataDir_Data(); using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg"))) { using (SvgRenderer renderer = new SvgRenderer()) using (XpsDevice device = new XpsDevice(dataDir + "ConvertSVGFilesUsingRenderer_out.xps")) { renderer.Render(device, document); } } //ExEnd: ConvertSVGFilesUsingRenderer }
private void button_toVector_Click(object sender, EventArgs e) { StartEvent(); SvgRenderer svg = new SvgRenderer(); SvgRenderer.SvgImage si = svg.Render(qrCodeWriter.Encode(qCode), qrCodeWriter.Format, qCode); var file = File.Open("D:\\a.eps", FileMode.OpenOrCreate); byte[] b = Encoding.UTF8.GetBytes(si.ToString()); file.Write(b, 0, b.Length); file.Close(); application.ActiveLayer.Import("D:\\a.eps"); //File.Delete("D:\\a.eps"); EndEvent(); }
public static void Run() { // ExStart:1 string dataDir = RunExamples.GetDataDir_Data(); using (var document = new Aspose.Html.Dom.Svg.SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", @"c:\work\")) { using (SvgRenderer renderer = new SvgRenderer()) using (ImageDevice device = new ImageDevice(dataDir + @"document_out.png")) { renderer.Render(device, document); } } // ExEnd:1 }
public static void Save(Control?control, Size size, string path) { if (control is null) { return; } if (path.EndsWith("png", StringComparison.OrdinalIgnoreCase)) { PngRenderer.Render(control, size, path); } if (path.EndsWith("svg", StringComparison.OrdinalIgnoreCase)) { using var stream = File.Create(path); SvgRenderer.Render(control, size, stream); } if (path.EndsWith("pdf", StringComparison.OrdinalIgnoreCase)) { using var stream = File.Create(path); PdfRenderer.Render(control, size, stream, 96); } if (path.EndsWith("xps", StringComparison.OrdinalIgnoreCase)) { using var stream = File.Create(path); XpsRenderer.Render(control, size, stream, 96); } if (path.EndsWith("skp", StringComparison.OrdinalIgnoreCase)) { using var stream = File.Create(path); SkpRenderer.Render(control, size, stream); } }
/// <summary> /// /// </summary> /// <param name="sourcePathList"></param> /// <param name="device"></param> protected override void Render(string[] sourcePathList, IDevice device) { SVGDocument[] docList = sourcePathList.Select <string, SVGDocument>( path => new SVGDocument(path)) .ToArray(); try { using (SvgRenderer renderer = new SvgRenderer()) { renderer.Render(device, docList); } } catch (Exception ex) { throw ex; } finally { foreach (var doc in docList) { doc.Dispose(); } } }
public async Task ProcessRequest() { var msg = $"{_context.Request.HttpMethod} {_context.Request.Url}"; Console.WriteLine(msg); var url = _context.Request.RawUrl; if (url != null && url != "/" && url != "" && url != "/new" && url != "/close") { _context.Response.StatusCode = 401; _context.Response.Close(); return; } var sb = new StringBuilder(); sb.AppendLine("<html>"); sb.AppendLine("<head>"); sb.AppendLine(" <link rel=\"icon\" href=\"data:;base64,iVBORw0KGgo=\">"); sb.AppendLine("</head>"); sb.AppendLine("<body>"); await Utilities.RunUiJob(() => { var control = Repl.GetMainView(); if (control is null) { return; } switch (url) { case "/new": (control.DataContext as ProjectEditorViewModel)?.OnNew(null); Dispatcher.UIThread.RunJobs(); break; case "/close": (control.DataContext as ProjectEditorViewModel)?.OnCloseProject(); Dispatcher.UIThread.RunJobs(); break; } Console.WriteLine($"Rendering..."); var sw = new Stopwatch(); sw.Start(); var size = new Size(1366, 690); using var stream = new MemoryStream(); SvgRenderer.Render(control, size, stream); stream.Position = 0; using var reader = new StreamReader(stream); var svg = reader.ReadToEnd(); sb.AppendLine(svg); sw.Stop(); Console.WriteLine($"Done in {sw.ElapsedMilliseconds}ms"); }); sb.AppendLine("</body></html>"); var bytes = Encoding.UTF8.GetBytes(sb.ToString()); _context.Response.ContentLength64 = bytes.Length; _context.Response.ContentType = "text/html"; _context.Response.StatusCode = 200; _context.Response.OutputStream.Write(bytes, 0, bytes.Length); _context.Response.OutputStream.Close(); }