Esempio n. 1
0
        /// <summary>
        /// Obsolete. Returns Pen representation of given pen string
        /// </summary>
        /// <remarks>This method is only for compatibility reasons.</remarks>
        /// <param name="str">A <see cref="String"/> representing the pen in Ogama 1.0 versions.</param>
        /// <returns>The converted <see cref="Pen"/>.</returns>
        public static Pen StringToPenOld(string str)
        {
            string[] parts    = str.Trim().Split(new string[] { "####" }, StringSplitOptions.RemoveEmptyEntries);
            Pen      newValue = new Pen(
                ObjectStringConverter.HtmlAlphaToColor(parts[0]),
                float.Parse(parts[1], System.Globalization.NumberStyles.Number));

            newValue.DashStyle = (DashStyle)Enum.Parse(typeof(DashStyle), parts[2]);
            return(newValue);
        }
Esempio n. 2
0
        /// <summary>
        /// Overridden <see cref="TypeConverter.ConvertFrom(ITypeDescriptorContext,CultureInfo,object)"/>
        /// Converts the given value to the type of this converter.</summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that
        /// provides a format context.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <returns>An <strong>Object</strong> that represents the converted value.</returns>
        public override object ConvertFrom(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value)
        {
            if (value is string)
            {
                return(ObjectStringConverter.StringToBrush((string)value));
            }

            return(base.ConvertFrom(context, culture, value));
        }
Esempio n. 3
0
        /// <summary>
        /// Overridden <see cref="TypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,object,Type)"/>
        /// Converts the given value object to the specified type,
        /// using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that
        /// provides a format context.</param>
        /// <param name="culture">A <see cref="CultureInfo"/>. If a null reference
        /// is passed, the current culture is assumed.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <param name="destinationType">The <see cref="Type"/> to convert the
        /// <strong>value</strong> parameter to.</param>
        /// <returns>An <strong>Object</strong> that represents the converted value.</returns>
        public override object ConvertTo(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value,
            Type destinationType)
        {
            if (destinationType == typeof(string) && value is Brush)
            {
                return(ObjectStringConverter.BrushToString((Brush)value));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Esempio n. 4
0
        /// <summary>
        /// Returns Pen representation of given pen string .
        /// </summary>
        /// <param name="str">A <see cref="String"/> with Color, Width, DashStyle and arrows.</param>
        /// <returns>The converted <see cref="Pen"/></returns>
        public static Pen StringToPen(string str)
        {
            Pen newValue = Pens.Black;

            try
            {
                string[] parts = str.Trim().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                newValue = new Pen(
                    ObjectStringConverter.HtmlAlphaToColor(parts[0].Remove(0, 7)),
                    float.Parse(parts[1].Replace(" px", string.Empty), System.Globalization.NumberStyles.Number));

                newValue.DashStyle = (DashStyle)Enum.Parse(typeof(DashStyle), parts[2]);
                if (parts.Length > 3)
                {
                    string[] parts3   = parts[3].Trim().Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                    string[] parts4   = parts[4].Trim().Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                    LineCap  startCap = (LineCap)Enum.Parse(typeof(LineCap), parts3[1]);
                    LineCap  endCap   = (LineCap)Enum.Parse(typeof(LineCap), parts4[1]);
                    newValue.StartCap = startCap;
                    newValue.EndCap   = endCap;
                    if (startCap == LineCap.Custom)
                    {
                        string[]           parts5         = parts[5].Trim().Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        AdjustableArrowCap customStartCap = new AdjustableArrowCap(float.Parse(parts5[1]), float.Parse(parts5[2]));
                        newValue.CustomStartCap = customStartCap;
                    }

                    if (endCap == LineCap.Custom)
                    {
                        string[]           parts6       = parts[6].Trim().Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        AdjustableArrowCap customEndCap = new AdjustableArrowCap(float.Parse(parts6[1]), float.Parse(parts6[2]));
                        newValue.CustomEndCap = customEndCap;
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("String could not be converted to pen. Standard black pen will be used.");
            }

            return(newValue);
        }
Esempio n. 5
0
        /// <summary>
        /// Returns unique string representation of a Pen structure.
        /// </summary>
        /// <param name="newPen">The <see cref="Pen"/> to convert.</param>
        /// <returns>A <see cref="String"/> with Color, Width, DashStyle and arrows.</returns>
        public static string PenToString(Pen newPen)
        {
            StringBuilder output = new StringBuilder();

            output.Append("Color: ");
            output.Append(ObjectStringConverter.ColorToHtmlAlpha(newPen.Color));
            output.Append(";");
            output.Append(newPen.Width.ToString());
            output.Append(" px");
            output.Append(";");
            output.Append(newPen.DashStyle.ToString());
            output.Append(";");
            output.Append("StartCap :");
            output.Append(newPen.StartCap.ToString());
            output.Append(";");
            output.Append("EndCap :");
            output.Append(newPen.EndCap.ToString());
            output.Append(";");

            output.Append("CustomStartCap AdjustableArrow:");
            if (newPen.StartCap == LineCap.Custom)
            {
                output.Append(((AdjustableArrowCap)newPen.CustomStartCap).Width.ToString());
                output.Append(":");
                output.Append(((AdjustableArrowCap)newPen.CustomStartCap).Height.ToString());
            }

            output.Append(";");
            output.Append("CustomEndCap AdjustableArrow:");
            if (newPen.EndCap == LineCap.Custom)
            {
                output.Append(((AdjustableArrowCap)newPen.CustomEndCap).Width.ToString());
                output.Append(":");
                output.Append(((AdjustableArrowCap)newPen.CustomEndCap).Height.ToString());
            }

            return(output.ToString());
        }