コード例 #1
0
        /// <summary>Adds a CSS function to the global set.
        /// This is generally done automatically, but you can also add one manually if you wish.</summary>
        /// <param name="functionType">The type of the function to add.</param>
        /// <returns>True if adding it was successful.</returns>
        public static bool Add(Type functionType)
        {
            if (All == null)
            {
                // Create the set:
                All = new Dictionary <string, CssFunction>();
            }

            // Instance it:
            CssFunction cssFunction = (CssFunction)Activator.CreateInstance(functionType);

            string[] names = cssFunction.GetNames();

            if (names == null || names.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < names.Length; i++)
            {
                // Grab the name:
                string name = names[i].ToLower();

                // Add it to functions:
                All[name] = cssFunction;
            }

            return(true);
        }
コード例 #2
0
        /// <summary>Attempts to find the named function, returning the global function if it's found.</summary>
        /// <param name="name">The function to look for.</param>
        /// <returns>The global CssFunction if the function was found; Null otherwise.</returns>
        public static CssFunction Get(string name)
        {
            CssFunction globalFunction = null;

            All.TryGetValue(name.ToLower(), out globalFunction);
            return(globalFunction);
        }
コード例 #3
0
        public override bool OnReadValue(Style styleBlock, Css.Value value, int start, out int size)
        {
            Css.CssFunction func = value[start] as Css.CssFunction;

            if (func != null && func.Name == Name)
            {
                size = 1;
                return(true);
            }

            size = 0;
            return(false);
        }
コード例 #4
0
        /// <summary>Reads a function with the given lowercase name. There must be a bracket at the current read head.</summary>
        public Css.Value ReadFunction(string name)
        {
            // Read off the open bracket:
            Read();

            // Get the global instance for the given function name (lowercase):
            CssFunction globalInstance = name == "" ? null : CssFunctions.Get(name);

            // Read the args:
            Css.Value parameters = null;

            if (globalInstance == null)
            {
                // Unsupported function.
                parameters = ReadValue();
            }
            else
            {
                // Set literal value:
                if (globalInstance.LiteralValue)
                {
                    parameters = ReadLiteralValue();
                }
                else
                {
                    parameters = ReadValue();
                }
            }

            // Skip any junk (which may be e.g. after a quote):
            SkipJunk();

            // Read off the close bracket:
            Read();

            if (name == "")
            {
                // This occurs with nested brackets - it's just a set.
                return(parameters);
            }

            if (globalInstance == null)
            {
                // Don't know what this function is - act like it's not even there.
                return(null);
            }

            // Copy the global instance:
            CssFunction result = globalInstance.Copy() as CssFunction;

            // Make sure params are a set:
            ValueSet set = parameters as ValueSet;

            if (set == null)
            {
                // It's a single value, or null

                if (parameters != null)
                {
                    // Push the single value:
                    result.Values = new Css.Value[] { parameters };
                }
            }
            else
            {
                // Apply the parameters:
                result.Values = set.Values;
            }

            // Tell it that it's ready:
            result.OnValueReady(this);

            // Ok:
            return(result);
        }