Package org.pdfclown.bytes

Examples of org.pdfclown.bytes.Buffer


    // Instantiate a jpeg image object!
    Image image = null;
    try
    {
      image = Image.get(
        new Buffer(imageFileFormField.get())
        ); // Abstract image (entity).
    }
    catch(Exception e)
    {/* NOOP. */}
    if(image == null)
View Full Code Here


  {
    // 1. Body.
    int dataByteOffset;
    {
      // Serializing the entries into the stream buffer...
      IBuffer indexBuffer = new Buffer();
      IBuffer dataBuffer = new Buffer();
      IndirectObjects indirectObjects = file.getIndirectObjects();
      int objectIndex = -1;
      for(Map.Entry<Integer,ObjectEntry> entry : getEntries().entrySet())
      {
        final int objectNumber = entry.getKey();

        // Update the xref entry!
        XRefEntry xrefEntry = indirectObjects.get(objectNumber).getXrefEntry();
        xrefEntry.setOffset(++objectIndex);

        /*
          NOTE: The entry offset MUST be updated only after its serialization, in order not to interfere
          with its possible data-object retrieval from the old serialization.
        */
        int entryValueOffset = (int)dataBuffer.getLength();

        // Index.
        indexBuffer
          .append(Integer.toString(objectNumber)).append(Chunk.Space) // Object number.
          .append(Integer.toString(entryValueOffset)).append(Chunk.Space); // Byte offset (relative to the first one).
View Full Code Here

            Object streamType = dictionary.get(PdfName.Type);
            if(PdfName.ObjStm.equals(streamType)) // Object stream [PDF:1.6:3.4.6].
              return new ObjectStream(
                dictionary,
                new Buffer(data),
                file
                );
            else if(PdfName.XRef.equals(streamType)) // Cross-reference stream [PDF:1.6:3.4.7].
              return new XRefStream(
                dictionary,
                new Buffer(data),
                file
                );
            else // Generic stream.
              return new PdfStream(
                dictionary,
                new Buffer(data)
                );
          }
          else // Stand-alone dictionary.
          {
            stream.seek(oldOffset); // Restores postcondition (last token should be the dictionary end).
View Full Code Here

        new PdfName[]
          {PdfName.Type},
        new PdfDirectObject[]
          {PdfName.XRef}
        ),
      new Buffer(),
      file
      );
    PdfDictionary header = getHeader();
    for(Entry<PdfName,PdfDirectObject> entry : file.getTrailer().entrySet())
    {
View Full Code Here

            PdfName.BPC, new PdfInteger(getBitsPerComponent()),
            PdfName.F, PdfName.DCT
            )
          ),
        new InlineImageBody(
          new Buffer(getStream().toByteArray())
          )
        )
      );
  }
View Full Code Here

            new PdfInteger(getBitsPerComponent()),
            PdfName.DeviceRGB,
            PdfName.DCTDecode
          }
          ),
        new Buffer(getStream().toByteArray())
        )
      );
  }
View Full Code Here

    }

    InlineImageBody body;
    {
      moveNext();
      Buffer data = new Buffer();
      byte c1 = 0, c2 = 0;
      do
      {
        try
        {
          while(true)
          {
            c1 = stream.readByte();
            c2 = stream.readByte();
            if(c1 == 'E' && c2 == 'I')
              break;

            data.append(c1);
            data.append(c2);
          } break;
        }
        catch(EOFException e)
        {
          /* NOTE: Current stream has finished. */
 
View Full Code Here

        cmapStream = new BufferedReader(
          new InputStreamReader(
            CMap.class.getResourceAsStream("/fonts/cmap/" + name)
            )
          );
        cmap = get(new Buffer(cmapStream));
      }
      catch(Exception e)
      { /* Ignore. */ }
      finally
      {
View Full Code Here

    PdfDictionary font,
    PdfDictionary cidFont
    )
  {
    // CMap [PDF:1.6:5.6.4].
    Buffer cmapBuffer = new Buffer();
    cmapBuffer.append(
      "%!PS-Adobe-3.0 Resource-CMap\n"
        + "%%DocumentNeededResources: ProcSet (CIDInit)\n"
        + "%%IncludeResource: ProcSet (CIDInit)\n"
        + "%%BeginResource: CMap (Adobe-Identity-UCS)\n"
        + "%%Title: (Adobe-Identity-UCS Adobe Identity 0)\n"
        + "%%Version: 1\n"
        + "%%EndComments\n"
        + "/CIDInit /ProcSet findresource begin\n"
        + "12 dict begin\n"
        + "begincmap\n"
        + "/CIDSystemInfo\n"
        + "3 dict dup begin\n"
        + "/Registry (Adobe) def\n"
        + "/Ordering (Identity) def\n"
        + "/Supplement 0 def\n"
        + "end def\n"
        + "/CMapName /Adobe-Identity-UCS def\n"
        + "/CMapVersion 1 def\n"
        + "/CMapType 0 def\n"
        + "/WMode 0 def\n"
        + "2 begincodespacerange\n"
        + "<20> <20>\n"
        + "<0000> <19FF>\n"
        + "endcodespacerange\n"
        + glyphIndexes.size() + " begincidchar\n"
      );
    // ToUnicode [PDF:1.6:5.9.2].
    Buffer toUnicodeBuffer = new Buffer();
    toUnicodeBuffer.append(
      "/CIDInit /ProcSet findresource begin\n"
        + "12 dict begin\n"
        + "begincmap\n"
        + "/CIDSystemInfo\n"
        + "<< /Registry (Adobe)\n"
        + "/Ordering (UCS)\n"
        + "/Supplement 0\n"
        + ">> def\n"
        + "/CMapName /Adobe-Identity-UCS def\n"
        + "/CMapVersion 10.001 def\n"
        + "/CMapType 2 def\n"
        + "2 begincodespacerange\n"
        + "<20> <20>\n"
        + "<0000> <19FF>\n"
        + "endcodespacerange\n"
        + glyphIndexes.size() + " beginbfchar\n"
      );
    // CIDToGIDMap [PDF:1.6:5.6.3].
    Buffer gIdBuffer = new Buffer();
    gIdBuffer.append((byte)0);
    gIdBuffer.append((byte)0);
    int code = 0;
    codes = new BiMap<ByteArray,Integer>(glyphIndexes.size());
    PdfArray widthsObject = new PdfArray(glyphWidths.size());
    for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
    {
      // Character code (codepoint to unicode) entry.
      code++;
      byte[] charCode = (glyphIndexEntry.getKey() == 32
        ? new byte[]{32}
        : new byte[]
          {
            (byte)((code >> 8) & 0xFF),
            (byte)(code & 0xFF)
          });
      codes.put(new ByteArray(charCode),glyphIndexEntry.getKey());

      // CMap entry.
      cmapBuffer.append("<");
      toUnicodeBuffer.append("<");
      for(int charCodeBytesIndex = 0,
          charCodeBytesLength = charCode.length;
        charCodeBytesIndex < charCodeBytesLength;
        charCodeBytesIndex++
        )
      {
        String hex = Integer.toHexString((int)charCode[charCodeBytesIndex]);
        //TODO:improve hex padding!!!
        if(hex.length() == 1)
        {hex = "0" + hex;}
        else
        {hex = hex.substring(hex.length()-2,hex.length());}
        cmapBuffer.append(hex);
        toUnicodeBuffer.append(hex);
      }
      cmapBuffer.append("> " + code + "\n");
      toUnicodeBuffer.append("> <" + getHex(glyphIndexEntry.getKey()) + ">\n");

      // CID-to-GID entry.
      int glyphIndex = glyphIndexEntry.getValue();
      gIdBuffer.append((byte)((glyphIndex >> 8) & 0xFF));
      gIdBuffer.append((byte)(glyphIndex & 0xFF));

      // Width.
      int width;
      try
      {width = glyphWidths.get(glyphIndex);if(width>1000){width=1000;}}
View Full Code Here

        new PdfStream(
          new PdfDictionary(
            new PdfName[]{PdfName.Subtype},
            new PdfDirectObject[]{PdfName.OpenType}
            ),
          new Buffer(parser.fontData.toByteArray())
          )
        );
      fontDescriptor.put(
        PdfName.FontFile3,
        fontFileReference
View Full Code Here

TOP

Related Classes of org.pdfclown.bytes.Buffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.