@Override public int read(byte[] b, int off, int len) throws IOException { return stream.read(b, off, len); }
strikeoutPosition = data.readSignedShort(); familyClass = data.readSignedShort(); panose = data.read(10); unicodeRange1 = data.readUnsignedInt(); unicodeRange2 = data.readUnsignedInt();
/** * Read a signed byte. * * @return A signed byte. * @throws IOException If there is an error reading the data. */ public int readSignedByte() throws IOException { int signedByte = read(); return signedByte < 127 ? signedByte : signedByte - 256; }
@Override public int read() throws IOException { return stream.read(); }
/** * Read an unsigned byte array. * * @param length the length of the array to be read * @return An unsigned byte array. * @throws IOException If there is an error reading the data. */ public int[] readUnsignedByteArray(int length) throws IOException { int[] array = new int[length]; for (int i = 0; i < length; i++) { array[i] = read(); } return array; }
/** * Read an unsigned integer. * * @return An unsiged integer. * @throws IOException If there is an error reading the data. */ public long readUnsignedInt() throws IOException { long byte1 = read(); long byte2 = read(); long byte3 = read(); long byte4 = read(); if (byte4 < 0) { throw new EOFException(); } return (byte1 << 24) + (byte2 << 16) + (byte3 << 8) + (byte4 << 0); }
/** * Read a fixed length string. * * @param length The length of the string to read in bytes. * @param charset The expected character set of the string. * @return A string of the desired length. * @throws IOException If there is an error reading the data. */ public String readString(int length, String charset) throws IOException { byte[] buffer = read(length); return new String(buffer, charset); }
/** * Reads a tag, an arrau of four uint8s used to identify a script, language system, feature, * or baseline. */ public String readTag() throws IOException { return new String(read(4), Charsets.US_ASCII); }
/** * Read a fixed length string. * * @param length The length of the string to read in bytes. * @param charset The expected character set of the string. * @return A string of the desired length. * @throws IOException If there is an error reading the data. */ public String readString(int length, Charset charset) throws IOException { byte[] buffer = read(length); return new String(buffer, charset); } /**
/** * Read a unsigned byte. Similar to {@link #read()}, but throws an exception if EOF is unexpectedly reached. * * @return A unsigned byte. * @throws IOException If there is an error reading the data. */ public int readUnsignedByte() throws IOException { int unsignedByte = read(); if (unsignedByte == -1) { throw new EOFException("premature EOF"); } return unsignedByte; }
/** * Read a specific number of bytes from the stream. * * @param numberOfBytes The number of bytes to read. * @return The byte buffer. * @throws IOException If there is an error while reading. */ public byte[] read(int numberOfBytes) throws IOException { byte[] data = new byte[numberOfBytes]; int amountRead = 0; int totalAmountRead = 0; // read at most numberOfBytes bytes from the stream. while (totalAmountRead < numberOfBytes && (amountRead = read(data, totalAmountRead, numberOfBytes - totalAmountRead)) != -1) { totalAmountRead += amountRead; } if (totalAmountRead == numberOfBytes) { return data; } else { throw new IOException("Unexpected end of TTF stream reached"); } }
/** * Initialize the CMapEntry when it is a subtype 0. * * @param data the data stream of the to be parsed ttf font * @throws IOException If there is an error parsing the true type font. */ protected void processSubtype0(TTFDataStream data) throws IOException { byte[] glyphMapping = data.read(256); glyphIdToCharacterCode = newGlyphIdToCharacterCode(256); characterCodeToGlyphId = new HashMap<>(glyphMapping.length); for (int i = 0; i < glyphMapping.length; i++) { int glyphIndex = glyphMapping[i] & 0xFF; glyphIdToCharacterCode[glyphIndex] = i; characterCodeToGlyphId.put(i, glyphIndex); } }
/** * This will read the required data from the stream. * * @param ttf The font that is being read. * @param data The stream to read the data from. * @throws java.io.IOException If there is an error reading the data. */ public void read(TrueTypeFont ttf, TTFDataStream data) throws IOException { byte[] bytes = data.read((int)getLength()); CFFParser parser = new CFFParser(); cffFont = parser.parse(bytes, new ByteSource(font)).get(0); initialized = true; }
/** * Returns the raw bytes of the given table. * @param table the table to read. * @throws IOException if there was an error accessing the table. */ public byte[] getTableBytes(TTFTable table) throws IOException { synchronized (lockReadtable) { // save current position long currentPosition = data.getCurrentPosition(); data.seek(table.getOffset()); // read all data byte[] bytes = data.read((int) table.getLength()); // restore current position data.seek(currentPosition); return bytes; } }
@Override public int read(byte[] b, int off, int len) throws IOException { return stream.read(b, off, len); }
@Override public int read() throws IOException { return stream.read(); }
@Override public int read(byte[] b, int off, int len) throws IOException { return stream.read(b, off, len); }
/** * Read a signed byte. * * @return A signed byte. * @throws IOException If there is an error reading the data. */ public int readSignedByte() throws IOException { int signedByte = read(); return signedByte < 127 ? signedByte : signedByte - 256; }
/** * Read a fixed length string. * * @param length The length of the string to read in bytes. * @param charset The expected character set of the string. * @return A string of the desired length. * @throws IOException If there is an error reading the data. */ public String readString(int length, String charset) throws IOException { byte[] buffer = read(length); return new String(buffer, charset); }
/** * Reads a tag, an arrau of four uint8s used to identify a script, language system, feature, * or baseline. */ public String readTag() throws IOException { return new String(read(4), Charsets.US_ASCII); }