private void symbolIDCodeLengths()

in src/main/java/org/apache/pdfbox/jbig2/segments/TextRegion.java [1029:1102]


    private void symbolIDCodeLengths() throws IOException
    {
        /* 1) - 2) */
        final List<Code> runCodeTable = new ArrayList<Code>();

        for (int i = 0; i < 35; i++)
        {
            final int prefLen = (int) (subInputStream.readBits(4) & 0xf);
            if (prefLen > 0)
            {
                runCodeTable.add(new Code(prefLen, 0, i, false));
            }
        }

        HuffmanTable ht = new FixedSizeTable(runCodeTable);

        /* 3) - 5) */
        long previousCodeLength = 0;

        int counter = 0;
        final List<Code> sbSymCodes = new ArrayList<Code>();
        while (counter < amountOfSymbols)
        {
            final long code = ht.decode(subInputStream);
            if (code < 32)
            {
                if (code > 0)
                {
                    sbSymCodes.add(new Code((int) code, 0, counter, false));
                }

                previousCodeLength = code;
                counter++;
            }
            else
            {

                long runLength = 0;
                long currCodeLength = 0;
                if (code == 32)
                {
                    runLength = 3 + subInputStream.readBits(2);
                    if (counter > 0)
                    {
                        currCodeLength = previousCodeLength;
                    }
                }
                else if (code == 33)
                {
                    runLength = 3 + subInputStream.readBits(3);
                }
                else if (code == 34)
                {
                    runLength = 11 + subInputStream.readBits(7);
                }

                for (int j = 0; j < runLength; j++)
                {
                    if (currCodeLength > 0)
                    {
                        sbSymCodes.add(new Code((int) currCodeLength, 0, counter, false));
                    }
                    counter++;
                }
            }
        }

        /* 6) - Skip over remaining bits in the last Byte read */
        subInputStream.skipBits();

        /* 7) */
        symbolCodeTable = new FixedSizeTable(sbSymCodes);

    }