protected byte[] getFullFont() throws IOException { RandomAccessFileOrArray rf2 = null; try { rf2 = new RandomAccessFileOrArray(rf); rf2.reOpen(); byte b[] = new byte[rf2.length()]; rf2.readFully(b); return b; } finally { try {if (rf2 != null) {rf2.close();}} catch (Exception e) {} } }
/** Reads the kerning information from the 'kern' table. * @throws IOException the font file could not be read */ void readKerning() throws IOException { int table_location[]; table_location = (int[])tables.get("kern"); if (table_location == null) return; rf.seek(table_location[0] + 2); int nTables = rf.readUnsignedShort(); int checkpoint = table_location[0] + 4; int length = 0; for (int k = 0; k < nTables; ++k) { checkpoint += length; rf.seek(checkpoint); rf.skipBytes(2); length = rf.readUnsignedShort(); int coverage = rf.readUnsignedShort(); if ((coverage & 0xfff7) == 0x0001) { int nPairs = rf.readUnsignedShort(); rf.skipBytes(6); for (int j = 0; j < nPairs; ++j) { int pair = rf.readInt(); int value = rf.readShort() * 1000 / head.unitsPerEm; kerning.put(pair, value); } } } }
public RandomAccessFileOrArray(InputStream is) throws IOException { this.arrayIn = InputStreamToArray(is); }
private int readUnsignedShort(RandomAccessFileOrArray stream) throws IOException { if (isBigEndian) { return stream.readUnsignedShort(); } else { return stream.readUnsignedShortLE(); } }
private short readShort(RandomAccessFileOrArray stream) throws IOException { if (isBigEndian) { return stream.readShort(); } else { return stream.readShortLE(); } }
throw new DocumentException("Table 'OS/2' does not exist in " + path); rf.seek(location[0]); rf.skip(4); descr.setWeight(rf.readUnsignedShort()); rf.skip(20); descr.setYStrikeoutSize(rf.readShort()); descr.setYStrikeoutPosition(rf.readShort()); rf.seek(location[0]); rf.skip(8); descr.setUnderlinePosition(rf.readShort()); descr.setUnderlineThickness(rf.readShort()); rf.close(); rf = null; return rf;
long pointer = stream.getFilePointer(); // Save stream pointer stream.seek(0L); int endian = stream.readUnsignedShort(); if (!isValidEndianTag(endian)) { throw new stream.seek(4L); long offset = readUnsignedInt(stream, isBigEndian); stream.seek(offset); int entries = readUnsignedShort(stream, isBigEndian); stream.skip(12*entries); offset = readUnsignedInt(stream, isBigEndian); } catch(EOFException eof) { stream.seek(pointer); // Reset stream pointer return numDirectories;
/** Reads and parses a PDF document. * @param url the URL of the document * @param ownerPassword the password to read the document * @throws IOException on error */ public PdfReader(URL url, byte ownerPassword[]) throws IOException { password = ownerPassword; tokens = new PRTokeniser(new RandomAccessFileOrArray(url)); readPdf(); }
public static void main(String[] args) { try { RandomAccessFileOrArray in = new RandomAccessFileOrArray(args[0]); OutputStream out = new FileOutputStream(args[1]); convert(in, out); in.close(); out.close(); } catch (Exception e) { e.printStackTrace(); } }
/** Reads the glyphs widths. The widths are extracted from the table 'hmtx'. * The glyphs are normalized to 1000 units. * @throws DocumentException the font is invalid * @throws IOException the font file could not be read */ protected void readGlyphWidths() throws DocumentException, IOException { int table_location[]; table_location = (int[])tables.get("hmtx"); if (table_location == null) throw new DocumentException("Table 'hmtx' does not exist in " + fileName + style); rf.seek(table_location[0]); GlyphWidths = new int[hhea.numberOfHMetrics]; for (int k = 0; k < hhea.numberOfHMetrics; ++k) { GlyphWidths[k] = (rf.readUnsignedShort() * 1000) / head.unitsPerEm; rf.readUnsignedShort(); } }
protected void readLoca() throws IOException, DocumentException { int tableLocation[]; tableLocation = (int[])tableDirectory.get("head"); if (tableLocation == null) throw new DocumentException("Table 'head' does not exist in " + fileName); rf.seek(tableLocation[TABLE_OFFSET] + HEAD_LOCA_FORMAT_OFFSET); locaShortTable = (rf.readUnsignedShort() == 0); tableLocation = (int[])tableDirectory.get("loca"); if (tableLocation == null) throw new DocumentException("Table 'loca' does not exist in " + fileName); rf.seek(tableLocation[TABLE_OFFSET]); if (locaShortTable) { int entries = tableLocation[TABLE_LENGTH] / 2; locaTable = new int[entries]; for (int k = 0; k < entries; ++k) locaTable[k] = rf.readUnsignedShort() * 2; } else { int entries = tableLocation[TABLE_LENGTH] / 4; locaTable = new int[entries]; for (int k = 0; k < entries; ++k) locaTable[k] = rf.readInt(); } }
void readSegment(JBIG2Segment s) throws IOException { int ptr = ra.getFilePointer(); if ( s.dataLength == 0xffffffffl ) { // TODO figure this bit out, 7.2.7 return; } byte[] data = new byte[(int)s.dataLength]; ra.read(data); s.data = data; if ( s.type == PAGE_INFORMATION ) { int last = ra.getFilePointer(); ra.seek(ptr); int page_bitmap_width = ra.readInt(); int page_bitmap_height = ra.readInt(); ra.seek(last); JBIG2Page p = (JBIG2Page)pages.get(new Integer(s.page)); if ( p == null ) { throw new IllegalStateException("referring to widht/height of page we havent seen yet? " + s.page); } p.pageBitmapWidth = page_bitmap_width; p.pageBitmapHeight = page_bitmap_height; } }
public void close() throws IOException { if (!closed) { raf.close(); closed = true; } } }
public void seek(long pos) throws IOException { seek((int)pos); }
public String readLine() throws IOException { StringBuffer input = new StringBuffer(); int c = -1; boolean eol = false; while (!eol) { switch (c = read()) { case -1: case '\n': eol = true; break; case '\r': eol = true; int cur = getFilePointer(); if ((read()) != '\n') { seek(cur); } break; default: input.append((char)c); break; } } if ((c == -1) && (input.length() == 0)) { return null; } return input.toString(); }
int newpos; pos = getFilePointer(); len = length(); newpos = pos + n; if (newpos > len) { newpos = len; seek(newpos);
public void emit(byte[] buffer) { //System.err.println("range emit offset "+offset+" size="+length); try { buf.seek(offset); for (int i=myOffset; i<myOffset+length; i++) buffer[i] = buf.readByte(); } catch (Exception e) { throw new ExceptionConverter(e); } //System.err.println("finished range emit"); } }
/** The information in the maps of the table 'cmap' is coded in several formats. * Format 6 is a trimmed table mapping. It is similar to format 0 but can have * less than 256 entries. * @return a <CODE>HashMap</CODE> representing this map * @throws IOException the font file could not be read */ HashMap readFormat6() throws IOException { HashMap h = new HashMap(); rf.skipBytes(4); int start_code = rf.readUnsignedShort(); int code_count = rf.readUnsignedShort(); for (int k = 0; k < code_count; ++k) { int[] r = new int[2]; r[0] = rf.readUnsignedShort(); r[1] = getGlyphWidth(r[0]); h.put(new Integer(k + start_code), r); } return h; }
short getShort() { try { return buf.readShort(); } catch (Exception e) { throw new ExceptionConverter(e); } }