<action dev="POI-DEVELOPERS" type="add">49508 - Allow the addition of paragraphs to XWPF Table Cells</action>
<action dev="POI-DEVELOPERS" type="fix">49446 - Don't consider 17.16.23 field codes as properly part of the paragraph's text</action>
<action dev="POI-DEVELOPERS" type="fix">XSLFSlideShow shouldn't break on .thmx (theme) files. Support for them is still very limited though</action>
+ <action dev="POI-DEVELOPERS" type="fix">HWPF: Improve reading of auto-saved ("complex") documents</action>
</release>
<release version="3.7-beta1" date="2010-06-20">
<action dev="POI-DEVELOPERS" type="fix">49432 - Lazy caching of XSSFComment CTComment objects by reference, to make repeated comment searching faster</action>
package org.apache.poi.hwpf.model;
+import org.apache.poi.hwpf.model.io.HWPFOutputStream;
+import org.apache.poi.poifs.common.POIFSConstants;
+
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
-import org.apache.poi.hwpf.model.io.HWPFOutputStream;
-import org.apache.poi.poifs.common.POIFSConstants;
-
/**
* The piece table for matching up character positions to bits of text. This
* mostly works in bytes, but the TextPieces themselves work in characters. This
*/
public final class TextPieceTable implements CharIndexTranslator {
protected ArrayList<TextPiece> _textPieces = new ArrayList<TextPiece>();
+ protected ArrayList<TextPiece> _textPiecesFCOrder = new ArrayList<TextPiece>();
// int _multiple;
int _cpMin;
// In the interest of our sanity, now sort the text pieces
// into order, if they're not already
- TextPiece[] tp = _textPieces.toArray(new TextPiece[_textPieces.size()]);
- Arrays.sort(tp);
- for (int i = 0; i < tp.length; i++) {
- _textPieces.set(i, tp[i]);
- }
+ Collections.sort(_textPieces);
+ _textPiecesFCOrder = new ArrayList<TextPiece>(_textPieces);
+ Collections.sort(_textPiecesFCOrder, new FCComparator());
}
public int getCpMin() {
return _textPieces;
}
+ public void add(TextPiece piece) {
+ _textPieces.add(piece);
+ _textPiecesFCOrder.add(piece);
+ Collections.sort(_textPieces);
+ Collections.sort(_textPiecesFCOrder, new FCComparator());
+ }
+
/**
* Is the text at the given Character offset unicode, or plain old ascii? In
* a very evil fashion, you have to actually know this to make sense of
public int getCharIndex(int bytePos) {
int charCount = 0;
- for(TextPiece tp : _textPieces) {
+ for(TextPiece tp : _textPiecesFCOrder) {
int pieceStart = tp.getPieceDescriptor().getFilePosition();
if (pieceStart >= bytePos) {
break;
return charCount;
}
+ private static class FCComparator implements Comparator<TextPiece> {
+ public int compare(TextPiece textPiece, TextPiece textPiece1) {
+ if (textPiece.getPieceDescriptor().fc>textPiece1.getPieceDescriptor().fc) {
+ return 1;
+ } else if (textPiece.getPieceDescriptor().fc<textPiece1.getPieceDescriptor().fc) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+ }
}