Example usage for org.apache.pdfbox.cos COSArray toFloatArray

List of usage examples for org.apache.pdfbox.cos COSArray toFloatArray

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSArray toFloatArray.

Prototype

public float[] toFloatArray() 

Source Link

Document

This will take an COSArray of numbers and convert it to a float[].

Usage

From source file:org.apache.fop.render.pdf.pdfbox.FOPPDFMultiByteFont.java

License:Apache License

private void readFontBBox(COSBase b) throws IOException {
    if (b instanceof COSDictionary) {
        COSDictionary dict = (COSDictionary) b;
        for (Map.Entry<COSName, COSBase> n : dict.entrySet()) {
            readFontBBox(n.getValue());/*from   w ww.j av  a2  s.com*/
            if (n.getKey() == COSName.FONT_BBOX) {
                COSArray w = (COSArray) n.getValue();
                float[] bboxf = w.toFloatArray();
                int[] bbox = new int[bboxf.length];
                for (int i = 0; i < bbox.length; i++) {
                    bbox[i] = (int) bboxf[i];
                }
                setFontBBox(bbox);
            }
        }
    } else if (b instanceof COSObject) {
        COSObject o = (COSObject) b;
        readFontBBox(o.getObject());
    } else if (b instanceof COSArray) {
        COSArray o = (COSArray) b;
        for (int i = 0; i < o.size(); i++) {
            readFontBBox(o.get(i));
        }
    }
}

From source file:org.apache.fop.render.pdf.pdfbox.PSPDFGraphics2D.java

License:Apache License

private static Function getFunction(PDFunction f) throws IOException {
    if (f instanceof PDFunctionType3) {
        PDFunctionType3 sourceFT3 = (PDFunctionType3) f;
        float[] bounds = sourceFT3.getBounds().toFloatArray();
        COSArray sourceFunctions = sourceFT3.getFunctions();
        List<Function> targetFunctions = new ArrayList<Function>();
        for (int j = 0; j < sourceFunctions.size(); j++) {
            targetFunctions.add(getFunction(PDFunction.create(sourceFunctions.get(j))));
        }/*  w ww .  jav a 2  s  . c o  m*/
        return new Function(null, null, targetFunctions, toList(bounds), null);
    } else if (f instanceof PDFunctionType2) {
        PDFunctionType2 sourceFT2 = (PDFunctionType2) f;
        double interpolation = (double) sourceFT2.getN();
        float[] c0 = sourceFT2.getC0().toFloatArray();
        float[] c1 = sourceFT2.getC1().toFloatArray();
        return new Function(null, null, c0, c1, interpolation);
    } else if (f instanceof PDFunctionType0) {
        COSDictionary s = f.getCOSObject();
        assert s instanceof COSStream;
        COSStream stream = (COSStream) s;
        COSArray encode = (COSArray) s.getDictionaryObject(COSName.ENCODE);
        COSArray domain = (COSArray) s.getDictionaryObject(COSName.DOMAIN);
        COSArray range = (COSArray) s.getDictionaryObject(COSName.RANGE);
        int bits = ((COSInteger) s.getDictionaryObject(COSName.BITS_PER_SAMPLE)).intValue();
        COSArray size = (COSArray) s.getDictionaryObject(COSName.SIZE);
        byte[] x = IOUtils.toByteArray(stream.getUnfilteredStream());
        for (byte y : x) {
            if (y != 0) {
                return new Function(floatArrayToDoubleList(domain.toFloatArray()),
                        floatArrayToDoubleList(range.toFloatArray()),
                        floatArrayToDoubleList(encode.toFloatArray()), x, bits, toList(size));
            }
        }
        return null;
    }
    throw new IOException("Unsupported " + f.toString());
}