Inheritance: IDisposable
Exemple #1
0
            protected override SVGElement GetSeparatorContainer(SVGDocument parentDocument, SeparatorDescription description)
            {
                var gSeparatorContainer =
                    (SVGGElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "g");

                gSeparatorContainer.SetAttribute("stroke", description.StrokeColor);
                gSeparatorContainer.SetAttribute("stroke-width", GetCulturedString(description.Stroke));
                gSeparatorContainer.SetAttribute("stroke-linecap", "bevel");
                gSeparatorContainer.SetAttribute("stroke-linejoin", "round");

                var width  = description.X + description.Width;
                var height = description.Y + description.Height + description.Stroke / 2;

                for (int i = 0; i < description.Amount; i++)
                {
                    var lineSeparator =
                        (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");
                    lineSeparator.SetAttribute("x1", GetCulturedString(description.X));
                    lineSeparator.SetAttribute("y1", GetCulturedString(height));
                    lineSeparator.SetAttribute("x2", GetCulturedString(width));
                    lineSeparator.SetAttribute("y2", GetCulturedString(height));
                    height += description.Height + description.Stroke;

                    gSeparatorContainer.AppendChild(lineSeparator);
                }

                return(gSeparatorContainer);
            }
Exemple #2
0
        /***************************************************/

        public static string ToSVGString(this SVGDocument svgDocument)
        {
            if (svgDocument == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot convert a null SVG Document.");
                return("");
            }

            BoundingBox box = Query.Bounds(svgDocument);

            string Width  = (box.Max.X - box.Min.X).ToString();
            string Height = (box.Max.Y - box.Min.Y).ToString();

            string canvasString = "<svg width=\"" + Width + "\" height=\"" + Height + "\">\n";

            double h = (box.Max.Y - box.Min.Y);

            string xTrans = (-box.Min.X).ToString();
            string yTrans = (-box.Min.Y).ToString();

            canvasString += "<g transform=\"translate(" + "0," + h + ") scale(1,-1) translate(" + xTrans + "," + yTrans + ")\">\n";

            for (int i = 0; i < svgDocument.SVGObjects.Count; i++)
            {
                canvasString += ToSVGString((svgDocument.SVGObjects[i]));
            }

            canvasString += "</g>\n</svg>";

            return(canvasString);
        }
        /***************************************************/

        public static string ToSVGString(this SVGDocument svgDocument)
        {
            BoundingBox box = Query.Bounds(svgDocument);

            string Width  = (box.Max.X - box.Min.X).ToString();
            string Height = (box.Max.Y - box.Min.Y).ToString();

            string canvasString = "<svg width=\"" + Width + "\" height=\"" + Height + "\">\n";

            double h = (box.Max.Y - box.Min.Y);

            string xTrans = (-box.Min.X).ToString();
            string yTrans = (-box.Min.Y).ToString();

            canvasString += "<g transform=\"translate(" + "0," + h + ") scale(1,-1) translate(" + xTrans + "," + yTrans + ")\">\n";

            for (int i = 0; i < svgDocument.SVGObjects.Count; i++)
            {
                canvasString += ToSVGString((svgDocument.SVGObjects[i]));
            }

            canvasString += "</g>\n</svg>";

            return(canvasString);
        }
        public void SVGtoXPSWithXpsSaveOptionsTest()
        {
            // Prepare a path to a source SVG file
            string documentPath = Path.Combine(DataDir, "aspose.svg");

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "aspose-options.xps");

            // Initialize an SVG document from the file
            using var document = new SVGDocument(documentPath);

            // Initialize XpsSaveOptions. Set up the page-size 500x500 pixels, margins, resolutions and change the background color to AliceBlue
            var options = new XpsSaveOptions()
            {
                HorizontalResolution = 200,
                VerticalResolution   = 200,
                BackgroundColor      = Color.AliceBlue
            };

            options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(500, 500), new Margin(30, 10, 10, 10));

            // Convert SVG to XPS
            Converter.ConvertSVG(document, options, savePath);

            Assert.True(File.Exists(Path.Combine(OutputDir, "aspose-options.xps")));
        }
Exemple #5
0
        public void SVGtoTIFFWithImageSaveOptionsTest()
        {
            // Prepare a path to a source SVG file
            string documentPath = Path.Combine(DataDir, "gradient.svg");

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "gradient-options.tiff");

            // Initialize an SVG document from the file
            using var document = new SVGDocument(documentPath);

            // Initialize ImageSaveOptions. Set up the compression, resolutions, and change the background color to AliceBlue
            var options = new ImageSaveOptions(ImageFormat.Tiff)
            {
                Compression          = Compression.None,
                HorizontalResolution = 200,
                VerticalResolution   = 200,
                BackgroundColor      = Color.AliceBlue
            };

            // Convert SVG to TIFF
            Converter.ConvertSVG(document, options, savePath);

            Assert.True(File.Exists(savePath));
        }
Exemple #6
0
        public void SaveHTMLToSVGTest()
        {
            // Prepare an output path for a document saving
            string documentPath = Path.Combine(OutputDir, "save-to-SVG.svg");

            // Prepare SVG code
            var code = @"
                <svg xmlns='http://www.w3.org/2000/svg' height='200' width='300'>
                    <g fill='none' stroke-width= '10' stroke-dasharray='30 10'>
                        <path stroke='red' d='M 25 40 l 215 0' />
                        <path stroke='black' d='M 35 80 l 215 0' />
                        <path stroke='blue' d='M 45 120 l 215 0' />
                    </g>
                </svg>";

            // Initialize an SVG instance from the content string
            using (var document = new SVGDocument(code, "."))
            {
                // Save the SVG file to a disk
                document.Save(documentPath);

                Assert.True(document.QuerySelectorAll("path").Length > 2);
            }

            Assert.True(File.Exists(documentPath));
        }
Exemple #7
0
        public static void Run()
        {
            //ExStart: 1
            string dataDir = RunExamples.GetDataDir_Convert();

            string svgCode = "<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'>" +
                             "<style>" +
                             "div {" +
                             "color: white;" +
                             "font: 18px serif;" +
                             "height: 100%;" +
                             "overflow: hidden;" +
                             " }" +
                             "</style>" +
                             "<polygon points='5,5 195,10 185,185 10,195' />" +
                             "<foreignObject x='20' y='20' width='160' height='160'>" +
                             "<div xmlns='http://www.w3.org/1999/xhtml'>" +
                             "Lorem ipsum dolor sit amet, consectetur adipiscing elit." +
                             "Sed mollis mollis mi ut ultricies. Nullam magna ipsum," +
                             "porta vel dui convallis, rutrum imperdiet eros. Aliquam" +
                             "erat volutpat." +
                             "</div>" +
                             "</foreignObject>" +
                             "</svg>";


            using (var document = new SVGDocument(svgCode, "."))
            {
                using (var device = new ImageDevice(new ImageRenderingOptions(ImageFormat.Jpeg), dataDir + "SupportForHtmlContentInSVG_out.jpg"))
                {
                    document.RenderTo(device);
                }
            }
            //ExEnd: 1
        }
Exemple #8
0
        public void SVGtoJPGWithImageSaveOptionsTest()
        {
            // Prepare a path to a source SVG file
            string documentPath = Path.Combine(DataDir, "flower.svg");

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "flower-options.jpg");

            // Initialize an SVG document from the file
            using var document = new SVGDocument(documentPath);

            // Initialize ImageSaveOptions. Set up the resolutions, SmoothingMode and change the background color to AliceBlue
            var options = new ImageSaveOptions(ImageFormat.Jpeg)
            {
                SmoothingMode        = SmoothingMode.HighQuality,
                HorizontalResolution = 200,
                VerticalResolution   = 200,
                BackgroundColor      = Color.AliceBlue
            };

            // Convert SVG to JPG
            Converter.ConvertSVG(document, options, savePath);

            Assert.True(File.Exists(Path.Combine(OutputDir, "flower-options_1.jpg")));
        }
Exemple #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sourcePath"></param>
 /// <param name="device"></param>
 protected override void Render(string sourcePath, IDevice device)
 {
     using (SVGDocument document = new SVGDocument(sourcePath))
     {
         var renderer = new SvgRenderer();
         renderer.Render(device, document);
     }
 }
 public static void Run()
 {
     //ExStart: CreateEmptySVGDocument
     using (var document = new SVGDocument())
     {
         // do some actions over the document here...
     }
     //ExEnd: CreateEmptySVGDocument
 }
Exemple #11
0
 public static void Run()
 {
     //ExStart: CreateSVGDocumentFromContent
     using (var document = new SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", "."))
     {
         // do some actions over the document here...
     }
     //ExEnd: CreateSVGDocumentFromContent
 }
 public static void Run()
 {
     //ExStart: LoadDocumentFromUrl
     using (var document = new SVGDocument("http://www1.plurib.us/1shot/2008/circle_design/circles_single.svg"))
     {
         // do some actions over the document here...
     }
     //ExEnd: LoadDocumentFromUrl
 }
Exemple #13
0
 public static void Run()
 {
     //ExStart: ViewDocumentContentAsString
     using (var document = new SVGDocument("http://www1.plurib.us/1shot/2008/circle_design/circles_single.svg"))
     {
         Console.WriteLine(document.DocumentElement.OuterHTML);
     }
     //ExEnd: ViewDocumentContentAsString
 }
 // Constructor
 public PackedSvgDocRef(SVGDocument svgDoc, TextAsset txtAsset)
 {
     this.m_SvgDoc   = svgDoc;
     this.m_TxtAsset = txtAsset;
     // SVGRenameImporter substitutes the ".svg" file extension with ".svg.txt" one (e.g. orc.svg --> orc.svg.txt)
     // Unity assets explorer does not show the last ".txt" postfix (e.g. in the editor we see orc.svg without the last .txt trait)
     // txtAsset.name does not contain the last ".txt" trait, but it still contains the ".svg"; at this level, we want to remove even that
     this.m_Name     = txtAsset.name.Replace(".svg", "");
     this.m_RefCount = 0;
 }
Exemple #15
0
        /***************************************************/

        public static BoundingBox Bounds(this SVGDocument svg)
        {
            if (svg == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot query the bounding box of a null SVG document.");
                return(null);
            }

            return(svg.Canvas);
        }
Exemple #16
0
        public void LoadSVGDocumentFromStringTest()
        {
            // Initialize an SVG document from the string object
            using (var document = new SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", "."))
            {
                // Write the document content to the output stream
                Output.WriteLine(document.DocumentElement.OuterHTML);

                Assert.True(document.QuerySelectorAll("circle").Length > 0);
            }
        }
        public static void Run()
        {
            //ExStart: LoadDocumentFromFile
            string dataDir = RunExamples.GetDataDir_Data();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                // do some actions over the document here...
            }
            //ExEnd: LoadDocumentFromFile
        }
Exemple #18
0
    void OnGUI()
    {
        _svgFile = (TextAsset)EditorGUILayout.ObjectField("SVG File", _svgFile, typeof(TextAsset), false);

        if (_svgFile != null && GUILayout.Button("SVG - OK"))
        {
            Debug.Log("Parse");
            var svgdoc = new SVGDocument(_svgFile.text, null);
            //DumpISVGDrawable(svgdoc.RootElement);
            Debug.Log(svgdoc);
        }
    }
Exemple #19
0
    protected XmlDocument GetDocument()
    {
        SVGNode n = parent;

        while (n.parent != null)
        {
            n = n.parent;
        }
        SVGDocument doc = n as SVGDocument;

        return(doc.doc);
    }
        public static void Run()
        {
            //ExStart: CSSSelector
            string dataDir = RunExamples.GetDataDir_SVG();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                var element = document.QuerySelector("g > :last-child");
                Console.WriteLine(element.OuterHTML);
            }
            //ExEnd: CSSSelector
        }
        public ActionResult GenerateFromScratch(string widthStr, string heightStr, string fontColorStr, string bkColorStr)
        {
            //In this method, we demonstrate another technique for setting values of width and height
            var width  = float.Parse(widthStr);
            var height = float.Parse(heightStr);

            //Creat new  (empty) image
            var document = new SVGDocument(new Configuration());

            //Adjast image size
            document.RootElement.Width.BaseVal.ValueAsString  = widthStr;
            document.RootElement.Height.BaseVal.ValueAsString = heightStr;

            document.RootElement.ViewBox.BaseVal.X      = 0;
            document.RootElement.ViewBox.BaseVal.Y      = 0;
            document.RootElement.ViewBox.BaseVal.Width  = width;
            document.RootElement.ViewBox.BaseVal.Height = height;


            var rect = document.CreateElementNS(SvgXmlns, "rect") as SVGRectElement;

            if (rect == null)
            {
                return(Content(document.RootElement.OuterHTML, ContentType));
            }
            rect.Width.BaseVal.Value  = width;
            rect.Height.BaseVal.Value = height;
            rect.Style.SetProperty("fill", "#" + bkColorStr, string.Empty);
            document.RootElement.AppendChild(rect);

            var text = document.CreateElementNS(SvgXmlns, "text") as SVGTextElement;

            if (text == null)
            {
                return(Content(document.RootElement.OuterHTML, ContentType));
            }
            text.SetAttributeNS(null, "x", (width / 2).ToString());
            text.SetAttributeNS(null, "y", (height / 2).ToString());
            text.TextContent = $"{widthStr}x{heightStr}";

            text.Style.SetProperty("font-family", "Arial", string.Empty);
            text.Style.SetProperty("font-weight", "bold", string.Empty);
            text.Style.SetProperty("dominant-baseline", "central", string.Empty);

            var fontSize = Math.Round(Math.Max(12, Math.Min(.75 * Math.Min(width, height), 0.75 * Math.Max(width, height) / 12)));

            text.Style.SetProperty("font-size", $"{fontSize}px", string.Empty);
            text.Style.SetProperty("fill", "#" + fontColorStr, string.Empty);
            text.Style.SetProperty("text-anchor", "middle", string.Empty);

            document.RootElement.AppendChild(text);
            return(Content(document.RootElement.OuterHTML, ContentType));
        }
Exemple #22
0
            protected SVGElement GetBorderContainer(SVGDocument parentDocument, BorderDescription description)
            {
                var gBorderContainer =
                    (SVGGElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "g");

                gBorderContainer.SetAttribute("stroke", description.StrokeColor);
                gBorderContainer.SetAttribute("stroke-width", GetCulturedString(description.Stroke));
                gBorderContainer.SetAttribute("stroke-linecap", "round");
                gBorderContainer.SetAttribute("stroke-linejoin", "round");

                // Lines around content
                // ================================
                // Border Line top
                var lineTop =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineTop.SetAttribute("x1", GetCulturedString(description.X));
                lineTop.SetAttribute("y1", GetCulturedString(description.Y));
                lineTop.SetAttribute("x2", GetCulturedString(description.X + description.Width));
                lineTop.SetAttribute("y2", GetCulturedString(description.Y));
                // Border Line right
                var lineRight =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineRight.SetAttribute("x1", GetCulturedString(description.X + description.Width));
                lineRight.SetAttribute("y1", GetCulturedString(description.Y));
                lineRight.SetAttribute("x2", GetCulturedString(description.X + description.Width));
                lineRight.SetAttribute("y2", GetCulturedString(description.Y + description.Height));
                // Border Line bottom
                var lineBottom =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineBottom.SetAttribute("x1", GetCulturedString(description.X + description.Width));
                lineBottom.SetAttribute("y1", GetCulturedString(description.Y + description.Height));
                lineBottom.SetAttribute("x2", GetCulturedString(description.X));
                lineBottom.SetAttribute("y2", GetCulturedString(description.Y + description.Height));
                // Border Line left
                var lineLeft =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineLeft.SetAttribute("x1", GetCulturedString(description.X));
                lineLeft.SetAttribute("y1", GetCulturedString(description.Y + description.Height));
                lineLeft.SetAttribute("x2", GetCulturedString(description.X));
                lineLeft.SetAttribute("y2", GetCulturedString(description.Y));

                gBorderContainer.AppendChild(lineTop);
                gBorderContainer.AppendChild(lineRight);
                gBorderContainer.AppendChild(lineBottom);
                gBorderContainer.AppendChild(lineLeft);

                return(gBorderContainer);
            }
Exemple #23
0
        private static void ApplyFilter(string srcFile, string filterId, string outputFile)
        {
            //Create a new svg document
            using (var svgDoc = new SVGDocument())
            {
                //Create an element <g> to which the filter will be applied.
                var g = svgDoc.CreateElementNS("http://www.w3.org/2000/svg", "g");
                svgDoc.RootElement.AppendChild(g);
                using (var image = System.Drawing.Image.FromFile(srcFile))
                {
                    //Create <image> element
                    var imageElement = (SVGImageElement)svgDoc.CreateElementNS("http://www.w3.org/2000/svg", "image");
                    imageElement.SetAttribute("href", srcFile);
                    var w = image.Width;
                    var h = image.Height;

                    const int maxSize = 2000;
                    var       size    = (float)Math.Max(w, h);
                    if (size > maxSize)
                    {
                        w = (int)(maxSize * w / size);
                        h = (int)(maxSize * h / size);
                    }
                    //Set the dimensions of <image> and <svg> elements to keep the original image size.
                    imageElement.Height.BaseVal.ValueAsString = $"{h}px";
                    imageElement.Width.BaseVal.ValueAsString  = $"{w}px";

                    svgDoc.RootElement.Height.BaseVal.ValueAsString = $"{h}px";
                    svgDoc.RootElement.Width.BaseVal.ValueAsString  = $"{w}px";

                    //Append <image> into <g> element.
                    g.AppendChild(imageElement);
                }
                //Load svg file which contains the list of available filters.
                //We use the filters.svg file as a repository because it is easy to edit and add new filters.
                using (var filtersStream = new FileStream("filters.svg", FileMode.Open))
                    using (var filtersDoc = new SVGDocument(filtersStream, Directory.GetCurrentDirectory()))
                    {
                        var filter = filtersDoc.GetElementById(filterId);
                        svgDoc.RootElement.AppendChild(filter);
                        g.SetAttribute("filter", $"url(#{filter.Id})");
                        var options = new ImageSaveOptions()
                        {
                            HorizontalResolution = 96, VerticalResolution = 96
                        };
                        options.PageSetup.Sizing = SizingType.FitContent;
                        //Here we convert svg document with image and  graphic filter to the result image file.
                        Converter.ConvertSVG(svgDoc, options, outputFile);
                    }
            }
        }
Exemple #24
0
        public static void ConvertSVGToTIFF()
        {
            //ExStart: ConvertSVGToTIFF
            string dataDir = RunExamples.GetDataDir_Data();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                using (var device = new ImageDevice(new ImageRenderingOptions(ImageFormat.Tiff), dataDir + "smiley_out.tiff"))
                {
                    document.RenderTo(device);
                }
            }
            //ExEnd: ConvertSVGToTIFF
        }
Exemple #25
0
        internal string NewImage(UndirectedGraph <Pixel, TaggedUndirectedEdge <Pixel, EdgeTag> > g, Shapes shapes, string fileName = "image.svg")
        {
            svg = new SVGDocument(Width * scale + 1, Height * scale + 1);
            String data;
            Color  color = new Color();

            foreach (Shape shape in shapes)
            {
                data = "M ";
                Pixel lastPixel = null;
                for (int i = 0; i < shape.Count; i++)
                {
                    ArrayList curve = ((Curve)shape[i]).CurveToPoints();
                    if (i != 0 && !curve[0].Equals(lastPixel)) // Corrige curvas que possa estar no sentido errado
                    {
                        curve.Reverse();
                    }

                    Pixel pixel = curve[0] as Pixel;
                    lastPixel = curve[curve.Count - 1] as Pixel;
                    if (i == 0)
                    {
                        data += pixel.x + "," + pixel.y;
                    }

                    curve.Add(curve[curve.Count - 1]);

                    data += CatmullRom2bezier(curve) + " ";

                    color = ((Curve)shape[0]).Color;
                }
                svg.DrawPath(color, color, 0.01, data);
            }

            /*
             * foreach (var v in g.Vertices)
             * {
             *  svg.DrawCircle(Color.Blue,
             *         Color.Transparent,
             *         0,
             *         v.x * 7 + 7 / 2,
             *         v.y * 7 + 7 / 2,
             *         1);
             * }*/

            //Retorna o nome do arquivo salvo
            svg.Save(fileName);
            return(fileName);
        }
        public static void Run()
        {
            //ExStart: XPathQuery
            string dataDir = RunExamples.GetDataDir_SVG();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                //  Evaluate XPath expression
                var xpathResult = document.Evaluate("//rect[@x='100']", document, null, XPathResultType.Any, null);

                //  Get the next evaluated node
                Console.WriteLine((xpathResult.IterateNext() as Element)?.OuterHTML);
            }
            //ExEnd: XPathQuery
        }
        public static void Run()
        {
            //ExStart: 1
            string dataDir = RunExamples.GetDataDir_Save();

            SVGDocument document = new SVGDocument(dataDir + "complex.svg");

            SVGSaveOptions saveOptions = new SVGSaveOptions
            {
                VectorizeText = true
            };

            document.Save(dataDir + @"vectorized_text_out.svg", saveOptions);
            //ExEnd: 1
        }
        public static void Run()
        {
            //ExStart: ConvertSVGFilesUsingRenderer
            string dataDir = RunExamples.GetDataDir_Data();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                using (SvgRenderer renderer = new SvgRenderer())
                    using (XpsDevice device = new XpsDevice(dataDir + "ConvertSVGFilesUsingRenderer_out.xps"))
                    {
                        renderer.Render(device, document);
                    }
            }
            //ExEnd: ConvertSVGFilesUsingRenderer
        }
        public static void Run()
        {
            //ExStart: InspectDocumentContent
            string dataDir = RunExamples.GetDataDir_SVG();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                var svg  = document.DocumentElement;
                var g    = svg.GetElementsByTagName("g").First() as SVGGElement;
                var rect = g.FirstElementChild as SVGRectElement;

                Console.WriteLine(rect.Width);  // 90%
                Console.WriteLine(rect.Height); // 90%
            }
            //ExEnd: InspectDocumentContent
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory
            string dataDir = RunExamples.GetDataDir_Data();
            // Source SVG document
            SVGDocument svgDocument = new SVGDocument(dataDir + "input.svg");
            // Initialize ImageSaveOptions
            ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg);
            // Output file path
            string outputFile = dataDir + "SVGtoImage_Output.jpeg";

            // Convert SVG to Image
            Converter.ConvertSVG(svgDocument, options, outputFile);
            // ExEnd:1
        }
 public void DestroyAll(bool fullDestroy)
 {
     // set an empty sprite
     SpriteRenderer renderer = this.gameObject.GetComponent<SpriteRenderer>();
     if (renderer != null)
         renderer.sprite = null;
     // destroy SVG document, if loaded
     if (this.m_SvgDoc != null && fullDestroy)
     {
         this.m_SvgDoc.Dispose();
         this.m_SvgDoc = null;
     }
     // destroy sprite
     if (this.m_Sprite != null)
     {
     #if UNITY_EDITOR
         DestroyImmediate(this.m_Sprite);
     #else
         Destroy(this.m_Sprite);
     #endif
         this.m_Sprite = null;
     }
     // destroy texture
     if (this.m_Texture != null)
     {
     #if UNITY_EDITOR
         DestroyImmediate(this.m_Texture);
     #else
         Destroy(this.m_Texture);
     #endif
         this.m_Texture = null;
     }
 }
Exemple #32
0
 /***********************************************************************************/
 /*-----------------------------------------------------------
   Methods: CreateEmptySVGDocument
   Use: tao 1 SVGDocument trong, day la buoc khoi dau cua viec bat
   dau phan tich va do du lieu vao trong 1 SVGDocument
   -------------------------------------------------------------*/
 private void CreateEmptySVGDocument()
 {
     _svgDocument = new SVGDocument (this._SVGFile.text, this._graphics);
 }
    void Reset()
    {
        if (this.RequirementsCheck())
        {
            this.SVGFile = null;
            this.ScaleAdaption = SVGBackgroundScaleType.Horizontal;
            this.Size = 256;
            this.ClearColor = new Color(1, 1, 1, 0);
            this.GenerateOnStart = true;

            this.Sliced = false;
            this.SlicedWidth = 256;
            this.SlicedHeight = 256;

            this.m_SvgDoc = null;
            this.m_Texture = null;
            this.m_Sprite = null;
            this.DestroyAll(true);
        }
    }
Exemple #34
0
 public uint[] Add(SVGDocument svgDoc, bool explodeGroup)
 {
     uint[] info = new uint[2];
     // add an SVG document to the current packing task, and get back information about collected bounding boxes
     int err = AmanithSVG.svgtPackingAdd(svgDoc.Handle, explodeGroup ? AmanithSVG.SVGT_TRUE : AmanithSVG.SVGT_FALSE, info);
     
     // check for errors
     if (err != AmanithSVG.SVGT_NO_ERROR)
     {
         AmanithSVG.svgtErrorLog("SVGPacker.Begin error: ", err);
         return null;
     }
     // info[0] = number of collected bounding boxes
     // info[1] = the actual number of packed bounding boxes (boxes whose dimensions exceed the 'maxDimension' value specified to the svgtPackingBegin function, will be discarded)
     return info;
 }
 private void LoadSVG()
 {
     // create and load SVG document
     this.m_SvgDoc = (this.SVGFile != null) ? SVGAssets.CreateDocument(this.SVGFile.text) : null;
 }
Exemple #36
0
    /*
        Draw an SVG document, on this drawing surface.

        First the drawing surface is cleared if a valid (i.e. not null) clear color is provided.
        Then the specified document, if valid, is drawn.

        It returns true if the operation was completed successfully, else false.
    */
    public bool Draw(SVGDocument document, SVGColor clearColor, SVGRenderingQuality renderingQuality)
    {
        int err;

        // set clear color
        if (!this.SetClearColor(clearColor))
            return false;

        if (document != null)
        {
            // update document viewport (AmanithSVG backend)
            if (!document.UpdateViewport())
                return false;
            // update surface viewport (AmanithSVG backend)
            if (!this.UpdateViewport())
                return false;

            // draw the document
            if ((err = AmanithSVG.svgtDocDraw(document.Handle, this.Handle, (uint)renderingQuality)) != AmanithSVG.SVGT_NO_ERROR)
            {
                AmanithSVG.svgtErrorLog("Surface draw error (drawing document): ", err);
                return false;
            }
        }
        return true;
    }