Example #1
0
 @Override
 public void process(Operator operator, List<COSBase> operands) throws IOException {
   COSNumber x = (COSNumber) operands.get(0);
   COSNumber y = (COSNumber) operands.get(1);
   Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
   context.moveTo(pos.x, pos.y);
 }
Example #2
0
  /**
   * This will get the average font width for all characters.
   *
   * @return The width is in 1000 unit of text space, ie 333 or 777
   * @throws IOException If an error occurs while parsing.
   */
  public float getAverageFontWidth() throws IOException {
    float average = 0.0f;

    if (avgFontWidth != 0.0f) {
      average = avgFontWidth;
    } else {
      float totalWidth = 0.0f;
      float characterCount = 0.0f;
      COSArray widths = (COSArray) font.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 = getAverageFontWidthFromAFMFile();
      }
      avgFontWidth = average;
    }
    return average;
  }
Example #3
0
  @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());
  }
  @Override
  public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.size() == 0) {
      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());
    }
  }
 /**
  * rg Set color space for non 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.setNonStrokingColor(new Color(r.floatValue(), g.floatValue(), b.floatValue()));
 }
  /**
   * process : y : Append curved segment to path (final point replicated).
   *
   * @param operator The operator that is being executed.
   * @param arguments List
   */
  public void process(PDFOperator operator, List<COSBase> arguments) {
    PageDrawer drawer = (PageDrawer) context;

    COSNumber x1 = (COSNumber) arguments.get(0);
    COSNumber y1 = (COSNumber) arguments.get(1);
    COSNumber x3 = (COSNumber) arguments.get(2);
    COSNumber y3 = (COSNumber) arguments.get(3);

    Point2D point1 = drawer.transformedPoint(x1.doubleValue(), y1.doubleValue());
    Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue());

    drawer
        .getLinePath()
        .curveTo(
            (float) point1.getX(),
            (float) point1.getY(),
            (float) point3.getX(),
            (float) point3.getY(),
            (float) point3.getX(),
            (float) point3.getY());
  }
Example #7
0
 /**
  * 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 #8
0
 /**
  * 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();
 }
 /**
  * Tr Set text rendering mode.
  *
  * @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 {
   COSNumber mode = (COSNumber) arguments.get(0);
   context.getGraphicsState().getTextState().setRenderingMode(mode.intValue());
 }