本文整理汇总了Java中com.google.typography.font.sfntly.table.core.OS2Table类的典型用法代码示例。如果您正苦于以下问题:Java OS2Table类的具体用法?Java OS2Table怎么用?Java OS2Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OS2Table类属于com.google.typography.font.sfntly.table.core包,在下文中一共展示了OS2Table类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAchVendId
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
public void testAchVendId() throws Exception {
Font.Builder fontBuilder = TestFontUtils.builderForFontFile(TEST_FONT_FILE);
OS2Table.Builder os2TableBuilder = (OS2Table.Builder) fontBuilder.getTableBuilder(Tag.OS_2);
os2TableBuilder.setAchVendId(achVendId_a);
assertTrue(TestUtils.equals(
achVendId_a_pad, 0, os2TableBuilder.achVendId(), 0, achVendId_a_pad.length));
os2TableBuilder.setAchVendId(achVendId_abcd);
assertTrue(
TestUtils.equals(achVendId_abcd, 0, os2TableBuilder.achVendId(), 0, achVendId_abcd.length));
os2TableBuilder.setAchVendId(achVendId_a);
assertTrue(TestUtils.equals(
achVendId_a_pad, 0, os2TableBuilder.achVendId(), 0, achVendId_a_pad.length));
}
示例2: subset
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
@Override
public boolean subset(Subsetter subsetter, Font font, Font.Builder fontBuilder) throws IOException {
OS2Table.Builder os2 = (OS2Table.Builder)fontBuilder.getTableBuilder(Tag.OS_2);
if (os2 != null) {
int fsType = os2.fsTypeAsInt();
//Zero out reserved bits, based on the OS/2 version number.
switch (os2.tableVersion()) {
case 0: case 1:
fsType &= 0xE; break;
case 2: case 3: case 4:
fsType &= 0x30E; break;
}
os2.setFsType(fsType);
}
return true;
}
示例3: listFontMetrics
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
/**
* Gets a list of information regarding various dimensions about the given
* font from the head, hhea, and OS/2 font tables
*
* @param font
* the source font
* @return a list of dimensional information about the font
*/
public static DataDisplayTable listFontMetrics(Font font) {
String[] header = { "Name", "Value" };
Align[] displayAlignment = { Align.Left, Align.Left };
DataDisplayTable table = new DataDisplayTable(Arrays.asList(header));
table.setAlignment(Arrays.asList(displayAlignment));
// Retrieve necessary tables
FontHeaderTable headTable = (FontHeaderTable) FontUtils.getTable(font, Tag.head);
HorizontalHeaderTable hheaTable = (HorizontalHeaderTable) FontUtils.getTable(font, Tag.hhea);
OS2Table os2Table = (OS2Table) FontUtils.getTable(font, Tag.OS_2);
table.add(Arrays.asList(
new String[] { "Units per em", String.format("%d", headTable.unitsPerEm()) }));
table.add(Arrays.asList(new String[] {
"[xMin, xMax]", String.format("[%d, %d]", headTable.xMin(), headTable.xMax()) }));
table.add(Arrays.asList(new String[] {
"[yMin, yMax]", String.format("[%d, %d]", headTable.yMin(), headTable.yMax()) }));
table.add(Arrays.asList(new String[] {
"Smallest readable size (px per em)", String.format("%d", headTable.lowestRecPPEM()) }));
table.add(
Arrays.asList(new String[] { "hhea ascender", String.format("%d", hheaTable.ascender()) }));
table.add(Arrays.asList(
new String[] { "hhea descender", String.format("%d", hheaTable.descender()) }));
table.add(Arrays.asList(
new String[] { "hhea typographic line gap", String.format("%d", hheaTable.lineGap()) }));
table.add(Arrays.asList(
new String[] { "OS/2 Windows ascender", String.format("%d", os2Table.usWinAscent()) }));
table.add(Arrays.asList(
new String[] { "OS/2 Windows descender", String.format("%d", os2Table.usWinDescent()) }));
table.add(Arrays.asList(new String[] {
"OS/2 typographic ascender", String.format("%d", os2Table.sTypoAscender()) }));
table.add(Arrays.asList(new String[] {
"OS/2 typographic ascender", String.format("%d", os2Table.sTypoDescender()) }));
table.add(Arrays.asList(new String[] {
"OS/2 typographic line gap", String.format("%d", os2Table.sTypoLineGap()) }));
return table;
}
示例4: writeUnicodeRanges
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
private int writeUnicodeRanges(int start, OS2Table os2Table, WritableFontData writableFontData) {
int index = start;
// TODO: change to loop when os2Table.ulUnicodeRange() is implemented
index += writableFontData.writeULongLE(index, os2Table.ulUnicodeRange1());
index += writableFontData.writeULongLE(index, os2Table.ulUnicodeRange2());
index += writableFontData.writeULongLE(index, os2Table.ulUnicodeRange3());
index += writableFontData.writeULongLE(index, os2Table.ulUnicodeRange4());
return index - start;
}
示例5: lintWindowsClipping
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的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");
}
}
示例6: lintOS2Misc
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
private void lintOS2Misc(Font font) {
OS2Table os2 = (OS2Table) font.getTable(Tag.OS_2);
int widthClass = os2.usWidthClass();
if (widthClass < 1 || widthClass > 9) {
reportProblem("widthClass must be [1..9] inclusive, was " + widthClass + "; IE9 fail");
}
int weightClass = os2.usWeightClass();
if (weightClass < 100 || weightClass > 900) {
reportProblem("weightClass must be [100..900] inclusive, was " + weightClass);
} else if ((weightClass % 100) != 0) {
reportProblem("weightClass must be multiple of 100, was " + weightClass);
}
}
示例7: subset
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
@Override
public boolean subset(Subsetter subsetter, Font font, Builder fontBuilder) throws IOException {
CMapFormat4 cmap4 = getCMapFormat4(subsetter, font);
if (cmap4 == null) {
throw new RuntimeException("CMap format 4 table in source font not found");
}
Map<Integer, Integer> mapping = computeMapping(subsetter, cmap4);
CMapTableBuilder cmapBuilder =
new CMapTableBuilder(fontBuilder, mapping, cmap4.cmapId());
cmapBuilder.build();
//OS/2 info. OS/2 info is split across the subsetters
OS2Table.Builder os2 = (OS2Table.Builder)fontBuilder.getTableBuilder(Tag.OS_2);
if (os2 != null) {
EnumSet<UnicodeRange> unicodeRange = EnumSet.noneOf(UnicodeRange.class);
int min = 0xFFFF, max = 0;
for (int unicode : mapping.keySet()) {
if (unicode < min)
min = unicode;
if (unicode > max && unicode != 0xFFFF)
max = unicode;
UnicodeRange range = OS2TableSubsetter.unicodeToRange(unicode);
if (range != null) {
unicodeRange.add(range);
}
}
os2.setUsFirstCharIndex(min);
os2.setUsLastCharIndex(max);
//Version 0 must have these bits set to 0.
if (os2.tableVersion() > 0)
os2.setUlUnicodeRange(unicodeRange);
}
return true;
}
示例8: subset
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的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;
}
示例9: convert
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
public WritableFontData convert(Font font) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
factory.serializeFont(font, baos);
byte[] fontData = baos.toByteArray();
NameTable name = font.getTable(Tag.name);
byte[] familyName = convertUTF16StringToLittleEndian(name.nameAsBytes(3, 1, 0x409, 1));
byte[] styleName = convertUTF16StringToLittleEndian(name.nameAsBytes(3, 1, 0x409, 2));
byte[] versionName = convertUTF16StringToLittleEndian(name.nameAsBytes(3, 1, 0x409, 5));
byte[] fullName = convertUTF16StringToLittleEndian(name.nameAsBytes(3, 1, 0x409, 4));
long flags = DEFAULT_FLAGS;
if (compressed) {
flags |= FLAGS_TT_COMPRESSED;
MtxWriter mtxWriter = new MtxWriter();
fontData = mtxWriter.compress(font);
}
long eotSize = computeEotSize(
familyName.length, styleName.length, versionName.length, fullName.length, fontData.length);
WritableFontData writableFontData = createWritableFontData((int) eotSize);
OS2Table os2Table = font.getTable(Tag.OS_2);
int index = 0;
index += writableFontData.writeULongLE(index, eotSize); // EOTSize
index += writableFontData.writeULongLE(index, fontData.length); // FontDataSize
index += writableFontData.writeULongLE(index, VERSION); // Version
index += writableFontData.writeULongLE(index, flags); // Flags
index += writeFontPANOSE(index, os2Table, writableFontData); // FontPANOSE
index += writableFontData.writeByte(index, DEFAULT_CHARSET); // Charset
index += writableFontData.writeByte(index, (byte) (os2Table.fsSelectionAsInt() & 1)); // Italic
index += writableFontData.writeULongLE(index, os2Table.usWeightClass()); // Weight
index += writableFontData.writeUShortLE(index, (short) os2Table.fsTypeAsInt()); // fsType
index += writableFontData.writeUShortLE(index, MAGIC_NUMBER); // MagicNumber
index += writeUnicodeRanges(index, os2Table, writableFontData); // UnicodeRange{1, 2, 3, 4}
index += writeCodePages(index, os2Table, writableFontData); // CodePageRange{1, 2}
FontHeaderTable head = font.getTable(Tag.head);
index += writableFontData.writeULongLE(index, head.checkSumAdjustment()); // CheckSumAdjustment
index += writeReservedFields(index, writableFontData); // Reserved{1, 2, 3, 4}
index += writePadding(index, writableFontData);
// FamilyNameSize, FamilyName[FamilyNameSize]
index += writeUTF16String(index, familyName, writableFontData);
index += writePadding(index, writableFontData);
// StyleNameSize, StyleName[StyleNameSize]
index += writeUTF16String(index, styleName, writableFontData);
index += writePadding(index, writableFontData);
// VersionNameSize, VersionName[VersionNameSize]
index += writeUTF16String(index, versionName, writableFontData);
index += writePadding(index, writableFontData);
// FullNameSize, FullName[FullNameSize]
index += writeUTF16String(index, fullName, writableFontData);
index += writePadding(index, writableFontData);
index += writePadding(index, writableFontData); // RootStringSize
if (VERSION > 0x20001) {
index += writableFontData.writeULongLE(index, CS_XORKEY); // RootStringCheckSum
index += writableFontData.writeULongLE(index, 0); // EUDCCodePage
index += writePadding(index, writableFontData);
index += writePadding(index, writableFontData); // SignatureSize
index += writableFontData.writeULongLE(index, 0); // EUDCFlags
index += writableFontData.writeULongLE(index, 0); // EUDCFontSize
}
writableFontData.writeBytes(index, fontData, 0, fontData.length); // FontData[FontDataSize]
return writableFontData;
}
示例10: writeFontPANOSE
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
private int writeFontPANOSE(int index, OS2Table os2Table, WritableFontData writableFontData) {
byte[] fontPANOSE = os2Table.panose();
return writableFontData.writeBytes(index, fontPANOSE, 0, fontPANOSE.length);
}
示例11: writeCodePages
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
private int writeCodePages(int start, OS2Table os2Table, WritableFontData writableFontData) {
int index = start;
index += writableFontData.writeULongLE(index, os2Table.ulCodePageRange1());
index += writableFontData.writeULongLE(index, os2Table.ulCodePageRange2());
return index - start;
}
示例12: subset
import com.google.typography.font.sfntly.table.core.OS2Table; //导入依赖的package包/类
@Override
public boolean subset(Subsetter subsetter, Font font, Font.Builder fontBuilder) throws IOException {
CMapFormat4 cmap4 = getCMapFormat4(subsetter, font);
if (cmap4 == null) {
throw new RuntimeException("CMap format 4 table in source font not found");
}
Map<Integer, Integer> mapping = computeMapping(subsetter, cmap4);
CMapTableBuilder cmapBuilder =
new CMapTableBuilder(fontBuilder, mapping, CMapTable.CMapId.WINDOWS_BMP);//cmap4.cmapId());
cmapBuilder.build();
//OS/2 info. OS/2 info is split across the subsetters
OS2Table.Builder os2 = (OS2Table.Builder)fontBuilder.getTableBuilder(Tag.OS_2);
if (os2 != null) {
EnumSet<OS2Table.UnicodeRange> unicodeRange = EnumSet.noneOf(OS2Table.UnicodeRange.class);
int min = 0xFFFF, max = 0;
for (int unicode : mapping.keySet()) {
if (unicode < min)
min = unicode;
if (unicode > max && unicode != 0xFFFF)
max = unicode;
OS2Table.UnicodeRange range = OS2TableSubsetter.unicodeToRange(unicode);
if (range != null) {
unicodeRange.add(range);
}
}
unicodeRange.remove(OS2Table.UnicodeRange.Specials);
os2.setUsFirstCharIndex(min);
os2.setUsLastCharIndex(max);
//Version 0 must have these bits set to 0.
if (os2.tableVersion() > 0) {
long codepage = os2.ulCodePageRange1() & ~(1 << 31) | 1;
os2.setUlCodePageRange1(codepage);
os2.setUlUnicodeRange(unicodeRange);
}
}
return true;
}