Java Code Examples for org.apache.pdfbox.cos.COSNumber#floatValue()
The following examples show how to use
org.apache.pdfbox.cos.COSNumber#floatValue() .
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: SetMatrix.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override public void process(Operator operator, List<COSBase> arguments) throws MissingOperandException { if (arguments.size() < 6) { throw new MissingOperandException(operator, arguments); } if (!checkArrayTypesClass(arguments, COSNumber.class)) { return; } 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.setTextMatrix(matrix); context.setTextLineMatrix(matrix.clone()); }
Example 2
Source File: Concatenate.java From gcs with Mozilla Public License 2.0 | 6 votes |
@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 3
Source File: PDExtendedGraphicsState.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * This will get a float item from the dictionary. * * @param key The key to the item. * * @return The value for that item. */ private Float getFloatItem( COSName key ) { Float retval = null; COSBase base = dict.getDictionaryObject(key); if (base instanceof COSNumber) { COSNumber value = (COSNumber) base; retval = value.floatValue(); } return retval; }
Example 4
Source File: PDCalGray.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * This will get the gamma value. If none is present then the default of 1 * will be returned. * * @return The gamma value. */ public float getGamma() { float retval = 1.0f; COSNumber gamma = (COSNumber) dictionary.getDictionaryObject(COSName.GAMMA); if (gamma != null) { retval = gamma.floatValue(); } return retval; }
Example 5
Source File: PDFont.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * This will get the average font width for all characters. * * @return The width is in 1000 unit of text space, ie 333 or 777 */ // todo: this method is highly suspicious, the average glyph width is not usually a good metric @Override public float getAverageFontWidth() { float average; if (avgFontWidth != 0.0f) { average = avgFontWidth; } else { float totalWidth = 0.0f; float characterCount = 0.0f; COSArray widths = (COSArray) dict.getDictionaryObject(COSName.WIDTHS); if (widths != null) { for (int i = 0; i < widths.size(); i++) { COSNumber fontWidth = (COSNumber) widths.getObject(i); if (fontWidth.floatValue() > 0) { totalWidth += fontWidth.floatValue(); characterCount += 1; } } } if (totalWidth > 0) { average = totalWidth / characterCount; } else { average = 0; } avgFontWidth = average; } return average; }
Example 6
Source File: AppendRectangleToPath.java From gcs with Mozilla Public License 2.0 | 5 votes |
@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 7
Source File: MoveText.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public void process(Operator operator, List<COSBase> arguments) throws MissingOperandException { if (arguments.size() < 2) { throw new MissingOperandException(operator, arguments); } Matrix textLineMatrix = context.getTextLineMatrix(); if (textLineMatrix == null) { LOG.warn("TextLineMatrix is null, " + getName() + " operator will be ignored"); return; } COSBase base0 = arguments.get(0); COSBase base1 = arguments.get(1); if (!(base0 instanceof COSNumber)) { return; } if (!(base1 instanceof COSNumber)) { return; } COSNumber x = (COSNumber) base0; COSNumber y = (COSNumber) base1; Matrix matrix = new Matrix(1, 0, 0, 1, x.floatValue(), y.floatValue()); textLineMatrix.concatenate(matrix); context.setTextMatrix(textLineMatrix.clone()); }
Example 8
Source File: PdfToTextInfoConverter.java From testarea-pdfbox2 with Apache License 2.0 | 5 votes |
@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); // to ensure that the path is created in the right direction, we have to create // it by combining single lines instead of creating a simple rectangle linePath.moveTo((float) p0.getX(), (float) p0.getY()); linePath.lineTo((float) p1.getX(), (float) p1.getY()); linePath.lineTo((float) p2.getX(), (float) p2.getY()); linePath.lineTo((float) p3.getX(), (float) p3.getY()); // close the subpath instead of adding the last line so that a possible set line // cap style isn't taken into account at the "beginning" of the rectangle linePath.closePath(); }
Example 9
Source File: PDFVisibleTextStripper.java From testarea-pdfbox2 with Apache License 2.0 | 5 votes |
@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); // to ensure that the path is created in the right direction, we have to create // it by combining single lines instead of creating a simple rectangle linePath.moveTo((float) p0.getX(), (float) p0.getY()); linePath.lineTo((float) p1.getX(), (float) p1.getY()); linePath.lineTo((float) p2.getX(), (float) p2.getY()); linePath.lineTo((float) p3.getX(), (float) p3.getY()); // close the subpath instead of adding the last line so that a possible set line // cap style isn't taken into account at the "beginning" of the rectangle linePath.closePath(); }
Example 10
Source File: PDFontSetting.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * This will get the size of the font. * * @return The size of the font. */ public float getFontSize() { COSNumber size = (COSNumber)fontSetting.get( 1 ); return size.floatValue(); }
Example 11
Source File: PDRange.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * This will get the minimum value of the range. * * @return The min value. */ public float getMin() { COSNumber min = (COSNumber)rangeArray.getObject( startingIndex*2 ); return min.floatValue(); }
Example 12
Source File: PDRange.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * This will get the maximum value of the range. * * @return The max value. */ public float getMax() { COSNumber max = (COSNumber)rangeArray.getObject( startingIndex*2+1 ); return max.floatValue(); }
Example 13
Source File: AppendRectangleToPath.java From pdfxtk with Apache License 2.0 | 4 votes |
/** * process : re : append rectangle 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 x = (COSNumber)arguments.get( 0 ); COSNumber y = (COSNumber)arguments.get( 1 ); COSNumber w = (COSNumber)arguments.get( 2 ); COSNumber h = (COSNumber)arguments.get( 3 ); double finalX = x.floatValue(); double finalY = y.floatValue(); double finalW = w.floatValue(); double finalH = h.floatValue(); Point2D Ppos = drawer.TransformedPoint(finalX, finalY); Point2D Psize = drawer.ScaledPoint(finalW, finalH); finalY = Ppos.getY() - Psize.getY(); if(finalY < 0) { finalY = 0; } //logger().info("Rectangle coords: " + Ppos.getX() + "," + finalY + "," + Psize.getX() + "," + Psize.getY() ); Rectangle2D rect = new Rectangle2D.Double(Ppos.getX(), finalY, Psize.getX(), Psize.getY()); drawer.getLinePath().reset(); //System.out.println( "Bounds before=" + drawer.getLinePath().getBounds() ); drawer.getLinePath().append( rect, false ); //graphics.drawRect((int)x.doubleValue(), (int)(pageSize.getHeight() - y.doubleValue()), // (int)w.doubleValue(),(int)h.doubleValue() ); //System.out.println( "<re x=\"" + x.getValue() + "\" y=\"" + y.getValue() + "\" width=\"" + // width.getValue() + "\" height=\"" + height.getValue() + "\" >" ); //drawer.simpleAddRect(x.floatValue(), y.floatValue(), w.floatValue(), h.floatValue()); drawer.newPath(); drawer.simpleAddRect((float)Ppos.getX(), (float)finalY, (float)Psize.getX(), (float)Psize.getY()); }