private CFFDataInput createTaggedCFFDataInput(CFFDataInput input, byte[] bytes) throws IOException { // this is OpenType font containing CFF data // so find CFF tag short numTables = input.readShort(); @SuppressWarnings({"unused", "squid:S1854"}) short searchRange = input.readShort(); @SuppressWarnings({"unused", "squid:S1854"}) short entrySelector = input.readShort(); @SuppressWarnings({"unused", "squid:S1854"}) short rangeShift = input.readShort(); for (int q = 0; q < numTables; q++) { String tagName = readTagName(input); @SuppressWarnings("unused") long checksum = readLong(input); long offset = readLong(input); long length = readLong(input); if ("CFF ".equals(tagName)) { byte[] bytes2 = Arrays.copyOfRange(bytes, (int) offset, (int) (offset + length)); return new CFFDataInput(bytes2); } } throw new IOException("CFF tag not found in this OpenType font."); }
private static Integer readIntegerNumber(CFFDataInput input, int b0) throws IOException { if (b0 == 28) { return (int) input.readShort(); } else if (b0 == 29) { return input.readInt(); } else if (b0 >= 32 && b0 <= 246) { return b0 - 139; } else if (b0 >= 247 && b0 <= 250) { int b1 = input.readUnsignedByte(); return (b0 - 247) * 256 + b1 + 108; } else if (b0 >= 251 && b0 <= 254) { int b1 = input.readUnsignedByte(); return -(b0 - 251) * 256 - b1 - 108; } else { throw new IllegalArgumentException(); } }
private CFFDataInput createTaggedCFFDataInput(CFFDataInput input, byte[] bytes) throws IOException { // this is OpenType font containing CFF data // so find CFF tag short numTables = input.readShort(); @SuppressWarnings("unused") short searchRange = input.readShort(); @SuppressWarnings("unused") short entrySelector = input.readShort(); @SuppressWarnings("unused") short rangeShift = input.readShort(); for (int q = 0; q < numTables; q++) { String tagName = readTagName(input); @SuppressWarnings("unused") long checksum = readLong(input); long offset = readLong(input); long length = readLong(input); if ("CFF ".equals(tagName)) { byte[] bytes2 = Arrays.copyOfRange(bytes, (int) offset, (int) (offset + length)); return new CFFDataInput(bytes2); } } throw new IOException("CFF tag not found in this OpenType font."); }
private CFFDataInput createTaggedCFFDataInput(CFFDataInput input, byte[] bytes) throws IOException { // this is OpenType font containing CFF data // so find CFF tag short numTables = input.readShort(); @SuppressWarnings("unused") short searchRange = input.readShort(); @SuppressWarnings("unused") short entrySelector = input.readShort(); @SuppressWarnings("unused") short rangeShift = input.readShort(); for (int q = 0; q < numTables; q++) { String tagName = readTagName(input); @SuppressWarnings("unused") long checksum = readLong(input); long offset = readLong(input); long length = readLong(input); if ("CFF ".equals(tagName)) { byte[] bytes2 = Arrays.copyOfRange(bytes, (int) offset, (int) (offset + length)); return new CFFDataInput(bytes2); } } throw new IOException("CFF tag not found in this OpenType font."); }
/** * Reads the CFFData from a given font file * @param fontFile The font file being read * @return The byte data found in the CFF table */ public static byte[] getCFFData(FontFileReader fontFile) throws IOException { byte[] cff = fontFile.getAllBytes(); CFFDataInput input = new CFFDataInput(fontFile.getAllBytes()); input.readBytes(4); //OTTO short numTables = input.readShort(); input.readShort(); //searchRange input.readShort(); //entrySelector input.readShort(); //rangeShift for (int q = 0; q < numTables; q++) { String tagName = new String(input.readBytes(4)); readLong(input); //Checksum long offset = readLong(input); long length = readLong(input); if (tagName.equals("CFF ")) { cff = new byte[(int)length]; System.arraycopy(fontFile.getAllBytes(), (int)offset, cff, 0, cff.length); break; } } return cff; }
private static Integer readIntegerNumber(CFFDataInput input, int b0) throws IOException { if (b0 == 28) { return (int) input.readShort(); } else if (b0 == 29) { return input.readInt(); } else if (b0 >= 32 && b0 <= 246) { return b0 - 139; } else if (b0 >= 247 && b0 <= 250) { int b1 = input.readUnsignedByte(); return (b0 - 247) * 256 + b1 + 108; } else if (b0 >= 251 && b0 <= 254) { int b1 = input.readUnsignedByte(); return -(b0 - 251) * 256 - b1 - 108; } else { throw new IllegalArgumentException(); } }
private static Integer readIntegerNumber(CFFDataInput input, int b0) throws IOException { if (b0 == 28) { return (int) input.readShort(); } else if (b0 == 29) { return input.readInt(); } else if (b0 >= 32 && b0 <= 246) { return b0 - 139; } else if (b0 >= 247 && b0 <= 250) { int b1 = input.readUnsignedByte(); return (b0 - 247) * 256 + b1 + 108; } else if (b0 >= 251 && b0 <= 254) { int b1 = input.readUnsignedByte(); return -(b0 - 251) * 256 - b1 - 108; } else { throw new IllegalArgumentException(); } }