SvgSpecArt.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. // Use GcSvgDocument to render a few images used as illustrations
  22. // in the SVG spec.
  23. public class SvgSpecArt
  24. {
  25. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  26. {
  27. // Load images from resources:
  28. var fnames = new List<string>() { "dash-path.svg", "opacity.svg", "paths.svg", "shadowstyle.svg", "units.svg", };
  29. var images = new List<(string, GcSvgDocument)>();
  30. foreach (var f in fnames)
  31. images.Add((f, GcSvgDocument.FromFile(Path.Combine("Resources", "SvgSpecArt", f))));
  32.  
  33. float margin = dpi / 2;
  34. float gapy = dpi / 4;
  35. var ip = new PointF(margin, margin);
  36.  
  37. // Render the images:
  38. var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
  39. using var g = bmp.CreateGraphics(Color.White);
  40. for (int i = 0; i < images.Count(); ++i)
  41. {
  42. var svg = images[i].Item2;
  43. var s = svg.GetIntrinsicSize(SvgLengthUnits.Pixels);
  44. g.DrawSvg(svg, ip);
  45. ip.Y += s.Height + gapy;
  46. }
  47. // Dispose images after saving the result:
  48. images.ForEach(t_ => t_.Item2.Dispose());
  49. // Done:
  50. return bmp;
  51. }
  52. }
  53. }
  54.