Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfArray


  @Override
  public <T> T[] toArray(
    T[] values
    )
  {
    PdfArray functionObjects = getBaseDataObject();
    if(values.length < functionObjects.size())
    {values = (T[])new Object[functionObjects.size()];}

    PdfIndirectObject container = getContainer();
    for(
      int index = 0,
        length = functionObjects.size();
      index < length;
      index++
      )
    {values[index] = (T)Function.wrap(functionObjects.get(index),container);}

    return values;
  }
View Full Code Here


    }

    public Point2D getStart(
      )
    {
      PdfArray coordinates = getBaseDataObject();

      return new Point2D.Double(
        ((PdfNumber<?>)coordinates.get(0)).getNumberValue(),
        page.getBox().getHeight() - ((PdfNumber<?>)coordinates.get(1)).getNumberValue()
        );
    }
View Full Code Here

    List<? extends PdfDirectObject> components
    )
  {
    super(
      null, //TODO:consider color space reference!
      new PdfArray(components)
      );
  }
View Full Code Here

    )
  {
    /*
      NOTE: 'IC' entry may be undefined.
    */
    PdfArray fillColorObject = (PdfArray)getBaseDataObject().get(PdfName.IC);
    if(fillColorObject == null)
      return null;
//TODO:use baseObject constructor!!!
    return new DeviceRGBColor(
      ((PdfNumber<?>)fillColorObject.get(0)).getNumberValue(),
      ((PdfNumber<?>)fillColorObject.get(1)).getNumberValue(),
      ((PdfNumber<?>)fillColorObject.get(2)).getNumberValue()
      );
  }
View Full Code Here

    List<? extends PdfDirectObject> components
    )
  {
    super(
      DeviceRGBColorSpace.Default,
      new PdfArray(components)
      );
  }
View Full Code Here

    loadEncoding();

    // Glyph widths.
    {
      glyphWidths = new Hashtable<Integer,Integer>();
      PdfArray glyphWidthObjects = (PdfArray)getCIDFontDictionary().resolve(PdfName.W);
      if(glyphWidthObjects != null)
      {
        for(Iterator<PdfDirectObject> iterator = glyphWidthObjects.iterator(); iterator.hasNext();)
        {
          //TODO: this algorithm is valid only in case cid-to-gid mapping is identity (see cidtogid map)!!
          /*
            NOTE: Font widths are grouped in one of the following formats [PDF:1.6:5.6.3]:
              1. startCID [glyphWidth1 glyphWidth2 ... glyphWidthn]
View Full Code Here

        // Encoding.
        load_createEncoding(baseDataObject,cidFontDictionary);
      }
      baseDataObject.put(
        PdfName.DescendantFonts,
        new PdfArray(new PdfDirectObject[]{getFile().register(cidFontDictionary)})
        );
    }
    catch(Exception e)
    {throw new RuntimeException(e);}
View Full Code Here

    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;}}
      catch(Exception e)
      {width = 0;}
      widthsObject.add(new PdfInteger(width));
    }
    cmapBuffer.append(
      "endcidchar\n"
        + "endcmap\n"
        + "CMapName currentdict /CMap defineresource pop\n"
        + "end\n"
        + "end\n"
        + "%%EndResource\n"
        + "%%EOF"
      );
    PdfStream cmapStream = new PdfStream(cmapBuffer);
    PdfDictionary cmapHead = cmapStream.getHeader();
    cmapHead.put(
      PdfName.Type,
      PdfName.CMap
      );
    cmapHead.put(
      PdfName.CMapName,
      new PdfName("Adobe-Identity-UCS")
      );
    cmapHead.put(
      PdfName.CIDSystemInfo,
      new PdfDictionary(
        new PdfName[]
        {
          PdfName.Registry,
          PdfName.Ordering,
          PdfName.Supplement
        },
        new PdfDirectObject[]
        {
          new PdfTextString("Adobe"),
          new PdfTextString("Identity"),
          new PdfInteger(0)
        }
        )
      ); // Generic predefined CMap (Identity-H/V (Adobe-Identity-0)) [PDF:1.6:5.6.4].
    font.put(
      PdfName.Encoding,
      getFile().register(cmapStream)
      );

    PdfStream gIdStream = new PdfStream(gIdBuffer);
    cidFont.put(
      PdfName.CIDToGIDMap,
      getFile().register(gIdStream)
      );

    cidFont.put(
      PdfName.W,
      new PdfArray(new PdfDirectObject[]{new PdfInteger(1),widthsObject})
      );

    toUnicodeBuffer.append(
      "endbfchar\n"
        + "endcmap\n"
View Full Code Here

    )
  {
    PdfDirectObject baseDataObject = getBaseDataObject();
    if(baseDataObject instanceof PdfArray)
    {
      PdfArray baseArrayObject = (PdfArray)baseDataObject;
      if(baseArrayObject.size() > 1)
        return ColorSpace.wrap(baseArrayObject.get(1), getContainer());
    }
    return null;
  }
View Full Code Here

    List<? extends PdfDirectObject> components
    )
  {
    super(
      null, //TODO:consider color space reference!
      new PdfArray(components)
      );
  }
View Full Code Here

TOP

Related Classes of org.pdfclown.objects.PdfArray

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.