More common XWPF/HWPF character run methods

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1657631 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-02-05 17:25:02 +00:00
parent b1cb4b0f68
commit 20349c8ce0
2 changed files with 108 additions and 17 deletions

View File

@ -456,6 +456,65 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
dstrike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
}
public boolean isSmallCaps() {
CTRPr pr = run.getRPr();
if(pr == null || !pr.isSetSmallCaps())
return false;
return isCTOnOff(pr.getSmallCaps());
}
public void setSmallCaps(boolean value) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTOnOff caps = pr.isSetSmallCaps() ? pr.getSmallCaps() : pr.addNewSmallCaps();
caps.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
}
public boolean isCapitalized() {
CTRPr pr = run.getRPr();
if(pr == null || !pr.isSetCaps())
return false;
return isCTOnOff(pr.getCaps());
}
public void setCapitalized(boolean value) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTOnOff caps = pr.isSetCaps() ? pr.getCaps() : pr.addNewCaps();
caps.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
}
public boolean isShadowed() {
CTRPr pr = run.getRPr();
if(pr == null || !pr.isSetShadow())
return false;
return isCTOnOff(pr.getShadow());
}
public void setShadow(boolean value) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTOnOff shadow = pr.isSetShadow() ? pr.getShadow() : pr.addNewShadow();
shadow.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
}
public boolean isImprinted() {
CTRPr pr = run.getRPr();
if(pr == null || !pr.isSetImprint())
return false;
return isCTOnOff(pr.getImprint());
}
public void setImprinted(boolean value) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTOnOff imprinted = pr.isSetImprint() ? pr.getImprint() : pr.addNewImprint();
imprinted.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
}
public boolean isEmbossed() {
CTRPr pr = run.getRPr();
if(pr == null || !pr.isSetEmboss())
return false;
return isCTOnOff(pr.getEmboss());
}
public void setEmbossed(boolean value) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTOnOff emboss = pr.isSetEmboss() ? pr.getEmboss() : pr.addNewEmboss();
emboss.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
}
/**
* Specifies the alignment which shall be applied to the contents of this
* run in relation to the default appearance of the run's text.
@ -492,6 +551,30 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
ctValign.setVal(STVerticalAlignRun.Enum.forInt(valign.getValue()));
}
public int getKerning() {
CTRPr pr = run.getRPr();
if(pr == null || !pr.isSetKern())
return 0;
return pr.getKern().getVal().intValue();
}
public void setKerning(int kern) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTHpsMeasure kernmes = pr.isSetKern() ? pr.getKern() : pr.addNewKern();
kernmes.setVal(BigInteger.valueOf(kern));
}
public int getCharacterSpacing() {
CTRPr pr = run.getRPr();
if(pr == null || !pr.isSetSpacing())
return 0;
return pr.getSpacing().getVal().intValue();
}
public void setCharacterSpacing(int twips) {
CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
CTSignedTwipsMeasure spc = pr.isSetSpacing() ? pr.getSpacing() : pr.addNewSpacing();
spc.setVal(BigInteger.valueOf(twips));
}
/**
* 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 characters
@ -502,6 +585,12 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public String getFontFamily() {
return getFontFamily(null);
}
/**
* Alias for {@link #getFontFamily()}
*/
public String getFontName() {
return getFontFamily();
}
/**
* Gets the font family for the specified font char range.

View File

@ -21,33 +21,34 @@ package org.apache.poi.wp.usermodel;
* This class represents a run of text that share common properties.
*/
public interface CharacterRun {// extends Range {
/*
public boolean isMarkedDeleted();
public void markDeleted(boolean mark);
public boolean isBold();
public void setBold(boolean bold);
public boolean isItalic();
public void setItalic(boolean italic);
public boolean isOutlined();
public void setOutline(boolean outlined);
public boolean isFldVanished();
public void setFldVanish(boolean fldVanish);
public boolean isSmallCaps();
public void setSmallCaps(boolean smallCaps);
public boolean isCapitalized();
public void setCapitalized(boolean caps);
/*
public boolean isFldVanished();
public void setFldVanish(boolean fldVanish);
public boolean isOutlined();
public void setOutline(boolean outlined);
public boolean isVanished();
public void setVanished(boolean vanish);
public boolean isMarkedDeleted();
public void markDeleted(boolean mark);
public boolean isMarkedInserted();
public void markInserted(boolean mark);
*/
public boolean isStrikeThrough();
public void setStrikeThrough(boolean strike);
@ -69,23 +70,24 @@ public interface CharacterRun {// extends Range {
public int getCharacterSpacing();
public void setCharacterSpacing(int twips);
public int getUnderlineCode();
public void setUnderlineCode(int kul);
// HWPF uses indexes, XWPF special
// public int getUnderlineCode();
// public void setUnderlineCode(int kul);
// HWPF uses indexes, XWPF enums
// HWPF uses indexes, XWPF special vertical alignments
// public short getSubSuperScriptIndex();
// public void setSubSuperScriptIndex(short iss);
// HWPF uses indexes, XWPF special vertical alignments
// public int getVerticalOffset();
// public void setVerticalOffset(int hpsPos);
// HWPF has colour indexes, XWPF colour names
// public int getColor();
// public void setColor(int color);
public int getVerticalOffset();
public void setVerticalOffset(int hpsPos);
public int getKerning();
public void setKerning(int kern);
public String getFontName();
*/
}