public static Glyf getGlyf(ByteBuffer data) {
        short numContours = data.getShort();
        
        Glyf g = null;
        if (numContours == 0) {
            // no glyph data
            g = new Glyf();
        } else if (numContours == -1) {
            // compound glyf
            g = new GlyfCompound();
        } else if (numContours > 0) {
            // simple glyf
            g = new GlyfSimple();
        } else {
            throw new IllegalArgumentException("Unknown glyf type: " + 
                                               numContours);
        }
        
        g.setNumContours(numContours);
        g.setMinX(data.getShort());
        g.setMinY(data.getShort());
        g.setMaxX(data.getShort());
        g.setMaxY(data.getShort());
        
        // do glyphtype-specific parsing
        g.setData(data);
    
        return g;
    }