Example #1
0
    /**
     * Is the font ready to build?
     *
     * @return true if ready to build; false otherwise
     */
    public boolean readyToBuild() {
      // just read in data with no manipulation
      if (this.tableBuilders == null && this.dataBlocks != null && this.dataBlocks.size() > 0) {
        return true;
      }

      for (Table.Builder<? extends Table> tableBuilder : this.tableBuilders.values()) {
        if (tableBuilder.readyToBuild() == false) {
          return false;
        }
      }
      return true;
    }
Example #2
0
    private static Map<Integer, Table> buildTablesFromBuilders(
        Font font, Map<Integer, Table.Builder<? extends Table>> builderMap) {
      Map<Integer, Table> tableMap = new TreeMap<Integer, Table>();

      interRelateBuilders(builderMap);

      long fontChecksum = 0;
      boolean tablesChanged = false;
      FontHeaderTable.Builder headerTableBuilder = null;

      // now build all the tables
      for (Table.Builder<? extends Table> builder : builderMap.values()) {
        Table table = null;
        if (Tag.isHeaderTable(builder.header().tag())) {
          headerTableBuilder = (FontHeaderTable.Builder) builder;
          continue;
        }
        if (builder.readyToBuild()) {
          tablesChanged |= builder.changed();
          table = builder.build();
        }
        if (table == null) {
          throw new RuntimeException("Unable to build table - " + builder);
        }
        long tableChecksum = table.calculatedChecksum();
        fontChecksum += tableChecksum;
        tableMap.put(table.header().tag(), table);
      }

      // now fix up the header table
      Table headerTable = null;
      if (headerTableBuilder != null) {
        if (tablesChanged) {
          headerTableBuilder.setFontChecksum(fontChecksum);
        }
        if (headerTableBuilder.readyToBuild()) {
          tablesChanged |= headerTableBuilder.changed();
          headerTable = headerTableBuilder.build();
        }
        if (headerTable == null) {
          throw new RuntimeException("Unable to build table - " + headerTableBuilder);
        }
        fontChecksum += headerTable.calculatedChecksum();
        tableMap.put(headerTable.header().tag(), headerTable);
      }

      font.checksum = fontChecksum & 0xffffffffL;
      return tableMap;
    }
Example #3
0
    /**
     * Creates a new empty table builder for the table type given by the table id tag.
     *
     * <p>This new table will be added to the font and will replace any existing builder for that
     * table.
     *
     * @param tag
     * @return new empty table of the type specified by tag; if tag is not known then a generic
     *     OpenTypeTable is returned
     */
    public Table.Builder<? extends Table> newTableBuilder(int tag) {
      Header header = new Header(tag);
      Table.Builder<? extends Table> builder = Table.Builder.getBuilder(header, null);
      this.tableBuilders.put(header.tag(), builder);

      return builder;
    }
Example #4
0
    /**
     * Creates a new table builder for the table type given by the table id tag. It makes a copy of
     * the data provided and uses that copy for the table.
     *
     * <p>This new table has been added to the font and will replace any existing builder for that
     * table.
     *
     * @param tag
     * @param srcData
     * @return new empty table of the type specified by tag; if tag is not known then a generic
     *     OpenTypeTable is returned
     */
    public Table.Builder<? extends Table> newTableBuilder(int tag, ReadableFontData srcData) {
      WritableFontData data;
      data = WritableFontData.createWritableFontData(srcData.length());
      // TODO(stuartg): take over original data instead?
      srcData.copyTo(data);

      Header header = new Header(tag, data.length());
      Table.Builder<? extends Table> builder = Table.Builder.getBuilder(header, data);

      this.tableBuilders.put(tag, builder);

      return builder;
    }
Example #5
0
 private Table.Builder<? extends Table> getTableBuilder(Header header, WritableFontData data) {
   Table.Builder<? extends Table> builder = Table.Builder.getBuilder(header, data);
   return builder;
 }