Exemple #1
0
 public EllipseShape(SVG svg, XmlNode node) : base(svg, node)
 {
     CX = XmlUtil.AttrValue(node, "cx", 0);
     CY = XmlUtil.AttrValue(node, "cy", 0);
     RX = XmlUtil.AttrValue(node, "rx", 0);
     RY = XmlUtil.AttrValue(node, "ry", 0);
 }
Exemple #2
0
 public LinearGradientColor(PaintServerManager owner, XmlNode node) : base(owner, node)
 {
     System.Diagnostics.Debug.Assert(node.Name == SVGTags.sLinearGradient);
     Id = XmlUtil.AttrValue(node, "id");
     X1 = XmlUtil.AttrValue(node, "x1", double.NaN);
     Y1 = XmlUtil.AttrValue(node, "y1", double.NaN);
     X2 = XmlUtil.AttrValue(node, "x2", double.NaN);
     Y2 = XmlUtil.AttrValue(node, "y2", double.NaN);
 }
Exemple #3
0
 public UseShape(SVG svg, XmlNode node) : base(svg, node)
 {
     X    = XmlUtil.AttrValue(node, "x", 0);
     Y    = XmlUtil.AttrValue(node, "y", 0);
     hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty);
     if (hRef.StartsWith("#"))
     {
         hRef = hRef.Substring(1);
     }
 }
Exemple #4
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);

            P1 = new Point(x1, y1);
            P2 = new Point(x2, y2);
        }
Exemple #5
0
 public ClipArtElement(XmlNode node)
 {
     if (node == null)
     {
         Id = "<null>";
     }
     else
     {
         Id = XmlUtil.AttrValue(node, "id");
     }
 }
Exemple #6
0
        public RadialGradientColor(PaintServerManager owner, XmlNode node) : base(owner, node)
        {
            System.Diagnostics.Debug.Assert(node.Name == SVGTags.sRadialGradient);
            Id = XmlUtil.AttrValue(node, "id");

            CX = XmlUtil.AttrValue(node, "cx", double.NaN);
            CY = XmlUtil.AttrValue(node, "cy", double.NaN);
            FX = XmlUtil.AttrValue(node, "fx", double.NaN);
            FY = XmlUtil.AttrValue(node, "fy", double.NaN);
            R  = XmlUtil.AttrValue(node, "r", double.NaN);
            Normalize();
        }
Exemple #7
0
        public PolylineShape(SVG svg, XmlNode node) : base(svg, node)
        {
            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());
            }
            Points = list.ToArray();
        }
Exemple #8
0
        public RectangleShape(SVG svg, XmlNode node) : base(svg, node)
        {
            X      = XmlUtil.AttrValue(node, "x", 0);
            Y      = XmlUtil.AttrValue(node, "y", 0);
            Width  = XmlUtil.AttrValue(node, "width", 0);
            Height = XmlUtil.AttrValue(node, "height", 0);
            RX     = XmlUtil.AttrValue(node, "rx", 0);
            RY     = XmlUtil.AttrValue(node, "ry", 0);

            if (DefaultFill == null)
            {
                DefaultFill       = new Fill(svg);
                DefaultFill.Color = svg.PaintServers.Parse("black");
            }
        }
Exemple #9
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());
            }
            Points = list.ToArray();
        }
Exemple #10
0
        public ImageShape(SVG svg, XmlNode node) : base(svg, node)
        {
            X      = XmlUtil.AttrValue(node, "x", 0);
            Y      = XmlUtil.AttrValue(node, "y", 0);
            Width  = XmlUtil.AttrValue(node, "width", 0);
            Height = XmlUtil.AttrValue(node, "height", 0);
            string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty);

            if (hRef.Length > 0)
            {
                // 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);

                BitmapImage b = new  BitmapImage();
                b.BeginInit();
                b.UriSource = new Uri(filename, UriKind.RelativeOrAbsolute);
                b.EndInit();
                ImageSource = b;
            }
        }
Exemple #11
0
 public TextShape(SVG svg, XmlNode node, Shape parent) : base(svg, node, parent)
 {
     X    = XmlUtil.AttrValue(node, "x", 0);
     Y    = XmlUtil.AttrValue(node, "y", 0);
     Text = node.InnerText;
     GetTextStyle(svg);
     // check for tSpan tag
     if (node.InnerXml.IndexOf("<") >= 0)
     {
         TextSpan = ParseTSpan(svg, node.InnerXml);
     }
     if (DefaultFill == null)
     {
         DefaultFill       = new Fill(svg);
         DefaultFill.Color = svg.PaintServers.Parse("black");
     }
     if (DefaultStroke == null)
     {
         DefaultStroke       = new Stroke(svg);
         DefaultStroke.Width = 0.1;
     }
 }
Exemple #12
0
 public PaintServer Create(XmlNode node)
 {
     if (node.Name == SVGTags.sLinearGradient)
     {
         string id = XmlUtil.AttrValue(node, "id");
         if (m_servers.ContainsKey(id) == false)
         {
             m_servers[id] = new LinearGradientColor(this, node);
         }
         return(m_servers[id]);
     }
     if (node.Name == SVGTags.sRadialGradient)
     {
         string id = XmlUtil.AttrValue(node, "id");
         if (m_servers.ContainsKey(id) == false)
         {
             m_servers[id] = new RadialGradientColor(this, node);
         }
         return(m_servers[id]);
     }
     return(null);
 }
Exemple #13
0
        // http://apike.ca/prog_svg_paths.html
        public PathShape(SVG svg, XmlNode node) : base(svg, node)
        {
            if (DefaultFill == null)
            {
                DefaultFill       = new Fill(svg);
                DefaultFill.Color = svg.PaintServers.Parse("black");
            }

            ClosePath = false;
            string             path = XmlUtil.AttrValue(node, "d", string.Empty);
            CommandSplitter    cmd  = new CommandSplitter(path);
            string             commandstring;
            char               command;
            List <PathElement> elements = m_elements;

            while (true)
            {
                commandstring = cmd.ReadNext();
                if (commandstring.Length == 0)
                {
                    break;
                }
                ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
                if (command == 'm' || command == 'M')
                {
                    elements.Add(new MoveTo(command, split));
                    if (split.More)
                    {
                        elements.Add(new LineTo(command, split));
                    }
                    continue;
                }
                if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
                {
                    elements.Add(new LineTo(command, split));
                    continue;
                }
                if (command == 'c' || command == 'C')
                {
                    while (split.More)
                    {
                        elements.Add(new CurveTo(command, split));
                    }
                    continue;
                }
                if (command == 's' || command == 'S')
                {
                    while (split.More)
                    {
                        CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
                        System.Diagnostics.Debug.Assert(lastshape != null);
                        elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
                    }
                    continue;
                }
                if (command == 'a' || command == 'A')
                {
                    elements.Add(new EllipticalArcTo(command, split));
                    while (split.More)
                    {
                        elements.Add(new EllipticalArcTo(command, split));
                    }
                    continue;
                }
                if (command == 'z' || command == 'Z')
                {
                    ClosePath = true;
                    continue;
                }

                // extended format moveto or lineto can contain multiple points which should be translated into lineto
                PathElement lastitem = elements[elements.Count - 1];
                if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
                {
                    //Point p = Point.Parse(s);
                    //elements.Add(new LineTo(p));
                    continue;
                }


                System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring));
            }
        }
Exemple #14
0
 public CircleShape(SVG svg, XmlNode node) : base(svg, node)
 {
     CX = XmlUtil.AttrValue(node, "cx", 0);
     CY = XmlUtil.AttrValue(node, "cy", 0);
     R  = XmlUtil.AttrValue(node, "r", 0);
 }
Exemple #15
0
 protected virtual void Parse(SVG svg, string name, string value)
 {
     if (name == SVGTags.sTransform)
     {
         Transform = ShapeUtil.ParseTransform(value.ToLower());
         return;
     }
     if (name == SVGTags.sStroke)
     {
         GetStroke(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sStrokeWidth)
     {
         GetStroke(svg).Width = XmlUtil.ParseDouble(svg, value);
         return;
     }
     if (name == SVGTags.sStrokeOpacity)
     {
         GetStroke(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sStrokeDashArray)
     {
         if (value == "none")
         {
             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());
         }
         GetStroke(svg).StrokeArray = a.ToArray();
         return;
     }
     if (name == SVGTags.sStrokeLinecap)
     {
         GetStroke(svg).LineCap = (ClipArtViewer.Stroke.eLineCap)Enum.Parse(typeof(ClipArtViewer.Stroke.eLineCap), value);
         return;
     }
     if (name == SVGTags.sStrokeLinejoin)
     {
         GetStroke(svg).LineJoin = (ClipArtViewer.Stroke.eLineJoin)Enum.Parse(typeof(ClipArtViewer.Stroke.eLineJoin), value);
         return;
     }
     if (name == SVGTags.sFill)
     {
         GetFill(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sFillOpacity)
     {
         GetFill(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sFillRule)
     {
         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))
         {
             Parse(svg, item);
         }
     }
     //********************** text *******************
     if (name == SVGTags.sFontFamily)
     {
         GetTextStyle(svg).FontFamily = value;
         return;
     }
     if (name == SVGTags.sFontSize)
     {
         GetTextStyle(svg).FontSize = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == SVGTags.sFontWeight)
     {
         GetTextStyle(svg).Fontweight = (FontWeight) new FontWeightConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sFontStyle)
     {
         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);
         GetTextStyle(svg).TextDecoration = tt;
         return;
     }
     if (name == SVGTags.sTextAnchor)
     {
         if (value == "start")
         {
             GetTextStyle(svg).TextAlignment = TextAlignment.Left;
         }
         if (value == "middle")
         {
             GetTextStyle(svg).TextAlignment = TextAlignment.Center;
         }
         if (value == "end")
         {
             GetTextStyle(svg).TextAlignment = TextAlignment.Right;
         }
         return;
     }
     if (name == "word-spacing")
     {
         GetTextStyle(svg).WordSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "letter-spacing")
     {
         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));
         GetTextStyle(svg).BaseLineShift = value;
         return;
     }
 }
Exemple #16
0
        public GradientColor(PaintServerManager owner, XmlNode node) : base(owner)
        {
            GradientUnits = XmlUtil.AttrValue(node, "gradientUnits", string.Empty);
            string transform = XmlUtil.AttrValue(node, "gradientTransform", string.Empty);

            if (transform.Length > 0)
            {
                Transform = ShapeUtil.ParseTransform(transform.ToLower());
            }

            if (node.ChildNodes.Count == 0 && XmlUtil.AttrValue(node, "xlink:href", string.Empty).Length > 0)
            {
                string        refid  = XmlUtil.AttrValue(node, "xlink:href", string.Empty);
                GradientColor refcol = owner.Parse(refid.Substring(1)) as GradientColor;
                if (refcol == null)
                {
                    return;
                }
                m_stops = new List <GradientStop>(refcol.m_stops);
            }
            foreach (XmlNode childnode in node.ChildNodes)
            {
                if (childnode.Name == "stop")
                {
                    List <XmlAttribute> styleattr = new List <XmlAttribute>();
                    string fullstyle = XmlUtil.AttrValue(childnode, SVGTags.sStyle, string.Empty);
                    if (fullstyle.Length > 0)
                    {
                        foreach (ShapeUtil.Attribute styleitem in XmlUtil.SplitStyle(null, fullstyle))
                        {
                            styleattr.Add(new XmlUtil.StyleItem(childnode, styleitem.Name, styleitem.Value));
                        }
                    }
                    foreach (XmlAttribute attr1 in styleattr)
                    {
                        childnode.Attributes.Append(attr1);
                    }


                    double offset = XmlUtil.AttrValue(childnode, "offset", (double)0);
                    string s      = XmlUtil.AttrValue(childnode, "stop-color", "#0");

                    double stopopacity = XmlUtil.AttrValue(childnode, "stop-opacity", (double)1);

                    Color color;
                    if (s.StartsWith("#"))
                    {
                        color = PaintServerManager.ParseHexColor(s);
                    }
                    else
                    {
                        color = PaintServerManager.KnownColor(s);
                    }

                    if (stopopacity != 1)
                    {
                        color = Color.FromArgb((byte)(stopopacity * 255), color.R, color.G, color.B);
                    }

                    if (offset > 1)
                    {
                        offset = offset / 100;
                    }
                    m_stops.Add(new GradientStop(color, offset));
                }
            }
        }