Home » pdfbox-1.1.0-src » org.apache.fontbox.cmap » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.fontbox.cmap;
   18   
   19   /**
   20    * This represents a single entry in the codespace range.
   21    *
   22    * @author Ben Litchfield (ben@benlitchfield.com)
   23    * @version $Revision: 1.1 $
   24    */
   25   public class CodespaceRange
   26   {
   27   
   28       private byte[] start;
   29       private byte[] end;
   30   
   31       /**
   32        * Creates a new instance of CodespaceRange.
   33        */
   34       public CodespaceRange()
   35       {
   36       }
   37   
   38       /** Getter for property end.
   39        * @return Value of property end.
   40        *
   41        */
   42       public byte[] getEnd()
   43       {
   44           return this.end;
   45       }
   46   
   47       /** Setter for property end.
   48        * @param endBytes New value of property end.
   49        *
   50        */
   51       public void setEnd(byte[] endBytes)
   52       {
   53           end = endBytes;
   54       }
   55   
   56       /** Getter for property start.
   57        * @return Value of property start.
   58        *
   59        */
   60       public byte[] getStart()
   61       {
   62           return this.start;
   63       }
   64   
   65       /** Setter for property start.
   66        * @param startBytes New value of property start.
   67        *
   68        */
   69       public void setStart(byte[] startBytes)
   70       {
   71           start = startBytes;
   72       }
   73   
   74       /**
   75        *  Check whether the given byte array is in this codespace range or ot.
   76        *  @param code The byte array to look for in the codespace range.
   77        *  @param offset The starting offset within the byte array.
   78        *  @param length The length of the part of the array.
   79        *  
   80        *  @return true if the given byte array is in the codespace range.
   81        */
   82       public boolean isInRange(byte[] code, int offset, int length)
   83       {
   84           if ( length < start.length || length > end.length ) 
   85           {
   86               return false;
   87           }
   88   
   89           if ( end.length == length ) 
   90           {
   91               for ( int i = 0; i < end.length; i++ ) 
   92               {
   93                   int endInt = ((int)end[i]) & 0xFF;
   94                   int codeInt = ((int)code[offset + i]) & 0xFF;
   95                   if ( endInt < codeInt )
   96                   {
   97                       return false;
   98                   }
   99               }
  100           }
  101           if ( start.length == length ) 
  102           {
  103               for ( int i = 0; i < end.length; i++ ) 
  104               {
  105                   int startInt = ((int)start[i]) & 0xFF;
  106                   int codeInt = ((int)code[offset + i]) & 0xFF;
  107                   if ( startInt > codeInt )
  108                   {
  109                       return false;
  110                   }
  111               }
  112           }
  113           return true;
  114       }
  115   }

Home » pdfbox-1.1.0-src » org.apache.fontbox.cmap » [javadoc | source]