示例#1
0
 public static PdfObject createInfoId(byte id[]) {
   ByteBuffer buf = new ByteBuffer(90);
   buf.append('[').append('<');
   for (int k = 0; k < 16; ++k) buf.appendHex(id[k]);
   buf.append('>').append('<');
   id = createDocumentId();
   for (int k = 0; k < 16; ++k) buf.appendHex(id[k]);
   buf.append('>').append(']');
   return new PdfLiteral(buf.toByteArray());
 }
示例#2
0
  public void unprepare(
      int X, int Y, final WaveFormat waveFormat, final ByteBuffer output, final Crc32 crc) {
    // decompress and convert from (x,y) -> (l,r)
    // sort of long and ugly.... sorry
    int channels = waveFormat.nChannels;
    int bitsPerSample = waveFormat.wBitsPerSample;
    if (channels == 2) {
      if (bitsPerSample == 16) {
        // get the right and left values
        short nR = (short) (X - (Y / 2));
        short nL = (short) (nR + Y);

        output.append(nR, nL);
        crc.append(nR, nL);
      } else if (bitsPerSample == 8) {
        byte R = (byte) (X - (Y / 2) + 128);
        byte L = (byte) (R + Y);

        output.append(R, L);
        crc.append(R, L);
      } else if (bitsPerSample == 24) {
        int RV = X - (Y / 2);
        int LV = RV + Y;

        if (RV < 0) RV = (RV + 0x800000) | 0x800000;
        if (LV < 0) LV = (LV + 0x800000) | 0x800000;

        output.append24(RV, LV);
        crc.append24(RV, LV);
      }
    } else if (channels == 1) {
      if (bitsPerSample == 16) {
        output.append((short) X);
        crc.append((short) X);
      } else if (bitsPerSample == 8) {
        byte R = (byte) (X + 128);

        output.append(R);
        crc.append(R);
      } else if (bitsPerSample == 24) {
        if (X < 0) X = (X + 0x800000) | 0x800000;

        output.append24(X);
        crc.append24(X);
      }
    }
  }
示例#3
0
 private void internalDispose(ByteBuffer buf) {
   int last = 0;
   int pos = 0;
   ByteBuffer buf2 = cb.getInternalBuffer();
   if (kids != null) {
     for (int k = 0; k < kids.size(); k += 2) {
       pos = ((Integer) kids.get(k)).intValue();
       PdfGraphics2D g2 = (PdfGraphics2D) kids.get(k + 1);
       g2.cb.restoreState();
       g2.cb.restoreState();
       buf.append(buf2.getBuffer(), last, pos - last);
       g2.dg2.dispose();
       g2.dg2 = null;
       g2.internalDispose(buf);
       last = pos;
     }
   }
   buf.append(buf2.getBuffer(), last, buf2.size() - last);
 }
  public void append(byte[] bytes, int offset, int length) throws IOException {
    List captureBuffers;
    if ((captureBuffers = mCaptureBuffers) != null) {
      int size = captureBuffers.size();
      for (int i = 0; i < size; i++) {
        ((ByteBuffer) captureBuffers.get(i)).append(bytes, offset, length);
      }
    }

    if (mSpillover == null) {
      if (mGroup.adjustLevel(length)) {
        mLocalBuffer.append(bytes, offset, length);
        return;
      }
      spillover();
    }

    mSpillover.append(bytes, offset, length);
  }
示例#5
0
 /** @see Graphics#dispose() */
 public void dispose() {
   if (kid) return;
   if (!disposeCalled) {
     disposeCalled = true;
     cb.restoreState();
     cb.restoreState();
     dg2.dispose();
     dg2 = null;
     if (kids != null) {
       ByteBuffer buf = new ByteBuffer();
       internalDispose(buf);
       ByteBuffer buf2 = cb.getInternalBuffer();
       buf2.reset();
       buf2.append(buf);
     }
   }
 }
示例#6
0
 public void alterContents() throws IOException {
   if (over == null && under == null) return;
   PdfArray ar = null;
   PdfObject content = PdfReader.getPdfObject(pageN.get(PdfName.CONTENTS), pageN);
   if (content == null) {
     ar = new PdfArray();
     pageN.put(PdfName.CONTENTS, ar);
   } else if (content.isArray()) {
     ar = (PdfArray) content;
   } else if (content.isStream()) {
     ar = new PdfArray();
     ar.add(pageN.get(PdfName.CONTENTS));
     pageN.put(PdfName.CONTENTS, ar);
   } else {
     ar = new PdfArray();
     pageN.put(PdfName.CONTENTS, ar);
   }
   ByteBuffer out = new ByteBuffer();
   if (under != null) {
     out.append(PdfContents.SAVESTATE);
     applyRotation(pageN, out);
     out.append(under.getInternalBuffer());
     out.append(PdfContents.RESTORESTATE);
   }
   if (over != null) out.append(PdfContents.SAVESTATE);
   PdfStream stream = new PdfStream(out.toByteArray());
   stream.flateCompress(cstp.getCompressionLevel());
   PdfIndirectReference ref1 = cstp.addToBody(stream).getIndirectReference();
   ar.addFirst(ref1);
   out.reset();
   if (over != null) {
     out.append(' ');
     out.append(PdfContents.RESTORESTATE);
     out.append(PdfContents.SAVESTATE);
     applyRotation(pageN, out);
     out.append(over.getInternalBuffer());
     out.append(PdfContents.RESTORESTATE);
     stream = new PdfStream(out.toByteArray());
     stream.flateCompress(cstp.getCompressionLevel());
     ar.add(cstp.addToBody(stream).getIndirectReference());
   }
   pageN.put(PdfName.RESOURCES, pageResources.getResources());
 }
示例#7
0
 /**
  * Constructs a new <CODE>PdfName</CODE>.
  *
  * @param name the new name
  * @param lengthCheck if <CODE>true</CODE> check the lenght validity, if <CODE>false</CODE> the
  *     name can have any length
  */
 public PdfDicString(String name, boolean lengthCheck) {
   super(PdfObject.NAME);
   // The minimum number of characters in a name is 0, the maximum is 127 (the '/' not included)
   int length = name.length();
   // if (lengthCheck && length > 127) {
   //    throw new IllegalArgumentException("The name '" + name + "' is too long (" + length + "
   // characters).");
   // }
   // The name has to be checked for illegal characters
   // every special character has to be substituted
   ByteBuffer pdfName = new ByteBuffer(length + 20);
   char character;
   char chars[] = name.toCharArray();
   // loop over all the characters
   for (int index = 0; index < length; index++) {
     character = (char) (chars[index] & 0xff);
     pdfName.append(character);
   }
   bytes = pdfName.toByteArray();
 }
示例#8
0
  public void AddData(byte[] pData, int nBytes) throws IOException {
    int nBytesDone = 0;

    while (nBytesDone < nBytes) {
      // lock the buffer
      m_nAddDataBytesAvailable.value = 0;
      ByteBuffer pBuffer = LockBuffer(m_nAddDataBytesAvailable);
      if (pBuffer == null || m_nAddDataBytesAvailable.value <= 0)
        throw new JMACException("Error Undefined");

      // calculate how many bytes to copy and add that much to the buffer
      int nBytesToProcess = Math.min(m_nAddDataBytesAvailable.value, nBytes - nBytesDone);
      pBuffer.append(pData, nBytesDone, nBytesToProcess);

      // unlock the buffer (fail if not successful)
      UnlockBuffer(nBytesToProcess);

      // update our progress
      nBytesDone += nBytesToProcess;
    }
  }
示例#9
0
 void applyRotation(PdfDictionary pageN, ByteBuffer out) {
   if (!cstp.rotateContents) return;
   Rectangle page = reader.getPageSizeWithRotation(pageN);
   int rotation = page.getRotation();
   switch (rotation) {
     case 90:
       out.append(PdfContents.ROTATE90);
       out.append(page.getTop());
       out.append(' ').append('0').append(PdfContents.ROTATEFINAL);
       break;
     case 180:
       out.append(PdfContents.ROTATE180);
       out.append(page.getRight());
       out.append(' ');
       out.append(page.getTop());
       out.append(PdfContents.ROTATEFINAL);
       break;
     case 270:
       out.append(PdfContents.ROTATE270);
       out.append('0').append(' ');
       out.append(page.getRight());
       out.append(PdfContents.ROTATEFINAL);
       break;
   }
 }
示例#10
0
  public void unprepareOld(
      int[] pInputX,
      int[] pInputY,
      int nBlocks,
      WaveFormat pWaveFormatEx,
      ByteBuffer output,
      Crc32 crc,
      int nFileVersion) {
    // the CRC that will be figured during decompression
    crc.init();

    // decompress and convert from (x,y) -> (l,r)
    // sort of int and ugly.... sorry
    int channels = pWaveFormatEx.nChannels;
    int bitsPerSample = pWaveFormatEx.wBitsPerSample;
    if (channels == 2) {
      // convert the x,y data to raw data
      if (bitsPerSample == 16) {
        short R;
        int pX = 0;
        int pY = 0;

        for (; pX < nBlocks; pX++, pY++) {
          R = (short) (pInputX[pX] - (pInputY[pY] / 2));

          output.append(R);
          crc.append(R);
          R += pInputY[pY];
          output.append(R);
          crc.append(R);
        }
      } else if (bitsPerSample == 8) {
        byte R;
        if (nFileVersion > 3830) {
          for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) {
            R = (byte) (pInputX[SampleIndex] - (pInputY[SampleIndex] / 2) + 128);
            output.append(R);
            crc.append(R);
            R += pInputY[SampleIndex];
            output.append(R);
            crc.append(R);
          }
        } else {
          for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) {
            R = (byte) (pInputX[SampleIndex] - (pInputY[SampleIndex] / 2));
            output.append(R);
            crc.append(R);
            R += pInputY[SampleIndex];
            output.append(R);
            crc.append(R);
          }
        }
      } else if (bitsPerSample == 24) {
        int RV, LV;

        for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) {
          RV = pInputX[SampleIndex] - (pInputY[SampleIndex] / 2);
          LV = RV + pInputY[SampleIndex];

          int nTemp = 0;
          if (RV < 0) nTemp = (RV + 0x800000) | 0x800000;
          else nTemp = RV;

          output.append24(nTemp);
          crc.append24(nTemp);

          nTemp = 0;
          if (LV < 0) nTemp = (LV + 0x800000) | 0x800000;
          else nTemp = LV;

          output.append24(nTemp);
          crc.append24(nTemp);
        }
      }
    } else if (channels == 1) {
      // convert to raw data
      if (bitsPerSample == 8) {
        byte R;
        if (nFileVersion > 3830) {
          for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) {
            R = (byte) (pInputX[SampleIndex] + 128);
            output.append(R);
            crc.append(R);
          }
        } else {
          for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) {
            R = (byte) (pInputX[SampleIndex]);
            output.append(R);
            crc.append(R);
          }
        }

      } else if (bitsPerSample == 24) {

        int RV;
        for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) {
          RV = pInputX[SampleIndex];

          int nTemp = 0;
          if (RV < 0) nTemp = (RV + 0x800000) | 0x800000;
          else nTemp = RV;

          output.append24(nTemp);
          crc.append24(nTemp);
        }
      } else {
        short R;
        for (int SampleIndex = 0; SampleIndex < nBlocks; SampleIndex++) {
          R = (short) (pInputX[SampleIndex]);
          output.append(R);
          crc.append(R);
        }
      }
    }
    crc.prefinalizeCrc();
  }