1 18 package org.apache.batik.svggen.font.table; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 22 import java.io.RandomAccessFile ; 23 24 28 public class HmtxTable implements Table { 29 30 private byte[] buf = null; 31 private int[] hMetrics = null; 32 private short[] leftSideBearing = null; 33 34 protected HmtxTable(DirectoryEntry de,RandomAccessFile raf) throws IOException { 35 raf.seek(de.getOffset()); 36 buf = new byte[de.getLength()]; 37 raf.read(buf); 38 53 } 54 55 public void init(int numberOfHMetrics, int lsbCount) { 56 if (buf == null) { 57 return; 58 } 59 hMetrics = new int[numberOfHMetrics]; 60 ByteArrayInputStream bais = new ByteArrayInputStream (buf); 61 for (int i = 0; i < numberOfHMetrics; i++) { 62 hMetrics[i] = (bais.read()<<24 | bais.read()<<16 | 63 bais.read()<< 8 | bais.read()); 64 } 65 if (lsbCount > 0) { 66 leftSideBearing = new short[lsbCount]; 67 for (int i = 0; i < lsbCount; i++) { 68 leftSideBearing[i] = (short)(bais.read()<<8 | bais.read()); 69 } 70 } 71 buf = null; 72 } 73 74 public int getAdvanceWidth(int i) { 75 if (hMetrics == null) { 76 return 0; 77 } 78 if (i < hMetrics.length) { 79 return hMetrics[i] >> 16; 80 } else { 81 return hMetrics[hMetrics.length - 1] >> 16; 82 } 83 } 84 85 public short getLeftSideBearing(int i) { 86 if (hMetrics == null) { 87 return 0; 88 } 89 if (i < hMetrics.length) { 90 return (short)(hMetrics[i] & 0xffff); 91 } else { 92 return leftSideBearing[i - hMetrics.length]; 93 } 94 } 95 96 public int getType() { 97 return hmtx; 98 } 99 } 100 | Popular Tags |