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 LocaTable implements Table { 29 30 private byte[] buf = null; 31 private int[] offsets = null; 32 private short factor = 0; 33 34 protected LocaTable(DirectoryEntry de, RandomAccessFile raf) throws IOException { 35 raf.seek(de.getOffset()); 36 buf = new byte[de.getLength()]; 37 raf.read(buf); 38 } 39 40 public void init(int numGlyphs, boolean shortEntries) { 41 if (buf == null) { 42 return; 43 } 44 offsets = new int[numGlyphs + 1]; 45 ByteArrayInputStream bais = new ByteArrayInputStream (buf); 46 if (shortEntries) { 47 factor = 2; 48 for (int i = 0; i <= numGlyphs; i++) { 49 offsets[i] = (bais.read()<<8 | bais.read()); 50 } 51 } else { 52 factor = 1; 53 for (int i = 0; i <= numGlyphs; i++) { 54 offsets[i] = (bais.read()<<24 | bais.read()<<16 | 55 bais.read()<< 8 | bais.read()); 56 } 57 } 58 buf = null; 59 } 60 61 public int getOffset(int i) { 62 if (offsets == null) { 63 return 0; 64 } 65 return offsets[i] * factor; 66 } 67 68 public int getType() { 69 return loca; 70 } 71 } 72 | Popular Tags |