Beispiel #1
0
        public void SetUp()
        {
            /**@todo verify the constructors*/
            _hWPFDocFixture = new HWPFDocFixture(this);
            _hWPFDocFixture.SetUp();
            FileInformationBlock fib = _hWPFDocFixture._fib;
            byte[] mainStream = _hWPFDocFixture._mainStream;
            byte[] tableStream = _hWPFDocFixture._tableStream;

            _hWPFDocFixture.SetUp();
            _styleSheet = new StyleSheet(tableStream, fib.GetFcStshf());
        }
Beispiel #2
0
        public void TestReadWriteFromNonZeroOffset()
        {
            HWPFFileSystem fileSys = new HWPFFileSystem();
            HWPFStream tableOut = fileSys.GetStream("1Table");

            tableOut.Write(new byte[20]); // 20 bytes of whatever at the front.
            _styleSheet.WriteTo(tableOut);

            byte[] newTableStream = tableOut.ToArray();

            StyleSheet newStyleSheet = new StyleSheet(newTableStream, 20);
            Assert.AreEqual(newStyleSheet, _styleSheet);
        }
Beispiel #3
0
        public void TestReadWrite()
        {
            HWPFFileSystem fileSys = new HWPFFileSystem();

            HWPFStream tableOut = fileSys.GetStream("1Table");
            HWPFStream mainOut = fileSys.GetStream("WordDocument");

            _styleSheet.WriteTo(tableOut);

            byte[] newTableStream = tableOut.ToArray();

            StyleSheet newStyleSheet = new StyleSheet(newTableStream, 0);
            Assert.AreEqual(newStyleSheet, _styleSheet);
        }
Beispiel #4
0
        public CharacterProperties GetCharacterProperties(StyleSheet ss, short istd)
        {
            if (ss == null)
            {
                // TODO Fix up for Word 6/95
                return new CharacterProperties();
            }

            CharacterProperties baseStyle = ss.GetCharacterStyle(istd);
            if (baseStyle == null)
                baseStyle = new CharacterProperties();

            CharacterProperties props = 
                CharacterSprmUncompressor.UncompressCHP(baseStyle, GetGrpprl(), 0);
            return props;
        }
Beispiel #5
0
        public ParagraphProperties GetParagraphProperties(StyleSheet ss)
        {
            if (ss == null)
            {
                // TODO Fix up for Word 6/95
                return new ParagraphProperties();
            }

            short istd = GetIstd();
            ParagraphProperties baseStyle = ss.GetParagraphStyle(istd);
            ParagraphProperties props = ParagraphSprmUncompressor.UncompressPAP(baseStyle, GetGrpprl(), 2);
            return props;
        }
Beispiel #6
0
 private void assertLevels(Range documentRange, StyleSheet styleSheet, int parIndex, int expectedStyleLvl, int expectedParLvl)
 {
     Paragraph par = documentRange.GetParagraph(parIndex);
     Assert.AreEqual(expectedStyleLvl, styleSheet.GetParagraphStyle(par.GetStyleIndex()).GetLvl());
     Assert.AreEqual(expectedParLvl, par.GetLvl());
 }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HWPFDocument"/> class.
        /// </summary>
        /// <param name="directory">The directory.</param>
        public HWPFDocument(DirectoryNode directory)
            : base(directory)
        {
            _endnotes = new NotesImpl(_endnotesTables);
            _footnotes = new NotesImpl(_footnotesTables);

            // Load the main stream and FIB
            // Also handles HPSF bits

            // Do the CP Split
            _cpSplit = new CPSplitCalculator(_fib);

            // Is this document too old for us?
            if (_fib.GetNFib() < 106)
            {
                throw new OldWordFileFormatException("The document is too old - Word 95 or older. Try HWPFOldDocument instead?");
            }

            // use the fib to determine the name of the table stream.
            String name = "0Table";
            if (_fib.IsFWhichTblStm())
            {
                name = "1Table";
            }

            // Grab the table stream.
            DocumentEntry tableProps;
            try
            {
                tableProps =
                    (DocumentEntry)directory.GetEntry(name);
            }
            catch (FileNotFoundException)
            {
                throw new InvalidOperationException("Table Stream '" + name + "' wasn't found - Either the document is corrupt, or is Word95 (or earlier)");
            }

            // read in the table stream.
            _tableStream = new byte[tableProps.Size];
            directory.CreatePOIFSDocumentReader(name).Read(_tableStream);

            _fib.FillVariableFields(_mainStream, _tableStream);

            // read in the data stream.
            try
            {
                DocumentEntry dataProps =
                    (DocumentEntry)directory.GetEntry("Data");
                _dataStream = new byte[dataProps.Size];
                directory.CreatePOIFSDocumentReader("Data").Read(_dataStream);
            }
            catch (FileNotFoundException)
            {
                _dataStream = new byte[0];
            }

            // Get the cp of the start of text in the main stream
            // The latest spec doc says this is always zero!
            int fcMin = 0;
            //fcMin = _fib.GetFcMin()

            // Start to load up our standard structures.
            _dop = new DocumentProperties(_tableStream, _fib.GetFcDop());
            _cft = new ComplexFileTable(_mainStream, _tableStream, _fib.GetFcClx(), fcMin);
            TextPieceTable _tpt = _cft.GetTextPieceTable();


            // Now load the rest of the properties, which need to be adjusted
            //  for where text really begin
            _cbt = new CHPBinTable(_mainStream, _tableStream, _fib.GetFcPlcfbteChpx(), _fib.GetLcbPlcfbteChpx(), _tpt);
            _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.GetFcPlcfbtePapx(), _fib.GetLcbPlcfbtePapx(), _tpt);

            _text = _tpt.Text;

            /*
 * in this mode we preserving PAPX/CHPX structure from file, so text may
 * miss from output, and text order may be corrupted
 */
            bool preserveBinTables = false;
            try
            {
                preserveBinTables = Boolean.Parse(
                    ConfigurationManager.AppSettings[PROPERTY_PRESERVE_BIN_TABLES]);
            }
            catch (Exception)
            {
                // ignore;
            }

            if (!preserveBinTables)
            {
                _cbt.Rebuild(_cft);
                _pbt.Rebuild(_text, _cft);
            }

            /*
             * Property to disable text rebuilding. In this mode changing the text
             * will lead to unpredictable behavior
             */
            bool preserveTextTable = false;
            try
            {
                preserveTextTable = Boolean.Parse(
                        ConfigurationManager.AppSettings[PROPERTY_PRESERVE_TEXT_TABLE]);
            }
            catch (Exception)
            {
                // ignore;
            }
            if (!preserveTextTable)
            {
                _cft = new ComplexFileTable();
                _tpt = _cft.GetTextPieceTable();
                TextPiece textPiece = new SinglentonTextPiece(_text);
                _tpt.Add(textPiece);
                _text = textPiece.GetStringBuilder();
            }

            // Read FSPA and Escher information
            // _fspa = new FSPATable(_tableStream, _fib.getFcPlcspaMom(),
            // _fib.getLcbPlcspaMom(), getTextTable().getTextPieces());
            _fspaHeaders = new FSPATable(_tableStream, _fib,
                    FSPADocumentPart.HEADER);
            _fspaMain = new FSPATable(_tableStream, _fib, FSPADocumentPart.MAIN);

            if (_fib.GetFcDggInfo() != 0)
            {
                _dgg = new EscherRecordHolder(_tableStream, _fib.GetFcDggInfo(), _fib.GetLcbDggInfo());
            }
            else
            {
                _dgg = new EscherRecordHolder();
            }

            // read in the pictures stream
            _pictures = new PicturesTable(this, _dataStream, _mainStream, _fspa, _dgg);
            // And the art shapes stream
            _officeArts = new ShapesTable(_tableStream, _fib);

            // And escher pictures
            _officeDrawingsHeaders = new OfficeDrawingsImpl(_fspaHeaders, _dgg, _mainStream);
            _officeDrawingsMain = new OfficeDrawingsImpl(_fspaMain, _dgg, _mainStream);

            _st = new SectionTable(_mainStream, _tableStream, _fib.GetFcPlcfsed(), _fib.GetLcbPlcfsed(), fcMin, _tpt, _cpSplit);
            _ss = new StyleSheet(_tableStream, _fib.GetFcStshf());
            _ft = new FontTable(_tableStream, _fib.GetFcSttbfffn(), _fib.GetLcbSttbfffn());

            int listOffset = _fib.GetFcPlcfLst();
            int lfoOffset = _fib.GetFcPlfLfo();
            if (listOffset != 0 && _fib.GetLcbPlcfLst() != 0)
            {
                _lt = new ListTables(_tableStream, _fib.GetFcPlcfLst(), _fib.GetFcPlfLfo());
            }

            int sbtOffset = _fib.GetFcSttbSavedBy();
            int sbtLength = _fib.GetLcbSttbSavedBy();
            if (sbtOffset != 0 && sbtLength != 0)
            {
                _sbt = new SavedByTable(_tableStream, sbtOffset, sbtLength);
            }

            int rmarkOffset = _fib.GetFcSttbfRMark();
            int rmarkLength = _fib.GetLcbSttbfRMark();
            if (rmarkOffset != 0 && rmarkLength != 0)
            {
                _rmat = new RevisionMarkAuthorTable(_tableStream, rmarkOffset, rmarkLength);
            }


            _bookmarksTables = new BookmarksTables(_tableStream, _fib);
            _bookmarks = new BookmarksImpl(_bookmarksTables);

            _endnotesTables = new NotesTables(NoteType.ENDNOTE, _tableStream, _fib);
            _endnotes = new NotesImpl(_endnotesTables);
            _footnotesTables = new NotesTables(NoteType.FOOTNOTE, _tableStream, _fib);
            _footnotes = new NotesImpl(_footnotesTables);

            _fieldsTables = new FieldsTables(_tableStream, _fib);
            _fields = new FieldsImpl(_fieldsTables);
        }
Beispiel #8
0
        public void TearDown()
        {
            _styleSheet = null;

            _hWPFDocFixture = null;
        }
Beispiel #9
0
        /**
         *
         * @param chpx The chpx this object is based on.
         * @param ss The stylesheet for the document this run belongs to.
         * @param istd The style index if this Run's base style.
         * @param parent The parent range of this character run (usually a paragraph).
         */
        internal CharacterRun(CHPX chpx, StyleSheet ss, short istd, Range parent)
            : base(Math.Max(parent._start, chpx.Start), Math.Min(parent._end, chpx.End), parent)
        {

            _props = chpx.GetCharacterProperties(ss, istd);
            _chpx = chpx.GetSprmBuf();
        }
Beispiel #10
0
 /**
  *
  * @param numbered true if the list should be numbered; false if it should be
  *        bulleted.
  * @param styleSheet The document's stylesheet.
  */
 public HWPFList(bool numbered, StyleSheet styleSheet)
 {
     _listData = new ListData((int)(new Random((int)DateTime.Now.Ticks).Next(0,100)/100 * DateTime.Now.Millisecond), numbered);
     _override = new ListFormatOverride(_listData.GetLsid());
     _styleSheet = styleSheet;
 }
Beispiel #11
0
        public void TearDown()
        {
            _styleSheet = null;

            _hWPFDocFixture = null;
        }