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

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

java 1次浏览

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

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

示例1: hintingSize

点赞 3

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
/**
 * Gets the size of hinting instructions in the glyph table, both in bytes and
 * as a fraction of the glyph table size.
 *
 * @param font
 *          the source font
 * @return the amount of hinting that is contained in the font
 */
public static String hintingSize(Font font) {
  int instrSize = 0;

  LocaTable locaTable = FontUtils.getLocaTable(font);
  GlyphTable glyfTable = FontUtils.getGlyphTable(font);

  // Get hinting information from each glyph
  for (int i = 0; i < locaTable.numGlyphs(); i++) {
    Glyph glyph = glyfTable.glyph(locaTable.glyphOffset(i), locaTable.glyphLength(i));
    instrSize += glyph.instructionSize();
  }

  double percentage = instrSize * 100.0 / glyfTable.headerLength();
  return String.format(
      "%d bytes (%s%% of glyf table)", instrSize, twoDecimalPlaces.format(percentage));
}
 

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

示例2: countSpecialGlyphs

点赞 3

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
private void countSpecialGlyphs(Font font) {
  LocaTable locaTable = font.getTable(Tag.loca);
  GlyphTable glyphTable = font.getTable(Tag.glyf);

  int count = 0;
  for (int glyphId = 0; glyphId < locaTable.numGlyphs(); glyphId++) {
    int offset = locaTable.glyphOffset(glyphId);
    int length = locaTable.glyphLength(glyphId);
    Glyph glyph = glyphTable.glyph(offset, length);
    if (glyph instanceof SimpleGlyph) {
      SimpleGlyph simple = (SimpleGlyph) glyph;
      if (simple.numberOfContours() != 2) {
        continue;
      }
      if ((simple.numberOfPoints(0) != 1) && (simple.numberOfPoints(1) != 1)) {
        continue;
      }
      count++;
    }
  }
  System.out.println("\n------ Special Glyph Count");
  System.out.println("\ttotal glyphs = " + locaTable.numGlyphs());
  System.out.println("\tspecial glyphs = " + count);    
}
 

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

示例3: listGlyphDimensionBounds

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
/**
 * Gets a list of minimum and maximum x and y dimensions for the glyphs in the
 * font. This is based on the reported min and max values for each glyph and
 * not on the actual outline sizes.
 *
 * @param font
 *          the source font
 * @return a list of glyph dimensions for the font
 */
public static DataDisplayTable listGlyphDimensionBounds(Font font) {
  String[] header = { "Dimension", "Value" };
  Align[] displayAlignment = { Align.Left, Align.Right };
  DataDisplayTable table = new DataDisplayTable(Arrays.asList(header));
  table.setAlignment(Arrays.asList(displayAlignment));

  LocaTable locaTable = FontUtils.getLocaTable(font);
  GlyphTable glyfTable = FontUtils.getGlyphTable(font);

  // Initialise boundaries
  int xMin = Integer.MAX_VALUE;
  int yMin = Integer.MAX_VALUE;
  int xMax = Integer.MIN_VALUE;
  int yMax = Integer.MIN_VALUE;

  // Find boundaries
  for (int i = 0; i < locaTable.numGlyphs(); i++) {
    Glyph glyph = glyfTable.glyph(locaTable.glyphOffset(i), locaTable.glyphLength(i));
    if (glyph.xMin() < xMin) {
      xMin = glyph.xMin();
    }
    if (glyph.yMin() < yMin) {
      yMin = glyph.yMin();
    }
    if (glyph.xMax() > xMax) {
      xMax = glyph.xMax();
    }
    if (glyph.yMax() > yMax) {
      yMax = glyph.yMax();
    }
  }

  table.add(Arrays.asList(new String[] { "xMin", String.format("%d", xMin) }));
  table.add(Arrays.asList(new String[] { "xMax", String.format("%d", xMax) }));
  table.add(Arrays.asList(new String[] { "yMin", String.format("%d", yMin) }));
  table.add(Arrays.asList(new String[] { "yMax", String.format("%d", yMax) }));

  return table;
}
 

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

示例4: listSubglyphFrequency

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
/**
 * Gets a list of glyphs in the font that are used as subglyphs and the number
 * of times each subglyph is used as a subglyph
 *
 * @param font
 *          the source font
 * @return the number of glyphs in the font that are used as subglyphs of
 *         other glyphs more than once
 */
public static DataDisplayTable listSubglyphFrequency(Font font) {
  Map<Integer, Integer> subglyphFreq = new HashMap<Integer, Integer>();
  String[] header = { "Glyph ID", "Frequency" };
  Align[] displayAlignment = { Align.Right, Align.Right };
  DataDisplayTable table = new DataDisplayTable(Arrays.asList(header));
  table.setAlignment(Arrays.asList(displayAlignment));

  LocaTable locaTable = FontUtils.getLocaTable(font);
  GlyphTable glyfTable = FontUtils.getGlyphTable(font);

  // Add subglyphs of all composite glyphs to hashmap
  for (int i = 0; i < locaTable.numGlyphs(); i++) {
    Glyph glyph = glyfTable.glyph(locaTable.glyphOffset(i), locaTable.glyphLength(i));
    if (glyph.glyphType() == GlyphType.Composite) {
      CompositeGlyph cGlyph = (CompositeGlyph) glyph;

      // Add all subglyphs of this glyph to hashmap
      for (int j = 0; j < cGlyph.numGlyphs(); j++) {
        int subglyphId = cGlyph.glyphIndex(j);
        int frequency = 1;
        if (subglyphFreq.containsKey(subglyphId)) {
          frequency += subglyphFreq.get(subglyphId);
        }
        subglyphFreq.put(subglyphId, frequency);
      }
    }
  }

  // Add frequency data to table
  int numSubglyphs = 0;
  Set<Integer> sortedKeySet = new TreeSet<Integer>(subglyphFreq.keySet());
  for (Integer key : sortedKeySet) {
    String[] data = { key.toString(), subglyphFreq.get(key).toString() };
    table.add(Arrays.asList(data));
  }

  return table;
}
 

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

示例5: encode

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
public void encode(Font sourceFont) {
  LocaTable loca = sourceFont.getTable(Tag.loca);
  int nGlyphs = loca.numGlyphs();
  GlyphTable glyf = sourceFont.getTable(Tag.glyf);

  for (int glyphId = 0; glyphId < nGlyphs; glyphId++) {
    int sourceOffset = loca.glyphOffset(glyphId);
    int length = loca.glyphLength(glyphId);
    Glyph glyph = glyf.glyph(sourceOffset, length);
    writeGlyph(glyph);
  }
}
 

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

示例6: subset

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
@Override
public boolean subset(Subsetter subsetter, Font font, Font.Builder fontBuilder)
    throws IOException {

  GlyphTable glyphTable = font.getTable(Tag.glyf);
  LocaTable locaTable = font.getTable(Tag.loca);
  if (glyphTable == null || locaTable == null) {
    throw new RuntimeException("Font to subset is not valid.");
  }
  ReadableFontData originalGlyfData = glyphTable.readFontData();

  GlyphTable.Builder glyphTableBuilder =
      (GlyphTable.Builder) fontBuilder.newTableBuilder(Tag.glyf);
  LocaTable.Builder locaTableBuilder = (LocaTable.Builder) fontBuilder.newTableBuilder(Tag.loca);
  List<Glyph.Builder<? extends Glyph>> glyphBuilders = glyphTableBuilder.glyphBuilders();

  GlyphStripper glyphStripper = new GlyphStripper(glyphTableBuilder);

  for (int i = 0; i < locaTable.numGlyphs(); i++) {
    int oldOffset = locaTable.glyphOffset(i);
    int oldLength = locaTable.glyphLength(i);
    Glyph glyph = glyphTable.glyph(oldOffset, oldLength);
    glyphBuilders.add(glyphStripper.stripGlyph(glyph));
  }

  List<Integer> locaList = glyphTableBuilder.generateLocaList();
  locaTableBuilder.setLocaList(locaList);
  return true;
}
 

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

示例7: getGlyph

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
private static Glyph getGlyph(Font font, int glyphId) {
  LocaTable locaTable = font.getTable(Tag.loca);
  GlyphTable glyfTable = font.getTable(Tag.glyf);
  int offset = locaTable.glyphOffset(glyphId);
  int length = locaTable.glyphLength(glyphId);
  return glyfTable.glyph(offset, length);
}
 

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

示例8: getGlyph

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
private com.google.typography.font.sfntly.table.truetype.Glyph getGlyph(int glyphId) {
    LocaTable locaTable = font.getTable(Tag.loca);
    GlyphTable glyphTable = font.getTable(Tag.glyf);
    int offset = locaTable.glyphOffset(glyphId);
    int length = locaTable.glyphLength(glyphId);
    
    com.google.typography.font.sfntly.table.truetype.Glyph glyph = glyphTable.glyph(offset, length);
	return glyph;
}
 

开发者ID:windwardadmin,
项目名称:android-awt,
代码行数:10,
代码来源:SfntlyFontPeer.java

示例9: dumpChar

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的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

示例10: lintWindowsClipping

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
private void lintWindowsClipping(Font font) {
  LocaTable loca = (LocaTable) font.getTable(Tag.loca);
  int nGlyphs = loca.numGlyphs();
  GlyphTable glyphTable = (GlyphTable) font.getTable(Tag.glyf);
  int bbox_xMin = 0;
  int bbox_yMin = 0;
  int bbox_xMax = 0;
  int bbox_yMax = 0;
  for (int glyphId = 0; glyphId < nGlyphs; glyphId++) {
    int offset = loca.glyphOffset(glyphId);
    int length = loca.glyphLength(glyphId);
    Glyph glyph = glyphTable.glyph(offset, length);
    if (glyph != null && glyph.numberOfContours() != 0) {
      int xMin = glyph.xMin();
      int yMin = glyph.yMin();
      int xMax = glyph.xMax();
      int yMax = glyph.yMax();
      if (glyphId == 0 || xMin < bbox_xMin) {
        bbox_xMin = xMin;
      }
      if (glyphId == 0 || yMin < bbox_yMin) {
        bbox_yMin = yMin;
      }
      if (glyphId == 0 || xMax > bbox_xMax) {
        bbox_xMax = xMax;
      }
      if (glyphId == 0 || yMax > bbox_yMax) {
        bbox_yMax = yMax;
      }
    }
  }
  OS2Table os2 = (OS2Table) font.getTable(Tag.OS_2);
  if (os2.usWinAscent() < bbox_yMax) {
    reportProblem("font is clipped on top by " + (bbox_yMax - os2.usWinAscent()) + " units");
  }
  if (os2.usWinDescent() < -bbox_yMin) {
    reportProblem("font is clipped on bottom by " + (-bbox_yMin - os2.usWinDescent()) + " units");
  }
}
 

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

示例11: lintAllGlyphs

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
private void lintAllGlyphs(Font font) {
  LocaTable loca = (LocaTable) font.getTable(Tag.loca);
  GlyphTable glyphTable = (GlyphTable) font.getTable(Tag.glyf);
  int nGlyphs = loca.numGlyphs();
  for (int glyphId = 0; glyphId < nGlyphs; glyphId++) {
    int offset = loca.glyphOffset(glyphId);
    int length = loca.glyphLength(glyphId);
    Glyph glyph = glyphTable.glyph(offset, length);
    if (glyph != null) {
      if (glyph.glyphType() == GlyphType.Composite) {
        lintCompositeGlyph(font, (CompositeGlyph)glyph, glyphId);
      }
    }      
  }
}
 

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

示例12: checkGlyph

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
/**
 * Basic glyph checking.
 * 
 * Currently only instantiates the glyph from the table and verifies that it
 * is non-null. This does ensure that the glyph data was able to be parsed correctly.
 * 
 * @param table glyph table
 * @param offset glyph offset in table
 * @param length length of glyph data
 */
private void checkGlyph(GlyphTable table, int offset, int length) {
  Glyph glyph = table.glyph(offset, length);
  if (length != 0) {
    assertNotNull(glyph);
  }
  // Check that padding is computed consistently.
  int padding1 = glyph.padding();
  glyph.instructionSize();
  int padding2 = glyph.padding();
  assertEquals(padding1, padding2);
}
 

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

示例13: subset

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
@Override
public boolean subset(Subsetter subsetter, Font font, Font.Builder fontBuilder) throws IOException {
  List<Integer> permutationTable = subsetter.glyphMappingTable();
  VerticalHeaderTable origHeader = font.getTable(Tag.vhea);
  VerticalMetricsTable origMetrics = font.getTable(Tag.vmtx);
  
  if (permutationTable == null || origHeader == null || origMetrics == null) {
    return false;
  }
  
  GlyphTable glyphTable = font.getTable(Tag.glyf);
  LocaTable locaTable = font.getTable(Tag.loca);
  List<Metrics> vMetrics = new ArrayList<Metrics>(permutationTable.size());
  
  for (int origGlyphId : permutationTable) {
    int advanceHeight = origMetrics.advanceHeight(origGlyphId);
    int topSideBearing = origMetrics.topSideBearing(origGlyphId);
    Glyph glyph = getGlyph(locaTable, glyphTable, origGlyphId);
    vMetrics.add(new Metrics(advanceHeight, topSideBearing, glyph));
  }
  
  int[] extents = new int[5];
  fontBuilder.newTableBuilder(Tag.vmtx, generateMetrics(vMetrics, extents));
  
  VerticalHeaderTable.Builder vheaBuilder = 
    (VerticalHeaderTable.Builder) fontBuilder.newTableBuilder(Tag.vhea, origHeader.readFontData());
  
  vheaBuilder.setAdvanceHeightMax(extents[0]);
  vheaBuilder.setMinTopSideBearing(extents[1]);
  vheaBuilder.setMinBottomSideBearing(extents[2]);
  vheaBuilder.setYMaxExtent(extents[3]);
  vheaBuilder.setNumberOfVMetrics(extents[4]);
  
  return true;
}
 

开发者ID:jtanx,
项目名称:sfntly-java-mod,
代码行数:36,
代码来源:VerticalMetricsTableSubsetter.java

示例14: subset

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
/**
 * Subsets the horizontal metrics table. Also sets xAvgCharWidth in the OS/2
 * table, since it iterates through the advance widths in the process.
 * 
 * @param subsetter
 * @param font
 * @param fontBuilder
 * @return 
 */
@Override
public boolean subset(Subsetter subsetter, Font font, Builder fontBuilder) {
  List<Integer> permutationTable = subsetter.glyphMappingTable();
  if (permutationTable == null) {
    return false;
  }
  
  OS2Table.Builder os2 = (OS2Table.Builder)fontBuilder.getTableBuilder(Tag.OS_2);
  HorizontalMetricsTable origMetrics = font.getTable(Tag.hmtx);
  GlyphTable glyphTable = font.getTable(Tag.glyf);
  LocaTable locaTable = font.getTable(Tag.loca);
  List<HorizontalMetricsTableBuilder.LongHorMetric> metrics =
      new ArrayList<HorizontalMetricsTableBuilder.LongHorMetric>();
  int nnz = 0, widthsum = 0;
  
  for (int i = 0; i < permutationTable.size(); i++) {
    int origGlyphId = permutationTable.get(i);
    int advanceWidth = origMetrics.advanceWidth(origGlyphId);
    int lsb = origMetrics.leftSideBearing(origGlyphId);
    Glyph glyph = getGlyph(locaTable, glyphTable, origGlyphId);
    //System.out.println(glyph);
    metrics.add(new HorizontalMetricsTableBuilder.LongHorMetric(advanceWidth, lsb, glyph.xMin(), glyph.xMax(), glyph.numberOfContours()));
  
    if (advanceWidth > 0) {
      nnz++;
      widthsum += advanceWidth;
    }
  }
  
  if (os2 != null) {
    //Technically incorrect for versions < 3
    os2.setXAvgCharWidth(nnz > 0 ? (widthsum / nnz) : 0);
  }
  new HorizontalMetricsTableBuilder(fontBuilder, metrics).build();
  return true;
}
 

开发者ID:jtanx,
项目名称:sfntly-java-mod,
代码行数:46,
代码来源:HorizontalMetricsTableSubsetter.java

示例15: getLastGlyph

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
private static Glyph getLastGlyph(Font font) {
  LocaTable locaTable = font.getTable(Tag.loca);
  int glyphId = locaTable.numGlyphs() - 1;
  GlyphTable glyfTable = font.getTable(Tag.glyf);
  int offset = locaTable.glyphOffset(glyphId);
  int length = locaTable.glyphLength(glyphId);
  return glyfTable.glyph(offset, length);
}
 

开发者ID:jtanx,
项目名称:sfntly-java-mod,
代码行数:9,
代码来源:Issue28Tests.java

示例16: GlyphStripper

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
public GlyphStripper(GlyphTable.Builder glyphTableBuilder) {
  this.glyphTableBuilder = glyphTableBuilder;
}
 

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

示例17: subset

点赞 2

import com.google.typography.font.sfntly.table.truetype.GlyphTable; //导入依赖的package包/类
@Override
public boolean subset(Subsetter subsetter, Font font, Font.Builder fontBuilder)
    throws IOException {
  if (DEBUG) {
    System.out.println("GlyphTableSubsetter.subset()");
  }
  List<Integer> permutationTable = subsetter.glyphMappingTable();
  if (permutationTable == null) {
    return false;
  }

  GlyphTable glyphTable = font.getTable(Tag.glyf);
  LocaTable locaTable = font.getTable(Tag.loca);
  if (glyphTable == null || locaTable == null) {
    throw new RuntimeException("Font to subset is not valid.");
  }

  GlyphTable.Builder glyphTableBuilder =
      (GlyphTable.Builder) fontBuilder.newTableBuilder(Tag.glyf);
  LocaTable.Builder locaTableBuilder = (LocaTable.Builder) fontBuilder.newTableBuilder(Tag.loca);
  if (glyphTableBuilder == null || locaTableBuilder == null) {
    throw new RuntimeException("Builder for subset is not valid.");
  }
  Map<Integer, Integer> inverseMap = subsetter.getInverseMapping();

  List<Glyph.Builder<? extends Glyph>> glyphBuilders = glyphTableBuilder.glyphBuilders();
  for (int oldGlyphId : permutationTable) {
    // TODO(stuartg): add subsetting individual glyph data - remove hints etc.

    int oldOffset = locaTable.glyphOffset(oldGlyphId);
    int oldLength = locaTable.glyphLength(oldGlyphId);
    Glyph glyph = glyphTable.glyph(oldOffset, oldLength);
    ReadableFontData data = glyph.readFontData();
    ReadableFontData renumberedData = GlyphRenumberer.renumberGlyph(data, inverseMap);
    Glyph.Builder<? extends Glyph> glyphBuilder = glyphTableBuilder.glyphBuilder(renumberedData);
    if (DEBUG) {
      System.out.println("\toldGlyphId = " + oldGlyphId);
      System.out.println("\toldOffset = " + oldOffset);
      System.out.println("\toldLength = " + oldLength);
      System.out.println("\told glyph = " + glyph);
      System.out.println("\tnew glyph builder = " + glyphBuilder);
    }
    glyphBuilders.add(glyphBuilder);

  }
  List<Integer> locaList = glyphTableBuilder.generateLocaList();
  if (DEBUG) {
    System.out.println("\tlocaList = " + locaList);
  }
  locaTableBuilder.setLocaList(locaList);
  MaximumProfileTable.Builder maxpBuilder =
    (MaximumProfileTable.Builder) fontBuilder.getTableBuilder(Tag.maxp);
  maxpBuilder.setNumGlyphs(locaTableBuilder.numGlyphs());
  return true;
}
 

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


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