aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2012-02-07 09:45:20 +0000
committerYegor Kozlov <yegor@apache.org>2012-02-07 09:45:20 +0000
commite40b15ff5506dd0daacbb2097aaf1cebdaa146e3 (patch)
tree98fe89814de35dd94af7c6afd2ee2f12d46a9101 /src
parentd6474fedf9e43f2983796bfb4e1e8534e3c4ecc1 (diff)
downloadpoi-e40b15ff5506dd0daacbb2097aaf1cebdaa146e3.tar.gz
poi-e40b15ff5506dd0daacbb2097aaf1cebdaa146e3.zip
Bugzilla 52568: added methods to set/get an XWPFRun's text color
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1241395 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java28
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java7
3 files changed, 36 insertions, 0 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 68d7792bc7..3f0996a3fc 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta6" date="2012-??-??">
+ <action dev="poi-developers" type="add">52568 - Added methods to set/get an XWPFRun's text color</action>
<action dev="poi-developers" type="add">52566 - Added methods to set/get vertical alignment and color in XWPFTableCell</action>
<action dev="poi-developers" type="add">52562 - Added methods to get/set a table row's Can't Split and Repeat Header attributes in XWPF</action>
<action dev="poi-developers" type="add">52561 - Added methods to set table inside borders and cell margins in XWPF</action>
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
index 73629f7467..f5d396abb8 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
@@ -48,6 +48,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
@@ -74,6 +75,8 @@ import org.openxmlformats.schemas.drawingml.x2006.picture.CTPictureNonVisual;
* XWPFRun object defines a region of text with a common set of properties
*
* @author Yegor Kozlov
+ * @author Gregg Morris (gregg dot morris at gmail dot com) - added getColor(), setColor()
+ *
*/
public class XWPFRun {
private CTR run;
@@ -245,6 +248,31 @@ public class XWPFRun {
}
/**
+ * Get text color. The returned value is a string in the hex form "RRGGBB".
+ */
+ public String getColor() {
+ String color = null;
+ if (run.isSetRPr()) {
+ CTRPr pr = run.getRPr();
+ if (pr.isSetColor()) {
+ CTColor clr = pr.getColor();
+ color = clr.xgetVal().getStringValue();
+ }
+ }
+ return color;
+ }
+
+ /**
+ * Set text color.
+ * @param rgbStr - the desired color, in the hex form "RRGGBB".
+ */
+ public void setColor(String rgbStr) {
+ CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
+ CTColor color = pr.isSetColor() ? pr.getColor() : pr.addNewColor();
+ color.setVal(rgbStr);
+ }
+
+ /**
* Return the string content of this text run
*
* @return the text of this text run or <code>null</code> if not set
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
index 272ca87d1c..086e117e53 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
@@ -161,6 +161,13 @@ public class TestXWPFRun extends TestCase {
assertEquals(2400, rpr.getPosition().getVal().longValue());
}
+ public void testSetGetColor() {
+ XWPFRun run = new XWPFRun(ctRun, p);
+ run.setColor("0F0F0F");
+ String clr = run.getColor();
+ assertEquals("0F0F0F", clr);
+ }
+
public void testAddCarriageReturn() {
ctRun.addNewT().setStringValue("TEST STRING");