RenderSvgText.cs
  1. //
  2. // This code is part of Document Solutions for Imaging demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Numerics;
  11. using GrapeCity.Documents.Drawing;
  12. using GrapeCity.Documents.Text;
  13. using GrapeCity.Documents.Imaging;
  14. using GrapeCity.Documents.Svg;
  15. using GCTEXT = GrapeCity.Documents.Text;
  16. using GCDRAW = GrapeCity.Documents.Drawing;
  17. using DsImagingWeb.Demos.Common;
  18.  
  19. namespace DsImagingWeb.Demos
  20. {
  21. // TBD:
  22. public class RenderSvgText
  23. {
  24. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  25. {
  26. // Load an SVG with text and tspan:
  27. var svgString =
  28. "<svg width='12cm' height='3cm' viewBox='0 0 1000 300' xmlns='http://www.w3.org/2000/svg' version='1.1'>" +
  29. " <g font-family='Verdana' font-size='64' >" +
  30. " <text x='160' y='180' fill='blue'>Apples are not <tspan font-weight='bold' fill='orange'>oranges</tspan>.</text>" +
  31. " </g>" +
  32. "</svg>";
  33. using var svg = GcSvgDocument.FromString(svgString);
  34.  
  35. // Render the SVG image and a border around it:
  36. var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
  37. using var g = bmp.CreateGraphics(Color.White);
  38. var pt = new PointF(dpi, dpi);
  39. g.DrawSvg(svg, pt);
  40. var sz = svg.GetIntrinsicSize(SvgLengthUnits.Pixels);
  41. g.DrawRectangle(new RectangleF(pt, sz), Color.MediumPurple);
  42.  
  43. // Done:
  44. return bmp;
  45. }
  46. }
  47. }
  48.