protected internal PdfObject GetSpotObject(PdfWriter writer) { PdfArray array = new PdfArray(PdfName.SEPARATION); array.Add(name); PdfFunction func = null; if (altcs is ExtendedColor) { int type = ((ExtendedColor)altcs).Type; switch (type) { case ExtendedColor.TYPE_GRAY: array.Add(PdfName.DEVICEGRAY); func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0}, new float[]{((GrayColor)altcs).Gray}, 1); break; case ExtendedColor.TYPE_CMYK: array.Add(PdfName.DEVICECMYK); CMYKColor cmyk = (CMYKColor)altcs; func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0, 0, 0, 0}, new float[]{cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black}, 1); break; default: throw new Exception("Only RGB, Gray and CMYK are supported as alternative color spaces."); } } else { array.Add(PdfName.DEVICERGB); func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{1, 1, 1}, new float[]{(float)altcs.R / 255, (float)altcs.G / 255, (float)altcs.B / 255}, 1); } array.Add(func.Reference); return array; }
public static PdfFunction Type0(PdfWriter writer, float[] domain, float[] range, int[] size, int bitsPerSample, int order, float[] encode, float[] decode, byte[] stream) { PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfStream(stream); ((PdfStream)func.dictionary).FlateCompress(writer.CompressionLevel); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(0)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); func.dictionary.Put(PdfName.SIZE, new PdfArray(size)); func.dictionary.Put(PdfName.BITSPERSAMPLE, new PdfNumber(bitsPerSample)); if (order != 1) { func.dictionary.Put(PdfName.ORDER, new PdfNumber(order)); } if (encode != null) { func.dictionary.Put(PdfName.ENCODE, new PdfArray(encode)); } if (decode != null) { func.dictionary.Put(PdfName.DECODE, new PdfArray(decode)); } return(func); }
public static PdfShading SimpleRadial(PdfWriter writer, float x0, float y0, float r0, float x1, float y1, float r1, BaseColor startColor, BaseColor endColor, bool extendStart, bool extendEnd) { CheckCompatibleColors(startColor, endColor); PdfFunction function = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, GetColorArray(startColor), GetColorArray(endColor), 1); return(Type3(writer, startColor, new float[] { x0, y0, r0, x1, y1, r1 }, null, function, new bool[] { extendStart, extendEnd })); }
public static PdfShading simpleAxial(PdfWriter writer, float x0, float y0, float x1, float y1, Color startColor, Color endColor, bool extendStart, bool extendEnd) { checkCompatibleColors(startColor, endColor); PdfFunction function = PdfFunction.type2(writer, new float[] { 0, 1 }, null, getColorArray(startColor), getColorArray(endColor), 1); return(type2(writer, startColor, new float[] { x0, y0, x1, y1 }, null, function, new bool[] { extendStart, extendEnd })); }
public virtual PdfObject GetPdfObject(PdfWriter writer) { PdfArray array = new PdfArray(PdfName.SEPARATION); array.Add(name); PdfFunction func = null; if (altcs is ExtendedColor) { int type = ((ExtendedColor)altcs).Type; switch (type) { case ExtendedColor.TYPE_GRAY: array.Add(PdfName.DEVICEGRAY); func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 1 }, new float[] { ((GrayColor)altcs).Gray }, 1); break; case ExtendedColor.TYPE_CMYK: array.Add(PdfName.DEVICECMYK); CMYKColor cmyk = (CMYKColor)altcs; func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 0, 0, 0, 0 }, new float[] { cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black }, 1); break; case ExtendedColor.TYPE_LAB: LabColor lab = (LabColor)altcs; if (altColorDetails != null) { array.Add(altColorDetails.IndirectReference); } else { array.Add(lab.LabColorSpace.GetPdfObject(writer)); } func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 100f, 0f, 0f }, new float[] { lab.L, lab.A, lab.B }, 1); break; default: throw new Exception( MessageLocalization.GetComposedMessage( "only.rgb.gray.and.cmyk.are.supported.as.alternative.color.spaces")); } } else { array.Add(PdfName.DEVICERGB); func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 1, 1, 1 }, new float[] { (float)altcs.R / 255, (float)altcs.G / 255, (float)altcs.B / 255 }, 1); } array.Add(func.Reference); return(array); }
public static PdfFunction Type4(PdfWriter writer, float[] domain, float[] range, string postscript) { byte[] b = new byte[postscript.Length]; for (int k = 0; k < b.Length; ++k) { b[k] = (byte)postscript[k]; } PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfStream(b); ((PdfStream)func.dictionary).FlateCompress(writer.CompressionLevel); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(4)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); return(func); }
public static PdfFunction Type0(PdfWriter writer, float[] domain, float[] range, int[] size, int bitsPerSample, int order, float[] encode, float[] decode, byte[] stream) { PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfStream(stream); ((PdfStream)func.dictionary).FlateCompress(writer.CompressionLevel); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(0)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); func.dictionary.Put(PdfName.SIZE, new PdfArray(size)); func.dictionary.Put(PdfName.BITSPERSAMPLE, new PdfNumber(bitsPerSample)); if (order != 1) func.dictionary.Put(PdfName.ORDER, new PdfNumber(order)); if (encode != null) func.dictionary.Put(PdfName.ENCODE, new PdfArray(encode)); if (decode != null) func.dictionary.Put(PdfName.DECODE, new PdfArray(decode)); return func; }
public static PdfFunction Type3(PdfWriter writer, float[] domain, float[] range, PdfFunction[] functions, float[] bounds, float[] encode) { PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfDictionary(); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(3)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); if (range != null) { func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); } PdfArray array = new PdfArray(); for (int k = 0; k < functions.Length; ++k) { array.Add(functions[k].Reference); } func.dictionary.Put(PdfName.FUNCTIONS, array); func.dictionary.Put(PdfName.BOUNDS, new PdfArray(bounds)); func.dictionary.Put(PdfName.ENCODE, new PdfArray(encode)); return(func); }
public static PdfFunction Type2(PdfWriter writer, float[] domain, float[] range, float[] c0, float[] c1, float n) { PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfDictionary(); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(2)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); if (range != null) { func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); } if (c0 != null) { func.dictionary.Put(PdfName.C0, new PdfArray(c0)); } if (c1 != null) { func.dictionary.Put(PdfName.C1, new PdfArray(c1)); } func.dictionary.Put(PdfName.N, new PdfNumber(n)); return(func); }
protected internal PdfObject GetSpotObject(PdfWriter writer) { var array = new PdfArray(PdfName.Separation); array.Add(Name); PdfFunction func = null; if (Altcs is ExtendedColor) { var type = ((ExtendedColor)Altcs).Type; switch (type) { case ExtendedColor.TYPE_GRAY: array.Add(PdfName.Devicegray); func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 0 }, new[] { ((GrayColor)Altcs).Gray }, 1); break; case ExtendedColor.TYPE_CMYK: array.Add(PdfName.Devicecmyk); var cmyk = (CmykColor)Altcs; func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 0, 0, 0, 0 }, new[] { cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black }, 1); break; default: throw new Exception("Only RGB, Gray and CMYK are supported as alternative color spaces."); } } else { array.Add(PdfName.Devicergb); func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 1, 1, 1 }, new[] { (float)Altcs.R / 255, (float)Altcs.G / 255, (float)Altcs.B / 255 }, 1); } array.Add(func.Reference); return(array); }
public static PdfShading Type2(PdfWriter writer, BaseColor colorSpace, float[] coords, float[] domain, PdfFunction function, bool[] extend) { PdfShading sp = new PdfShading(writer); sp.shading = new PdfDictionary(); sp.shadingType = 2; sp.shading.Put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); sp.SetColorSpace(colorSpace); sp.shading.Put(PdfName.COORDS, new PdfArray(coords)); if (domain != null) { sp.shading.Put(PdfName.DOMAIN, new PdfArray(domain)); } sp.shading.Put(PdfName.FUNCTION, function.Reference); if (extend != null && (extend[0] || extend[1])) { PdfArray array = new PdfArray(extend[0] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE); array.Add(extend[1] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE); sp.shading.Put(PdfName.EXTEND, array); } return(sp); }
public virtual PdfObject GetPdfObject(PdfWriter writer) { PdfArray array = new PdfArray(PdfName.DEVICEN); PdfArray colorants = new PdfArray(); float[] colorantsRanges = new float[spotColors.Length * 2]; PdfDictionary colorantsDict = new PdfDictionary(); String psFunFooter = ""; int numberOfColorants = spotColors.Length; float[,] CMYK = new float[4, numberOfColorants]; int i = 0; for (; i < numberOfColorants; i++) { PdfSpotColor spotColorant = spotColors[i]; colorantsRanges[2 * i] = 0; colorantsRanges[2 * i + 1] = 1; colorants.Add(spotColorant.Name); if (colorantsDict.Get(spotColorant.Name) != null) { throw new Exception(MessageLocalization.GetComposedMessage("devicen.component.names.shall.be.different")); } if (colorantsDetails != null) { colorantsDict.Put(spotColorant.Name, colorantsDetails[i].IndirectReference); } else { colorantsDict.Put(spotColorant.Name, spotColorant.GetPdfObject(writer)); } BaseColor color = spotColorant.AlternativeCS; if (color is ExtendedColor) { int type = ((ExtendedColor)color).Type; switch (type) { case ExtendedColor.TYPE_GRAY: CMYK[0, i] = 0; CMYK[1, i] = 0; CMYK[2, i] = 0; CMYK[3, i] = 1 - ((GrayColor)color).Gray; break; case ExtendedColor.TYPE_CMYK: CMYK[0, i] = ((CMYKColor)color).Cyan; CMYK[1, i] = ((CMYKColor)color).Magenta; CMYK[2, i] = ((CMYKColor)color).Yellow; CMYK[3, i] = ((CMYKColor)color).Black; break; case ExtendedColor.TYPE_LAB: CMYKColor cmyk = ((LabColor)color).ToCmyk(); CMYK[0, i] = cmyk.Cyan; CMYK[1, i] = cmyk.Magenta; CMYK[2, i] = cmyk.Yellow; CMYK[3, i] = cmyk.Black; break; default: throw new Exception( MessageLocalization.GetComposedMessage( "only.rgb.gray.and.cmyk.are.supported.as.alternative.color.spaces")); } } else { float r = color.R; float g = color.G; float b = color.B; float computedC = 0, computedM = 0, computedY = 0, computedK = 0; // BLACK if (r == 0 && g == 0 && b == 0) { computedK = 1; } else { computedC = 1 - (r / 255); computedM = 1 - (g / 255); computedY = 1 - (b / 255); float minCMY = Math.Min(computedC, Math.Min(computedM, computedY)); computedC = (computedC - minCMY) / (1 - minCMY); computedM = (computedM - minCMY) / (1 - minCMY); computedY = (computedY - minCMY) / (1 - minCMY); computedK = minCMY; } CMYK[0, i] = computedC; CMYK[1, i] = computedM; CMYK[2, i] = computedY; CMYK[3, i] = computedK; } psFunFooter += "pop "; } array.Add(colorants); String psFunHeader = String.Format(NumberFormatInfo.InvariantInfo, "1.000000 {0} 1 roll ", numberOfColorants + 1); array.Add(PdfName.DEVICECMYK); psFunHeader = psFunHeader + psFunHeader + psFunHeader + psFunHeader; String psFun = ""; i = numberOfColorants + 4; for (; i > numberOfColorants; i--) { psFun += String.Format(NumberFormatInfo.InvariantInfo, "{0} -1 roll ", i); for (int j = numberOfColorants; j > 0; j--) { psFun += String.Format(NumberFormatInfo.InvariantInfo, "{0} index {1} mul 1.000000 cvr exch sub mul ", j, CMYK[numberOfColorants + 4 - i, numberOfColorants - j]); } psFun += String.Format(NumberFormatInfo.InvariantInfo, "1.000000 cvr exch sub {0} 1 roll ", i); } PdfFunction func = PdfFunction.Type4(writer, colorantsRanges, new float[] { 0, 1, 0, 1, 0, 1, 0, 1 }, "{ " + psFunHeader + psFun + psFunFooter + "}"); array.Add(func.Reference); PdfDictionary attr = new PdfDictionary(); attr.Put(PdfName.SUBTYPE, PdfName.NCHANNEL); attr.Put(PdfName.COLORANTS, colorantsDict); array.Add(attr); return(array); }
public static PdfShading Type3(PdfWriter writer, BaseColor colorSpace, float[] coords, float[] domain, PdfFunction function, bool[] extend) { PdfShading sp = Type2(writer, colorSpace, coords, domain, function, extend); sp.shadingType = 3; sp.shading.Put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); return sp; }
public static PdfShading Type2(PdfWriter writer, BaseColor colorSpace, float[] coords, float[] domain, PdfFunction function, bool[] extend) { PdfShading sp = new PdfShading(writer); sp.shading = new PdfDictionary(); sp.shadingType = 2; sp.shading.Put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); sp.SetColorSpace(colorSpace); sp.shading.Put(PdfName.COORDS, new PdfArray(coords)); if (domain != null) sp.shading.Put(PdfName.DOMAIN, new PdfArray(domain)); sp.shading.Put(PdfName.FUNCTION, function.Reference); if (extend != null && (extend[0] || extend[1])) { PdfArray array = new PdfArray(extend[0] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE); array.Add(extend[1] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE); sp.shading.Put(PdfName.EXTEND, array); } return sp; }
public static PdfShading Type1(PdfWriter writer, BaseColor colorSpace, float[] domain, float[] tMatrix, PdfFunction function) { PdfShading sp = new PdfShading(writer); sp.shading = new PdfDictionary(); sp.shadingType = 1; sp.shading.Put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); sp.SetColorSpace(colorSpace); if (domain != null) sp.shading.Put(PdfName.DOMAIN, new PdfArray(domain)); if (tMatrix != null) sp.shading.Put(PdfName.MATRIX, new PdfArray(tMatrix)); sp.shading.Put(PdfName.FUNCTION, function.Reference); return sp; }
public static PdfFunction Type3(PdfWriter writer, float[] domain, float[] range, PdfFunction[] functions, float[] bounds, float[] encode) { PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfDictionary(); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(3)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); if (range != null) func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); PdfArray array = new PdfArray(); for (int k = 0; k < functions.Length; ++k) array.Add(functions[k].Reference); func.dictionary.Put(PdfName.FUNCTIONS, array); func.dictionary.Put(PdfName.BOUNDS, new PdfArray(bounds)); func.dictionary.Put(PdfName.ENCODE, new PdfArray(encode)); return func; }
public static PdfShading Type3(PdfWriter writer, BaseColor colorSpace, float[] coords, float[] domain, PdfFunction function, bool[] extend) { PdfShading sp = Type2(writer, colorSpace, coords, domain, function, extend); sp.shadingType = 3; sp.shading.Put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); return(sp); }
public static PdfShading Type2(PdfWriter writer, BaseColor colorSpace, float[] coords, float[] domain, PdfFunction function, bool[] extend) { PdfShading sp = new PdfShading(writer); sp.Shading = new PdfDictionary(); sp.ShadingType = 2; sp.Shading.Put(PdfName.Shadingtype, new PdfNumber(sp.ShadingType)); sp.SetColorSpace(colorSpace); sp.Shading.Put(PdfName.Coords, new PdfArray(coords)); if (domain != null) { sp.Shading.Put(PdfName.Domain, new PdfArray(domain)); } sp.Shading.Put(PdfName.Function, function.Reference); if (extend != null && (extend[0] || extend[1])) { PdfArray array = new PdfArray(extend[0] ? PdfBoolean.Pdftrue : PdfBoolean.Pdffalse); array.Add(extend[1] ? PdfBoolean.Pdftrue : PdfBoolean.Pdffalse); sp.Shading.Put(PdfName.Extend, array); } return(sp); }
public static PdfShading Type1(PdfWriter writer, BaseColor colorSpace, float[] domain, float[] tMatrix, PdfFunction function) { PdfShading sp = new PdfShading(writer); sp.shading = new PdfDictionary(); sp.shadingType = 1; sp.shading.Put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); sp.SetColorSpace(colorSpace); if (domain != null) { sp.shading.Put(PdfName.DOMAIN, new PdfArray(domain)); } if (tMatrix != null) { sp.shading.Put(PdfName.MATRIX, new PdfArray(tMatrix)); } sp.shading.Put(PdfName.FUNCTION, function.Reference); return(sp); }
public static PdfFunction Type4(PdfWriter writer, float[] domain, float[] range, string postscript) { byte[] b = new byte[postscript.Length]; for (int k = 0; k < b.Length; ++k) b[k] = (byte)postscript[k]; PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfStream(b); ((PdfStream)func.dictionary).FlateCompress(writer.CompressionLevel); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(4)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); return func; }
public static PdfFunction Type2(PdfWriter writer, float[] domain, float[] range, float[] c0, float[] c1, float n) { PdfFunction func = new PdfFunction(writer); func.dictionary = new PdfDictionary(); func.dictionary.Put(PdfName.FUNCTIONTYPE, new PdfNumber(2)); func.dictionary.Put(PdfName.DOMAIN, new PdfArray(domain)); if (range != null) func.dictionary.Put(PdfName.RANGE, new PdfArray(range)); if (c0 != null) func.dictionary.Put(PdfName.C0, new PdfArray(c0)); if (c1 != null) func.dictionary.Put(PdfName.C1, new PdfArray(c1)); func.dictionary.Put(PdfName.N, new PdfNumber(n)); return func; }