public void WriteTo(HWPFFileSystem sys, int fcMin) { HWPFStream docStream = sys.GetStream("WordDocument"); HWPFStream tableStream = sys.GetStream("1Table"); int offset = docStream.Offset; int len = _sections.Count; PlexOfCps plex = new PlexOfCps(SED_SIZE); for (int x = 0; x < len; x++) { SEPX sepx = _sections[x]; byte[] grpprl = sepx.GetGrpprl(); // write the sepx to the document stream. starts with a 2 byte size // followed by the grpprl byte[] shortBuf = new byte[2]; LittleEndian.PutShort(shortBuf, (short)grpprl.Length); docStream.Write(shortBuf); docStream.Write(grpprl); // set the fc in the section descriptor SectionDescriptor sed = sepx.GetSectionDescriptor(); sed.SetFc(offset); // add the section descriptor bytes to the PlexOfCps. // original line - //GenericPropertyNode property = new GenericPropertyNode(sepx.Start, sepx.End, sed.ToArray()); // Line using Ryan's FCtoCP() conversion method - // unable to observe any effect on our testcases when using this code - piers GenericPropertyNode property = new GenericPropertyNode(tpt.GetCharIndex(sepx.StartBytes), tpt.GetCharIndex(sepx.EndBytes), sed.ToArray()); plex.AddProperty(property); offset = docStream.Offset; } tableStream.Write(plex.ToByteArray()); }
public OldSectionTable(byte[] documentStream, int offset, int size) { PlexOfCps sedPlex = new PlexOfCps(documentStream, offset, size, 12); int length = sedPlex.Length; for (int x = 0; x < length; x++) { GenericPropertyNode node = sedPlex.GetProperty(x); SectionDescriptor sed = new SectionDescriptor(node.Bytes, 0); int fileOffset = sed.GetFc(); int startAt = node.Start; int endAt = node.End; SEPX sepx; // check for the optimization if (fileOffset == unchecked ((int)0xffffffff)) { sepx = new SEPX(sed, startAt, endAt, new byte[0]); } else { // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.GetShort(documentStream, fileOffset); // Because we don't properly know about all the details of the old // section properties, and we're trying to decode them as if they // were the new ones, we sometimes "need" more data than we have. // As a workaround, have a few extra 0 bytes on the end! byte[] buf = new byte[sepxSize + 2]; fileOffset += LittleEndianConsts.SHORT_SIZE; Array.Copy(documentStream, fileOffset, buf, 0, buf.Length >= documentStream.Length - fileOffset?documentStream.Length - fileOffset: buf.Length); sepx = new SEPX(sed, startAt, endAt, buf); } _sections.Add(sepx); } _sections.Sort(PropertyNode.SEPXComparator.instance); }
public OldSectionTable(byte[] documentStream, int offset, int size) { PlexOfCps sedPlex = new PlexOfCps(documentStream, offset, size, 12); int length = sedPlex.Length; for (int x = 0; x < length; x++) { GenericPropertyNode node = sedPlex.GetProperty(x); SectionDescriptor sed = new SectionDescriptor(node.Bytes, 0); int fileOffset = sed.GetFc(); int startAt = node.Start; int endAt = node.End; SEPX sepx; // check for the optimization if (fileOffset == unchecked((int)0xffffffff)) { sepx = new SEPX(sed, startAt, endAt, new byte[0]); } else { // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.GetShort(documentStream, fileOffset); // Because we don't properly know about all the details of the old // section properties, and we're trying to decode them as if they // were the new ones, we sometimes "need" more data than we have. // As a workaround, have a few extra 0 bytes on the end! byte[] buf = new byte[sepxSize+2]; fileOffset += LittleEndianConsts.SHORT_SIZE; Array.Copy(documentStream, fileOffset, buf, 0, buf.Length>=documentStream.Length - fileOffset?documentStream.Length - fileOffset: buf.Length); sepx = new SEPX(sed, startAt, endAt,buf); } _sections.Add(sepx); } _sections.Sort(PropertyNode.SEPXComparator.instance); }
public SectionTable(byte[] documentStream, byte[] tableStream, int OffSet, int size, int fcMin, TextPieceTable tpt, CPSplitCalculator cps) { PlexOfCps sedPlex = new PlexOfCps(tableStream, OffSet, size, SED_SIZE); this.tpt = tpt; this._text = tpt.TextPieces; int length = sedPlex.Length; for (int x = 0; x < length; x++) { GenericPropertyNode node = sedPlex.GetProperty(x); SectionDescriptor sed = new SectionDescriptor(node.Bytes, 0); int fileOffset = sed.GetFc(); int startAt = CPtoFC(node.Start); int endAt = CPtoFC(node.End); // check for the optimization if (fileOffset == unchecked((int)0xffffffff)) { _sections.Add(new SEPX(sed, startAt, endAt, new byte[0])); } else { // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.GetShort(documentStream, fileOffset); byte[] buf = new byte[sepxSize]; fileOffset += LittleEndianConsts.SHORT_SIZE; Array.Copy(documentStream, fileOffset, buf, 0, buf.Length); _sections.Add(new SEPX(sed, startAt, endAt, buf)); } } // Some files seem to lie about their unicode status, which // is very very pesky. Try to work around these, but this // is Getting on for black magic... int mainEndsAt = cps.GetMainDocumentEnd(); bool matchAt = false; bool matchHalf = false; for (int i = 0; i < _sections.Count; i++) { SEPX s = _sections[i]; if (s.End == mainEndsAt) { matchAt = true; } else if (s.EndBytes == mainEndsAt || s.EndBytes == mainEndsAt - 1) { matchHalf = true; } } if (!matchAt && matchHalf) { //System.err.println("Your document seemed to be mostly unicode, but the section defInition was in bytes! Trying anyway, but things may well go wrong!"); for (int i = 0; i < _sections.Count; i++) { SEPX s = _sections[i]; GenericPropertyNode node = sedPlex.GetProperty(i); int startAt = node.Start; int endAt = node.End; s.Start = (startAt); s.End = (endAt); } } }
public SectionTable(byte[] documentStream, byte[] tableStream, int OffSet, int size, int fcMin, TextPieceTable tpt, int mainLength) { PlexOfCps sedPlex = new PlexOfCps(tableStream, OffSet, size, SED_SIZE); this.tpt = tpt; this._text = tpt.TextPieces; int length = sedPlex.Length; for (int x = 0; x < length; x++) { GenericPropertyNode node = sedPlex.GetProperty(x); SectionDescriptor sed = new SectionDescriptor(node.Bytes, 0); int fileOffset = sed.GetFc(); //int startAt = CPtoFC(node.Start); //int endAt = CPtoFC(node.End); int startAt = node.Start; int endAt = node.End; // check for the optimization if (fileOffset == unchecked ((int)0xffffffff)) { _sections.Add(new SEPX(sed, startAt, endAt, new byte[0])); } else { // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.GetShort(documentStream, fileOffset); byte[] buf = new byte[sepxSize]; fileOffset += LittleEndianConsts.SHORT_SIZE; Array.Copy(documentStream, fileOffset, buf, 0, buf.Length); _sections.Add(new SEPX(sed, startAt, endAt, buf)); } } // Some files seem to lie about their unicode status, which // is very very pesky. Try to work around these, but this // is Getting on for black magic... int mainEndsAt = mainLength; bool matchAt = false; bool matchHalf = false; for (int i = 0; i < _sections.Count; i++) { SEPX s = _sections[i]; if (s.End == mainEndsAt) { matchAt = true; } else if (s.End == mainEndsAt || s.End == mainEndsAt - 1) { matchHalf = true; } } if (!matchAt && matchHalf) { //System.err.println("Your document seemed to be mostly unicode, but the section defInition was in bytes! Trying anyway, but things may well go wrong!"); for (int i = 0; i < _sections.Count; i++) { SEPX s = _sections[i]; GenericPropertyNode node = sedPlex.GetProperty(i); int startAt = node.Start; int endAt = node.End; s.Start = (startAt); s.End = (endAt); } } }
public SEPX(SectionDescriptor sed, int start, int end, byte[] grpprl) : base(start, end, new SprmBuffer(grpprl, 0)) { _sed = sed; }
public SEPX(SectionDescriptor sed, int start, int end, byte[] grpprl) : base(start, end, new SprmBuffer(grpprl, 0)) { _sed = sed; }
public override bool Equals(Object o) { SectionDescriptor sed = (SectionDescriptor)o; return(sed.fn == fn && sed.fnMpr == fnMpr); }