예제 #1
0
  /** {@inheritDoc} */
  protected void determineEncoding() {
    String cmapName = null;
    COSName encodingName = null;
    COSBase encoding = getEncoding();
    Encoding fontEncoding = null;
    if (encoding != null) {
      if (encoding instanceof COSName) {
        if (cmap == null) {
          encodingName = (COSName) encoding;
          cmap = cmapObjects.get(encodingName.getName());
          if (cmap == null) {
            cmapName = encodingName.getName();
          }
        }
        if (cmap == null && cmapName != null) {
          try {
            fontEncoding = EncodingManager.INSTANCE.getEncoding(encodingName);
          } catch (IOException exception) {
            LOG.debug("Debug: Could not find encoding for " + encodingName);
          }
        }
      } else if (encoding instanceof COSStream) {
        if (cmap == null) {
          COSStream encodingStream = (COSStream) encoding;
          try {
            cmap = parseCmap(null, encodingStream.getUnfilteredStream());
          } catch (IOException exception) {
            LOG.error("Error: Could not parse the embedded CMAP");
          }
        }
      } else if (encoding instanceof COSDictionary) {
        try {
          fontEncoding = new DictionaryEncoding((COSDictionary) encoding);
        } catch (IOException exception) {
          LOG.error("Error: Could not create the DictionaryEncoding");
        }
      }
    }
    setFontEncoding(fontEncoding);
    extractToUnicodeEncoding();

    if (cmap == null && cmapName != null) {
      String resourceName = resourceRootCMAP + cmapName;
      try {
        cmap = parseCmap(resourceRootCMAP, ResourceLoader.loadResource(resourceName));
        if (cmap == null && encodingName == null) {
          LOG.error("Error: Could not parse predefined CMAP file for '" + cmapName + "'");
        }
      } catch (IOException exception) {
        LOG.error("Error: Could not find predefined CMAP file for '" + cmapName + "'");
      }
    }
  }
  /**
   * 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());
  }