From: Nick Burch Date: Fri, 28 May 2010 13:44:45 +0000 (+0000) Subject: Fix bug #48718 - Make the creation of multiple, un-modified fonts in a row in XSSF... X-Git-Tag: REL_3_7_BETA1~42 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8bb16bee4bd474af96970a5f07c469ef50ab8c2e;p=poi.git Fix bug #48718 - Make the creation of multiple, un-modified fonts in a row in XSSF match the old HSSF behaviour git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@949177 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 93047f340e..1cf13a4b36 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 48718 - Make the creation of multiple, un-modified fonts in a row in XSSF match the old HSSF behaviour 44916 - Allow access to the HSSFPatriarch from HSSFSheet once created 48779 - Allow you to get straight from a CellStyle to a Color, irrespective of if the Color is indexed or inline-defined 48924 - Allow access of the HWPF DateAndTime underlying date values 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 c0ad5f1bd1..6120e5b48b 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java @@ -176,14 +176,29 @@ public class StylesTable extends POIXMLDocumentPart { return fonts.get(idx); } - public int putFont(XSSFFont font) { - int idx = fonts.indexOf(font); + /** + * Records the given font in the font table. + * Will re-use an existing font index if this + * font matches another, EXCEPT if forced + * registration is requested. + * This allows people to create several fonts + * then customise them later. + */ + public int putFont(XSSFFont font, boolean forceRegistration) { + int idx = -1; + if(!forceRegistration) { + idx = fonts.indexOf(font); + } + if (idx != -1) { return idx; } fonts.add(font); return fonts.size() - 1; } + public int putFont(XSSFFont font) { + return putFont(font, false); + } public XSSFCellStyle getStyleAt(int idx) { int styleXfId = 0; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java index 3b92c6fd35..1578f6af55 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java @@ -85,7 +85,7 @@ public class XSSFFont implements Font { setFontName(DEFAULT_FONT_NAME); setFontHeight((double)DEFAULT_FONT_SIZE); } - + /** * get the underlying CTFont font */ @@ -516,10 +516,11 @@ public class XSSFFont implements Font { /** - * Register ourselfs in the style table + * Perform a registration of ourselves + * to the style table */ - public long putFont(StylesTable styles) { - short idx = (short)styles.putFont(this); + public long registerTo(StylesTable styles) { + short idx = (short)styles.putFont(this, true); this._index = idx; return idx; } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 2fef9ad5f4..4c73e3496a 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -453,7 +453,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable