use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class COSParser method retrieveCOSDictionary.
private COSDictionary retrieveCOSDictionary(COSObjectKey key, long offset) throws IOException {
COSDictionary dictionary = null;
// handle compressed objects
if (offset < 0) {
COSObject compressedObject = document.getObjectFromPool(key);
if (compressedObject.getObject() == null) {
parseObjectStream((int) -offset);
}
COSBase baseObject = compressedObject.getObject();
if (baseObject instanceof COSDictionary) {
dictionary = (COSDictionary) baseObject;
}
} else {
source.seek(offset);
readObjectNumber();
readGenerationNumber();
readExpectedString(OBJ_MARKER, true);
if (source.peek() != '<') {
return null;
}
try {
dictionary = parseCOSDictionary();
} catch (IOException exception) {
Log.d("PdfBox-Android", "Skipped object " + key + ", either it's corrupt or not a dictionary");
}
}
return dictionary;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDAnnotationLine method setEndPointEndingStyle.
/**
* This will set the line ending style for the end point, see the LE_ constants for the possible values.
*
* @param style The new style.
*/
public void setEndPointEndingStyle(String style) {
if (style == null) {
style = LE_NONE;
}
COSBase base = getCOSObject().getDictionaryObject(COSName.LE);
COSArray array;
if (!(base instanceof COSArray) || ((COSArray) base).size() < 2) {
array = new COSArray();
array.add(COSName.getPDFName(LE_NONE));
array.add(COSName.getPDFName(style));
getCOSObject().setItem(COSName.LE, array);
} else {
array = (COSArray) base;
array.setName(1, style);
}
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDAnnotationMarkup method getInkList.
/**
* Get one or more disjoint paths that make this annotation.
*
* @return An array of arrays, each representing a stroked path. Each array shall be a series of
* alternating horizontal and vertical coordinates.
*/
public float[][] getInkList() {
COSBase base = getCOSObject().getDictionaryObject(COSName.INKLIST);
if (base instanceof COSArray) {
COSArray array = (COSArray) base;
float[][] inkList = new float[array.size()][];
for (int i = 0; i < array.size(); ++i) {
COSBase base2 = array.getObject(i);
if (base2 instanceof COSArray) {
inkList[i] = ((COSArray) array.getObject(i)).toFloatArray();
} else {
inkList[i] = new float[0];
}
}
return inkList;
}
return new float[0][0];
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDAnnotationMarkup method setStartPointEndingStyle.
/**
* This will set the line ending style for the start point, see the LE_ constants for the possible values.
*
* @param style The new style.
*/
public void setStartPointEndingStyle(String style) {
String actualStyle = style == null ? PDAnnotationLine.LE_NONE : style;
COSBase base = getCOSObject().getDictionaryObject(COSName.LE);
COSArray array;
if (!(base instanceof COSArray) || ((COSArray) base).size() == 0) {
array = new COSArray();
array.add(COSName.getPDFName(actualStyle));
array.add(COSName.getPDFName(PDAnnotationLine.LE_NONE));
getCOSObject().setItem(COSName.LE, array);
} else {
array = (COSArray) base;
array.setName(0, actualStyle);
}
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDFreeTextAppearanceHandler method extractNonStrokingColor.
// get the last non stroking color from the /DA entry
private PDColor extractNonStrokingColor(PDAnnotationMarkup annotation) {
// It could also work with a regular expression, but that should be written so that
// "/LucidaConsole 13.94766 Tf .392 .585 .93 rg" does not produce "2 .585 .93 rg" as result
// Another alternative might be to create a PDDocument and a PDPage with /DA content as /Content,
// process the whole thing and then get the non stroking color.
PDColor strokingColor = new PDColor(new float[] { 0 }, PDDeviceGray.INSTANCE);
String defaultAppearance = annotation.getDefaultAppearance();
if (defaultAppearance == null) {
return strokingColor;
}
try {
// not sure if charset is correct, but we only need numbers and simple characters
PDFStreamParser parser = new PDFStreamParser(defaultAppearance.getBytes(Charsets.US_ASCII));
COSArray arguments = new COSArray();
COSArray colors = null;
Operator graphicOp = null;
for (Object token = parser.parseNextToken(); token != null; token = parser.parseNextToken()) {
if (token instanceof COSObject) {
arguments.add(((COSObject) token).getObject());
} else if (token instanceof Operator) {
Operator op = (Operator) token;
String name = op.getName();
if (OperatorName.NON_STROKING_GRAY.equals(name) || OperatorName.NON_STROKING_RGB.equals(name) || OperatorName.NON_STROKING_CMYK.equals(name)) {
graphicOp = op;
colors = arguments;
}
arguments = new COSArray();
} else {
arguments.add((COSBase) token);
}
}
if (graphicOp != null) {
String graphicOpName = graphicOp.getName();
if (OperatorName.NON_STROKING_GRAY.equals(graphicOpName)) {
strokingColor = new PDColor(colors, PDDeviceGray.INSTANCE);
} else if (OperatorName.NON_STROKING_RGB.equals(graphicOpName)) {
strokingColor = new PDColor(colors, PDDeviceRGB.INSTANCE);
} else if (OperatorName.NON_STROKING_CMYK.equals(graphicOpName)) {
// strokingColor = new PDColor(colors, PDDeviceCMYK.INSTANCE); TODO: PdfBox-Android
}
}
} catch (IOException ex) {
Log.w("PdfBox-Android", "Problem parsing /DA, will use default black", ex);
}
return strokingColor;
}
Aggregations