<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>
public void setTheme(ThemesTable theme) {
this.theme = theme;
+ for(XSSFFont font : fonts) {
+ font.setThemesTable(theme);
+ }
}
/**
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++;
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;
*/
public static final short DEFAULT_FONT_COLOR = IndexedColors.BLACK.getIndex();
+ private ThemesTable _themes;
private CTFont _ctFont;
private short _index;
*/
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;
+ }
}
* 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.
* @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;
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;
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;
}
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();
}
}
return st;
}
+
+ private ThemesTable getThemesTable() {
+ if(styles == null) return null;
+ return styles.getTheme();
+ }
}
* 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);
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
}
}
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;
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