You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2015/11/05 16:15:40 UTC
svn commit: r1712793 - in /poi/trunk/src: java/org/apache/poi/wp/usermodel/
ooxml/java/org/apache/poi/xwpf/usermodel/
ooxml/testcases/org/apache/poi/xwpf/usermodel/
scratchpad/src/org/apache/poi/hwpf/usermodel/
Author: nick
Date: Thu Nov 5 15:15:36 2015
New Revision: 1712793
URL: http://svn.apache.org/viewvc?rev=1712793&view=rev
Log:
Add a XWPFRun equivalent of isHighlighted, and add to the common WP interface
Modified:
poi/trunk/src/java/org/apache/poi/wp/usermodel/CharacterRun.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java
Modified: poi/trunk/src/java/org/apache/poi/wp/usermodel/CharacterRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/wp/usermodel/CharacterRun.java?rev=1712793&r1=1712792&r2=1712793&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/wp/usermodel/CharacterRun.java (original)
+++ poi/trunk/src/java/org/apache/poi/wp/usermodel/CharacterRun.java Thu Nov 5 15:15:36 2015
@@ -55,7 +55,25 @@ public interface CharacterRun {
int getKerning();
void setKerning(int kern);
+
+ boolean isHighlighted();
+
+ // HWPF has colour indexes, XWPF has a highlight enum with the colours in
+// byte getHighlightedColor();
+// void setHighlighted(byte color);
+
+ // HWPF has colour indexes, XWPF colour names
+// int getColor();
+// void setColor(int color);
+
+ /**
+ * Gets the fonts which shall be used to display the text contents of
+ * this run. Specifies a font which shall be used to format all "normal"
+ * characters in the run
+ *
+ * @return a string representing the font
+ */
String getFontName();
/**
@@ -71,14 +89,6 @@ public interface CharacterRun {
// short getSubSuperScriptIndex();
// void setSubSuperScriptIndex(short iss);
- // HWPF uses indexes, XWPF special vertical alignments
-// int getVerticalOffset();
-// void setVerticalOffset(int hpsPos);
-
- // HWPF has colour indexes, XWPF colour names
-// int getColor();
-// void setColor(int color);
-
// TODO Review these, and add to XWPFRun if possible
/*
boolean isFldVanished();
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=1712793&r1=1712792&r2=1712793&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Thu Nov 5 15:15:36 2015
@@ -73,11 +73,12 @@ import org.openxmlformats.schemas.wordpr
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
+import org.w3c.dom.Text;
/**
* XWPFRun object defines a region of text with a common set of properties
@@ -623,6 +624,17 @@ public class XWPFRun implements ISDTCont
kernmes.setVal(BigInteger.valueOf(kern));
}
+ public boolean isHighlighted() {
+ CTRPr pr = run.getRPr();
+ if (pr == null || !pr.isSetHighlight())
+ return false;
+ if (pr.getHighlight().getVal() == STHighlightColor.NONE)
+ return false;
+ return true;
+ }
+ // TODO Provide a wrapper round STHighlightColor, then expose getter/setter
+ // for the highlight colour. Ideally also then add to CharacterRun interface
+
public int getCharacterSpacing() {
CTRPr pr = run.getRPr();
if (pr == null || !pr.isSetSpacing())
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1712793&r1=1712792&r2=1712793&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Thu Nov 5 15:15:36 2015
@@ -23,12 +23,14 @@ import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
+
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
@@ -382,6 +384,19 @@ public class TestXWPFRun extends TestCas
assertEquals(1, count);
}
+
+ public void testSetGetHighlight() throws Exception {
+ XWPFRun run = p.createRun();
+ assertEquals(false, run.isHighlighted());
+
+ // TODO Do this using XWPFRun methods
+ run.getCTR().addNewRPr().addNewHighlight().setVal(STHighlightColor.NONE);
+ assertEquals(false, run.isHighlighted());
+ run.getCTR().getRPr().getHighlight().setVal(STHighlightColor.CYAN);
+ assertEquals(true, run.isHighlighted());
+ run.getCTR().getRPr().getHighlight().setVal(STHighlightColor.NONE);
+ assertEquals(false, run.isHighlighted());
+ }
public void testAddPicture() throws Exception {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
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=1712793&r1=1712792&r2=1712793&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 Nov 5 15:15:36 2015
@@ -106,6 +106,7 @@ public final class CharacterRun extends
*
* @return TYPE_CHARACTER
*/
+ @SuppressWarnings("deprecation")
public int type()
{
return TYPE_CHARACTER;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org