/// <summary>Set the offset specified by its value and type</summary>
 /// <param name="offset">
 /// the offset's value to be set. Makes sense only if the
 /// <paramref name="offsetType"/>
 /// is not
 /// <see cref="OffsetType.AUTO"/>
 /// </param>
 /// <param name="offsetType">the offset's type to be set</param>
 /// <returns>
 /// the current
 /// <see cref="GradientColorStop"/>
 /// instance
 /// </returns>
 public virtual iText.Kernel.Colors.Gradients.GradientColorStop SetOffset(double offset, GradientColorStop.OffsetType
                                                                          offsetType)
 {
     this.offsetType = offsetType != null ? offsetType : GradientColorStop.OffsetType.AUTO;
     this.offset     = this.offsetType != GradientColorStop.OffsetType.AUTO ? offset : 0d;
     return(this);
 }
 private GradientColorStop(float[] rgb, float opacity, double offset, GradientColorStop.OffsetType offsetType
                           )
 {
     this.rgb     = CopyRgbArray(rgb);
     this.opacity = Normalize(opacity);
     SetOffset(offset, offsetType);
 }
Exemple #3
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);
        }
 /// <summary>Constructor that creates the stop with the same color as the another stop and new offset</summary>
 /// <param name="gradientColorStop">the gradient stop color from which the color value would be copied</param>
 /// <param name="offset">
 /// the new offset. Makes sense only if the
 /// <paramref name="offsetType"/>
 /// is not
 /// <see cref="OffsetType.AUTO"/>
 /// </param>
 /// <param name="offsetType">the new offset's type</param>
 public GradientColorStop(iText.Kernel.Colors.Gradients.GradientColorStop gradientColorStop, double offset,
                          GradientColorStop.OffsetType offsetType)
     : this(gradientColorStop.GetRgbArray(), gradientColorStop.GetOpacity(), offset, offsetType)
 {
 }
 /// <summary>Constructor of stop color with with specified rgb color and offset</summary>
 /// <param name="rgb">the color value</param>
 /// <param name="offset">
 /// the offset value. Makes sense only if the
 /// <paramref name="offsetType"/>
 /// is not
 /// <see cref="OffsetType.AUTO"/>
 /// </param>
 /// <param name="offsetType">the offset's type</param>
 public GradientColorStop(float[] rgb, double offset, GradientColorStop.OffsetType offsetType)
     : this(rgb, 1f, offset, offsetType)
 {
 }