View | Details | Raw Unified | Return to bug 52568
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (+28 lines)
Lines 48-53 Link Here
48
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
48
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
49
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
49
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
50
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
50
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
51
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor;
51
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
52
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
52
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
53
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
53
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
54
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
Lines 74-79 Link Here
74
 * XWPFRun object defines a region of text with a common set of properties
75
 * XWPFRun object defines a region of text with a common set of properties
75
 *
76
 *
76
 * @author Yegor Kozlov
77
 * @author Yegor Kozlov
78
 * @author Gregg Morris (gregg dot morris at gmail dot com) - added getColor(), setColor()
79
 *
77
 */
80
 */
78
public class XWPFRun {
81
public class XWPFRun {
79
    private CTR run;
82
    private CTR run;
Lines 245-250 Link Here
245
    }
248
    }
246
249
247
    /**
250
    /**
251
     * Get text color. The returned value is a string in the hex form "RRGGBB".
252
     */
253
    public String getColor() {
254
    	String color = null;
255
        if (run.isSetRPr()) {
256
        	CTRPr pr = run.getRPr();
257
        	if (pr.isSetColor()) {
258
        		CTColor clr = pr.getColor();
259
        		color = clr.xgetVal().getStringValue();
260
        	}
261
        }
262
    	return color;
263
    }
264
265
    /**
266
     * Set text color.
267
     * @param rgbStr - the desired color, in the hex form "RRGGBB".
268
     */
269
    public void setColor(String rgbStr) {
270
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
271
        CTColor color = pr.isSetColor() ? pr.getColor() : pr.addNewColor();
272
        color.setVal(rgbStr);
273
    }
274
275
    /**
248
     * Return the string content of this text run
276
     * Return the string content of this text run
249
     *
277
     *
250
     * @return the text of this text run or <code>null</code> if not set
278
     * @return the text of this text run or <code>null</code> if not set
(-)src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (+7 lines)
Lines 161-166 Link Here
161
        assertEquals(2400, rpr.getPosition().getVal().longValue());
161
        assertEquals(2400, rpr.getPosition().getVal().longValue());
162
    }
162
    }
163
163
164
    public void testSetGetColor() {
165
        XWPFRun run = new XWPFRun(ctRun, p);
166
        run.setColor("0F0F0F");
167
        String clr = run.getColor();
168
        assertEquals("0F0F0F", clr);
169
    }
170
164
    public void testAddCarriageReturn() {
171
    public void testAddCarriageReturn() {
165
	
172
	
166
	ctRun.addNewT().setStringValue("TEST STRING");
173
	ctRun.addNewT().setStringValue("TEST STRING");

Return to bug 52568