DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27901>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=27901

TextCharIterator.remove() does not work properly

           Summary: TextCharIterator.remove() does not work properly
           Product: Fop
           Version: 1.0dev
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: page-master/layout
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


The method remove() of the TextCharIterator class, defined private in the file 
fo/FOText.java, should remove the current character, pointed to by curIndex, 
but its effect is to remove the one pointed to by the start index.

The fo file I am going to attach can be used to see the problem; there are two 
block with the same text, but in the second one there are some extra spaces 
that should be removed as white-space-collapse default value is true; instead 
of the extra spaces, the first character are removed.

Now, the code is:

  public void remove() {
      if (start < ca.length) {
          start++;
      }
  }

A simple solution could be shifting the whole array of character every time 
remove is called, but that would not be very efficient, especially with big 
arrays:

  public void remove() {
      if (start < ca.length) {
          for (int i = curIndex - 1;
               i > start;
               ca[i] = ca[--i]) {
              // nothing
          }
          start++;
      }
  }

Maybe a better idea would be to store the indexes of the character to remove 
(a kind of "black list"), and to actually remove them when creating the 
TextLayouyManager.
Instead of calling a single System.arraycopy, the TextLayoutManager 
constructor should call a method of the FOText class, which would copy sub-
array of consecutive "good" indexes between  two indexes in the black list (or 
between the array start and the first black index, or between the last black 
index and the array end).

Reply via email to