Exemplo n.º 1
0
        public void Fill_PatternRepeatTest()
        {
            Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
            Assert.AreEqual(target.PatternRepeat, PatternRepeat.RepeatBoth); //RepeatBoth is the current default.

            target.PatternRepeat = PatternRepeat.RepeatX;
            Assert.AreEqual(target.PatternRepeat, PatternRepeat.RepeatX);

            target.PatternRepeat = PatternRepeat.None;
            Assert.AreEqual(target.PatternRepeat, PatternRepeat.None);

            target.RemovePatternRepeat();
            Assert.AreEqual(target.PatternRepeat, PatternRepeat.RepeatBoth);
        }
Exemplo n.º 2
0
        public void Fill_FillStyleTest()
        {
            Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
            Assert.AreEqual(target.Style, Scryber.Drawing.FillType.None);

            target.Style = Scryber.Drawing.FillType.Solid;
            Assert.AreEqual(target.Style, Scryber.Drawing.FillType.Solid);

            target.Style = Scryber.Drawing.FillType.Image;
            Assert.AreEqual(target.Style, Scryber.Drawing.FillType.Image);

            target.RemoveFillStyle();
            Assert.AreEqual(target.Style, Scryber.Drawing.FillType.None);
        }
Exemplo n.º 3
0
        public void Fill_ColorTest()
        {
            Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
            Assert.AreEqual(target.Color, PDFStyleConst.DefaultFillColor);

            target.Color = PDFColors.Red;
            Assert.AreEqual(target.Color, PDFColors.Red);

            target.Color = PDFColors.Blue;
            Assert.AreEqual(target.Color, PDFColors.Blue);

            target.RemoveColor();
            Assert.AreEqual(target.Color, PDFStyleConst.DefaultFillColor);
        }
Exemplo n.º 4
0
        public void AddTest()
        {
            Style style = new Style();
            StyleItemCollection target = new StyleItemCollection(style);

            StyleItemBase item = new BorderStyle();

            target.Add(item);

            Assert.AreEqual(1, target.Count);

            item = new Scryber.Styles.FillStyle();
            target.Add(item);
            Assert.AreEqual(2, target.Count);
        }
Exemplo n.º 5
0
        public void ContainsTest()
        {
            Style style = new Style();
            StyleItemCollection         target = new StyleItemCollection(style);
            IEnumerable <StyleItemBase> all    = GetStdCollection();

            target.AddRange(all);
            Assert.AreEqual(StdCollectionCount, target.Count);


            StyleItemBase item     = new Scryber.Styles.FillStyle();
            bool          expected = false;
            bool          actual   = target.Contains(item);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void Fill_PatternYStepTest()
        {
            Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
            Assert.AreEqual(target.PatternYStep, PDFUnit.Zero);

            PDFUnit expected = (PDFUnit)10;

            target.PatternYStep = expected;
            Assert.AreEqual(target.PatternYStep, expected);

            expected            = -20;
            target.PatternYStep = expected;
            Assert.AreEqual(target.PatternYStep, expected);

            target.RemovePatternYStep();
            Assert.AreEqual(target.PatternYStep, PDFUnit.Zero);
        }
Exemplo n.º 7
0
        public void Fill_OpacityTest()
        {
            Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
            Assert.AreEqual(target.Opacity, (PDFReal)1.0);

            double opacity = 0.4;

            target.Opacity = opacity;
            Assert.AreEqual(target.Opacity, opacity);

            opacity        = 0.8;
            target.Opacity = opacity;
            Assert.AreEqual(target.Opacity, opacity);

            target.RemoveOpacity();
            Assert.AreEqual(target.Opacity, (PDFReal)1.0);
        }
Exemplo n.º 8
0
        public void Fill_ImageSourceTest()
        {
            Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
            Assert.IsTrue(string.IsNullOrEmpty(target.ImageSource));

            string path = "../images/image.png";

            target.ImageSource = path;
            Assert.AreEqual(target.ImageSource, path);

            path = "../images/image2.png";
            target.ImageSource = path;
            Assert.AreEqual(target.ImageSource, path);

            target.RemoveImageSource();
            Assert.IsTrue(string.IsNullOrEmpty(target.ImageSource));
        }
Exemplo n.º 9
0
        public void Fill_CreateBrushTest()
        {
            Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
            target.Style = Scryber.Drawing.FillType.Solid;
            target.Color = PDFColors.Red;
            PDFBrush expected = new PDFSolidBrush(PDFColors.Red);
            PDFBrush actual;

            actual = target.CreateBrush();
            Assert.AreEqual(expected.GetType(), actual.GetType());
            Assert.AreEqual(expected.FillStyle, actual.FillStyle);

            PDFSolidBrush solidexpected = (PDFSolidBrush)expected;
            PDFSolidBrush solidactual   = (PDFSolidBrush)actual;

            Assert.AreEqual(solidexpected.Color, solidactual.Color);
            Assert.AreEqual(solidexpected.Opacity, solidactual.Opacity);

            target                  = new Scryber.Styles.FillStyle();
            target.Style            = Scryber.Drawing.FillType.Image;
            target.ImageSource      = "../images/animage.png";
            target.PatternRepeat    = PatternRepeat.RepeatBoth;
            target.PatternXPosition = 10;
            target.PatternXSize     = 100;
            target.PatternXStep     = 90;
            target.PatternYPosition = 20;
            target.PatternYSize     = 200;
            target.PatternYStep     = 180;


            expected = new PDFImageBrush("../images/animage.png");
            actual   = target.CreateBrush();
            Assert.AreEqual(expected.GetType(), actual.GetType());
            Assert.AreEqual(expected.FillStyle, actual.FillStyle);

            PDFImageBrush imgexpected = (PDFImageBrush)expected;
            PDFImageBrush imgactual   = (PDFImageBrush)actual;

            Assert.AreEqual(imgexpected.ImageSource, imgactual.ImageSource);
            Assert.AreEqual(imgexpected.Opacity, imgactual.Opacity);
            Assert.AreEqual(target.PatternXPosition, imgactual.XPostion);
            Assert.AreEqual(target.PatternXSize, imgactual.XSize);
            Assert.AreEqual(target.PatternXStep, imgactual.XStep);
            Assert.AreEqual(target.PatternYPosition, imgactual.YPostion);
            Assert.AreEqual(target.PatternYSize, imgactual.YSize);
            Assert.AreEqual(target.PatternYStep, imgactual.YStep);

            //check that the patterns are conformed to repeating

            target.PatternRepeat = PatternRepeat.RepeatX;
            imgactual            = (PDFImageBrush)target.CreateBrush();
            Assert.AreEqual(imgactual.YStep, Scryber.Styles.FillStyle.NoYRepeatStepSize);

            target.PatternRepeat = PatternRepeat.RepeatY;
            imgactual            = (PDFImageBrush)target.CreateBrush();
            Assert.AreEqual(imgactual.XStep, Scryber.Styles.FillStyle.NoXRepeatStepSize);

            target.PatternRepeat = PatternRepeat.None;
            imgactual            = (PDFImageBrush)target.CreateBrush();
            Assert.AreEqual(imgactual.YStep, Scryber.Styles.FillStyle.NoYRepeatStepSize);
            Assert.AreEqual(imgactual.XStep, Scryber.Styles.FillStyle.NoXRepeatStepSize);
        }
Exemplo n.º 10
0
 public void Fill_ConstructorTest()
 {
     Scryber.Styles.FillStyle target = new Scryber.Styles.FillStyle();
     Assert.IsNotNull(target);
     Assert.AreEqual(StyleKeys.FillItemKey, target.ItemKey);
 }
Exemplo n.º 11
0
        protected static PDFBrush Create(FillStyle fill)
        {
            if (fill == null)
            {
                throw new ArgumentNullException("fill");
            }

            Drawing.FillType fillstyle;
            bool             fillstyledefined;
            string           imgsrc;
            double           opacity;
            PDFColor         color;

            if (fill.TryGetValue(StyleKeys.FillStyleKey, out fillstyle))
            {
                if (fillstyle == Drawing.FillType.None)
                {
                    return(null);
                }
                fillstyledefined = true;
            }
            else
            {
                fillstyledefined = false;
            }

            //If we have an image source and we are set to use an image fill style (or it has not been specified)
            if (fill.TryGetValue(StyleKeys.FillImgSrcKey, out imgsrc) && !string.IsNullOrEmpty(imgsrc) && (fillstyle == Drawing.FillType.Image || fillstyledefined == false))
            {
                PDFImageBrush img    = new PDFImageBrush(imgsrc);
                PatternRepeat repeat = fill.PatternRepeat;

                if (repeat == PatternRepeat.RepeatX || repeat == PatternRepeat.RepeatBoth)
                {
                    img.XStep = fill.PatternXStep;
                }
                else
                {
                    img.XStep = NoXRepeatStepSize;
                }

                if (repeat == PatternRepeat.RepeatY || repeat == PatternRepeat.RepeatBoth)
                {
                    img.YStep = fill.PatternYStep;
                }
                else
                {
                    img.YStep = NoYRepeatStepSize;
                }

                img.XPostion = fill.PatternXPosition;
                img.YPostion = fill.PatternYPosition;

                PDFUnit x, y;

                if (fill.TryGetValue(StyleKeys.FillXSizeKey, out x))
                {
                    img.XSize = x;
                }

                if (fill.TryGetValue(StyleKeys.FillYSizeKey, out y))
                {
                    img.YSize = y;
                }

                if (fill.TryGetValue(StyleKeys.FillOpacityKey, out opacity))
                {
                    img.Opacity = opacity;
                }

                return(img);
            }

            //if we have a colour and a solid style (or no style)
            else if (fill.TryGetValue(StyleKeys.FillColorKey, out color) && (fill.Style == Drawing.FillType.Solid || fillstyledefined == false))
            {
                PDFSolidBrush solid = new PDFSolidBrush(fill.Color);

                //if we have an opacity set it.
                if (fill.TryGetValue(StyleKeys.FillOpacityKey, out opacity))
                {
                    solid.Opacity = opacity;
                }

                return(solid);
            }
            else
            {
                return(null);
            }
        }