コード例 #1
0
        public void ToARGBHexStringTest()
        {
            var colorHalf       = ColorRGB.FromHex("#7FFF0000");
            var colorEightyFive = ColorRGB.FromHex("#80FF0000");

            Assert.AreEqual(colorHalf.ToAlphaHex(), "#7FFF0000");
            Assert.AreEqual(colorEightyFive.ToAlphaHex(), "#80FF0000");
        }
コード例 #2
0
        public void ParseARGBHexStringTest()
        {
            var colorHalf       = ColorRGB.FromHex("#80FF0000");
            var colorEightyFive = ColorRGB.FromHex("#D9FF0000");

            Assert.AreEqual(colorHalf.A, .5d);
            Assert.AreEqual(colorEightyFive.A, .85d);
        }
コード例 #3
0
        public void FromHexTest()
        {
            var colorRed    = new ColorRGB(1d, 0d, 0d);
            var colorRedHex = ColorRGB.FromHex("#FF0000");

            Assert.AreEqual(colorRed.R, colorRedHex.R);
            Assert.AreEqual(colorRed.G, colorRedHex.G);
            Assert.AreEqual(colorRed.B, colorRedHex.B);
        }
コード例 #4
0
        public void BasicHexToRGBConversion()
        {
            var hex1 = "#886A11";
            var hex2 = "#55B0A5";
            var hex3 = "#6653B2";

            var color1 = ColorRGB.FromHex(hex1);
            var color2 = ColorRGB.FromHex(hex2);
            var color3 = ColorRGB.FromHex(hex3);

            Assert.AreEqual(color1.ToHex(), hex1);
            Assert.AreEqual(color2.ToHex(), hex2);
            Assert.AreEqual(color3.ToHex(), hex3);
        }
コード例 #5
0
        public void RGBtoHSBConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var hsb          = (ColorHSB)ColorHSB.FromColor(rgb);
            var rgbConverted = (ColorRGB)hsb.ToRgb();

            // HSL
            Assert.AreEqual(hsb.Hue, 252);
            Assert.AreEqual(hsb.Saturation, 53.37);
            Assert.AreEqual(hsb.Brightness, 69.8);

            // RGB Converted
            Assert.AreEqual(rgbConverted.Red, 102);
            Assert.AreEqual(rgbConverted.Green, 83);
            Assert.AreEqual(rgbConverted.Blue, 178);
        }
コード例 #6
0
        public void RGBtoHSLConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var hsl          = (ColorHSL)ColorHSL.FromColor(rgb);
            var rgbConverter = (ColorRGB)hsl.ToRgb();

            // HSL
            Assert.AreEqual(hsl.Hue, 252);
            Assert.AreEqual(hsl.Saturation, 38.15);
            Assert.AreEqual(hsl.Luminance, 51.18);

            // RGB Converted
            Assert.AreEqual(rgbConverter.Red, 102);
            Assert.AreEqual(rgbConverter.Green, 83);
            Assert.AreEqual(rgbConverter.Blue, 178);
        }
コード例 #7
0
        public void BasicHexToRGBIntConversion()
        {
            var hex1 = "#886A11";
            var hex2 = "#55B0A5";
            var hex3 = "#6653B2";

            var color1 = ColorRGB.FromHex(hex1);
            var color2 = ColorRGB.FromHex(hex2);
            var color3 = ColorRGB.FromHex(hex3);

            Assert.AreEqual(color1.ToValueRGB(), 8940049);
            Assert.AreEqual(color1.ToValueARGB(), 4287130129);

            Assert.AreEqual(color2.ToValueRGB(), 5615781);
            Assert.AreEqual(color2.ToValueARGB(), 4283805861);

            Assert.AreEqual(color3.ToValueRGB(), 6706098);
            Assert.AreEqual(color3.ToValueARGB(), 4284896178);
        }
コード例 #8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            testColor = ColorRGB.FromHex("#745EC4");

            var builder = new StringBuilder();

            builder.AppendLine("MAIN COLOR: " + testColor.ToHex());
            builder.AppendLine();

            var colors = new TestColor [] {
                TestColorRGB(),
                TestColorLAB(),
                TestColorHSB(),
                TestColorHSL(),
                TestColorXYZ()
            };

            var matching    = new StringBuilder();
            var mismatching = new StringBuilder();

            for (int i = 0; i < colors.Length; i++)
            {
                var output = colors [i].Name + " " + colors [i].Value + " " + colors [i].NativeValue;
                if (colors [i].Value == testColor.ToHex())
                {
                    matching.AppendLine(output);
                }
                else
                {
                    mismatching.AppendLine(output);
                }
            }

            // Display Matching
            matching.AppendLine();
            matching.AppendLine("MISMATCHED:");
            matching.AppendLine(mismatching.ToString());

            textDisplay.Text = matching.ToString();
        }
コード例 #9
0
        public void RGBtoLABConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var lab          = (ColorLAB)ColorLAB.FromColor(rgb);
            var rgbConverted = (ColorRGB)lab.ToRgb();

            // LAB
            var l = Math.Truncate(100 * lab.L) / 100;
            var a = Math.Truncate(100 * lab.A) / 100;
            var b = Math.Truncate(100 * lab.B) / 100;

            Assert.AreEqual(l, 41.57);
            Assert.AreEqual(a, 31.37);
            Assert.AreEqual(b, -52.39);             // Differs from Colorize.org which shows -48.16

            // RGB Converted
            Assert.AreEqual(rgbConverted.Red, 102);
            Assert.AreEqual(rgbConverted.Green, 83);
            Assert.AreEqual(rgbConverted.Blue, 178);
        }
コード例 #10
0
        public void RGBtoXYZConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var xyz          = (ColorXYZ)ColorXYZ.FromColor(rgb);
            var rgbConverted = (ColorRGB)xyz.ToRgb();

            // LAB
            var x = Math.Round(xyz.X, 2);
            var y = Math.Round(xyz.Y, 2);
            var z = Math.Round(xyz.Z, 2);

            Assert.AreEqual(x, 16.61);
            Assert.AreEqual(y, 12.23);
            Assert.AreEqual(z, 43.6);

            // RGB Converted
            Assert.AreEqual(rgbConverted.Red, 102);
            Assert.AreEqual(rgbConverted.Green, 83);
            Assert.AreEqual(rgbConverted.Blue, 178);
        }
コード例 #11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var hsbPrimary   = ColorSwatches.FlatMagenta;
            var primaryColor = ColorRGB.FromHex("#F04C3B");

            swatches = new List <UIView>()
            {
                //CreateSwatchView (primaryColor, ColorSchemeType.Monochromatic, "Monochromatic", useFlatColors),
                CreateSwatchView(primaryColor, ColorSchemeType.Complementary, "Complementary"),
                CreateSwatchView(primaryColor, ColorSchemeType.Triadic, "Triadic"),
                CreateSwatchView(primaryColor, ColorSchemeType.Square, "Square"),
                CreateSwatchView(primaryColor, ColorSchemeType.Analogous, "Analogous"),
                CreateSwatchView(primaryColor, ColorSchemeType.SplitComplementary, "Split Complementary"),
                CreateSwatchView(primaryColor, ColorSchemeType.Rectangle, "Rectangle")
            };

            var curFrame = new CGRect();
            var offset   = 70f;

            for (int i = 0; i < swatches.Count; i++)
            {
                var currentView = swatches[i];

                if (i > 0)
                {
                    offset = 0;
                }

                curFrame = new CGRect(
                    View.Frame.Width / 2 - currentView.Frame.Width / 2,
                    curFrame.Bottom + padding + offset,
                    currentView.Frame.Width,
                    currentView.Frame.Height
                    );

                currentView.Frame = curFrame;
                Add(currentView);
            }
        }
コード例 #12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var padding = 40;

            swatchSize = (float)(View.Frame.Width - padding * 2) / 3f;

            var rowRect      = new CGRect(40, swatchSize, swatchSize, swatchSize);
            var primaryColor = ColorRGB.FromHex("#F04C3B");

            // Row
            var primary = new ColorSwatchView(rowRect, primaryColor, "Primary\n" + primaryColor.ToHex());

            Add(primary);

            rowRect.Offset(swatchSize, 0);
            var colorLightened = primaryColor.Lightened();
            var lighter        = new ColorSwatchView(rowRect, colorLightened, "Lighter\n" + colorLightened.ToHex());

            Add(lighter);

            rowRect.Offset(swatchSize, 0);
            var colorDarkened = primaryColor.Darkened();
            var darker        = new ColorSwatchView(rowRect, colorDarkened, "Darker\n" + colorDarkened.ToHex());

            Add(darker);

            // Row 2
            rowRect.Offset(-swatchSize * 2, swatchSize);
            var colorSaturated = primaryColor.Saturated();
            var saturated      = new ColorSwatchView(rowRect, colorSaturated, "Saturated\n" + colorSaturated.ToHex());

            Add(saturated);

            rowRect.Offset(swatchSize, 0);
            var colorDesaturated = primaryColor.Desaturated();
            var desaturated      = new ColorSwatchView(rowRect, colorDesaturated, "Desaturated\n" + colorDesaturated.ToHex());

            Add(desaturated);

            rowRect.Offset(swatchSize, 0);
            var colorGray  = primaryColor.GrayScale();
            var grayscaled = new ColorSwatchView(rowRect, colorGray, "Grayscale\n" + colorGray.ToHex());

            Add(grayscaled);

            // Row 32
            rowRect.Offset(-swatchSize * 2, swatchSize);
            var colorAdjusted = primaryColor.AdjustHue(45);
            var adjusted      = new ColorSwatchView(rowRect, colorAdjusted, "Adjusted\n" + colorAdjusted.ToHex());

            Add(adjusted);

            rowRect.Offset(swatchSize, 0);
            var colorCompliment = primaryColor.Complementary();
            var compliment      = new ColorSwatchView(rowRect, colorCompliment, "Compliment\n" + colorCompliment.ToHex());

            Add(compliment);

            rowRect.Offset(swatchSize, 0);
            var colorInverted = primaryColor.Inverted();
            var invert        = new ColorSwatchView(rowRect, colorInverted, "Invert\n" + colorInverted.ToHex());

            Add(invert);

            // Row3
            rowRect.Offset(-swatchSize * 2, swatchSize);
            var colorMixBlue = primaryColor.Mix(ConvertColor(UIColor.Blue));
            var mixBlue      = new ColorSwatchView(rowRect, colorMixBlue, "Mix Blue\n" + colorMixBlue.ToHex());

            Add(mixBlue);

            rowRect.Offset(swatchSize, 0);
            var colorMixGreen = primaryColor.Mix(ConvertColor(UIColor.Green));
            var mixGreen      = new ColorSwatchView(rowRect, colorMixGreen, "Mix Green\n" + colorMixGreen.ToHex());

            Add(mixGreen);

            rowRect.Offset(swatchSize, 0);
            var colorMixYellow = primaryColor.Mix(ConvertColor(UIColor.Yellow));
            var mixYellow      = new ColorSwatchView(rowRect, colorMixYellow, "Mix Yellow\n" + colorMixYellow.ToHex());

            Add(mixYellow);

            // Row 5 3
            rowRect.Offset(-swatchSize * 2, swatchSize);
            var colorTinted = primaryColor.Tinted();
            var tint        = new ColorSwatchView(rowRect, colorTinted, "Tint\n" + colorTinted.ToHex());

            Add(tint);

            rowRect.Offset(swatchSize, 0);
            var colorShaded = primaryColor.Shaded();
            var shade       = new ColorSwatchView(rowRect, colorShaded, "Shade\n" + colorShaded.ToHex());

            Add(shade);
        }
コード例 #13
0
        /// <summary>
        /// Parses the CSS rule.
        /// </summary>
        /// <param name="curStyle">Current style.</param>
        /// <param name="rule">Rule.</param>
        internal static void ParseCSSRule(ref TextStyleParameters curStyle, CssParserRule rule, Dictionary <string, string> cssVariables)
        {
            foreach (var declaration in rule.Declarations)
            {
                if (_textStyleProperties.ContainsKey(declaration.Property))
                {
                    // Assign the variable if it exists
                    if (cssVariables != null && declaration.ReferencesVariable)
                    {
                        declaration.Value = cssVariables[declaration.Value];
                    }

                    var cleanedValue = declaration.Value.Replace("\"", "");
                    cleanedValue = cleanedValue.Trim();

                    var prop = _textStyleProperties[declaration.Property];
                    switch (prop.PropertyType.Name)
                    {
                    case "String":
                        curStyle.SetValue(prop.Name, cleanedValue);
                        break;

                    case "Int32":
                        int numInt;
                        if (int.TryParse(cleanedValue, out numInt))
                        {
                            curStyle.SetValue(prop.Name, numInt);
                        }
                        break;

                    case "Single":
                        cleanedValue = cleanedValue.Replace("px", "");
                        float numFloat;
                        if (float.TryParse(cleanedValue, out numFloat))
                        {
                            curStyle.SetValue(prop.Name, numFloat);
                        }
                        else
                        {
                            throw new Exception("Failed to Parse Single value " + cleanedValue);
                        }
                        break;

                    case "Single[]":
                        var parts        = cleanedValue.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                        var parsedValues = new float[parts.Length];
                        for (int i = 0; i < parts.Length; i++)
                        {
                            float numArrayFloat;
                            if (float.TryParse(parts[i], out numArrayFloat))
                            {
                                parsedValues[i] = numArrayFloat;
                            }
                        }
                        curStyle.SetValue(prop.Name, parsedValues);
                        break;

                    case "ColorRGB":
                        curStyle.SetValue(prop.Name, ColorRGB.FromHex(cleanedValue));
                        break;

                    case "CssAlign":
                        curStyle.TextAlign = EnumUtils.FromDescription <CssAlign>(cleanedValue);
                        break;

                    case "CssDecoration":
                        curStyle.TextDecoration = EnumUtils.FromDescription <CssDecoration>(cleanedValue);
                        break;

                    case "CssTextTransform":
                        curStyle.TextTransform = EnumUtils.FromDescription <CssTextTransform>(cleanedValue);
                        break;

                    case "CssTextOverflow":
                        curStyle.TextOverflow = EnumUtils.FromDescription <CssTextOverflow>(cleanedValue);
                        break;

                    case "CssFontStyle":
                        curStyle.FontStyle = EnumUtils.FromDescription <CssFontStyle>(cleanedValue);
                        break;

                    case "CssFontWeight":
                        curStyle.FontWeight = EnumUtils.FromDescription <CssFontWeight>(cleanedValue);
                        break;

                    default:
                        throw new InvalidCastException("Could not find the appropriate type " + prop.PropertyType.Name);
                    }
                }
            }
        }
コード例 #14
0
        public void ToRGBColorValueTest()
        {
            var colorRed = ColorRGB.FromHex("#FF0000");

            Assert.AreEqual(colorRed.ValueRGB, 16711680);
        }