You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2009/01/17 15:57:13 UTC

DO NOT REPLY [Bug 46553] New: Fix for applyFont() method of HSSFRichTextString

https://issues.apache.org/bugzilla/show_bug.cgi?id=46553

           Summary: Fix for applyFont() method of HSSFRichTextString
           Product: POI
           Version: 3.5-dev
          Platform: PC
        OS/Version: Windows Vista
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: davidcw@mit.edu
                CC: davidcw@mit.edu


Created an attachment (id=23137)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=23137)
Code that demonstrates the problem

I believe I found a bug in the applyFont() method of class HSSFRichTextString.
I am also posting the corresponding fix. I am also including posting think demo
code is necessary for this because 



Incidently, in searching for a related bug to which I could apply this fix, I
found a similar bug: Bug 40520, "HSSFFont.applyFont() formats wrong parts of
HSSFRichTextString". 

It looks like this bug has already been resolved in release 3.5-beta4. (I
didn't test if it was resolved in 3.2 FINAL). I'm not fully familiar with the
posting rules, so I didn't mark it as such.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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


DO NOT REPLY [Bug 46553] Fix for applyFont() method of HSSFRichTextString

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=46553





--- Comment #1 from David Wang <da...@mit.edu>  2009-01-17 07:11:28 PST ---
Apologies, I accidently submitted this bug by clicking the Commit button
prematurely. Here is the completed report...

I believe I found a bug in the applyFont() method of class HSSFRichTextString.
The fix for the applyFont() method is included in plain-text, below. The fix is
simple: In the applyFont() method, in the section of code that "reapplies" the
current font, it samples the font at the "startIndex". However, it would seem
to make more sense if it samples the font at the "endIndex", and reapplies that
instead.

I have also attached the code that demonstrates this bug, this time with the
associated excel file.

This 'bug' exists in both release 3.2 FINAL and 3.5-beta4.

PROPOSED FIX:
============================
    public void applyFont(int startIndex, int endIndex, short fontIndex)
    {
        if (startIndex > endIndex)
            throw new IllegalArgumentException("Start index must be less than
end index.");
        if (startIndex < 0 || endIndex > length())
            throw new IllegalArgumentException("Start and end index not in
range.");
        if (startIndex == endIndex)
            return;

        //Need to check what the font is currently, so we can reapply it after
        //the range is completed
        short currentFont = NO_FONT;
        if (endIndex != length()) {
          // FIX: USES "endIndex" instead of the original "startIndex".
          currentFont = this.getFontAtIndex(endIndex); 
        }

        //Need to clear the current formatting between the startIndex and
endIndex
        string = cloneStringIfRequired();
        Iterator formatting = string.formatIterator();
        if (formatting != null) {
          while (formatting.hasNext()) {
            UnicodeString.FormatRun r =
(UnicodeString.FormatRun)formatting.next();
            if ((r.getCharacterPos() >= startIndex) && (r.getCharacterPos() <
endIndex))
              formatting.remove();
          }
        }


        string.addFormatRun(new UnicodeString.FormatRun((short)startIndex,
fontIndex));
        if (endIndex != length())
          string.addFormatRun(new UnicodeString.FormatRun((short)endIndex,
currentFont));

        addToSSTIfRequired();
    }


============================

Incidently, in searching for a related bug to which I could apply this fix, I
found a similar bug: Bug 40520, "HSSFFont.applyFont() formats wrong parts of
HSSFRichTextString". 

It looks like this bug has already been resolved in release 3.5-beta4. (I
didn't test if it was resolved in 3.2 FINAL). I'm not fully familiar with the
posting rules, so I didn't mark it as such. 


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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


DO NOT REPLY [Bug 46553] Fix for applyFont() method of HSSFRichTextString

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=46553


Yegor Kozlov <ye...@dinom.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #3 from Yegor Kozlov <ye...@dinom.ru>  2009-01-29 08:06:16 PST ---
the fix applied in r738908 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=738908 )

Thanks,
Yegor


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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


DO NOT REPLY [Bug 46553] Fix for applyFont() method of HSSFRichTextString

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=46553


David Wang <da...@mit.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #23137|0                           |1
        is obsolete|                            |




--- Comment #2 from David Wang <da...@mit.edu>  2009-01-17 07:12:57 PST ---
Created an attachment (id=23138)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=23138)
Example problem code with the excel document it acts on.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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