]> source.dussan.org Git - poi.git/commitdiff
fixed bugs 40520 and 46553: HSSFFont.applyFont() formats wrong parts of HSSFRichTextS...
authorYegor Kozlov <yegor@apache.org>
Thu, 29 Jan 2009 16:03:52 +0000 (16:03 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 29 Jan 2009 16:03:52 +0000 (16:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@738908 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java

index 8167226ca4cac6cb3f33e58aa29166fe69cdcefb..0e2a141d688deb0dcca2d5019501963766b8d73d 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions</action>
            <action dev="POI-DEVELOPERS" type="fix">46545 - Fixed ObjRecord to ignore excessive padding written by previous POI versions</action>
            <action dev="POI-DEVELOPERS" type="fix">46613 - Fixed evaluator to perform case insensitive string comparisons</action>
            <action dev="POI-DEVELOPERS" type="add">46544 - command line interface for hssf ExcelExtractor</action>
index 131c087137d926898a8c940f0eb032fc5c831579..4bd2067fac2838d7affb41a7788c00fad7a125b5 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions</action>
            <action dev="POI-DEVELOPERS" type="fix">46545 - Fixed ObjRecord to ignore excessive padding written by previous POI versions</action>
            <action dev="POI-DEVELOPERS" type="fix">46613 - Fixed evaluator to perform case insensitive string comparisons</action>
            <action dev="POI-DEVELOPERS" type="add">46544 - command line interface for hssf ExcelExtractor</action>
index 35f91eaef5d61f04cf3ecc4b788ba0cb0599949d..d22030ac77989a593b71e3d0e7e00b12e24cff79 100644 (file)
@@ -109,7 +109,7 @@ public class HSSFRichTextString
         //the range is completed
         short currentFont = NO_FONT;
         if (endIndex != length()) {
-          currentFont = this.getFontAtIndex(startIndex);
+          currentFont = this.getFontAtIndex(endIndex);
         }
 
         //Need to clear the current formatting between the startIndex and endIndex
index 016128a20013c3ed549bd57c00304e7b693ede9e..a14c2510b51a3a37e5767b40e7a0645025a27414 100644 (file)
@@ -74,4 +74,59 @@ public class TestHSSFRichTextString extends TestCase
       r.clearFormatting();
       assertEquals(0, r.numFormattingRuns());
     }
+
+
+    /**
+     * Test case proposed in Bug 40520:  formated twice => will format whole String
+     */
+    public void test40520_1(){
+
+        short font = 3;
+
+        HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890");
+
+        r.applyFont(0,7,font);
+        r.applyFont(5,9,font);
+
+        for(int i=0; i < 7; i++) assertEquals(font, r.getFontAtIndex(i));
+        for(int i=5; i < 9; i++) assertEquals(font, r.getFontAtIndex(i));
+        for(int i=9; i < r.length(); i++) assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(i));
+    }
+
+    /**
+     * Test case proposed in Bug 40520:  overlapped range => will format whole String
+     */
+    public void test40520_2(){
+
+        short font = 3;
+        HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890");
+
+        r.applyFont(0,2,font);
+        for(int i=0; i < 2; i++) assertEquals(font, r.getFontAtIndex(i));
+        for(int i=2; i < r.length(); i++) assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(i));
+
+        r.applyFont(0,2,font);
+        for(int i=0; i < 2; i++) assertEquals(font, r.getFontAtIndex(i));
+        for(int i=2; i < r.length(); i++) assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(i));
+    }
+
+    /**
+     * Test case proposed in Bug 40520:  formated twice => will format whole String
+     */
+    public void test40520_3(){
+
+        short font = 3;
+        HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890");
+
+        // wrong order => will format 0-6
+        r.applyFont(0,2,font);
+        r.applyFont(5,7,font);
+        r.applyFont(0,2,font);
+
+        r.applyFont(0,2,font);
+        for(int i=0; i < 2; i++) assertEquals(font, r.getFontAtIndex(i));
+        for(int i=2; i < 5; i++) assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(i));
+        for(int i=5; i < 7; i++) assertEquals(font, r.getFontAtIndex(i));
+        for(int i=7; i < r.length(); i++) assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(i));
+    }
 }