From: Yegor Kozlov Date: Thu, 29 Jan 2009 16:03:52 +0000 (+0000) Subject: fixed bugs 40520 and 46553: HSSFFont.applyFont() formats wrong parts of HSSFRichTextS... X-Git-Tag: REL_3_5_BETA5~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d01cd80981cc07a6b7e13430a49faac3bd76be54;p=poi.git fixed bugs 40520 and 46553: HSSFFont.applyFont() formats wrong parts of HSSFRichTextString git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@738908 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 8167226ca4..0e2a141d68 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions 46545 - Fixed ObjRecord to ignore excessive padding written by previous POI versions 46613 - Fixed evaluator to perform case insensitive string comparisons 46544 - command line interface for hssf ExcelExtractor diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 131c087137..4bd2067fac 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions 46545 - Fixed ObjRecord to ignore excessive padding written by previous POI versions 46613 - Fixed evaluator to perform case insensitive string comparisons 46544 - command line interface for hssf ExcelExtractor diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java index 35f91eaef5..d22030ac77 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java @@ -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 diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java index 016128a200..a14c2510b5 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java @@ -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)); + } }