private static StiBrush Brush(string text)
            {
                var values = text.Split(':');

                switch (values[0])
                {
                    #region StiEmptyBrush
                case "empty":
                    return(new StiEmptyBrush());

                    #endregion

                    #region StiGlassBrush
                case "glass":
                {
                    var glass = new StiGlassBrush();

                    if (!string.IsNullOrEmpty(values[1]))
                    {
                        glass.Color = Color(values[1]);
                    }

                    if (!string.IsNullOrEmpty(values[2]))
                    {
                        glass.DrawHatch = true;
                    }

                    if (!string.IsNullOrEmpty(values[3]))
                    {
                        glass.Blend = float.Parse(values[3]);
                    }

                    return(glass);
                }
                    #endregion

                    #region StiGlareBrush
                case "glare":
                {
                    var glare = new StiGlareBrush();

                    if (!string.IsNullOrEmpty(values[1]))
                    {
                        glare.StartColor = Color(values[1]);
                    }

                    if (!string.IsNullOrEmpty(values[2]))
                    {
                        glare.EndColor = Color(values[2]);
                    }

                    if (!string.IsNullOrEmpty(values[3]))
                    {
                        glare.Angle = double.Parse(values[3]);
                    }

                    if (!string.IsNullOrEmpty(values[4]))
                    {
                        glare.Focus = float.Parse(values[4]);
                    }

                    if (!string.IsNullOrEmpty(values[5]))
                    {
                        glare.Scale = float.Parse(values[5]);
                    }

                    return(glare);
                }
                    #endregion

                    #region StiHatchBrush
                case "hatch":
                {
                    var hatch = new StiHatchBrush();

                    if (!string.IsNullOrEmpty(values[1]))
                    {
                        hatch.BackColor = Color(values[1]);
                    }

                    if (!string.IsNullOrEmpty(values[2]))
                    {
                        hatch.ForeColor = Color(values[2]);
                    }

                    if (!string.IsNullOrEmpty(values[3]))
                    {
                        hatch.Style = (HatchStyle)Enum.Parse(typeof(HatchStyle), values[3]);
                    }

                    return(hatch);
                }
                    #endregion

                    #region StiGradientBrush
                case "gradient":
                {
                    var gradient = new StiGradientBrush();

                    if (!string.IsNullOrEmpty(values[1]))
                    {
                        gradient.StartColor = Color(values[1]);
                    }

                    if (!string.IsNullOrEmpty(values[2]))
                    {
                        gradient.EndColor = Color(values[2]);
                    }

                    if (!string.IsNullOrEmpty(values[3]))
                    {
                        gradient.Angle = double.Parse(values[3]);
                    }

                    return(gradient);
                }
                    #endregion

                    #region StiSolidBrush
                case "solid":
                {
                    var solid = new StiSolidBrush();

                    if (!string.IsNullOrEmpty(values[1]))
                    {
                        solid.Color = Color(values[1]);
                    }

                    return(solid);
                }
                    #endregion
                }

                return(null);
            }
예제 #2
0
        private StiBrush GetBrush(XmlNode node, StiComponent comp, string key)
        {
            try
            {
                XmlAttribute attr = node.Attributes[key];
                if (attr != null)
                {
                    switch (attr.Value)
                    {
                    case "LinearGradient":
                        StiGradientBrush gradientBrush = new StiGradientBrush();
                        gradientBrush.StartColor = ReadColor(node, key + ".StartColor");
                        gradientBrush.EndColor   = ReadColor(node, key + ".EndColor");
                        gradientBrush.Angle      = (float)ReadDouble(node, key + ".Angle", comp, 0d);
                        return(gradientBrush);

                    case "PathGradient":
                        StiGlareBrush glareBrush = new StiGlareBrush();
                        glareBrush.StartColor = ReadColor(node, key + ".CenterColor");
                        glareBrush.EndColor   = ReadColor(node, key + ".EdgeColor");
                        return(glareBrush);

                    case "Hatch":
                        StiHatchBrush hatchBrush = new StiHatchBrush();
                        hatchBrush.ForeColor = ReadColor(node, key + ".ForeColor");
                        hatchBrush.BackColor = ReadColor(node, key + ".BackColor");
                        string str = ReadString(node, key + ".Style", "BackwardDiagonal");
                        hatchBrush.Style = (HatchStyle)Enum.Parse(typeof(HatchStyle), str, false);
                        return(hatchBrush);

                    case "Glass":
                        StiGlassBrush glassBrush = new StiGlassBrush();
                        glassBrush.Color     = ReadColor(node, key + ".Color");
                        glassBrush.Blend     = (float)ReadDouble(node, key + ".Blend", comp, 0.2d);
                        glassBrush.DrawHatch = ReadBool(node, key + ".Hatch", comp, false);
                        return(glassBrush);
                    }
                }
                else
                {
                    XmlAttribute attr2 = node.Attributes[key + ".Color"];
                    if (attr2 != null)
                    {
                        StiSolidBrush solidBrush = new StiSolidBrush();
                        solidBrush.Color = ReadColor(node, key + ".Color");
                        return(solidBrush);
                    }
                }
            }
            catch
            {
            }
            if (key == "Fill")
            {
                return(new StiEmptyBrush());
            }
            else
            {
                return(new StiSolidBrush(Color.Black));
            }
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
                                         object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                if (value == null)
                {
                    return("null");
                }
                else if (value is StiEmptyBrush)
                {
                    return(StiLocalization.Get("Report", "StiEmptyBrush"));
                }
                else if (value is StiSolidBrush)
                {
                    return(StiLocalization.Get("Report", "StiSolidBrush"));
                }
                else if (value is StiGradientBrush)
                {
                    return(StiLocalization.Get("Report", "StiGradientBrush"));
                }
                else if (value is StiHatchBrush)
                {
                    return(StiLocalization.Get("Report", "StiHatchBrush"));
                }
                else if (value is StiGlareBrush)
                {
                    return(StiLocalization.Get("Report", "StiGlareBrush"));
                }
                else if (value is StiGlassBrush)
                {
                    return(StiLocalization.Get("Report", "StiGlassBrush"));
                }
            }
            if (destinationType == typeof(InstanceDescriptor) && value != null)
            {
                Type[]          types;
                ConstructorInfo info;
                object[]        objs;

                #region StiSolidBrush
                if (value is StiEmptyBrush)
                {
                    types = new Type[0];

                    info = typeof(StiEmptyBrush).GetConstructor(types);
                    if (info != null)
                    {
                        objs = new object[0];

                        return(CreateNewInstanceDescriptor(info, objs));
                    }
                }
                #endregion

                #region StiGradientBrush
                else if (value is StiGradientBrush)
                {
                    StiGradientBrush brush = (StiGradientBrush)value;

                    types = new Type[] {
                        typeof(Color),
                        typeof(Color),
                        typeof(double)
                    };

                    info = typeof(StiGradientBrush).GetConstructor(types);
                    if (info != null)
                    {
                        objs = new object[]     { brush.StartColor,
                                                  brush.EndColor,
                                                  brush.Angle };

                        return(CreateNewInstanceDescriptor(info, objs));
                    }
                }
                #endregion

                #region StiHatchBrush
                else if (value is StiHatchBrush)
                {
                    StiHatchBrush brush = (StiHatchBrush)value;

                    types = new Type[] { typeof(HatchStyle),
                                         typeof(Color),
                                         typeof(Color) };

                    info = typeof(StiHatchBrush).GetConstructor(types);
                    if (info != null)
                    {
                        objs = new object[]     { brush.Style,
                                                  brush.ForeColor,
                                                  brush.BackColor };

                        return(CreateNewInstanceDescriptor(info, objs));
                    }
                }
                #endregion

                #region StiSolidBrush
                else if (value is StiSolidBrush)
                {
                    StiSolidBrush brush = (StiSolidBrush)value;

                    types = new Type[] { typeof(Color) };

                    info = typeof(StiSolidBrush).GetConstructor(types);
                    if (info != null)
                    {
                        objs = new object[] { brush.Color };

                        return(CreateNewInstanceDescriptor(info, objs));
                    }
                }
                #endregion

                #region StiGlareBrush
                else if (value is StiGlareBrush)
                {
                    StiGlareBrush brush = (StiGlareBrush)value;

                    types = new Type[] {
                        typeof(Color),
                        typeof(Color),
                        typeof(double),
                        typeof(float),
                        typeof(float)
                    };

                    info = typeof(StiGlareBrush).GetConstructor(types);
                    if (info != null)
                    {
                        objs = new object[]     { brush.StartColor,
                                                  brush.EndColor,
                                                  brush.Angle,
                                                  brush.Focus,
                                                  brush.Scale };

                        return(CreateNewInstanceDescriptor(info, objs));
                    }
                }
                #endregion

                #region StiGlassBrush
                else if (value is StiGlassBrush)
                {
                    StiGlassBrush brush = (StiGlassBrush)value;

                    types = new Type[] {
                        typeof(Color),
                        typeof(bool),
                        typeof(float)
                    };

                    info = typeof(StiGlassBrush).GetConstructor(types);
                    if (info != null)
                    {
                        objs = new object[]     { brush.Color,
                                                  brush.DrawHatch,
                                                  brush.Blend };

                        return(CreateNewInstanceDescriptor(info, objs));
                    }
                }
                #endregion
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }