private static String readTagName(CFFDataInput input) throws IOException { byte[] b = input.readBytes(4); return new String(b, Charsets.ISO_8859_1); }
private static byte[][] readIndexData(CFFDataInput input) throws IOException { int[] offsets = readIndexDataOffsets(input); if (offsets == null) { return null; } int count = offsets.length-1; byte[][] indexDataValues = new byte[count][]; for (int i = 0; i < count; i++) { int length = offsets[i + 1] - offsets[i]; indexDataValues[i] = input.readBytes(length); } return indexDataValues; }
private static String[] readStringIndexData(CFFDataInput input) throws IOException { int[] offsets = readIndexDataOffsets(input); if (offsets == null) { return null; } int count = offsets.length-1; String[] indexDataValues = new String[count]; for (int i = 0; i < count; i++) { int length = offsets[i + 1] - offsets[i]; if (length < 0) { throw new IOException("Negative index data length + " + length + " at " + i + ": offsets[" + (i + 1) + "]=" + offsets[i + 1] + ", offsets[" + i + "]=" + offsets[i]); } indexDataValues[i] = new String(input.readBytes(length), Charsets.ISO_8859_1); } return indexDataValues; }
private byte[] readHeader() throws IOException { //Read known header byte[] fixedHeader = cffData.readBytes(4); int hdrSize = (fixedHeader[2] & 0xFF); byte[] extra = cffData.readBytes(hdrSize - 4); byte[] header = new byte[hdrSize]; for (int i = 0; i < fixedHeader.length; i++) { header[i] = fixedHeader[i]; } for (int i = 4; i < extra.length; i++) { header[i] = extra[i - 4]; } return header; }
private static String readTagName(CFFDataInput input) throws IOException { byte[] b = input.readBytes(4); return new String(b, Charsets.ISO_8859_1); }
private static String readTagName(CFFDataInput input) throws IOException { byte[] b = input.readBytes(4); return new String(b, Charsets.ISO_8859_1); }
/** * Retrieves a number of bytes from the CFF data stream * @param offset The offset of the bytes to retrieve * @param length The number of bytes to retrieve * @return Returns a byte array of requested bytes * @throws IOException Throws an IO Exception if an error occurs */ private byte[] getCFFOffsetBytes(int offset, int length) throws IOException { cffData.setPosition(offset); return cffData.readBytes(length); }
private static byte[][] readIndexData(CFFDataInput input) throws IOException { int[] offsets = readIndexDataOffsets(input); if (offsets == null) { return null; } int count = offsets.length-1; byte[][] indexDataValues = new byte[count][]; for (int i = 0; i < count; i++) { int length = offsets[i + 1] - offsets[i]; indexDataValues[i] = input.readBytes(length); } return indexDataValues; }
private static byte[][] readIndexData(CFFDataInput input) throws IOException { int[] offsets = readIndexDataOffsets(input); if (offsets == null) { return null; } int count = offsets.length-1; byte[][] indexDataValues = new byte[count][]; for (int i = 0; i < count; i++) { int length = offsets[i + 1] - offsets[i]; indexDataValues[i] = input.readBytes(length); } return indexDataValues; }
private static String[] readStringIndexData(CFFDataInput input) throws IOException { int[] offsets = readIndexDataOffsets(input); if (offsets == null) { return null; } int count = offsets.length-1; String[] indexDataValues = new String[count]; for (int i = 0; i < count; i++) { int length = offsets[i + 1] - offsets[i]; if (length < 0) { throw new IOException("Negative index data length + " + length + " at " + i + ": offsets[" + (i + 1) + "]=" + offsets[i + 1] + ", offsets[" + i + "]=" + offsets[i]); } indexDataValues[i] = new String(input.readBytes(length), Charsets.ISO_8859_1); } return indexDataValues; }
private static String[] readStringIndexData(CFFDataInput input) throws IOException { int[] offsets = readIndexDataOffsets(input); if (offsets == null) { return null; } int count = offsets.length-1; String[] indexDataValues = new String[count]; for (int i = 0; i < count; i++) { int length = offsets[i + 1] - offsets[i]; if (length < 0) { throw new IOException("Negative index data length + " + length + " at " + i + ": offsets[" + (i + 1) + "]=" + offsets[i + 1] + ", offsets[" + i + "]=" + offsets[i]); } indexDataValues[i] = new String(input.readBytes(length), Charsets.ISO_8859_1); } return indexDataValues; }
private CFFIndexData readLocalIndexSubrs() throws IOException { CFFIndexData localSubrs = null; DICTEntry privateEntry = topDict.get("Private"); if (privateEntry != null) { int length = privateEntry.getOperands().get(0).intValue(); int offset = privateEntry.getOperands().get(1).intValue(); cffData.setPosition(offset); byte[] privateData = cffData.readBytes(length); Map<String, DICTEntry> privateDict = parseDictData(privateData); DICTEntry localSubrsEntry = privateDict.get("Subrs"); if (localSubrsEntry != null) { int localOffset = offset + localSubrsEntry.getOperands().get(0).intValue(); cffData.setPosition(localOffset); localSubrs = readIndex(); } } return localSubrs; }
private FontDict setFDData(DICTEntry privateFDEntry, FontDict newFontDict) throws IOException { int privateFDLength = privateFDEntry.getOperands().get(0).intValue(); int privateFDOffset = privateFDEntry.getOperands().get(1).intValue(); cffData.setPosition(privateFDOffset); byte[] privateDict = cffData.readBytes(privateFDLength); newFontDict.setPrivateDictData(privateFDOffset, privateFDLength); Map<String, DICTEntry> privateEntries = parseDictData(privateDict); DICTEntry subroutines = privateEntries.get("Subrs"); if (subroutines != null) { CFFIndexData localSubrs = readIndex(privateFDOffset + subroutines.getOperands().get(0).intValue()); newFontDict.setLocalSubrData(localSubrs); } else { newFontDict.setLocalSubrData(new CFFIndexData()); } return newFontDict; }
/** * Retrieves data from the index data * @param index The index position of the data to retrieve * @return Returns the byte data for the given index * @throws IOException Throws an IO Exception if an error occurs */ public byte[] getValue(int index) throws IOException { int oldPos = cffData.getPosition(); try { cffData.setPosition(dataLocation.getDataPosition() + (offsets[index] - 1)); return cffData.readBytes(offsets[index + 1] - offsets[index]); } finally { cffData.setPosition(oldPos); } }
public byte[] getData() throws IOException { int origPos = cffData.getPosition(); try { cffData.setPosition(dataLocation.getDataPosition()); return cffData.readBytes(dataLocation.getDataLength()); } finally { cffData.setPosition(origPos); } }
public byte[] getPrivateDictData() throws IOException { int origPos = cffData.getPosition(); try { cffData.setPosition(dataLocation.getDataPosition()); return cffData.readBytes(dataLocation.getDataLength()); } finally { cffData.setPosition(origPos); } }
public byte[] getByteData() throws IOException { int oldPos = cffData.getPosition(); try { cffData.setPosition(dataLocation.getDataPosition()); return cffData.readBytes(dataLocation.getDataLength()); } finally { cffData.setPosition(oldPos); } } }
/** * 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; }