use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState in project PdfBox-Android by TomRoush.
the class PDTextAppearanceHandler method drawCircles.
private void drawCircles(PDAnnotationText annotation, final PDAppearanceContentStream contentStream) throws IOException {
PDRectangle bbox = adjustRectAndBBox(annotation, 20, 20);
// strategy used by Adobe:
// 1) add small circle in white using /ca /CA 0.6 and width 1
// 2) fill
// 3) add small circle in one direction
// 4) add large circle in other direction
// 5) stroke + fill
// with square width 20 small r = 6.36, large r = 9.756
float smallR = 6.36f;
float largeR = 9.756f;
contentStream.setMiterLimit(4);
contentStream.setLineJoinStyle(1);
contentStream.setLineCapStyle(0);
contentStream.saveGraphicsState();
contentStream.setLineWidth(1);
PDExtendedGraphicsState gs = new PDExtendedGraphicsState();
gs.setAlphaSourceFlag(false);
gs.setStrokingAlphaConstant(0.6f);
gs.setNonStrokingAlphaConstant(0.6f);
gs.setBlendMode(BlendMode.NORMAL);
contentStream.setGraphicsStateParameters(gs);
contentStream.setNonStrokingColor(1f);
drawCircle(contentStream, bbox.getWidth() / 2, bbox.getHeight() / 2, smallR);
contentStream.fill();
contentStream.restoreGraphicsState();
// value from Adobe
contentStream.setLineWidth(0.59f);
drawCircle(contentStream, bbox.getWidth() / 2, bbox.getHeight() / 2, smallR);
drawCircle2(contentStream, bbox.getWidth() / 2, bbox.getHeight() / 2, largeR);
contentStream.fillAndStroke();
}
use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState in project PdfBox-Android by TomRoush.
the class PDResources method getExtGState.
/**
* Returns the extended graphics state resource with the given name, or null if none exists.
*
* @param name Name of the graphics state resource.
*
* @return the extended graphics state resource with the given name.
*/
public PDExtendedGraphicsState getExtGState(COSName name) {
COSObject indirect = getIndirect(COSName.EXT_G_STATE, name);
if (cache != null && indirect != null) {
PDExtendedGraphicsState cached = cache.getExtGState(indirect);
if (cached != null) {
return cached;
}
}
// get the instance
PDExtendedGraphicsState extGState = null;
COSDictionary dict = (COSDictionary) get(COSName.EXT_G_STATE, name);
if (dict != null) {
extGState = new PDExtendedGraphicsState(dict);
}
if (cache != null) {
cache.put(indirect, extGState);
}
return extGState;
}
use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState in project PdfBox-Android by TomRoush.
the class PageDrawer method hasBlendMode.
private boolean hasBlendMode(PDTransparencyGroup group, Set<COSBase> groupsDone) {
if (groupsDone.contains(group.getCOSObject())) {
// The group was already processed. Avoid endless recursion.
return false;
}
groupsDone.add(group.getCOSObject());
PDResources resources = group.getResources();
if (resources == null) {
return false;
}
for (COSName name : resources.getExtGStateNames()) {
PDExtendedGraphicsState extGState = resources.getExtGState(name);
if (extGState == null) {
continue;
}
BlendMode blendMode = extGState.getBlendMode();
if (blendMode != BlendMode.NORMAL) {
return true;
}
}
// Recursively process nested transparency groups
for (COSName name : resources.getXObjectNames()) {
PDXObject xObject;
try {
xObject = resources.getXObject(name);
} catch (IOException ex) {
continue;
}
if (xObject instanceof PDTransparencyGroup && hasBlendMode((PDTransparencyGroup) xObject, groupsDone)) {
return true;
}
}
return false;
}
use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState in project PdfBox-Android by TomRoush.
the class PDFRenderer method hasBlendMode.
private boolean hasBlendMode(PDPage page) {
// check the current resources for blend modes
PDResources resources = page.getResources();
if (resources == null) {
return false;
}
for (COSName name : resources.getExtGStateNames()) {
PDExtendedGraphicsState extGState = resources.getExtGState(name);
if (extGState == null) {
// see PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf
continue;
}
BlendMode blendMode = extGState.getBlendMode();
if (blendMode != BlendMode.NORMAL) {
return true;
}
}
return false;
}
use of com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState in project PdfBox-Android by TomRoush.
the class SetGraphicsStateParameters method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.isEmpty()) {
throw new MissingOperandException(operator, arguments);
}
COSBase base0 = arguments.get(0);
if (!(base0 instanceof COSName)) {
return;
}
// set parameters from graphics state parameter dictionary
COSName graphicsName = (COSName) base0;
PDExtendedGraphicsState gs = context.getResources().getExtGState(graphicsName);
if (gs == null) {
Log.e("PdfBox-Android", "name for 'gs' operator not found in resources: /" + graphicsName.getName());
return;
}
gs.copyIntoGraphicsState(context.getGraphicsState());
}
Aggregations