Home » pdfbox-1.1.0-src » org.apache.fontbox.ttf » [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.ttf;
   18   
   19   import java.io.IOException;
   20   
   21   /**
   22    * A table in a true type font.
   23    * 
   24    * @author Ben Litchfield (ben@benlitchfield.com)
   25    * @version $Revision: 1.1 $
   26    */
   27   public class IndexToLocationTable extends TTFTable
   28   {
   29       private static final short SHORT_OFFSETS = 0;
   30       private static final short LONG_OFFSETS = 1;
   31       
   32       /**
   33        * A tag that identifies this table type.
   34        */
   35       public static final String TAG = "loca";
   36       
   37       private long[] offsets;
   38       
   39       /**
   40        * This will read the required data from the stream.
   41        * 
   42        * @param ttf The font that is being read.
   43        * @param data The stream to read the data from.
   44        * @throws IOException If there is an error reading the data.
   45        */
   46       public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException
   47       {
   48           HeaderTable head = ttf.getHeader();
   49           MaximumProfileTable maxp = ttf.getMaximumProfile();
   50           int numGlyphs = maxp.getNumGlyphs();
   51           offsets = new long[ numGlyphs +1];
   52           for( int i=0; i<numGlyphs+1; i++ )
   53           {
   54               if( head.getIndexToLocFormat() == SHORT_OFFSETS )
   55               {
   56                   offsets[i] = data.readUnsignedShort() * 2;
   57               }
   58               else if(  head.getIndexToLocFormat() == LONG_OFFSETS )
   59               {
   60                   offsets[i] = data.readUnsignedInt();
   61               }
   62               else
   63               {
   64                   throw new IOException( "Error:TTF.loca unknown offset format.");
   65               }
   66           }
   67       }
   68       /**
   69        * @return Returns the offsets.
   70        */
   71       public long[] getOffsets()
   72       {
   73           return offsets;
   74       }
   75       /**
   76        * @param offsetsValue The offsets to set.
   77        */
   78       public void setOffsets(long[] offsetsValue)
   79       {
   80           this.offsets = offsetsValue;
   81       }
   82   }

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