View | Details | Raw Unified | Return to bug 46610
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java (-3 / +6 lines)
Lines 30-39 Link Here
30
	 * @param fcStart The start of the text for this property, in _bytes_
30
	 * @param fcStart The start of the text for this property, in _bytes_
31
	 * @param fcEnd The end of the text for this property, in _bytes_
31
	 * @param fcEnd The end of the text for this property, in _bytes_
32
	 */
32
	 */
33
	public BytePropertyNode(int fcStart, int fcEnd, Object buf, boolean isUnicode) {
33
	public BytePropertyNode(int fcStart, int fcEnd, CharIndexTranslator translator, Object buf, boolean isUnicode) {
34
		super(
34
		super(
35
				generateCp(fcStart, isUnicode),
35
				translator.getCharIndex(fcStart),
36
				generateCp(fcEnd, isUnicode),
36
				translator.getCharIndex(fcEnd),
37
				buf
37
				buf
38
		);
38
		);
39
		this.isUnicode = isUnicode;
39
		this.isUnicode = isUnicode;
Lines 45-58 Link Here
45
	}
45
	}
46
	
46
	
47
	public boolean isUnicode() {
47
	public boolean isUnicode() {
48
		//XXX Is this method useful?
48
		return isUnicode;
49
		return isUnicode;
49
	}
50
	}
50
	public int getStartBytes() {
51
	public int getStartBytes() {
52
		//XXX That is wrong in most cases!
51
		if(isUnicode)
53
		if(isUnicode)
52
			return getStart()*2;
54
			return getStart()*2;
53
		return getStart();
55
		return getStart();
54
	}
56
	}
55
	public int getEndBytes() {
57
	public int getEndBytes() {
58
		//XXX That is wrong in most cases!
56
		if(isUnicode)
59
		if(isUnicode)
57
			return getEnd()*2;
60
			return getEnd()*2;
58
		return getEnd();
61
		return getEnd();
(-)src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java (+14 lines)
Line 0 Link Here
1
package org.apache.poi.hwpf.model;
2
3
public interface CharIndexTranslator {
4
5
	/**
6
	 * Calculates the char index of the given byte index.
7
	 * 
8
	 * @param byteStart
9
	 * @param bytePos
10
	 * @return
11
	 */
12
	int getCharIndex(int bytePos);
13
14
}
(-)src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java (-2 / +2 lines)
Lines 121-127 Link Here
121
  {
121
  {
122
	boolean needsToBeUnicode = tpt.isUnicodeAtCharOffset(cpStart);
122
	boolean needsToBeUnicode = tpt.isUnicodeAtCharOffset(cpStart);
123
	  
123
	  
124
    CHPX insertChpx = new CHPX(0, 0, buf, needsToBeUnicode);
124
    CHPX insertChpx = new CHPX(0, 0, tpt,buf, needsToBeUnicode);
125
    
125
    
126
    // Ensure character offsets are really characters
126
    // Ensure character offsets are really characters
127
    insertChpx.setStart(cpStart);
127
    insertChpx.setStart(cpStart);
Lines 141-147 Link Here
141
    	//  Original, until insert at point
141
    	//  Original, until insert at point
142
    	//  New one
142
    	//  New one
143
    	//  Clone of original, on to the old end
143
    	//  Clone of original, on to the old end
144
        CHPX clone = new CHPX(0, 0, chpx.getSprmBuf(), needsToBeUnicode);
144
        CHPX clone = new CHPX(0, 0, tpt,chpx.getSprmBuf(), needsToBeUnicode);
145
        // Again ensure contains character based offsets no matter what
145
        // Again ensure contains character based offsets no matter what
146
        clone.setStart(cpStart);
146
        clone.setStart(cpStart);
147
        clone.setEnd(chpx.getEnd());
147
        clone.setEnd(chpx.getEnd());
(-)src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java (-2 / +4 lines)
Lines 61-68 Link Here
61
61
62
      for (int x = 0; x < _crun; x++)
62
      for (int x = 0; x < _crun; x++)
63
      {
63
      {
64
    	boolean isUnicode = tpt.isUnicodeAtByteOffset( getStart(x) );
64
    	int startAt = getStart(x) - fcMin;
65
        _chpxList.add(new CHPX(getStart(x) - fcMin, getEnd(x) - fcMin, getGrpprl(x), isUnicode));
65
    	boolean isUnicode = tpt.isUnicodeAtByteOffset( startAt );
66
		int endAt = getEnd(x) - fcMin;
67
		_chpxList.add(new CHPX(startAt, endAt, tpt, getGrpprl(x), isUnicode));
66
      }
68
      }
67
    }
69
    }
68
70
(-)src/scratchpad/src/org/apache/poi/hwpf/model/CHPX.java (-4 / +4 lines)
Lines 37-50 Link Here
37
public class CHPX extends BytePropertyNode
37
public class CHPX extends BytePropertyNode
38
{
38
{
39
39
40
  public CHPX(int fcStart, int fcEnd, byte[] grpprl, boolean isUnicode)
40
  public CHPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] grpprl, boolean isUnicode)
41
  {
41
  {
42
    super(fcStart, fcEnd, new SprmBuffer(grpprl), isUnicode);
42
    super(fcStart, fcEnd, translator, new SprmBuffer(grpprl), isUnicode);
43
  }
43
  }
44
44
45
  public CHPX(int fcStart, int fcEnd, SprmBuffer buf, boolean isUnicode)
45
  public CHPX(int fcStart, int fcEnd, CharIndexTranslator translator, SprmBuffer buf, boolean isUnicode)
46
  {
46
  {
47
    super(fcStart, fcEnd, buf, isUnicode);
47
    super(fcStart, fcEnd, translator ,buf, isUnicode);
48
  }
48
  }
49
49
50
50
(-)src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java (-2 / +2 lines)
Lines 78-84 Link Here
78
  {
78
  {
79
    boolean needsToBeUnicode = tpt.isUnicodeAtCharOffset(cpStart);
79
    boolean needsToBeUnicode = tpt.isUnicodeAtCharOffset(cpStart);
80
    
80
    
81
    PAPX forInsert = new PAPX(0, 0, buf, _dataStream, needsToBeUnicode);
81
    PAPX forInsert = new PAPX(0, 0, tpt, buf, _dataStream, needsToBeUnicode);
82
    
82
    
83
    // Ensure character offsets are really characters
83
    // Ensure character offsets are really characters
84
    forInsert.setStart(cpStart);
84
    forInsert.setStart(cpStart);
Lines 108-114 Link Here
108
    	//  Original, until insert at point
108
    	//  Original, until insert at point
109
    	//  New one
109
    	//  New one
110
    	//  Clone of original, on to the old end
110
    	//  Clone of original, on to the old end
111
        PAPX clone = new PAPX(0, 0, clonedBuf, _dataStream, needsToBeUnicode);
111
        PAPX clone = new PAPX(0, 0, tpt, clonedBuf, _dataStream, needsToBeUnicode);
112
        // Again ensure contains character based offsets no matter what
112
        // Again ensure contains character based offsets no matter what
113
        clone.setStart(cpStart);
113
        clone.setStart(cpStart);
114
        clone.setEnd(currentPap.getEnd());
114
        clone.setEnd(currentPap.getEnd());
(-)src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java (-1 / +1 lines)
Lines 70-76 Link Here
70
    	 boolean isUnicode = tpt.isUnicodeAtByteOffset(startAt);
70
    	 boolean isUnicode = tpt.isUnicodeAtByteOffset(startAt);
71
         //System.err.println(startAt + " -> " + endAt + " = " + isUnicode);
71
         //System.err.println(startAt + " -> " + endAt + " = " + isUnicode);
72
    	 
72
    	 
73
         _papxList.add(new PAPX(startAt, endAt, getGrpprl(x), getParagraphHeight(x), dataStream, isUnicode));
73
         _papxList.add(new PAPX(startAt, endAt, tpt, getGrpprl(x), getParagraphHeight(x), dataStream, isUnicode));
74
      }
74
      }
75
      _fkp = null;
75
      _fkp = null;
76
      _dataStream = dataStream;
76
      _dataStream = dataStream;
(-)src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java (-4 / +4 lines)
Lines 43-60 Link Here
43
  private ParagraphHeight _phe;
43
  private ParagraphHeight _phe;
44
  private int _hugeGrpprlOffset = -1;
44
  private int _hugeGrpprlOffset = -1;
45
45
46
  public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe, byte[] dataStream, boolean isUnicode)
46
  public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] papx, ParagraphHeight phe, byte[] dataStream, boolean isUnicode)
47
  {
47
  {
48
    super(fcStart, fcEnd, new SprmBuffer(papx), isUnicode);
48
    super(fcStart, fcEnd, translator, new SprmBuffer(papx), isUnicode);
49
    _phe = phe;
49
    _phe = phe;
50
    SprmBuffer buf = findHuge(new SprmBuffer(papx), dataStream);
50
    SprmBuffer buf = findHuge(new SprmBuffer(papx), dataStream);
51
    if(buf != null)
51
    if(buf != null)
52
      _buf = buf;
52
      _buf = buf;
53
  }
53
  }
54
54
55
  public PAPX(int fcStart, int fcEnd, SprmBuffer buf, byte[] dataStream, boolean isUnicode)
55
  public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, SprmBuffer buf, byte[] dataStream, boolean isUnicode)
56
  {
56
  {
57
    super(fcStart, fcEnd, buf, isUnicode);
57
    super(fcStart, fcEnd, translator, buf, isUnicode);
58
    _phe = new ParagraphHeight();
58
    _phe = new ParagraphHeight();
59
    buf = findHuge(buf, dataStream);
59
    buf = findHuge(buf, dataStream);
60
    if(buf != null)
60
    if(buf != null)
(-)src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java (-2 / +2 lines)
Lines 67-73 Link Here
67
      // check for the optimization
67
      // check for the optimization
68
      if (fileOffset == 0xffffffff)
68
      if (fileOffset == 0xffffffff)
69
      {
69
      {
70
        _sections.add(new SEPX(sed, startAt, endAt, new byte[0], isUnicodeAtStart));
70
        _sections.add(new SEPX(sed, startAt, endAt, tpt, new byte[0], isUnicodeAtStart));
71
      }
71
      }
72
      else
72
      else
73
      {
73
      {
Lines 76-82 Link Here
76
        byte[] buf = new byte[sepxSize];
76
        byte[] buf = new byte[sepxSize];
77
        fileOffset += LittleEndian.SHORT_SIZE;
77
        fileOffset += LittleEndian.SHORT_SIZE;
78
        System.arraycopy(documentStream, fileOffset, buf, 0, buf.length);
78
        System.arraycopy(documentStream, fileOffset, buf, 0, buf.length);
79
        _sections.add(new SEPX(sed, startAt, endAt, buf, isUnicodeAtStart));
79
        _sections.add(new SEPX(sed, startAt, endAt, tpt, buf, isUnicodeAtStart));
80
      }
80
      }
81
    }
81
    }
82
    
82
    
(-)src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java (-2 / +2 lines)
Lines 31-39 Link Here
31
31
32
  SectionDescriptor _sed;
32
  SectionDescriptor _sed;
33
33
34
  public SEPX(SectionDescriptor sed, int start, int end, byte[] grpprl, boolean isUnicode)
34
  public SEPX(SectionDescriptor sed, int start, int end, CharIndexTranslator translator, byte[] grpprl, boolean isUnicode)
35
  {
35
  {
36
    super(start, end, SectionSprmUncompressor.uncompressSEP(grpprl, 0), isUnicode);
36
    super(start, end, translator, SectionSprmUncompressor.uncompressSEP(grpprl, 0), isUnicode);
37
    _sed = sed;
37
    _sed = sed;
38
  }
38
  }
39
39
(-)src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java (-1 / +29 lines)
Lines 38-44 Link Here
38
 *  convertion.
38
 *  convertion.
39
 * @author Ryan Ackley
39
 * @author Ryan Ackley
40
 */
40
 */
41
public class TextPieceTable
41
public class TextPieceTable implements CharIndexTranslator 
42
{
42
{
43
  protected ArrayList _textPieces = new ArrayList();
43
  protected ArrayList _textPieces = new ArrayList();
44
  //int _multiple;
44
  //int _multiple;
Lines 269-272 Link Here
269
    }
269
    }
270
    return false;
270
    return false;
271
  }
271
  }
272
  	/* (non-Javadoc)
273
	 * @see org.apache.poi.hwpf.model.CharIndexTranslator#getLengthInChars(int)
274
	 */
275
	public int getCharIndex(int bytePos) {
276
		int charCount = 0;
277
		int curByte = 0;
278
279
		Iterator it = _textPieces.iterator();
280
		while (it.hasNext() && curByte < bytePos) {
281
			TextPiece tp = (TextPiece) it.next();
282
283
			int bytesLength = tp.bytesLength();
284
			int nextByte = curByte + bytesLength;
285
286
			int toAdd = bytePos > nextByte ? bytesLength : bytesLength
287
					- (nextByte - bytePos);
288
289
			if (tp.isUnicode()) {
290
				charCount += toAdd / 2;
291
			} else {
292
				charCount += toAdd;
293
			}
294
295
			curByte = nextByte;
296
		}
297
298
		return charCount;
299
	}
272
}
300
}

Return to bug 46610