Beispiel #1
0
        private static Bitmap renderSvg(System.String svgString, int width, int height)
        {
            try
            {
                if (svgBitmap != null)
                {
                    svgBitmap.Dispose();
                    svgBitmap = null;
                }

                SVG svg = SVG.GetFromString(svgString);
                svg.SetDocumentHeight(height.ToString());
                svg.SetDocumentWidth(width.ToString());

                svgBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb4444);
                Canvas canvas = new Canvas(svgBitmap);
                svg.RenderToCanvas(canvas);

                return(svgBitmap);
            }
            catch (Java.Lang.Exception e)
            {
                e.PrintStackTrace();
            }

            return(null);
        }
Beispiel #2
0
        public Group(SVG svg, XmlNode node, Shape parent)
            : base(svg, node)
        {
            // parent on group must be set before children are added
            var clp = XmlUtil.AttrValue(node, "clip-path", null);

            if (!string.IsNullOrEmpty(clp))
            {
                Shape  result;
                string id = ShapeUtil.ExtractBetween(clp, '(', ')');
                if (id.Length > 0 && id[0] == '#')
                {
                    id = id.Substring(1);
                }
                svg.m_shapes.TryGetValue(id, out result);
                this.m_clip = result as Clip;
            }

            this.Parent = parent;
            foreach (XmlNode childnode in node.ChildNodes)
            {
                Shape shape = AddToList(svg, this.m_elements, childnode, this);
                if (shape != null)
                {
                    shape.Parent = this;
                }
            }
        }
Beispiel #3
0
 public CircleShape(SVG svg, XmlNode node)
     : base(svg, node)
 {
     this.CX = XmlUtil.AttrValue(node, "cx", 0);
     this.CY = XmlUtil.AttrValue(node, "cy", 0);
     this.R  = XmlUtil.AttrValue(node, "r", 0);
 }
Beispiel #4
0
        protected override void Parse(SVG svg, string name, string value)
        {
            if (name.Contains(":"))
            {
                name = name.Split(':')[1];
            }

            if (name == SVGTags.sHref)
            {
                this.hRef = value;
                if (this.hRef.StartsWith("#"))
                {
                    this.hRef = this.hRef.Substring(1);
                }
                return;
            }
            if (name == "x")
            {
                this.X = XmlUtil.GetDoubleValue(value, svg.Size.Width);
                return;
            }
            if (name == "y")
            {
                this.Y = XmlUtil.GetDoubleValue(value, svg.Size.Height);
                return;
            }

            base.Parse(svg, name, value);
        }
        void ConvertToPathXaml(FileEntity file)
        {
            SVG svg = SVGReader.Read(file.FilePath);

            Drawing drawing = svg.GetDrawing();

            DrawingGroup group = drawing as DrawingGroup;

            Action <DrawingGroup> drawingAction = null;

            this.tx_code.Text = null;

            drawingAction = l =>
            {
                foreach (var item in l.Children)
                {
                    if (item is GeometryDrawing)
                    {
                        GeometryDrawing gd = item as GeometryDrawing;

                        string line = $"<Path Stroke=\"{gd.Pen?.Brush}\" Fill=\"{gd.Brush}\" Data=\"{gd.Geometry.ToString()}\"/>";

                        this.tx_code.Text += line.Replace($"Stroke =\"\"", "").Replace($"Fill =\"\"", "") + Environment.NewLine;
                    }
                    else if (item is DrawingGroup)
                    {
                        drawingAction(item as DrawingGroup);
                    }
                }
            };

            drawingAction(group);
        }
Beispiel #6
0
 public ImageShape(SVG svg, XmlNode node)
     : base(svg, node)
 {
     this.X = XmlUtil.AttrValue(node, "x", 0);
     this.Y = XmlUtil.AttrValue(node, "y", 0);
     this.Width = XmlUtil.AttrValue(node, "width", 0);
     this.Height = XmlUtil.AttrValue(node, "height", 0);
     string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty);
     if (hRef.Length > 0)
     {
         BitmapImage b = new BitmapImage();
         b.BeginInit();
         if (hRef.StartsWith("data:image/png;base64"))
         {
             b.StreamSource = new System.IO.MemoryStream(Convert.FromBase64String(hRef.Substring("data:image/png;base64,".Length)));
         }
         else
         {
             // filename given must be relative to the location of the svg file
             string svgpath = System.IO.Path.GetDirectoryName(svg.Filename);
             string filename = System.IO.Path.Combine(svgpath, hRef);
             b.UriSource = new Uri(filename, UriKind.RelativeOrAbsolute);
         }
         b.EndInit();
         this.ImageSource = b;
     }
 }
 public string Create(SVG svg, XmlNode node)
 {
     if (node.Name == SVGTags.sLinearGradient)
     {
         string id = XmlUtil.AttrValue(node, "id");
         if (this.m_servers.ContainsKey(id) == false)
         {
             this.m_servers[id] = new LinearGradientColorPaintServerPaintServer(this, node);
         }
         return(id);
     }
     if (node.Name == SVGTags.sRadialGradient)
     {
         string id = XmlUtil.AttrValue(node, "id");
         if (this.m_servers.ContainsKey(id) == false)
         {
             this.m_servers[id] = new RadialGradientColorPaintServerPaintServer(this, node);
         }
         return(id);
     }
     if (node.Name == SVGTags.sPattern)
     {
         string id = XmlUtil.AttrValue(node, "id");
         if (this.m_servers.ContainsKey(id) == false)
         {
             this.m_servers[id] = new PatternPaintServer(this, svg, node);
         }
         return(id);
     }
     return(null);
 }
 public override Brush GetBrush(double opacity, SVG svg)
 {
     byte a = (byte)(255 * opacity / 100);
     Color c = this.Color;
     Color newcol = System.Windows.Media.Color.FromArgb(a, c.R, c.G, c.B);
     return new SolidColorBrush(newcol);
 }
Beispiel #9
0
        /// <summary>
        /// 绘制缩略图
        /// </summary>
        /// <param name="g"></param>
        /// <param name="doc"></param>
        private void DrawPic(Graphics g, SvgDocument doc)
        {
            if (doc == null && doc.RootElement == null)
            {
                return;
            }
            SVG svgroot = doc.RootElement as SVG;

            if (svgroot == null)
            {
                return;
            }
            RectangleF rtf1;

            rtf1 = svgroot.ContentBounds;
            SizeF sf1 = vectorControl.DocumentSize;

            if (!rtf1.IsEmpty)
            {
                sf1 = rtf1.Size;
            }
            else
            {
                rtf1.Size = sf1;
            }
            SizeF sf2 = this.viewPic.Size;

            scale = GetScaleSingle(sf2, rtf1.Size);

            g.DrawRectangle(Pens.Black, offX, offY, scale * sf1.Width + 1, scale * sf1.Height + 1);
            g.FillRectangle(Brushes.White, offX, offY, scale * sf1.Width, scale * sf1.Height);

            using (Matrix matrix1 = new Matrix())
            {
                matrix1.Translate(-rtf1.X, -rtf1.Y, MatrixOrder.Prepend);
                matrix1.Scale(scale, scale, MatrixOrder.Append);
                matrix1.Translate(offX, offY, MatrixOrder.Append);
                Matrix matrix2 = svgroot.GraphTransform.Matrix.Clone();
                svgroot.GraphTransform.Matrix = matrix1;

                if (svgroot != null)
                {
                    svgroot.Draw(g, 0);
                }
                svgroot.GraphTransform.Matrix = matrix2;
            }
            RectangleF rtf3 = this.viewBounds;

            rtf3.Width  *= scale;
            rtf3.Height *= scale;
            //rtf3.Offset(-rtf1.X, -rtf1.Y);
            rtf3.X *= scale;
            rtf3.Y *= scale;
            rtf3.Offset(offX, offY);

            Pen tempPen = new Pen(Color.Blue, 2);

            g.TranslateTransform(-rtf1.X * scale, -rtf1.Y * scale);
            g.DrawRectangle(tempPen, Rectangle.Round(rtf3));
        }
Beispiel #10
0
        public ImageShape(SVG svg, XmlNode node) : base(svg, node)
        {
            this.X      = XmlUtil.AttrValue(node, "x", 0, svg.Size.Width);
            this.Y      = XmlUtil.AttrValue(node, "y", 0, svg.Size.Height);
            this.Width  = XmlUtil.AttrValue(node, "width", 0, svg.Size.Width);
            this.Height = XmlUtil.AttrValue(node, "height", 0, svg.Size.Height);
            string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty);

            if (hRef.Length > 0)
            {
                try
                {
                    BitmapImage b = new BitmapImage();
                    b.BeginInit();
                    if (hRef.StartsWith("data:image/png;base64"))
                    {
                        b.StreamSource = new MemoryStream(Convert.FromBase64String(hRef.Substring("data:image/png;base64,".Length)));
                    }
                    else
                    {
                        if (svg.ExternalFileLoader != null)
                        {
                            b.StreamSource = svg.ExternalFileLoader.LoadFile(hRef, svg.Filename);
                        }
                    }

                    b.EndInit();
                    this.ImageSource = b;
                }
                catch (Exception ex)
                { }
            }
        }
Beispiel #11
0
    // What to do when the user wants to export a TeX file
    private void exportHandler(object sender, EventArgs e)
    {
        Stream         stream;
        SaveFileDialog saveFileDialog = new SaveFileDialog();

        saveFileDialog.Filter           = "SVG files|*.svg|TeX files|(*.tex)";
        saveFileDialog.RestoreDirectory = true;

        if (saveFileDialog.ShowDialog() == DialogResult.OK)
        {
            if ((stream = saveFileDialog.OpenFile()) != null)
            {
                // Insert code here that generates the string of LaTeX
                //   commands to draw the shapes

                SVG graphics = new SVG();
                foreach (Shape shape in shapes)
                {
                    shape.Draw(graphics);
                }
                graphics.Export();

                //System.IO.File.WriteAllLines(saveFileDialog.FileName, graphics.Document);

                using (StreamWriter writer = new StreamWriter(stream))
                {
                    // Write strings to the file here using:
                    foreach (string regel in graphics.Document)
                    {
                        writer.WriteLine(regel);
                    }
                }
            }
        }
    }
Beispiel #12
0
        // SVG
        private static Bitmap renderSvg(System.String svgString, Bitmap bitmap)
        {
            try
            {
                if (svgBitmap != null)
                {
                    svgBitmap.Dispose();
                    svgBitmap = null;
                }

                SVG svg = SVG.GetFromString(svgString);
                svg.SetDocumentHeight(bitmap.Height.ToString());
                svg.SetDocumentWidth(bitmap.Width.ToString());

                svgBitmap = bitmap.Copy(bitmap.GetConfig(), true);
                Canvas canvas = new Canvas(svgBitmap);
                svg.RenderToCanvas(canvas);

                return(svgBitmap);
            }
            catch (Java.Lang.Exception e)
            {
                e.PrintStackTrace();
            }

            return(bitmap);
        }
Beispiel #13
0
        private void RenderTo(Graphics g)
        {
            setTJhide();
            SvgDocument svgdoc  = tlVectorControl1.SVGDocument;
            Matrix      matrix1 = new Matrix();
            Matrix      matrix2 = new Matrix();

            matrix1 = ((SVG)svgdoc.RootElement).GraphTransform.Matrix;
            matrix2.Multiply(matrix1);
            matrix1.Reset();
            matrix1.Multiply(g.Transform);
            g.ResetTransform();
            try
            {
                SVG svg1 = svgdoc.DocumentElement as SVG;
                svgdoc.BeginPrint = true;
                SmoothingMode mode1 = svgdoc.SmoothingMode;
                svgdoc.SmoothingMode = g.SmoothingMode;
                svg1.Draw(g, svgdoc.ControlTime);
                svgdoc.SmoothingMode = mode1;
                svgdoc.BeginPrint    = false;
            }
            finally
            {
                g.Transform = matrix1.Clone();
                matrix1.Reset();
                matrix1.Multiply(matrix2);
            }
            setTJshow();
        }
Beispiel #14
0
        /// <summary>
        /// The SVGElementTest function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A SVGElementTestOutputs instance containing computed results and the model with any new elements.</returns>
        public static SVGElementTestOutputs Execute(Dictionary <string, Model> inputModels, SVGElementTestInputs input)
        {
            var outputs = new SVGElementTestOutputs();
            // var svgFile = input.SVGFile.LocalFilePath;
            // var fileName = Path.GetFileNameWithoutExtension(svgFile);
            // var svgContent = File.ReadAllText(svgFile);
            // var svgElement = new SVGGraphic(svgContent, Guid.NewGuid(), fileName);
            // outputs.Model.AddElement(svgElement);
            var rect = Polygon.Rectangle(input.Length, input.Width);
            var svg  = new SVG();

            svg.AddGeometry(Polygon.Rectangle(10, 10), new SVG.Style
            {
                EnableFill   = false,
                EnableStroke = false
            });
            svg.AddGeometry(rect, new SVG.Style
            {
                Fill        = Colors.Red,
                Stroke      = Colors.Blue,
                StrokeWidth = input.StrokeWidth
            });
            var svgElement2 = new SVGGraphic(svg.SvgString(), Guid.NewGuid(), "Rectangle");

            outputs.Model.AddElement(svgElement2);
            return(outputs);
        }
        void ImportSVG(string file)
        {
            SVG svg = new SVG(file);

            originalPoints.Clear();
            imported = svg.CreateSplineComputers(Vector3.zero, Quaternion.identity);
            if (imported.Count == 0)
            {
                return;
            }
            importedParent = new GameObject(svg.name);
            foreach (SplineComputer comp in imported)
            {
                comp.transform.parent = importedParent.transform;
            }
#if UNITY_2019_1_OR_NEWER
            SceneView.duringSceneGui += OnScene;
#else
            SceneView.onSceneGUIDelegate += OnScene;
#endif

            GetImportedPoints();
            ApplyPoints();
            promptSave = true;
        }
Beispiel #16
0
        protected virtual void Parse(SVG svg, ShapeUtil.Attribute attr)
        {
            string name  = attr.Name;
            string value = attr.Value;

            this.Parse(svg, name, value);
        }
Beispiel #17
0
        public ImageShape(SVG svg, XmlNode node)
            : base(svg, node)
        {
            this.X      = XmlUtil.AttrValue(node, "x", 0);
            this.Y      = XmlUtil.AttrValue(node, "y", 0);
            this.Width  = XmlUtil.AttrValue(node, "width", 0);
            this.Height = XmlUtil.AttrValue(node, "height", 0);
            string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty);

            if (hRef.Length > 0)
            {
                BitmapImage b = new BitmapImage();
                b.BeginInit();
                if (hRef.StartsWith("data:image/png;base64"))
                {
                    b.StreamSource = new System.IO.MemoryStream(Convert.FromBase64String(hRef.Substring("data:image/png;base64,".Length)));
                }
                else
                {
                    // filename given must be relative to the location of the svg file
                    string svgpath  = System.IO.Path.GetDirectoryName(svg.Filename);
                    string filename = System.IO.Path.Combine(svgpath, hRef);
                    b.UriSource = new Uri(filename, UriKind.RelativeOrAbsolute);
                }
                b.EndInit();
                this.ImageSource = b;
            }
        }
Beispiel #18
0
 public CircleShape(SVG svg, XmlNode node)
     : base(svg, node)
 {
     this.CX = XmlUtil.AttrValue(node, "cx", 0);
     this.CY = XmlUtil.AttrValue(node, "cy", 0);
     this.R = XmlUtil.AttrValue(node, "r", 0);
 }
Beispiel #19
0
        private void updatePreview(int vectorIndex, VectorAction action, PictureBox box)
        {
            if (vectorIndex < 0 || vectorIndex >= vectors.Count || vectors.Count == 0)
            {
                return;
            }

            SVG                 temp        = Editor.svgFromDataFactory(vectors[vectorIndex].data);
            List <SVG>          tempVectors = new List <SVG>();
            List <VectorAction> tempActions = new List <VectorAction>();

            tempVectors.Add(temp);

            if (action != null)
            {
                tempActions.Add(action);
            }

            tempActions.AddRange(actions);

            Editor.refreshActions(tempActions);
            Editor.assignAllActions(tempVectors, tempActions);
            Editor.doActions(tempVectors);

            drawPreview(tempVectors[0], svgPreview);
        }
Beispiel #20
0
        private void drawPreview(SVG vector, PictureBox box)
        {
            if (vector == null || box == null)
            {
                return;
            }

            SVG previewVector = showOriginalVector ? vectors[selectedVector] : vector;

            using (Bitmap preview = Editor.getPreview(previewVector))
            {
                if (preview == null)
                {
                    box.Image = box.InitialImage;
                }

                using (Bitmap finalPreview = new Bitmap(box.Width, box.Height))
                {
                    using (Graphics g = Graphics.FromImage(finalPreview))
                    {
                        g.DrawImage(preview, new Point((box.Width - preview.Width) / 2, (box.Height - preview.Height) / 2));
                    }

                    box.Image = (Image)finalPreview.Clone();
                }
            }
        }
Beispiel #21
0
        public IActionResult Post([FromBody] SVG svg)
        {
            svg.PNG = SVG2Binary(svg.Specification);
            _dbContext.SVGs.Add(svg);
            _dbContext.SaveChanges();

            return(Content(svg.Id.ToString()));
        }
Beispiel #22
0
 protected TextStyle GetTextStyle(SVG svg)
 {
     if (this.m_textstyle == null)
     {
         this.m_textstyle = new TextStyle(svg, this);
     }
     return(this.m_textstyle);
 }
Beispiel #23
0
 protected Fill GetFill(SVG svg)
 {
     if (this.m_fill == null)
     {
         this.m_fill = new Fill(svg);
     }
     return(this.m_fill);
 }
Beispiel #24
0
 private Stroke GetStroke(SVG svg)
 {
     if (this.m_stroke == null)
     {
         this.m_stroke = new Stroke(svg);
     }
     return(this.m_stroke);
 }
Beispiel #25
0
 public EllipseShape(SVG svg, XmlNode node)
     : base(svg, node)
 {
     this.CX = XmlUtil.AttrValue(node, "cx", 0);
     this.CY = XmlUtil.AttrValue(node, "cy", 0);
     this.RX = XmlUtil.AttrValue(node, "rx", 0);
     this.RY = XmlUtil.AttrValue(node, "ry", 0);
 }
Beispiel #26
0
 public EllipseShape(SVG svg, XmlNode node)
     : base(svg, node)
 {
     this.CX = XmlUtil.AttrValue(node, "cx", 0);
     this.CY = XmlUtil.AttrValue(node, "cy", 0);
     this.RX = XmlUtil.AttrValue(node, "rx", 0);
     this.RY = XmlUtil.AttrValue(node, "ry", 0);
 }
Beispiel #27
0
 public UseShape(SVG svg, XmlNode node)
     : base(svg, node)
 {
     this.X = XmlUtil.AttrValue(node, "x", 0);
     this.Y = XmlUtil.AttrValue(node, "y", 0);
     this.hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty);
     if (this.hRef.StartsWith("#")) this.hRef = this.hRef.Substring(1);
 }
Beispiel #28
0
 public RectangleShape(SVG svg, XmlNode node) : base(svg, node)
 {
     //if (DefaultFill == null)
     //{
     //    DefaultFill = new Fill(svg);
     //    DefaultFill.PaintServerKey = svg.PaintServers.Parse("black");
     //}
 }
        public override Brush GetBrush(double opacity, SVG svg, SVGRender svgRender, Rect bounds)
        {
            byte  a      = (byte)(255 * opacity / 100);
            Color c      = this.Color;
            Color newcol = System.Windows.Media.Color.FromArgb(a, c.R, c.G, c.B);

            return(new SolidColorBrush(newcol));
        }
Beispiel #30
0
 public RectangleShape(SVG svg, XmlNode node) : base(svg, node)
 {
     if (DefaultFill == null)
     {
         DefaultFill       = new Fill(svg);
         DefaultFill.Color = svg.PaintServers.Parse("black");
     }
 }
Beispiel #31
0
            public bool isEqual(SVG vector)
            {
                if (vector == null)
                {
                    return(false);
                }

                return(vector.data.Equals(_data) && vector.path.Equals(_path));
            }
Beispiel #32
0
 public Shape(SVG svg, List<ShapeUtil.Attribute> attrs, Shape parent)
     : base(null)
 {
     this.Parent = parent;
     if (attrs != null)
     {
         foreach (ShapeUtil.Attribute attr in attrs) this.Parse(svg, attr);
     }
 }
Beispiel #33
0
 public Shape(SVG svg, XmlNode node, Shape parent)
     : base(node)
 {
     this.Parent = parent;
     if (node != null)
     {
         foreach (XmlAttribute attr in node.Attributes) this.Parse(svg, attr);
     }
 }
        private void CenterSVGPath()
        {
            // Move icon to center of "dot"
            SKRect iconBounds = new SKRect();

            SVG.GetBounds(out iconBounds);
            SKMatrix translate = SKMatrix.MakeTranslation(Center.X - iconBounds.Width / 2, Center.Y - iconBounds.Height / 2);

            SVG.Transform(translate);
        }
Beispiel #35
0
 public LineShape(SVG svg, XmlNode node)
     : base(svg, node)
 {
     double x1 = XmlUtil.AttrValue(node, "x1", 0);
     double y1 = XmlUtil.AttrValue(node, "y1", 0);
     double x2 = XmlUtil.AttrValue(node, "x2", 0);
     double y2 = XmlUtil.AttrValue(node, "y2", 0);
     this.P1 = new Point(x1, y1);
     this.P2 = new Point(x2, y2);
 }
Beispiel #36
0
        private void addThumbnail(SVG svg)
        {
            ListViewItem item = new ListViewItem();

            thumbnails.Images.Add(svg.path, Editor.getPreview(svg));
            item.ImageKey          = svg.path;
            item.Tag               = svg.path;
            svgList.LargeImageList = thumbnails;
            svgList.Items.Add(item);
        }
Beispiel #37
0
        public LineShape(SVG svg, XmlNode node) : base(svg, node)
        {
            double x1 = XmlUtil.AttrValue(node, "x1", 0, svg.Size.Width);
            double y1 = XmlUtil.AttrValue(node, "y1", 0, svg.Size.Height);
            double x2 = XmlUtil.AttrValue(node, "x2", 0, svg.Size.Width);
            double y2 = XmlUtil.AttrValue(node, "y2", 0, svg.Size.Height);

            this.P1 = new Point(x1, y1);
            this.P2 = new Point(x2, y2);
        }
        public override Brush GetBrush(double opacity, SVG svg, SVGRender svgRender, Rect bounds)
        {
            if (this.brush != null)
            {
                return(this.brush);
            }

            RadialGradientBrush b = new RadialGradientBrush();

            foreach (GradientStop stop in this.Stops)
            {
                b.GradientStops.Add(stop);
            }

            b.GradientOrigin = new System.Windows.Point(0.5, 0.5);
            b.Center         = new System.Windows.Point(0.5, 0.5);
            b.RadiusX        = 0.5;
            b.RadiusY        = 0.5;

            if (this.GradientUnits == SVGTags.sUserSpaceOnUse)
            {
                b.Center         = new System.Windows.Point(this.CX, this.CY);
                b.GradientOrigin = new System.Windows.Point(this.FX, this.FY);
                b.RadiusX        = this.R;
                b.RadiusY        = this.R;
                b.MappingMode    = BrushMappingMode.Absolute;
            }
            else
            {
                double scale = 1d / 100d;
                if (double.IsNaN(this.CX) == false && double.IsNaN(this.CY) == false)
                {
                    //b.GradientOrigin = new System.Windows.Point(this.CX*scale, this.CY*scale);
                    b.Center = new System.Windows.Point(this.CX /* *scale */, this.CY /* *scale */);
                }
                if (double.IsNaN(this.FX) == false && double.IsNaN(this.FY) == false)
                {
                    b.GradientOrigin = new System.Windows.Point(this.FX * scale, this.FY * scale);
                }
                if (double.IsNaN(this.R) == false)
                {
                    b.RadiusX = this.R /* *scale*/;
                    b.RadiusY = this.R /* *scale*/;
                }
                b.MappingMode = BrushMappingMode.RelativeToBoundingBox;
            }
            if (this.Transform != null)
            {
                b.Transform = this.Transform;
            }

            this.brush = b;

            return(b);
        }
		public void Load (Context context, int svgResource)
		{
			if (svg != null)
				return;
			try {
				svg = SVG.GetFromResource (context,svgResource);
				svg.DocumentPreserveAspectRatio = PreserveAspectRatio.Unscaled;
			} catch (Exception e) {
				Log.Error (LOG_TAG, "Could not load specified SVG resource", e);
			}
		}
Beispiel #40
0
        public RectangleShape(SVG svg, XmlNode node)
            : base(svg, node)
        {
            this.X = XmlUtil.AttrValue(node, "x", 0);
            this.Y = XmlUtil.AttrValue(node, "y", 0);
            this.Width = XmlUtil.AttrValue(node, "width", 0);
            this.Height = XmlUtil.AttrValue(node, "height", 0);
            this.RX = XmlUtil.AttrValue(node, "rx", 0);
            this.RY = XmlUtil.AttrValue(node, "ry", 0);

            if (DefaultFill == null)
            {
                DefaultFill = new Fill(svg);
                DefaultFill.Color = svg.PaintServers.Parse("black");
            }
        }
        public override Brush GetBrush(double opacity, SVG svg)
        {
            if (this.brush != null) return this.brush;

            RadialGradientBrush b = new RadialGradientBrush();
            foreach (GradientStop stop in this.Stops) b.GradientStops.Add(stop);

            b.GradientOrigin = new System.Windows.Point(0.5, 0.5);
            b.Center = new System.Windows.Point(0.5, 0.5);
            b.RadiusX = 0.5;
            b.RadiusY = 0.5;

            if (this.GradientUnits == SVGTags.sGradientUserSpace)
            {
                b.Center = new System.Windows.Point(this.CX, this.CY);
                b.GradientOrigin = new System.Windows.Point(this.FX, this.FY);
                b.RadiusX = this.R;
                b.RadiusY = this.R;
                b.MappingMode = BrushMappingMode.Absolute;
            }
            else
            {
                double scale = 1d / 100d;
                if (double.IsNaN(this.CX) == false && double.IsNaN(this.CY) == false)
                {
                    //b.GradientOrigin = new System.Windows.Point(this.CX*scale, this.CY*scale);
                    b.Center = new System.Windows.Point(this.CX /* *scale */, this.CY /* *scale */);
                }
                if (double.IsNaN(this.FX) == false && double.IsNaN(this.FY) == false)
                {
                    b.GradientOrigin = new System.Windows.Point(this.FX * scale, this.FY * scale);
                }
                if (double.IsNaN(this.R) == false)
                {
                    b.RadiusX = this.R /* *scale*/;
                    b.RadiusY = this.R /* *scale*/;
                }
                b.MappingMode = BrushMappingMode.RelativeToBoundingBox;
            }
            if (this.Transform != null) b.Transform = this.Transform;

            this.brush = b;

            return b;
        }
Beispiel #42
0
        public PolygonShape(SVG svg, XmlNode node)
            : base(svg, node)
        {
            if (DefaultFill == null)
            {
                DefaultFill = new Fill(svg);
                DefaultFill.Color = svg.PaintServers.Parse("black");
            }

            string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty);
            ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points);
            List<Point> list = new List<Point>();
            while (split.More)
            {
                list.Add(split.ReadNextPoint());
            }
            this.Points = list.ToArray();
        }
Beispiel #43
0
        public Group(SVG svg, XmlNode node, Shape parent)
            : base(svg, node)
        {
            // parent on group must be set before children are added
            var clp = XmlUtil.AttrValue(node, "clip-path", null);
            if (!string.IsNullOrEmpty(clp))
            {
                Shape result;
                string id = ShapeUtil.ExtractBetween(clp, '(', ')');
                if (id.Length > 0 && id[0] == '#') id = id.Substring(1);
                svg.m_shapes.TryGetValue(id, out result);
                this.m_clip = result as Clip;
            }

            this.Parent = parent;
            foreach (XmlNode childnode in node.ChildNodes)
            {
                Shape shape = AddToList(svg, this.m_elements, childnode, this);
                if (shape != null) shape.Parent = this;
            }
            if (this.Id.Length > 0) svg.AddShape(this.Id, this);
        }
Beispiel #44
0
        public void Circles(SVG svgDoc, XmlNode parent, Attr attr)
        {
            int oldIndex = this.genes.Index;

            this.genes.Index = DEFAULT_CIRCLE_INDEX;

            XmlNode mainGroup = svgDoc.Group(parent, attr);

            int numRings = (int)(this.genes.Next() * (float)CIRCLE_RING_RANGE) + CIRCLE_RING_MIN;
            int harmonic = this.harmonic;

            for (int r = 0; r < numRings; r++)
            {
                int numCircs = (int)((this.genes.Next() * (float)CIRCLE_CIRC_RANGE) + CIRCLE_CIRC_MIN) * harmonic;
                float circRadii = this.genes.Next() * CIRC_RADII_MAX;
                float ringRadii = this.genes.Next() * CIRC_RADII_MAX;

                float angCirc = (float)(Math.PI * 2.0) / (float)numCircs;

                float ringPhase = this.genes.Next() < 0.5f ? 0.0f : (angCirc * 0.5f);

                float strokeWidth = this.genes.Next() * MAX_STROKE_WIDTH;

                for (int c = 0; c < numCircs; c++)
                {
                    float cx = (float)Math.Sin(angCirc * c) * ringRadii + MIDX;
                    float cy = (float)Math.Cos(angCirc * c) * ringRadii + MIDY;

                    svgDoc.Circle(mainGroup, cx, cy, circRadii, new Attr() {
                                                                                {"fill",         "none"},
                                                                                {"stroke",       "black"},
                                                                                {"stroke-width", strokeWidth.ToString("0.###")}
                                                                            });
                }
            }

            this.genes.Index = oldIndex;
        }
        public override Brush GetBrush(double opacity, SVG svg)
        {
            if (this.brush != null) return this.brush;

            LinearGradientBrush b = new LinearGradientBrush();
            foreach (GradientStop stop in this.Stops) b.GradientStops.Add(stop);

            b.MappingMode = BrushMappingMode.RelativeToBoundingBox;
            b.StartPoint = new System.Windows.Point(0, 0);
            b.EndPoint = new System.Windows.Point(1, 0);

            if (this.GradientUnits == SVGTags.sGradientUserSpace)
            {
                Transform tr = this.Transform as Transform;
                if (tr != null)
                {
                    b.StartPoint = tr.Transform(new System.Windows.Point(this.X1, this.Y1));
                    b.EndPoint = tr.Transform(new System.Windows.Point(this.X2, this.Y2));
                }
                else
                {
                    b.StartPoint = new System.Windows.Point(this.X1, this.Y1);
                    b.EndPoint = new System.Windows.Point(this.X2, this.Y2);
                }
                this.Transform = null;
                b.MappingMode = BrushMappingMode.Absolute;
            }
            else
            {
                this.Normalize();
                if (double.IsNaN(this.X1) == false) b.StartPoint = new System.Windows.Point(this.X1, this.Y1);
                if (double.IsNaN(this.X2) == false) b.EndPoint = new System.Windows.Point(this.X2, this.Y2);
            }

            this.brush = b;

            return b;
        }
Beispiel #46
0
 protected Fill GetFill(SVG svg)
 {
     if (this.m_fill == null) this.m_fill = new Fill(svg);
     return this.m_fill;
 }
Beispiel #47
0
 public Shape(SVG svg, XmlNode node)
     : this(svg, node, null)
 {
 }
Beispiel #48
0
 private Stroke GetStroke(SVG svg)
 {
     if (this.m_stroke == null) this.m_stroke = new Stroke(svg);
     return this.m_stroke;
 }
Beispiel #49
0
 public abstract Brush GetBrush(double opacity, SVG svg);
Beispiel #50
0
        public override XmlElement CreateElement(string prefix, string localName, string ns)
        {
            XmlElement element1;
            if (this.firstload)
            {
            //				SvgElement element2 = null;
                if (this.preelement != null)
                {
                    //                    if (this.preelement.ParentNode == null)
                    //                    {
                    //                        if (this.groups.Count > 0)
                    //                        {
                    //                            element2 = (SvgElement) this.groups[this.groups.Count - 1];
                    //                            if ((element2 is ContainerElement) && ((ContainerElement) element2).IsValidChild(this.preelement))
                    //                            {
                    //                                ((ContainerElement) element2).ChildList.Add(this.preelement);
                    //                            }
                    //                        }
                    //                        this.groups.Add(this.preelement);
                    //                    }
                    //                    else if (this.groups.Count > 0)
                    //                    {
                    //						if(this.preelement.ParentNode is ContainerElement && ((ContainerElement) this.preelement.ParentNode).IsValidChild(this.preelement))
                    //						{
                    //							((ContainerElement)this.preelement.ParentNode).ChildList.Add(this.preelement);
                    //						}
                    //
                    //                    }
                }
            }
            switch (localName)
            {
                case "clipPath":
                {
                    element1 = new ClipPath(prefix, localName, ns, this);
                    break;
                }
                case "rect":
                {
                    element1 = new RectangleElement(prefix, localName, ns, this);
                    break;
                }
                case "path":
                {
                    element1 = new GraphPath(prefix, localName, ns, this);
                    break;
                }
                case "polyline":
                {
                    element1 = new Polyline(prefix, localName, ns, this);
                    break;
                }
                case "polygon":
                {
                    element1 = new Polygon(prefix, localName, ns, this);
                    break;
                }
                case "circle":
                {
                    element1 = new Circle(prefix, localName, ns, this);
                    break;
                }
                case "ellipse":
                {
                    element1 = new Ellips(prefix, localName, ns, this);
                    break;
                }
                case "script":
                {
                    element1 = new SvgScript(prefix, localName, ns, this);
                    break;
                }
                case "line":
                {
                    element1 = new Line(prefix, localName, ns, this);
                    break;
                }
                case "connectline":
                case "connect":
                {
                    element1 = new ConnectLine(prefix, localName, ns, this);
                    break;
                }
                case "g":
                {
                    element1 = new Group(prefix, localName, ns, this);
                    break;
                }
                case "svg":
                {
                    element1 = new SVG(prefix, localName, ns, this);
                    break;
                }
                case "text":
                {
                    element1 = new Text(prefix, localName, ns, this);
                    break;
                }
                case "tspan":
                {
                    element1 = new TSpan(prefix, localName, ns, this);
                    break;
                }
                case "tref":
                {
                    element1 = new TRef(prefix, localName, ns, this);
                    break;
                }
                case "linearGradient":
                {
                    element1 = new LinearGradient(prefix, localName, ns, this);
                    break;
                }
                case "radialGradient":
                {
                    element1 = new RadialGradients(prefix, localName, ns, this);
                    break;
                }
                case "stop":
                {
                    element1 = new GradientStop(prefix, localName, ns, this);
                    break;
                }
                case "symbol":
                {
                    element1 = new ItopVector.Core.Figure.Symbol(prefix, localName, ns, this);
                    break;
                }
                case "marker":
                {
                    element1 = new ItopVector.Core.Figure.Marker(prefix, localName, ns, this);
                    break;
                }
                case "defs":
                {
                    element1 = new ItopVector.Core.Figure.Defs(prefix, localName, ns, this);
                    break;
                }
                case "image":
                {
                    element1 = new ItopVector.Core.Figure.Image(prefix, localName, ns, this);
                    break;
                }
                case "a":
                {
                    element1 = new ItopVector.Core.Figure.Link(prefix, localName, ns, this);
                    break;
                }
                case "use":
                {
                    element1 = new ItopVector.Core.Figure.Use(prefix, localName, ns, this);
                    break;
                }
                case "animate":
                {
                    element1 = new ItopVector.Core.Animate.Animate(prefix, localName, ns, this);
                    break;
                }
                case "set":
                {
                    element1 = new SetAnimate(prefix, localName, ns, this);
                    break;
                }
                case "animateColor":
                {
                    element1 = new ColorAnimate(prefix, localName, ns, this);
                    break;
                }
                case "animateMotion":
                {
                    element1 = new MotionAnimate(prefix, localName, ns, this);
                    break;
                }
                case "animateTransform":
                {
                    element1 = new TransformAnimate(prefix, localName, ns, this);
                    break;
                }
                case "pattern":
                {
                    element1 = new Pattern(prefix, localName, ns, this);
                    break;
                }
                case "audio3d":
                case "audio":
                {
                    element1 = new AudioAnimate(prefix, localName, ns, this);
                    break;
                }
                case "state"://״̬
                {
                    element1 =new State(prefix, localName, ns, this);
                    break;
                }
                case "layer":
                {
                    element1 =new Layer(prefix, localName, ns, this);
                    break;
                }
                default:
                {
                    element1 = base.CreateElement(prefix, localName, ns);
                    break;
                }
            }
            if (element1 is SvgElement)
            {
                ((SvgElement) element1).ShowParticular = this.AutoShowAnim;
            }
            if ((element1 is SvgElement) && this.firstload)
            {
                this.preelement = (SvgElement) element1;
            }
            else
            {
                this.preelement = null;
            }
            if (this.xmlreader != null)
            {
                int num3 = this.xmlreader.LineNumber;
                int num4 = this.xmlreader.LinePosition;
            }
            //			if ((element1 is SVG) && (this.DocumentType == null))
            //			{
            //				XmlDocumentType type1 = this.CreateDocumentType("svg", "-/W3C/DTD SVG 1.1/EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null);
            //				this.AppendChild(type1);
            //				this.AppendChild(this.CreateWhitespace("\r\n"));
            //			}

            return element1;
        }
Beispiel #51
0
 protected virtual void Parse(SVG svg, string name, string value)
 {
     if (name == SVGTags.sTransform)
     {
         this.Transform = ShapeUtil.ParseTransform(value.ToLower());
         return;
     }
     if (name == SVGTags.sStroke)
     {
         this.GetStroke(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sStrokeWidth)
     {
         this.GetStroke(svg).Width = XmlUtil.ParseDouble(svg, value);
         return;
     }
     if (name == SVGTags.sStrokeOpacity)
     {
         this.GetStroke(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sStrokeDashArray)
     {
         if (value == "none")
         {
             this.GetStroke(svg).StrokeArray = null;
             return;
         }
         ShapeUtil.StringSplitter sp = new ShapeUtil.StringSplitter(value);
         List<double> a = new List<double>();
         while (sp.More)
         {
             a.Add(sp.ReadNextValue());
         }
         this.GetStroke(svg).StrokeArray = a.ToArray();
         return;
     }
     if (name == SVGTags.sStrokeLinecap)
     {
         this.GetStroke(svg).LineCap = (Stroke.eLineCap)Enum.Parse(typeof(Stroke.eLineCap), value);
         return;
     }
     if (name == SVGTags.sStrokeLinejoin)
     {
         this.GetStroke(svg).LineJoin = (Stroke.eLineJoin)Enum.Parse(typeof(Stroke.eLineJoin), value);
         return;
     }
     if (name == SVGTags.sClipPath)
     {
         if (value.StartsWith("url"))
         {
             Shape result;
             string id = ShapeUtil.ExtractBetween(value, '(', ')');
             if (id.Length > 0 && id[0] == '#') id = id.Substring(1);
             svg.m_shapes.TryGetValue(id, out result);
             this.m_clip = result as Clip;
             return;
         }
         return;
     }
     if (name == SVGTags.sFill)
     {
         this.GetFill(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sFillOpacity)
     {
         this.GetFill(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sFillRule)
     {
         this.GetFill(svg).FillRule = (Fill.eFillRule)Enum.Parse(typeof(Fill.eFillRule), value);
         return;
     }
     if (name == SVGTags.sStyle)
     {
         foreach (ShapeUtil.Attribute item in XmlUtil.SplitStyle(svg, value)) this.Parse(svg, item);
     }
     //********************** text *******************
     if (name == SVGTags.sFontFamily)
     {
         this.GetTextStyle(svg).FontFamily = value;
         return;
     }
     if (name == SVGTags.sFontSize)
     {
         this.GetTextStyle(svg).FontSize = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == SVGTags.sFontWeight)
     {
         this.GetTextStyle(svg).Fontweight = (FontWeight)new FontWeightConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sFontStyle)
     {
         this.GetTextStyle(svg).Fontstyle = (FontStyle)new FontStyleConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sTextDecoration)
     {
         TextDecoration t = new TextDecoration();
         if (value == "none") return;
         if (value == "underline") t.Location = TextDecorationLocation.Underline;
         if (value == "overline") t.Location = TextDecorationLocation.OverLine;
         if (value == "line-through") t.Location = TextDecorationLocation.Strikethrough;
         TextDecorationCollection tt = new TextDecorationCollection();
         tt.Add(t);
         this.GetTextStyle(svg).TextDecoration = tt;
         return;
     }
     if (name == SVGTags.sTextAnchor)
     {
         if (value == "start") this.GetTextStyle(svg).TextAlignment = TextAlignment.Left;
         if (value == "middle") this.GetTextStyle(svg).TextAlignment = TextAlignment.Center;
         if (value == "end") this.GetTextStyle(svg).TextAlignment = TextAlignment.Right;
         return;
     }
     if (name == "word-spacing")
     {
         this.GetTextStyle(svg).WordSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "letter-spacing")
     {
         this.GetTextStyle(svg).LetterSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "baseline-shift")
     {
         //GetTextStyle(svg).BaseLineShift = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         this.GetTextStyle(svg).BaseLineShift = value;
         return;
     }
 }
Beispiel #52
0
 private static void ReadDefs(SVG svg, List<Shape> list, XmlNode node)
 {
     list = new List<Shape>(); // temp list, not needed.
     //ShapeGroups defined in the 'def' section is added the the 'Shapes' dictionary in SVG for later reference
     foreach (XmlNode childnode in node.ChildNodes)
     {
         if (childnode.Name == SVGTags.sLinearGradient)
         {
             svg.PaintServers.Create(childnode);
             continue;
         }
         if (childnode.Name == SVGTags.sRadialGradient)
         {
             svg.PaintServers.Create(childnode);
             continue;
         }
         Group.AddToList(svg, list, childnode, null);
     }
 }
Beispiel #53
0
 protected TextStyle GetTextStyle(SVG svg)
 {
     if (this.m_textstyle == null) this.m_textstyle = new TextStyle(svg, this);
     return this.m_textstyle;
 }
Beispiel #54
0
        public static Shape AddToList(SVG svg, List<Shape> list, XmlNode childnode, Shape parent)
        {
            if (childnode.NodeType != XmlNodeType.Element) return null;

            if (childnode.Name == SVGTags.sShapeRect)
            {
                list.Add(new RectangleShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapeCircle)
            {
                list.Add(new CircleShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapeEllipse)
            {
                list.Add(new EllipseShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapeLine)
            {
                list.Add(new LineShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapePolyline)
            {
                list.Add(new PolylineShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapePolygon)
            {
                list.Add(new PolygonShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapePath)
            {
                list.Add(new PathShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sClipPath)
            {
                list.Add(new Clip(svg, childnode, parent));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapeGroup || childnode.Name == SVGTags.sSwitch)
            {
                list.Add(new Group(svg, childnode, parent));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sLinearGradient)
            {
                svg.PaintServers.Create(childnode);
                return null;
            }
            if (childnode.Name == SVGTags.sRadialGradient)
            {
                svg.PaintServers.Create(childnode);
                return null;
            }
            if (childnode.Name == SVGTags.sDefinitions)
            {
                ReadDefs(svg, list, childnode);
                return null;
            }
            if (childnode.Name == SVGTags.sShapeUse)
            {
                list.Add(new UseShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sShapeImage)
            {
                list.Add(new ImageShape(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == SVGTags.sAnimateTransform)
            {
                list.Add(new AnimateTransform(svg, childnode));
                return list[list.Count - 1];
            }
            if (childnode.Name == "text")
            {
                list.Add(new TextShape(svg, childnode, parent));
                return list[list.Count - 1];
            }
            return null;
        }
Beispiel #55
0
 protected virtual void Parse(SVG svg, ShapeUtil.Attribute attr)
 {
     string name = attr.Name;
     string value = attr.Value;
     this.Parse(svg, name, value);
 }
Beispiel #56
0
 public Clip(SVG svg, XmlNode node, Shape parent)
     : base(svg, node, parent)
 {
 }
Beispiel #57
0
        public static void StartTest(String testName = "all")
        {
            //start testing
            Console.WriteLine("Starting Testing...");
            /*
            SVG testDoc = new SVG(new Attr() {
                                                {"width" , "1000"},
                                                {"height" , "1000"}
                                             });
            */
            SVG testDoc = new SVG();

            if (testName == "defs" || testName == "all")
            {
                Console.WriteLine("Testing AddToDefs method...");

                XmlDocument newDef = new XmlDocument();

                newDef.LoadXml("<g>" +
                                "<helloDefs/>" +
                                "</g>"
                                );

                testDoc.AddToDefs(newDef);
            }

            if (testName == "group" || testName == "all")
            {
                Console.WriteLine("Testing Group method...");

                testDoc.Group(testDoc.root, new Attr() { { "GROUP_TEST", "TESTED" } });
            }

            if (testName == "use" || testName == "all")
            {
                Console.WriteLine("Testing Use method...");

                testDoc.Use(testDoc.root, "TESTED");
            }

            if (testName == "rect" || testName == "all")
            {
                Console.WriteLine("Testing Rect method...");

                testDoc.Rect(testDoc.root, 0.0f, 1.0f, 2.0f, 3.0f, 3.0f, 4.0f, new Attr() { { "RECT_TEST", "TESTED" } });
            }

            if (testName == "circle" || testName == "all")
            {
                Console.WriteLine("Testing Circle method...");

                testDoc.Circle(testDoc.root, 0.0f, 1.0f, 2.0f, new Attr() { { "CIRCLE_TEST", "TESTED" } });
            }

            if (testName == "ellipse" || testName == "all")
            {
                Console.WriteLine("Testing Ellipse method...");

                testDoc.Ellipse(testDoc.root, 0.0f, 1.0f, 2.0f, 3.0f, new Attr() { { "ELLIPSE_TEST", "TESTED" } });
            }

            if (testName == "line" || testName == "all")
            {
                Console.WriteLine("Testing Line method...");

                testDoc.Line(testDoc.root, 0.0f, 1.0f, 2.0f, 3.0f, new Attr() { { "LINE_TEST", "TESTED" } });
            }

            testDoc.svgDoc.Save(Console.Out);
            Console.WriteLine();
        }