/// <summary>
 /// Set the color hint specified by its value and type (
 /// <see cref="GradientColorStop">more details</see>
 /// ).
 /// </summary>
 /// <param name="hintOffset">
 /// the hint offset's value to be set. Makes sense only
 /// if the
 /// <paramref name="hintOffsetType"/>
 /// is not
 /// <see cref="HintOffsetType.NONE"/>
 /// </param>
 /// <param name="hintOffsetType">the hint offset's type to be set</param>
 /// <returns>
 /// the current
 /// <see cref="GradientColorStop"/>
 /// instance
 /// </returns>
 public virtual iText.Kernel.Colors.Gradients.GradientColorStop SetHint(double hintOffset, GradientColorStop.HintOffsetType
                                                                        hintOffsetType)
 {
     this.hintOffsetType = hintOffsetType != null ? hintOffsetType : GradientColorStop.HintOffsetType.NONE;
     this.hintOffset     = this.hintOffsetType != GradientColorStop.HintOffsetType.NONE ? hintOffset : 0d;
     return(this);
 }
Example #2
0
        private static IList <GradientColorStop> CopyStopsAndNormalizeAbsoluteOffsets(IList <GradientColorStop> toNormalize
                                                                                      , double baseVectorLength)
        {
            double lastUsedOffset          = double.NegativeInfinity;
            IList <GradientColorStop> copy = new List <GradientColorStop>(toNormalize.Count);

            foreach (GradientColorStop stop in toNormalize)
            {
                double offset = stop.GetOffset();
                GradientColorStop.OffsetType offsetType = stop.GetOffsetType();
                if (offsetType == GradientColorStop.OffsetType.ABSOLUTE)
                {
                    offsetType = GradientColorStop.OffsetType.RELATIVE;
                    offset    /= baseVectorLength;
                }
                if (offsetType == GradientColorStop.OffsetType.RELATIVE)
                {
                    if (offset < lastUsedOffset)
                    {
                        offset = lastUsedOffset;
                    }
                    lastUsedOffset = offset;
                }
                GradientColorStop result     = new GradientColorStop(stop, offset, offsetType);
                double            hintOffset = stop.GetHintOffset();
                GradientColorStop.HintOffsetType hintOffsetType = stop.GetHintOffsetType();
                if (hintOffsetType == GradientColorStop.HintOffsetType.ABSOLUTE_ON_GRADIENT)
                {
                    hintOffsetType = GradientColorStop.HintOffsetType.RELATIVE_ON_GRADIENT;
                    hintOffset    /= baseVectorLength;
                }
                if (hintOffsetType == GradientColorStop.HintOffsetType.RELATIVE_ON_GRADIENT)
                {
                    if (hintOffset < lastUsedOffset)
                    {
                        hintOffset = lastUsedOffset;
                    }
                    lastUsedOffset = hintOffset;
                }
                result.SetHint(hintOffset, hintOffsetType);
                copy.Add(result);
            }
            return(copy);
        }