use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class PDStandardAttributeObject method getNumberOrArrayOfNumber.
/**
* Gets a number or an array of numbers.
*
* @param name the attribute name
* @param defaultValue the default value
* @return a Float or an array of floats
*/
protected Object getNumberOrArrayOfNumber(String name, float defaultValue) {
COSBase v = this.getCOSObject().getDictionaryObject(name);
if (v instanceof COSArray) {
COSArray array = (COSArray) v;
float[] values = new float[array.size()];
for (int i = 0; i < array.size(); i++) {
COSBase item = array.getObject(i);
if (item instanceof COSNumber) {
values[i] = ((COSNumber) item).floatValue();
}
}
return values;
}
if (v instanceof COSNumber) {
return ((COSNumber) v).floatValue();
}
if (Float.compare(defaultValue, UNSPECIFIED) == 0) {
return null;
}
return defaultValue;
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class PDFont method getAverageFontWidth.
/**
* This will get the average font width for all characters.
*
* @return The width is in 1000 unit of text space, ie 333 or 777
*/
// todo: this method is highly suspicious, the average glyph width is not usually a good metric
@Override
public float getAverageFontWidth() {
float average;
if (Float.compare(avgFontWidth, 0.0f) != 0) {
average = avgFontWidth;
} else {
float totalWidth = 0.0f;
float characterCount = 0.0f;
COSArray widths = (COSArray) dict.getDictionaryObject(COSName.WIDTHS);
if (widths != null) {
for (int i = 0; i < widths.size(); i++) {
COSNumber fontWidth = (COSNumber) widths.getObject(i);
if (fontWidth.floatValue() > 0) {
totalWidth += fontWidth.floatValue();
characterCount += 1;
}
}
}
if (totalWidth > 0) {
average = totalWidth / characterCount;
} else {
average = 0;
}
avgFontWidth = average;
}
return average;
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class FDFField method getSetWidgetFieldFlags.
/**
* This will get the SetF entry of the cos dictionary. If it it not present then this method will return null.
*
* @return The field flags.
*/
public Integer getSetWidgetFieldFlags() {
Integer retval = null;
COSNumber ff = (COSNumber) field.getDictionaryObject(COSName.SET_F);
if (ff != null) {
retval = ff.intValue();
}
return retval;
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class FDFField method getWidgetFieldFlags.
/**
* This will get the F entry of the cos dictionary. If it it not present then this method will return null.
*
* @return The widget field flags.
*/
public Integer getWidgetFieldFlags() {
Integer retval = null;
COSNumber f = (COSNumber) field.getDictionaryObject("F");
if (f != null) {
retval = f.intValue();
}
return retval;
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class DictionaryEncoding method applyDifferences.
private void applyDifferences() {
// now replace with the differences
COSBase base = encoding.getDictionaryObject(COSName.DIFFERENCES);
if (!(base instanceof COSArray)) {
return;
}
COSArray diffArray = (COSArray) base;
int currentIndex = -1;
for (int i = 0; i < diffArray.size(); i++) {
COSBase next = diffArray.getObject(i);
if (next instanceof COSNumber) {
currentIndex = ((COSNumber) next).intValue();
} else if (next instanceof COSName) {
COSName name = (COSName) next;
overwrite(currentIndex, name.getName());
this.differences.put(currentIndex, name.getName());
currentIndex++;
}
}
}
Aggregations