private static PdfFunction ConstructSingleGradientSegmentFunction(GradientColorStop from, GradientColorStop to) { double exponent = 1d; float[] fromColor = from.GetRgbArray(); float[] toColor = to.GetRgbArray(); if (from.GetHintOffsetType() == GradientColorStop.HintOffsetType.RELATIVE_BETWEEN_COLORS) { double hintOffset = from.GetHintOffset(); if (hintOffset <= 0d + ZERO_EPSILON) { fromColor = toColor; } else { if (hintOffset >= 1d - ZERO_EPSILON) { toColor = fromColor; } else { // similar to css color hint logic exponent = Math.Log(0.5) / Math.Log(hintOffset); } } } return(new PdfFunction.Type2(new PdfArray(new float[] { 0f, 1f }), null, new PdfArray(fromColor), new PdfArray (toColor), new PdfNumber(exponent))); }
public virtual void CornerCasesTest() { GradientColorStop stopToTest = new GradientColorStop((float[])null, 1.5, GradientColorStop.OffsetType.AUTO ).SetHint(1.5, GradientColorStop.HintOffsetType.NONE); NUnit.Framework.Assert.AreEqual(new float[] { 0f, 0f, 0f }, stopToTest.GetRgbArray()); NUnit.Framework.Assert.AreEqual(0, stopToTest.GetOffset(), 1e-10); NUnit.Framework.Assert.AreEqual(GradientColorStop.OffsetType.AUTO, stopToTest.GetOffsetType()); NUnit.Framework.Assert.AreEqual(0, stopToTest.GetHintOffset(), 1e-10); NUnit.Framework.Assert.AreEqual(GradientColorStop.HintOffsetType.NONE, stopToTest.GetHintOffsetType()); }
public virtual void NormalizationTest() { GradientColorStop stopToTest = new GradientColorStop(new float[] { -0.5f, 1.5f, 0.5f, 0.5f }, 1.5, GradientColorStop.OffsetType .AUTO).SetHint(1.5, GradientColorStop.HintOffsetType.NONE); NUnit.Framework.Assert.AreEqual(new float[] { 0f, 1f, 0.5f }, stopToTest.GetRgbArray()); NUnit.Framework.Assert.AreEqual(0, stopToTest.GetOffset(), 1e-10); NUnit.Framework.Assert.AreEqual(GradientColorStop.OffsetType.AUTO, stopToTest.GetOffsetType()); NUnit.Framework.Assert.AreEqual(0, stopToTest.GetHintOffset(), 1e-10); NUnit.Framework.Assert.AreEqual(GradientColorStop.HintOffsetType.NONE, stopToTest.GetHintOffsetType()); }