public void dumpChpx( boolean withProperties, boolean withSprms ) { for ( CHPX chpx : _doc.getCharacterTable().getTextRuns() ) { System.out.println( chpx ); if ( withProperties ) { System.out.println( chpx.getCharacterProperties( _doc.getStyleSheet(), (short) StyleSheet.NIL_STYLE ) ); } if ( withSprms ) { SprmIterator sprmIt = new SprmIterator( chpx.getGrpprl(), 0 ); while ( sprmIt.hasNext() ) { SprmOperation sprm = sprmIt.next(); System.out.println( "\t" + sprm); } } String text = new Range( chpx.getStart(), chpx.getEnd(), _doc.getOverallRange() ) { public String toString() { return "CHPX range (" + super.toString() + ")"; } }.text(); StringBuilder stringBuilder = new StringBuilder(); for ( char c : text.toCharArray() ) { if ( c < 30 ) stringBuilder.append("\\0x").append(Integer.toHexString(c)); else stringBuilder.append( c ); } System.out.println( stringBuilder ); } }
/** * Inserts text into the front of this range. * * @param text * The text to insert * @return The character run that text was inserted into. */ public CharacterRun insertBefore( String text ) { initAll(); _text.insert( _start, text ); _doc.getCharacterTable().adjustForInsert( _charStart, text.length() ); _doc.getParagraphTable().adjustForInsert( _parStart, text.length() ); _doc.getSectionTable().adjustForInsert( _sectionStart, text.length() ); if ( _doc instanceof HWPFDocument ) { ( (BookmarksImpl) ( (HWPFDocument) _doc ).getBookmarks() ) .afterInsert( _start, text.length() ); } adjustForInsert( text.length() ); // update the FIB.CCPText + friends fields adjustFIB( text.length() ); sanityCheck(); return getCharacterRun( 0 ); }
lastTextRunStart = boundary; int startPosition = binarySearch( oldChpxSortedByStartPos, boundary ); startPosition = Math.abs( startPosition ); while ( startPosition >= oldChpxSortedByStartPos.size() )
int chpSize = LittleEndian.getInt(header, 0xfe); int fcMin = LittleEndian.getInt(header, 0x18); CHPBinTable cbt = new CHPBinTable(header, tableStream, chpOffset, chpSize, fcMin); headerProps = null; List textRuns = cbt.getTextRuns(); Iterator runIt = textRuns.iterator(); Iterator textIt = textPieces.iterator();
_cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), _tpt); _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), _tpt); _cbt.rebuild( _cft ); _pbt.rebuild( _text, _cft );
/** * Inserts text into the front of this range and it gives that text the * CharacterProperties specified in props. * * @param text * The text to insert. * @param props * The CharacterProperties to give the text. * @return A new CharacterRun that has the given text and properties and is * n ow a part of the document. * @deprecated POI 3.8 beta 4. User code should not work with {@link CharacterProperties} */ @Deprecated private CharacterRun insertBefore(String text, CharacterProperties props) { initAll(); PAPX papx = _paragraphs.get(_parStart); short istd = papx.getIstd(); StyleSheet ss = _doc.getStyleSheet(); CharacterProperties baseStyle = ss.getCharacterStyle(istd); byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); SprmBuffer buf = new SprmBuffer(grpprl, 0); _doc.getCharacterTable().insert(_charStart, _start, buf); return insertBefore(text); }
public void writeTo( ByteArrayOutputStream wordDocumentStream, ByteArrayOutputStream tableStream, int fcMin, CharIndexTranslator translator ) throws IOException { /* * Page 35: * * "Associated with each interval is a BTE. A BTE holds a four-byte PN * (page number) which identifies the FKP page in the file which * contains the formatting information for that interval. A CHPX FKP * further partitions an interval into runs of exception text." */ PlexOfCps bte = new PlexOfCps( 4 ); // each FKP must start on a 512 byte page. int docOffset = wordDocumentStream.size(); int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE; if (mod != 0) { byte[] padding = new byte[POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod]; wordDocumentStream.write(padding); } // get the page number for the first fkp docOffset = wordDocumentStream.size(); int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE; // get the ending fc // CHPX lastRun = _textRuns.get(_textRuns.size() - 1);
_cbt.rebuild( cft ); _pbt.rebuild( _text, cft );
_cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), _tpt); _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), _tpt); _cbt.rebuild( _cft ); _pbt.rebuild( _text, _cft );
/** * Inserts text into the front of this range and it gives that text the * CharacterProperties specified in props. * * @param text * The text to insert. * @param props * The CharacterProperties to give the text. * @return A new CharacterRun that has the given text and properties and is * n ow a part of the document. * @deprecated User code should not work with {@link CharacterProperties} */ @Deprecated public CharacterRun insertBefore(String text, CharacterProperties props) // throws UnsupportedEncodingException { initAll(); PAPX papx = _paragraphs.get(_parStart); short istd = papx.getIstd(); StyleSheet ss = _doc.getStyleSheet(); CharacterProperties baseStyle = ss.getCharacterStyle(istd); byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); SprmBuffer buf = new SprmBuffer(grpprl, 0); _doc.getCharacterTable().insert(_charStart, _start, buf); return insertBefore(text); }
_cbt.writeTo(wordDocumentStream, tableStream, mainOffset, _cft.getTextPieceTable()); _fib.setLcbPlcfbteChpx(tableStream.size() - tableOffset); tableOffset = tableStream.size();
_cbt.rebuild( cft ); _pbt.rebuild( _text, cft );
public void dumpChpx( boolean withProperties, boolean withSprms ) for ( CHPX chpx : _doc.getCharacterTable().getTextRuns() )
/** * Inserts text into the front of this range. * * @param text * The text to insert * @return The character run that text was inserted into. */ public CharacterRun insertBefore( String text ) { initAll(); _text.insert( _start, text ); _doc.getCharacterTable().adjustForInsert( _charStart, text.length() ); _doc.getParagraphTable().adjustForInsert( _parStart, text.length() ); _doc.getSectionTable().adjustForInsert( _sectionStart, text.length() ); if ( _doc instanceof HWPFDocument ) { ( (BookmarksImpl) ( (HWPFDocument) _doc ).getBookmarks() ) .afterInsert( _start, text.length() ); } adjustForInsert( text.length() ); // update the FIB.CCPText + friends fields adjustFIB( text.length() ); assert sanityCheck(); return getCharacterRun( 0 ); }
/** * Inserts text onto the end of this range and gives that text the * CharacterProperties specified in props. * * @param text * The text to insert. * @param props * The CharacterProperties to give the text. * @return A new CharacterRun that has the given text and properties and is * n ow a part of the document. * @deprecated POI 3.8 beta 4. User code should not work with {@link CharacterProperties} */ @Deprecated private CharacterRun insertAfter(String text, CharacterProperties props) { initAll(); PAPX papx = _paragraphs.get(_parEnd - 1); short istd = papx.getIstd(); StyleSheet ss = _doc.getStyleSheet(); CharacterProperties baseStyle = ss.getCharacterStyle(istd); byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); SprmBuffer buf = new SprmBuffer(grpprl, 0); _doc.getCharacterTable().insert(_charEnd, _end, buf); _charEnd++; return insertAfter(text); }
public void writeTo( HWPFOutputStream wordDocumentStream, HWPFOutputStream tableStream, int fcMin, CharIndexTranslator translator ) throws IOException { /* * Page 35: * * "Associated with each interval is a BTE. A BTE holds a four-byte PN * (page number) which identifies the FKP page in the file which * contains the formatting information for that interval. A CHPX FKP * further partitions an interval into runs of exception text." */ PlexOfCps bte = new PlexOfCps( 4 ); // each FKP must start on a 512 byte page. int docOffset = wordDocumentStream.getOffset(); int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE; if (mod != 0) { byte[] padding = new byte[POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod]; wordDocumentStream.write(padding); } // get the page number for the first fkp docOffset = wordDocumentStream.getOffset(); int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE; // get the ending fc // CHPX lastRun = _textRuns.get(_textRuns.size() - 1);
lastTextRunStart = endExclusive; int startPosition = binarySearch( oldChpxSortedByStartPos, boundary ); startPosition = Math.abs( startPosition ); while ( startPosition >= oldChpxSortedByStartPos.size() )
/** * Used to construct a Range from a document. This is generally used to * create a Range that spans the whole document, or at least one whole part * of the document (eg main text, header, comment) * * @param start * Starting character offset of the range. * @param end * Ending character offset of the range. * @param doc * The HWPFDocument the range is based on. */ public Range(int start, int end, HWPFDocumentCore doc) { _start = start; _end = end; _doc = doc; _sections = _doc.getSectionTable().getSections(); _paragraphs = _doc.getParagraphTable().getParagraphs(); _characters = _doc.getCharacterTable().getTextRuns(); _text = _doc.getText(); _parent = new WeakReference<>(null); sanityCheckStartEnd(); }
/** * Inserts text onto the end of this range * * @param text * The text to insert * @return The character run the text was inserted into. */ public CharacterRun insertAfter( String text ) { initAll(); _text.insert( _end, text ); _doc.getCharacterTable().adjustForInsert( _charEnd - 1, text.length() ); _doc.getParagraphTable().adjustForInsert( _parEnd - 1, text.length() ); _doc.getSectionTable().adjustForInsert( _sectionEnd - 1, text.length() ); if ( _doc instanceof HWPFDocument ) { ( (BookmarksImpl) ( (HWPFDocument) _doc ).getBookmarks() ) .afterInsert( _end, text.length() ); } adjustForInsert( text.length() ); assert sanityCheck(); return getCharacterRun( numCharacterRuns() - 1 ); }
/** * Inserts text onto the end of this range and gives that text the * CharacterProperties specified in props. * * @param text * The text to insert. * @param props * The CharacterProperties to give the text. * @return A new CharacterRun that has the given text and properties and is * n ow a part of the document. * @deprecated User code should not work with {@link CharacterProperties} */ @Deprecated public CharacterRun insertAfter(String text, CharacterProperties props) // throws UnsupportedEncodingException { initAll(); PAPX papx = _paragraphs.get(_parEnd - 1); short istd = papx.getIstd(); StyleSheet ss = _doc.getStyleSheet(); CharacterProperties baseStyle = ss.getCharacterStyle(istd); byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); SprmBuffer buf = new SprmBuffer(grpprl, 0); _doc.getCharacterTable().insert(_charEnd, _end, buf); _charEnd++; return insertAfter(text); }