Search in sources :

Example 21 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class PDFStreamEngine method processStream.

/**
 * Process a content stream.
 *
 * @param contentStream the content stream
 * @throws IOException if there is an exception while processing the stream
 */
private void processStream(PDContentStream contentStream) throws IOException {
    PDResources parent = pushResources(contentStream);
    Deque<PDGraphicsState> savedStack = saveGraphicsStack();
    Matrix parentMatrix = initialMatrix;
    // transform the CTM using the stream's matrix
    getGraphicsState().getCurrentTransformationMatrix().concatenate(contentStream.getMatrix());
    // the stream's initial matrix includes the parent CTM, e.g. this allows a scaled form
    initialMatrix = getGraphicsState().getCurrentTransformationMatrix().clone();
    // clip to bounding box
    PDRectangle bbox = contentStream.getBBox();
    clipToRect(bbox);
    processStreamOperators(contentStream);
    initialMatrix = parentMatrix;
    restoreGraphicsStack(savedStack);
    popResources(parent);
}
Also used : Matrix(com.tom_roush.pdfbox.util.Matrix) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) PDGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDGraphicsState)

Example 22 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class PDFStreamEngine method processTilingPattern.

/**
 * Process the given tiling pattern. Allows the pattern matrix to be overridden for custom
 * rendering.
 *
 * @param tilingPattern the tiling pattern
 * @param color color to use, if this is an uncoloured pattern, otherwise null.
 * @param colorSpace color space to use, if this is an uncoloured pattern, otherwise null.
 * @param patternMatrix the pattern matrix, may be overridden for custom rendering.
 * @throws IOException if there is an error reading or parsing the tiling pattern content stream.
 */
protected final void processTilingPattern(PDTilingPattern tilingPattern, PDColor color, PDColorSpace colorSpace, Matrix patternMatrix) throws IOException {
    PDResources parent = pushResources(tilingPattern);
    Matrix parentMatrix = initialMatrix;
    initialMatrix = Matrix.concatenate(initialMatrix, patternMatrix);
    // save the original graphics state
    Deque<PDGraphicsState> savedStack = saveGraphicsStack();
    // save a clean state (new clipping path, line path, etc.)
    RectF bbox = new RectF();
    tilingPattern.getBBox().transform(patternMatrix).computeBounds(bbox, true);
    PDRectangle rect = new PDRectangle((float) bbox.left, (float) bbox.top, (float) bbox.width(), (float) bbox.height());
    graphicsStack.push(new PDGraphicsState(rect));
    // non-colored patterns have to be given a color
    if (colorSpace != null) {
        color = new PDColor(color.getComponents(), colorSpace);
        getGraphicsState().setNonStrokingColorSpace(colorSpace);
        getGraphicsState().setNonStrokingColor(color);
        getGraphicsState().setStrokingColorSpace(colorSpace);
        getGraphicsState().setStrokingColor(color);
    }
    // transform the CTM using the stream's matrix
    getGraphicsState().getCurrentTransformationMatrix().concatenate(patternMatrix);
    // clip to bounding box
    clipToRect(tilingPattern.getBBox());
    processStreamOperators(tilingPattern);
    initialMatrix = parentMatrix;
    restoreGraphicsStack(savedStack);
    popResources(parent);
}
Also used : RectF(android.graphics.RectF) Matrix(com.tom_roush.pdfbox.util.Matrix) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) PDGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDGraphicsState) PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Example 23 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class FDFAnnotationFreeText method initFringe.

private void initFringe(Element element) throws IOException {
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty()) {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4) {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) IOException(java.io.IOException)

Example 24 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class FDFAnnotationSquare method initFringe.

private void initFringe(Element element) throws IOException {
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty()) {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4) {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) IOException(java.io.IOException)

Example 25 with PDRectangle

use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.

the class PDTilingPattern method getBBox.

/**
 * An array of four numbers in the form coordinate system (see
 * below), giving the coordinates of the left, bottom, right, and top edges,
 * respectively, of the pattern's bounding box.
 *
 * @return The BBox of the pattern.
 */
@Override
public PDRectangle getBBox() {
    PDRectangle retval = null;
    COSBase base = getCOSObject().getDictionaryObject(COSName.BBOX);
    if (base instanceof COSArray) {
        retval = new PDRectangle((COSArray) base);
    }
    return retval;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Aggregations

PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)82 IOException (java.io.IOException)19 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)13 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)12 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)11 Matrix (com.tom_roush.pdfbox.util.Matrix)11 COSArray (com.tom_roush.pdfbox.cos.COSArray)10 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)10 PDAppearanceStream (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream)9 Path (android.graphics.Path)8 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)6 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)5 PDPageContentStream (com.tom_roush.pdfbox.pdmodel.PDPageContentStream)5 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)4 COSName (com.tom_roush.pdfbox.cos.COSName)4 PDExtendedGraphicsState (com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState)4 PDAnnotationTextMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup)4 PDAnnotationWidget (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget)4