Пример #1
0
 private void loadFont(InputStream is) throws IOException {
   if (is == null) {
     throw new IOException("No input stream for font.");
   }
   FontInputStream fontIS = null;
   try {
     fontIS = new FontInputStream(is);
     SortedSet<Header> records = readHeader(fontIS);
     this.dataBlocks = loadTableData(records, fontIS);
     this.tableBuilders = buildAllTableBuilders(this.dataBlocks);
   } finally {
     fontIS.close();
   }
 }
Пример #2
0
 private Map<Header, WritableFontData> loadTableData(
     SortedSet<Header> headers, FontInputStream is) throws IOException {
   Map<Header, WritableFontData> tableData =
       new HashMap<Header, WritableFontData>(headers.size());
   logger.fine("########  Reading Table Data");
   for (Header tableHeader : headers) {
     is.skip(tableHeader.offset() - is.position());
     logger.finer("\t" + tableHeader);
     logger.finest("\t\tStream Position = " + Integer.toHexString((int) is.position()));
     // don't close this or the whole stream is gone
     FontInputStream tableIS = new FontInputStream(is, tableHeader.length());
     // TODO(stuartg): start tracking bad tables and other errors
     WritableFontData data = WritableFontData.createWritableFontData(tableHeader.length());
     data.copyFrom(tableIS, tableHeader.length());
     tableData.put(tableHeader, data);
   }
   return tableData;
 }
Пример #3
0
    private SortedSet<Header> readHeader(FontInputStream is) throws IOException {
      SortedSet<Header> records = new TreeSet<Header>(Header.COMPARATOR_BY_OFFSET);

      this.sfntVersion = is.readFixed();
      this.numTables = is.readUShort();
      this.searchRange = is.readUShort();
      this.entrySelector = is.readUShort();
      this.rangeShift = is.readUShort();

      for (int tableNumber = 0; tableNumber < this.numTables; tableNumber++) {
        Header table =
            new Header(
                is.readULongAsInt(), // safe since the tag is ASCII
                is.readULong(), // checksum
                is.readULongAsInt(), // offset
                is.readULongAsInt()); // length
        records.add(table);
      }
      return records;
    }