protected bool DoConvertBorderColor(StyleBase onStyle, object value, out PDFColor result)
        {
            double?opacity;

            if (null == value)
            {
                result = PDFColor.Transparent;
                return(false);
            }
            else if (value is PDFColor color)
            {
                result = color;
                return(true);
            }
            else if (ParseCSSColor(value.ToString(), out result, out opacity))
            {
                if (opacity.HasValue)
                {
                    onStyle.SetValue(StyleKeys.BorderOpacityKey, opacity.Value);
                }
                return(true);
            }
            else
            {
                result = PDFColor.Transparent;
                return(false);
            }
        }
Exemplo n.º 2
0
        protected bool DoConvertBorderColor(StyleBase onStyle, object value, out PDFColor result)
        {
            double?opacity;

            if (null == value)
            {
                result = PDFColor.Transparent;
                return(false);
            }
            else if (value is PDFColor color)
            {
                result = color;
                return(true);
            }
            else if (ParseCSSColor(value.ToString(), out result, out opacity))
            {
                //TODO:Support individual opacity on borders
                return(true);
            }
            else
            {
                result = PDFColor.Transparent;
                return(false);
            }
        }
Exemplo n.º 3
0
        public void ColorSpace_Test()
        {
            ColorSpace cs     = ColorSpace.RGB;
            PDFColor   target = new PDFColor(cs, 1.0, 1.0, 1.0);
            ColorSpace actual;

            actual = target.ColorSpace;
            Assert.AreEqual(actual, cs);
        }
Exemplo n.º 4
0
        public void op_Implicit_Test()
        {
            Color    rgbcolor = Color.FromArgb(255, 255, 255);
            PDFColor expected = new PDFColor(1, 1, 1);
            PDFColor actual;

            actual = rgbcolor;
            Assert.AreEqual(expected, actual);
        }
        protected override object DoGetNativeValue(string key, string qsValue, IPDFComponent comp)
        {
            PDFColor val;

            if (string.IsNullOrEmpty(qsValue) || !PDFColor.TryParse(qsValue, out val))
            {
                val = this.Value;
            }
            return(val);
        }
        public void FillStyle_Test()
        {
            PDFColor      color    = PDFColors.Aqua;
            PDFSolidBrush target   = new PDFSolidBrush(color);
            FillType      expected = FillType.Solid;
            FillType      actual;

            actual = target.FillStyle;
            Assert.AreEqual(expected, actual);
        }
        public void PDFSolidPenConstructor_Test()
        {
            PDFColor    color  = PDFColors.Aqua; // TODO: Initialize to an appropriate value
            PDFUnit     width  = 1;
            PDFSolidPen target = new PDFSolidPen(color, width);

            Assert.IsNotNull(target);
            Assert.AreEqual(color, target.Color);
            Assert.AreEqual(width, target.Width);
        }
        public void PDFSolidBrushConstructor_Test3()
        {
            PDFColor      color  = PDFColors.Aqua;
            PDFSolidBrush target = new PDFSolidBrush(color);

            Assert.IsNotNull(target);
            Assert.AreEqual(color, target.Color);
            Assert.AreEqual((PDFReal)1, target.Opacity);
            Assert.AreEqual(FillType.Solid, target.FillStyle);
        }
        public void PDFSolidBrushConstructor_Test()
        {
            PDFColor      color   = PDFColors.Aqua;
            double        opacity = 1F;
            PDFSolidBrush target  = new PDFSolidBrush(color, opacity);

            Assert.IsNotNull(target);
            Assert.AreEqual(color, target.Color);
            Assert.AreEqual(opacity, target.Opacity.Value);
        }
        public void Color_Test()
        {
            PDFSolidPen target   = new PDFSolidPen(); // TODO: Initialize to an appropriate value
            PDFColor    expected = PDFColors.Aqua;
            PDFColor    actual;

            target.Color = expected;
            actual       = target.Color;
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 11
0
        public void ToString_Test()
        {
            ColorSpace cs       = ColorSpace.RGB;
            Color      c        = Color.FromArgb(255, 255, 255);
            PDFColor   target   = new PDFColor(cs, c);
            string     expected = "rgb(255,255,255)";
            string     actual;

            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 12
0
        public void PDFColorConstructor_Test4()
        {
            double   gray   = 0.5;
            PDFColor target = new PDFColor(gray);

            Assert.AreEqual(ColorSpace.G, target.ColorSpace);
            double expected = Math.Round(gray, 1);
            double actual   = Math.Round(target.Gray.Value, 1);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 13
0
        public void Color_Test()
        {
            ColorSpace cs     = ColorSpace.RGB;
            PDFColor   target = new PDFColor(cs, 1.0, 1.0, 1.0);
            Color      actual;

            actual = target.Color;
            Assert.AreEqual(actual.R, 255);
            Assert.AreEqual(actual.G, 255);
            Assert.AreEqual(actual.B, 255);
        }
 protected override void DoSetNativeValue(object value, IPDFComponent owner)
 {
     if (null == value)
     {
         this.Value = PDFColor.Transparent;
     }
     else
     {
         this.Value = (PDFColor)value;
     }
 }
Exemplo n.º 15
0
        public void IsEmpty_Test()
        {
            ColorSpace cs     = ColorSpace.RGB;
            Color      c      = new Color();//Empty System.Drawing.Color
            PDFColor   target = new PDFColor(cs, c);

            Assert.IsTrue(target.IsEmpty);

            c      = Color.FromArgb(255, 0, 0);
            target = new PDFColor(cs, c);
            Assert.IsFalse(target.IsEmpty);
        }
Exemplo n.º 16
0
        public void PDFColorConstructor_Test2()
        {
            double   red    = 1.0;
            double   green  = 0.0;
            double   blue   = 0.0;
            PDFColor target = new PDFColor(red, green, blue);

            Assert.AreEqual(ColorSpace.RGB, target.ColorSpace);
            Assert.AreEqual(red, Math.Round(target.Red.Value, 2));
            Assert.AreEqual(green, Math.Round(target.Green.Value, 2));
            Assert.AreEqual(blue, Math.Round(target.Blue.Value, 2));
        }
Exemplo n.º 17
0
        internal static PDColor GetColor(PDFColor color)
        {
            PDColor pDColor;

            try
            {
                switch (color)
                {
                case PDFColor.Black:
                {
                    pDColor = new PDColor(new float[3], PDDeviceRGB.INSTANCE);
                    return(pDColor);
                }

                case PDFColor.White:
                {
                    pDColor = new PDColor(new float[] { 1f, 1f, 1f }, PDDeviceRGB.INSTANCE);
                    return(pDColor);
                }

                case PDFColor.Red:
                {
                    pDColor = new PDColor(new float[] { 1f, default(float), default(float) }, PDDeviceRGB.INSTANCE);
                    return(pDColor);
                }

                case PDFColor.Blue:
                {
                    pDColor = new PDColor(new float[] { default(float), default(float), 1f }, PDDeviceRGB.INSTANCE);
                    return(pDColor);
                }

                case PDFColor.Green:
                {
                    pDColor = new PDColor(new float[] { default(float), 1f, default(float) }, PDDeviceRGB.INSTANCE);
                    return(pDColor);
                }

                case PDFColor.Yellow:
                {
                    pDColor = new PDColor(new float[] { 1f, 1f, default(float) }, PDDeviceRGB.INSTANCE);
                    return(pDColor);
                }
                }
                pDColor = new PDColor(new float[3], PDDeviceRGB.INSTANCE);
            }
            catch (Exception exception)
            {
                pDColor = new PDColor(new float[3], PDDeviceRGB.INSTANCE);
            }
            return(pDColor);
        }
        public void Create_Test()
        {
            PDFColor      color    = PDFColors.Aqua;
            PDFSolidBrush expected = new PDFSolidBrush(color);
            PDFSolidBrush actual;

            actual = PDFSolidBrush.Create(color);

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Color, actual.Color);
            Assert.AreEqual(expected.Opacity, actual.Opacity);
            Assert.AreEqual(expected.FillStyle, actual.FillStyle);
        }
        public void Opacity_Test()
        {
            PDFColor      color   = PDFColors.Aqua;
            PDFReal       opacity = 1F;
            PDFSolidBrush target  = new PDFSolidBrush(color, opacity);

            Assert.AreEqual(opacity, target.Opacity);

            PDFReal expected = 0.4F;

            target.Opacity = expected;
            Assert.AreEqual(expected, target.Opacity);
        }
Exemplo n.º 20
0
        public void PDFColorConstructor_Test3()
        {
            ColorSpace cs     = ColorSpace.RGB;
            double     one    = 0.2;
            double     two    = 1.0;
            double     three  = 0.5;
            PDFColor   target = new PDFColor(cs, one, two, three);

            Assert.AreEqual(cs, target.ColorSpace);
            Assert.AreEqual(one, Math.Round(target.Red.Value, 1));
            Assert.AreEqual(two, Math.Round(target.Green.Value, 1));
            Assert.AreEqual(three, Math.Round(target.Blue.Value, 1));
        }
Exemplo n.º 21
0
        public void Red_Test()
        {
            ColorSpace cs     = ColorSpace.RGB;
            PDFColor   target = new PDFColor(cs, 1.0, 1.0, 1.0);
            PDFReal    actual;

            actual = target.Red;
            Assert.AreEqual(Math.Round(actual.Value, 2), 1.0);

            target = new PDFColor(cs, 0.5, 1.0, 0);
            actual = target.Red;
            Assert.AreEqual(Math.Round(actual.Value, 1), 0.5);
        }
Exemplo n.º 22
0
        public void Parse_Test()
        {
            string   color    = "#FF00FF";
            PDFColor expected = new PDFColor(1.0, 0.0, 1.0);
            PDFColor actual;

            actual = PDFColor.Parse(color);
            Assert.AreEqual(expected, actual);

            color  = "rgb(255,0,255)";
            actual = PDFColor.Parse(color);
            Assert.AreEqual(expected, actual);
        }
        public void Color_Test()
        {
            PDFColor      color    = PDFColors.Aqua;
            PDFSolidBrush target   = new PDFSolidBrush(color);
            PDFColor      expected = color;
            PDFColor      actual   = target.Color;

            Assert.AreEqual(expected, actual);

            expected     = PDFColors.White;
            target.Color = expected;
            actual       = target.Color;
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 24
0
        public void Gray_Test()
        {
            ColorSpace cs     = ColorSpace.RGB;
            PDFColor   target = new PDFColor(cs, 1.0, 1.0, 1.0);
            PDFReal    actual;

            actual = target.Gray;
            Assert.AreEqual(Math.Round(actual.Value, 1), 1.0);

            cs     = ColorSpace.G;
            target = new PDFColor(0.5);
            actual = target.Gray;
            Assert.AreEqual(Math.Round(actual.Value, 1), 0.5);
        }
        private static PDFColor[] GetPDFPalette(ColorSpace cspace, Color[] colors)
        {
            if (null == colors)
            {
                throw new ArgumentNullException("colors");
            }
            PDFColor[] all = new PDFColor[colors.Length];

            for (int i = 0; i < colors.Length; i++)
            {
                all[i] = new PDFColor(cspace, colors[i]);
            }

            return(all);
        }
Exemplo n.º 26
0
        private RgbColor ConvertPDFColor(PDFColor color)
        {
            switch (color)
            {
            case PDFColor.Beige:    return(RgbColor.Beige);

            case PDFColor.Black:    return(RgbColor.Black);

            case PDFColor.Blue:     return(RgbColor.Blue);

            case PDFColor.Brown:    return(RgbColor.Brown);

            case PDFColor.DarkBlue: return(RgbColor.DarkBlue);

            case PDFColor.DarkGray: return(RgbColor.DarkGray);

            case PDFColor.DarkGreen: return(RgbColor.DarkGreen);

            case PDFColor.DarkRed:  return(RgbColor.DarkRed);

            case PDFColor.Gold:     return(RgbColor.Gold);

            case PDFColor.Gray:     return(RgbColor.Gray);

            case PDFColor.Green:    return(RgbColor.Green);

            case PDFColor.Navy:     return(RgbColor.Navy);

            case PDFColor.Olive:    return(RgbColor.Olive);

            case PDFColor.Pink:    return(RgbColor.Pink);

            case PDFColor.Purple:   return(RgbColor.Purple);

            case PDFColor.Red:      return(RgbColor.Red);

            case PDFColor.Teal:     return(RgbColor.Teal);

            case PDFColor.White:    return(RgbColor.White);

            case PDFColor.Yellow:   return(RgbColor.Yellow);

            default:                return(RgbColor.Black);
            }
        }
Exemplo n.º 27
0
        public void Create_Test()
        {
            PDFColor    color    = PDFColors.Aqua;
            PDFUnit     width    = 1;
            PDFSolidPen expected = new PDFSolidPen();

            expected.Color = color;
            expected.Width = width;

            PDFPen actual;

            actual = PDFPen.Create(color, width);
            Assert.IsInstanceOfType(actual, typeof(PDFSolidPen));
            PDFSolidPen solid = (PDFSolidPen)actual;

            Assert.AreEqual(expected.Width, solid.Width);
            Assert.AreEqual(expected.Color, solid.Color);
        }
        protected override void DoSetNativeValueFromString(string value, IPDFComponent owner)
        {
            PDFColor val;

            if (string.IsNullOrEmpty(value))
            {
                this.Value = PDFColor.Transparent;
            }

            else if (PDFColor.TryParse(value, out val))
            {
                this.Value = val;
            }
            else
            {
                throw new InvalidCastException("Could not parse the value '" + value + "' to a PDFColor");
            }
        }
Exemplo n.º 29
0
        public void Outline_ColorTest()
        {
            OutlineStyle target   = new OutlineStyle();
            PDFColor     expected = PDFColors.Transparent;

            Assert.AreEqual(expected, target.Color);

            expected     = PDFColors.Olive;
            target.Color = expected;
            Assert.AreEqual(expected, target.Color);

            expected     = PDFColors.Gray;
            target.Color = expected;
            Assert.AreEqual(expected, target.Color);

            target.RemoveColor();
            expected = PDFColors.Transparent;
            Assert.AreEqual(expected, target.Color);
        }
Exemplo n.º 30
0
        public void PDFLinearBrushConstructor_Test()
        {
            PDFGradientLinearDescriptor descriptor = new PDFGradientLinearDescriptor();

            descriptor.Colors = new List <PDFGradientColor>(new PDFGradientColor[]
            {
                new PDFGradientColor(PDFColors.Red, null, null)
            });

            PDFGradientLinearBrush target = new PDFGradientLinearBrush(descriptor);
            PDFColor color    = PDFColors.Red;
            double?  opacity  = null;
            double?  distance = null;

            Assert.IsNotNull(target);
            Assert.AreEqual(GradientType.Linear, target.GradientType);
            Assert.AreEqual(color, target.Colors[0].Color);
            Assert.AreEqual(opacity, target.Colors[0].Opacity);
            Assert.AreEqual(distance, target.Colors[0].Distance);
        }