Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
        /**
         * StyleSheet constructor. Loads a document's stylesheet information,
         *
         * @param tableStream A byte array Containing a document's raw stylesheet
         *        info. Found by using FileInformationBlock.GetFcStshf() and
         *        FileInformationBLock.GetLcbStshf()
         */
        public StyleSheet(byte[] tableStream, int offset)
        {
            int startoffset = offset;

            _stshiLength = LittleEndian.GetShort(tableStream, offset);
            offset      += LittleEndianConsts.SHORT_SIZE;
            int stdCount = LittleEndian.GetShort(tableStream, offset);

            offset           += LittleEndianConsts.SHORT_SIZE;
            _baseLength       = LittleEndian.GetShort(tableStream, offset);
            offset           += LittleEndianConsts.SHORT_SIZE;
            _flags            = LittleEndian.GetShort(tableStream, offset);
            offset           += LittleEndianConsts.SHORT_SIZE;
            _maxIndex         = LittleEndian.GetShort(tableStream, offset);
            offset           += LittleEndianConsts.SHORT_SIZE;
            _maxFixedIndex    = LittleEndian.GetShort(tableStream, offset);
            offset           += LittleEndianConsts.SHORT_SIZE;
            _stylenameVersion = LittleEndian.GetShort(tableStream, offset);
            offset           += LittleEndianConsts.SHORT_SIZE;

            _rgftc    = new int[3];
            _rgftc[0] = LittleEndian.GetShort(tableStream, offset);
            offset   += LittleEndianConsts.SHORT_SIZE;
            _rgftc[1] = LittleEndian.GetShort(tableStream, offset);
            offset   += LittleEndianConsts.SHORT_SIZE;
            _rgftc[2] = LittleEndian.GetShort(tableStream, offset);
            offset   += LittleEndianConsts.SHORT_SIZE;

            offset             = startoffset + LittleEndianConsts.SHORT_SIZE + _stshiLength;
            _styleDescriptions = new StyleDescription[stdCount];
            for (int x = 0; x < stdCount; x++)
            {
                int stdSize = LittleEndian.GetShort(tableStream, offset);
                //get past the size
                offset += 2;
                if (stdSize > 0)
                {
                    //byte[] std = new byte[stdSize];

                    StyleDescription aStyle = new StyleDescription(tableStream,
                                                                   _baseLength, offset, true);

                    _styleDescriptions[x] = aStyle;
                }

                offset += stdSize;
            }
            for (int x = 0; x < _styleDescriptions.Length; x++)
            {
                if (_styleDescriptions[x] != null)
                {
                    CreatePap(x);
                    CreateChp(x);
                }
            }
        }
Beispiel #4
0
        public override bool Equals(Object o)
        {
            StyleDescription sd = (StyleDescription)o;

            if (sd._infoshort == _infoshort && sd._infoshort2 == _infoshort2 &&
                sd._infoshort3 == _infoshort3 && sd._bchUpe == _bchUpe &&
                sd._infoshort4 == _infoshort4 &&
                _name.Equals(sd._name))
            {
                if (!Arrays.Equals(_upxs, sd._upxs))
                {
                    return(false);
                }
                return(true);
            }
            return(false);
        }
Beispiel #5
0
        /**
         * StyleSheet constructor. Loads a document's stylesheet information,
         *
         * @param tableStream A byte array Containing a document's raw stylesheet
         *        info. Found by using FileInformationBlock.GetFcStshf() and
         *        FileInformationBLock.GetLcbStshf()
         */
        public StyleSheet(byte[] tableStream, int offset)
        {
            int startoffset = offset;
            _stshiLength = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            int stdCount = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            _baseLength = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            _flags = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            _maxIndex = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            _maxFixedIndex = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            _stylenameVersion = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;

            _rgftc = new int[3];
            _rgftc[0] = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            _rgftc[1] = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;
            _rgftc[2] = LittleEndian.GetShort(tableStream, offset);
            offset += LittleEndianConsts.SHORT_SIZE;

            offset = startoffset + LittleEndianConsts.SHORT_SIZE + _stshiLength;
            _styleDescriptions = new StyleDescription[stdCount];
            for (int x = 0; x < stdCount; x++)
            {
                int stdSize = LittleEndian.GetShort(tableStream, offset);
                //get past the size
                offset += 2;
                if (stdSize > 0)
                {
                    //byte[] std = new byte[stdSize];

                    StyleDescription aStyle = new StyleDescription(tableStream,
                      _baseLength, offset, true);

                    _styleDescriptions[x] = aStyle;
                }

                offset += stdSize;

            }
            for (int x = 0; x < _styleDescriptions.Length; x++)
            {
                if (_styleDescriptions[x] != null)
                {
                    CreatePap(x);
                    CreateChp(x);
                }
            }
        }