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); }
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); } }