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
This commit is contained in:
Yegor Kozlov 2009-01-29 16:03:52 +00:00
parent fce473fada
commit d01cd80981
4 changed files with 58 additions and 1 deletions

View 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>

View 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>

View 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

View 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));
}
}