Example #1
0
        /**
         * Creates a CharacterProperties object from a chpx stored in the
         * StyleDescription at the index istd in the StyleDescription array. The
         * CharacterProperties object is placed in the StyleDescription at istd after
         * its been Created. Not every StyleDescription will contain a chpx. In these
         * cases this function does nothing.
         *
         * @param istd The index of the StyleDescription to create the
         *        CharacterProperties object from.
         */
        private void CreateChp(int istd)
        {
            StyleDescription    sd  = _styleDescriptions[istd];
            CharacterProperties chp = sd.GetCHP();

            byte[] chpx      = sd.GetCHPX();
            int    baseIndex = sd.GetBaseStyle();

            if (baseIndex == istd)
            {
                // Oh dear, this isn't allowed...
                // The word file seems to be corrupted
                // Switch to using the nil style so that
                //  there's a chance we can read it
                baseIndex = NIL_STYLE;
            }

            // Build and decompress the Chp if required
            if (chp == null && chpx != null)
            {
                CharacterProperties parentCHP = new CharacterProperties();
                if (baseIndex != NIL_STYLE)
                {
                    parentCHP = _styleDescriptions[baseIndex].GetCHP();
                    if (parentCHP == null)
                    {
                        CreateChp(baseIndex);
                        parentCHP = _styleDescriptions[baseIndex].GetCHP();
                    }
                }

                chp = CharacterSprmUncompressor.UncompressCHP(parentCHP, chpx, 0);
                sd.SetCHP(chp);
            }
        }
Example #2
0
        /**
         * Creates a PartagraphProperties object from a papx stored in the
         * StyleDescription at the index istd in the StyleDescription array. The PAP
         * is placed in the StyleDescription at istd after its been Created. Not
         * every StyleDescription will contain a papx. In these cases this function
         * does nothing
         *
         * @param istd The index of the StyleDescription to create the
         *        ParagraphProperties  from (and also place the finished PAP in)
         */
        private void CreatePap(int istd)
        {
            StyleDescription    sd  = _styleDescriptions[istd];
            ParagraphProperties pap = sd.GetPAP();

            byte[] papx      = sd.GetPAPX();
            int    baseIndex = sd.GetBaseStyle();

            if (pap == null && papx != null)
            {
                ParagraphProperties parentPAP = new ParagraphProperties();
                if (baseIndex != NIL_STYLE)
                {
                    parentPAP = _styleDescriptions[baseIndex].GetPAP();
                    if (parentPAP == null)
                    {
                        if (baseIndex == istd)
                        {
                            // Oh dear, style claims that it is its own parent
                            throw new InvalidOperationException("Pap style " + istd + " claimed to have itself as its parent, which isn't allowed");
                        }
                        // Create the parent style
                        CreatePap(baseIndex);
                        parentPAP = _styleDescriptions[baseIndex].GetPAP();
                    }
                }

                pap = ParagraphSprmUncompressor.UncompressPAP(parentPAP, papx, 2);
                sd.SetPAP(pap);
            }
        }