RenderSvgText.cs
//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//using System.Drawing;using GrapeCity.Documents.Imaging;using GrapeCity.Documents.Svg;
namespace DsImagingWeb.Demos{ // TBD: public class RenderSvgText { public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) { // Load an SVG with text and tspan: var svgString = "<svg width='12cm' height='3cm' viewBox='0 0 1000 300' xmlns='http://www.w3.org/2000/svg' version='1.1'>" + " <g font-family='Verdana' font-size='64' >" + " <text x='160' y='180' fill='blue'>Apples are not <tspan font-weight='bold' fill='orange'>oranges</tspan>.</text>" + " </g>" + "</svg>"; using var svg = GcSvgDocument.FromString(svgString);
// Render the SVG image and a border around it: var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi); using var g = bmp.CreateGraphics(Color.White); var pt = new PointF(dpi, dpi); g.DrawSvg(svg, pt); var sz = svg.GetIntrinsicSize(SvgLengthUnits.Pixels); g.DrawRectangle(new RectangleF(pt, sz), Color.MediumPurple);
// Done: return bmp; } }}