use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class PDCIDFont method readVerticalDisplacements.
private void readVerticalDisplacements() {
// default position vector and vertical displacement vector
COSBase dw2Base = dict.getDictionaryObject(COSName.DW2);
if (dw2Base instanceof COSArray) {
COSArray dw2Array = (COSArray) dw2Base;
COSBase base0 = dw2Array.getObject(0);
COSBase base1 = dw2Array.getObject(1);
if (base0 instanceof COSNumber && base1 instanceof COSNumber) {
dw2[0] = ((COSNumber) base0).floatValue();
dw2[1] = ((COSNumber) base1).floatValue();
}
}
// vertical metrics for individual CIDs.
COSBase w2Base = dict.getDictionaryObject(COSName.W2);
if (w2Base instanceof COSArray) {
COSArray w2Array = (COSArray) w2Base;
for (int i = 0; i < w2Array.size(); i++) {
COSNumber c = (COSNumber) w2Array.getObject(i);
COSBase next = w2Array.getObject(++i);
if (next instanceof COSArray) {
COSArray array = (COSArray) next;
for (int j = 0; j < array.size(); j++) {
int cid = c.intValue() + j / 3;
COSNumber w1y = (COSNumber) array.getObject(j);
COSNumber v1x = (COSNumber) array.getObject(++j);
COSNumber v1y = (COSNumber) array.getObject(++j);
verticalDisplacementY.put(cid, w1y.floatValue());
positionVectors.put(cid, new Vector(v1x.floatValue(), v1y.floatValue()));
}
} else {
int first = c.intValue();
int last = ((COSNumber) next).intValue();
COSNumber w1y = (COSNumber) w2Array.getObject(++i);
COSNumber v1x = (COSNumber) w2Array.getObject(++i);
COSNumber v1y = (COSNumber) w2Array.getObject(++i);
for (int cid = first; cid <= last; cid++) {
verticalDisplacementY.put(cid, w1y.floatValue());
positionVectors.put(cid, new Vector(v1x.floatValue(), v1y.floatValue()));
}
}
}
}
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class PDCIDFont method readWidths.
private void readWidths() {
widths = new HashMap<>();
COSBase wBase = dict.getDictionaryObject(COSName.W);
if (wBase instanceof COSArray) {
COSArray wArray = (COSArray) wBase;
int size = wArray.size();
int counter = 0;
while (counter < size) {
COSNumber firstCode = (COSNumber) wArray.getObject(counter++);
COSBase next = wArray.getObject(counter++);
if (next instanceof COSArray) {
COSArray array = (COSArray) next;
int startRange = firstCode.intValue();
int arraySize = array.size();
for (int i = 0; i < arraySize; i++) {
COSNumber width = (COSNumber) array.getObject(i);
widths.put(startRange + i, width.floatValue());
}
} else {
COSNumber secondCode = (COSNumber) next;
COSNumber rangeWidth = (COSNumber) wArray.getObject(counter++);
int startRange = firstCode.intValue();
int endRange = secondCode.intValue();
float width = rangeWidth.floatValue();
for (int i = startRange; i <= endRange; i++) {
widths.put(i, width);
}
}
}
}
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class PDDefaultAppearanceString method processSetFont.
/**
* Process the set font and font size operator.
*
* @param operands the font name and size
* @throws IOException in case there are missing operators or the font is not within the resources
*/
private void processSetFont(List<COSBase> operands) throws IOException {
if (operands.size() < 2) {
throw new IOException("Missing operands for set font operator " + Arrays.toString(operands.toArray()));
}
COSBase base0 = operands.get(0);
COSBase base1 = operands.get(1);
if (!(base0 instanceof COSName)) {
return;
}
if (!(base1 instanceof COSNumber)) {
return;
}
COSName fontName = (COSName) base0;
PDFont font = defaultResources.getFont(fontName);
float fontSize = ((COSNumber) base1).floatValue();
// todo: handle cases where font == null with special mapping logic (see PDFBOX-2661)
if (font == null) {
throw new IOException("Could not find font: /" + fontName.getName());
}
setFontName(fontName);
setFont(font);
setFontSize(fontSize);
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class COSArrayList method convertIntegerCOSArrayToList.
/**
* This will take an array of COSNumbers and return a COSArrayList of
* java.lang.Integer values.
*
* @param intArray The existing integer Array.
*
* @return A list that is part of the core Java collections.
*/
public static List<Integer> convertIntegerCOSArrayToList(COSArray intArray) {
List<Integer> retval = null;
if (intArray != null) {
List<Integer> numbers = new ArrayList<>();
for (int i = 0; i < intArray.size(); i++) {
COSNumber num;
if (intArray.get(i) instanceof COSObject) {
num = (COSNumber) ((COSObject) intArray.get(i)).getObject();
} else {
num = (COSNumber) intArray.get(i);
}
numbers.add(num.intValue());
}
retval = new COSArrayList<>(numbers, intArray);
}
return retval;
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class PDStructureElement method getAttributes.
/**
* Returns the attributes together with their revision numbers (A).
*
* @return the attributes as a list, never null.
*/
public Revisions<PDAttributeObject> getAttributes() {
Revisions<PDAttributeObject> attributes = new Revisions<>();
COSBase a = this.getCOSObject().getDictionaryObject(COSName.A);
if (a instanceof COSArray) {
COSArray aa = (COSArray) a;
Iterator<COSBase> it = aa.iterator();
PDAttributeObject ao = null;
while (it.hasNext()) {
COSBase item = it.next();
if (item instanceof COSDictionary) {
ao = PDAttributeObject.create((COSDictionary) item);
ao.setStructureElement(this);
attributes.addObject(ao, 0);
} else if (item instanceof COSInteger) {
attributes.setRevisionNumber(ao, ((COSNumber) item).intValue());
}
}
}
if (a instanceof COSDictionary) {
PDAttributeObject ao = PDAttributeObject.create((COSDictionary) a);
ao.setStructureElement(this);
attributes.addObject(ao, 0);
}
return attributes;
}
Aggregations