Beispiel #1
0
  /** write TrueType file to the random access file */
  public void write() throws IOException {
    m_cmap.write();
    // hmtx must be written before hhea
    m_hmtx.write();
    m_hhea.write();

    m_glyf.write();
    m_loca.write();

    m_head.setCheckSumAdjustment(0);
    m_head.write();
    m_maxp.write(); // must be written after m_glyf
    m_hdmx.write();
    m_name.write();
    m_post.write();
    m_os2.write();

    writeTableDirectory();
    byte[] tableDir = toByteArray();
    for (FontFormatWriter table : m_tables) {
      m_buffer.write(table.toByteArray());
    } // for table

    long checkSum = 0xb1b0afba - (0xffffffff & getCheckSum());
    m_head.setCheckSumAdjustment(checkSum);
    m_head.reset();
    m_head.write();

    reset();

    m_buffer.write(tableDir);
    for (FontFormatWriter table : m_tables) {
      m_buffer.write(table.toByteArray());
    } // for table

    //		FileOutputStream writer = new FileOutputStream(m_file);
    //		writer.write(toByteArray());
    //		writer.close();
  }
Beispiel #2
0
  /**
   * writes table directory.
   *
   * @throws IOException
   */
  private void writeTableDirectory() throws IOException {
    int headerLength = m_tables.size() * 16 + 16;
    int tableOffset = headerLength;
    for (FontFormatWriter table : m_tables) {
      table.setOffset(tableOffset);
      tableOffset += table.size();
    } // for table

    ArrayList<FontFormatWriter> tables = (ArrayList<FontFormatWriter>) m_tables.clone();
    Collections.sort(
        tables,
        new Comparator<FontFormatWriter>() {
          public int compare(FontFormatWriter a_lhs, FontFormatWriter a_rhs) {
            return a_lhs.getTag().compareTo(a_rhs.getTag());
          }

          public boolean equals(Object a_value) {
            return false;
          }
        });

    writeFixed32(1.0);

    int numOfTables = tables.size();
    writeUInt16(numOfTables);
    int searchRange = getSearchRange(numOfTables);
    writeUInt16(searchRange);
    int entrySelector = getEntrySelector(numOfTables);
    writeUInt16(entrySelector);
    writeUInt16(numOfTables * 16 - searchRange);

    for (FontFormatWriter table : tables) {
      writeTag(table.getTag());
      writeUInt32(table.getCheckSum());
      writeUInt32(table.getOffset());
      writeUInt32(table.size());
    } // for

    // padding is always 4 zeros
    for (int i = 0; i < 4; i++) {
      writeUInt8(0);
    } // for i
  }