Example usage for com.lowagie.text.pdf RandomAccessFileOrArray seek

List of usage examples for com.lowagie.text.pdf RandomAccessFileOrArray seek

Introduction

In this page you can find the example usage for com.lowagie.text.pdf RandomAccessFileOrArray seek.

Prototype

public void seek(long pos) throws IOException 

Source Link

Usage

From source file:org.xhtmlrenderer.pdf.TrueTypeUtil.java

License:Open Source License

private static RandomAccessFileOrArray populateDescription0(String path, BaseFont font, FontDescription descr,
        RandomAccessFileOrArray rf)
        throws NoSuchFieldException, IllegalAccessException, DocumentException, IOException {
    Map tables = extractTables(font);

    descr.setStyle(guessStyle(font));// ww w  .j  a  v  a2 s  . c  o m

    int[] location = (int[]) tables.get("OS/2");
    if (location == null) {
        throw new DocumentException("Table 'OS/2' does not exist in " + path);
    }
    rf.seek(location[0]);
    int want = 4;
    long got = rf.skip(want);
    if (got < want) {
        throw new DocumentException("Skip TT font weight, expect read " + want + " bytes, but only got " + got);
    }
    descr.setWeight(rf.readUnsignedShort());
    want = 20;
    got = rf.skip(want);
    if (got < want) {
        throw new DocumentException(
                "Skip TT font strikeout, expect read " + want + " bytes, but only got " + got);
    }
    descr.setYStrikeoutSize(rf.readShort());
    descr.setYStrikeoutPosition(rf.readShort());

    location = (int[]) tables.get("post");

    if (location != null) {
        rf.seek(location[0]);
        want = 8;
        got = rf.skip(want);
        if (got < want) {
            throw new DocumentException(
                    "Skip TT font underline, expect read " + want + " bytes, but only got " + got);
        }
        descr.setUnderlinePosition(rf.readShort());
        descr.setUnderlineThickness(rf.readShort());
    }

    rf.close();
    rf = null;
    return rf;
}