1 50 51 package com.lowagie.text.pdf; 52 53 import java.awt.Color ; 54 55 60 61 public class PdfSpotColor{ 62 63 64 protected float tint; 65 66 67 public PdfName name; 68 69 70 public Color altcs; 71 73 80 81 public PdfSpotColor(String name, float tint, Color altcs) { 82 this.name = new PdfName(name); 83 this.tint = tint; 84 this.altcs = altcs; 85 } 86 87 91 public float getTint() { 92 return tint; 93 } 94 95 99 public Color getAlternativeCS() { 100 return altcs; 101 } 102 103 protected PdfObject getSpotObject(PdfWriter writer) { 104 PdfArray array = new PdfArray(PdfName.SEPARATION); 105 array.add(name); 106 PdfFunction func = null; 107 if (altcs instanceof ExtendedColor) { 108 int type = ((ExtendedColor)altcs).type; 109 switch (type) { 110 case ExtendedColor.TYPE_GRAY: 111 array.add(PdfName.DEVICEGRAY); 112 func = PdfFunction.type2(writer, new float[]{0, 1}, null, new float[]{0}, new float[]{((GrayColor)altcs).getGray()}, 1); 113 break; 114 case ExtendedColor.TYPE_CMYK: 115 array.add(PdfName.DEVICECMYK); 116 CMYKColor cmyk = (CMYKColor)altcs; 117 func = PdfFunction.type2(writer, new float[]{0, 1}, null, new float[]{0, 0, 0, 0}, 118 new float[]{cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()}, 1); 119 break; 120 default: 121 throw new RuntimeException ("Only RGB, Gray and CMYK are supported as alternative color spaces."); 122 } 123 } 124 else { 125 array.add(PdfName.DEVICERGB); 126 func = PdfFunction.type2(writer, new float[]{0, 1}, null, new float[]{1, 1, 1}, 127 new float[]{(float)altcs.getRed() / 255, (float)altcs.getGreen() / 255, (float)altcs.getBlue() / 255}, 1); 128 } 129 array.add(func.getReference()); 130 return array; 131 } 132 } 133 | Popular Tags |