Exemplo n.º 1
0
        private static IList <BackgroundImage> GetBackgroundImagesList(IList <String> backgroundImagesArray, ProcessorContext
                                                                       context, float em, float rem, IList <String> backgroundPositionXArray, IList <String> backgroundPositionYArray
                                                                       , IList <IList <String> > backgroundSizeArray, IList <String> backgroundBlendModeArray, IList <String> backgroundRepeatArray
                                                                       , IList <String> backgroundClipArray, IList <String> backgroundOriginArray)
        {
            IList <BackgroundImage> backgroundImagesList = new List <BackgroundImage>();

            for (int i = 0; i < backgroundImagesArray.Count; ++i)
            {
                String backgroundImage = backgroundImagesArray[i];
                if (backgroundImage == null || CssConstants.NONE.Equals(backgroundImage))
                {
                    continue;
                }
                BackgroundPosition position = ApplyBackgroundPosition(backgroundPositionXArray, backgroundPositionYArray,
                                                                      i, em, rem);
                BlendMode        blendMode    = ApplyBackgroundBlendMode(backgroundBlendModeArray, i);
                bool             imageApplied = false;
                BackgroundRepeat repeat       = ApplyBackgroundRepeat(backgroundRepeatArray, i);
                BackgroundBox    clip         = GetBackgroundBoxProperty(backgroundClipArray, i, BackgroundBox.BORDER_BOX);
                BackgroundBox    origin       = GetBackgroundBoxProperty(backgroundOriginArray, i, BackgroundBox.PADDING_BOX);
                if (CssGradientUtil.IsCssLinearGradientValue(backgroundImage))
                {
                    imageApplied = ApplyLinearGradient(backgroundImage, backgroundImagesList, blendMode, position, em, rem, repeat
                                                       , clip, origin);
                }
                else
                {
                    PdfXObject image = context.GetResourceResolver().RetrieveImageExtended(CssUtils.ExtractUrl(backgroundImage
                                                                                                               ));
                    imageApplied = ApplyBackgroundImage(image, backgroundImagesList, repeat, blendMode, position, clip, origin
                                                        );
                }
                if (imageApplied)
                {
                    ApplyBackgroundSize(backgroundSizeArray, em, rem, i, backgroundImagesList[backgroundImagesList.Count - 1]);
                }
            }
            return(backgroundImagesList);
        }
Exemplo n.º 2
0
    public async Task EnterAsync(BackgroundPosition oldPosition, BackgroundPosition newPosition)
    {
        var oldState = new BackgroundState("alpha", BackgroundType.Image, oldPosition);
        var newState = new BackgroundState("alpha", BackgroundType.Image, newPosition);

        var when = A.Dummy <ICondition>();

        var context = A.Dummy <INavigationContext>();

        context.State.Background = oldState;
        var invoker = new TestInvoker(context);

        var sut = new ScrollNode(when);
        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <IBackgroundScrollEvent>(
            i => i.Should().BeEquivalentTo(new { Position = newPosition })
            );

        context.State.Background.Should().Be(newState);
    }
 /// <summary>
 /// Creates a new
 /// <see cref="HtmlBackgroundImage"/>
 /// instance.
 /// </summary>
 /// <param name="xObject">
 /// background-image property.
 /// <see cref="iText.Kernel.Pdf.Xobject.PdfFormXObject"/>
 /// instance.
 /// </param>
 /// <param name="repeat">
 /// background-repeat property.
 /// <see cref="iText.Layout.Properties.BackgroundRepeat"/>
 /// instance.
 /// </param>
 /// <param name="position">
 /// background-position property.
 /// <see cref="iText.Layout.Properties.BackgroundPosition"/>
 /// instance.
 /// </param>
 /// <param name="blendMode">
 /// background-blend-mode property.
 /// <see cref="iText.Layout.Properties.BlendMode"/>
 /// instance.
 /// </param>
 /// <param name="clip">
 /// background-clip property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 /// <param name="origin">
 /// background-origin property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 public HtmlBackgroundImage(PdfFormXObject xObject, BackgroundRepeat repeat, BackgroundPosition position, BlendMode
                            blendMode, BackgroundBox clip, BackgroundBox origin)
     : base(new BackgroundImage.Builder().SetImage(xObject).SetBackgroundRepeat(repeat).SetBackgroundPosition(position
                                                                                                              ).SetBackgroundBlendMode(blendMode).SetBackgroundClip(clip).SetBackgroundOrigin(origin).Build())
 {
 }
 /// <summary>
 /// Creates a new
 /// <see cref="HtmlBackgroundImage"/>
 /// instance.
 /// </summary>
 /// <param name="xObject">
 /// background-image property.
 /// <see cref="iText.Kernel.Pdf.Xobject.PdfImageXObject"/>
 /// instance.
 /// </param>
 /// <param name="repeat">
 /// background-repeat property.
 /// <see cref="iText.Layout.Properties.BackgroundRepeat"/>
 /// instance.
 /// </param>
 /// <param name="position">
 /// background-position property.
 /// <see cref="iText.Layout.Properties.BackgroundPosition"/>
 /// instance.
 /// </param>
 /// <param name="blendMode">
 /// background-blend-mode property.
 /// <see cref="iText.Layout.Properties.BlendMode"/>
 /// instance.
 /// </param>
 /// <param name="clip">
 /// background-clip property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 /// <param name="origin">
 /// background-origin property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 public HtmlBackgroundImage(PdfImageXObject xObject, BackgroundRepeat repeat, BackgroundPosition position,
                            BlendMode blendMode, BackgroundBox clip, BackgroundBox origin)
     : base(new BackgroundImage.Builder().SetImage(xObject).SetBackgroundRepeat(repeat).SetBackgroundPosition(position
                                                                                                              ).SetBackgroundBlendMode(blendMode).SetBackgroundClip(clip).SetBackgroundOrigin(origin).Build())
 {
     dimensionMultiplier = PX_TO_PT_MULTIPLIER;
 }
 private static bool ApplyBackgroundImage(PdfXObject image, IList <BackgroundImage> backgroundImagesList, BackgroundRepeat
                                          repeat, BlendMode backgroundBlendMode, BackgroundPosition position, BackgroundBox clip, BackgroundBox
                                          origin)
 {
     if (image == null)
     {
         return(false);
     }
     if (image is PdfImageXObject)
     {
         backgroundImagesList.Add(new BackgroundApplierUtil.HtmlBackgroundImage((PdfImageXObject)image, repeat, position
                                                                                , backgroundBlendMode, clip, origin));
         return(true);
     }
     else
     {
         if (image is PdfFormXObject)
         {
             backgroundImagesList.Add(new BackgroundApplierUtil.HtmlBackgroundImage((PdfFormXObject)image, repeat, position
                                                                                    , backgroundBlendMode, clip, origin));
             return(true);
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>Adds the url in list which would be passed to the
        /// image assembly tool for concatenation</summary>
        /// <param name="url">The url for sprite candidate image</param>
        /// <param name="backgroundPosition">THe background position</param>
        private void AddImageReference(string url, BackgroundPosition backgroundPosition)
        {
            var relativeUrl = url.NormalizeUrl();
            var originalUrl = url;

            // as long as there is token.
            if (ResourcesResolver.LocalizationResourceKeyRegex.IsMatch(relativeUrl))
            {
                // ignore tokenized urls. this is having assumption that build time tokenization must be done before spriting.
                return;
            }

            url = this.GetAbsoluteImagePath(relativeUrl);

            // No need to report the url if it is present in ignore list
            if (this._imageReferencesToIgnore.Contains(relativeUrl) || this._imageReferencesToIgnore.Contains(Path.GetDirectoryName(relativeUrl) + "\\*"))
            {
                return;
            }

            if (this._imagesCriteriaFailedReferences.Any(ir => ir.Equals(url, StringComparison.OrdinalIgnoreCase)))
            {
                // Throw an exception if image has failed the criteria in past and now
                // now passes the criteria
                throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, CssStrings.DuplicateImageReferenceWithDifferentRulesError, url));
            }

            var imagePosition = backgroundPosition.GetImagePositionInVerticalSprite();
            var added         = false;

            ////
            //// Try adding the image in the non default scan output
            ////
            for (var count = 1; count < this._imageAssemblyScanOutputs.Count; count++)
            {
                var imageAssemblyScanOutput = this._imageAssemblyScanOutputs[count];
                if (!imageAssemblyScanOutput.ImageAssemblyScanInput.ImagesInBucket.Contains(url))
                {
                    continue;
                }

                // Make sure that image don't exist already in list
                if (imageAssemblyScanOutput.ImageReferencesToAssemble.Any(inputImage => inputImage.AbsoluteImagePath == url && inputImage.Position == imagePosition))
                {
                    continue;
                }

                imageAssemblyScanOutput.ImageReferencesToAssemble.Add(new InputImage {
                    AbsoluteImagePath = url, Position = imagePosition, OriginalImagePath = originalUrl
                });
                added = true;
            }

            if (added)
            {
                return;
            }

            ////
            //// Add the image in the default scan output
            ////
            if (this._defaultImageAssemblyScanOutput.ImageReferencesToAssemble.Any(inputImage => inputImage.AbsoluteImagePath == url && inputImage.Position == imagePosition))
            {
                return;
            }

            this._defaultImageAssemblyScanOutput.ImageReferencesToAssemble.Add(new InputImage {
                AbsoluteImagePath = url, Position = imagePosition, OriginalImagePath = originalUrl
            });
        }
Exemplo n.º 7
0
        /// <summary>Gets the assembled image information from the dictionary</summary>
        /// <param name="parsedImagePath">The parsed url</param>
        /// <param name="backgroundPosition">The background position node</param>
        /// <param name="assembledImage">The assembled image path</param>
        /// <returns>The assembled image object</returns>
        private bool TryGetAssembledImage(string parsedImagePath, BackgroundPosition backgroundPosition, out AssembledImage assembledImage)
        {
            if (this.availableSourceImages == null && string.IsNullOrWhiteSpace(this.cssPath))
            {
                throw new BuildWorkflowException("Need either images or css path to be able to set a valid image file.");
            }

            assembledImage = null;

            if (this.inputImages == null)
            {
                return(false);
            }

            // TODO - Spec. issue: What are the supported path formats supported in CSS?
            // For optimization, should the relative paths be enforced?

            // Get the full path of parsed image file (convert from ../../ to absolute path)
            if (parsedImagePath.StartsWith("hash://", StringComparison.OrdinalIgnoreCase))
            {
                parsedImagePath = parsedImagePath.Substring(7);
            }

            if (this.availableSourceImages != null)
            {
                if (!this.availableSourceImages.TryGetValue(parsedImagePath.NormalizeUrl(), out parsedImagePath))
                {
                    if (!string.IsNullOrWhiteSpace(this.missingImage))
                    {
                        parsedImagePath = this.availableSourceImages.TryGetValue(this.missingImage);
                    }
                }
            }
            else
            {
                parsedImagePath = parsedImagePath.MakeAbsoluteTo(this.cssPath);
            }

            var imagePosition = ImagePosition.Left;

            if (backgroundPosition != null)
            {
                imagePosition = backgroundPosition.GetImagePositionInVerticalSprite();
            }

            // Try to locate the input image in the list
            assembledImage = this.inputImages.FirstOrDefault(inputImage => inputImage.ImagePosition == imagePosition && inputImage.OriginalFilePath.Equals(parsedImagePath, StringComparison.OrdinalIgnoreCase));

            if (assembledImage != null &&
                assembledImage.OutputFilePath != null)
            {
                assembledImage.RelativeOutputFilePath =
                    !string.IsNullOrWhiteSpace(this.destinationDirectory)
                        ? Path.Combine(this.prependToDestination, assembledImage.OutputFilePath.MakeRelativeToDirectory(this.destinationDirectory).Replace('\\', '/'))
                        : assembledImage.OutputFilePath.MakeRelativeTo(this.cssPath);

                if (!string.IsNullOrWhiteSpace(assembledImage.RelativeOutputFilePath))
                {
                    assembledImage.RelativeOutputFilePath = assembledImage.RelativeOutputFilePath.Replace('\\', '/');
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 8
0
        /// <summary>Updates the list of declarations with the updated value from
        /// image assembly log.
        /// Example Css with shorthand declaration:
        /// #selector
        /// {
        ///   background: url(../../i/02/3118D8F3781159C8341246BBF2B4CA.gif) no-repeat -10px -200px;
        /// }
        /// Example Css with long declarations:
        /// #selector
        /// {
        ///   background-repeat: no-repeat;
        ///   background-position: -10px  -200px;
        ///   background-image: url(../../i/02/3118D8F3781159C8341246BBF2B4CA.gif);
        /// }</summary>
        /// <param name="declarationNodes">The list of declarations</param>
        /// <param name="parent">The parent AST node</param>
        /// <returns>The list of updated declarations</returns>
        private ReadOnlyCollection <DeclarationNode> UpdateDeclarations(ReadOnlyCollection <DeclarationNode> declarationNodes, AstNode parent)
        {
            try
            {
                // Populate the nodes from AST extension
                Background         backgroundNode;
                BackgroundImage    backgroundImageNode;
                BackgroundPosition backgroundPositionNode;
                DeclarationNode    backgroundSizeNode;

                // There is no background node found in set of declarations, return without any change
                if (!declarationNodes.TryGetBackgroundDeclaration(parent, out backgroundNode, out backgroundImageNode, out backgroundPositionNode, out backgroundSizeNode, null, null, null, this.outputUnit, this.outputUnitFactor))
                {
                    // No change, return the original collection
                    return(declarationNodes);
                }

                // At this point, there should be atleast one "background" or "background-image" node found.
                // In addition, there can be an optional "background-position" node
                // Initialize a cloned set of declarations (The original AST collection is immutable by design)
                var updatedDeclarations = new List <DeclarationNode>(declarationNodes);

                if (this.dpi != 1f)
                {
                    // not a normal-DPI (1x) -- output a comment at the top stating what our DPI really is
                    updatedDeclarations.Insert(0, CreateDpiComment(this.dpi));
                }

                // Empty object to be discovered from log
                AssembledImage assembledImage;

                if (backgroundNode != null)
                {
                    // Short hand declaration found:
                    // #selector
                    // {
                    // background: url(../../i/02/3118D8F3781159C8341246BBF2B4CA.gif) no-repeat -10px -200px;
                    // }
                    // Query the log file and see if there is an assembled node for
                    // the background image
                    if (!this.TryGetAssembledImage(backgroundNode.Url, backgroundNode.BackgroundPosition, out assembledImage))
                    {
                        return(declarationNodes);
                    }

                    // add some comments that we can use to help debugging
                    updatedDeclarations.Insert(0, CreateDebugOriginalPositionComment(backgroundNode.BackgroundPosition.X, backgroundNode.BackgroundPosition.XSource, backgroundNode.BackgroundPosition.Y, backgroundNode.BackgroundPosition.YSource));
                    updatedDeclarations.Insert(0, CreateDebugSpritePositionComment(assembledImage.X, assembledImage.Y));

                    // Update the declaration node with new values in AST
                    var updatedDeclaration = backgroundNode.UpdateBackgroundNode(assembledImage.RelativeOutputFilePath, assembledImage.X, assembledImage.Y, this.dpi);

                    // Update the declaration list
                    UpdateDeclarations(updatedDeclarations, backgroundNode.DeclarationAstNode, updatedDeclaration);

                    this.SetBackgroundSize(updatedDeclarations, backgroundSizeNode, this.dpi, assembledImage);
                }
                else if (backgroundImageNode != null)
                {
                    // Long declaration found for background-image:
                    // #selector
                    // {
                    // background-image: url(../../i/02/3118D8F3781159C8341246BBF2B4CA.gif);
                    // }
                    // Query the log file and see if there is an assembled node for
                    // the background image
                    if (!this.TryGetAssembledImage(backgroundImageNode.Url, backgroundPositionNode, out assembledImage))
                    {
                        // Return without update with a group of declarations
                        return(declarationNodes);
                    }

                    // Update the declaration node with new values in AST
                    var updatedDeclaration = backgroundImageNode.UpdateBackgroundImageNode(assembledImage.RelativeOutputFilePath);

                    // Update the list of declarations
                    UpdateDeclarations(updatedDeclarations, backgroundImageNode.DeclarationNode, updatedDeclaration);

                    if (backgroundPositionNode != null)
                    {
                        // Long declaration found for background-position:
                        // #selector
                        // {
                        // background-position: -10px  -200px;
                        // }
                        // Update the declaration node with new values in AST

                        // add some comments that can help with debugging
                        updatedDeclarations.Insert(0, CreateDebugOriginalPositionComment(backgroundPositionNode.X, backgroundPositionNode.XSource, backgroundPositionNode.Y, backgroundPositionNode.YSource));
                        updatedDeclarations.Insert(0, CreateDebugSpritePositionComment(assembledImage.X, assembledImage.Y));

                        updatedDeclaration = backgroundPositionNode.UpdateBackgroundPositionNode(assembledImage.X, assembledImage.Y, this.dpi);

                        // Update the list of declarations
                        UpdateDeclarations(updatedDeclarations, backgroundPositionNode.DeclarationNode, updatedDeclaration);
                    }
                    else
                    {
                        // If there is no declaration found for "background-position",
                        // Create a new declaration node in AST for "background-position" declaration
                        var newDeclaration = BackgroundPosition.CreateNewDeclaration(assembledImage.X, assembledImage.Y, this.dpi, this.outputUnit, this.outputUnitFactor);

                        // add a comment to help with debugging
                        updatedDeclarations.Insert(0, CreateDebugSpritePositionComment(assembledImage.X, assembledImage.Y));

                        if (newDeclaration != null)
                        {
                            updatedDeclarations.Add(newDeclaration);
                        }
                    }

                    this.SetBackgroundSize(updatedDeclarations, backgroundSizeNode, this.dpi, assembledImage);
                }

                return(updatedDeclarations.AsReadOnly());
            }
            catch (Exception exception)
            {
                throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, CssStrings.InnerExceptionSelector, parent.PrettyPrint()), exception);
            }
        }
Exemplo n.º 9
0
        internal static bool TryGetBackgroundDeclaration(this IEnumerable <DeclarationNode> declarationAstNodes, AstNode parentAstNode, out Background backgroundNode, out BackgroundImage backgroundImageNode, out BackgroundPosition backgroundPositionNode, out DeclarationNode backgroundSize, List <string> imageReferencesInInvalidDeclarations, HashSet <string> imageReferencesToIgnore, ImageAssemblyAnalysisLog imageAssemblyAnalysisLog, string outputUnit, double outputUnitFactor, bool ignoreImagesWithNonDefaultBackgroundSize = false)
        {
            // Initialize the nodes to null
            backgroundNode         = null;
            backgroundImageNode    = null;
            backgroundPositionNode = null;
            backgroundSize         = null;

            // With CSS3 multiple urls can be present in a single rule, this is not yet supported
            // background: url(flower.png), url(ball.png), url(grass.png) no-repeat;
            if (BackgroundImage.HasMultipleUrls(parentAstNode.MinifyPrint()))
            {
                imageAssemblyAnalysisLog.SafeAdd(parentAstNode, null, FailureReason.MultipleUrls);
                return(false);
            }

            // This will check if the selector hash -wg-spriting: ignore. If it does we will ignore the sprite.
            var webGreaseSpritingProperty = declarationAstNodes.FirstOrDefault(d => d.Property == "-wg-spriting");

            if (webGreaseSpritingProperty != null && webGreaseSpritingProperty.ExprNode.TermNode.StringBasedValue == "ignore")
            {
                imageAssemblyAnalysisLog.SafeAdd(parentAstNode, null, FailureReason.SpritingIgnore);
                return(false);
            }

            // The list of declarations should not have the duplicate declaration
            // properties. Validate and get the dictionary of declarations.
            var declarationProperties = declarationAstNodes.LoadDeclarationPropertiesDictionary();

            // The selector design is inefficient if the shorthand notation and long name is defined
            // in a scope of ruleset declaration, media ruleset declaration or page declaration. This
            // would be a great feature to add to Optimization visitor but would require a full table
            // scanning which is not yet implemented.
            // Per MSN CSS standards, the practice of defining the shorthand notation and long name
            // in scope of same selector is not allowed.
            DeclarationNode declarationAstNode;

            if (declarationProperties.TryGetValue(ImageAssembleConstants.Background, out declarationAstNode))
            {
                // There should not be any short and long notation simultaneosuly used in these set of declarations.
                // For example: Such a list of declarations end up in inefficient CSS.
                // #selector
                // {
                // background:url(foo.gif);
                // background-image:url(../../i/D5/DF5D9B4EFD5CFF9122942A67A1EEC5.gif);
                // background-position:500px 500px;
                // background-repeat:no-repeat
                // }
                // By design, we are not computing cascade here.
                // TODO: RTUIT: Add support to override some of these with extra values depending on the order, or use optimization to do this when merging styles.
                if (declarationProperties.ContainsKey(ImageAssembleConstants.BackgroundRepeat) ||
                    declarationProperties.ContainsKey(ImageAssembleConstants.BackgroundImage) ||
                    declarationProperties.ContainsKey(ImageAssembleConstants.BackgroundPosition))
                {
                    throw new ImageAssembleException(CssStrings.DuplicateBackgroundFormatError);
                }

                // Load the model for the "background" declaration
                var parsedBackground = new Background(declarationAstNode, outputUnit, outputUnitFactor);

                ////
                //// The url should be present
                ////
                bool shouldIgnore;
                if (!parsedBackground.BackgroundImage.VerifyBackgroundUrl(parentAstNode, imageReferencesToIgnore, imageAssemblyAnalysisLog, out shouldIgnore) ||
                    shouldIgnore)
                {
                    return(false);
                }

                ////
                //// The "no-repeat" term should be explicitly configured on the "background" declaration
                ////
                if (!parsedBackground.BackgroundRepeat.VerifyBackgroundNoRepeat())
                {
                    imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackground.Url, FailureReason.BackgroundRepeatInvalid);
                    UpdateFailedUrlsList(parsedBackground.Url, imageReferencesInInvalidDeclarations);
                    return(false);
                }

                ////
                //// The background position should only be empty, x = any value and y = 0, top or px
                ////
                if (!parsedBackground.BackgroundPosition.IsVerticalSpriteCandidate())
                {
                    imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackground.Url, FailureReason.IncorrectPosition);
                    UpdateFailedUrlsList(parsedBackground.Url, imageReferencesInInvalidDeclarations);
                    return(false);
                }

                //// Try to get the background size, returns false if we want to ignore images with background sizes and the background size is set to a non-default value.
                if (!TryGetBackgroundSize(ignoreImagesWithNonDefaultBackgroundSize, declarationProperties, out backgroundSize))
                {
                    imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackground.Url, FailureReason.BackgroundSizeIsSetToNonDefaultValue);
                    UpdateFailedUrlsList(parsedBackground.Url, imageReferencesInInvalidDeclarations);
                    return(false);
                }

                backgroundNode = parsedBackground;
                imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackground.Url);

                //// SUCCESS - This is the candidate!
                return(true);
            }

            // Now there should be declaration for "background-image" or "background-repeat" or both
            if (declarationProperties.TryGetValue(ImageAssembleConstants.BackgroundImage, out declarationAstNode))
            {
                // Load the property model for the "background-image" declaration
                var parsedBackgroundImage = new BackgroundImage(declarationAstNode);

                ////
                //// The url should be present
                ////
                bool shouldIgnore;
                if (!parsedBackgroundImage.VerifyBackgroundUrl(parentAstNode, imageReferencesToIgnore, imageAssemblyAnalysisLog, out shouldIgnore) ||
                    shouldIgnore)
                {
                    return(false);
                }

                ////
                //// There is a "background-repeat" declaration found
                ////
                DeclarationNode backgroundRepeat;
                if (!declarationProperties.TryGetValue(ImageAssembleConstants.BackgroundRepeat, out backgroundRepeat))
                {
                    imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackgroundImage.Url, FailureReason.NoRepeat);
                    UpdateFailedUrlsList(parsedBackgroundImage.Url, imageReferencesInInvalidDeclarations);
                    return(false);
                }

                ////
                //// Now make sure that "background-repeat" is "no-repeat"
                ////
                if (!new BackgroundRepeat(backgroundRepeat).VerifyBackgroundNoRepeat())
                {
                    imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackgroundImage.Url, FailureReason.BackgroundRepeatInvalid);
                    UpdateFailedUrlsList(parsedBackgroundImage.Url, imageReferencesInInvalidDeclarations);
                    return(false);
                }

                //// Try to get the background size, returns false if we want to ignore images with background sizes and the background size is set to a non-default value.
                if (!TryGetBackgroundSize(ignoreImagesWithNonDefaultBackgroundSize, declarationProperties, out backgroundSize))
                {
                    imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackgroundImage.Url, FailureReason.BackgroundSizeIsSetToNonDefaultValue);
                    UpdateFailedUrlsList(parsedBackgroundImage.Url, imageReferencesInInvalidDeclarations);
                    return(false);
                }

                ////
                //// The background position should only be empty, x = any value and y = 0, top or px
                ////
                DeclarationNode backgroundPosition;
                if (declarationProperties.TryGetValue(ImageAssembleConstants.BackgroundPosition, out backgroundPosition))
                {
                    // Now if there is a "background-position" declaration (optional), lets make
                    // it should only be empty, px or left/top or right/px
                    var parsedBackgroundPosition = new BackgroundPosition(backgroundPosition, outputUnit, outputUnitFactor);

                    if (!parsedBackgroundPosition.IsVerticalSpriteCandidate())
                    {
                        imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackgroundImage.Url, FailureReason.IncorrectPosition);
                        UpdateFailedUrlsList(parsedBackgroundImage.Url, imageReferencesInInvalidDeclarations);
                        return(false);
                    }

                    backgroundImageNode    = parsedBackgroundImage;
                    backgroundPositionNode = parsedBackgroundPosition;
                    imageAssemblyAnalysisLog.SafeAdd(parentAstNode, parsedBackgroundImage.Url);

                    //// SUCCESS - This is the candidate!
                    return(true);
                }

                backgroundImageNode = parsedBackgroundImage;
                imageAssemblyAnalysisLog.SafeAdd(parentAstNode, backgroundImageNode.Url);

                //// SUCCESS - This is the candidate!
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
    public void ToStringTest(string name, BackgroundType type, BackgroundPosition position, string expected)
    {
        var sut = new BackgroundState(name, type, position);

        sut.ToString().Should().Be(expected);
    }