Add a XWPFRun equivalent of isHighlighted, and add to the common WP interface
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1712793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5636e64d68
commit
172593de22
@ -56,6 +56,24 @@ public interface CharacterRun {
|
|||||||
int getKerning();
|
int getKerning();
|
||||||
void setKerning(int kern);
|
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();
|
String getFontName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,14 +89,6 @@ public interface CharacterRun {
|
|||||||
// short getSubSuperScriptIndex();
|
// short getSubSuperScriptIndex();
|
||||||
// void setSubSuperScriptIndex(short iss);
|
// 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
|
// TODO Review these, and add to XWPFRun if possible
|
||||||
/*
|
/*
|
||||||
boolean isFldVanished();
|
boolean isFldVanished();
|
||||||
|
@ -73,6 +73,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalAlignRun
|
|||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
|
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.STOnOff;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
|
||||||
@ -623,6 +624,17 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
|
|||||||
kernmes.setVal(BigInteger.valueOf(kern));
|
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() {
|
public int getCharacterSpacing() {
|
||||||
CTRPr pr = run.getRPr();
|
CTRPr pr = run.getRPr();
|
||||||
if (pr == null || !pr.isSetSpacing())
|
if (pr == null || !pr.isSetSpacing())
|
||||||
|
@ -23,12 +23,14 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.xwpf.XWPFTestDataSamples;
|
import org.apache.poi.xwpf.XWPFTestDataSamples;
|
||||||
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
|
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
|
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.STOnOff;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
|
||||||
@ -383,6 +385,19 @@ public class TestXWPFRun extends TestCase {
|
|||||||
assertEquals(1, count);
|
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 {
|
public void testAddPicture() throws Exception {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
|
||||||
XWPFParagraph p = doc.getParagraphArray(2);
|
XWPFParagraph p = doc.getParagraphArray(2);
|
||||||
|
@ -106,6 +106,7 @@ public final class CharacterRun extends Range
|
|||||||
*
|
*
|
||||||
* @return TYPE_CHARACTER
|
* @return TYPE_CHARACTER
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public int type()
|
public int type()
|
||||||
{
|
{
|
||||||
return TYPE_CHARACTER;
|
return TYPE_CHARACTER;
|
||||||
|
Loading…
Reference in New Issue
Block a user