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

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

Introduction

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

Prototype

public int readUnsignedShort() 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 av  a2  s  .co  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;
}