Search in sources :

Example 51 with COSNumber

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;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Example 52 with COSNumber

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()));
                }
            }
        }
    }
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) Vector(com.tom_roush.pdfbox.util.Vector)

Example 53 with COSNumber

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;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Example 54 with COSNumber

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;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Example 55 with COSNumber

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;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Aggregations

COSNumber (com.tom_roush.pdfbox.cos.COSNumber)55 COSBase (com.tom_roush.pdfbox.cos.COSBase)29 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)18 COSArray (com.tom_roush.pdfbox.cos.COSArray)17 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)10 PointF (android.graphics.PointF)6 IOException (java.io.IOException)6 COSName (com.tom_roush.pdfbox.cos.COSName)5 PDBorderStyleDictionary (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)5 COSObject (com.tom_roush.pdfbox.cos.COSObject)4 PDAnnotationMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup)4 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)3 PDFont (com.tom_roush.pdfbox.pdmodel.font.PDFont)3 ArrayList (java.util.ArrayList)3 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)2 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)2 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)2 COSStream (com.tom_roush.pdfbox.cos.COSStream)2 PDFStreamParser (com.tom_roush.pdfbox.pdfparser.PDFStreamParser)2 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)2