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 HorizontalMetricsTable extends TTFTable 28 { 29 /** 30 * A tag that identifies this table type. 31 */ 32 public static final String TAG = "hmtx"; 33 34 private int[] advanceWidth; 35 private short[] leftSideBearing; 36 private short[] nonHorizontalLeftSideBearing; 37 38 /** 39 * This will read the required data from the stream. 40 * 41 * @param ttf The font that is being read. 42 * @param data The stream to read the data from. 43 * @throws IOException If there is an error reading the data. 44 */ 45 public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException 46 { 47 HorizontalHeaderTable hHeader = ttf.getHorizontalHeader(); 48 MaximumProfileTable maxp = ttf.getMaximumProfile(); 49 int numHMetrics = hHeader.getNumberOfHMetrics(); 50 int numGlyphs = maxp.getNumGlyphs(); 51 52 advanceWidth = new int[ numHMetrics ]; 53 leftSideBearing = new short[ numHMetrics ]; 54 for( int i=0; i<numHMetrics; i++ ) 55 { 56 advanceWidth[i] = data.readUnsignedShort(); 57 leftSideBearing[i] = data.readSignedShort(); 58 } 59 60 int numberNonHorizontal = numGlyphs - numHMetrics; 61 nonHorizontalLeftSideBearing = new short[ numberNonHorizontal ]; 62 for( int i=0; i<numberNonHorizontal; i++ ) 63 { 64 nonHorizontalLeftSideBearing[i] = data.readSignedShort(); 65 } 66 } 67 /** 68 * @return Returns the advanceWidth. 69 */ 70 public int[] getAdvanceWidth() 71 { 72 return advanceWidth; 73 } 74 /** 75 * @param advanceWidthValue The advanceWidth to set. 76 */ 77 public void setAdvanceWidth(int[] advanceWidthValue) 78 { 79 this.advanceWidth = advanceWidthValue; 80 } 81 }