Example #1
0
        public static string GetColorName(Color col)
        {
            PropertyInfo colorProperty = typeof(Colors).GetProperties()
                                         .FirstOrDefault(p => Color.AreClose((Color)p.GetValue(null), col));

            return(colorProperty != null ? colorProperty.Name : "Black");
        }
Example #2
0
        private void colorsListPopup_Opened(object sender, EventArgs e)
        {
            if (_knownColorsListBox != null)
            {
                _knownColorsListBox.SelectedIndex = -1;
            }

            if (_standardColorsListBox != null && ShowStandardColors)
            {
                _standardColorsListBox.SelectedIndex = -1;

                foreach (ColorItem item in _standardColorsListBox.Items)
                {
                    if (Color.AreClose(item.Color, SelectedColor))
                    {
                        _standardColorsListBox.SelectedItem = item;
                        return;
                    }
                }
            }

            if (_knownColorsListBox != null)
            {
                foreach (ColorItem item in _knownColorsListBox.Items)
                {
                    if (Color.AreClose(item.Color, SelectedColor))
                    {
                        _knownColorsListBox.SelectedItem = item;
                        return;
                    }
                }
            }
        }
Example #3
0
 public bool IsEqualToColor(Color value)
 {
     if (this.GetIsSourceScRGB())
     {
         return(Color.AreClose(this.Color, value));
     }
     if ((int)this.Color.A == (int)value.A && (int)this.Color.R == (int)value.R && (int)this.Color.G == (int)value.G)
     {
         return((int)this.Color.B == (int)value.B);
     }
     return(false);
 }
Example #4
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Получение кисти через цвет
            /// </summary>
            /// <param name="color">Цвет</param>
            /// <returns>Найденную кисть или новую кисть на основе цвета</returns>
            //---------------------------------------------------------------------------------------------------------
            public static SolidColorBrush GetBrushByColor(Color color)
            {
                for (Int32 i = 0; i < mKnownBrushes.Count; i++)
                {
                    if (Color.AreClose(mKnownBrushes[i].Value.Color, color))
                    {
                        return(mKnownBrushes[i].Value);
                    }
                }

                return(new SolidColorBrush(color));
            }
Example #5
0
 private void CloseColourCheck(object sender, PropertyChangedEventArgs e)
 {
     switch (e.PropertyName)
     {
     case "OverrideForegroundColour":
     case "OverrideBackgroundColour":
     case "BackgroundColourIndex":
     case "ForegroundColourIndex":
         ColoursClose = !OverrideBackgroundColour || !OverrideForegroundColour
                                ? false
                                : Color.AreClose(ForegroundColour, BackgroundColour);
         break;
     }
 }
Example #6
0
        /// <summary>
        /// Returns a value indicating whether the specified color is a predefined and when true sets the name of the color.
        /// </summary>
        /// <param name="color">A <see cref="System.Windows.Media.Color"/> value to inspecting.</param>
        /// <param name="name">The name of the predefined color.</param>
        /// <returns>true if <paramref name="color"/> is predefined color; otherwise, false.</returns>
        public static bool IsKnownColor(Color color, out string name)
        {
            foreach (ColorItem item in KnownColorItems)
            {
                if (Color.AreClose(item.Color, color))
                {
                    name = item.Name;
                    return(true);
                }
            }

            name = null;
            return(false);
        }
Example #7
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Получение имени сплошной кисти или пустой строки
            /// </summary>
            /// <param name="brush">Сплошная кисть</param>
            /// <returns>Имя кисти</returns>
            //---------------------------------------------------------------------------------------------------------
            public static String GetKnownBrushName(SolidColorBrush brush)
            {
                String result = String.Empty;

                for (Int32 i = 0; i < mKnownColors.Count; i++)
                {
                    if (Color.AreClose(mKnownBrushes[i].Value.Color, brush.Color))
                    {
                        return(mKnownColors[i].Key);
                    }
                }

                return(result);
            }
Example #8
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Получение имени цвета или пустой строки
            /// </summary>
            /// <param name="color">Цвет</param>
            /// <returns>Имя цвета</returns>
            //---------------------------------------------------------------------------------------------------------
            public static String GetKnownColorName(Color color)
            {
                String result = String.Empty;

                for (Int32 i = 0; i < mKnownColors.Count; i++)
                {
                    if (Color.AreClose(mKnownColors[i].Value, color))
                    {
                        return(mKnownColors[i].Key);
                    }
                }

                return(result);
            }
 /// <summary>
 /// Given a Color, return the corresponding NamedColor
 /// (or transparent is no match).
 /// </summary>
 /// <param name="color">The color to match up with our list of named colors</param>
 /// <returns>The appropriate NamedColor, or transparent if it's not one of the color-names</returns>
 public static NamedColor From(Color color)
 {
     foreach (NamedColor namedColor in AllWindowsMediaColors)
     {
         if (Color.AreClose(color, namedColor.Color))
         {
             return(namedColor);
         }
     }
     foreach (NamedColor namedColor in AllSystemColors)
     {
         if (Color.AreClose(color, namedColor.Color))
         {
             return(namedColor);
         }
     }
     return(NamedColor.Empty);
 }
        private ColorItem ContainsColor(Color newColor)
        {
            foreach (Object o in colorList.Items)
            {
                ColorItem item = o as ColorItem;

                if (item == null)
                {
                    continue;
                }
                if (Color.AreClose(item.Color, newColor))
                {
                    return(item);
                }
            }

            return(null);
        }
        public int GetFormatId(double fontSize, FontType fontType, FontStyle fontStyle, FontWeight fontWeight, SolidColorBrush textBrush, bool useUnderline)
        {
            double     num = Math.Round(fontSize, 1);
            TextFormat tf  = formattingList.Where(x =>
            {
                return(x.FontSize == Math.Round(fontSize, 1) &&
                       x.FontType == fontType &&
                       x.FontStyle == fontStyle &&
                       x.UseUnderline == useUnderline &&
                       Color.AreClose(x.TextBrush.Color, textBrush.Color) &&
                       x.FontWeight == fontWeight);
            }).FirstOrDefault();

            if (tf == null)
            {
                tf = new TextFormat(fontSize, fontType, fontStyle, fontWeight, textBrush, useUnderline);
                AddToList(tf);
            }
            return(tf.Index);
        }
        public int GetFormatIdForNewUnderline(int oldId, bool newUnderline)
        {
            TextFormat oldFormat = formattingList[oldId];

            TextFormat tf = formattingList.Where(x =>
            {
                return(x.FontSize == oldFormat.FontSize &&
                       x.FontType == oldFormat.FontType &&
                       x.FontStyle == oldFormat.FontStyle &&
                       x.UseUnderline == newUnderline &&
                       Color.AreClose(x.TextBrush.Color, oldFormat.TextBrush.Color) &&
                       x.FontWeight == oldFormat.FontWeight);
            }).FirstOrDefault();

            if (tf == null)
            {
                tf = new TextFormat(oldFormat.FontSize, oldFormat.FontType, oldFormat.FontStyle, oldFormat.FontWeight, oldFormat.TextBrush, newUnderline);
                AddToList(tf);
            }
            return(tf.Index);
        }
Example #13
0
        private void RepaintRibbon()
        {
            foreach (Border border in Children)
            {
                var color = TargetColor;
                switch (Spectr)
                {
                case Spectr.Red:
                    color.R = Convert.ToByte(border.Tag);
                    break;

                case Spectr.Green:
                    color.G = Convert.ToByte(border.Tag);
                    break;

                case Spectr.Blue:
                    color.B = Convert.ToByte(border.Tag);
                    break;
                }
                if (IsHighlight)
                {
                    if (Color.AreClose(color, TargetColor))
                    {
                        border.Background = Brushes.BlueViolet;
                    }
                    else
                    {
                        border.Background = Brushes.DarkGray;
                    }
                }
                else
                {
                    border.Background = new SolidColorBrush(color);
                }
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var color = value as Color?;

            if (color != null)
            {
                PropertyInfo colorProperty = typeof(Colors).GetProperties().FirstOrDefault(p => Color.AreClose((Color)p.GetValue(null), color.Value));
                return(colorProperty != null ? colorProperty.Name : string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.Value.A, color.Value.R, color.Value.G, color.Value.B));
            }
            return(string.Empty);
        }
        public void ProcessPastedXML(XElement rootXE)
        {
            //XElement thisElement = rootXE.Element(GetType().Name);
            XElement[]             formatElements = rootXE.Element(GetType().Name).Elements("Formats").Elements().ToArray();
            IEnumerable <XElement> formats        = rootXE.Descendants(typeof(TextEquation).Name).Descendants("Formats");
            Dictionary <int, int>  allFormatIds   = new Dictionary <int, int>();

            foreach (XElement xe in formats)
            {
                if (xe.Value.Length > 0)
                {
                    string[] formatStrings = xe.Value.Split(',');
                    foreach (string s in formatStrings)
                    {
                        int id = int.Parse(s);
                        if (!allFormatIds.Keys.Contains(id))
                        {
                            allFormatIds.Add(id, id);
                        }
                    }
                }
            }
            for (int i = 0; i < allFormatIds.Count; i++)
            {
                int        key   = allFormatIds.ElementAt(i).Key;
                TextFormat tf    = TextFormat.DeSerialize(formatElements[key]);
                TextFormat match = formattingList.Where(x =>
                {
                    return(x.FontSize == Math.Round(tf.FontSize, 1) &&
                           x.FontType == tf.FontType &&
                           x.FontStyle == tf.FontStyle &&
                           x.UseUnderline == tf.UseUnderline &&
                           Color.AreClose(x.TextBrush.Color, tf.TextBrush.Color) &&
                           x.FontWeight == tf.FontWeight);
                }).FirstOrDefault();

                int newValue = 0;
                if (match == null)
                {
                    AddToList(tf);
                    newValue = tf.Index;
                }
                else
                {
                    newValue = match.Index;
                }
                allFormatIds[key] = newValue;
            }
            IEnumerable <XElement> textElements = rootXE.Descendants(typeof(TextEquation).Name);

            foreach (XElement xe in textElements)
            {
                XElement formatsElement = xe.Elements("Formats").FirstOrDefault();
                if (formatsElement != null)
                {
                    StringBuilder strBuilder    = new StringBuilder();
                    string[]      formatStrings = formatsElement.Value.Split(',');
                    foreach (string s in formatStrings)
                    {
                        if (s.Length > 0)
                        {
                            int id = int.Parse(s);
                            strBuilder.Append(allFormatIds[id] + ",");
                        }
                    }
                    if (strBuilder.Length > 0)
                    {
                        strBuilder.Remove(strBuilder.Length - 1, 1);
                    }
                    formatsElement.Value = strBuilder.ToString();
                }
            }
        }
 static string GetColorName(Color col)
 {
     System.Reflection.PropertyInfo colorProperty = typeof(Colors).GetProperties()
                                                    .FirstOrDefault(p => Color.AreClose((Color)p.GetValue(null), col));
     return(colorProperty != null ? colorProperty.Name : "unnamed color");
 }