From: Nick Burch Date: Thu, 5 Feb 2015 17:00:08 +0000 (+0000) Subject: XWPF double strikethrough, and start on a common interface for HWPF and XWPF characte... X-Git-Tag: REL_3_12_BETA1~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b1cb4b0f68e7dfab30c3772c2100b590907f6b93;p=poi.git XWPF double strikethrough, and start on a common interface for HWPF and XWPF character runs git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1657624 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunElement.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunElement.java index 6d845364b3..f11b46a135 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunElement.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/IRunElement.java @@ -16,11 +16,15 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import org.apache.poi.wp.usermodel.CharacterRun; + /** * Common interface for things that can occur * where a run (text with common stylings) can, * eg {@link XWPFRun} or {@link XWPFSDT}. - * More methods to follow shortly! + * TODO More methods to follow shortly! + * + * TODO Make this based on {@link CharacterRun} */ public interface IRunElement { } \ No newline at end of file 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 d93e54f274..9fb32c4e76 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java @@ -28,6 +28,7 @@ import javax.xml.namespace.QName; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.util.Internal; +import org.apache.poi.wp.usermodel.CharacterRun; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; @@ -47,7 +48,7 @@ import org.w3c.dom.Text; /** * XWPFRun object defines a region of text with a common set of properties */ -public class XWPFRun implements ISDTContents, IRunElement{ +public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { private CTR run; private String pictureText; private IRunBody parent; @@ -388,19 +389,35 @@ public class XWPFRun implements ISDTContents, IRunElement{ * * @return true if the strike property is applied */ - public boolean isStrike() { + public boolean isStrikeThrough() { CTRPr pr = run.getRPr(); if(pr == null || !pr.isSetStrike()) return false; return isCTOnOff(pr.getStrike()); } + @Deprecated + public boolean isStrike() { + return isStrikeThrough(); + } + /** + * Specifies that the contents of this run shall be displayed with a double + * horizontal line through the center of the line. + * + * @return true if the double strike property is applied + */ + public boolean isDoubleStrikeThrough() { + CTRPr pr = run.getRPr(); + if(pr == null || !pr.isSetDstrike()) + return false; + return isCTOnOff(pr.getDstrike()); + } /** * Specifies that the contents of this run shall be displayed with a single * horizontal line through the center of the line. *

* This formatting property is a toggle property, which specifies that its - * behavior differs between its use within a style definition and its use as + * behaviour differs between its use within a style definition and its use as * direct formatting. When used as part of a style definition, setting this * property shall toggle the current state of that property as specified up * to this point in the hierarchy (i.e. applied to not applied, and vice @@ -419,11 +436,25 @@ public class XWPFRun implements ISDTContents, IRunElement{ * @param value true if the strike property is applied to * this run */ - public void setStrike(boolean value) { + public void setStrikeThrough(boolean value) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTOnOff strike = pr.isSetStrike() ? pr.getStrike() : pr.addNewStrike(); strike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE); } + @Deprecated + public void setStrike(boolean value) { + setStrikeThrough(value); + } + /** + * Specifies that the contents of this run shall be displayed with a + * double horizontal line through the center of the line. + * @see #setStrikeThrough(boolean) for the rules about this + */ + public void setDoubleStrikethrough(boolean value) { + CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); + CTOnOff dstrike = pr.isSetDstrike() ? pr.getDstrike() : pr.addNewDstrike(); + dstrike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE); + } /** * Specifies the alignment which shall be applied to the contents of this diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java index 43d2a9b33c..d02f8ae9b8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java @@ -27,12 +27,9 @@ import org.apache.poi.hwpf.sprm.SprmBuffer; /** * This class represents a run of text that share common properties. - * - * @author Ryan Ackley */ -public final class CharacterRun - extends Range - implements Cloneable +public final class CharacterRun extends Range + implements Cloneable, org.apache.poi.wp.usermodel.CharacterRun { public final static short SPRM_FRMARKDEL = (short)0x0800; public final static short SPRM_FRMARK = 0x0801; @@ -245,6 +242,10 @@ public final class CharacterRun return _props.isFStrike(); } + public void setStrikeThrough(boolean strike) + { + strikeThrough(strike); + } public void strikeThrough(boolean strike) { _props.setFStrike(strike); diff --git a/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java b/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java new file mode 100644 index 0000000000..0ab7a49655 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/wp/usermodel/CharacterRun.java @@ -0,0 +1,91 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +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 isVanished(); + public void setVanished(boolean vanish); + + public boolean isMarkedInserted(); + public void markInserted(boolean mark); + + public boolean isStrikeThrough(); + public void setStrikeThrough(boolean strike); + public boolean isDoubleStrikeThrough(); + public void setDoubleStrikethrough(boolean dstrike); + + public boolean isShadowed(); + public void setShadow(boolean shadow); + + public boolean isEmbossed(); + public void setEmbossed(boolean emboss); + + public boolean isImprinted(); + public void setImprinted(boolean imprint); + + public int getFontSize(); + public void setFontSize(int halfPoints); + + public int getCharacterSpacing(); + public void setCharacterSpacing(int twips); + + public int getUnderlineCode(); + public void setUnderlineCode(int kul); + + // HWPF uses indexes, XWPF enums +// public short getSubSuperScriptIndex(); +// public void setSubSuperScriptIndex(short iss); + + // 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(); +*/ +}