You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2010/10/07 15:40:59 UTC
svn commit: r1005443 - in /poi/trunk: src/documentation/content/xdocs/
src/scratchpad/src/org/apache/poi/hwpf/usermodel/
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/ test-data/document/
Author: yegor
Date: Thu Oct 7 13:40:58 2010
New Revision: 1005443
URL: http://svn.apache.org/viewvc?rev=1005443&view=rev
Log:
support for processing of symbols in HWPF, see Bugzilla 49908
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeSymbols.java (with props)
poi/trunk/test-data/document/Bug49908.doc (with props)
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1005443&r1=1005442&r2=1005443&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Oct 7 13:40:58 2010
@@ -34,6 +34,7 @@
<changes>
<release version="3.7-beta4" date="2010-??-??">
+ <action dev="poi-developers" type="fix">49908 - support for processing of symbols in HWPF</action>
<action dev="poi-developers" type="fix">50022 - support for retrieving pictures from HSSF workbooks</action>
<action dev="poi-developers" type="fix">50020 - Avoid IllegalStateException when creating Data validation in sheet with macro</action>
<action dev="poi-developers" type="fix">50033 - Improved rounding in MOD</action>
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java?rev=1005443&r1=1005442&r2=1005443&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java Thu Oct 7 13:40:58 2010
@@ -18,6 +18,7 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.CHPX;
+import org.apache.poi.hwpf.model.Ffn;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.sprm.SprmBuffer;
@@ -557,5 +558,50 @@ public final class CharacterRun
return cp;
}
+
+ /**
+ * Returns true, if the CharacterRun is a special character run containing a symbol, otherwise false.
+ *
+ * <p>In case of a symbol, the {@link #text()} method always returns a single character 0x0028, but word actually stores
+ * the character in a different field. Use {@link #getSymbolCharacter()} to get that character and {@link #getSymbolFont()}
+ * to determine its font.
+ */
+ public boolean isSymbol()
+ {
+ return isSpecialCharacter() && text().equals("\u0028");
+ }
+
+ /**
+ * Returns the symbol character, if this is a symbol character run.
+ *
+ * @see #isSymbol()
+ * @throws IllegalStateException If this is not a symbol character run: call {@link #isSymbol()} first.
+ */
+ public char getSymbolCharacter()
+ {
+ if (isSymbol()) {
+ return (char)_props.getXchSym();
+ } else
+ throw new IllegalStateException("Not a symbol CharacterRun");
+ }
+
+ /**
+ * Returns the symbol font, if this is a symbol character run. Might return null, if the font index is not found in the font table.
+ *
+ * @see #isSymbol()
+ * @throws IllegalStateException If this is not a symbol character run: call {@link #isSymbol()} first.
+ */
+ public Ffn getSymbolFont()
+ {
+ if (isSymbol()) {
+ Ffn[] fontNames = _doc.getFontTable().getFontNames();
+
+ if (fontNames.length <= _props.getFtcSym())
+ return null;
+
+ return fontNames[_props.getFtcSym()];
+ } else
+ throw new IllegalStateException("Not a symbol CharacterRun");
+ }
}
Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeSymbols.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeSymbols.java?rev=1005443&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeSymbols.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeSymbols.java Thu Oct 7 13:40:58 2010
@@ -0,0 +1,48 @@
+/* ====================================================================
+ 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.hwpf.usermodel;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
+
+/**
+ * API for processing of symbols, see Bugzilla 49908
+ */
+public final class TestRangeSymbols extends TestCase {
+
+ public void test() throws IOException {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49908.doc");
+
+ Range range = doc.getRange();
+
+ assertTrue(range.numCharacterRuns() >= 2);
+ CharacterRun chr = range.getCharacterRun(0);
+ assertEquals(false, chr.isSymbol());
+
+ chr = range.getCharacterRun(1);
+ assertEquals(true, chr.isSymbol());
+ assertEquals("\u0028", chr.text());
+ assertEquals("Wingdings", chr.getSymbolFont().getMainFontName());
+ assertEquals(0xf028, chr.getSymbolCharacter());
+ }
+
+}
\ No newline at end of file
Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeSymbols.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/test-data/document/Bug49908.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/Bug49908.doc?rev=1005443&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/document/Bug49908.doc
------------------------------------------------------------------------------
svn:executable = *
Propchange: poi/trunk/test-data/document/Bug49908.doc
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org