void LoadSVG(string fname) { SVGParser p = new SVGParser(m_SVGPath); p.Parse(fname); m_SVGPath.ArrangeOrientations(); m_SVGPathBounds = m_SVGPath.Bounds; m_ScaleSlider.Value = (float)(System.Math.Min(m_DrawingPanel.ClientWidth / m_SVGPathBounds.Width, m_DrawingPanel.ClientHeight / m_SVGPathBounds.Height) * 0.75); }
public override void OnImportAsset(AssetImportContext ctx) { string svgStr = null; using (StreamReader reader = new StreamReader(ctx.assetPath)) svgStr = reader.ReadToEnd(); SVGParser svgParser = new SVGParser(); GameObject svgObj = svgParser.Parse(svgStr, _stripGroups); ctx.AddObjectToAsset("SVG root", svgObj); ctx.SetMainObject(svgObj); }
public ICollection <TikzShape> ConvertMany(string data) { try { File.WriteAllText("job.txt", data); //3. Call latex for conversion to DVI Process latex = new Process(); latex.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; latex.StartInfo.FileName = "latex"; latex.StartInfo.Arguments = "-shell-escape -quiet job.txt"; latex.StartInfo.UseShellExecute = true; latex.StartInfo.CreateNoWindow = true; latex.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; latex.Start(); latex.WaitForExit(100000); //wait 10s before terminating if (latex.ExitCode != 0) { throw new Exception("Latex conversion failed"); } //4. Call dvisvgm to convert dvi to svg that we can easily parse Process dvi2svg = new Process(); dvi2svg.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; dvi2svg.StartInfo.FileName = "dvisvgm"; dvi2svg.StartInfo.Arguments = "-n -v 0 -o job.svg job.dvi"; dvi2svg.StartInfo.CreateNoWindow = true; dvi2svg.StartInfo.UseShellExecute = true; dvi2svg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; dvi2svg.Start(); dvi2svg.WaitForExit(100000); //wait 10s before terminating if (dvi2svg.ExitCode != 0) { throw new Exception("DVI conversion failed"); } string svg = File.ReadAllText("job.svg"); return(SVGParser.Parse(svg)); } catch (Exception e) { Debug.WriteLine(e.Message); return(new List <TikzShape> { }); } }
void LoadSVG(string fname) { SVGParser p = new SVGParser(m_SVGPath); p.Parse(fname); m_SVGPath.ArrangeOrientations(); m_SVGPathBounds = m_SVGPath.Bounds; m_Scale = System.Math.Min(m_DrawingPanel.ClientWidth / m_SVGPathBounds.Width, m_DrawingPanel.ClientHeight / m_SVGPathBounds.Height) * 0.75; m_SVGPathScaledBounds = m_SVGPathBounds - m_SVGPathBounds.Location; m_SVGPathScaledBounds.Width *= m_Scale; m_SVGPathScaledBounds.Height *= m_Scale; m_SVGPathScaledBounds += new Point(m_x, m_y) - m_SVGPathScaledBounds.Center; m_PolygonElement.SetXn(0, m_SVGPathScaledBounds.Left); m_PolygonElement.SetYn(0, m_SVGPathScaledBounds.Top); m_PolygonElement.SetXn(1, m_SVGPathScaledBounds.Right); m_PolygonElement.SetYn(1, m_SVGPathScaledBounds.Top); m_PolygonElement.SetXn(2, m_SVGPathScaledBounds.Right); m_PolygonElement.SetYn(2, m_SVGPathScaledBounds.Bottom); m_PolygonElement.SetXn(3, m_SVGPathScaledBounds.Left); m_PolygonElement.SetYn(3, m_SVGPathScaledBounds.Bottom); }
public ICollection <TikzShape> ConvertMany(string data) { SaveData d = JsonSerializer.Deserialize <SaveData>(data); List <TikzShape> result = new List <TikzShape>(); ITool currentTool; foreach (LocalShapeData shapeData in d.localShapeData) { currentTool = toolNameToolMap[shapeData.ToolName]; foreach (CanvasEventArgs canvasEventArgs in shapeData.KeyPoints) { DrawingShape r = currentTool.GetShape(canvasEventArgs, shapeData.Style); if (r.ShapeState == ShapeState.FINISHED) { result.Add(r.TikzShape); } } } foreach (SvgData raw in d.svgRawData) { List <TikzShape> c = SVGParser.Parse(raw.data); foreach (TikzShape s in c) { Canvas.SetLeft(s.Shape, raw.translate.X); Canvas.SetTop(s.Shape, raw.translate.Y); s.TikzStyle = raw.style; s.Shape.SetStyle(raw.style); } result.AddRange(c); } return(result); }