Search in sources :

Example 41 with COSNumber

use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.

the class MoveTextSetLeading method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.size() < 2) {
        throw new MissingOperandException(operator, arguments);
    }
    // move text position and set leading
    COSBase base1 = arguments.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSNumber y = (COSNumber) base1;
    List<COSBase> args = new ArrayList<COSBase>();
    args.add(new COSFloat(-1 * y.floatValue()));
    context.processOperator(OperatorName.SET_TEXT_LEADING, args);
    context.processOperator(OperatorName.MOVE_TEXT, arguments);
}
Also used : MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) ArrayList(java.util.ArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 42 with COSNumber

use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.

the class SetCharSpacing method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.isEmpty()) {
        throw new MissingOperandException(operator, arguments);
    }
    // there are some documents which are incorrectly structured, and have
    // a wrong number of arguments to this, so we will assume the last argument
    // in the list
    Object charSpacing = arguments.get(arguments.size() - 1);
    if (charSpacing instanceof COSNumber) {
        COSNumber characterSpacing = (COSNumber) charSpacing;
        context.getGraphicsState().getTextState().setCharacterSpacing(characterSpacing.floatValue());
    }
}
Also used : MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Example 43 with COSNumber

use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.

the class PDCircleAppearanceHandler method getLineWidth.

/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationMarkup annotation = (PDAnnotationMarkup) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    }
    COSArray borderCharacteristics = annotation.getBorder();
    if (borderCharacteristics.size() >= 3) {
        COSBase base = borderCharacteristics.getObject(2);
        if (base instanceof COSNumber) {
            return ((COSNumber) base).floatValue();
        }
    }
    return 1;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotationMarkup(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDBorderStyleDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

Example 44 with COSNumber

use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.

the class PDFreeTextAppearanceHandler method extractFontDetails.

// TODO extractNonStrokingColor and extractFontDetails
// might somehow be replaced with PDDefaultAppearanceString, which is quite similar.
private void extractFontDetails(PDAnnotationMarkup annotation) {
    String defaultAppearance = annotation.getDefaultAppearance();
    if (defaultAppearance == null && document != null && document.getDocumentCatalog().getAcroForm() != null) {
        defaultAppearance = document.getDocumentCatalog().getAcroForm().getDefaultAppearance();
    }
    if (defaultAppearance == null) {
        return;
    }
    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 fontArguments = new COSArray();
        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.SET_FONT_AND_SIZE.equals(name)) {
                    fontArguments = arguments;
                }
                arguments = new COSArray();
            } else {
                arguments.add((COSBase) token);
            }
        }
        if (fontArguments.size() >= 2) {
            COSBase base = fontArguments.get(0);
            if (base instanceof COSName) {
                fontName = (COSName) base;
            }
            base = fontArguments.get(1);
            if (base instanceof COSNumber) {
                fontSize = ((COSNumber) base).floatValue();
            }
        }
    } catch (IOException ex) {
        Log.w("PdfBox-Android", "Problem parsing /DA, will use default 'Helv 10'", ex);
    }
}
Also used : Operator(com.tom_roush.pdfbox.contentstream.operator.Operator) PDFStreamParser(com.tom_roush.pdfbox.pdfparser.PDFStreamParser) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSName(com.tom_roush.pdfbox.cos.COSName) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSObject(com.tom_roush.pdfbox.cos.COSObject) IOException(java.io.IOException)

Example 45 with COSNumber

use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.

the class PDLinkAppearanceHandler method getLineWidth.

/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationLink annotation = (PDAnnotationLink) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    }
    COSArray borderCharacteristics = annotation.getBorder();
    if (borderCharacteristics.size() >= 3) {
        COSBase base = borderCharacteristics.getObject(2);
        if (base instanceof COSNumber) {
            return ((COSNumber) base).floatValue();
        }
    }
    return 1;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDBorderStyleDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

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