Search in sources :

Example 76 with PDRectangle

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

the class CloudyBorder method getRectDifference.

/**
 * Returns the updated <code>RD</code> entry for Square and Circle annotations.
 *
 * @return Annotation <code>RD</code> value.
 */
PDRectangle getRectDifference() {
    if (annotRect == null) {
        float d = (float) lineWidth / 2;
        return new PDRectangle(d, d, (float) lineWidth, (float) lineWidth);
    }
    PDRectangle re = (rectWithDiff != null) ? rectWithDiff : annotRect;
    float left = re.getLowerLeftX() - (float) bboxMinX;
    float bottom = re.getLowerLeftY() - (float) bboxMinY;
    float right = (float) bboxMaxX - re.getUpperRightX();
    float top = (float) bboxMaxY - re.getUpperRightY();
    return new PDRectangle(left, bottom, right - left, top - bottom);
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 77 with PDRectangle

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

the class PDFStreamEngine method processAnnotation.

/**
 * Process the given annotation with the specified appearance stream.
 *
 * @param annotation The annotation containing the appearance stream to process.
 * @param appearance The appearance stream to process.
 * @throws IOException If there is an error reading or parsing the appearance content stream.
 */
protected void processAnnotation(PDAnnotation annotation, PDAppearanceStream appearance) throws IOException {
    PDResources parent = pushResources(appearance);
    Deque<PDGraphicsState> savedStack = saveGraphicsStack();
    PDRectangle bbox = appearance.getBBox();
    PDRectangle rect = annotation.getRectangle();
    Matrix matrix = appearance.getMatrix();
    // zero-sized rectangles are not valid
    if (rect != null && rect.getWidth() > 0 && rect.getHeight() > 0 && bbox != null) {
        // transformed appearance box  fixme: may be an arbitrary shape
        RectF transformedBox = new RectF();
        bbox.transform(matrix).computeBounds(transformedBox, true);
        // compute a matrix which scales and translates the transformed appearance box to align
        // with the edges of the annotation's rectangle
        Matrix a = Matrix.getTranslateInstance(rect.getLowerLeftX(), rect.getLowerLeftY());
        a.concatenate(Matrix.getScaleInstance((float) (rect.getWidth() / transformedBox.width()), (float) (rect.getHeight() / transformedBox.height())));
        a.concatenate(Matrix.getTranslateInstance((float) -transformedBox.left, (float) -transformedBox.top));
        // Matrix shall be concatenated with A to form a matrix AA that maps from the appearance's
        // coordinate system to the annotation's rectangle in default user space
        // 
        // HOWEVER only the opposite order works for rotated pages with
        // filled fields / annotations that have a matrix in the appearance stream, see PDFBOX-3083
        Matrix aa = Matrix.concatenate(a, matrix);
        // make matrix AA the CTM
        getGraphicsState().setCurrentTransformationMatrix(aa);
        // clip to bounding box
        clipToRect(bbox);
        // needed for patterns in appearance streams, e.g. PDFBOX-2182
        initialMatrix = aa.clone();
        processStreamOperators(appearance);
    }
    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)

Example 78 with PDRectangle

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

the class PDType1FontEmbedder method buildFontDescriptor.

/**
 * Returns a PDFontDescriptor for the given PFB.
 */
static PDFontDescriptor buildFontDescriptor(Type1Font type1) {
    boolean isSymbolic = type1.getEncoding() instanceof com.tom_roush.fontbox.encoding.BuiltInEncoding;
    PDFontDescriptor fd = new PDFontDescriptor();
    fd.setFontName(type1.getName());
    fd.setFontFamily(type1.getFamilyName());
    fd.setNonSymbolic(!isSymbolic);
    fd.setSymbolic(isSymbolic);
    fd.setFontBoundingBox(new PDRectangle(type1.getFontBBox()));
    fd.setItalicAngle(type1.getItalicAngle());
    fd.setAscent(type1.getFontBBox().getUpperRightY());
    fd.setDescent(type1.getFontBBox().getLowerLeftY());
    fd.setCapHeight(type1.getBlueValues().get(2).floatValue());
    // for PDF/A
    fd.setStemV(0);
    return fd;
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 79 with PDRectangle

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

the class PDType1FontEmbedder method buildFontDescriptor.

/**
 * Returns a PDFontDescriptor for the given AFM. Used only for Standard 14 fonts.
 *
 * @param metrics AFM
 */
static PDFontDescriptor buildFontDescriptor(FontMetrics metrics) {
    boolean isSymbolic = metrics.getEncodingScheme().equals("FontSpecific");
    PDFontDescriptor fd = new PDFontDescriptor();
    fd.setFontName(metrics.getFontName());
    fd.setFontFamily(metrics.getFamilyName());
    fd.setNonSymbolic(!isSymbolic);
    fd.setSymbolic(isSymbolic);
    fd.setFontBoundingBox(new PDRectangle(metrics.getFontBBox()));
    fd.setItalicAngle(metrics.getItalicAngle());
    fd.setAscent(metrics.getAscender());
    fd.setDescent(metrics.getDescender());
    fd.setCapHeight(metrics.getCapHeight());
    fd.setXHeight(metrics.getXHeight());
    fd.setAverageWidth(metrics.getAverageCharacterWidth());
    fd.setCharacterSet(metrics.getCharacterSet());
    // for PDF/A
    fd.setStemV(0);
    return fd;
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 80 with PDRectangle

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

the class PDType3Font method getHeight.

@Override
public float getHeight(int code) throws IOException {
    PDFontDescriptor desc = getFontDescriptor();
    if (desc != null) {
        // the following values are all more or less accurate at least all are average
        // values. Maybe we'll find another way to get those value for every single glyph
        // in the future if needed
        PDRectangle bbox = desc.getFontBoundingBox();
        float retval = 0;
        if (bbox != null) {
            retval = bbox.getHeight() / 2;
        }
        if (retval == 0) {
            retval = desc.getCapHeight();
        }
        if (retval == 0) {
            retval = desc.getAscent();
        }
        if (retval == 0) {
            retval = desc.getXHeight();
            if (retval > 0) {
                retval -= desc.getDescent();
            }
        }
        return retval;
    }
    return 0;
}
Also used : 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