Java Code Examples for org.apache.pdfbox.cos.COSArray#toFloatArray()

The following examples show how to use org.apache.pdfbox.cos.COSArray#toFloatArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShadingContext.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param shading the shading type to be used
 * @param cm the color model to be used
 * @param xform transformation for user to device space
 * @param matrix the pattern matrix concatenated with that of the parent content stream
 * @throws java.io.IOException if there is an error getting the color space
 * or doing background color conversion.
 */
public ShadingContext(PDShading shading, ColorModel cm, AffineTransform xform,
                      Matrix matrix) throws IOException
{
    this.shading = shading;
    shadingColorSpace = shading.getColorSpace();

    // create the output color model using RGB+alpha as color space
    ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    outputColorModel = new ComponentColorModel(outputCS, true, false, Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);

    // get background values if available
    COSArray bg = shading.getBackground();
    if (bg != null)
    {
        background = bg.toFloatArray();
        rgbBackground = convertToRGB(background);
    }
}
 
Example 2
Source File: PDFunction.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Clip the given input values to the ranges.
 * 
 * @param inputValues the input values
 * @return the clipped values
 */
protected float[] clipToRange(float[] inputValues) 
{
    COSArray rangesArray = getRangeValues();
    float[] result;
    if (rangesArray != null) 
    {
        float[] rangeValues = rangesArray.toFloatArray();
        int numberOfRanges = rangeValues.length/2;
        result = new float[numberOfRanges];
        for (int i=0; i<numberOfRanges; i++)
        {
            int index = i << 1;
            result[i] = clipToRange(inputValues[i], rangeValues[index], rangeValues[index + 1]);
        }
    }
    else
    {
        result = inputValues;
    }
    return result;
}
 
Example 3
Source File: PDCalRGB.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Returns the linear interpretation matrix, which is an array of nine numbers.
 * If the underlying dictionary contains null then the identity matrix will be returned.
 * @return the linear interpretation matrix
 */
public final float[] getMatrix()
{
    COSArray matrix = (COSArray)dictionary.getDictionaryObject(COSName.MATRIX);
    if (matrix == null)
    {
        return new float[] {  1, 0, 0, 0, 1, 0, 0, 0, 1 };
    }
    else
    {
       return matrix.toFloatArray();
    }
}
 
Example 4
Source File: FDFAnnotationLine.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will retrieve the start and end coordinates of the line (or leader line if LL entry is set).
 *
 * @return array of floats [x1, y1, x2, y2] line start and end points in default user space.
 */
public float[] getLine()
{
    COSArray array = (COSArray) annot.getDictionaryObject(COSName.L);
    if (array != null)
    {
        return array.toFloatArray();
    }
    else
    {
        return null; // Should never happen as this is a required item
    }
}
 
Example 5
Source File: FDFAnnotationLine.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will retrieve the horizontal offset of the caption.
 * 
 * @return the horizontal offset of the caption
 */
public float getCaptionHorizontalOffset()
{
    float retval = 0.f;
    COSArray array = (COSArray) annot.getDictionaryObject(COSName.CO);
    if (array != null)
    {
        retval = array.toFloatArray()[0];
    }

    return retval;
}
 
Example 6
Source File: FDFAnnotationLine.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will retrieve the vertical offset of the caption.
 * 
 * @return the vertical offset of the caption
 */
public float getCaptionVerticalOffset()
{
    float retval = 0.f;
    COSArray array = (COSArray) annot.getDictionaryObject(COSName.CO);
    if (array != null)
    {
        retval = array.toFloatArray()[1];
    }
    return retval;
}
 
Example 7
Source File: FDFAnnotationPolygon.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will get the coordinates of the vertices.
 *
 * @return array of floats [x1, y1, x2, y2, ...] vertex coordinates in default user space.
 */
public float[] getVertices()
{
    COSArray array = (COSArray) annot.getDictionaryObject(COSName.VERTICES);
    if (array != null)
    {
        return array.toFloatArray();
    }
    else
    {
        return null; // Should never happen as this is a required item
    }
}
 
Example 8
Source File: FDFAnnotationPolyline.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will get the coordinates of the vertices.
 *
 * @return array of floats [x1, y1, x2, y2, ...] vertex coordinates in default user space.
 */
public float[] getVertices()
{
    COSArray array = (COSArray) annot.getDictionaryObject(COSName.VERTICES);
    if (array != null)
    {
        return array.toFloatArray();
    }
    else
    {
        return null; // Should never happen as this is a required item
    }
}
 
Example 9
Source File: FDFAnnotationFreeText.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will get the coordinates of the callout line.
 *
 * @return An array of four or six numbers specifying a callout line attached to the free text
 * annotation. Six numbers [ x1 y1 x2 y2 x3 y3 ] represent the starting, knee point, and ending
 * coordinates of the line in default user space, Four numbers [ x1 y1 x2 y2 ] represent the
 * starting and ending coordinates of the line.
 */
public float[] getCallout()
{
    COSArray array = (COSArray) annot.getDictionaryObject(COSName.CL);
    if (array != null)
    {
        return array.toFloatArray();
    }
    else
    {
        return null;
    }
}
 
Example 10
Source File: PDAnnotationLine.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will retrieve the horizontal offset of the caption.
 * 
 * @return the horizontal offset of the caption
 */
public float getCaptionHorizontalOffset()
{
    float retval = 0.f;
    COSArray array = (COSArray) this.getCOSObject().getDictionaryObject(COSName.CO);
    if (array != null)
    {
        retval = array.toFloatArray()[0];
    }

    return retval;
}
 
Example 11
Source File: PDAnnotationLine.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will retrieve the vertical offset of the caption.
 * 
 * @return the vertical offset of the caption
 */
public float getCaptionVerticalOffset()
{
    float retval = 0.f;
    COSArray array = (COSArray) this.getCOSObject().getDictionaryObject(COSName.CO);
    if (array != null)
    {
        retval = array.toFloatArray()[1];
    }
    return retval;
}
 
Example 12
Source File: PDRectlinearMeasureDictionary.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will return the origin of the coordinate system.
 * 
 * @return the origin
 */
public float[] getCoordSystemOrigin()
{
    COSArray o = (COSArray)this.getCOSObject().getDictionaryObject("O");
    if (o != null)
    {
        return o.toFloatArray();
    }
    return null;
}
 
Example 13
Source File: PDLineDashPattern.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a new line dash pattern from a dash array and phase.
 * @param array the dash array
 * @param phase the phase
 */
public PDLineDashPattern(COSArray array, int phase)
{
    this.array = array.toFloatArray();
    this.phase = phase;
}
 
Example 14
Source File: SampledImageReader.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private static float[] getDecodeArray(PDImage pdImage) throws IOException
{
    final COSArray cosDecode = pdImage.getDecode();
    float[] decode = null;

    if (cosDecode != null)
    {
        int numberOfComponents = pdImage.getColorSpace().getNumberOfComponents();
        if (cosDecode.size() != numberOfComponents * 2)
        {
            if (pdImage.isStencil() && cosDecode.size() >= 2
                    && cosDecode.get(0) instanceof COSNumber
                    && cosDecode.get(1) instanceof COSNumber)
            {
                float decode0 = ((COSNumber) cosDecode.get(0)).floatValue();
                float decode1 = ((COSNumber) cosDecode.get(1)).floatValue();
                if (decode0 >= 0 && decode0 <= 1 && decode1 >= 0 && decode1 <= 1)
                {
                    LOG.warn("decode array " + cosDecode
                            + " not compatible with color space, using the first two entries");
                    return new float[]
                    {
                        decode0, decode1
                    };
                }
            }
            LOG.error("decode array " + cosDecode
                    + " not compatible with color space, using default");
        }
        else
        {
            decode = cosDecode.toFloatArray();
        }
    }

    // use color space default
    if (decode == null)
    {
        return pdImage.getColorSpace().getDefaultDecode(pdImage.getBitsPerComponent());
    }

    return decode;
}
 
Example 15
Source File: PDAnnotationLine.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * This will retrieve the start and end coordinates of the line (or leader line if LL entry is set).
 *
 * @return array of floats [x1, y1, x2, y2] line start and end points in default user space.
 */
public float[] getLine()
{
    COSArray l = (COSArray) getCOSObject().getDictionaryObject(COSName.L);
    return l.toFloatArray();
}