Пример #1
0
        public object ReadYaml(IParser parser, Type type)
        {
            var color     = parser.Expect <Scalar>();
            var converter = new System.Drawing.ColorConverter();

            return((Color)converter.ConvertFromInvariantString(color.Value));
        }
Пример #2
0
			private void HandleEscSeq2(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\=(":
						{
							var newParent = new SubSuperScript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\p(":
						{
							double val;
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							string numberString;
							Altaxo.Serialization.LengthUnit lengthUnit;

							if (s1.EndsWith("%"))
							{
								numberString = s1.Substring(0, s1.Length - 1);
								if (double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val))
								{
									newContext.BaseFontId = context.BaseFontId.WithSize(context.BaseFontId.Size * val / 100);
									newContext.ScaleFont(val / 100);
								}
							}
							else if (Altaxo.Serialization.LengthUnit.TryParse(s1, out lengthUnit, out numberString) &&
								double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val * (double)(lengthUnit.UnitInMeter / Altaxo.Serialization.LengthUnit.Point.UnitInMeter);
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							else if (double.TryParse(s1, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val;
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\c(":
						{
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							var conv = new ColorConverter();

							try
							{
								object result = conv.ConvertFromInvariantString(s1);
								newContext.brush = new SolidBrush((Color)result);
							}
							catch (Exception)
							{
							}

							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\l(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotSymbol(context, plotNumber, plotLayer));
							}
						}
						break;

					case @"\%(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotName(context, plotNumber, plotLayer));
							}
							else if (int.TryParse(s1, out plotNumber))
							{
								var label = new PlotName(context, plotNumber);
								label.SetPropertyColumnName(s2);
								parent.Add(label);
							}
						}
						break;
				}
			}
Пример #3
0
 private void repositoryItemColorEdit1_Validating(object sender, CancelEventArgs e)
 {
     DevExpress.XtraEditors.TextEdit tx = (DevExpress.XtraEditors.TextEdit)sender;
     if (tx.Text.Length > 0)
     {
         ColorConverter cc = new ColorConverter();
         Color obj= (Color)cc.ConvertFromInvariantString(tx.Text);
         _obj.Color = ColorTranslator.ToOle(obj);
     }
 }
Пример #4
0
 public void ConvertFromInvariantString_NotNumber()
 {
     var conv = new ColorConverter();
     var ex = Assert.Throws<Exception>(() =>
     {
         conv.ConvertFromInvariantString("hello");
     });
     Assert.NotNull(ex.InnerException);
     Assert.IsType<FormatException>(ex.InnerException);
 }
Пример #5
0
    TryConvertFromInvariantString
    (
        String theString,
        ColorConverter colorConverter,
        out Color color
    )
    {
        Debug.Assert(colorConverter != null);
        Debug.Assert(theString != null);

        color = Color.Empty;

        // Remove spaces in named colors, so that "Light Blue" becomes
        // "LightBlue", for example.

        theString = theString.Replace(" ", String.Empty);

        if (theString.Length == 0)
        {
            // ColorConverter converts an empty string to Color.Black.  Bypass
            // ColorConverter.

            return (false);
        }

        try
        {
            color = (Color)colorConverter.ConvertFromInvariantString(
                theString);
        }
        catch (Exception)
        {
            // (Format errors raise a System.Exception with an inner exception
            // of type FormatException.  Go figure.)

            return (false);
        }

        return (true);
    }
Пример #6
0
 public void ConvertFromInvariantString_Name(string name)
 {
     var conv = new ColorConverter();
     var color = Color.FromName(name);
     Assert.Equal(color, (Color) conv.ConvertFromInvariantString(name));
 }
Пример #7
0
 public void ConvertFromInvariantString_Invalid()
 {
     var conv = new ColorConverter();
     Assert.Throws<ArgumentException>(() =>
     {
         conv.ConvertFromInvariantString("1, 2, 3, 4, 5");
     });
 }
Пример #8
0
 public void ConvertFromInvariantString(int a, int r, int g, int b)
 {
     var conv = new ColorConverter();
     var color = (Color) conv.ConvertFromInvariantString($"{a}, {r}, {g}, {b}");
     Assert.Equal(a, color.A);
     Assert.Equal(r, color.R);
     Assert.Equal(g, color.G);
     Assert.Equal(b, color.B);
 }
    ConvertFrom
    (
        ITypeDescriptorContext context,
        CultureInfo culture,
        Object value
    )
    {
        Debug.Assert(value != null);
        Debug.Assert(value is String);
        AssertValid();

        ColorColumnAutoFillUserSettings oColorColumnAutoFillUserSettings =
            new ColorColumnAutoFillUserSettings();

        ColorConverter oColorConverter = new ColorConverter();

        String [] asStrings = ( (String)value ).Split( new Char[] {'\t'} );

        Debug.Assert(asStrings.Length >= 7);

        oColorColumnAutoFillUserSettings.UseSourceNumber1 =
            Boolean.Parse( asStrings[0] );

        oColorColumnAutoFillUserSettings.UseSourceNumber2 =
            Boolean.Parse( asStrings[1] );

        oColorColumnAutoFillUserSettings.SourceNumber1 =
            MathUtil.ParseCultureInvariantDouble( asStrings[2] );

        oColorColumnAutoFillUserSettings.SourceNumber2 =
            MathUtil.ParseCultureInvariantDouble(asStrings[3]);

        oColorColumnAutoFillUserSettings.DestinationColor1 =
            (Color)oColorConverter.ConvertFromInvariantString( asStrings[4] );

        oColorColumnAutoFillUserSettings.DestinationColor2 =
            (Color)oColorConverter.ConvertFromInvariantString( asStrings[5] );

        oColorColumnAutoFillUserSettings.IgnoreOutliers =
            Boolean.Parse( asStrings[6] );

        // The UseLogs property wasn't added until NodeXL version 1.0.1.92.

        oColorColumnAutoFillUserSettings.UseLogs =
            (asStrings.Length > 7) ? Boolean.Parse( asStrings[7] ) : false;

        // The SourceColumnContainsNumbers property wasn't added until NodeXL
        // version 1.0.1.153.

        oColorColumnAutoFillUserSettings.SourceColumnContainsNumbers =
            (asStrings.Length > 8) ? Boolean.Parse( asStrings[8] ) : true;

        return (oColorColumnAutoFillUserSettings);
    }
    ConvertFromString
    (
        String [] asFields,
        Int32 iStartIndex
    )
    {
        Debug.Assert(asFields != null);
        Debug.Assert(iStartIndex >= 0);

        iStartIndex = base.ConvertFromString(asFields, iStartIndex);

        Debug.Assert(iStartIndex + 3 < asFields.Length);

        ColorConverter oColorConverter = new ColorConverter();

        m_bSourceColumnContainsNumbers =
            (Boolean)( new System.ComponentModel.BooleanConverter() ).
                ConvertFromInvariantString( asFields[iStartIndex + 0] );

        m_oDestinationColor1 =
            (Color)oColorConverter.ConvertFromInvariantString(
                asFields[iStartIndex + 1] );

        m_oDestinationColor2 =
            (Color)oColorConverter.ConvertFromInvariantString(
                asFields[iStartIndex + 2] );

        m_oCategoryNames = asFields[iStartIndex + 3].Split(
            PerWorkbookSettings.SubFieldSeparator);

        // Note:
        //
        // If another field is added here, the total expected field count in 
        // AutoFillWorkbookResults.ConvertFromString() must be increased.

        return (iStartIndex + 4);
    }
    ConvertFrom
    (
        ITypeDescriptorContext context,
        CultureInfo culture,
        Object value
    )
    {
        Debug.Assert(value != null);
        Debug.Assert(value is String);
        AssertValid();

        LabelUserSettings oLabelUserSettings = new LabelUserSettings();

        String [] asStrings = ( (String)value ).Split( new Char[] {'\t'} );

        Debug.Assert(asStrings.Length >= 5);

        ColorConverter oColorConverter = new ColorConverter();

        oLabelUserSettings.Font = (Font)
            ( new FontConverter() ).ConvertFromInvariantString(asStrings[0] );

        oLabelUserSettings.VertexLabelFillColor = (Color)
            oColorConverter.ConvertFromInvariantString(asStrings[1] );

        oLabelUserSettings.VertexLabelPosition = (VertexLabelPosition)
            Enum.Parse( typeof(VertexLabelPosition), asStrings[2] );

        oLabelUserSettings.VertexLabelMaximumLength =
            MathUtil.ParseCultureInvariantInt32( asStrings[3] );

        oLabelUserSettings.EdgeLabelMaximumLength =
            MathUtil.ParseCultureInvariantInt32(asStrings[4]);

        if (asStrings.Length > 5)
        {
            // Edge label text color wasn't added until version 1.0.1.154.

            oLabelUserSettings.EdgeLabelTextColor = (Color)
                oColorConverter.ConvertFromInvariantString(asStrings[5] );
        }

        if (asStrings.Length > 6)
        {
            // Vertex label wrapping wasn't added until version 1.0.1.175.

            oLabelUserSettings.VertexLabelWrapText =
                Boolean.Parse( asStrings[6] );

            oLabelUserSettings.VertexLabelWrapMaxTextWidth =
                MathUtil.ParseCultureInvariantDouble( asStrings[7] );
        }

        if (asStrings.Length > 8)
        {
            // Group label text color and alpha weren't added until version
            // 1.0.1.190.

            oLabelUserSettings.GroupLabelTextColor = (Color)
                oColorConverter.ConvertFromInvariantString( asStrings[8] );

            oLabelUserSettings.GroupLabelTextAlpha =
                MathUtil.ParseCultureInvariantSingle( asStrings[9] );
        }

        if (asStrings.Length > 10)
        {
            // Group label position wasn't added until version 1.0.1.215.

            oLabelUserSettings.GroupLabelPosition = (VertexLabelPosition)
                Enum.Parse( typeof(VertexLabelPosition), asStrings[10] );
        }

        return (oLabelUserSettings);
    }
Пример #12
0
        /// <summary>
        /// Generates an object from its XML representation.
        /// </summary>
        /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
        void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            ColorConverter conv = new ColorConverter();

            while (reader.Read())
            {
                // end element
                if (reader.NodeType == System.Xml.XmlNodeType.EndElement &&
                    reader.Name == "TimeSaverSettings")
                    break;

                if (reader.NodeType == System.Xml.XmlNodeType.Element &&
                    !reader.IsEmptyElement)
                {
                    string text = reader.ReadString();
                    switch (reader.Name)
                    {
                        case "TextColor":
                            TextColor = (Color)conv.ConvertFromInvariantString(text);
                            break;

                        case "BackColor":
                            BackColor = (Color)conv.ConvertFromInvariantString(text);
                            break;

                        case "DisplayMode":
                            if (Enum.IsDefined(typeof(DisplayMode), text))
                                DisplayMode = (DisplayMode)Enum.Parse(typeof(DisplayMode), text, true);
                            break;

                        case "BlinkTimeSeparator":
                            bool blink;
                            if (bool.TryParse(text, out blink))
                                BlinkTimeSeparator = blink;
                            break;

                        case "UseUpperCase":
                            bool upperCase;
                            if (bool.TryParse(text, out upperCase))
                                UseUpperCase = upperCase;
                            break;
                    }
                }
            }
        }