public SVGGraphicsStroke(SVGGraphics graphics) { _graphics = graphics; _basicDraw = new SVGBasicDraw(); _basicDraw.SetPixelMethod = new SetPixelDelegate(SetPixel); }
// What to do when the user wants to export a SVG or TeX file private void exportHandler(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "SVG image|*.svg|TeX file|*.tex"; saveFileDialog.RestoreDirectory = true; if(saveFileDialog.ShowDialog() == DialogResult.OK) { IGraphics graphics; switch (saveFileDialog.FilterIndex) { case 1: graphics = new SVGGraphics(saveFileDialog.FileName); break; case 2: graphics = new TexGraphics(saveFileDialog.FileName); break; default: throw new Exception("savefiledialog filterindex: " + saveFileDialog.FilterIndex + " not supported"); break; } this.drawShapes(graphics); } }
public SVGPolylineElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _listPoints = ExtractPoints(attrList.GetValue("points")); }
/***********************************************************************************/ public SVGPathElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { _attrList = attrList; _paintable = new SVGPaintable(inheritPaintable, attrList); _render = r; Initial(); }
public SVGPolylineElement(Dictionary<string,string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _listPoints = ExtractPoints(attrList.GetValue("points")); }
protected SVGBasicElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _render = render; _paintable = new SVGPaintable(inheritPaintable, attrList); }
public SVGCircleElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _r = new SVGLength(attrList.GetValue("r")); }
protected SVGBasicElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _render = render; _paintable = new SVGPaintable(inheritPaintable, attrList); }
public SVGDocument(string originalDocument, SVGGraphics r) { parser = new SVGParser(originalDocument); while (!parser.isEOF && parser.node.name != SVGNodeName.SVG) parser.Next(); _rootElement = new SVGElement(parser, new SVGTransformList(), null, true); }
public SVGCircleElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _r = new SVGLength(attrList.GetValue("r")); }
//================================================================================ public SVGPolygonElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._render = _render; this._paintable = new SVGPaintable(inheritPaintable, attrList); this._listPoints = ExtractPoints(this._attrList.GetValue("points")); }
public static void Clear() { if (atlasData != null) { atlasData.Clear(); atlasData = null; } SVGParser.Clear(); SVGGraphics.Clear(); }
//================================================================================ public SVGPolylineElement( AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._render = _render; this._paintable = new SVGPaintable(inheritPaintable, attrList); this._listPoints = ExtractPoints(this._attrList.GetValue("points")); }
public SVGGraphicsFill(SVGGraphics _graphics) { graphics = _graphics; flagStep = 0; width = 0; height = 0; subW = subH = 0; //Basic Draw basicDraw = new SVGBasicDraw { SetPixelMethod = SetPixelForFlag }; }
public SVGEllipseElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); currentTransformList = new SVGTransformList(attrList.GetValue("transform")); }
public SVGGraphicsFill(SVGGraphics graphics) { _graphics = graphics; _flagStep = 0; _width = 0; _height = 0; _subW = _subH = 0; //Basic Draw _basicDraw = new SVGBasicDraw {SetPixelMethod = SetPixelForFlag}; }
public SVGDocument(string originalDocument, SVGGraphics r) { parser = new SVGParser(originalDocument); while (!parser.isEOF && parser.node.name != SVGNodeName.SVG) { parser.Next(); } _rootElement = new SVGElement(parser, new SVGTransformList(), null, true); }
public SVGGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _render = render; Dictionary<string, string> attrList = xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, attrList); currentTransformList = new SVGTransformList(attrList.GetValue("transform")); xmlImp.GetElementList(_elementList, _paintable, _render, summaryTransformList); }
public SVGGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _render = render; Dictionary <string, string> attrList = xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, attrList); currentTransformList = new SVGTransformList(attrList.GetValue("transform")); xmlImp.GetElementList(_elementList, _paintable, _render, summaryTransformList); }
public SVGLineElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _paintable = new SVGPaintable(inheritPaintable, attrList); _render = render; _x1 = new SVGLength(attrList.GetValue("x1")); _y1 = new SVGLength(attrList.GetValue("y1")); _x2 = new SVGLength(attrList.GetValue("x2")); _y2 = new SVGLength(attrList.GetValue("y2")); }
//================================================================================ public SVGCircleElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._render = _render; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._cx = new SVGLength(attrList.GetValue("cx")); this._cy = new SVGLength(attrList.GetValue("cy")); this._r = new SVGLength(attrList.GetValue("r")); }
public SVGEllipseElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); currentTransformList = new SVGTransformList(attrList.GetValue("transform")); }
public SVGRectElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _x = new SVGLength(attrList.GetValue("x")); _y = new SVGLength(attrList.GetValue("y")); _width = new SVGLength(attrList.GetValue("width")); _height = new SVGLength(attrList.GetValue("height")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); }
public SVGRectElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _x = new SVGLength(attrList.GetValue("x")); _y = new SVGLength(attrList.GetValue("y")); _width = new SVGLength(attrList.GetValue("width")); _height = new SVGLength(attrList.GetValue("height")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); }
public SVGLineElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _paintable = new SVGPaintable(inheritPaintable, attrList); _render = render; _x1 = new SVGLength(attrList.GetValue("x1")); _y1 = new SVGLength(attrList.GetValue("y1")); _x2 = new SVGLength(attrList.GetValue("x2")); _y2 = new SVGLength(attrList.GetValue("y2")); }
/***********************************************************************************/ public SVGLineElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._render = _render; this._x1 = new SVGLength(attrList.GetValue("x1")); this._y1 = new SVGLength(attrList.GetValue("y1")); this._x2 = new SVGLength(attrList.GetValue("x2")); this._y2 = new SVGLength(attrList.GetValue("y2")); }
/***********************************************************************************/ public SVGGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _render = render; _xmlImp = xmlImp; _attrList = _xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, _attrList); _elementList = new List <object>(); currentTransformList = new SVGTransformList(_attrList.GetValue("transform")); GetElementList(); }
/***********************************************************************************/ public SVGSVGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { _render = r; _xmlImp = xmlImp; _attrList = _xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, _attrList); _width = new SVGLength(_attrList.GetValue("width")); _height = new SVGLength(_attrList.GetValue("height")); Initial(); }
public SVGGraphicsFill(SVGGraphics graphics) { _graphics = graphics; _flagStep = 0; _width = 0; _height = 0; _subW = _subH = 0; //Basic Draw _basicDraw = new SVGBasicDraw { SetPixelMethod = SetPixelForFlag }; }
public SVGGraphicsFill(SVGGraphics graphics) { this._graphics = graphics; this._flagStep = 0; this._width = 0; this._height = 0; this._translateX = 0; this._translateY = 0; this._subW = this._subH = 0; //Basic Draw this._basicDraw = new SVGBasicDraw(); this._basicDraw.SetPixelMethod = new SetPixelDelegate(SetPixelForFlag); }
/***********************************************************************************/ public SVGGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _render = render; _xmlImp = xmlImp; _attrList = _xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, _attrList); _elementList = new List<object>(); currentTransformList = new SVGTransformList(_attrList.GetValue("transform")); GetElementList(); }
/***********************************************************************************/ public SVGSVGElement( SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { _render = r; _xmlImp = xmlImp; _attrList = _xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, _attrList); _width = new SVGLength(_attrList.GetValue("width")); _height = new SVGLength(_attrList.GetValue("height")); Initial(); }
/***********************************************************************************/ public SVGLineElement( AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._render = _render; this._x1 = new SVGLength(attrList.GetValue("x1")); this._y1 = new SVGLength(attrList.GetValue("y1")); this._x2 = new SVGLength(attrList.GetValue("x2")); this._y2 = new SVGLength(attrList.GetValue("y2")); }
//================================================================================ public SVGRectElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._render = _render; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._x = new SVGLength(attrList.GetValue("x")); this._y = new SVGLength(attrList.GetValue("y")); this._width = new SVGLength(attrList.GetValue("width")); this._height = new SVGLength(attrList.GetValue("height")); this._rx = new SVGLength(attrList.GetValue("rx")); this._ry = new SVGLength(attrList.GetValue("ry")); }
public void GetElementList(List <ISVGDrawable> elementList, SVGPaintable paintable, SVGGraphics render, SVGTransformList summaryTransformList) { bool exitFlag = false; while (!exitFlag && Next()) { if (Node is BlockCloseNode) { exitFlag = true; continue; } switch (Node.Name) { case SVGNodeName.Rect: elementList.Add(new SVGRectElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Line: elementList.Add(new SVGLineElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Circle: elementList.Add(new SVGCircleElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Ellipse: elementList.Add(new SVGEllipseElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.PolyLine: elementList.Add(new SVGPolylineElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Polygon: elementList.Add(new SVGPolygonElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Path: elementList.Add(new SVGPathElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.SVG: elementList.Add(new SVGSVGElement(this, summaryTransformList, paintable, render)); break; case SVGNodeName.G: elementList.Add(new SVGGElement(this, summaryTransformList, paintable, render)); break; case SVGNodeName.LinearGradient: paintable.AppendLinearGradient(new SVGLinearGradientElement(this, Node.Attributes)); break; case SVGNodeName.RadialGradient: paintable.AppendRadialGradient(new SVGRadialGradientElement(this, Node.Attributes)); break; case SVGNodeName.Defs: GetElementList(elementList, paintable, render, summaryTransformList); break; case SVGNodeName.Title: GetElementList(elementList, paintable, render, summaryTransformList); break; case SVGNodeName.Desc: GetElementList(elementList, paintable, render, summaryTransformList); break; } } }
public SVGSVGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { _render = r; _attrList = xmlImp.Node.Attributes; var paintable = new SVGPaintable(inheritPaintable, _attrList); _width = new SVGLength(_attrList.GetValue("width")); _height = new SVGLength(_attrList.GetValue("height")); SetViewBox(); ViewBoxTransform(); SVGTransform temp = new SVGTransform(_cachedViewBoxTransform); SVGTransformList t_currentTransformList = new SVGTransformList(); t_currentTransformList.AppendItem(temp); currentTransformList = t_currentTransformList; // use setter only once, since it also updates other lists xmlImp.GetElementList(_elementList, paintable, _render, summaryTransformList); }
/***********************************************************************************/ public SvgAsset(ISVGDevice device, TextAsset svgFile = null) { this._SVGFile = svgFile; _device = device; _graphics = new SVGGraphics (_device); }
protected void ProduceResponse(HttpContext context, ITypeAccepter accepter, string title, RenderContext ctx, Size tileSize, AbstractMatrix transform, bool transparent = false, IDictionary <string, object> queryDefaults = null) { // New-style Options #region URL Parameters // TODO: move to ParseOptions (maybe - requires options to be parsed after stylesheet creation?) if (GetBoolOption("sscoords", queryDefaults: queryDefaults, defaultValue: false)) { ctx.Styles.hexCoordinateStyle = HexCoordinateStyle.Subsector; } if (GetBoolOption("allhexes", queryDefaults: queryDefaults, defaultValue: false)) { ctx.Styles.numberAllHexes = true; } if (GetBoolOption("nogrid", queryDefaults: queryDefaults, defaultValue: false)) { ctx.Styles.parsecGrid.visible = false; } if (!GetBoolOption("routes", queryDefaults: queryDefaults, defaultValue: true)) { ctx.Styles.macroRoutes.visible = false; ctx.Styles.microRoutes.visible = false; } if (!GetBoolOption("rifts", queryDefaults: queryDefaults, defaultValue: true)) { ctx.Styles.showRiftOverlay = false; } if (GetBoolOption("po", queryDefaults: queryDefaults, defaultValue: false)) { ctx.Styles.populationOverlay.visible = true; } if (GetBoolOption("im", queryDefaults: queryDefaults, defaultValue: false)) { ctx.Styles.importanceOverlay.visible = true; } if (GetBoolOption("cp", queryDefaults: queryDefaults, defaultValue: false)) { ctx.Styles.capitalOverlay.visible = true; } if (GetBoolOption("stellar", queryDefaults: queryDefaults, defaultValue: false)) { ctx.Styles.showStellarOverlay = true; } ctx.Styles.dimUnofficialSectors = GetBoolOption("dimunofficial", queryDefaults: queryDefaults, defaultValue: false); ctx.Styles.colorCodeSectorStatus = GetBoolOption("review", queryDefaults: queryDefaults, defaultValue: false); ctx.Styles.droyneWorlds.visible = GetBoolOption("dw", queryDefaults: queryDefaults, defaultValue: false); ctx.Styles.minorHomeWorlds.visible = GetBoolOption("mh", queryDefaults: queryDefaults, defaultValue: false); ctx.Styles.ancientsWorlds.visible = GetBoolOption("an", queryDefaults: queryDefaults, defaultValue: false); // TODO: Return an error if pattern is invalid? ctx.Styles.highlightWorldsPattern = HighlightWorldPattern.Parse( GetStringOption("hw", queryDefaults: queryDefaults, defaultValue: String.Empty).Replace(' ', '+')); ctx.Styles.highlightWorlds.visible = ctx.Styles.highlightWorldsPattern != null; double devicePixelRatio = GetDoubleOption("dpr", defaultValue: 1, queryDefaults: queryDefaults); devicePixelRatio = Math.Round(devicePixelRatio, 1); if (devicePixelRatio <= 0) { devicePixelRatio = 1; } if (devicePixelRatio > 2) { devicePixelRatio = 2; } bool dataURI = GetBoolOption("datauri", queryDefaults: queryDefaults, defaultValue: false); if (GetStringOption("milieu", SectorMap.DEFAULT_MILIEU) != SectorMap.DEFAULT_MILIEU) { // TODO: Make this declarative in resource files. if (ctx.Styles.macroBorders.visible) { ctx.Styles.macroBorders.visible = false; ctx.Styles.microBorders.visible = true; } ctx.Styles.macroNames.visible = false; ctx.Styles.macroRoutes.visible = false; } #endregion MemoryStream ms = null; if (dataURI) { ms = new MemoryStream(); } Stream outputStream = ms ?? Context.Response.OutputStream; if (accepter.Accepts(context, ContentTypes.Image.Svg, ignoreHeaderFallbacks: true)) { #region SVG Generation using (var svg = new SVGGraphics(tileSize.Width, tileSize.Height)) { RenderToGraphics(ctx, transform, svg); using (var stream = new MemoryStream()) { svg.Serialize(new StreamWriter(stream)); context.Response.ContentType = ContentTypes.Image.Svg; if (!dataURI) { context.Response.AddHeader("content-length", stream.Length.ToString()); context.Response.AddHeader("content-disposition", $"inline;filename=\"{Util.SanitizeFilename(title)}.svg\""); } stream.WriteTo(outputStream); } } #endregion } else if (accepter.Accepts(context, ContentTypes.Application.Pdf, ignoreHeaderFallbacks: true)) { #region PDF Generation using (var document = new PdfDocument()) { document.Version = 14; // 1.4 for opacity document.Info.Title = title; document.Info.Author = "Joshua Bell"; document.Info.Creator = "TravellerMap.com"; document.Info.Subject = DateTime.Now.ToString("F", CultureInfo.InvariantCulture); document.Info.Keywords = "The Traveller game in all forms is owned by Far Future Enterprises. Copyright (C) 1977 - 2019 Far Future Enterprises. Traveller is a registered trademark of Far Future Enterprises."; // TODO: Credits/Copyright // This is close, but doesn't define the namespace correctly: // document.Info.Elements.Add( new KeyValuePair<string, PdfItem>( "/photoshop/Copyright", new PdfString( "HelloWorld" ) ) ); PdfPage page = document.AddPage(); // NOTE: only PageUnit currently supported in MGraphics is Points page.Width = XUnit.FromPoint(tileSize.Width); page.Height = XUnit.FromPoint(tileSize.Height); using (var gfx = new PdfSharpGraphics(XGraphics.FromPdfPage(page))) { RenderToGraphics(ctx, transform, gfx); using (var stream = new MemoryStream()) { document.Save(stream, closeStream: false); context.Response.ContentType = ContentTypes.Application.Pdf; if (!dataURI) { context.Response.AddHeader("content-length", stream.Length.ToString()); context.Response.AddHeader("content-disposition", $"inline;filename=\"{Util.SanitizeFilename(title)}.pdf\""); } stream.WriteTo(outputStream); } } } #endregion } else { #region Bitmap Generation int width = (int)Math.Floor(tileSize.Width * devicePixelRatio); int height = (int)Math.Floor(tileSize.Height * devicePixelRatio); using (var bitmap = TryConstructBitmap(width, height, PixelFormat.Format32bppArgb)) { if (bitmap == null) { throw new HttpError(500, "Internal Server Error", $"Failed to allocate bitmap ({width}x{height}). Insufficient memory?"); } if (transparent) { bitmap.MakeTransparent(); } using (var g = System.Drawing.Graphics.FromImage(bitmap)) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; using (var graphics = new BitmapGraphics(g)) { graphics.ScaleTransform((float)devicePixelRatio); RenderToGraphics(ctx, transform, graphics); } } BitmapResponse(context.Response, outputStream, ctx.Styles, bitmap, transparent ? ContentTypes.Image.Png : null); } #endregion } if (dataURI) { string contentType = context.Response.ContentType; context.Response.ContentType = ContentTypes.Text.Plain; ms.Seek(0, SeekOrigin.Begin); context.Response.Output.Write("data:"); context.Response.Output.Write(contentType); context.Response.Output.Write(";base64,"); context.Response.Output.Flush(); System.Security.Cryptography.ICryptoTransform encoder = new System.Security.Cryptography.ToBase64Transform(); using (System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(context.Response.OutputStream, encoder, System.Security.Cryptography.CryptoStreamMode.Write)) { ms.WriteTo(cs); cs.FlushFinalBlock(); } } context.Response.Flush(); context.Response.Close(); return; }
public void GetElementList(List<ISVGDrawable> elementList, SVGPaintable paintable, SVGGraphics render, SVGTransformList summaryTransformList) { bool exitFlag = false; while(!exitFlag && Next()) { if(Node is BlockCloseNode) { exitFlag = true; continue; } switch(Node.Name) { case SVGNodeName.Rect: elementList.Add(new SVGRectElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Line: elementList.Add(new SVGLineElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Circle: elementList.Add(new SVGCircleElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Ellipse: elementList.Add(new SVGEllipseElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.PolyLine: elementList.Add(new SVGPolylineElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Polygon: elementList.Add(new SVGPolygonElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.Path: elementList.Add(new SVGPathElement(Node.Attributes, summaryTransformList, paintable, render)); break; case SVGNodeName.SVG: elementList.Add(new SVGSVGElement(this, summaryTransformList, paintable, render)); break; case SVGNodeName.G: elementList.Add(new SVGGElement(this, summaryTransformList, paintable, render)); break; case SVGNodeName.LinearGradient: paintable.AppendLinearGradient(new SVGLinearGradientElement(this, Node.Attributes)); break; case SVGNodeName.RadialGradient: paintable.AppendRadialGradient(new SVGRadialGradientElement(this, Node.Attributes)); break; case SVGNodeName.Defs: GetElementList(elementList, paintable, render, summaryTransformList); break; case SVGNodeName.Title: GetElementList(elementList, paintable, render, summaryTransformList); break; case SVGNodeName.Desc: GetElementList(elementList, paintable, render, summaryTransformList); break; } } }
public void StartProcess(SVGAsset asset) { if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) { return; } if (errors == null) { errors = new List <SVGError>(); } else { errors.Clear(); } _importingSVG = true; System.Reflection.FieldInfo _editor_runtimeMaterials = typeof(SVGAsset).GetField("_runtimeMaterials", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_runtimeMaterials.SetValue(asset, null); System.Reflection.FieldInfo _editor_runtimeMesh = typeof(SVGAsset).GetField("_runtimeMesh", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_runtimeMesh.SetValue(asset, null); UnityEditor.SerializedObject svgAsset = new UnityEditor.SerializedObject(asset); UnityEditor.SerializedProperty sharedMesh = svgAsset.FindProperty("_sharedMesh"); UnityEditor.SerializedProperty sharedShaders = svgAsset.FindProperty("_sharedShaders"); Clear(); SVGParser.Init(); SVGGraphics.Init(); atlasData = new SVGAtlasData(); atlasData.Init(SVGAtlas.defaultAtlasTextureWidth * SVGAtlas.defaultAtlasTextureHeight); atlasData.AddGradient(SVGAtlasData.GetDefaultGradient()); SVGElement _rootSVGElement = null; #if IGNORE_EXCEPTIONS try { #else Debug.LogWarning("Exceptions are turned on!"); #endif // Create new Asset CreateEmptySVGDocument(); _rootSVGElement = this._svgDocument.rootElement; #if IGNORE_EXCEPTIONS } catch (System.Exception exception) { _rootSVGElement = null; errors.Add(SVGError.Syntax); Debug.LogError("SVG Document Exception: " + exception.Message, asset); } #endif if (_rootSVGElement == null) { Debug.LogError("SVG Document is corrupted! " + UnityEditor.AssetDatabase.GetAssetPath(asset), asset); _importingSVG = false; return; } #if IGNORE_EXCEPTIONS try { #endif _rootSVGElement.Render(); Rect viewport = _rootSVGElement.paintable.viewport; viewport.x *= SVGAssetImport.meshScale; viewport.y *= SVGAssetImport.meshScale; viewport.size *= SVGAssetImport.meshScale; Vector2 offset; SVGGraphics.CorrectSVGLayers(SVGGraphics.layers, viewport, asset, out offset); // Handle gradients bool hasGradients = false; // Create actual Mesh Shader[] outputShaders; Mesh mesh = new Mesh(); SVGMesh.CombineMeshes(SVGGraphics.layers.ToArray(), mesh, out outputShaders, useGradients, format, compressDepth, asset.antialiasing); if (mesh == null) { return; } if (useGradients == SVGUseGradients.Always) { if (outputShaders != null) { for (int i = 0; i < outputShaders.Length; i++) { if (outputShaders[i] == null) { continue; } if (outputShaders[i].name == SVGShader.SolidColorOpaque.name) { outputShaders[i] = SVGShader.GradientColorOpaque; } else if (outputShaders[i].name == SVGShader.SolidColorAlphaBlended.name) { outputShaders[i] = SVGShader.GradientColorAlphaBlended; } else if (outputShaders[i].name == SVGShader.SolidColorAlphaBlendedAntialiased.name) { outputShaders[i] = SVGShader.GradientColorAlphaBlendedAntialiased; } } } hasGradients = true; } else { if (outputShaders != null) { for (int i = 0; i < outputShaders.Length; i++) { if (outputShaders[i] == null) { continue; } if (outputShaders[i].name == SVGShader.GradientColorOpaque.name || outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name || outputShaders[i].name == SVGShader.GradientColorAlphaBlendedAntialiased.name || outputShaders[i].name == SVGShader.GradientColorAlphaBlendedAntialiasedCompressed.name) { hasGradients = true; break; } } } } if (!asset.useLayers) { sharedMesh.objectReferenceValue = AddObjectToAsset <Mesh>(mesh, asset, HideFlags.HideInHierarchy); } // Material sharedMaterial; if (outputShaders != null && outputShaders.Length > 0) { sharedShaders.arraySize = outputShaders.Length; if (hasGradients) { for (int i = 0; i < outputShaders.Length; i++) { sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name; } } else { for (int i = 0; i < outputShaders.Length; i++) { if (outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name) { outputShaders[i] = SVGShader.SolidColorAlphaBlended; } else if (outputShaders[i].name == SVGShader.GradientColorOpaque.name) { outputShaders[i] = SVGShader.SolidColorOpaque; } sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name; } } } // Serialize the Asset svgAsset.ApplyModifiedProperties(); // Handle Canvas Rectangle System.Reflection.MethodInfo _editor_SetCanvasRectangle = typeof(SVGAsset).GetMethod("_editor_SetCanvasRectangle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_SetCanvasRectangle.Invoke(asset, new object[] { new Rect(viewport.x, viewport.y, viewport.size.x, viewport.size.y) }); if (asset.generateCollider) { // Create polygon contour if (SVGGraphics.paths != null && SVGGraphics.paths.Count > 0) { List <List <Vector2> > polygons = new List <List <Vector2> >(); for (int i = 0; i < SVGGraphics.paths.Count; i++) { Vector2[] points = SVGGraphics.paths[i].points; for (int j = 0; j < points.Length; j++) { points[j].x = points[j].x * SVGAssetImport.meshScale - offset.x; points[j].y = (points[j].y * SVGAssetImport.meshScale + offset.y) * -1f; } polygons.Add(new List <Vector2>(points)); } polygons = SVGGeom.MergePolygon(polygons); SVGPath[] paths = new SVGPath[polygons.Count]; for (int i = 0; i < polygons.Count; i++) { paths[i] = new SVGPath(polygons[i].ToArray()); } System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (paths != null && paths.Length > 0) { _editor_SetColliderShape.Invoke(asset, new object[] { paths }); } else { _editor_SetColliderShape.Invoke(asset, new object[] { null }); } } } else { System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_SetColliderShape.Invoke(asset, new object[] { null }); } System.Reflection.MethodInfo _editor_SetGradients = typeof(SVGAsset).GetMethod("_editor_SetGradients", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_SetGradients.Invoke(asset, new object[] { null }); if (hasGradients) { if (atlasData.gradientCache != null && atlasData.gradientCache.Count > 0) { int gradientsCount = SVGAssetImport.atlasData.gradientCache.Count; CCGradient[] gradients = new CCGradient[gradientsCount]; int i = 0; foreach (KeyValuePair <string, CCGradient> entry in SVGAssetImport.atlasData.gradientCache) { gradients[i++] = entry.Value; } _editor_SetGradients.Invoke(asset, new object[] { gradients }); } } System.Reflection.MethodInfo _editor_SetLayers = typeof(SVGAsset).GetMethod("_editor_SetLayers", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_SetLayers.Invoke(asset, new object[] { null }); if (asset.useLayers) { if (SVGGraphics.layers != null && SVGGraphics.layers.Count > 0) { _editor_SetLayers.Invoke(asset, new object[] { SVGGraphics.layers.ToArray() }); } } #if IGNORE_EXCEPTIONS } catch (System.Exception exception) { Debug.LogWarning("Asset: " + UnityEditor.AssetDatabase.GetAssetPath(asset) + " Failed to import\n" + exception.Message, asset); errors.Add(SVGError.CorruptedFile); } #endif if (_svgDocument != null) { _svgDocument.Clear(); _svgDocument = null; } Clear(); UnityEditor.EditorUtility.SetDirty(asset); _importingSVG = false; }
public SVGAssetImport(string svgFile, float vertexPerMeter = 1000f) { vpm = vertexPerMeter; this._SVGFile = svgFile; _graphics = new SVGGraphics(vertexPerMeter, antialiasing); }
/***********************************************************************************/ public Implement(TextAsset svgFile) { this._SVGFile = svgFile; _device = new SVGDevice(); _graphics = new SVGGraphics(_device); }
public SVGDocument(string originalDocument, SVGGraphics r) { parser = new SVGParser(originalDocument); render = r; }
public void StartProcess(SVGAsset asset) { if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) { return; } if (errors == null) { errors = new List <SVGError>(); } else { errors.Clear(); } _importingSVG = true; UnityEditor.SerializedObject svgAsset = new UnityEditor.SerializedObject(asset); UnityEditor.SerializedProperty sharedMesh = svgAsset.FindProperty("_sharedMesh"); UnityEditor.SerializedProperty sharedShaders = svgAsset.FindProperty("_sharedShaders"); Clear(); SVGParser.Init(); SVGGraphics.Init(); atlasData = new SVGAtlasData(); SVGElement _rootSVGElement = null; #if IGNORE_EXCEPTIONS try { #else Debug.LogWarning("Exceptions are turned on!"); #endif // Create new Asset CreateEmptySVGDocument(); _rootSVGElement = this._svgDocument.rootElement; #if IGNORE_EXCEPTIONS } catch (System.Exception exception) { _rootSVGElement = null; errors.Add(SVGError.Syntax); Debug.LogError("SVG Document Exception: " + exception.Message, asset); } #endif if (_rootSVGElement == null) { Debug.LogError("SVG Document is corrupted! " + UnityEditor.AssetDatabase.GetAssetPath(asset), asset); _importingSVG = false; return; } SVGGraphics.depthTree = new SVGDepthTree(_rootSVGElement.paintable.viewport); #if IGNORE_EXCEPTIONS try { #endif _rootSVGElement.Render(); // Handle gradients bool hasGradients = (useGradients == SVGUseGradients.Always); // Create actual Mesh Shader[] outputShaders; SVGLayer[] outputLayers; Mesh mesh = SVGMesh.CombineMeshes(SVGGraphics.meshes, out outputLayers, out outputShaders, useGradients, format, compressDepth); if (mesh == null) { return; } if (outputShaders != null) { for (int i = 0; i < outputShaders.Length; i++) { if (outputShaders[i] == null) { continue; } if (outputShaders[i].name == SVGShader.GradientColorOpaque.name || outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name) { hasGradients = true; break; } } } Vector3[] vertices = mesh.vertices; Vector2 offset; Bounds bounds = mesh.bounds; Rect viewport = _rootSVGElement.paintable.viewport; viewport.x *= SVGAssetImport.meshScale; viewport.y *= SVGAssetImport.meshScale; viewport.size *= SVGAssetImport.meshScale; if (asset.ignoreSVGCanvas) { offset = new Vector2(bounds.min.x + bounds.size.x * asset.pivotPoint.x, bounds.min.y + bounds.size.y * asset.pivotPoint.y); } else { offset = new Vector2(viewport.min.x + viewport.size.x * asset.pivotPoint.x, viewport.min.y + viewport.size.y * asset.pivotPoint.y); } // Apply pivot point and Flip Y Axis for (int i = 0; i < vertices.Length; i++) { vertices[i].x = vertices[i].x - offset.x; vertices[i].y = (vertices[i].y - offset.y) * -1f; } mesh.vertices = vertices; mesh.RecalculateBounds(); sharedMesh.objectReferenceValue = AddObjectToAsset <Mesh>(mesh, asset, HideFlags.HideInHierarchy); // Material sharedMaterial; if (outputShaders != null && outputShaders.Length > 0) { sharedShaders.arraySize = outputShaders.Length; if (hasGradients) { for (int i = 0; i < outputShaders.Length; i++) { sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name; } } else { for (int i = 0; i < outputShaders.Length; i++) { if (outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name) { outputShaders[i] = SVGShader.SolidColorAlphaBlended; } else if (outputShaders[i].name == SVGShader.GradientColorOpaque.name) { outputShaders[i] = SVGShader.SolidColorOpaque; } sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name; } } } // Serialize the Asset svgAsset.ApplyModifiedProperties(); // Handle Canvas Rectangle System.Reflection.MethodInfo _editor_SetCanvasRectangle = typeof(SVGAsset).GetMethod("_editor_SetCanvasRectangle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_SetCanvasRectangle.Invoke(asset, new object[] { new Rect(viewport.x, viewport.y, viewport.size.x, viewport.size.y) }); if (asset.generateCollider) { // Create polygon contour if (SVGGraphics.paths != null && SVGGraphics.paths.Count > 0) { List <List <Vector2> > polygons = new List <List <Vector2> >(); for (int i = 0; i < SVGGraphics.paths.Count; i++) { Vector2[] points = SVGGraphics.paths[i].points; for (int j = 0; j < points.Length; j++) { points[j].x = points[j].x * SVGAssetImport.meshScale - offset.x; points[j].y = (points[j].y * SVGAssetImport.meshScale - offset.y) * -1f; } polygons.Add(new List <Vector2>(points)); } polygons = SVGGeom.MergePolygon(polygons); SVGPath[] paths = new SVGPath[polygons.Count]; for (int i = 0; i < polygons.Count; i++) { paths[i] = new SVGPath(polygons[i].ToArray()); } System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (paths != null && paths.Length > 0) { _editor_SetColliderShape.Invoke(asset, new object[] { paths }); } else { _editor_SetColliderShape.Invoke(asset, new object[] { null }); } } } else { System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); _editor_SetColliderShape.Invoke(asset, new object[] { null }); } if (hasGradients) { System.Reflection.MethodInfo _editor_SetGradients = typeof(SVGAsset).GetMethod("_editor_SetGradients", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (atlasData.gradients != null && atlasData.gradients.Count > 0) { _editor_SetGradients.Invoke(asset, new object[] { atlasData.gradients.ToArray() }); } else { _editor_SetGradients.Invoke(asset, new object[] { null }); } } #if IGNORE_EXCEPTIONS } catch (System.Exception exception) { Debug.LogWarning("Asset: " + UnityEditor.AssetDatabase.GetAssetPath(asset) + " Failed to import\n" + exception.Message, asset); errors.Add(SVGError.CorruptedFile); } #endif if (_svgDocument != null) { _svgDocument.Clear(); _svgDocument = null; } Clear(); UnityEditor.EditorUtility.SetDirty(asset); _importingSVG = false; }
public SVGPathElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { Profiler.BeginSample("SVGPathElement constructor"); _paintable = new SVGPaintable(inheritPaintable, attrList); _render = r; currentTransformList = new SVGTransformList(attrList.GetValue("transform")); string dstr = attrList.GetValue("d"); int nbSegments = 0; for(int i = 0; i < dstr.Length; ++i) { switch(dstr[i]) { case 'Z': case 'z': case 'M': case 'm': case 'L': case 'l': case 'C': case 'c': case 'S': case 's': case 'Q': case 'q': case 'T': case 't': case 'A': case 'a': case 'H': case 'h': case 'V': case 'v': ++nbSegments; break; } } _segList = new SVGPathSegList(nbSegments); // optimization: count number of segments before starting for(int i = 0; i < dstr.Length;) { while(i < dstr.Length - 1 && dstr[i] == ' ') // skip whitespace before type character ++i; char _char = dstr[i]; switch(_char) { case 'Z': case 'z': _segList.AppendItem(CreateSVGPathSegClosePath()); ++i; break; case 'M': { try { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegMovetoAbs(a, b)); } catch(Exception) { Debug.Log("exception when parsing " + dstr); throw; } break; } case 'm': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegMovetoRel(a, b)); break; } case 'L': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoAbs(a, b)); break; } case 'l': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoRel(a, b)); break; } case 'C': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); float e = ReadFloat(dstr, ref i); float f = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicAbs(a, b, c, d, e, f)); break; } case 'c': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); float e = ReadFloat(dstr, ref i); float f = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicRel(a, b, c, d, e, f)); break; } case 'S': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothAbs(a, b, c, d)); break; } case 's': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothRel(a, b, c, d)); break; } case 'Q': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticAbs(a, b, c, d)); break; } case 'q': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticRel(a, b, c, d)); break; } case 'T': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothAbs(a, b)); break; } case 't': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothRel(a, b)); break; } case 'A': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); bool d = ReadFloat(dstr, ref i) > 0; bool e = ReadFloat(dstr, ref i) > 0; float f = ReadFloat(dstr, ref i); float g = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegArcAbs(a, b, c, d, e, f, g)); break; } case 'a': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); bool d = ReadFloat(dstr, ref i) > 0; bool e = ReadFloat(dstr, ref i) > 0; float f = ReadFloat(dstr, ref i); float g = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegArcRel(a, b, c, d, e, f, g)); break; } case 'H': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoHorizontalAbs(a)); break; } case 'h': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoHorizontalRel(a)); break; } case 'V': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoVerticalAbs(a)); break; } case 'v': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoVerticalRel(a)); break; } default: ++i; break; } } //List<char> _charList = new List<char>(); //List<string> _valueList = new List<string>(); //SVGStringExtractor.ExtractPathSegList(dstr, ref _charList, ref _valueList); //_segList = new SVGPathSegList(_charList.Count); //for (int i = 0; i < _charList.Count; i++) //{ // char _char = _charList[i]; // string _value = _valueList[i]; // float[] parms = SVGStringExtractor.ExtractTransformValueAsPX(_value); // switch (_char) // { // case 'Z': // case 'z': // _segList.AppendItem(CreateSVGPathSegClosePath()); // break; // case 'M': // _segList.AppendItem(new SVGPathSegMovetoAbs(parms[0], parms[1])); // break; // case 'm': // _segList.AppendItem(new SVGPathSegMovetoRel(parms[0], parms[1])); // break; // case 'L': // _segList.AppendItem(new SVGPathSegLinetoAbs(parms[0], parms[1])); // break; // case 'l': // _segList.AppendItem(new SVGPathSegLinetoRel(parms[0], parms[1])); // break; // case 'C': // _segList.AppendItem(new SVGPathSegCurvetoCubicAbs(parms[0], parms[1], parms[2], parms[3], parms[4], parms[5])); // break; // case 'c': // _segList.AppendItem(new SVGPathSegCurvetoCubicRel(parms[0], parms[1], parms[2], parms[3], parms[4], parms[5])); // break; // case 'S': // _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothAbs(parms[0], parms[1], parms[2], parms[3])); // break; // case 's': // _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothRel(parms[0], parms[1], parms[2], parms[3])); // break; // case 'Q': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticAbs(parms[0], parms[1], parms[2], parms[3])); // break; // case 'q': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticRel(parms[0], parms[1], parms[2], parms[3])); // break; // case 'T': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothAbs(parms[0], parms[1])); // break; // case 't': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothRel(parms[0], parms[1])); // break; // case 'A': // _segList.AppendItem(new SVGPathSegArcAbs(parms[0], parms[1], parms[2], parms[3] == 1f, parms[4] == 1f, parms[5], // parms[6])); // break; // case 'a': // _segList.AppendItem(new SVGPathSegArcRel(parms[0], parms[1], parms[2], parms[3] == 1f, parms[4] == 1f, parms[5], // parms[6])); // break; // case 'H': // _segList.AppendItem(new SVGPathSegLinetoHorizontalAbs(parms[0])); // break; // case 'h': // _segList.AppendItem(new SVGPathSegLinetoHorizontalRel(parms[0])); // break; // case 'V': // _segList.AppendItem(new SVGPathSegLinetoVerticalAbs(parms[0])); // break; // case 'v': // _segList.AppendItem(new SVGPathSegLinetoVerticalRel(parms[0])); // break; // } //} Profiler.EndSample(); }
public Implement(TextAsset svgFile, ISVGDevice device) { _SVGFile = svgFile; _graphics = new SVGGraphics(device); }
protected static Mesh CreateAutomaticMesh(out Material[] materials) { materials = new Material[0]; if (sliceMesh) { Create9Slice(); } // Z Sort meshes if (SVGMesh.format == SVGAssetFormat.Opaque) { int meshCount = SVGGraphics.meshes.Count; SVGFill fill; if (compressDepth) { SVGBounds meshBounds = SVGBounds.InfiniteInverse; for (int i = 0; i < meshCount; i++) { if (SVGGraphics.meshes [i] == null) { continue; } meshBounds.Encapsulate(SVGGraphics.meshes [i].bounds); } if (!meshBounds.isInfiniteInverse) { SVGGraphics.depthTree.Clear(); SVGGraphics.depthTree = new SVGDepthTree(meshBounds); } for (int i = 0; i < meshCount; i++) { if (SVGGraphics.meshes [i] == null) { continue; } fill = SVGGraphics.meshes [i]._fill; if (fill != null) { SVGMesh[] nodes = SVGGraphics.depthTree.TestDepthAdd(SVGGraphics.meshes [i], new SVGBounds(SVGGraphics.meshes [i]._bounds)); int nodesLength = 0; if (nodes == null || nodes.Length == 0) { SVGGraphics.meshes [i]._depth = 0; } else { nodesLength = nodes.Length; int highestDepth = 0; SVGMesh highestMesh = null; for (int j = 0; j < nodesLength; j++) { if (nodes[j].depth > highestDepth) { highestDepth = nodes[j].depth; highestMesh = nodes[j]; } } if (fill.blend == FILL_BLEND.OPAQUE) { SVGGraphics.meshes [i]._depth = highestDepth + 1; } else { if (highestMesh != null && highestMesh.fill.blend == FILL_BLEND.OPAQUE) { SVGGraphics.meshes [i]._depth = highestDepth + 1; } else { SVGGraphics.meshes [i]._depth = highestDepth; } } } SVGGraphics.meshes [i].UpdateDepth(); } } } else { for (int i = 0; i < meshCount; i++) { if (SVGGraphics.meshes [i] == null) { continue; } fill = SVGGraphics.meshes [i]._fill; if (fill != null) { if (fill.blend == FILL_BLEND.OPAQUE || lastBlendType == FILL_BLEND.OPAQUE) { SVGGraphics.meshes [i]._depth = SVGGraphics.IncreaseDepth(); } else { SVGGraphics.meshes [i]._depth = SVGGraphics.currentDepthOffset; } lastBlendType = fill.blend; SVGGraphics.meshes [i].UpdateDepth(); } } } } // Combine Meshes List <CombineInstance> combineInstancesOpaque = new List <CombineInstance>(); List <CombineInstance> combineInstancesTransparent = new List <CombineInstance>(); GetCombineInstances(combineInstancesOpaque, combineInstancesTransparent); int count = combineInstancesOpaque.Count + combineInstancesTransparent.Count; if (count == 0) { return(null); } List <Material> outputMaterials = new List <Material>(count); List <CombineInstance> combineInstances = new List <CombineInstance>(); if (combineInstancesOpaque.Count > 0) { outputMaterials.Add(SVGAtlas.Instance.opaqueGradient); combineInstances.Add(GetCombinedInstance(combineInstancesOpaque)); } if (combineInstancesTransparent.Count > 0) { outputMaterials.Add(SVGAtlas.Instance.transparentGradient); combineInstances.Add(GetCombinedInstance(combineInstancesTransparent)); } if (outputMaterials.Count != 0) { materials = outputMaterials.ToArray(); } if (combineInstances.Count > 1) { Mesh output = new Mesh(); output.CombineMeshes(combineInstances.ToArray(), false, false); return(output); } else if (combineInstances.Count == 1) { return(combineInstances [0].mesh); } else { return(null); } }
public SVGPathElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { Profiler.BeginSample("SVGPathElement constructor"); _paintable = new SVGPaintable(inheritPaintable, attrList); _render = r; currentTransformList = new SVGTransformList(attrList.GetValue("transform")); string dstr = attrList.GetValue("d"); int nbSegments = 0; for (int i = 0; i < dstr.Length; ++i) { switch (dstr[i]) { case 'Z': case 'z': case 'M': case 'm': case 'L': case 'l': case 'C': case 'c': case 'S': case 's': case 'Q': case 'q': case 'T': case 't': case 'A': case 'a': case 'H': case 'h': case 'V': case 'v': ++nbSegments; break; } } _segList = new SVGPathSegList(nbSegments); // optimization: count number of segments before starting for (int i = 0; i < dstr.Length;) { while (i < dstr.Length - 1 && dstr[i] == ' ') // skip whitespace before type character { ++i; } char _char = dstr[i]; switch (_char) { case 'Z': case 'z': _segList.AppendItem(CreateSVGPathSegClosePath()); ++i; break; case 'M': { try { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegMovetoAbs(a, b)); } catch (Exception) { Debug.Log("exception when parsing " + dstr); throw; } break; } case 'm': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegMovetoRel(a, b)); break; } case 'L': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoAbs(a, b)); break; } case 'l': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoRel(a, b)); break; } case 'C': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); float e = ReadFloat(dstr, ref i); float f = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicAbs(a, b, c, d, e, f)); break; } case 'c': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); float e = ReadFloat(dstr, ref i); float f = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicRel(a, b, c, d, e, f)); break; } case 'S': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothAbs(a, b, c, d)); break; } case 's': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothRel(a, b, c, d)); break; } case 'Q': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticAbs(a, b, c, d)); break; } case 'q': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); float d = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticRel(a, b, c, d)); break; } case 'T': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothAbs(a, b)); break; } case 't': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothRel(a, b)); break; } case 'A': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); bool d = ReadFloat(dstr, ref i) > 0; bool e = ReadFloat(dstr, ref i) > 0; float f = ReadFloat(dstr, ref i); float g = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegArcAbs(a, b, c, d, e, f, g)); break; } case 'a': { float a = ReadFloat(dstr, ref i); float b = ReadFloat(dstr, ref i); float c = ReadFloat(dstr, ref i); bool d = ReadFloat(dstr, ref i) > 0; bool e = ReadFloat(dstr, ref i) > 0; float f = ReadFloat(dstr, ref i); float g = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegArcRel(a, b, c, d, e, f, g)); break; } case 'H': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoHorizontalAbs(a)); break; } case 'h': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoHorizontalRel(a)); break; } case 'V': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoVerticalAbs(a)); break; } case 'v': { float a = ReadFloat(dstr, ref i); _segList.AppendItem(new SVGPathSegLinetoVerticalRel(a)); break; } default: ++i; break; } } //List<char> _charList = new List<char>(); //List<string> _valueList = new List<string>(); //SVGStringExtractor.ExtractPathSegList(dstr, ref _charList, ref _valueList); //_segList = new SVGPathSegList(_charList.Count); //for (int i = 0; i < _charList.Count; i++) //{ // char _char = _charList[i]; // string _value = _valueList[i]; // float[] parms = SVGStringExtractor.ExtractTransformValueAsPX(_value); // switch (_char) // { // case 'Z': // case 'z': // _segList.AppendItem(CreateSVGPathSegClosePath()); // break; // case 'M': // _segList.AppendItem(new SVGPathSegMovetoAbs(parms[0], parms[1])); // break; // case 'm': // _segList.AppendItem(new SVGPathSegMovetoRel(parms[0], parms[1])); // break; // case 'L': // _segList.AppendItem(new SVGPathSegLinetoAbs(parms[0], parms[1])); // break; // case 'l': // _segList.AppendItem(new SVGPathSegLinetoRel(parms[0], parms[1])); // break; // case 'C': // _segList.AppendItem(new SVGPathSegCurvetoCubicAbs(parms[0], parms[1], parms[2], parms[3], parms[4], parms[5])); // break; // case 'c': // _segList.AppendItem(new SVGPathSegCurvetoCubicRel(parms[0], parms[1], parms[2], parms[3], parms[4], parms[5])); // break; // case 'S': // _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothAbs(parms[0], parms[1], parms[2], parms[3])); // break; // case 's': // _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothRel(parms[0], parms[1], parms[2], parms[3])); // break; // case 'Q': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticAbs(parms[0], parms[1], parms[2], parms[3])); // break; // case 'q': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticRel(parms[0], parms[1], parms[2], parms[3])); // break; // case 'T': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothAbs(parms[0], parms[1])); // break; // case 't': // _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothRel(parms[0], parms[1])); // break; // case 'A': // _segList.AppendItem(new SVGPathSegArcAbs(parms[0], parms[1], parms[2], parms[3] == 1f, parms[4] == 1f, parms[5], // parms[6])); // break; // case 'a': // _segList.AppendItem(new SVGPathSegArcRel(parms[0], parms[1], parms[2], parms[3] == 1f, parms[4] == 1f, parms[5], // parms[6])); // break; // case 'H': // _segList.AppendItem(new SVGPathSegLinetoHorizontalAbs(parms[0])); // break; // case 'h': // _segList.AppendItem(new SVGPathSegLinetoHorizontalRel(parms[0])); // break; // case 'V': // _segList.AppendItem(new SVGPathSegLinetoVerticalAbs(parms[0])); // break; // case 'v': // _segList.AppendItem(new SVGPathSegLinetoVerticalRel(parms[0])); // break; // } //} Profiler.EndSample(); }
public SVGDocument(string originalDocument, SVGGraphics r) { parser = new SVGParser(originalDocument); _render = r; }
/***********************************************************************************/ public Implement(TextAsset svgFile, ISVGDevice device) { this._SVGFile = svgFile; _device = device; _graphics = new SVGGraphics(_device); }