private static int ConvertToXg(ConvertToXgOptions convertToXgOptions) { foreach (string inputFileName in convertToXgOptions.InputFiles) { SvgImporter.SvgImporter svgImporter = new SvgImporter.SvgImporter(); using FileStream inputStream = File.Open(inputFileName, FileMode.Open); XCanvas xCanvas = svgImporter.Import(inputStream); string outputFileName = Path.ChangeExtension(inputFileName, ".xg"); using FileStream outputStream = File.Open(outputFileName, FileMode.Create); new XGraphicsExporter(xCanvas).Export(outputStream); } return(0); }
public ICanvas Read(BinaryReader reader) { _reader = reader; _natives = new Dictionary<int, INative>(); // read binary points _bpoints = new Dictionary<int, BPoint>(); int length = _reader.ReadInt32(); for (int i = 0; i < length; i++) { var bpoint = ReadBPoint(); _bpoints.Add(bpoint.Id, bpoint); } // read canvas contents var nativeType = ReadNativeType(); if (nativeType != NativeType.Canvas) { throw new InvalidDataException(); } var canvas = new XCanvas() { Id = _reader.ReadInt32(), Width = _reader.ReadDouble(), Height = _reader.ReadDouble(), Background = ReadColor(), EnableSnap = _reader.ReadBoolean(), SnapX = _reader.ReadDouble(), SnapY = _reader.ReadDouble() }; var children = canvas.Children; while (reader.BaseStream.Position != reader.BaseStream.Length) { var type = ReadNativeType(); switch (type) { case NativeType.Pin: children.Add(ReadPin()); break; case NativeType.Line: children.Add(ReadLine()); break; case NativeType.Bezier: children.Add(ReadBezier()); break; case NativeType.QuadraticBezier: children.Add(ReadQuadraticBezier()); break; case NativeType.Arc: children.Add(ReadArc()); break; case NativeType.Rectangle: children.Add(ReadRectangle()); break; case NativeType.Ellipse: children.Add(ReadEllipse()); break; case NativeType.Text: children.Add(ReadText()); break; case NativeType.Block: children.Add(ReadBlock()); break; case NativeType.End: _reader = null; UpdatePointConnections(); return canvas; default: _reader = null; throw new InvalidDataException(); } } _reader = null; throw new InvalidDataException(); }
public XGraphicsExporter(XCanvas canvas) => _canvas = canvas;
private void PaintGraphicsElements(IEnumerable <IGraphicsElement> graphicsElements) { foreach (IGraphicsElement graphicsElement in graphicsElements) { ITransform?renderTransform = graphicsElement.RenderTransform; if (renderTransform != null) { skCanvas.Save(); ApplyTransform(renderTransform, graphicsElement); } if (graphicsElement is IPath path) { PaintPath(path); } else if (graphicsElement is ICanvas canvas) { // TODO: Handle canvas offset / transform PaintGraphicsElements(canvas.Children); } else if (graphicsElement is IShape shape) { SKPath skiaPath = NonPathShapeToSkiaPath(shape); FillSkiaPath(skiaPath, shape); StrokeSkiaPath(skiaPath, shape); } else if (graphicsElement is IImage image) { IImageSource imageSource = image.Source; if (imageSource is ILoadableImageSource loadableImageSource) { LoadingStatus loadingStatus = loadableImageSource.LoadingStatus; if (loadingStatus == LoadingStatus.NotStarted) { _imageLoader.LoadImage(loadableImageSource, null); } else if (loadingStatus == LoadingStatus.Succeeded) { LoadedImage loadedImage = loadableImageSource.LoadedImage !; if (loadedImage is BitmapLoadedImage bitmapLoadedImage) { SKBitmap bitmap = (SKBitmap)bitmapLoadedImage.ImageObject; // TODO: Render it } else if (loadedImage is VectorLoadedImage vectorLoadedImage) { XCanvas childCanvas = vectorLoadedImage.Canvas; PaintGraphicsElements(childCanvas.Children); } } } } else { throw new InvalidOperationException($"Unknown graphics element type {graphicsElement.GetType()}"); } if (renderTransform != null) { skCanvas.Restore(); } } }
public VectorLoadedImage(XCanvas canvas) { Canvas = canvas; }
public ICanvas Read(BinaryReader reader) { _reader = reader; _natives = new Dictionary <int, INative>(); // read binary points _bpoints = new Dictionary <int, BPoint>(); int length = _reader.ReadInt32(); for (int i = 0; i < length; i++) { var bpoint = ReadBPoint(); _bpoints.Add(bpoint.Id, bpoint); } // read canvas contents var nativeType = ReadNativeType(); if (nativeType != NativeType.Canvas) { throw new InvalidDataException(); } var canvas = new XCanvas() { Id = _reader.ReadInt32(), Width = _reader.ReadDouble(), Height = _reader.ReadDouble(), Background = ReadColor(), EnableSnap = _reader.ReadBoolean(), SnapX = _reader.ReadDouble(), SnapY = _reader.ReadDouble() }; var children = canvas.Children; while (reader.BaseStream.Position != reader.BaseStream.Length) { var type = ReadNativeType(); switch (type) { case NativeType.Pin: children.Add(ReadPin()); break; case NativeType.Line: children.Add(ReadLine()); break; case NativeType.Bezier: children.Add(ReadBezier()); break; case NativeType.QuadraticBezier: children.Add(ReadQuadraticBezier()); break; case NativeType.Arc: children.Add(ReadArc()); break; case NativeType.Rectangle: children.Add(ReadRectangle()); break; case NativeType.Ellipse: children.Add(ReadEllipse()); break; case NativeType.Text: children.Add(ReadText()); break; case NativeType.Block: children.Add(ReadBlock()); break; case NativeType.End: _reader = null; UpdatePointConnections(); return(canvas); default: _reader = null; throw new InvalidDataException(); } } _reader = null; throw new InvalidDataException(); }