| Method from com.lowagie.text.pdf.PdfShading Detail: |
void addToBody() throws IOException {
if (bBox != null)
shading.put(PdfName.BBOX, new PdfArray(bBox));
if (antiAlias)
shading.put(PdfName.ANTIALIAS, PdfBoolean.PDFTRUE);
writer.addToBody(shading, getShadingReference());
}
|
public static void checkCompatibleColors(Color c1,
Color c2) {
int type1 = ExtendedColor.getType(c1);
int type2 = ExtendedColor.getType(c2);
if (type1 != type2)
throw new IllegalArgumentException("Both colors must be of the same type.");
if (type1 == ExtendedColor.TYPE_SEPARATION && ((SpotColor)c1).getPdfSpotColor() != ((SpotColor)c2).getPdfSpotColor())
throw new IllegalArgumentException("The spot color must be the same, only the tint can vary.");
if (type1 == ExtendedColor.TYPE_PATTERN || type1 == ExtendedColor.TYPE_SHADING)
throwColorSpaceError();
}
|
public float[] getBBox() {
return bBox;
}
|
public static float[] getColorArray(Color color) {
int type = ExtendedColor.getType(color);
switch (type) {
case ExtendedColor.TYPE_GRAY: {
return new float[]{((GrayColor)color).getGray()};
}
case ExtendedColor.TYPE_CMYK: {
CMYKColor cmyk = (CMYKColor)color;
return new float[]{cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()};
}
case ExtendedColor.TYPE_SEPARATION: {
return new float[]{((SpotColor)color).getTint()};
}
case ExtendedColor.TYPE_RGB: {
return new float[]{color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f};
}
}
throwColorSpaceError();
return null;
}
|
ColorDetails getColorDetails() {
return colorDetails;
}
|
public Color getColorSpace() {
return cspace;
}
|
PdfName getShadingName() {
return shadingName;
}
|
PdfIndirectReference getShadingReference() {
if (shadingReference == null)
shadingReference = writer.getPdfIndirectReference();
return shadingReference;
}
|
PdfWriter getWriter() {
return writer;
}
|
public boolean isAntiAlias() {
return antiAlias;
}
|
public void setAntiAlias(boolean antiAlias) {
this.antiAlias = antiAlias;
}
|
public void setBBox(float[] bBox) {
if (bBox.length != 4)
throw new IllegalArgumentException("BBox must be a 4 element array.");
this.bBox = bBox;
}
|
protected void setColorSpace(Color color) {
cspace = color;
int type = ExtendedColor.getType(color);
PdfObject colorSpace = null;
switch (type) {
case ExtendedColor.TYPE_GRAY: {
colorSpace = PdfName.DEVICEGRAY;
break;
}
case ExtendedColor.TYPE_CMYK: {
colorSpace = PdfName.DEVICECMYK;
break;
}
case ExtendedColor.TYPE_SEPARATION: {
SpotColor spot = (SpotColor)color;
colorDetails = writer.addSimple(spot.getPdfSpotColor());
colorSpace = colorDetails.getIndirectReference();
break;
}
case ExtendedColor.TYPE_PATTERN:
case ExtendedColor.TYPE_SHADING: {
throwColorSpaceError();
}
default:
colorSpace = PdfName.DEVICERGB;
break;
}
shading.put(PdfName.COLORSPACE, colorSpace);
}
|
void setName(int number) {
shadingName = new PdfName("Sh" + number);
}
|
public static PdfShading simpleAxial(PdfWriter writer,
float x0,
float y0,
float x1,
float y1,
Color startColor,
Color endColor) {
return simpleAxial(writer, x0, y0, x1, y1, startColor, endColor, true, true);
}
|
public static PdfShading simpleAxial(PdfWriter writer,
float x0,
float y0,
float x1,
float y1,
Color startColor,
Color endColor,
boolean extendStart,
boolean 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 boolean[]{extendStart, extendEnd});
}
|
public static PdfShading simpleRadial(PdfWriter writer,
float x0,
float y0,
float r0,
float x1,
float y1,
float r1,
Color startColor,
Color endColor) {
return simpleRadial(writer, x0, y0, r0, x1, y1, r1, startColor, endColor, true, true);
}
|
public static PdfShading simpleRadial(PdfWriter writer,
float x0,
float y0,
float r0,
float x1,
float y1,
float r1,
Color startColor,
Color endColor,
boolean extendStart,
boolean 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 boolean[]{extendStart, extendEnd});
}
|
public static void throwColorSpaceError() {
throw new IllegalArgumentException("A tiling or shading pattern cannot be used as a color space in a shading pattern");
}
|
public static PdfShading type1(PdfWriter writer,
Color 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.getReference());
return sp;
}
|
public static PdfShading type2(PdfWriter writer,
Color colorSpace,
float[] coords,
float[] domain,
PdfFunction function,
boolean[] 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.getReference());
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 type3(PdfWriter writer,
Color colorSpace,
float[] coords,
float[] domain,
PdfFunction function,
boolean[] extend) {
PdfShading sp = type2(writer, colorSpace, coords, domain, function, extend);
sp.shadingType = 3;
sp.shading.put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType));
return sp;
}
|