1 18 package org.apache.batik.svggen.font.table; 19 20 import java.io.IOException ; 21 import java.io.RandomAccessFile ; 22 23 27 public class TableDirectory { 28 29 private int version = 0; 30 private short numTables = 0; 31 private short searchRange = 0; 32 private short entrySelector = 0; 33 private short rangeShift = 0; 34 private DirectoryEntry[] entries; 35 36 public TableDirectory(RandomAccessFile raf) throws IOException { 37 version = raf.readInt(); 38 numTables = raf.readShort(); 39 searchRange = raf.readShort(); 40 entrySelector = raf.readShort(); 41 rangeShift = raf.readShort(); 42 entries = new DirectoryEntry[numTables]; 43 for (int i = 0; i < numTables; i++) { 44 entries[i] = new DirectoryEntry(raf); 45 } 46 47 boolean modified = true; 49 while (modified) { 50 modified = false; 51 for (int i = 0; i < numTables - 1; i++) { 52 if (entries[i].getOffset() > entries[i+1].getOffset()) { 53 DirectoryEntry temp = entries[i]; 54 entries[i] = entries[i+1]; 55 entries[i+1] = temp; 56 modified = true; 57 } 58 } 59 } 60 } 61 62 public DirectoryEntry getEntry(int index) { 63 return entries[index]; 64 } 65 66 public DirectoryEntry getEntryByTag(int tag) { 67 for (int i = 0; i < numTables; i++) { 68 if (entries[i].getTag() == tag) { 69 return entries[i]; 70 } 71 } 72 return null; 73 } 74 75 public short getEntrySelector() { 76 return entrySelector; 77 } 78 79 public short getNumTables() { 80 return numTables; 81 } 82 83 public short getRangeShift() { 84 return rangeShift; 85 } 86 87 public short getSearchRange() { 88 return searchRange; 89 } 90 91 public int getVersion() { 92 return version; 93 } 94 } 95 | Popular Tags |