本文整理汇总了Java中com.google.typography.font.sfntly.table.core.HorizontalDeviceMetricsTable.width方法的典型用法代码示例。如果您正苦于以下问题:Java HorizontalDeviceMetricsTable.width方法的具体用法?Java HorizontalDeviceMetricsTable.width怎么用?Java HorizontalDeviceMetricsTable.width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.typography.font.sfntly.table.core.HorizontalDeviceMetricsTable
的用法示例。
在下文中一共展示了HorizontalDeviceMetricsTable.width方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import com.google.typography.font.sfntly.table.core.HorizontalDeviceMetricsTable; //导入方法依赖的package包/类
public WritableFontData encode(Font sourceFont) {
HorizontalDeviceMetricsTable hdmx = sourceFont.getTable(Tag.hdmx);
HorizontalMetricsTable hmtx = sourceFont.getTable(Tag.hmtx);
MaximumProfileTable maxp = sourceFont.getTable(Tag.maxp);
FontHeaderTable head = sourceFont.<FontHeaderTable>getTable(Tag.head);
int unitsPerEm = head.unitsPerEm();
int numRecords = hdmx.numRecords();
int numGlyphs = maxp.numGlyphs();
MagnitudeDependentWriter magWriter = new MagnitudeDependentWriter();
for (int i = 0; i < numRecords; i++) {
int ppem = hdmx.pixelSize(i);
for (int j = 0; j < numGlyphs; j++) {
int roundedTtAw =
((64 * ppem * hmtx.advanceWidth(j) + unitsPerEm / 2) / unitsPerEm + 32) / 64;
int surprise = hdmx.width(i, j) - roundedTtAw;
magWriter.writeValue(surprise);
}
}
magWriter.flush();
byte[] magBytes = magWriter.toByteArray();
int resultSize = magBytes.length + HEADER_SIZE + RECORD_SIZE * numRecords;
WritableFontData result = WritableFontData.createWritableFontData(resultSize);
result.writeUShort(0, 0);
result.writeUShort(2, numRecords);
result.writeLong(4, hdmx.recordSize());
for (int i = 0; i < numRecords; i++) {
result.writeByte(HEADER_SIZE + RECORD_SIZE * i, (byte) hdmx.pixelSize(i));
result.writeByte(HEADER_SIZE + RECORD_SIZE * i + 1, (byte) hdmx.maxWidth(i));
}
result.writeBytes(HEADER_SIZE + RECORD_SIZE * numRecords, magBytes);
return result;
}