From 4bdf3c6de2563256b6ba072eb5ba71310d269b5f Mon Sep 17 00:00:00 2001 From: Paolo Mottadelli Date: Tue, 25 Mar 2008 18:35:00 +0000 Subject: [PATCH] XSSFCellStyle getFont method; XSSFFont class added all methods to be implemented; tests git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@640934 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/model/StylesTable.java | 14 +- .../poi/xssf/usermodel/XSSFCellStyle.java | 15 ++ .../apache/poi/xssf/usermodel/XSSFFont.java | 150 ++++++++++++++++++ .../poi/xssf/usermodel/TestXSSFCellStyle.java | 11 ++ 4 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java index 81af8d8a9e..c26f2af3fe 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java @@ -29,6 +29,7 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.StylesSource; import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder; import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; import org.apache.xmlbeans.XmlException; @@ -164,15 +165,13 @@ public class StylesTable implements StylesSource, XSSFModel { } public Font getFontAt(long idx) { - // TODO - return null; + return new XSSFFont(fonts.get((int) idx)); } public synchronized long putFont(Font font) { - // TODO - return -1; + return putFont((XSSFFont)font, fonts); } - public CellStyle getStyleAt(long idx) { + public CellStyle getStyleAt(long idx) { CTXf mainXf = xfs.get((int)idx); CTXf styleXf = null; @@ -320,7 +319,12 @@ public class StylesTable implements StylesSource, XSSFModel { private long putBorder(XSSFCellBorder border, LinkedList borders) { return border.putBorder(borders); } + private long putFill(XSSFCellFill fill, LinkedList fills) { return fill.putFill(fills); } + + private long putFont(XSSFFont font, LinkedList fonts) { + return font.putFont(fonts); + } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java index 083dd3b3a5..84d9ed96c7 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java @@ -35,6 +35,7 @@ public class XSSFCellStyle implements CellStyle { private CTXf cellStyleXf; private XSSFCellBorder cellBorder; private XSSFCellFill cellFill; + private XSSFFont font; /** * Creates a Cell Style from the supplied parts @@ -137,6 +138,13 @@ public class XSSFCellStyle implements CellStyle { // TODO Auto-generated method stub return null; } + + public Font getFont() { + if (font == null) { + font = (XSSFFont) ((StylesTable)stylesSource).getFontAt(getFontId()); + } + return font; + } public short getFontIndex() { // TODO Auto-generated method stub @@ -326,4 +334,11 @@ public class XSSFCellStyle implements CellStyle { return (short) getCellBorder().getBorderColor(side).getIndexed(); } + private int getFontId() { + if (cellXf.isSetFontId()) { + return (int) cellXf.getFontId(); + } + return (int) cellStyleXf.getFontId(); + } + } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java new file mode 100644 index 0000000000..cc250e85c2 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java @@ -0,0 +1,150 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xssf.usermodel; + +import java.util.LinkedList; + +import org.apache.poi.ss.usermodel.Font; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont; + +public class XSSFFont implements Font { + + private CTFont font; + + public XSSFFont(CTFont font) { + this.font = font; + } + + public XSSFFont() { + this.font = CTFont.Factory.newInstance(); + } + + public short getBoldweight() { + // TODO Auto-generated method stub + return 0; + } + + public byte getCharSet() { + // TODO Auto-generated method stub + return 0; + } + + public short getColor() { + // TODO Auto-generated method stub + return 0; + } + + public short getFontHeight() { + // TODO Auto-generated method stub + return 0; + } + + public short getFontHeightInPoints() { + // TODO Auto-generated method stub + return 0; + } + + public String getFontName() { + // TODO Auto-generated method stub + return null; + } + + public short getIndex() { + // TODO Auto-generated method stub + return 0; + } + + public boolean getItalic() { + // TODO Auto-generated method stub + return false; + } + + public boolean getStrikeout() { + // TODO Auto-generated method stub + return false; + } + + public short getTypeOffset() { + // TODO Auto-generated method stub + return 0; + } + + public byte getUnderline() { + // TODO Auto-generated method stub + return 0; + } + + public void setBoldweight(short boldweight) { + // TODO Auto-generated method stub + + } + + public void setCharSet(byte charset) { + // TODO Auto-generated method stub + + } + + public void setColor(short color) { + // TODO Auto-generated method stub + + } + + public void setFontHeight(short height) { + // TODO Auto-generated method stub + + } + + public void setFontHeightInPoints(short height) { + // TODO Auto-generated method stub + + } + + public void setFontName(String name) { + // TODO Auto-generated method stub + + } + + public void setItalic(boolean italic) { + // TODO Auto-generated method stub + + } + + public void setStrikeout(boolean strikeout) { + // TODO Auto-generated method stub + + } + + public void setTypeOffset(short offset) { + // TODO Auto-generated method stub + + } + + public void setUnderline(byte underline) { + // TODO Auto-generated method stub + + } + + public long putFont(LinkedList fonts) { + if(fonts.contains(font)) { + return fonts.indexOf(font); + } + fonts.add(font); + return fonts.size() - 1; + } + +} diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java index 1cd6f063d2..542e7a4bbd 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java @@ -25,6 +25,7 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf; @@ -37,6 +38,7 @@ public class TestXSSFCellStyle extends TestCase { private StylesTable stylesTable; private CTBorder ctBorderA; private CTFill ctFill; + private CTFont ctFont; private CTXf cellStyleXf; private CTXf cellXf; private XSSFCellStyle cellStyle; @@ -60,6 +62,11 @@ public class TestXSSFCellStyle extends TestCase { long fillId = stylesTable.putFill(fill); assertEquals(0, fillId); + ctFont = CTFont.Factory.newInstance(); + XSSFFont font = new XSSFFont(ctFont); + long fontId = stylesTable.putFont(font); + assertEquals(0, fontId); + cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf(); cellStyleXf.setBorderId(0); cellXf = ctStylesheet.addNewCellXfs().addNewXf(); @@ -126,4 +133,8 @@ public class TestXSSFCellStyle extends TestCase { ctPatternFill.setPatternType(STPatternType.DARK_DOWN); assertEquals(8, cellStyle.getFillPattern()); } + + public void testGetFont() { + assertNotNull(cellStyle.getFont()); + } } -- 2.39.5