Exemple #1
0
        /// <summary>
        /// Creates a new style, but does not do a deep copy on the members in the style.  Thus if any of these are
        /// not strings, they meay be left referred to by more than one style or element.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            SvgStyle r = new SvgStyle();

            r += this;
            return(r);
        }
Exemple #2
0
        public static SvgStyle operator +(SvgStyle lhs, SvgStyle rhs)
        {
            SvgStyle svgStyle = new SvgStyle();

            foreach (string attname in lhs._styles.Keys)
            {
                object obj = lhs[attname];
                if (typeof(ICloneable).IsInstanceOfType(obj))
                {
                    svgStyle[attname] = ((ICloneable)obj).Clone();
                }
                else
                {
                    svgStyle[attname] = obj;
                }
            }
            foreach (string attname in rhs._styles.Keys)
            {
                object obj = rhs[attname];
                if (typeof(ICloneable).IsInstanceOfType(obj))
                {
                    svgStyle[attname] = ((ICloneable)obj).Clone();
                }
                else
                {
                    svgStyle[attname] = obj;
                }
            }
            return(svgStyle);
        }
Exemple #3
0
        /// <summary>
        /// Adds two SvgStyles together, resulting in a new object that contains all the attributes of both styles.
        /// Attributes are copied deeply, i.e. cloned if they are <c>ICloneable</c>.
        /// </summary>
        public static SvgStyle operator +(SvgStyle lhs, SvgStyle rhs)
        {
            SvgStyle res = new SvgStyle();

            foreach (string key in lhs._styles.Keys)
            {
                object o = lhs[key];
                if (typeof(ICloneable).IsInstanceOfType(o))
                {
                    res[key] = ((ICloneable)o).Clone();
                }
                else
                {
                    res[key] = o;
                }
            }

            foreach (string key in rhs._styles.Keys)
            {
                object o = rhs[key];
                if (typeof(ICloneable).IsInstanceOfType(o))
                {
                    res[key] = ((ICloneable)o).Clone();
                }
                else
                {
                    res[key] = o;
                }
            }

            return(res);
        }
		internal static SvgEllipseElement CreateCenteredCircle(double radius, SvgStyle style)
		{
			SvgEllipseElement circleElement = new SvgEllipseElement(
				0, 0,
				(float)radius, (float)radius);

			circleElement.Style = style;
			return circleElement;
		}
Exemple #5
0
        public static SvgEllipseElement CreateCircle(Point center, double radius, SvgStyle style)
        {
            SvgEllipseElement circleElement = new SvgEllipseElement(
                center.X, center.Y,
                radius, radius);

            if (style != null)
            {
                circleElement.Style = style;
            }
            return circleElement;
        }
Exemple #6
0
 /// <summary>
 /// Given a document and a current node, read this element from the node.
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="el"></param>
 public override void ReadXmlElement(XmlDocument doc, XmlElement el)
 {
     foreach (XmlAttribute att in el.Attributes)
     {
         if (att.Name == "style")
         {
             Style = new SvgStyle(att.Value);
         }
         else if (att.Name == "transform")
         {
             Transform = new SvgTransformList(att.Value);
         }
         else
         {
             this[att.Name] = att.Value;
         }
     }
 }
Exemple #7
0
 /// <summary>
 /// Creates a new style, but does not do a deep copy on the members in the style.  Thus if any of these are
 /// not strings, they meay be left referred to by more than one style or element.
 /// </summary>
 /// <returns></returns>
 public object Clone()
 {
     SvgStyle r = new SvgStyle();
     r += this;
     return r;
 }
Exemple #8
0
        /// <summary>
        /// Adds two SvgStyles together, resulting in a new object that contains all the attributes of both styles.
        /// Attributes are copied deeply, i.e. cloned if they are <c>ICloneable</c>.
        /// </summary>
        public static SvgStyle operator +(SvgStyle lhs, SvgStyle rhs)
        {
            SvgStyle res = new SvgStyle();

            foreach(string key in lhs._styles.Keys)
            {
                object o = lhs[key];
                if (typeof(ICloneable).IsInstanceOfType(o))
                    res[key] = ((ICloneable)o).Clone();
                else
                    res[key] = o;
            }

            foreach(string key in rhs._styles.Keys)
            {
                object o = rhs[key];
                if (typeof(ICloneable).IsInstanceOfType(o))
                    res[key] = ((ICloneable)o).Clone();
                else
                    res[key] = o;
            }

            return res;
        }
Exemple #9
0
        /// <summary>
        /// When a GDI instruction with a brush parameter is called, there can be a lot we have to do to emulate the brush.  The aim is to return a 
        /// style that represents the brush.
        /// <para>
        /// Solid brush is very easy.
        /// </para>
        /// <para>
        /// Linear grad brush:  we ignore the blend curve and the transformation (and therefore the rotation parameter if any)
        /// Hatch brush: 
        /// </para>
        /// <para>
        /// Other types of brushes are too hard to emulate and are rendered pink.
        /// </para>
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>
        private SvgStyle HandleBrush(Brush br)
        {
            if (br.GetType() == typeof(SolidBrush))
            {
                return new SvgStyle((SolidBrush)br);
            }

            if (br.GetType() == typeof(LinearGradientBrush))
            {
                LinearGradientBrush grbr = (LinearGradientBrush)br;
                RectangleF rc = grbr.Rectangle;

                SvgLinearGradient grad = new SvgLinearGradient(rc.Left, rc.Top, rc.Right, rc.Bottom);

                switch(grbr.WrapMode)
                {
                        //I have not been able to test Clamp because using a clamped gradient appears to crash the process
                        //under XP (?!?!)
                    case WrapMode.Clamp:
                        grad.SpreadMethod = "pad"; grad.GradientUnits = "objectBoundingBox"; break;
                    case WrapMode.Tile:
                        grad.SpreadMethod = "repeat"; grad.GradientUnits = "userSpaceOnUse"; break;
                    default:
                        grad.SpreadMethod = "reflect"; grad.GradientUnits = "userSpaceOnUse"; break;
                }

                ColorBlend cb = null;

                //GDI dll tends to crash when you try and access some members of gradient brushes that haven't been specified.
                try
                {
                    cb = grbr.InterpolationColors;
                }
                catch(Exception){}

                if(cb != null)
                {
                    for(int i = 0; i < grbr.InterpolationColors.Colors.Length; ++i)
                    {
                        grad.AddChild(new SvgStopElement(grbr.InterpolationColors.Positions[i], grbr.InterpolationColors.Colors[i]));
                    }
                }
                else
                {
                    grad.AddChild(new SvgStopElement("0%", grbr.LinearColors[0]));
                    grad.AddChild(new SvgStopElement("100%", grbr.LinearColors[1]));
                }

                grad.Id += "_LinearGradientBrush";

                _defs.AddChild(grad);

                SvgStyle s = new SvgStyle();
                s.Set("fill", new SvgUriReference(grad));
                return s;
            }

            if (br.GetType() == typeof(HatchBrush))
            {
                HatchBrush habr = (HatchBrush)br;

                SvgPatternElement patty = new SvgPatternElement(0,0,8,8, new SvgNumList("4 4 12 12"));
                patty.Style.Set("shape-rendering", "crispEdges");
                patty.Style.Set("stroke-linecap", "butt");

                SvgRectElement rc = new SvgRectElement(0,0,8,8);
                rc.Style.Set("fill", new SvgColor(habr.BackgroundColor));
                patty.AddChild(rc);

                AddHatchBrushDetails(patty, new SvgColor(habr.ForegroundColor), habr.HatchStyle);

                patty.Id += "_HatchBrush";
                patty.PatternUnits = "userSpaceOnUse";
                patty.PatternContentUnits = "userSpaceOnUse";
                _defs.AddChild(patty);

                SvgStyle s = new SvgStyle();
                s.Set("fill", new SvgUriReference(patty));
                return s;
            }

            //most types of brush we can't emulate, but luckily they are quite unusual
            return new SvgStyle(new SolidBrush(Color.Salmon));
        }
Exemple #10
0
        public object Clone()
        {
            SvgStyle lhs = new SvgStyle();

            return(lhs + this);
        }