git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1077986 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_8_BETA2
@@ -34,6 +34,7 @@ | |||
<changes> | |||
<release version="3.8-beta2" date="2011-??-??"> | |||
<action dev="poi-developers" type="fix">50784 - XSSFColors return by XSSFFont now have theme information applied to them</action> | |||
<action dev="poi-developers" type="fix">50846 - Improve how XSSFColor inherits from Themes</action> | |||
<action dev="poi-developers" type="fix">50847 - XSSFFont now accepts the full range of Charsets from FontChartset</action> | |||
<action dev="poi-developers" type="fix">50786 - Speed up calls to HSSFColor.getIndexHash() by returning a cached, unmodifiable Map. HSSFColor.getModifiableIndexHash() provides access to the old (slow but modifiable) functionality</action> |
@@ -98,6 +98,9 @@ public class StylesTable extends POIXMLDocumentPart { | |||
public void setTheme(ThemesTable theme) { | |||
this.theme = theme; | |||
for(XSSFFont font : fonts) { | |||
font.setThemesTable(theme); | |||
} | |||
} | |||
/** | |||
@@ -125,6 +128,7 @@ public class StylesTable extends POIXMLDocumentPart { | |||
if(ctfonts != null){ | |||
int idx = 0; | |||
for (CTFont font : ctfonts.getFontArray()) { | |||
// Create the font and save it. Themes Table supplied later | |||
XSSFFont f = new XSSFFont(font, idx); | |||
fonts.add(f); | |||
idx++; |
@@ -25,6 +25,7 @@ import org.apache.poi.ss.usermodel.FontScheme; | |||
import org.apache.poi.ss.usermodel.FontUnderline; | |||
import org.apache.poi.ss.usermodel.IndexedColors; | |||
import org.apache.poi.xssf.model.StylesTable; | |||
import org.apache.poi.xssf.model.ThemesTable; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont; | |||
@@ -59,6 +60,7 @@ public class XSSFFont implements Font { | |||
*/ | |||
public static final short DEFAULT_FONT_COLOR = IndexedColors.BLACK.getIndex(); | |||
private ThemesTable _themes; | |||
private CTFont _ctFont; | |||
private short _index; | |||
@@ -147,7 +149,15 @@ public class XSSFFont implements Font { | |||
*/ | |||
public XSSFColor getXSSFColor() { | |||
CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.getColorArray(0); | |||
return ctColor == null ? null : new XSSFColor(ctColor); | |||
if(ctColor != null) { | |||
XSSFColor color = new XSSFColor(ctColor); | |||
if(_themes != null) { | |||
_themes.inheritFromThemeAsRequired(color); | |||
} | |||
return color; | |||
} else { | |||
return null; | |||
} | |||
} | |||
@@ -520,10 +530,19 @@ public class XSSFFont implements Font { | |||
* to the style table | |||
*/ | |||
public long registerTo(StylesTable styles) { | |||
this._themes = styles.getTheme(); | |||
short idx = (short)styles.putFont(this, true); | |||
this._index = idx; | |||
return idx; | |||
} | |||
/** | |||
* Records the Themes Table that is associated with | |||
* the current font, used when looking up theme | |||
* based colours and properties. | |||
*/ | |||
public void setThemesTable(ThemesTable themes) { | |||
this._themes = themes; | |||
} | |||
/** | |||
* get the font scheme property. | |||
@@ -589,7 +608,6 @@ public class XSSFFont implements Font { | |||
* @return unique index number of the underlying record this Font represents (probably you don't care | |||
* unless you're comparing which one is which) | |||
*/ | |||
public short getIndex() | |||
{ | |||
return _index; |
@@ -26,6 +26,7 @@ import javax.xml.namespace.QName; | |||
import org.apache.poi.ss.usermodel.Font; | |||
import org.apache.poi.ss.usermodel.RichTextString; | |||
import org.apache.poi.xssf.model.StylesTable; | |||
import org.apache.poi.xssf.model.ThemesTable; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.xmlbeans.XmlCursor; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; | |||
@@ -342,7 +343,11 @@ public class XSSFRichTextString implements RichTextString { | |||
for(int i = 0; i < st.sizeOfRArray(); i++){ | |||
CTRElt r = st.getRArray(i); | |||
if(i == index) return new XSSFFont(toCTFont(r.getRPr())); | |||
if(i == index) { | |||
XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr())); | |||
fnt.setThemesTable(getThemesTable()); | |||
return fnt; | |||
} | |||
} | |||
return null; | |||
} | |||
@@ -361,7 +366,11 @@ public class XSSFRichTextString implements RichTextString { | |||
int pos = 0; | |||
for(int i = 0; i < st.sizeOfRArray(); i++){ | |||
CTRElt r = st.getRArray(i); | |||
if(index >= pos && index < pos + r.getT().length()) return new XSSFFont(toCTFont(r.getRPr())); | |||
if(index >= pos && index < pos + r.getT().length()) { | |||
XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr())); | |||
fnt.setThemesTable(getThemesTable()); | |||
return fnt; | |||
} | |||
pos += r.getT().length(); | |||
} | |||
@@ -543,4 +552,9 @@ public class XSSFRichTextString implements RichTextString { | |||
} | |||
return st; | |||
} | |||
private ThemesTable getThemesTable() { | |||
if(styles == null) return null; | |||
return styles.getTheme(); | |||
} | |||
} |
@@ -742,10 +742,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { | |||
* Fonts where their colours come from the theme rather | |||
* then being set explicitly still should allow the | |||
* fetching of the RGB. | |||
* TODO Allow XSSFFont to get at the themes table, so it can do | |||
* the same trick that XSSFCellStyle does with theme colours | |||
*/ | |||
public void DISABLEDtest50784() throws Exception { | |||
public void test50784() throws Exception { | |||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50784-font_theme_colours.xlsx"); | |||
XSSFSheet s = wb.getSheetAt(0); | |||
XSSFRow r = s.getRow(0); | |||
@@ -766,8 +764,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { | |||
assertEquals(9, colt.getTheme()); | |||
XSSFColor themeC = wb.getTheme().getThemeColor(colt.getTheme()); | |||
assertNotNull( themeC.getRgb() ); | |||
// TODO Fix it so this works | |||
assertNotNull( colt.getRgb() ); | |||
assertEquals( themeC.getRgb(), colt.getRgb() ); // The same colour | |||
assertEquals( themeC.getARGBHex(), colt.getARGBHex() ); // The same colour | |||
} | |||
} |
@@ -18,7 +18,13 @@ | |||
package org.apache.poi.xssf.usermodel; | |||
import org.apache.poi.POIXMLException; | |||
import org.apache.poi.ss.usermodel.*; | |||
import org.apache.poi.ss.usermodel.BaseTestFont; | |||
import org.apache.poi.ss.usermodel.Font; | |||
import org.apache.poi.ss.usermodel.FontCharset; | |||
import org.apache.poi.ss.usermodel.FontFamily; | |||
import org.apache.poi.ss.usermodel.FontScheme; | |||
import org.apache.poi.ss.usermodel.FontUnderline; | |||
import org.apache.poi.ss.usermodel.IndexedColors; | |||
import org.apache.poi.xssf.XSSFITestDataProvider; | |||
import org.apache.poi.xssf.XSSFTestDataSamples; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty; |
@@ -17,13 +17,13 @@ | |||
package org.apache.poi.xssf.usermodel; | |||
import java.util.TreeMap; | |||
import junit.framework.TestCase; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring; | |||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; | |||
import java.util.TreeMap; | |||
/** | |||
* Tests functionality of the XSSFRichTextRun object |