You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/05/20 18:57:21 UTC

svn commit: r658349 - in /poi/trunk/src: documentation/content/xdocs/ scratchpad/src/org/apache/poi/hwpf/model/ scratchpad/src/org/apache/poi/hwpf/usermodel/

Author: nick
Date: Tue May 20 09:57:20 2008
New Revision: 658349

URL: http://svn.apache.org/viewvc?rev=658349&view=rev
Log:
Patch from bug #45001 - Partial fix for HWPF Range.insertBefore() and Range.delete() with unicode characters

Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=658349&r1=658348&r2=658349&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Tue May 20 09:57:20 2008
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1-final" date="2008-06-??">
+           <action dev="POI-DEVELOPERS" type="fix">45001 - Partial fix for HWPF Range.insertBefore() and Range.delete() with unicode characters</action>
            <action dev="POI-DEVELOPERS" type="fix">44977 - Support for AM/PM in excel date formats</action>
            <action dev="POI-DEVELOPERS" type="add">Support for specifying a policy to HSSF on missing / blank cells when fetching</action>
            <action dev="POI-DEVELOPERS" type="add">44937 - Partial support for extracting Escher images from HWPF files</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=658349&r1=658348&r2=658349&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue May 20 09:57:20 2008
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-final" date="2008-06-??">
+           <action dev="POI-DEVELOPERS" type="fix">45001 - Partial fix for HWPF Range.insertBefore() and Range.delete() with unicode characters</action>
            <action dev="POI-DEVELOPERS" type="fix">44977 - Support for AM/PM in excel date formats</action>
            <action dev="POI-DEVELOPERS" type="add">Support for specifying a policy to HSSF on missing / blank cells when fetching</action>
            <action dev="POI-DEVELOPERS" type="add">44937 - Partial support for extracting Escher images from HWPF files</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java?rev=658349&r1=658348&r2=658349&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java Tue May 20 09:57:20 2008
@@ -294,6 +294,16 @@
       _longHandler.setLong(FIBLongHandler.CBMAC, cbMac);
     }
 
+	public int getCcpText()
+	{
+	  return _longHandler.getLong(FIBLongHandler.CCPTEXT);
+	}
+
+	public void setCcpText(int ccpText)
+	{
+	  _longHandler.setLong(FIBLongHandler.CCPTEXT, ccpText);
+	}
+
     public void clearOffsetsSizes()
     {
       _fieldHandler.clearFields();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java?rev=658349&r1=658348&r2=658349&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java Tue May 20 09:57:20 2008
@@ -90,12 +90,20 @@
 
    public void adjustForDelete(int start, int length)
    {
+
+	   if (usesUnicode()) {
+
+		   start /= 2;
+		   length /= 2;
+	   }
+
 	   int myStart = getStart();
 	   int myEnd = getEnd();
 	   int end = start + length;
 
 	   /* do we have to delete from this text piece? */
 	   if (start <= myEnd && end >= myStart) {
+
 		   /* find where the deleted area overlaps with this text piece */
 		   int overlapStart = Math.max(myStart, start);
 		   int overlapEnd = Math.min(myEnd, end);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java?rev=658349&r1=658348&r2=658349&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java Tue May 20 09:57:20 2008
@@ -227,6 +227,25 @@
   }
 
   /**
+   * Does any <code>TextPiece</code> in this Range use unicode?
+   *
+   *	@return	true if it does and false if it doesn't
+   */
+  public boolean usesUnicode() {
+
+	initText();
+
+	for (int i = _textStart; i < _textEnd; i++)
+	{
+	  TextPiece piece = (TextPiece)_text.get(i);
+	  if (piece.usesUnicode())
+		  return true;
+	}
+
+	return false;
+  }
+
+  /**
    * Gets the text that this Range contains.
    *
    * @return The text for this range.
@@ -306,13 +325,19 @@
     // Since this is the first item in our list, it is safe to assume that
     // _start >= tp.getStart()
     int insertIndex = _start - tp.getStart();
+	if (tp.usesUnicode())
+		insertIndex /= 2;
     sb.insert(insertIndex, text);
+
     int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length());
     _doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength);
     _doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength);
     _doc.getSectionTable().adjustForInsert(_sectionStart, adjustedLength);
     adjustForInsert(text.length());
 
+	// update the FIB.CCPText field
+	adjustFIB(text.length());
+
     return getCharacterRun(0);
   }
 
@@ -489,6 +514,7 @@
 
   public void delete()
   {
+
     initAll();
 
     int numSections = _sections.size();
@@ -519,6 +545,12 @@
     	TextPiece piece = (TextPiece)_text.get(x);
     	piece.adjustForDelete(_start, _end - _start);
     }
+
+	// update the FIB.CCPText field
+	if (usesUnicode())
+		adjustFIB(-((_end - _start) / 2));
+	else
+		adjustFIB(-(_end - _start));
   }
 
   /**
@@ -828,12 +860,26 @@
   }
 
   /**
+   *	Adjust the value of <code>FIB.CCPText</code> after an insert or a delete...
+   *
+   *	@param	adjustment	The (signed) value that should be added to <code>FIB.CCPText</code>
+   */
+  protected void adjustFIB(int adjustment) {
+
+	// update the FIB.CCPText field (this should happen once per adjustment, so we don't want it in
+	// adjustForInsert() or it would get updated multiple times if the range has a parent)
+	// without this, OpenOffice.org (v. 2.2.x) does not see all the text in the document
+	_doc.getFileInformationBlock().setCcpText(_doc.getFileInformationBlock().getCcpText() + adjustment);
+  }
+
+  /**
    * adjust this range after an insert happens.
    * @param length the length to adjust for
    */
   private void adjustForInsert(int length)
   {
     _end += length;
+
     reset();
     Range parent = (Range)_parent.get();
     if (parent != null)
@@ -842,4 +888,14 @@
     }
   }
 
+
+	public int getStartOffset() {
+
+		return _start;
+	}
+
+	public int getEndOffset() {
+
+		return _end;
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org