org.apache.pdfbox.cos.COSNumber Java Examples

The following examples show how to use org.apache.pdfbox.cos.COSNumber. 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: SetFontAndSize.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException
{
    if (arguments.size() < 2)
    {
        throw new MissingOperandException(operator, arguments);
    }

    COSBase base0 = arguments.get(0);
    COSBase base1 = arguments.get(1);
    if (!(base0 instanceof COSName))
    {
        return;
    }
    if (!(base1 instanceof COSNumber))
    {
        return;
    }
    COSName fontName = (COSName) base0;
    float fontSize = ((COSNumber) base1).floatValue();
    context.getGraphicsState().getTextState().setFontSize(fontSize);
    PDFont font = context.getResources().getFont(fontName);
    context.getGraphicsState().getTextState().setFont(font);
}
 
Example #2
Source File: PDFVisibleTextStripper.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 6) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x1 = (COSNumber) operands.get(0);
    COSNumber y1 = (COSNumber) operands.get(1);
    COSNumber x2 = (COSNumber) operands.get(2);
    COSNumber y2 = (COSNumber) operands.get(3);
    COSNumber x3 = (COSNumber) operands.get(4);
    COSNumber y3 = (COSNumber) operands.get(5);

    Point2D.Float point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    linePath.curveTo(point1.x, point1.y, point2.x, point2.y, point3.x, point3.y);
}
 
Example #3
Source File: PdfToTextInfoConverter.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 2) {
        throw new MissingOperandException(operator, operands);
    }
    COSBase base0 = operands.get(0);
    if (!(base0 instanceof COSNumber)) {
        return;
    }
    COSBase base1 = operands.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;
    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
    linePath.moveTo(pos.x, pos.y);
}
 
Example #4
Source File: COSParser.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void readValidStream(OutputStream out, COSNumber streamLengthObj) throws IOException
{
    long remainBytes = streamLengthObj.longValue();
    while (remainBytes > 0)
    {
        final int chunk = (remainBytes > STREAMCOPYBUFLEN) ? STREAMCOPYBUFLEN : (int) remainBytes;
        final int readBytes = source.read(streamCopyBuf, 0, chunk);
        if (readBytes <= 0)
        {
            // shouldn't happen, the stream length has already been validated
            throw new IOException("read error at offset " + source.getPosition()
                    + ": expected " + chunk + " bytes, but read() returns " + readBytes);
        }
        out.write(streamCopyBuf, 0, readBytes);
        remainBytes -= readBytes;
    }
}
 
Example #5
Source File: PDFVisibleTextStripper.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 2) {
        throw new MissingOperandException(operator, operands);
    }
    COSBase base0 = operands.get(0);
    if (!(base0 instanceof COSNumber)) {
        return;
    }
    COSBase base1 = operands.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    // append straight line segment from the current point to the point
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;

    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());

    linePath.lineTo(pos.x, pos.y);
}
 
Example #6
Source File: PDCIDFont.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * This will get the default width. The default value for the default width is 1000.
 *
 * @return The default width for the glyphs in this font.
 */
private float getDefaultWidth()
{
    if (defaultWidth == 0)
    {
        COSBase base = dict.getDictionaryObject(COSName.DW);
        if (base instanceof COSNumber)
        {
            defaultWidth = ((COSNumber) base).floatValue();
        }
        else
        {
            defaultWidth = 1000;
        }
    }
    return defaultWidth;
}
 
Example #7
Source File: DictionaryEncoding.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void applyDifferences()
{
    // now replace with the differences
    COSBase base = encoding.getDictionaryObject(COSName.DIFFERENCES);
    if (!(base instanceof COSArray))
    {
        return;
    }
    COSArray diffArray = (COSArray) base;
    int currentIndex = -1;
    for (int i = 0; i < diffArray.size(); i++)
    {
        COSBase next = diffArray.getObject(i);
        if( next instanceof COSNumber)
        {
            currentIndex = ((COSNumber)next).intValue();
        }
        else if( next instanceof COSName )
        {
            COSName name = (COSName)next;
            overwrite(currentIndex, name.getName());
            this.differences.put(currentIndex, name.getName());
            currentIndex++;
        }
    }
}
 
Example #8
Source File: PDType3CharProc.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private float parseWidth(Operator operator, List<COSBase> arguments) throws IOException
{
    if (operator.getName().equals("d0") || operator.getName().equals("d1"))
    {
        COSBase obj = arguments.get(0);
        if (obj instanceof COSNumber)
        {
            return ((COSNumber) obj).floatValue();
        }
        throw new IOException("Unexpected argument type: " + obj.getClass().getName());
    }
    else
    {
        throw new IOException("First operator must be d0 or d1");
    }
}
 
Example #9
Source File: PDFVisibleTextStripper.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 2) {
        throw new MissingOperandException(operator, operands);
    }
    COSBase base0 = operands.get(0);
    if (!(base0 instanceof COSNumber)) {
        return;
    }
    COSBase base1 = operands.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;
    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
    linePath.moveTo(pos.x, pos.y);
}
 
Example #10
Source File: PDFVisibleTextStripper.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 4) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x1 = (COSNumber) operands.get(0);
    COSNumber y1 = (COSNumber) operands.get(1);
    COSNumber x3 = (COSNumber) operands.get(2);
    COSNumber y3 = (COSNumber) operands.get(3);

    Point2D.Float point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    linePath.curveTo(point1.x, point1.y, point3.x, point3.y, point3.x, point3.y);
}
 
Example #11
Source File: PdfToTextInfoConverter.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 4) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x1 = (COSNumber) operands.get(0);
    COSNumber y1 = (COSNumber) operands.get(1);
    COSNumber x3 = (COSNumber) operands.get(2);
    COSNumber y3 = (COSNumber) operands.get(3);

    Point2D.Float point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    linePath.curveTo(point1.x, point1.y, point3.x, point3.y, point3.x, point3.y);
}
 
Example #12
Source File: PDPageDestination.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Returns the page number for this destination, regardless of whether this is a page number or
 * a reference to a page.
 *
 * @since Apache PDFBox 1.0.0
 * @see org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem
 * @return page number, or -1 if the destination type is unknown. The page number is 0-based if
 * it was in the dictionary (for remote destinations), and 1-based if it was computed from a
 * page reference (for local destinations).
 * @deprecated This method has inconsistent behavior (see returns), use {@link #retrievePageNumber()} instead.
 */
@Deprecated
public int findPageNumber()
{
    int retval = -1;
    if( array.size() > 0 )
    {
        COSBase page = array.getObject( 0 );
        if( page instanceof COSNumber )
        {
            retval = ((COSNumber)page).intValue();
        }
        else if (page instanceof COSDictionary)
        {
            COSBase parent = page;
            while (((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P) != null)
            {
                parent = ((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P);
            }
            // now parent is the pages node
            PDPageTree pages = new PDPageTree((COSDictionary) parent);
            return pages.indexOf(new PDPage((COSDictionary) page)) + 1;
        }
    }
    return retval;
}
 
Example #13
Source File: CurveTo.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
/**
 * process : c : Append curved segment to path.
 * @param operator The operator that is being executed.
 * @param arguments List
 */
public void process(PDFOperator operator, List arguments) 
{
    PDFObjectExtractor drawer = (PDFObjectExtractor)context;
    
    COSNumber x1 = (COSNumber)arguments.get( 0 );
    COSNumber y1 = (COSNumber)arguments.get( 1 );
    COSNumber x2 = (COSNumber)arguments.get( 2 );
    COSNumber y2 = (COSNumber)arguments.get( 3 );
    COSNumber x3 = (COSNumber)arguments.get( 4 );
    COSNumber y3 = (COSNumber)arguments.get( 5 );
   /* float x1f = x1.floatValue();
    float y1f = (float)drawer.fixY( x1f, y1.floatValue() );
    float x2f = x2.floatValue();
    float y2f = (float)drawer.fixY( x2f, y2.floatValue() );
    float x3f = x3.floatValue();
    float y3f = (float)drawer.fixY( x3f, y3.floatValue() );
    drawer.getLinePath().curveTo(x1f,y1f,x2f,y2f,x3f,y3f);
    */
    Point2D P1 = drawer.TransformedPoint(x1.doubleValue(), y1.doubleValue());
    Point2D P2 = drawer.TransformedPoint(x2.doubleValue(), y2.doubleValue());
    Point2D P3 = drawer.TransformedPoint(x3.doubleValue(), y3.doubleValue());
    
    drawer.getLinePath().curveTo((float)P1.getX(), (float)P1.getY(), (float)P2.getX(), (float)P2.getY(), (float)P3.getX(), (float)P3.getY());
    drawer.simpleCurveTo((float)P1.getX(), (float)P1.getY(), (float)P2.getX(), (float)P2.getY(), (float)P3.getX(), (float)P3.getY());
}
 
Example #14
Source File: COSArrayList.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * This will take an array of COSNumbers and return a COSArrayList of
 * java.lang.Float values.
 *
 * @param floatArray The existing float Array.
 *
 * @return The list of Float objects.
 */
public static List<Float> convertFloatCOSArrayToList( COSArray floatArray )
{
    List<Float> retval = null;
    if( floatArray != null )
    {
        List<Float> numbers = new ArrayList<Float>(floatArray.size());
        for( int i=0; i<floatArray.size(); i++ )
        {
            COSBase base = floatArray.getObject(i);
            if (base instanceof COSNumber)
            {
                numbers.add(((COSNumber) base).floatValue());
            }
            else
            {
                numbers.add(null);
            }
        }
        retval = new COSArrayList<Float>( numbers, floatArray );
    }
    return retval;
}
 
Example #15
Source File: SetCharSpacing.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException
{
    if (arguments.isEmpty())
    {
        throw new MissingOperandException(operator, arguments);
    }

    // there are some documents which are incorrectly structured, and have
    // a wrong number of arguments to this, so we will assume the last argument
    // in the list
    Object charSpacing = arguments.get(arguments.size()-1);
    if (charSpacing instanceof COSNumber)
    {
        COSNumber characterSpacing = (COSNumber)charSpacing;
        context.getGraphicsState().getTextState().setCharacterSpacing(characterSpacing.floatValue());
    }
}
 
Example #16
Source File: PdfToTextInfoConverter.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 4) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x2 = (COSNumber) operands.get(0);
    COSNumber y2 = (COSNumber) operands.get(1);
    COSNumber x3 = (COSNumber) operands.get(2);
    COSNumber y3 = (COSNumber) operands.get(3);

    Point2D currentPoint = linePath.getCurrentPoint();

    Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    linePath.curveTo((float) currentPoint.getX(), (float) currentPoint.getY(), point2.x, point2.y, point3.x, point3.y);
}
 
Example #17
Source File: PdfToTextInfoConverter.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 2) {
        throw new MissingOperandException(operator, operands);
    }
    COSBase base0 = operands.get(0);
    if (!(base0 instanceof COSNumber)) {
        return;
    }
    COSBase base1 = operands.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    // append straight line segment from the current point to the point
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;

    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());

    linePath.lineTo(pos.x, pos.y);
}
 
Example #18
Source File: MoveTextSetLeading.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException
{
    if (arguments.size() < 2)
    {
        throw new MissingOperandException(operator, arguments);
    }
    
    //move text position and set leading
    COSBase base1 = arguments.get(1);
    if (!(base1 instanceof COSNumber))
    {
        return;
    }
    COSNumber y = (COSNumber) base1;
    
    List<COSBase> args = new ArrayList<COSBase>();
    args.add(new COSFloat(-1 * y.floatValue()));
    context.processOperator(OperatorName.SET_TEXT_LEADING, args);
    context.processOperator(OperatorName.MOVE_TEXT, arguments);
}
 
Example #19
Source File: Concatenate.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException
{
    if (arguments.size() < 6)
    {
        throw new MissingOperandException(operator, arguments);
    }
    if (!checkArrayTypesClass(arguments, COSNumber.class))
    {
        return;
    }
    
    // concatenate matrix to current transformation matrix
    COSNumber a = (COSNumber) arguments.get(0);
    COSNumber b = (COSNumber) arguments.get(1);
    COSNumber c = (COSNumber) arguments.get(2);
    COSNumber d = (COSNumber) arguments.get(3);
    COSNumber e = (COSNumber) arguments.get(4);
    COSNumber f = (COSNumber) arguments.get(5);

    Matrix matrix = new Matrix(a.floatValue(), b.floatValue(), c.floatValue(),
                               d.floatValue(), e.floatValue(), f.floatValue());

    context.getGraphicsState().getCurrentTransformationMatrix().concatenate(matrix);
}
 
Example #20
Source File: PDFVisibleTextStripper.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 4) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x2 = (COSNumber) operands.get(0);
    COSNumber y2 = (COSNumber) operands.get(1);
    COSNumber x3 = (COSNumber) operands.get(2);
    COSNumber y3 = (COSNumber) operands.get(3);

    Point2D currentPoint = linePath.getCurrentPoint();

    Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    linePath.curveTo((float) currentPoint.getX(), (float) currentPoint.getY(), point2.x, point2.y, point3.x, point3.y);
}
 
Example #21
Source File: CurveToReplicateFinalPoint.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException
{
    if (operands.size() < 4)
    {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class))
    {
        return;
    }
    COSNumber x1 = (COSNumber)operands.get(0);
    COSNumber y1 = (COSNumber)operands.get(1);
    COSNumber x3 = (COSNumber)operands.get(2);
    COSNumber y3 = (COSNumber)operands.get(3);

    Point2D.Float point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    context.curveTo(point1.x, point1.y,
                    point3.x, point3.y,
                    point3.x, point3.y);
}
 
Example #22
Source File: MoveTo.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException
{
    if (operands.size() < 2)
    {
        throw new MissingOperandException(operator, operands);
    }
    COSBase base0 = operands.get(0);
    if (!(base0 instanceof COSNumber))
    {
        return;
    }
    COSBase base1 = operands.get(1);
    if (!(base1 instanceof COSNumber))
    {
        return;
    }
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;
    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
    context.moveTo(pos.x, pos.y);
}
 
Example #23
Source File: Matrix.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Convenience method to be used when creating a matrix from unverified data. If the parameter
 * is a COSArray with at least six numbers, a Matrix object is created from the first six
 * numbers and returned. If not, then the identity Matrix is returned.
 *
 * @param base a COS object, preferably a COSArray with six numbers.
 *
 * @return a Matrix object.
 */
public static Matrix createMatrix(COSBase base)
{
    if (!(base instanceof COSArray))
    {
        return new Matrix();
    }
    COSArray array = (COSArray) base;
    if (array.size() < 6)
    {
        return new Matrix();
    }
    for (int i = 0; i < 6; ++i)
    {
        if (!(array.getObject(i) instanceof COSNumber))
        {
            return new Matrix();
        }
    }
    return new Matrix(array);
}
 
Example #24
Source File: PDPageDestination.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Returns the page number for this destination, regardless of whether this is a page number or
 * a reference to a page.
 *
 * @see org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem
 * @return the 0-based page number, or -1 if the destination type is unknown.
 */
public int retrievePageNumber()
{
    int retval = -1;
    if (array.size() > 0)
    {
        COSBase page = array.getObject(0);
        if (page instanceof COSNumber)
        {
            retval = ((COSNumber) page).intValue();
        }
        else if (page instanceof COSDictionary)
        {
            return indexOfPageTree((COSDictionary) page);
        }
    }
    return retval;
}
 
Example #25
Source File: AppendRectangleToPath.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException
{
    if (operands.size() < 4)
    {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class))
    {
        return;
    }
    COSNumber x = (COSNumber) operands.get(0);
    COSNumber y = (COSNumber) operands.get(1);
    COSNumber w = (COSNumber) operands.get(2);
    COSNumber h = (COSNumber) operands.get(3);

    float x1 = x.floatValue();
    float y1 = y.floatValue();

    // create a pair of coordinates for the transformation
    float x2 = w.floatValue() + x1;
    float y2 = h.floatValue() + y1;

    Point2D p0 = context.transformedPoint(x1, y1);
    Point2D p1 = context.transformedPoint(x2, y1);
    Point2D p2 = context.transformedPoint(x2, y2);
    Point2D p3 = context.transformedPoint(x1, y2);

    context.appendRectangle(p0, p1, p2, p3);
}
 
Example #26
Source File: LineTo.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException
{
    if (operands.size() < 2)
    {
        throw new MissingOperandException(operator, operands);
    }
    COSBase base0 = operands.get(0);
    if (!(base0 instanceof COSNumber))
    {
        return;
    }
    COSBase base1 = operands.get(1);
    if (!(base1 instanceof COSNumber))
    {
        return;
    }
    // append straight line segment from the current point to the point
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;

    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());

    if (context.getCurrentPoint() == null)
    {
        LOG.warn("LineTo (" + pos.x + "," + pos.y + ") without initial MoveTo");
        context.moveTo(pos.x, pos.y);
    }
    else
    {
        context.lineTo(pos.x, pos.y);
    }
}
 
Example #27
Source File: PDPageDestination.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will get the page number for this destination. A page destination can either reference a
 * page (for a local destination) or a page number (when doing a remote destination to another
 * PDF). If this object is referencing by page number then this method will return that number,
 * otherwise -1 will be returned.
 *
 * @return The zero-based page number for this destination.
 */
public int getPageNumber()
{
    int retval = -1;
    if( array.size() > 0 )
    {
        COSBase page = array.getObject( 0 );
        if( page instanceof COSNumber )
        {
            retval = ((COSNumber)page).intValue();
        }
    }
    return retval;
}
 
Example #28
Source File: SetStrokingRGBColor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/**
 * RG Set color space for stroking operations.
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws IOException If an error occurs while processing the font.
 */
public void process(PDFOperator operator, List arguments) throws IOException
{
    super.process( operator, arguments );
    PDFObjectExtractor drawer = (PDFObjectExtractor)context;
    COSNumber r = (COSNumber)arguments.get( 0 );
    COSNumber g = (COSNumber)arguments.get( 1 );
    COSNumber b = (COSNumber)arguments.get( 2 );
    drawer.setStrokingColor( new Color( r.floatValue(), g.floatValue(), b.floatValue() ) );
}
 
Example #29
Source File: CurveToReplicateInitialPoint.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException
{
    if (operands.size() < 4)
    {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class))
    {
        return;
    }
    COSNumber x2 = (COSNumber)operands.get(0);
    COSNumber y2 = (COSNumber)operands.get(1);
    COSNumber x3 = (COSNumber)operands.get(2);
    COSNumber y3 = (COSNumber)operands.get(3);

    Point2D currentPoint = context.getCurrentPoint();

    Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());

    if (currentPoint == null)
    {
        LOG.warn("curveTo (" + point3.x + "," + point3.y + ") without initial MoveTo");
        context.moveTo(point3.x, point3.y);
    }
    else
    {
        context.curveTo((float) currentPoint.getX(), (float) currentPoint.getY(),
                point2.x, point2.y,
                point3.x, point3.y);
    }
}
 
Example #30
Source File: PDSquareAppearanceHandler.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Get the line with of the border.
 * 
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 * 
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth()
{
    PDAnnotationMarkup annotation = (PDAnnotationMarkup) getAnnotation();

    PDBorderStyleDictionary bs = annotation.getBorderStyle();

    if (bs != null)
    {
        return bs.getWidth();
    }

    COSArray borderCharacteristics = annotation.getBorder();
    if (borderCharacteristics.size() >= 3)
    {
        COSBase base = borderCharacteristics.getObject(2);
        if (base instanceof COSNumber)
        {
            return ((COSNumber) base).floatValue();
        }
    }

    return 1;
}