use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class SetStrokingDeviceCMYKColor method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
PDColorSpace cs = context.getResources().getColorSpace(COSName.DEVICECMYK);
context.getGraphicsState().setStrokingColorSpace(cs);
super.process(operator, arguments);
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class SetStrokingDeviceGrayColor method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
PDColorSpace cs = context.getResources().getColorSpace(COSName.DEVICEGRAY);
context.getGraphicsState().setStrokingColorSpace(cs);
super.process(operator, arguments);
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class PageDrawer method applySoftMaskToPaint.
// TODO: move soft mask apply to getPaint()?
private Paint applySoftMaskToPaint(Paint parentPaint, PDSoftMask softMask) throws IOException {
if (softMask == null || softMask.getGroup() == null) {
return parentPaint;
}
PDColor backdropColor = null;
if (COSName.LUMINOSITY.equals(softMask.getSubType())) {
COSArray backdropColorArray = softMask.getBackdropColor();
PDColorSpace colorSpace = softMask.getGroup().getGroup().getColorSpace();
if (colorSpace != null && backdropColorArray != null) {
backdropColor = new PDColor(backdropColorArray, colorSpace);
}
}
TransparencyGroup transparencyGroup = new TransparencyGroup(softMask.getGroup(), true, softMask.getInitialTransformationMatrix(), backdropColor);
BufferedImage image = transparencyGroup.getImage();
if (image == null) {
// sample file: PDFJS-6967_reduced_outside_softmask.pdf
return parentPaint;
}
BufferedImage gray = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
if (COSName.ALPHA.equals(softMask.getSubType())) {
gray.setData(image.getAlphaRaster());
} else if (COSName.LUMINOSITY.equals(softMask.getSubType())) {
Graphics g = gray.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
} else {
throw new IOException("Invalid soft mask subtype.");
}
gray = getRotatedImage(gray);
Rectangle2D tpgBounds = transparencyGroup.getBounds();
adjustRectangle(tpgBounds);
return new SoftMask(parentPaint, gray, tpgBounds, backdropColor, softMask.getTransferFunction());
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class PageDrawer method intersectShadingBBox.
// checks whether this is a shading pattern and if yes,
// get the transformed BBox and intersect with current paint area
// need to do it here and not in shading getRaster() because it may have been rotated
private void intersectShadingBBox(PDColor color, Area area) throws IOException {
if (color.getColorSpace() instanceof PDPattern) {
PDColorSpace colorSpace = color.getColorSpace();
PDAbstractPattern pat = ((PDPattern) colorSpace).getPattern(color);
if (pat instanceof PDShadingPattern) {
PDShading shading = ((PDShadingPattern) pat).getShading();
PDRectangle bbox = shading.getBBox();
if (bbox != null) {
Matrix m = Matrix.concatenate(getInitialMatrix(), pat.getMatrix());
Area bboxArea = new Area(bbox.transform(m));
area.intersect(bboxArea);
}
}
}
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class PageDrawer method getPaint.
/**
* Returns an AWT paint for the given PDColor.
*
* @param color The color to get a paint for. This can be an actual color or a pattern.
* @throws IOException
*/
protected Paint getPaint(PDColor color) throws IOException {
PDColorSpace colorSpace = color.getColorSpace();
if (!(colorSpace instanceof PDPattern)) {
float[] rgb = colorSpace.toRGB(color.getComponents());
return new Color(clampColor(rgb[0]), clampColor(rgb[1]), clampColor(rgb[2]));
} else {
PDPattern patternSpace = (PDPattern) colorSpace;
PDAbstractPattern pattern = patternSpace.getPattern(color);
if (pattern instanceof PDTilingPattern) {
PDTilingPattern tilingPattern = (PDTilingPattern) pattern;
if (tilingPattern.getPaintType() == PDTilingPattern.PAINT_COLORED) {
// colored tiling pattern
return tilingPaintFactory.create(tilingPattern, null, null, xform);
} else {
// uncolored tiling pattern
return tilingPaintFactory.create(tilingPattern, patternSpace.getUnderlyingColorSpace(), color, xform);
}
} else {
PDShadingPattern shadingPattern = (PDShadingPattern) pattern;
PDShading shading = shadingPattern.getShading();
if (shading == null) {
LOG.error("shadingPattern is null, will be filled with transparency");
return new Color(0, 0, 0, 0);
}
return shading.toPaint(Matrix.concatenate(getInitialMatrix(), shadingPattern.getMatrix()));
}
}
}
Aggregations