You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/04/27 22:13:46 UTC
svn commit: r1676365 [7/9] - in /poi/branches/common_sl/src:
examples/src/org/apache/poi/hslf/examples/
examples/src/org/apache/poi/hssf/usermodel/examples/
examples/src/org/apache/poi/xslf/usermodel/tutorial/
examples/src/org/apache/poi/xssf/usermodel...
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java (from r1667902, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextShape.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextShape.java&r1=1667902&r2=1676365&rev=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextShape.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java Mon Apr 27 20:13:43 2015
@@ -15,40 +15,25 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.hslf.model;
+package org.apache.poi.hslf.usermodel;
+
+import static org.apache.poi.hslf.record.RecordTypes.*;
-import java.awt.Font;
-import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.font.FontRenderContext;
-import java.awt.font.TextLayout;
-import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
+import java.awt.geom.Rectangle2D.Double;
import java.io.IOException;
+import java.util.*;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.ddf.EscherSpRecord;
-import org.apache.poi.ddf.EscherTextboxRecord;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.ddf.*;
import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.record.EscherTextboxWrapper;
-import org.apache.poi.hslf.record.InteractiveInfo;
-import org.apache.poi.hslf.record.InteractiveInfoAtom;
-import org.apache.poi.hslf.record.OEPlaceholderAtom;
-import org.apache.poi.hslf.record.OutlineTextRefAtom;
-import org.apache.poi.hslf.record.PPDrawing;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextBytesAtom;
-import org.apache.poi.hslf.record.TextCharsAtom;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
-import org.apache.poi.hslf.usermodel.HSLFTextRun;
-import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.sl.draw.DrawFactory;
+import org.apache.poi.sl.draw.DrawTextShape;
+import org.apache.poi.sl.usermodel.*;
import org.apache.poi.util.POILogger;
/**
@@ -56,21 +41,21 @@ import org.apache.poi.util.POILogger;
*
* @author Yegor Kozlov
*/
-public abstract class HSLFTextShape extends HSLFSimpleShape {
+public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape<HSLFTextParagraph> {
/**
* How to anchor the text
*/
- public static final int AnchorTop = 0;
- public static final int AnchorMiddle = 1;
- public static final int AnchorBottom = 2;
- public static final int AnchorTopCentered = 3;
- public static final int AnchorMiddleCentered = 4;
- public static final int AnchorBottomCentered = 5;
- public static final int AnchorTopBaseline = 6;
- public static final int AnchorBottomBaseline = 7;
- public static final int AnchorTopCenteredBaseline = 8;
- public static final int AnchorBottomCenteredBaseline = 9;
+ /* package */ static final int AnchorTop = 0;
+ /* package */ static final int AnchorMiddle = 1;
+ /* package */ static final int AnchorBottom = 2;
+ /* package */ static final int AnchorTopCentered = 3;
+ /* package */ static final int AnchorMiddleCentered = 4;
+ /* package */ static final int AnchorBottomCentered = 5;
+ /* package */ static final int AnchorTopBaseline = 6;
+ /* package */ static final int AnchorBottomBaseline = 7;
+ /* package */ static final int AnchorTopCenteredBaseline = 8;
+ /* package */ static final int AnchorBottomCenteredBaseline = 9;
/**
* How to wrap the text
@@ -82,17 +67,9 @@ public abstract class HSLFTextShape exte
public static final int WrapThrough = 4;
/**
- * How to align the text
- */
- public static final int AlignLeft = 0;
- public static final int AlignCenter = 1;
- public static final int AlignRight = 2;
- public static final int AlignJustify = 3;
-
- /**
* TextRun object which holds actual text and format data
*/
- protected HSLFTextParagraph _txtrun;
+ protected List<HSLFTextParagraph> _paragraphs = new ArrayList<HSLFTextParagraph>();
/**
* Escher container which holds text attributes such as
@@ -101,6 +78,13 @@ public abstract class HSLFTextShape exte
protected EscherTextboxWrapper _txtbox;
/**
+ * This setting is used for supporting a deprecated alignment
+ *
+ * @see <a href=""></a>
+ */
+ boolean alignToBaseline = false;
+
+ /**
* Used to calculate text bounds
*/
protected static final FontRenderContext _frc = new FontRenderContext(null, true, true);
@@ -135,34 +119,6 @@ public abstract class HSLFTextShape exte
this(null);
}
- public HSLFTextParagraph createTextRun(){
- _txtbox = getEscherTextboxWrapper();
- if(_txtbox == null) _txtbox = new EscherTextboxWrapper();
-
- _txtrun = getTextParagraph();
- if(_txtrun == null){
- TextHeaderAtom tha = new TextHeaderAtom();
- tha.setParentRecord(_txtbox);
- _txtbox.appendChildRecord(tha);
-
- TextCharsAtom tca = new TextCharsAtom();
- _txtbox.appendChildRecord(tca);
-
- StyleTextPropAtom sta = new StyleTextPropAtom(0);
- _txtbox.appendChildRecord(sta);
-
- _txtrun = new HSLFTextParagraph(tha,tca,sta);
- _txtrun._records = new Record[]{tha, tca, sta};
- _txtrun.setText("");
-
- _escherContainer.addChildRecord(_txtbox.getEscherRecord());
-
- setDefaultTextProperties(_txtrun);
- }
-
- return _txtrun;
- }
-
/**
* Set default properties for the TextRun.
* Depending on the text and shape type the defaults are different:
@@ -175,30 +131,6 @@ public abstract class HSLFTextShape exte
}
/**
- * Returns the text contained in this text frame.
- *
- * @return the text string for this textbox.
- */
- public String getText(){
- HSLFTextParagraph tx = getTextParagraph();
- return tx == null ? null : tx.getText();
- }
-
- /**
- * Sets the text contained in this text frame.
- *
- * @param text the text string used by this object.
- */
- public void setText(String text){
- HSLFTextParagraph tx = getTextParagraph();
- if(tx == null){
- tx = createTextRun();
- }
- tx.setText(text);
- setTextId(text.hashCode());
- }
-
- /**
* When a textbox is added to a sheet we need to tell upper-level
* <code>PPDrawing</code> about it.
*
@@ -219,10 +151,10 @@ public abstract class HSLFTextShape exte
}
if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();
}
- if(_txtrun != null) {
- _txtrun.setShapeId(getShapeId());
- sh.onAddTextShape(this);
+ for (HSLFTextParagraph htp : _paragraphs) {
+ htp.setShapeId(getShapeId());
}
+ sh.onAddTextShape(this);
}
protected EscherTextboxWrapper getEscherTextboxWrapper(){
@@ -232,117 +164,189 @@ public abstract class HSLFTextShape exte
}
return _txtbox;
}
+
/**
- * Adjust the size of the TextShape so it encompasses the text inside it.
+ * Adjust the size of the shape so it encompasses the text inside it.
*
- * @return a <code>Rectangle2D</code> that is the bounds of this <code>TextShape</code>.
+ * @return a <code>Rectangle2D</code> that is the bounds of this shape.
*/
public Rectangle2D resizeToFitText(){
- String txt = getText();
- if(txt == null || txt.length() == 0) return new Rectangle2D.Float();
-
- HSLFTextRun rt = getTextParagraph().getRichTextRuns()[0];
- int size = rt.getFontSize();
- int style = 0;
- if (rt.isBold()) style |= Font.BOLD;
- if (rt.isItalic()) style |= Font.ITALIC;
- String fntname = rt.getFontName();
- Font font = new Font(fntname, style, size);
-
- float width = 0, height = 0, leading = 0;
- String[] lines = txt.split("\n");
- for (int i = 0; i < lines.length; i++) {
- if(lines[i].length() == 0) continue;
-
- TextLayout layout = new TextLayout(lines[i], font, _frc);
-
- leading = Math.max(leading, layout.getLeading());
- width = Math.max(width, layout.getAdvance());
- height = Math.max(height, (height + (layout.getDescent() + layout.getAscent())));
- }
-
- // add one character to width
- Rectangle2D charBounds = font.getMaxCharBounds(_frc);
- width += getMarginLeft() + getMarginRight() + charBounds.getWidth();
-
- // add leading to height
- height += getMarginTop() + getMarginBottom() + leading;
-
- Rectangle2D anchor = getAnchor2D();
- anchor.setRect(anchor.getX(), anchor.getY(), width, height);
+ Rectangle2D anchor = getAnchor();
+ if(anchor.getWidth() == 0.) {
+ logger.log(POILogger.WARN, "Width of shape wasn't set. Defaulting to 200px");
+ anchor = new Rectangle2D.Double(anchor.getX(), anchor.getY(), 200, anchor.getHeight());
+ setAnchor(anchor);
+ }
+ double height = getTextHeight();
+ height += 1; // add a pixel to compensate rounding errors
+
+ anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height);
setAnchor(anchor);
-
+
return anchor;
+ }
+
+ /**
+ * Returns the type of the text, from the TextHeaderAtom.
+ * Possible values can be seen from TextHeaderAtom
+ * @see org.apache.poi.hslf.record.TextHeaderAtom
+ */
+ public int getRunType() {
+ getEscherTextboxWrapper();
+ if (_txtbox == null) return -1;
+ TextHeaderAtom headerAtom = (TextHeaderAtom)_txtbox.findFirstOfType(TextHeaderAtom.typeID);
+ assert(headerAtom != null);
+ return headerAtom.getTextType();
}
/**
+ * Changes the type of the text. Values should be taken
+ * from TextHeaderAtom. No checking is done to ensure you
+ * set this to a valid value!
+ * @see org.apache.poi.hslf.record.TextHeaderAtom
+ */
+ public void setRunType(int type) {
+ getEscherTextboxWrapper();
+ if (_txtbox == null) return;
+ TextHeaderAtom headerAtom = (TextHeaderAtom)_txtbox.findFirstOfType(TextHeaderAtom.typeID);
+ assert(headerAtom != null);
+ headerAtom.setTextType(type);
+ }
+
+ /**
* Returns the type of vertical alignment for the text.
* One of the <code>Anchor*</code> constants defined in this class.
*
* @return the type of alignment
*/
- public int getVerticalAlignment(){
+ /* package */ int getAlignment(){
EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
- int valign = HSLFTextShape.AnchorTop;
+ int align = HSLFTextShape.AnchorTop;
if (prop == null){
/**
* If vertical alignment was not found in the shape properties then try to
* fetch the master shape and search for the align property there.
*/
- int type = getTextParagraph().getRunType();
+ int type = getRunType();
HSLFMasterSheet master = getSheet().getMasterSheet();
if(master != null){
HSLFTextShape masterShape = master.getPlaceholderByTextType(type);
- if(masterShape != null) valign = masterShape.getVerticalAlignment();
+ if(masterShape != null) align = masterShape.getAlignment();
} else {
//not found in the master sheet. Use the hardcoded defaults.
switch (type){
- case TextHeaderAtom.TITLE_TYPE:
- case TextHeaderAtom.CENTER_TITLE_TYPE:
- valign = HSLFTextShape.AnchorMiddle;
+ case org.apache.poi.hslf.record.TextHeaderAtom.TITLE_TYPE:
+ case org.apache.poi.hslf.record.TextHeaderAtom.CENTER_TITLE_TYPE:
+ align = HSLFTextShape.AnchorMiddle;
break;
default:
- valign = HSLFTextShape.AnchorTop;
+ align = HSLFTextShape.AnchorTop;
break;
}
}
} else {
- valign = prop.getPropertyValue();
+ align = prop.getPropertyValue();
}
- return valign;
+
+ alignToBaseline = (align == AnchorBottomBaseline || align == AnchorBottomCenteredBaseline
+ || align == AnchorTopBaseline || align == AnchorTopCenteredBaseline);
+
+ return align;
}
/**
- * Sets the type of vertical alignment for the text.
+ * Sets the type of alignment for the text.
* One of the <code>Anchor*</code> constants defined in this class.
*
* @param align - the type of alignment
*/
- public void setVerticalAlignment(int align){
- setEscherProperty(EscherProperties.TEXT__ANCHORTEXT, align);
+ /* package */ void setAlignment(Boolean isCentered, VerticalAlignment vAlign) {
+ int align[];
+ switch (vAlign) {
+ case TOP:
+ align = new int[]{AnchorTop, AnchorTopCentered, AnchorTopBaseline, AnchorTopCenteredBaseline};
+ break;
+ default:
+ case MIDDLE:
+ align = new int[]{AnchorMiddle, AnchorMiddleCentered, AnchorMiddle, AnchorMiddleCentered};
+ break;
+ case BOTTOM:
+ align = new int[]{AnchorBottom, AnchorBottomCentered, AnchorBottomBaseline, AnchorBottomCenteredBaseline};
+ break;
+ }
+
+ int align2 = align[(isCentered ? 1 : 0)+(alignToBaseline ? 2 : 0)];
+
+ setEscherProperty(EscherProperties.TEXT__ANCHORTEXT, align2);
+ }
+
+ @Override
+ public VerticalAlignment getVerticalAlignment() {
+ int va = getAlignment();
+ switch (va) {
+ case AnchorTop:
+ case AnchorTopCentered:
+ case AnchorTopBaseline:
+ case AnchorTopCenteredBaseline: return VerticalAlignment.TOP;
+ case AnchorBottom:
+ case AnchorBottomCentered:
+ case AnchorBottomBaseline:
+ case AnchorBottomCenteredBaseline: return VerticalAlignment.BOTTOM;
+ default:
+ case AnchorMiddle:
+ case AnchorMiddleCentered: return VerticalAlignment.MIDDLE;
+ }
}
/**
- * Sets the type of horizontal alignment for the text.
- * One of the <code>Align*</code> constants defined in this class.
+ * @return true, if vertical alignment is relative to baseline
+ * this is only used for older versions less equals Office 2003
+ */
+ public boolean isAlignToBaseline() {
+ getAlignment();
+ return alignToBaseline;
+ }
+
+ /**
+ * Sets the vertical alignment relative to the baseline
*
- * @param align - the type of horizontal alignment
+ * @param alignToBaseline if true, vertical alignment is relative to baseline
*/
- public void setHorizontalAlignment(int align){
- HSLFTextParagraph tx = getTextParagraph();
- if(tx != null) tx.getRichTextRuns()[0].setAlignment(align);
+ public void setAlignToBaseline(boolean alignToBaseline) {
+ this.alignToBaseline = alignToBaseline;
+ setAlignment(isHorizontalCentered(), getVerticalAlignment());
+ }
+
+ @Override
+ public boolean isHorizontalCentered() {
+ int va = getAlignment();
+ switch (va) {
+ case AnchorTopCentered:
+ case AnchorTopCenteredBaseline:
+ case AnchorBottomCentered:
+ case AnchorBottomCenteredBaseline:
+ case AnchorMiddleCentered:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public void setVerticalAlignment(VerticalAlignment vAlign) {
+ setAlignment(isHorizontalCentered(), vAlign);
}
/**
- * Gets the type of horizontal alignment for the text.
- * One of the <code>Align*</code> constants defined in this class.
+ * Sets if the paragraphs are horizontal centered
*
- * @return align - the type of horizontal alignment
+ * @param isCentered true, if the paragraphs are horizontal centered
+ * A {@code null} values unsets this property.
+ *
+ * @see TextShape#isHorizontalCentered()
*/
- public int getHorizontalAlignment(){
- HSLFTextParagraph tx = getTextParagraph();
- return tx == null ? -1 : tx.getRichTextRuns()[0].getAlignment();
+ public void setHorizontalCentered(Boolean isCentered){
+ setAlignment(isCentered, getVerticalAlignment());
}
/**
@@ -352,20 +356,20 @@ public abstract class HSLFTextShape exte
*
* @return the botom margin
*/
- public float getMarginBottom(){
+ public double getBottomInset(){
EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
+ return val/EMU_PER_POINT;
}
/**
* Sets the botom margin.
- * @see #getMarginBottom()
+ * @see #getBottomInset()
*
* @param margin the bottom margin
*/
- public void setMarginBottom(float margin){
+ public void setBottomInset(double margin){
setEscherProperty(EscherProperties.TEXT__TEXTBOTTOM, (int)(margin*EMU_PER_POINT));
}
@@ -377,20 +381,20 @@ public abstract class HSLFTextShape exte
*
* @return the left margin
*/
- public float getMarginLeft(){
+ public double getLeftInset(){
EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT);
int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
+ return val/EMU_PER_POINT;
}
/**
* Sets the left margin.
- * @see #getMarginLeft()
+ * @see #getLeftInset()
*
* @param margin the left margin
*/
- public void setMarginLeft(float margin){
+ public void setLeftInset(double margin){
setEscherProperty(EscherProperties.TEXT__TEXTLEFT, (int)(margin*EMU_PER_POINT));
}
@@ -402,20 +406,20 @@ public abstract class HSLFTextShape exte
*
* @return the right margin
*/
- public float getMarginRight(){
+ public double getRightInset(){
EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
+ return val/EMU_PER_POINT;
}
/**
* Sets the right margin.
- * @see #getMarginRight()
+ * @see #getRightInset()
*
* @param margin the right margin
*/
- public void setMarginRight(float margin){
+ public void setRightInset(double margin){
setEscherProperty(EscherProperties.TEXT__TEXTRIGHT, (int)(margin*EMU_PER_POINT));
}
@@ -426,31 +430,38 @@ public abstract class HSLFTextShape exte
*
* @return the top margin
*/
- public float getMarginTop(){
+ public double getTopInset(){
EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
+ return val/EMU_PER_POINT;
}
/**
* Sets the top margin.
- * @see #getMarginTop()
+ * @see #getTopInset()
*
* @param margin the top margin
*/
- public void setMarginTop(float margin){
+ public void setTopInset(double margin){
setEscherProperty(EscherProperties.TEXT__TEXTTOP, (int)(margin*EMU_PER_POINT));
}
+ @Override
+ public boolean getWordWrap(){
+ int ww = getWordWrapEx();
+ return (ww != WrapNone);
+ }
/**
* Returns the value indicating word wrap.
*
* @return the value indicating word wrap.
* Must be one of the <code>Wrap*</code> constants defined in this class.
+ *
+ * @see <a href="https://msdn.microsoft.com/en-us/library/dd948168(v=office.12).aspx">MSOWRAPMODE</a>
*/
- public int getWordWrap(){
+ public int getWordWrapEx() {
EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
return prop == null ? WrapSquare : prop.getPropertyValue();
@@ -487,32 +498,28 @@ public abstract class HSLFTextShape exte
/**
* @return the TextRun object for this text box
*/
- public HSLFTextParagraph getTextParagraph(){
- if (null == this._txtrun) initTextRun();
- if (null == this._txtrun && null != this._txtbox) {
- TextHeaderAtom tha = null;
- TextBytesAtom tba = null;
- TextCharsAtom tca = null;
- StyleTextPropAtom sta = null;
- Record[] childRecords = this._txtbox.getChildRecords();
- for (Record r : childRecords) {
- if (r instanceof TextHeaderAtom) {
- tha = (TextHeaderAtom) r;
- } else if (r instanceof TextBytesAtom) {
- tba = (TextBytesAtom) r;
- } else if (r instanceof TextCharsAtom) {
- tca = (TextCharsAtom) r;
- } else if (r instanceof StyleTextPropAtom) {
- sta = (StyleTextPropAtom) r;
- }
- }
- if (tba != null) {
- this._txtrun = new HSLFTextParagraph(tha, tba, sta);
- } else if (tca != null) {
- this._txtrun = new HSLFTextParagraph(tha, tca, sta);
- }
- }
- return _txtrun;
+ public List<HSLFTextParagraph> getTextParagraphs(){
+ if (!_paragraphs.isEmpty()) return _paragraphs;
+
+ _txtbox = getEscherTextboxWrapper();
+ if (_txtbox == null) {
+ _paragraphs.addAll(HSLFTextParagraph.createEmptyParagraph());
+ _txtbox = _paragraphs.get(0).getTextboxWrapper();
+ } else {
+ initParagraphsFromSheetRecords();
+ if (_paragraphs.isEmpty()) {
+ List<List<HSLFTextParagraph>> llhtp = HSLFTextParagraph.findTextParagraphs(_txtbox);
+ if (!llhtp.isEmpty()) {
+ _paragraphs.addAll(llhtp.get(0));
+ }
+ }
+ }
+
+ for (HSLFTextParagraph p : _paragraphs) {
+ p.setParentShape(this);
+ }
+
+ return _paragraphs;
}
public void setSheet(HSLFSheet sheet) {
@@ -522,14 +529,13 @@ public abstract class HSLFTextShape exte
// (We can't do it in the constructor because the sheet
// is not assigned then, it's only built once we have
// all the records)
- HSLFTextParagraph tx = getTextParagraph();
- if (tx != null) {
+ for (HSLFTextParagraph htp : getTextParagraphs()) {
// Supply the sheet to our child RichTextRuns
- tx.supplySheet(_sheet);
+ htp.supplySheet(_sheet);
}
}
- protected void initTextRun(){
+ protected void initParagraphsFromSheetRecords(){
EscherTextboxWrapper txtbox = getEscherTextboxWrapper();
HSLFSheet sheet = getSheet();
@@ -545,55 +551,69 @@ public abstract class HSLFTextShape exte
}
}
- HSLFTextParagraph[] runs = _sheet.getTextRuns();
- if (ota != null) {
- int idx = ota.getTextIndex();
- for (int i = 0; i < runs.length; i++) {
- if(runs[i].getIndex() == idx){
- _txtrun = runs[i];
- break;
+ List<List<HSLFTextParagraph>> sheetRuns = _sheet.getTextParagraphs();
+ _paragraphs.clear();
+ if (sheetRuns != null) {
+ if (ota != null) {
+ int idx = ota.getTextIndex();
+ for (List<HSLFTextParagraph> r : sheetRuns) {
+ if (r.isEmpty()) continue;
+ int ridx = r.get(0).getIndex();
+ if (ridx > idx) break;
+ if (ridx == idx) _paragraphs.addAll(r);
}
- }
- if(_txtrun == null) {
- logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
- }
- } else {
- EscherSpRecord escherSpRecord = getEscherChild(EscherSpRecord.RECORD_ID);
- int shapeId = escherSpRecord.getShapeId();
- if(runs != null) for (int i = 0; i < runs.length; i++) {
- if(runs[i].getShapeId() == shapeId){
- _txtrun = runs[i];
- break;
+ if(_paragraphs.isEmpty()) {
+ logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
}
- }
- }
-
- // ensure the same references child records of TextRun
- if(_txtrun != null) {
- for (int i = 0; i < child.length; i++) {
- for (Record r : _txtrun.getRecords()) {
- if (child[i].getRecordType() == r.getRecordType()) {
- child[i] = r;
- }
+ } else {
+ int shapeId = getShapeId();
+ for (List<HSLFTextParagraph> r : sheetRuns) {
+ if (r.isEmpty()) continue;
+ if (r.get(0).getShapeId() == shapeId) _paragraphs.addAll(r);
}
}
}
- }
- public void draw(Graphics2D graphics){
- AffineTransform at = graphics.getTransform();
- ShapePainter.paint(this, graphics);
- new TextPainter(this).paint(graphics);
- graphics.setTransform(at);
- }
+ // ensure the same references child records of TextRun
+ // TODO: check the purpose of this ...
+// if(_txtrun != null) {
+// for (int i = 0; i < child.length; i++) {
+// for (Record r : _txtrun.getRecords()) {
+// if (child[i].getRecordType() == r.getRecordType()) {
+// child[i] = r;
+// }
+// }
+// }
+// }
+ }
+
+ /*
+ // 0xB acts like cariage return in page titles and like blank in the others
+ char replChr;
+ switch(tha == null ? -1 : tha.getTextType()) {
+ case -1:
+ case TextHeaderAtom.TITLE_TYPE:
+ case TextHeaderAtom.CENTER_TITLE_TYPE:
+ replChr = '\n';
+ break;
+ default:
+ replChr = ' ';
+ break;
+ }
+ // PowerPoint seems to store files with \r as the line break
+ // The messes things up on everything but a Mac, so translate
+ // them to \n
+ String text = rawText.replace('\r','\n').replace('\u000b', replChr);
+ */
+
/**
* Return <code>OEPlaceholderAtom</code>, the atom that describes a placeholder.
*
* @return <code>OEPlaceholderAtom</code> or <code>null</code> if not found
*/
public OEPlaceholderAtom getPlaceholderAtom(){
- return getClientDataRecord(RecordTypes.OEPlaceholderAtom.typeID);
+ return getClientDataRecord(OEPlaceholderAtom.typeID);
}
/**
@@ -603,15 +623,15 @@ public abstract class HSLFTextShape exte
* @param linkId id of the hyperlink, @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
* @param beginIndex the beginning index, inclusive.
* @param endIndex the ending index, exclusive.
- * @see org.apache.poi.hslf.usermodel.HSLFSlideShow#addHyperlink(Hyperlink)
+ * @see org.apache.poi.hslf.usermodel.HSLFSlideShow#addHyperlink(HSLFHyperlink)
*/
public void setHyperlink(int linkId, int beginIndex, int endIndex){
//TODO validate beginIndex and endIndex and throw IllegalArgumentException
InteractiveInfo info = new InteractiveInfo();
InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
- infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
+ infoAtom.setAction(org.apache.poi.hslf.record.InteractiveInfoAtom.ACTION_HYPERLINK);
+ infoAtom.setHyperlinkType(org.apache.poi.hslf.record.InteractiveInfoAtom.LINK_Url);
infoAtom.setHyperlinkID(linkId);
_txtbox.appendChildRecord(info);
@@ -629,11 +649,106 @@ public abstract class HSLFTextShape exte
if (oep != null) return true;
//special case for files saved in Office 2007
- RoundTripHFPlaceholder12 hldr = getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID);
+ RoundTripHFPlaceholder12 hldr = getClientDataRecord(RoundTripHFPlaceholder12.typeID);
if (hldr != null) return true;
return false;
}
+
+ @Override
+ public Iterator<HSLFTextParagraph> iterator() {
+ return _paragraphs.iterator();
+ }
+
+ @Override
+ public Insets2D getInsets() {
+ Insets2D insets = new Insets2D(getTopInset(), getLeftInset(), getBottomInset(), getRightInset());
+ return insets;
+ }
+
+ @Override
+ public double getTextHeight(){
+ DrawFactory drawFact = DrawFactory.getInstance(null);
+ DrawTextShape<HSLFTextShape> dts = drawFact.getDrawable(this);
+ return dts.getTextHeight();
+ }
+
+ @Override
+ public TextDirection getTextDirection() {
+ // TODO: determine vertical text setting
+ return TextDirection.HORIZONTAL;
+ }
+
+ /**
+ * Returns the raw text content of the shape. This hasn't had any
+ * changes applied to it, and so is probably unlikely to print
+ * out nicely.
+ */
+ public String getRawText() {
+ return HSLFTextParagraph.getRawText(getTextParagraphs());
+ }
+
+ /**
+ * Returns the text contained in this text frame, which has been made safe
+ * for printing and other use.
+ *
+ * @return the text string for this textbox.
+ */
+ public String getText() {
+ String rawText = getRawText();
+ TextHeaderAtom _headerAtom = (TextHeaderAtom)_txtbox.findFirstOfType(TextHeaderAtom.typeID);
+ int runType = (_headerAtom == null) ? -1 : _headerAtom.getTextType();
+
+ return HSLFTextParagraph.toExternalString(rawText, runType);
+ }
+
-}
+ // Update methods follow
+
+ /**
+ * Adds the supplied text onto the end of the TextParagraphs,
+ * creating a new RichTextRun for it to sit in.
+ *
+ * @param text the text string used by this object.
+ */
+ public void appendText(String text, boolean newParagraph) {
+ // init paragraphs
+ List<HSLFTextParagraph> paras = getTextParagraphs();
+ HSLFTextParagraph.appendText(paras, text, newParagraph);
+ }
+
+ /**
+ * Sets (overwrites) the current text.
+ * Uses the properties of the first paragraph / textrun
+ *
+ * @param text the text string used by this object.
+ */
+ public void setText(String text) {
+ // init paragraphs
+ List<HSLFTextParagraph> paras = getTextParagraphs();
+ HSLFTextParagraph.setText(paras, text);
+ setTextId(text.hashCode());
+ }
+
+ /**
+ * Saves the modified paragraphs/textrun to the records.
+ * Also updates the styles to the correct text length.
+ */
+ protected void storeText() {
+ HSLFTextParagraph.storeText(_paragraphs);
+ }
+ // Accesser methods follow
+
+ /**
+ * Returns the array of all hyperlinks in this text run
+ *
+ * @return the array of all hyperlinks in this text run or <code>null</code>
+ * if not found.
+ */
+ public HSLFHyperlink[] getHyperlinks() {
+ return HSLFHyperlink.find(this);
+ }
+
+
+}
\ No newline at end of file
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTitleMaster.java (from r1667902, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTitleMaster.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTitleMaster.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java&r1=1667902&r2=1676365&rev=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTitleMaster.java Mon Apr 27 20:13:43 2015
@@ -15,34 +15,36 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.hslf.model;
+package org.apache.poi.hslf.usermodel;
+
+import java.util.ArrayList;
+import java.util.List;
import org.apache.poi.hslf.model.textproperties.TextProp;
-import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.record.SlideAtom;
/**
* Title masters define the design template for slides with a Title Slide layout.
*
* @author Yegor Kozlov
*/
-public final class TitleMaster extends HSLFMasterSheet {
- private HSLFTextParagraph[] _runs;
+public final class HSLFTitleMaster extends HSLFMasterSheet {
+ private final List<List<HSLFTextParagraph>> _runs = new ArrayList<List<HSLFTextParagraph>>();
/**
* Constructs a TitleMaster
*
*/
- public TitleMaster(org.apache.poi.hslf.record.Slide record, int sheetNo) {
+ public HSLFTitleMaster(org.apache.poi.hslf.record.Slide record, int sheetNo) {
super(record, sheetNo);
- _runs = findTextRuns(getPPDrawing());
- for (int i = 0; i < _runs.length; i++) _runs[i].setSheet(this);
+ _runs.addAll(HSLFTextParagraph.findTextParagraphs(getPPDrawing()));
}
/**
* Returns an array of all the TextRuns found
*/
- public HSLFTextParagraph[] getTextRuns() {
+ public List<List<HSLFTextParagraph>> getTextParagraphs() {
return _runs;
}
@@ -58,11 +60,11 @@ public final class TitleMaster extends H
* Returns the slide master for this title master.
*/
public HSLFMasterSheet getMasterSheet(){
- SlideMaster[] master = getSlideShow().getSlidesMasters();
+ List<HSLFSlideMaster> master = getSlideShow().getSlideMasters();
SlideAtom sa = ((org.apache.poi.hslf.record.Slide)getSheetContainer()).getSlideAtom();
int masterId = sa.getMasterID();
- for (int i = 0; i < master.length; i++) {
- if (masterId == master[i]._getSheetNumber()) return master[i];
+ for (HSLFSlideMaster sm : master) {
+ if (masterId == sm._getSheetNumber()) return sm;
}
return null;
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java Mon Apr 27 20:13:43 2015
@@ -76,7 +76,7 @@ public class DrawFactory {
} else if (shape instanceof Background) {
return getDrawable((Background)shape);
} else if (shape instanceof Slide) {
- return getDrawable((Slide<? extends Shape, ? extends SlideShow>)shape);
+ return getDrawable((Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>)shape);
} else if (shape instanceof MasterSheet) {
return getDrawable((MasterSheet<? extends Shape, ? extends SlideShow>)shape);
} else if (shape instanceof Sheet) {
@@ -86,7 +86,7 @@ public class DrawFactory {
throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());
}
- public <T extends Slide<? extends Shape, ? extends SlideShow>> DrawSlide<T> getDrawable(T sheet) {
+ public <T extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> DrawSlide<T> getDrawable(T sheet) {
return new DrawSlide<T>(sheet);
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java Mon Apr 27 20:13:43 2015
@@ -5,7 +5,7 @@ import java.awt.Graphics2D;
import org.apache.poi.sl.usermodel.*;
-public class DrawSlide<T extends Slide<? extends Shape, ? extends SlideShow>> extends DrawSheet<T> {
+public class DrawSlide<T extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> extends DrawSheet<T> {
public DrawSlide(T slide) {
super(slide);
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextParagraph.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextParagraph.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextParagraph.java Mon Apr 27 20:13:43 2015
@@ -237,7 +237,7 @@ public class DrawTextParagraph<T extends
protected String getRenderableText(TextRun tr) {
StringBuilder buf = new StringBuilder();
TextCap cap = tr.getTextCap();
- for (char c : tr.getText().toCharArray()) {
+ for (char c : tr.getRawText().toCharArray()) {
if(c == '\t') {
// TODO: finish support for tabs
buf.append(" ");
@@ -346,7 +346,7 @@ public class DrawTextParagraph<T extends
if(run.isItalic()) {
attList.add(new AttributedStringData(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, beginIndex, endIndex));
}
- if(run.isUnderline()) {
+ if(run.isUnderlined()) {
attList.add(new AttributedStringData(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, beginIndex, endIndex));
attList.add(new AttributedStringData(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_TWO_PIXEL, beginIndex, endIndex));
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java Mon Apr 27 20:13:43 2015
@@ -19,8 +19,7 @@
package org.apache.poi.sl.draw.geom;
-import java.io.*;
-import java.nio.charset.Charset;
+import java.io.InputStream;
import java.util.LinkedHashMap;
import javax.xml.bind.*;
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java Mon Apr 27 20:13:43 2015
@@ -17,6 +17,6 @@
package org.apache.poi.sl.usermodel;
-public interface Line extends AutoShape {
+public interface Line<T extends TextParagraph<? extends TextRun>> extends AutoShape<T> {
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java Mon Apr 27 20:13:43 2015
@@ -20,5 +20,5 @@ package org.apache.poi.sl.usermodel;
import java.util.List;
public interface Notes<T extends Shape, SS extends SlideShow> extends Sheet<T,SS> {
- List<? extends TextParagraph<? extends TextRun>> getTextParagraphs();
+ List<? extends List<? extends TextParagraph<? extends TextRun>>> getTextParagraphs();
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java Mon Apr 27 20:13:43 2015
@@ -17,18 +17,20 @@
package org.apache.poi.sl.usermodel;
+import java.util.List;
+
public interface ShapeContainer<T extends Shape> extends Iterable<T> {
/**
- * Returns an array containing all of the elements in this container in proper
+ * Returns an list containing all of the elements in this container in proper
* sequence (from first to last element).
*
- * @return an array containing all of the elements in this container in proper
+ * @return an list containing all of the elements in this container in proper
* sequence
*/
- public T[] getShapes();
+ List<T> getShapes();
- public void addShape(T shape);
+ void addShape(T shape);
/**
* Removes the specified shape from this sheet, if it is present
@@ -40,5 +42,5 @@ public interface ShapeContainer<T extend
* @throws IllegalArgumentException if the type of the specified shape
* is incompatible with this sheet (optional)
*/
- public boolean removeShape(T shape);
+ boolean removeShape(T shape);
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java Mon Apr 27 20:13:43 2015
@@ -285,6 +285,25 @@ public enum ShapeType {
this.nativeName = nativeName;
}
+ /** name of the presetShapeDefinit(i)on entry */
+ public String getOoxmlName() {
+ if (this == SEAL) return STAR_16.getOoxmlName();
+ if (ooxmlId == -1) return null;
+
+ StringBuilder sb = new StringBuilder();
+ boolean toLower = true;
+ for (char ch : name().toCharArray()) {
+ if (ch == '_') {
+ toLower = false;
+ continue;
+ }
+ sb.append(toLower ? Character.toLowerCase(ch) : Character.toUpperCase(ch));
+ toLower = true;
+ }
+
+ return sb.toString();
+ }
+
public static ShapeType forId(int id, boolean isOoxmlId){
for(ShapeType t : values()){
if((isOoxmlId && t.ooxmlId == id) ||
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java Mon Apr 27 20:13:43 2015
@@ -17,16 +17,16 @@
package org.apache.poi.sl.usermodel;
-public interface Slide<T extends Shape, SS extends SlideShow> extends Sheet<T, SS> {
- public Notes<T,SS> getNotes();
- public void setNotes(Notes<T,SS> notes);
+public interface Slide<T extends Shape, SS extends SlideShow, N extends Notes<T,SS>> extends Sheet<T, SS> {
+ N getNotes();
+ void setNotes(N notes);
- public boolean getFollowMasterBackground();
- public void setFollowMasterBackground(boolean follow);
+ boolean getFollowMasterBackground();
+ void setFollowMasterBackground(boolean follow);
- public boolean getFollowMasterColourScheme();
- public void setFollowMasterColourScheme(boolean follow);
+ boolean getFollowMasterColourScheme();
+ void setFollowMasterColourScheme(boolean follow);
- public boolean getFollowMasterObjects();
- public void setFollowMasterObjects(boolean follow);
+ boolean getFollowMasterObjects();
+ void setFollowMasterObjects(boolean follow);
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java Mon Apr 27 20:13:43 2015
@@ -19,13 +19,20 @@ package org.apache.poi.sl.usermodel;
import java.awt.Dimension;
import java.io.IOException;
+import java.util.List;
public interface SlideShow {
- Slide<? extends Shape, ? extends SlideShow> createSlide() throws IOException;
- MasterSheet<? extends Shape, ? extends SlideShow> createMasterSheet() throws IOException;
+ Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>> createSlide() throws IOException;
- Slide<? extends Shape, ? extends SlideShow>[] getSlides();
- MasterSheet<? extends Shape, ? extends SlideShow>[] getMasterSheet();
+ List<? extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> getSlides();
+
+ MasterSheet<? extends Shape, ? extends SlideShow> createMasterSheet() throws IOException;
+
+ /**
+ * Returns all slide masters.
+ * This doesn't include notes master and other arbitrary masters.
+ */
+ List<? extends MasterSheet<? extends Shape, ? extends SlideShow>> getSlideMasters();
Resources getResources();
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java Mon Apr 27 20:13:43 2015
@@ -22,7 +22,7 @@ import java.awt.Color;
public interface TextParagraph<T extends TextRun> extends Iterable<T> {
/**
- * Specified a list of text alignment types
+ * Specifies a list of text alignment types
*/
public enum TextAlign {
/**
@@ -50,6 +50,13 @@ public interface TextParagraph<T extends
THAI_DIST
}
+ /**
+ *
+ */
+ public enum FontAlign {
+ AUTO, TOP, CENTER, BASELINE, BOTTOM;
+ }
+
public interface BulletStyle {
String getBulletCharacter();
String getBulletFont();
@@ -87,16 +94,32 @@ public interface TextParagraph<T extends
double getLeftMargin();
/**
+ * @param leftMargin the left margin (in points)
+ */
+ void setLeftMargin(double leftMargin);
+
+
+ /**
* @return the right margin (in points) of the paragraph
*/
double getRightMargin();
/**
- * @return the indent applied (in points) to the first line of text in the paragraph.
+ * @param rightMargin the right margin (in points) of the paragraph
+ */
+ void setRightMargin(double rightMargin);
+
+ /**
+ * @return the indent (in points) applied to the first line of text in the paragraph.
*/
double getIndent();
/**
+ * @param indent the indent (in points) applied to the first line of text in the paragraph
+ */
+ void setIndent(double indent);
+
+ /**
* Returns the vertical line spacing that is to be used within a paragraph.
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
@@ -123,6 +146,15 @@ public interface TextParagraph<T extends
*/
TextAlign getTextAlign();
+
+ /**
+ * Returns the font alignment that is applied to the paragraph.
+ *
+ * If this attribute is omitted, then a value of auto (~ left) is implied.
+ * @return ??? alignment that is applied to the paragraph
+ */
+ FontAlign getFontAlign();
+
/**
* @return the bullet style of the paragraph, if {@code null} then no bullets are used
*/
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java Mon Apr 27 20:13:43 2015
@@ -31,7 +31,7 @@ public interface TextRun {
ALL
}
- public String getText();
+ public String getRawText();
public void setText(String text);
TextCap getTextCap();
@@ -42,7 +42,7 @@ public interface TextRun {
boolean isBold();
boolean isItalic();
- boolean isUnderline();
+ boolean isUnderlined();
boolean isStrikethrough();
boolean isSubscript();
boolean isSuperscript();
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java Mon Apr 27 20:13:43 2015
@@ -17,6 +17,8 @@
package org.apache.poi.sl.usermodel;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+
public interface TextShape<T extends TextParagraph<? extends TextRun>> extends SimpleShape, Iterable<T> {
@@ -105,6 +107,16 @@ public interface TextShape<T extends Tex
VerticalAlignment getVerticalAlignment();
/**
+ * Returns if the text is centered.
+ * If true and if the individual paragraph settings allow it,
+ * the whole text block will be displayed centered, i.e. its left and right
+ * margin will be maximized while still keeping the alignment of the paragraphs
+ *
+ * @return true, if the text anchor is horizontal centered
+ */
+ boolean isHorizontalCentered();
+
+ /**
* @return whether to wrap words within the bounding rectangle
*/
boolean getWordWrap();
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java Mon Apr 27 20:13:43 2015
@@ -25,7 +25,7 @@ import junit.framework.TestCase;
import java.io.*;
-import org.apache.poi.hslf.model.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.poifs.filesystem.*;
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java Mon Apr 27 20:13:43 2015
@@ -24,8 +24,8 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
public class HSLFTestDataSamples {
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java Mon Apr 27 20:13:43 2015
@@ -21,7 +21,7 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
-import org.apache.poi.hslf.model.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
/**
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java Mon Apr 27 20:13:43 2015
@@ -25,8 +25,8 @@ import java.io.FileNotFoundException;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java Mon Apr 27 20:13:43 2015
@@ -23,8 +23,8 @@ import junit.framework.TestCase;
import java.io.*;
import java.util.*;
-import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java Mon Apr 27 20:13:43 2015
@@ -20,8 +20,8 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
-import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
/**
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java Mon Apr 27 20:13:43 2015
@@ -23,9 +23,9 @@ import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
-import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.model.OLEShape;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.DirectoryNode;
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java Mon Apr 27 20:13:43 2015
@@ -17,6 +17,7 @@
package org.apache.poi.hslf.model;
+import org.apache.poi.hslf.usermodel.TestTextRun;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java Mon Apr 27 20:13:43 2015
@@ -33,7 +33,7 @@ import org.apache.poi.ddf.EscherProperti
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.sl.usermodel.ShapeType;
import org.junit.Test;
@@ -53,7 +53,7 @@ public final class TestBackground {
public void defaults() {
HSLFSlideShow ppt = new HSLFSlideShow();
- assertEquals(HSLFFill.FILL_SOLID, ppt.getSlidesMasters()[0].getBackground().getFill().getFillType());
+ assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType());
HSLFSlide slide = ppt.createSlide();
assertTrue(slide.getFollowMasterBackground());
@@ -72,26 +72,26 @@ public final class TestBackground {
HSLFFill fill;
HSLFShape shape;
- HSLFSlide[] slide = ppt.getSlides();
+ List<HSLFSlide> slide = ppt.getSlides();
- fill = slide[0].getBackground().getFill();
+ fill = slide.get(0).getBackground().getFill();
assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
- shape = slide[0].getShapes()[0];
+ shape = slide.get(0).getShapes().get(0);
assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
- fill = slide[1].getBackground().getFill();
+ fill = slide.get(1).getBackground().getFill();
assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
- shape = slide[1].getShapes()[0];
+ shape = slide.get(1).getShapes().get(0);
assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
- fill = slide[2].getBackground().getFill();
+ fill = slide.get(2).getBackground().getFill();
assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
- shape = slide[2].getShapes()[0];
+ shape = slide.get(2).getShapes().get(0);
assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
- fill = slide[3].getBackground().getFill();
+ fill = slide.get(3).getBackground().getFill();
assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
- shape = slide[3].getShapes()[0];
+ shape = slide.get(3).getShapes().get(0);
assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
}
@@ -174,29 +174,29 @@ public final class TestBackground {
out.close();
ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
- HSLFSlide[] slides = ppt.getSlides();
+ List<HSLFSlide> slides = ppt.getSlides();
- fill = slides[0].getBackground().getFill();
+ fill = slides.get(0).getBackground().getFill();
assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
- assertEquals(3, getFillPictureRefCount(slides[0].getBackground(), fill));
- shape = slides[0].getShapes()[0];
+ assertEquals(3, getFillPictureRefCount(slides.get(0).getBackground(), fill));
+ shape = slides.get(0).getShapes().get(0);
assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
- fill = slides[1].getBackground().getFill();
+ fill = slides.get(1).getBackground().getFill();
assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
- shape = slides[1].getShapes()[0];
+ shape = slides.get(1).getShapes().get(0);
assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
- fill = slides[2].getBackground().getFill();
+ fill = slides.get(2).getBackground().getFill();
assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
- assertEquals(3, getFillPictureRefCount(slides[2].getBackground(), fill));
- shape = slides[2].getShapes()[0];
+ assertEquals(3, getFillPictureRefCount(slides.get(2).getBackground(), fill));
+ shape = slides.get(2).getShapes().get(0);
assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
assertEquals(1, getFillPictureRefCount(shape, fill));
- fill = slides[3].getBackground().getFill();
+ fill = slides.get(3).getBackground().getFill();
assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
- shape = slides[3].getShapes()[0];
+ shape = slides.get(3).getShapes().get(0);
assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
}
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java Mon Apr 27 20:13:43 2015
@@ -17,12 +17,13 @@
package org.apache.poi.hslf.model;
-import java.awt.geom.Area;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.awt.geom.*;
+
+import org.apache.poi.hslf.usermodel.HSLFFreeformShape;
+import org.junit.Test;
/**
* Test Freeform object.
@@ -32,8 +33,9 @@ import junit.framework.TestCase;
*
* @author Yegor Kozlov
*/
-public final class TestFreeform extends TestCase {
+public final class TestFreeform {
+ @Test
public void testClosedPath() {
GeneralPath path1 = new GeneralPath();
@@ -50,6 +52,7 @@ public final class TestFreeform extends
assertTrue(new Area(path1).equals(new Area(path2)));
}
+ @Test
public void testLine() {
GeneralPath path1 = new GeneralPath(new Line2D.Double(100, 100, 200, 100));
@@ -61,6 +64,7 @@ public final class TestFreeform extends
assertTrue(new Area(path1).equals(new Area(path2)));
}
+ @Test
public void testRectangle() {
GeneralPath path1 = new GeneralPath(new Rectangle2D.Double(100, 100, 200, 50));
@@ -76,6 +80,7 @@ public final class TestFreeform extends
* Avoid NPE in Freeform.getOutline() if either GEOMETRY__VERTICES or
* GEOMETRY__SEGMENTINFO is missing, see Bugzilla 54188
*/
+ @Test
public void test54188() {
HSLFFreeformShape p = new HSLFFreeformShape();
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java Mon Apr 27 20:13:43 2015
@@ -17,22 +17,27 @@
package org.apache.poi.hslf.model;
-import java.io.*;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
-import org.apache.poi.POIDataSamples;
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.List;
-import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.usermodel.HSLFSlide;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.junit.Test;
/**
* Test {@link org.apache.poi.hslf.model.HeadersFooters} object
*/
-public final class TestHeadersFooters extends TestCase
+public final class TestHeadersFooters
{
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
- public void testRead() throws Exception
- {
+ @Test
+ public void testRead() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("headers_footers.ppt"));
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
@@ -53,9 +58,9 @@ public final class TestHeadersFooters ex
assertTrue(notesHdd.isUserDateVisible());
assertNull(notesHdd.getDateTimeText());
- HSLFSlide[] slide = ppt.getSlides();
+ List<HSLFSlide> slide = ppt.getSlides();
//the first slide uses presentation-scope headers / footers
- HeadersFooters hd1 = slide[0].getHeadersFooters();
+ HeadersFooters hd1 = slide.get(0).getHeadersFooters();
assertEquals(slideHdd.isFooterVisible(), hd1.isFooterVisible());
assertEquals(slideHdd.getFooterText(), hd1.getFooterText());
assertEquals(slideHdd.isSlideNumberVisible(), hd1.isSlideNumberVisible());
@@ -65,7 +70,7 @@ public final class TestHeadersFooters ex
assertEquals(slideHdd.getDateTimeText(), hd1.getDateTimeText());
//the first slide uses per-slide headers / footers
- HeadersFooters hd2 = slide[1].getHeadersFooters();
+ HeadersFooters hd2 = slide.get(1).getHeadersFooters();
assertEquals(true, hd2.isFooterVisible());
assertEquals("per-slide footer", hd2.getFooterText());
assertEquals(true, hd2.isUserDateVisible());
@@ -75,8 +80,8 @@ public final class TestHeadersFooters ex
/**
* If Headers / Footers are not set, all the getters should return <code>false</code> or <code>null</code>
*/
- public void testReadNoHeadersFooters() throws Exception
- {
+ @Test
+ public void testReadNoHeadersFooters() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
@@ -97,9 +102,8 @@ public final class TestHeadersFooters ex
assertFalse(notesHdd.isUserDateVisible());
assertNull(notesHdd.getDateTimeText());
- HSLFSlide[] slide = ppt.getSlides();
- for(int i=0 ; i < slide.length; i++){
- HeadersFooters hd1 = slide[i].getHeadersFooters();
+ for(HSLFSlide s : ppt.getSlides()) {
+ HeadersFooters hd1 = s.getHeadersFooters();
assertFalse(hd1.isFooterVisible());
assertNull(hd1.getFooterText());
assertFalse(hd1.isHeaderVisible());
@@ -112,8 +116,8 @@ public final class TestHeadersFooters ex
/**
* Test extraction of headers / footers from PPTs saved in Office 2007
*/
- public void testRead2007() throws Exception
- {
+ @Test
+ public void testRead2007() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("headers_footers_2007.ppt"));
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
@@ -137,9 +141,9 @@ public final class TestHeadersFooters ex
//assertEquals("08/12/08", notesHdd.getDateTimeText());
//per-slide headers / footers
- HSLFSlide[] slide = ppt.getSlides();
+ List<HSLFSlide> slide = ppt.getSlides();
//the first slide uses presentation-scope headers / footers
- HeadersFooters hd1 = slide[0].getHeadersFooters();
+ HeadersFooters hd1 = slide.get(0).getHeadersFooters();
assertTrue(hd1.isFooterVisible());
assertEquals("THE FOOTER TEXT", hd1.getFooterText());
assertTrue(hd1.isSlideNumberVisible());
@@ -150,7 +154,7 @@ public final class TestHeadersFooters ex
assertEquals("Wednesday, August 06, 2008", hd1.getDateTimeText());
//the second slide uses custom per-slide headers / footers
- HeadersFooters hd2 = slide[1].getHeadersFooters();
+ HeadersFooters hd2 = slide.get(1).getHeadersFooters();
assertTrue(hd2.isFooterVisible());
assertEquals("THE FOOTER TEXT FOR SLIDE 2", hd2.getFooterText());
assertTrue(hd2.isSlideNumberVisible());
@@ -161,7 +165,7 @@ public final class TestHeadersFooters ex
assertEquals("August 06, 2008", hd2.getDateTimeText());
//the third slide uses per-slide headers / footers
- HeadersFooters hd3 = slide[2].getHeadersFooters();
+ HeadersFooters hd3 = slide.get(2).getHeadersFooters();
assertTrue(hd3.isFooterVisible());
assertEquals("THE FOOTER TEXT", hd3.getFooterText());
assertTrue(hd3.isSlideNumberVisible());
@@ -172,8 +176,8 @@ public final class TestHeadersFooters ex
assertEquals("Wednesday, August 06, 2008", hd3.getDateTimeText());
}
- public void testCreateSlideFooters() throws Exception
- {
+ @Test
+ public void testCreateSlideFooters() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow();
HeadersFooters hdd = ppt.getSlideHeadersFooters();
hdd.setFootersText("My slide footer");
@@ -190,8 +194,8 @@ public final class TestHeadersFooters ex
assertEquals("My slide footer", hdd2.getFooterText());
}
- public void testCreateNotesFooters() throws Exception
- {
+ @Test
+ public void testCreateNotesFooters() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow();
HeadersFooters hdd = ppt.getNotesHeadersFooters();
hdd.setFootersText("My notes footer");
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java Mon Apr 27 20:13:43 2015
@@ -17,70 +17,68 @@
package org.apache.poi.hslf.model;
-import junit.framework.TestCase;
+import static org.apache.poi.hslf.usermodel.HSLFTextParagraph.getRawText;
+import static org.apache.poi.hslf.usermodel.HSLFTextParagraph.toExternalString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.usermodel.*;
+import org.junit.Test;
/**
* Test Hyperlink.
*
* @author Yegor Kozlov
*/
-public final class TestHyperlink extends TestCase {
+public final class TestHyperlink {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+ @Test
public void testTextRunHyperlinks() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("WithLinks.ppt"));
- HSLFTextParagraph[] run;
- HSLFSlide slide;
- slide = ppt.getSlides()[0];
- run = slide.getTextRuns();
- for (int i = 0; i < run.length; i++) {
- String text = run[i].getText();
- if (text.equals(
- "This page has two links:\n" +
- "http://jakarta.apache.org/poi/\n" +
- "\n" +
- "http://slashdot.org/\n" +
- "\n" +
- "In addition, its notes has one link")){
-
- Hyperlink[] links = run[i].getHyperlinks();
- assertNotNull(links);
- assertEquals(2, links.length);
-
- assertEquals("http://jakarta.apache.org/poi/", links[0].getTitle());
- assertEquals("http://jakarta.apache.org/poi/", links[0].getAddress());
- assertEquals("http://jakarta.apache.org/poi/", text.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
-
- assertEquals("http://slashdot.org/", links[1].getTitle());
- assertEquals("http://slashdot.org/", links[1].getAddress());
- assertEquals("http://slashdot.org/", text.substring(links[1].getStartIndex(), links[1].getEndIndex()-1));
-
- }
- }
-
- slide = ppt.getSlides()[1];
- run = slide.getTextRuns();
- for (int i = 0; i < run.length; i++) {
- String text = run[i].getText();
- if (text.equals(
- "I have the one link:\n" +
- "Jakarta HSSF")){
-
- Hyperlink[] links = run[i].getHyperlinks();
- assertNotNull(links);
- assertEquals(1, links.length);
-
- assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getTitle());
- assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getAddress());
- assertEquals("Jakarta HSSF", text.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
-
- }
- }
-
+ HSLFSlide slide = ppt.getSlides().get(0);
+ List<HSLFTextParagraph> para = slide.getTextParagraphs().get(1);
+
+ String rawText = toExternalString(getRawText(para), para.get(0).getRunType());
+ String expected =
+ "This page has two links:\n"+
+ "http://jakarta.apache.org/poi/\n"+
+ "\n"+
+ "http://slashdot.org/\n"+
+ "\n"+
+ "In addition, its notes has one link";
+ assertEquals(expected, rawText);
+
+ HSLFHyperlink[] links = HSLFHyperlink.find(para.get(1));
+ assertNotNull(links);
+ assertEquals(2, links.length);
+
+ assertEquals("http://jakarta.apache.org/poi/", links[0].getTitle());
+ assertEquals("http://jakarta.apache.org/poi/", links[0].getAddress());
+ assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
+
+ assertEquals("http://slashdot.org/", links[1].getTitle());
+ assertEquals("http://slashdot.org/", links[1].getAddress());
+ assertEquals("http://slashdot.org/", rawText.substring(links[1].getStartIndex(), links[1].getEndIndex()-1));
+
+ slide = ppt.getSlides().get(1);
+ para = slide.getTextParagraphs().get(1);
+ rawText = toExternalString(getRawText(para), para.get(0).getRunType());
+ expected =
+ "I have the one link:\n" +
+ "Jakarta HSSF";
+ assertEquals(expected, rawText);
+
+ links = HSLFHyperlink.find(para.get(1));
+ assertNotNull(links);
+ assertEquals(1, links.length);
+
+ assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getTitle());
+ assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getAddress());
+ assertEquals("Jakarta HSSF", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
}
-
}
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java Mon Apr 27 20:13:43 2015
@@ -24,6 +24,7 @@ import junit.framework.TestCase;
import org.apache.poi.hslf.blip.BitmapPainter;
import org.apache.poi.hslf.blip.ImagePainter;
import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.usermodel.HSLFPictureShape;
/**
* Test Picture shape.
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java Mon Apr 27 20:13:43 2015
@@ -19,17 +19,20 @@ package org.apache.poi.hslf.model;
import java.awt.Color;
-import junit.framework.TestCase;
-
+import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
+import org.junit.Test;
/**
* Test Line shape.
*
* @author Yegor Kozlov
*/
-public final class TestLine extends TestCase {
+public final class TestLine {
+ @Test
public void testCreateLines() {
HSLFSlideShow ppt = new HSLFSlideShow();
@@ -44,31 +47,31 @@ public final class TestLine extends Test
*/
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 200, 300, 0));
- line.setLineStyle(Line.LINE_SIMPLE);
+ line.setLineCompound(LineCompound.SINGLE);
line.setLineColor(Color.blue);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 230, 300, 0));
- line.setLineStyle(Line.LINE_DOUBLE);
+ line.setLineCompound(LineCompound.DOUBLE);
line.setLineWidth(3.5);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 260, 300, 0));
- line.setLineStyle(Line.LINE_TRIPLE);
+ line.setLineCompound(LineCompound.TRIPLE);
line.setLineWidth(6);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 290, 300, 0));
- line.setLineStyle(Line.LINE_THICKTHIN);
+ line.setLineCompound(LineCompound.THICK_THIN);
line.setLineWidth(4.5);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 320, 300, 0));
- line.setLineStyle(Line.LINE_THINTHICK);
+ line.setLineCompound(LineCompound.THIN_THICK);
line.setLineWidth(5.5);
slide.addShape(line);
@@ -77,27 +80,27 @@ public final class TestLine extends Test
*/
line = new Line();
line.setAnchor(new java.awt.Rectangle(450, 200, 300, 0));
- line.setLineDashing(Line.PEN_SOLID);
+ line.setLineDashing(LineDash.SOLID);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(450, 230, 300, 0));
- line.setLineDashing(Line.PEN_PS_DASH);
+ line.setLineDashing(LineDash.DASH);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(450, 260, 300, 0));
- line.setLineDashing(Line.PEN_DOT);
+ line.setLineDashing(LineDash.DOT);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(450, 290, 300, 0));
- line.setLineDashing(Line.PEN_DOTGEL);
+ line.setLineDashing(LineDash.DASH_DOT);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(450, 320, 300, 0));
- line.setLineDashing(Line.PEN_LONGDASHDOTDOTGEL);
+ line.setLineDashing(LineDash.LG_DASH_DOT_DOT);
slide.addShape(line);
/**
@@ -105,22 +108,22 @@ public final class TestLine extends Test
*/
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 400, 300, 0));
- line.setLineDashing(Line.PEN_DASHDOT);
- line.setLineStyle(Line.LINE_TRIPLE);
+ line.setLineDashing(LineDash.DASH_DOT);
+ line.setLineCompound(LineCompound.TRIPLE);
line.setLineWidth(5.0);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 430, 300, 0));
- line.setLineDashing(Line.PEN_DASH);
- line.setLineStyle(Line.LINE_THICKTHIN);
+ line.setLineDashing(LineDash.DASH);
+ line.setLineCompound(LineCompound.THICK_THIN);
line.setLineWidth(4.0);
slide.addShape(line);
line = new Line();
line.setAnchor(new java.awt.Rectangle(75, 460, 300, 0));
- line.setLineDashing(Line.PEN_DOT);
- line.setLineStyle(Line.LINE_DOUBLE);
+ line.setLineDashing(LineDash.DOT);
+ line.setLineCompound(LineCompound.DOUBLE);
line.setLineWidth(8.0);
slide.addShape(line);
}
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java?rev=1676365&r1=1676364&r2=1676365&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java Mon Apr 27 20:13:43 2015
@@ -17,24 +17,26 @@
package org.apache.poi.hslf.model;
+import static org.junit.Assert.*;
+
import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
-
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.usermodel.*;
+import org.junit.Test;
/**
* Test <code>MovieShape</code> object.
*
* @author Yegor Kozlov
*/
-public final class TestMovieShape extends TestCase {
+public final class TestMovieShape {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+ @Test
public void testCreate() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow();
@@ -57,8 +59,8 @@ public final class TestMovieShape extend
ppt.write(out);
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
- slide = ppt.getSlides()[0];
- shape = (MovieShape)slide.getShapes()[0];
+ slide = ppt.getSlides().get(0);
+ shape = (MovieShape)slide.getShapes().get(0);
assertEquals(path, shape.getPath());
assertFalse(shape.isAutoPlay());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org