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/02/05 18:25:03 UTC

svn commit: r1657631 - in /poi/trunk/src: ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java

Author: nick
Date: Thu Feb  5 17:25:02 2015
New Revision: 1657631

URL: http://svn.apache.org/r1657631
Log:
More common XWPF/HWPF character run methods

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java

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=1657631&r1=1657630&r2=1657631&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 Feb  5 17:25:02 2015
@@ -456,6 +456,65 @@ public class XWPFRun implements ISDTCont
         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 ISDTCont
         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 ISDTCont
     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.

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java?rev=1657631&r1=1657630&r2=1657631&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java Thu Feb  5 17:25:02 2015
@@ -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 {// extend
     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();
-*/
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org