コード例 #1
0
 public PDFGradientBrush(PDFGradientDescriptor descriptor)
 {
     this.Descriptor = descriptor;
 }
コード例 #2
0
        /// <summary>
        /// Attempts to parse a css style gradient string into a specific gradient descriptor
        /// </summary>
        /// <param name="value">The string to parse e.g. radial-gradient(red, green)</param>
        /// <param name="descriptor">Set to the parsed descriptor value</param>
        /// <returns>True if the gradient was parsed correctly</returns>
        public static bool TryParse(string value, out PDFGradientDescriptor descriptor)
        {
            descriptor = null;

            if (null == value)
            {
                return(false);
            }

            value = value.Trim();


            if (string.IsNullOrEmpty(value))
            {
                return(false);
            }

            else if (value.StartsWith("linear-gradient"))
            {
                value = value.Substring("linear-gradient".Length).Trim();
                PDFGradientLinearDescriptor linear;

                if (value.StartsWith("(") && value.EndsWith(")") && PDFGradientLinearDescriptor.TryParseLinear(value.Substring(1, value.Length - 2), out linear))
                {
                    linear.Repeating = false;
                    descriptor       = linear;
                    return(true);
                }
            }
            else if (value.StartsWith("repeating-linear-gradient"))
            {
                value = value.Substring("repeating-linear-gradient".Length).Trim();
                PDFGradientLinearDescriptor linear;

                if (value.StartsWith("(") && value.EndsWith(")") && PDFGradientLinearDescriptor.TryParseLinear(value.Substring(1, value.Length - 2), out linear))
                {
                    linear.Repeating = true;
                    descriptor       = linear;
                    return(true);
                }
            }
            else if (value.StartsWith("radial-gradient"))
            {
                value = value.Substring("radial-gradient".Length).Trim();
                PDFGradientRadialDescriptor radial;

                if (value.StartsWith("(") && value.EndsWith(")") && PDFGradientRadialDescriptor.TryParseRadial(value.Substring(1, value.Length - 2), out radial))
                {
                    radial.Repeating = false;
                    descriptor       = radial;
                    return(true);
                }
            }
            else if (value.StartsWith("repeating-radial-gradient"))
            {
                value = value.Substring("repeating-radial-gradient".Length).Trim();
                PDFGradientRadialDescriptor radial;

                if (value.StartsWith("(") && value.EndsWith(")") && PDFGradientRadialDescriptor.TryParseRadial(value.Substring(1, value.Length - 2), out radial))
                {
                    radial.Repeating = true;
                    descriptor       = radial;
                    return(true);
                }
            }

            return(false);
        }