• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java CMap类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.google.typography.font.sfntly.table.core.CMap的典型用法代码示例。如果您正苦于以下问题:Java CMap类的具体用法?Java CMap怎么用?Java CMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

CMap类属于com.google.typography.font.sfntly.table.core包,在下文中一共展示了CMap类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: glyphGroupForText

点赞 3

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
public static GlyphGroup glyphGroupForText(String str, CMapTable cmapTable) {
  GlyphGroup glyphGroup = new GlyphGroup();
  Set<Integer> codes = codepointsFromStr(str);
  for (int code : codes) {
    for (CMap cmap : cmapTable) {
      if (cmap.platformId() == 3 && cmap.encodingId() == 1 || // Unicode BMP
          cmap.platformId() == 3 && cmap.encodingId() == 10 || // UCS2
          cmap.platformId() == 0 && cmap.encodingId() == 5) { // Variation
        int glyph = cmap.glyphId(code);
        if (glyph != CMapTable.NOTDEF) {
          glyphGroup.add(glyph);
        }
        // System.out.println("code: " + code + " glyph: " + glyph + " platform: " + cmap.platformId() + " encodingId: " + cmap.encodingId() + " format: " + cmap.format());

      }
    }
  }
  return glyphGroup;
}
 

开发者ID:terro,
项目名称:WCFont,
代码行数:20,
代码来源:Rule.java

示例2: getUCSCMap

点赞 3

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
/**
 * Gets either a UCS4 or UCS2 cmap, if available
 *
 * @param font
 *          the source font
 * @return the UCS4 or UCS2 cmap
 * @throws UnsupportedOperationException
 *           if font does not contain a UCS-4 or UCS-2 cmap
 */
public static CMap getUCSCMap(Font font) {
  CMapTable cmapTable = getCMapTable(font);

  // Obtain the UCS-4 cmap. If it doesn't exist, then obtain the UCS-2 cmap
  CMap cmap = null;
  cmap = cmapTable.cmap(
      Font.PlatformId.Windows.value(), Font.WindowsEncodingId.UnicodeUCS4.value());
  if (cmap == null) {
    cmap = cmapTable.cmap(
        Font.PlatformId.Windows.value(), Font.WindowsEncodingId.UnicodeUCS2.value());
  }
  if (cmap == null) {
    throw new UnsupportedOperationException("Font has no UCS-4 or UCS-2 cmap");
  }

  return cmap;
}
 

开发者ID:terro,
项目名称:WCFont,
代码行数:27,
代码来源:FontUtils.java

示例3: listCmaps

点赞 3

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
/**
 * Gets a list containing the platform ID, encoding ID, and format of all the
 * cmaps in a font
 *
 * @param font
 *          the source font
 * @return a list of information about the cmaps in the font
 */
public static DataDisplayTable listCmaps(Font font) {
  String[] header = { "Platform ID", "Encoding ID", "Format" };
  Align[] displayAlignment = { Align.Right, Align.Right, Align.Right };
  DataDisplayTable table = new DataDisplayTable(Arrays.asList(header));
  table.setAlignment(Arrays.asList(displayAlignment));

  // Add information about each individual cmap in the table
  CMapTable cmapTable = FontUtils.getCMapTable(font);
  for (CMap cmap : cmapTable) {
    String[] data = { String.format("%d", cmap.platformId()),
        String.format("%d", cmap.encodingId()), String.format("%d", cmap.format()) };
    table.add(Arrays.asList(data));
  }

  return table;
}
 

开发者ID:terro,
项目名称:WCFont,
代码行数:25,
代码来源:FontInfo.java

示例4: listChars

点赞 3

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
/**
 * Gets a list of code points of valid characters and their names in the given
 * font.
 *
 * @param font
 *          the source font
 * @return a list of code points of valid characters and their names in the
 *         given font.
 * @throws UnsupportedOperationException
 *           if font does not contain a UCS-4 or UCS-2 cmap
 */
public static DataDisplayTable listChars(Font font) {
  String[] header = { "Code point", "Glyph ID", "Unicode-designated name for code point" };
  Align[] displayAlignment = { Align.Right, Align.Right, Align.Left };
  DataDisplayTable table = new DataDisplayTable(Arrays.asList(header));
  table.setAlignment(Arrays.asList(displayAlignment));

  // Iterate through all code points
  CMap cmap = FontUtils.getUCSCMap(font);
  for (int charId : cmap) {
    int glyphId = cmap.glyphId(charId);
    if (glyphId != CMapTable.NOTDEF) {
      String[] data = { FontUtils.getFormattedCodePointString(charId),
          String.format("%d", glyphId), UCharacter.getExtendedName(charId) };
      table.add(Arrays.asList(data));
    }
  }

  return table;
}
 

开发者ID:terro,
项目名称:WCFont,
代码行数:31,
代码来源:FontInfo.java

示例5: listUnmappedGlyphs

点赞 3

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
/**
 * Gets a list of IDs for glyphs that are not mapped by any cmap in the font
 *
 * @param font
 *          the source font
 * @return a list of unmapped glyphs
 */
public static DataDisplayTable listUnmappedGlyphs(Font font) {
  String[] header = { "Glyph ID" };
  Align[] displayAlignment = { Align.Right };
  DataDisplayTable table = new DataDisplayTable(Arrays.asList(header));
  table.setAlignment(Arrays.asList(displayAlignment));

  // Get a set of all mapped glyph IDs
  Set<Integer> mappedGlyphs = new HashSet<Integer>();
  CMapTable cmapTable = FontUtils.getCMapTable(font);
  for (CMap cmap : cmapTable) {
    for (Integer codePoint : cmap) {
      mappedGlyphs.add(cmap.glyphId(codePoint));
    }
  }

  // Iterate through all glyph IDs and check if in the set
  LocaTable locaTable = FontUtils.getLocaTable(font);
  for (int i = 0; i < locaTable.numGlyphs(); i++) {
    if (!mappedGlyphs.contains(i)) {
      table.add(Arrays.asList(new String[] { String.format("%d", i) }));
    }
  }

  return table;
}
 

开发者ID:terro,
项目名称:WCFont,
代码行数:33,
代码来源:FontInfo.java

示例6: testCMap4WithNoEditing

点赞 3

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
public void testCMap4WithNoEditing() throws Exception {
  Font.Builder fontBuilder = TestFontUtils.builderForFontFile(TEST_FONT_FILE);
  CMapTable.Builder cmapTableBuilder = (CMapTable.Builder) fontBuilder.getTableBuilder(Tag.cmap);

  CMap.Builder<? extends CMap> cmapBuilder =
      cmapTableBuilder.cmapBuilder(CMapId.WINDOWS_BMP);
  assertEquals(cmapBuilder.format(), CMapFormat.Format4);
  
  // build and test the changed font
  Font newFont = fontBuilder.build();
  if (DEBUG) {
    // serialize changed font for debugging
    File dstFontFile = TestFontUtils.serializeFont(newFont, ".ttf");
    System.out.println(dstFontFile);
  }
  CMapTable newCMapTable = newFont.getTable(Tag.cmap);
  CMap newCMap = newCMapTable.cmap(CMapId.WINDOWS_BMP);
  assertNotNull(newCMap);
}
 

开发者ID:witwall,
项目名称:sfntly-java
代码行数:20,
代码来源:CMapEditingTests.java

示例7: dumpChar

点赞 2

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
private void dumpChar(int charId, CMap cmap, LocaTable locaTable, GlyphTable glyphTable) {
  int glyphId = cmap.glyphId(charId);
  int offset = locaTable.glyphOffset(glyphId);
  int length = locaTable.glyphLength(glyphId);
  Glyph glyph = glyphTable.glyph(offset, length);
  System.out.println("char = 0x" + Integer.toHexString(charId) + ", glyph id = 0x"
      + Integer.toHexString(glyphId));
  if (glyph != null) {
    System.out.println(glyph);
  } else {
    System.out.println();
  }
}
 

开发者ID:witwall,
项目名称:sfntly-java
代码行数:14,
代码来源:SfntDump.java

示例8: dumpCMapMapping

点赞 2

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
private void dumpCMapMapping(CMap cmap) {
  Iterator<Integer> iter = cmap.iterator();
  while (iter.hasNext()) {
    int c = iter.next();
    int g = cmap.glyphId(c);
    if (g != CMapTable.NOTDEF) {
      System.out.printf("%x -> %x\n", c, g);
    }
  }
}
 

开发者ID:witwall,
项目名称:sfntly-java
代码行数:11,
代码来源:SfntDump.java

示例9: testCMap4Editing

点赞 2

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
public void testCMap4Editing() throws Exception {
  Font.Builder fontBuilder = TestFontUtils.builderForFontFile(TEST_FONT_FILE);
  CMapTable.Builder cmapTableBuilder = (CMapTable.Builder) fontBuilder.getTableBuilder(Tag.cmap);

  CMap.Builder<? extends CMap> cmapBuilder = 
    cmapTableBuilder.cmapBuilder(CMapId.WINDOWS_BMP);
  if (cmapBuilder.format() != CMapFormat.Format4) {
    fail("Windows BMP CMap is not Format 4.");
  }

  if (DEBUG) {
    System.out.println(cmapBuilder.toString());
  }

  CMapFormat4.Builder cmapFormat4Builder = (CMapFormat4.Builder) cmapBuilder;
  List<CMapFormat4.Builder.Segment> segments = cmapFormat4Builder.getSegments();
  List<Integer> glyphIdArray = cmapFormat4Builder.getGlyphIdArray();

  int segmentModified = -1;
  int newStartCode = 'd';
  int newIdDelta = 0;
  for (int i = 0; i < segments.size(); i++) {
    CMapFormat4.Builder.Segment segment = segments.get(i);
    if ('a' > segment.getStartCount() && 'a' < segment.getEndCount()) {
      if (DEBUG) {
        System.out.println(segment);
      }
      segmentModified = i;
      newIdDelta = segment.getIdDelta() + 1;
      segment.setIdDelta(newIdDelta);
      segment.setStartCount(newStartCode);
    }
  }
  cmapFormat4Builder.setSegments(segments);

  // build and test the changed font
  Font newFont = fontBuilder.build();    
  if (DEBUG) {
    // serialize changed font for debugging
    File dstFontFile = TestFontUtils.serializeFont(newFont, ".ttf");
    System.out.println(dstFontFile);
  }
  CMapTable newCMapTable = newFont.getTable(Tag.cmap);
  CMap newCMap = newCMapTable.cmap(CMapId.WINDOWS_BMP);

  //Font originalFont = TestFontUtils.loadFont(TEST_FONT_FILE)[0];
  //CMapTable cmapTable = originalFont.table(Tag.cmap);
  //CMapTable.CMap cmap = cmapTable.cmap(CMapId.WINDOWS_BMP);
  assertEquals(CMapFormat.Format4.value(), newCMap.format());
  assertTrue(segmentModified >= 0);
  CMapFormat4 cmap4 = (CMapFormat4) newCMap;
  assertEquals(newStartCode, cmap4.startCode(segmentModified));
  assertEquals(newIdDelta, cmap4.idDelta(segmentModified));
  if (DEBUG) {
    int c = 32;
    int gid = newCMap.glyphId(c);
    int newGid = newCMap.glyphId(c);
    System.out.printf("char = %x => original gid = %x, new gid = %x\n", c, gid, newGid);
  }
}
 

开发者ID:witwall,
项目名称:sfntly-java
代码行数:61,
代码来源:CMapEditingTests.java

示例10: buildAndCheckFont

点赞 2

import com.google.typography.font.sfntly.table.core.CMap; //导入依赖的package包/类
public static
Font[] buildAndCheckFont(FontFactory fontFactory, InputStream is, int debug) throws IOException {

  Font[] fontArray = fontFactory.loadFonts(is);

  for (Font font : fontArray) {

    if (debug >= 1) {
      logger.info(font.toString());
    }

    FontHeaderTable head = font.getTable(Tag.head);
    if (head != null) {
      long magicNumber = head.magicNumber();
      if (0x5F0F3CF5 != magicNumber) {
        throw new RuntimeException("Magic number is incorrect.");
      }
      if (debug >= 2) {
        logger.fine("magic number = " + Long.toHexString(magicNumber));
        MaximumProfileTable maxp = font.getTable(Tag.maxp);
        logger.fine("Number of glyphs = " + maxp.numGlyphs());
        logger.fine("\n------ Tables by File Location");
      }
    } else {
      // should find a bhed table if no head table
      FontDataTable bhed = font.getTable(Tag.intValue("bhed"));
      if (bhed == null) {
        throw new RuntimeException("No head table or bhed");
      }
    }

    Set<Table> tables = new TreeSet<Table>(TABLE_COMPARATOR_BY_OFFSET);
    tables.addAll(font.tableMap().values());

    for (Table table : tables) {
      if (debug >= 2) {
        System.out.println(table);
      }
      Header header = table.header();
      boolean csValid = table.calculatedChecksum() == header.checksum();
      if (!csValid) {
        logger.severe("\t**** Checksum not valid!");
        logger.severe("\tcalculated = 0x" + Long.toHexString(table.calculatedChecksum()));
        logger.severe("\tread       = 0x" + Long.toHexString(header.checksum()));
        throw new RuntimeException("Checksum for table " + Tag.stringValue(header.tag()));
      }
    }

    if (debug >= 2) {
      logger.fine("\n------ CMap Tables");
      CMapTable cmap = (CMapTable) font.getTable(Tag.cmap);
      for (CMap cmt : cmap) {
        logger.fine(cmt.toString());
        for (int c = 0; c < 256; c++) {
          logger.finer(c + " = " + cmt.glyphId(c));
        }
      }

      logger.fine("\n----- Name Tables");
      NameTable name = (NameTable) font.getTable(Tag.name);
      for (NameEntry entry : name) {
        logger.finer(entry.toString());
      }
    }
  }
  return fontArray;
}
 

开发者ID:witwall,
项目名称:sfntly-java
代码行数:68,
代码来源:TestFontUtils.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)