Exemple #1
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;
 }
Exemple #2
0
 private Map<Header, WritableFontData> loadTableData(
     SortedSet<Header> headers, WritableFontData fd) {
   Map<Header, WritableFontData> tableData =
       new HashMap<Header, WritableFontData>(headers.size());
   logger.fine("########  Reading Table Data");
   for (Header tableHeader : headers) {
     WritableFontData data = fd.slice(tableHeader.offset(), tableHeader.length());
     tableData.put(tableHeader, data);
   }
   return tableData;
 }
Exemple #3
0
  /**
   * Searialize the headers.
   *
   * @param fos the destination stream for the headers
   * @param tableHeaders the headers to serialize
   * @throws IOException
   */
  private void serializeHeader(FontOutputStream fos, List<Header> tableHeaders) throws IOException {
    fos.writeFixed(this.sfntVersion);
    fos.writeUShort(tableHeaders.size());
    int log2OfMaxPowerOf2 = FontMath.log2(tableHeaders.size());
    int searchRange = 2 << (log2OfMaxPowerOf2 - 1 + 4);
    fos.writeUShort(searchRange);
    fos.writeUShort(log2OfMaxPowerOf2);
    fos.writeUShort((tableHeaders.size() * 16) - searchRange);

    List<Header> sortedHeaders = new ArrayList<Header>(tableHeaders);
    Collections.sort(sortedHeaders, Header.COMPARATOR_BY_TAG);

    for (Header record : sortedHeaders) {
      fos.writeULong(record.tag());
      fos.writeULong(record.checksum());
      fos.writeULong(record.offset());
      fos.writeULong(record.length());
    }
  }