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;
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");
+ }
}
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hwpf.usermodel;\r
+\r
+import java.io.IOException;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.hwpf.HWPFDocument;\r
+import org.apache.poi.hwpf.HWPFTestDataSamples;\r
+\r
+/**\r
+ * API for processing of symbols, see Bugzilla 49908\r
+ */\r
+public final class TestRangeSymbols extends TestCase {\r
+\r
+ public void test() throws IOException {\r
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49908.doc");\r
+\r
+ Range range = doc.getRange();\r
+\r
+ assertTrue(range.numCharacterRuns() >= 2);\r
+ CharacterRun chr = range.getCharacterRun(0);\r
+ assertEquals(false, chr.isSymbol());\r
+\r
+ chr = range.getCharacterRun(1);\r
+ assertEquals(true, chr.isSymbol());\r
+ assertEquals("\u0028", chr.text());\r
+ assertEquals("Wingdings", chr.getSymbolFont().getMainFontName());\r
+ assertEquals(0xf028, chr.getSymbolCharacter());\r
+ }\r
+\r
+}
\ No newline at end of file