Search in sources :

Example 81 with PDRectangle

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

the class PDType3Font method generateBoundingBox.

private BoundingBox generateBoundingBox() {
    PDRectangle rect = getFontBBox();
    if (rect.getLowerLeftX() == 0 && rect.getLowerLeftY() == 0 && rect.getUpperRightX() == 0 && rect.getUpperRightY() == 0) {
        // Plan B: get the max bounding box of the glyphs
        COSDictionary cp = getCharProcs();
        for (COSName name : cp.keySet()) {
            COSBase base = cp.getDictionaryObject(name);
            if (base instanceof COSStream) {
                PDType3CharProc charProc = new PDType3CharProc(this, (COSStream) base);
                try {
                    PDRectangle glyphBBox = charProc.getGlyphBBox();
                    if (glyphBBox == null) {
                        continue;
                    }
                    rect.setLowerLeftX(Math.min(rect.getLowerLeftX(), glyphBBox.getLowerLeftX()));
                    rect.setLowerLeftY(Math.min(rect.getLowerLeftY(), glyphBBox.getLowerLeftY()));
                    rect.setUpperRightX(Math.max(rect.getUpperRightX(), glyphBBox.getUpperRightX()));
                    rect.setUpperRightY(Math.max(rect.getUpperRightY(), glyphBBox.getUpperRightY()));
                } catch (IOException ex) {
                // ignore
                }
            }
        }
    }
    return new BoundingBox(rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY());
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSName(com.tom_roush.pdfbox.cos.COSName) BoundingBox(com.tom_roush.fontbox.util.BoundingBox) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) IOException(java.io.IOException)

Example 82 with PDRectangle

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

the class PDFontDescriptor method getFontBoundingBox.

/**
 * This will get the fonts bounding box.
 *
 * @return The fonts bounding box.
 */
public PDRectangle getFontBoundingBox() {
    COSArray rect = (COSArray) dic.getDictionaryObject(COSName.FONT_BBOX);
    PDRectangle retval = null;
    if (rect != null) {
        retval = new PDRectangle(rect);
    }
    return retval;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) 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