/**
  * Constructor.
  *
  * @param array The array of COSStreams to concatenate together.
  */
 public COSStreamArray(COSArray array) {
   super(new COSDictionary(), null);
   streams = array;
   if (array.size() > 0) {
     firstStream = (COSStream) array.getObject(0);
   }
 }
Пример #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;
  }
Пример #3
0
  protected PDFunction getTintTransformer(COSStream xstream) throws IOException {
    COSBase cs = xstream.getDictionaryObject(COSName.COLORSPACE, COSName.CS);
    if (cs == null) {
      return null;
    }

    COSArray array = getCOSArray(cs);
    if (array == null) {
      return null;
    }
    String name = ((COSName) array.getObject(0)).getName();

    if (name.equals("DeviceN")) {
      PDFunction function = PDFunction.create(array.getObject(3));
      return function;
    }

    return null;
  }
 /**
  * Returns this field's children. These may be either terminal or non-terminal fields.
  *
  * @return he list of child fields.
  */
 public List<PDField> getChildren() {
   List<PDField> children = new ArrayList<PDField>();
   COSArray kids = (COSArray) getCOSObject().getDictionaryObject(COSName.KIDS);
   for (int i = 0; i < kids.size(); i++) {
     PDField field =
         PDField.fromDictionary(getAcroForm(), (COSDictionary) kids.getObject(i), this);
     if (field != null) {
       children.add(field);
     }
   }
   return children;
 }
  /**
   * This will get the logical content stream with none of the filters.
   *
   * @return the bytes of the logical (decoded) stream
   * @throws IOException when encoding/decoding causes an exception
   */
  public InputStream getUnfilteredStream() throws IOException {
    Vector<InputStream> inputStreams = new Vector<InputStream>();
    byte[] inbetweenStreamBytes = "\n".getBytes("ISO-8859-1");

    for (int i = 0; i < streams.size(); i++) {
      COSStream stream = (COSStream) streams.getObject(i);
      inputStreams.add(stream.getUnfilteredStream());
      // handle the case where there is no whitespace in the
      // between streams in the contents array, without this
      // it is possible that two operators will get concatenated
      // together
      inputStreams.add(new ByteArrayInputStream(inbetweenStreamBytes));
    }

    return new SequenceInputStream(inputStreams.elements());
  }
Пример #6
0
 /**
  * This will find one of the child elements. The name array are the components of the name to
  * search down the tree of names. The nameIndex is where to start in that array. This method is
  * called recursively until it finds the end point based on the name array.
  *
  * @param name An array that picks the path to the field.
  * @param nameIndex The index into the array.
  * @return The field at the endpoint or null if none is found.
  */
 PDField findKid(String[] name, int nameIndex) {
   PDField retval = null;
   COSArray kids = (COSArray) dictionary.getDictionaryObject(COSName.KIDS);
   if (kids != null) {
     for (int i = 0; retval == null && i < kids.size(); i++) {
       COSDictionary kidDictionary = (COSDictionary) kids.getObject(i);
       if (name[nameIndex].equals(kidDictionary.getString(COSName.T))) {
         retval = PDField.fromDictionary(acroForm, kidDictionary, (PDNonTerminalField) this);
         if (retval != null && name.length > nameIndex + 1) {
           retval = retval.findKid(name, nameIndex + 1);
         }
       }
     }
   }
   return retval;
 }
Пример #7
0
  /**
   * This will get the next action, or sequence of actions, to be performed after this one. The
   * value is either a single action dictionary or an array of action dictionaries to be performed
   * in order.
   *
   * @return The Next action or sequence of actions.
   */
  public List getNext() {
    List retval = null;
    COSBase next = action.getDictionaryObject("Next");
    if (next instanceof COSDictionary) {
      PDAction pdAction = PDActionFactory.createAction((COSDictionary) next);
      retval = new COSArrayList(pdAction, next, action, COSName.getPDFName("Next"));
    } else if (next instanceof COSArray) {
      COSArray array = (COSArray) next;
      List actions = new ArrayList();
      for (int i = 0; i < array.size(); i++) {
        actions.add(PDActionFactory.createAction((COSDictionary) array.getObject(i)));
      }
      retval = new COSArrayList(actions, array);
    }

    return retval;
  }
Пример #8
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();
 }
Пример #9
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();
 }