1 50 51 package com.lowagie.text.pdf; 52 53 import java.io.IOException ; 54 import java.util.HashMap ; 55 56 import com.lowagie.text.DocumentException; 57 61 class EnumerateTTC extends TrueTypeFont{ 62 63 protected String [] names; 64 65 EnumerateTTC(String ttcFile) throws DocumentException, IOException { 66 fileName = ttcFile; 67 rf = new RandomAccessFileOrArray(ttcFile); 68 findNames(); 69 } 70 71 EnumerateTTC(byte ttcArray[]) throws DocumentException, IOException { 72 fileName = "Byte array TTC"; 73 rf = new RandomAccessFileOrArray(ttcArray); 74 findNames(); 75 } 76 77 void findNames() throws DocumentException, IOException { 78 tables = new HashMap (); 79 80 try { 81 String mainTag = readStandardString(4); 82 if (!mainTag.equals("ttcf")) 83 throw new DocumentException(fileName + " is not a valid TTC file."); 84 rf.skipBytes(4); 85 int dirCount = rf.readInt(); 86 names = new String [dirCount]; 87 int dirPos = rf.getFilePointer(); 88 for (int dirIdx = 0; dirIdx < dirCount; ++dirIdx) { 89 tables.clear(); 90 rf.seek(dirPos); 91 rf.skipBytes(dirIdx * 4); 92 directoryOffset = rf.readInt(); 93 rf.seek(directoryOffset); 94 if (rf.readInt() != 0x00010000) 95 throw new DocumentException(fileName + " is not a valid TTF file."); 96 int num_tables = rf.readUnsignedShort(); 97 rf.skipBytes(6); 98 for (int k = 0; k < num_tables; ++k) { 99 String tag = readStandardString(4); 100 rf.skipBytes(4); 101 int table_location[] = new int[2]; 102 table_location[0] = rf.readInt(); 103 table_location[1] = rf.readInt(); 104 tables.put(tag, table_location); 105 } 106 names[dirIdx] = getBaseFont(); 107 } 108 } 109 finally { 110 if (rf != null) 111 rf.close(); 112 } 113 } 114 115 String [] getNames() { 116 return names; 117 } 118 119 } 120 | Popular Tags |