public short getLength() {
        // start with the length of the superclass
        short length = super.getLength();
        
        // add the length of the end points
        length += getNumContours() * 2;
        
        // add the length of the instructions
        length += 2 + getNumInstructions();
        
        // add the length of the flags, avoiding repeats
        for (int i = 0; i < getNumPoints(); i++) {
            // check for repeats
            while (i > 0 && (getFlag(i) == getFlag(i - 1)));
            length++;
        }
        
        // add the length of the xCoordinates
        for (int i = 0; i < getNumPoints(); i++) {
            if (xIsByte(i)) {
                length++;
            } else if (!xIsSame(i)) {
                length += 2;
            }
            
            if (yIsByte(i)) {
                length++;
            } else if (!yIsSame(i)) {
                length += 2;
            }
        }
         
        return length;
    }