use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
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 (avgFontWidth != 0.0f) {
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 com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
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 com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class FDFField method getClearFieldFlags.
/**
* This will get the ClrFf entry of the cos dictionary. If it it not present then this method will return null.
*
* @return The field flags.
*/
public Integer getClearFieldFlags() {
Integer retval = null;
COSNumber ff = (COSNumber) field.getDictionaryObject(COSName.CLR_FF);
if (ff != null) {
retval = ff.intValue();
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class FDFField method getFieldFlags.
/**
* This will get the Ff entry of the cos dictionary. If it it not present then this method will return null.
*
* @return The field flags.
*/
public Integer getFieldFlags() {
Integer retval = null;
COSNumber ff = (COSNumber) field.getDictionaryObject(COSName.FF);
if (ff != null) {
retval = ff.intValue();
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
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;
}
Aggregations