From 5c86e51b65d6b874f22186bf5a70be2bbb3ee4f9 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 5 Feb 2015 17:35:09 +0000 Subject: [PATCH] More common HWPF/XWPF interfaces git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1657634 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xwpf/usermodel/IRunBody.java | 3 ++ .../poi/xwpf/usermodel/XWPFParagraph.java | 1 + .../apache/poi/xwpf/usermodel/XWPFRun.java | 8 +++- .../apache/poi/wp/usermodel/CharacterRun.java | 48 +++++++++++-------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunBody.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunBody.java index 55510ce4da..3ea4acabee 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunBody.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunBody.java @@ -17,10 +17,13 @@ package org.apache.poi.xwpf.usermodel; import org.apache.poi.POIXMLDocumentPart; +import org.apache.poi.wp.usermodel.Paragraph; /** * Simple interface describing both {@link XWPFParagraph} * and {@link XWPFSDT} + * + * TODO Should this be based on / extend {@link Paragraph}? */ public interface IRunBody { public XWPFDocument getDocument(); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index 5a4d7b33b7..1d11c032a4 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.util.Internal; +import org.apache.poi.wp.usermodel.Paragraph; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum; 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 8bbb1849df..07debb98c6 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java @@ -964,11 +964,17 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { } } + /** + * Returns the string version of the text + */ + public String toString() { + return text(); + } /** * Returns the string version of the text, with tabs and * carriage returns in place of their xml equivalents. */ - public String toString() { + public String text() { StringBuffer text = new StringBuffer(); // Grab the text and tabs of the text run diff --git a/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java b/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java index 5712dc0527..34165463aa 100644 --- a/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java +++ b/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java @@ -20,7 +20,7 @@ package org.apache.poi.wp.usermodel; /** * This class represents a run of text that share common properties. */ -public interface CharacterRun {// extends Range { +public interface CharacterRun { public boolean isBold(); public void setBold(boolean bold); @@ -33,23 +33,6 @@ public interface CharacterRun {// extends Range { 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); public boolean isDoubleStrikeThrough(); @@ -70,6 +53,16 @@ public interface CharacterRun {// extends Range { public int getCharacterSpacing(); public void setCharacterSpacing(int twips); + public int getKerning(); + public void setKerning(int kern); + + public String getFontName(); + + /** + * @return The text of the run, including any tabs/spaces/etc + */ + public String text(); + // HWPF uses indexes, XWPF special // public int getUnderlineCode(); // public void setUnderlineCode(int kul); @@ -86,8 +79,21 @@ public interface CharacterRun {// extends Range { // public int getColor(); // public void setColor(int color); - public int getKerning(); - public void setKerning(int kern); + // TODO Review these, and add to XWPFRun if possible +/* + 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 String getFontName(); + public boolean isMarkedDeleted(); + public void markDeleted(boolean mark); + + public boolean isMarkedInserted(); + public void markInserted(boolean mark); +*/ }