ASF Bugzilla – Attachment 11154 Details for
Bug 28232
[PATCH] Fix for Section ranges
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
HWPFDocument.java, SectionTable.java, TextPiece.java, TextPieceTable.java
patchfile.SectionFixes.txt (text/plain), 5.81 KB, created by
Piers
on 2004-04-06 15:23:48 UTC
(
hide
)
Description:
HWPFDocument.java, SectionTable.java, TextPiece.java, TextPieceTable.java
Filename:
MIME Type:
Creator:
Piers
Created:
2004-04-06 15:23:48 UTC
Size:
5.81 KB
patch
obsolete
>Index: hwpf/HWPFDocument.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java,v >retrieving revision 1.11 >diff -u -r1.11 HWPFDocument.java >--- hwpf/HWPFDocument.java 6 Apr 2004 04:43:59 -0000 1.11 >+++ hwpf/HWPFDocument.java 6 Apr 2004 14:49:07 -0000 >@@ -156,7 +156,7 @@ > _pbt.adjustForDelete(0, 0, cpMin); > } > >- _st = new SectionTable(_mainStream, _tableStream, _fib.getFcPlcfsed(), _fib.getLcbPlcfsed(), fcMin); >+ _st = new SectionTable(_mainStream, _tableStream, _fib.getFcPlcfsed(), _fib.getLcbPlcfsed(), fcMin, getTextTable().getTextPieces()); > _ss = new StyleSheet(_tableStream, _fib.getFcStshf()); > _ft = new FontTable(_tableStream, _fib.getFcSttbfffn(), _fib.getLcbSttbfffn()); > >Index: hwpf/model/SectionTable.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java,v >retrieving revision 1.2 >diff -u -r1.2 SectionTable.java >--- hwpf/model/SectionTable.java 6 Apr 2004 04:44:01 -0000 1.2 >+++ hwpf/model/SectionTable.java 6 Apr 2004 14:49:07 -0000 >@@ -19,6 +19,7 @@ > import java.util.ArrayList; > import java.io.ByteArrayOutputStream; > import java.io.IOException; >+import java.util.List; > > import org.apache.poi.util.LittleEndian; > import org.apache.poi.hwpf.model.io.*; >@@ -36,8 +37,10 @@ > { > } > >+ > public SectionTable(byte[] documentStream, byte[] tableStream, int offset, >- int size, int fcMin) >+ int size, int fcMin, >+ List tpt) > { > PlexOfCps sedPlex = new PlexOfCps(tableStream, offset, size, SED_SIZE); > >@@ -53,7 +56,7 @@ > // check for the optimization > if (fileOffset == 0xffffffff) > { >- _sections.add(new SEPX(sed, node.getStart(), node.getEnd(), new byte[0])); >+ _sections.add(new SEPX(sed, CPtoFC(node.getStart(),tpt), CPtoFC(node.getEnd(),tpt), new byte[0])); > } > else > { >@@ -62,7 +65,7 @@ > byte[] buf = new byte[sepxSize]; > fileOffset += LittleEndian.SHORT_SIZE; > System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); >- _sections.add(new SEPX(sed, node.getStart(), node.getEnd(), buf)); >+ _sections.add(new SEPX(sed, CPtoFC(node.getStart(),tpt), CPtoFC(node.getEnd(),tpt), buf)); > } > } > } >@@ -123,4 +126,19 @@ > tableStream.write(plex.toByteArray()); > } > >+ private int CPtoFC(int CP, List tpt) >+ { >+ TextPiece TP = null; >+ >+ for(int i=tpt.size()-1; i>-1; i--) >+ { >+ TP = (TextPiece)tpt.get(i); >+ >+ if(CP >= TP.getCP()) break; >+ } >+ int FC = TP.getPieceDescriptor().getFilePosition(); >+ int offset = CP - TP.getCP(); >+ if(TP.usesUnicode()) offset*=2; >+ return FC+offset-((TextPiece)tpt.get(0)).getPieceDescriptor().getFilePosition(); >+ } > } >Index: hwpf/model/TextPiece.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java,v >retrieving revision 1.3 >diff -u -r1.3 TextPiece.java >--- hwpf/model/TextPiece.java 23 Mar 2004 05:51:52 -0000 1.3 >+++ hwpf/model/TextPiece.java 6 Apr 2004 14:49:07 -0000 >@@ -31,13 +31,15 @@ > > private PieceDescriptor _pd; > >+ private int _cpStart; >+ > /** > * @param start Offset in main document stream. > * @param length The total length of the text in bytes. Note: 1 character > * does not necessarily refer to 1 byte. > * @param unicode true if this text is unicode. > */ >- public TextPiece(int start, int end, byte[] text, PieceDescriptor pd) >+ public TextPiece(int start, int end, byte[] text, PieceDescriptor pd, int cpStart) > throws UnsupportedEncodingException > { > /** start - end is length on file. This is double the expected when its >@@ -45,6 +47,7 @@ > super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252"))); > _usesUnicode = pd.isUnicode(); > _pd = pd; >+ _cpStart = cpStart; > } > /** > * @return If this text piece uses unicode >@@ -106,6 +109,12 @@ > tp._usesUnicode == _usesUnicode && _pd.equals(tp._pd); > } > return false; >+ } >+ >+ >+ public int getCP() >+ { >+ return _cpStart; > } > > } >Index: hwpf/model/TextPieceTable.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java,v >retrieving revision 1.3 >diff -u -r1.3 TextPieceTable.java >--- hwpf/model/TextPieceTable.java 6 Apr 2004 04:44:01 -0000 1.3 >+++ hwpf/model/TextPieceTable.java 6 Apr 2004 14:49:07 -0000 >@@ -65,10 +65,8 @@ > // } > } > >- _cpMin = pieces[0].getFilePosition() - fcMin; >- // if a piece is unicode the actual offset may be bumped because of the >- // doubling of the needed size. >- int bump = 0; >+ int firstPieceFilePosition = pieces[0].getFilePosition(); >+ _cpMin = firstPieceFilePosition - fcMin; > > // using the PieceDescriptors, build our list of TextPieces. > for (int x = 0; x < pieces.length; x++) >@@ -92,12 +90,9 @@ > > byte[] buf = new byte[textSize]; > System.arraycopy(documentStream, start, buf, 0, textSize); >- _textPieces.add(new TextPiece(nodeStart + bump, nodeEnd + bump, buf, pieces[x])); > >- if (unicode) >- { >- bump += (node.getEnd() - nodeStart); >- } >+ int startFilePosition = start - firstPieceFilePosition; >+ _textPieces.add(new TextPiece(startFilePosition, startFilePosition+textSize, buf, pieces[x], node.getStart())); > } > } > >@@ -203,4 +198,5 @@ > } > return false; > } >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 28232
: 11154