示例#1
0
  public static Table create(
      final OTFontCollection fc,
      final OTFont font,
      final DirectoryEntry de,
      final DataInputStream dis)
      throws IOException {
    Table t = null;

    // First, if we have a font collection, look for the table there
    if (fc != null) {
      t = fc.getTable(de);
      if (t != null) {
        return t;
      }
    }

    // Create the table
    switch (de.getTag()) {
      case Table.BASE:
        t = new BaseTable(de, dis);
        break;
      case Table.CFF:
        t = new CffTable(de, dis);
        break;
      case Table.DSIG:
        t = new DsigTable(de, dis);
        break;
      case Table.EBDT:
        break;
      case Table.EBLC:
        break;
      case Table.EBSC:
        break;
      case Table.GDEF:
        break;
      case Table.GPOS:
        t = new GposTable(de, dis);
        break;
      case Table.GSUB:
        t = new GsubTable(de, dis);
        break;
      case Table.JSTF:
        break;
      case Table.LTSH:
        t = new LtshTable(de, dis);
        break;
      case Table.MMFX:
        break;
      case Table.MMSD:
        break;
      case Table.OS_2:
        t = new Os2Table(de, dis);
        break;
      case Table.PCLT:
        t = new PcltTable(de, dis);
        break;
      case Table.VDMX:
        t = new VdmxTable(de, dis);
        break;
      case Table.cmap:
        t = new CmapTable(de, dis);
        break;
      case Table.cvt:
        t = new CvtTable(de, dis);
        break;
      case Table.fpgm:
        t = new FpgmTable(de, dis);
        break;
      case Table.fvar:
        break;
      case Table.gasp:
        t = new GaspTable(de, dis);
        break;
      case Table.glyf:
        t = new GlyfTable(de, dis, font.getMaxpTable(), font.getLocaTable());
        break;
      case Table.hdmx:
        t = new HdmxTable(de, dis, font.getMaxpTable());
        break;
      case Table.head:
        t = new HeadTable(de, dis);
        break;
      case Table.hhea:
        t = new HheaTable(de, dis);
        break;
      case Table.hmtx:
        t = new HmtxTable(de, dis, font.getHheaTable(), font.getMaxpTable());
        break;
      case Table.kern:
        t = new KernTable(de, dis);
        break;
      case Table.loca:
        t = new LocaTable(de, dis, font.getHeadTable(), font.getMaxpTable());
        break;
      case Table.maxp:
        t = new MaxpTable(de, dis);
        break;
      case Table.name:
        t = new NameTable(de, dis);
        break;
      case Table.prep:
        t = new PrepTable(de, dis);
        break;
      case Table.post:
        t = new PostTable(de, dis);
        break;
      case Table.vhea:
        t = new VheaTable(de, dis);
        break;
      case Table.vmtx:
        t = new VmtxTable(de, dis, font.getVheaTable(), font.getMaxpTable());
        break;
    }

    // If we have a font collection, add this table to it
    if ((fc != null) && (t != null)) {
      fc.addTable(t);
    }
    return t;
  }
示例#2
0
  public TypecastFont(OTFontCollection fontset) throws FontException {
    this.fontset = fontset;
    this.font = fontset.getFont(0);

    // Generic attempt to find the best CmapTable,
    // which is assumed to be the one with the most entries (stupid 'eh?)
    CmapTable cmapTable = font.getCmapTable();
    CmapFormat[] cmapFormatP = {null, null, null, null};
    int platform = -1;
    int platformLength = -1;
    int encoding = -1;
    for (int i = 0; i < cmapTable.getNumTables(); i++) {
      CmapIndexEntry cmapIdxEntry = cmapTable.getCmapIndexEntry(i);
      int pidx = cmapIdxEntry.getPlatformId();
      CmapFormat cf = cmapIdxEntry.getFormat();
      if (DEBUG) {
        logger.debug(
            "CmapFormat["
                + i
                + "]: platform "
                + pidx
                + ", encoding "
                + cmapIdxEntry.getEncodingId()
                + ": "
                + cf);
      }
      if (cmapFormatP[pidx] == null || cmapFormatP[pidx].getLength() < cf.getLength()) {
        cmapFormatP[pidx] = cf;
        if (cf.getLength() > platformLength) {
          platformLength = cf.getLength();
          platform = pidx;
          encoding = cmapIdxEntry.getEncodingId();
        }
      }
    }
    if (0 <= platform) {
      cmapFormat = cmapFormatP[platform];
      if (DEBUG) {
        logger.debug(
            "Selected CmapFormat: platform "
                + platform
                + ", encoding "
                + encoding
                + ": "
                + cmapFormat);
      }
    } else {
      CmapFormat tmpCmapFormat = null;

      if (null == tmpCmapFormat) {
        // default unicode
        platform = ID.platformMicrosoft;
        encoding = ID.encodingUnicode;
        tmpCmapFormat = cmapTable.getCmapFormat((short) platform, (short) encoding);
      }
      if (null == tmpCmapFormat) {
        // maybe a symbol font ?
        platform = ID.platformMicrosoft;
        encoding = ID.encodingSymbol;
        tmpCmapFormat = cmapTable.getCmapFormat((short) platform, (short) encoding);
      }
      if (null == tmpCmapFormat) {
        throw new FontException("Cannot find a suitable cmap table for font " + font);
      }
      cmapFormat = tmpCmapFormat;
      if (DEBUG) {
        logger.debug(
            "Selected CmapFormat (2): platform "
                + platform
                + ", encoding "
                + encoding
                + ": "
                + cmapFormat);
      }
    }

    cmapentries = 0;
    for (int i = 0; i < cmapFormat.getRangeCount(); ++i) {
      CmapFormat.Range range = cmapFormat.getRange(i);
      cmapentries = cmapentries + (range.getEndCode() - range.getStartCode() + 1); // end
      // included
    }
    if (DEBUG) {
      logger.debug("font direction hint: " + font.getHeadTable().getFontDirectionHint());
      logger.debug("num glyphs: " + font.getNumGlyphs());
      logger.debug("num cmap entries: " + cmapentries);
      logger.debug("num cmap ranges: " + cmapFormat.getRangeCount());

      for (int i = 0; i < cmapFormat.getRangeCount(); ++i) {
        CmapFormat.Range range = cmapFormat.getRange(i);
        for (int j = range.getStartCode(); j <= range.getEndCode(); ++j) {
          final int code = cmapFormat.mapCharCode(j);
          if (code < 15) {
            logger.debug(" char: " + j + " ( " + (char) j + " ) -> " + code);
          }
        }
      }
    }
    char2Glyph = new IntObjectHashMap(cmapentries + cmapentries / 4);
  }