public static FrameworkElement LoadSvg(string filename) { var settings = new WpfDrawingSettings(); settings.IncludeRuntime = true; var renderer = new WpfDrawingRenderer(settings); renderer.LinkVisitor = new LinkVisitor(); renderer.ImageVisitor = new EmbeddedImageVisitor(); renderer.FontFamilyVisitor = new FontFamilyVisitor(); var svgWindow = new WpfSvgWindow(4096, 4096, renderer); svgWindow.LoadDocument(filename); svgWindow.Resize((int)svgWindow.Document.RootElement.Width.BaseVal.Value, (int)svgWindow.Document.RootElement.Height.BaseVal.Value); renderer.InvalidRect = SvgRectF.Empty; renderer.Render(svgWindow.Document as SvgDocument); var drawing = new System.Windows.Media.DrawingImage(); drawing.Drawing = renderer.Drawing; var image = new System.Windows.Controls.Image(); image.Source = drawing; image.Width = renderer.Window.InnerWidth; image.Height = renderer.Window.InnerHeight; return(image); }
/// <summary> /// Initializes a new instance of the <see cref="FileSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in XAML file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed XAML format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public FileSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(640, 480, _wpfRenderer); }
/// <summary> /// Initializes a new instance of the <see cref="FileSvgConverter"/> class /// with the specified drawing or rendering settings, the saving options /// and the working directory. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in XAML file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed XAML format, similar to the SVGZ. /// </param> /// <param name="workingDir"> /// The working directory, where converted outputs are saved. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public FileSvgReader(bool saveXaml, bool saveZaml, DirectoryInfo workingDir, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { long pixelWidth = 0; long pixelHeight = 0; if (settings != null && settings.HasPixelSize) { pixelWidth = settings.PixelWidth; pixelHeight = settings.PixelHeight; } _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(pixelWidth, pixelHeight, _wpfRenderer); _workingDir = workingDir; if (_workingDir != null) { if (!_workingDir.Exists) { _workingDir.Create(); } } }
public ShapeSvgCanvas() { _wpfRenderer = new WpfShapeRenderer(); _wpfRenderer.Canvas = this; _wpfWindow = new WpfSvgWindow(640, 480, _wpfRenderer); this.ClipToBounds = true; this.Bounds = Rect.Empty; }
/// <summary> /// This releases the unmanaged resources used by the <see cref="SvgConverter"/> /// and optionally releases the managed resources. /// </summary> /// <param name="disposing"> /// This is <see langword="true"/> if managed resources should be /// disposed; otherwise, <see langword="false"/>. /// </param> protected override void Dispose(bool disposing) { _drawing = null; _wpfWindow = null; _wpfRenderer = null; base.Dispose(disposing); }
/// <summary> /// Initializes a new instance of the <see cref="ImageSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in image file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed image format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public ImageSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { _encoderType = ImageEncoderType.PngBitmap; _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(640, 480, _wpfRenderer); }
public SvgShapeViewer() { _wpfRenderer = new WpfShapeRenderer(); _wpfRenderer.Canvas = this; _wpfWindow = new WpfSvgWindow(640, 480, _wpfRenderer); ClipToBounds = true; Bounds = Rect.Empty; }
private static Rect CalculateBounds(WpfSvgWindow window) { if (window.Document?.RootElement == null) { return(Rect.Empty); } var rect = window.Document.RootElement.GetBBox(); return(new Rect(rect.X, rect.Y, rect.Width, rect.Height)); }
/// <summary> /// Initializes a new instance of the <see cref="FileSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in XAML file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed XAML format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public FileSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { long pixelWidth = 0; long pixelHeight = 0; if (settings != null && settings.HasPixelSize) { pixelWidth = settings.PixelWidth; pixelHeight = settings.PixelHeight; } _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(pixelWidth, pixelHeight, _wpfRenderer); }
/// <summary> /// Initializes a new instance of the <see cref="FileSvgConverter"/> class /// with the specified drawing or rendering settings, the saving options /// and the working directory. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in XAML file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed XAML format, similar to the SVGZ. /// </param> /// <param name="workingDir"> /// The working directory, where converted outputs are saved. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public FileSvgReader(bool saveXaml, bool saveZaml, DirectoryInfo workingDir, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(640, 480, _wpfRenderer); _workingDir = workingDir; if (_workingDir != null) { if (!_workingDir.Exists) { _workingDir.Create(); } } }
/// <summary> /// Initializes a new instance of the <see cref="ImageSvgConverter"/> class /// with the specified drawing or rendering settings and the saving options. /// </summary> /// <param name="saveXaml"> /// This specifies whether to save result object tree in image file. /// </param> /// <param name="saveZaml"> /// This specifies whether to save result object tree in ZAML file. The /// ZAML is simply a G-Zip compressed image format, similar to the SVGZ. /// </param> /// <param name="settings"> /// This specifies the settings used by the rendering or drawing engine. /// If this is <see langword="null"/>, the default settings is used. /// </param> public ImageSvgConverter(bool saveXaml, bool saveZaml, WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings) { long pixelWidth = 0; long pixelHeight = 0; if (settings != null) { settings.EnsureViewboxSize = true; if (settings.HasPixelSize) { pixelWidth = settings.PixelWidth; pixelHeight = settings.PixelHeight; } } _encoderType = ImageEncoderType.PngBitmap; _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings); _wpfWindow = new WpfSvgWindow(pixelWidth, pixelHeight, _wpfRenderer); }