Package org.pdfclown.util

Examples of org.pdfclown.util.ByteArray


      int codeBufferSize = 1;
      while(position < codeLength)
      {
        byte[] codeBuffer = codeBuffers[codeBufferSize];
        System.arraycopy(code,position,codeBuffer,0,codeBufferSize);
        Integer textChar = codes.get(new ByteArray(codeBuffer));
        if(textChar == null)
        {
          if(codeBufferSize < charCodeMaxLength)
          {
            codeBufferSize++;
View Full Code Here


    {
      if(differenceObject instanceof PdfInteger)
      {charCodeData[0] = (byte)((((PdfInteger)differenceObject).getValue().intValue()) & 0xFF);} //TODO:verify whether it can be directly cast to byte (.byteValue())!
      else // NOTE: MUST be PdfName.
      {
        ByteArray charCode = new ByteArray(charCodeData);
        String charName = (String)((PdfName)differenceObject).getValue();
        if(charName.equals(".notdef"))
        {codes.remove(charCode);}
        else
        {
View Full Code Here

    {
      glyphWidths = new Hashtable<Integer,Integer>();
      PdfArray glyphWidthObjects = (PdfArray)getBaseDataObject().resolve(PdfName.Widths);
      if(glyphWidthObjects != null)
      {
        ByteArray charCode = new ByteArray(
          new byte[]
          {(byte)(int)((PdfInteger)getBaseDataObject().get(PdfName.FirstChar)).getRawValue()}
          );
        for(PdfDirectObject glyphWidthObject : glyphWidthObjects)
        {
View Full Code Here

    {
      Map<ByteArray,Integer> codes = new Hashtable<ByteArray,Integer>();
      for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
      {
        codes.put(
          new ByteArray(new byte[]{ConvertUtils.intToByteArray(glyphIndexEntry.getValue())[3]}),
          glyphIndexEntry.getKey()
          );
      }
      return codes;
    }
View Full Code Here

        : 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,
View Full Code Here

            if(!encodingLineMatcher.find())
              break;

            byte[] inputCode = new byte[]{(byte)Integer.parseInt(encodingLineMatcher.group(1))};
            String name = encodingLineMatcher.group(2).substring(1);
            codes.put(new ByteArray(inputCode),GlyphMapping.nameToCode(name));
          }
          break;
        }
      }
    }
View Full Code Here

  // <protected>
  protected void put(
    int charCode,
    String charName
    )
  {codes.put(new ByteArray(new byte[]{(byte)charCode}),GlyphMapping.nameToCode(charName));}
View Full Code Here

                  itemIndex++
                  )
                {
                  // 1. Input code.
                  moveNext();
                  ByteArray inputCode = new ByteArray((byte[])token);
                  // 2. Character...
                  moveNext();
                  switch(tokenType)
                  {
                    case Hex: // ...code (hex).
                      codes.put(inputCode,ConvertUtils.byteArrayToInt((byte[])token));
                      break;
                    case Integer: // ...code (plain).
                      codes.put(inputCode,(Integer)token);
                      break;
                    case Name: // ...name.
                      codes.put(inputCode,GlyphMapping.nameToCode((String)token));
                      break;
                    default:
                      throw new RuntimeException(
                        operator + " section syntax error: hex string, integer or name expected instead of " + tokenType
                        );
                  }
                }
              }
              else if(operator.equals(BeginBaseFontRangeOperator)
                || operator.equals(BeginCIDRangeOperator))
              {
                /*
                  NOTE: The first and second elements in each line are the beginning and
                  ending valid input codes for the template font; the third element is
                  the beginning character code for the range.
                */
                for(
                  int itemIndex = 0;
                  itemIndex < itemCount;
                  itemIndex++
                  )
                {
                  // 1. Beginning input code.
                  moveNext();
                  byte[] beginInputCode = (byte[])token;
                  // 2. Ending input code.
                  moveNext();
                  byte[] endInputCode = (byte[])token;
                  // 3. Character codes.
                  moveNext();
                  switch(tokenType)
                  {
                    case Hex:
                    case Integer:
                    {
                      byte[] inputCode = beginInputCode;
                      int charCode;
                      switch(tokenType)
                      {
                        case Hex:
                          charCode = ConvertUtils.byteArrayToInt((byte[])token);
                          break;
                        case Integer:
                          charCode = (Integer)token;
                          break;
                        default:
                          throw new RuntimeException(
                            operator + " section syntax error: hex string or integer expected instead of " + tokenType
                            );
                      }
                      int endCharCode = charCode + (ConvertUtils.byteArrayToInt(endInputCode) - ConvertUtils.byteArrayToInt(beginInputCode));
                      while(true)
                      {
                        codes.put(new ByteArray(inputCode),charCode);
                        if(charCode == endCharCode)
                          break;

                        OperationUtils.increment(inputCode);
                        charCode++;
                      }
                      break;
                    }
                    case ArrayBegin:
                    {
                      byte[] inputCode = beginInputCode;
                      while(moveNext()
                        && tokenType != TokenTypeEnum.ArrayEnd)
                      {
                        codes.put(new ByteArray(inputCode),GlyphMapping.nameToCode((String)token));
                        OperationUtils.increment(inputCode);
                      }
                      break;
                    }
                    default:
View Full Code Here

          (i.e. when ToUnicode stream is available).
        */
        Map<Integer,Integer> unicodeGlyphIndexes = new Hashtable<Integer,Integer>();
        for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
        {
          Integer code = codes.get(new ByteArray(new byte[]{(byte)(int)glyphIndexEntry.getKey()}));
          if(code == null)
            continue;

          unicodeGlyphIndexes.put(code,glyphIndexEntry.getValue());
        }
        glyphIndexes = unicodeGlyphIndexes;
      }
    }

    PdfDataObject encodingObject = getBaseDataObject().resolve(PdfName.Encoding);
    EnumSet<FlagsEnum> flags = getFlags();
    if(flags.contains(FlagsEnum.Symbolic)
      || (!flags.contains(FlagsEnum.Nonsymbolic) && encodingObject == null)) // Symbolic.
    {
      symbolic = true;

      if(glyphIndexes == null)
      {
        /*
          NOTE: In case no font file is available, we have to synthesize its metrics
          from existing entries.
        */
        glyphIndexes = new Hashtable<Integer,Integer>();
        PdfArray glyphWidthObjects = (PdfArray)getBaseDataObject().resolve(PdfName.Widths);
        if(glyphWidthObjects != null)
        {
          int code = ((PdfInteger)getBaseDataObject().get(PdfName.FirstChar)).getRawValue();
          for(PdfDirectObject glyphWidthObject : glyphWidthObjects)
          {
            if(((PdfInteger)glyphWidthObject).getRawValue() > 0)
            {glyphIndexes.put(code,code);}

            code++;
          }
        }
      }

      if(codes == null)
      {
        Map<ByteArray,Integer> codes = new HashMap<ByteArray,Integer>();
        for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
        {
          if(glyphIndexEntry.getValue() > 0)
          {
            int glyphCharCode = glyphIndexEntry.getKey();
            byte[] charCode = new byte[]{(byte)glyphCharCode};
            codes.put(new ByteArray(charCode),glyphCharCode);
          }
        }
        this.codes = new BiMap<ByteArray,Integer>(codes);
      }
    }
    else // Nonsymbolic.
    {
      symbolic = false;

      if(codes == null)
      {
        Map<ByteArray,Integer> codes;
        if(encodingObject == null) // Default encoding.
        {codes = Encoding.get(PdfName.StandardEncoding).getCodes();}
        else if(encodingObject instanceof PdfName) // Predefined encoding.
        {codes = Encoding.get((PdfName)encodingObject).getCodes();}
        else // Custom encoding.
        {
          PdfDictionary encodingDictionary = (PdfDictionary)encodingObject;

          // 1. Base encoding.
          PdfName baseEncodingName = (PdfName)encodingDictionary.get(PdfName.BaseEncoding);
          if(baseEncodingName == null) // Default base encoding.
          {codes = Encoding.get(PdfName.StandardEncoding).getCodes();}
          else // Predefined base encoding.
          {codes = Encoding.get(baseEncodingName).getCodes();}

          // 2. Differences.
          loadEncodingDifferences(encodingDictionary, codes);
        }
        this.codes = new BiMap<ByteArray,Integer>(codes);
      }

      if(glyphIndexes == null)
      {
        /*
          NOTE: In case no font file is available, we have to synthesize its metrics
          from existing entries.
        */
        glyphIndexes = new Hashtable<Integer,Integer>();
        PdfArray glyphWidthObjects = (PdfArray)getBaseDataObject().resolve(PdfName.Widths);
        if(glyphWidthObjects != null)
        {
          ByteArray charCode = new ByteArray(
            new byte[]
            {(byte)(int)((PdfInteger)getBaseDataObject().get(PdfName.FirstChar)).getRawValue()}
            );
          for(PdfDirectObject glyphWidthObject : glyphWidthObjects)
          {
View Full Code Here

TOP

Related Classes of org.pdfclown.util.ByteArray

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.