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/03/20 00:44:25 UTC
svn commit: r1667902 [3/8] - 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/
examples/src/org/apache/poi/xssf/usermodel/examples...
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFPictureShape.java (from r1664935, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFPictureShape.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFPictureShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java&r1=1664935&r2=1667902&rev=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFPictureShape.java Thu Mar 19 23:44:23 2015
@@ -37,8 +37,8 @@ import org.apache.poi.ddf.EscherSimplePr
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hslf.blip.Bitmap;
import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.usermodel.PictureData;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.POILogger;
@@ -51,7 +51,7 @@ import org.apache.poi.util.Units;
*
* @author Yegor Kozlov
*/
-public class Picture extends SimpleShape {
+public class HSLFPictureShape extends HSLFSimpleShape {
/**
* Windows Enhanced Metafile (EMF)
@@ -88,7 +88,7 @@ public class Picture extends SimpleShape
*
* @param idx the index of the picture
*/
- public Picture(int idx){
+ public HSLFPictureShape(int idx){
this(idx, null);
}
@@ -98,7 +98,7 @@ public class Picture extends SimpleShape
* @param idx the index of the picture
* @param parent the parent shape
*/
- public Picture(int idx, ShapeContainer<HSLFShape> parent) {
+ public HSLFPictureShape(int idx, ShapeContainer<HSLFShape> parent) {
super(null, parent);
_escherContainer = createSpContainer(idx, parent instanceof HSLFGroupShape);
}
@@ -110,7 +110,7 @@ public class Picture extends SimpleShape
* this picture in the <code>Slide</code>
* @param parent the parent shape of this picture
*/
- protected Picture(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
super(escherRecord, parent);
}
@@ -156,7 +156,7 @@ public class Picture extends SimpleShape
* for other types sets the default size of 200x200 pixels.
*/
public void setDefaultSize(){
- PictureData pict = getPictureData();
+ HSLFPictureData pict = getPictureData();
if (pict instanceof Bitmap){
BufferedImage img = null;
try {
@@ -183,9 +183,9 @@ public class Picture extends SimpleShape
*
* @return the picture data for this picture.
*/
- public PictureData getPictureData(){
- SlideShow ppt = getSheet().getSlideShow();
- PictureData[] pict = ppt.getPictureData();
+ public HSLFPictureData getPictureData(){
+ HSLFSlideShow ppt = getSheet().getSlideShow();
+ HSLFPictureData[] pict = ppt.getPictureData();
EscherBSERecord bse = getEscherBSERecord();
if (bse == null){
@@ -202,7 +202,7 @@ public class Picture extends SimpleShape
}
protected EscherBSERecord getEscherBSERecord(){
- SlideShow ppt = getSheet().getSlideShow();
+ HSLFSlideShow ppt = getSheet().getSlideShow();
Document doc = ppt.getDocumentRecord();
EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
@@ -247,7 +247,7 @@ public class Picture extends SimpleShape
/**
* By default set the orininal image size
*/
- protected void afterInsert(Sheet sh){
+ protected void afterInsert(HSLFSheet sh){
super.afterInsert(sh);
EscherBSERecord bse = getEscherBSERecord();
@@ -263,7 +263,7 @@ public class Picture extends SimpleShape
AffineTransform at = graphics.getTransform();
ShapePainter.paint(this, graphics);
- PictureData data = getPictureData();
+ HSLFPictureData data = getPictureData();
if(data != null) data.draw(graphics, this);
graphics.setTransform(at);
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFShape.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFShape.java?rev=1667902&r1=1667901&r2=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFShape.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFShape.java Thu Mar 19 23:44:23 2015
@@ -17,17 +17,15 @@
package org.apache.poi.hslf.model;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
+
import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.ColorSchemeAtom;
-import org.apache.poi.sl.usermodel.ShapeContainer;
-import org.apache.poi.sl.usermodel.ShapeType;
-import org.apache.poi.util.POILogger;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.Units;
-
-import java.util.*;
-import java.awt.*;
-import java.awt.geom.Rectangle2D;
+import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.util.*;
/**
* <p>
@@ -45,7 +43,7 @@ import java.awt.geom.Rectangle2D;
*
* @author Yegor Kozlov
*/
-public abstract class HSLFShape implements org.apache.poi.sl.usermodel.Shape<HSLFShape> {
+public abstract class HSLFShape implements Shape {
// For logging
protected POILogger logger = POILogFactory.getLogger(this.getClass());
@@ -90,12 +88,12 @@ public abstract class HSLFShape implemen
/**
* The <code>Sheet</code> this shape belongs to
*/
- protected Sheet _sheet;
+ protected HSLFSheet _sheet;
/**
* Fill
*/
- protected Fill _fill;
+ protected HSLFFill _fill;
/**
* Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
@@ -336,7 +334,7 @@ public abstract class HSLFShape implemen
*
* @param sh - owning shape
*/
- protected void afterInsert(Sheet sh){
+ protected void afterInsert(HSLFSheet sh){
if(_fill != null) {
_fill.afterInsert(sh);
}
@@ -345,7 +343,7 @@ public abstract class HSLFShape implemen
/**
* @return the <code>SlideShow</code> this shape belongs to
*/
- public Sheet getSheet(){
+ public HSLFSheet getSheet(){
return _sheet;
}
@@ -354,7 +352,7 @@ public abstract class HSLFShape implemen
*
* @param sheet owner of this shape
*/
- public void setSheet(Sheet sheet){
+ public void setSheet(HSLFSheet sheet){
_sheet = sheet;
}
@@ -375,7 +373,7 @@ public abstract class HSLFShape implemen
int rgb[] = ecr.getRGB();
- Sheet sheet = getSheet();
+ HSLFSheet sheet = getSheet();
if (fSchemeIndex && sheet != null) {
//red is the index to the color scheme
ColorSchemeAtom ca = sheet.getColorScheme();
@@ -394,13 +392,18 @@ public abstract class HSLFShape implemen
//TODO
}
+ double alpha = getAlpha(opacityProperty);
+ return new Color(rgb[0], rgb[1], rgb[2], (int)(alpha*255.0));
+ }
+
+ double getAlpha(short opacityProperty) {
+ EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty op = getEscherProperty(opt, opacityProperty);
int defaultOpacity = 0x00010000;
int opacity = (op == null) ? defaultOpacity : op.getPropertyValue();
- double alpha = Units.fixedPointToDouble(opacity)*255.0;
- return new Color(rgb[0], rgb[1], rgb[2], (int)alpha);
+ return Units.fixedPointToDouble(opacity);
}
-
+
Color toRGB(int val){
int a = (val >> 24) & 0xFF;
int b = (val >> 16) & 0xFF;
@@ -446,11 +449,16 @@ public abstract class HSLFShape implemen
*
* @return fill properties of this shape
*/
- public Fill getFill(){
- if(_fill == null) _fill = new Fill(this);
+ public HSLFFill getFill(){
+ if(_fill == null) {
+ _fill = new HSLFFill(this);
+ }
return _fill;
}
+ public FillStyle getFillStyle() {
+ return getFill().getFillStyle();
+ }
/**
* Returns the hyperlink assigned to this shape
@@ -479,46 +487,39 @@ public abstract class HSLFShape implemen
return getEscherChild(EscherOptRecord.RECORD_ID);
}
- @Override
public boolean getFlipHorizontal(){
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
return (spRecord.getFlags()& EscherSpRecord.FLAG_FLIPHORIZ) != 0;
}
- @Override
public void setFlipHorizontal(boolean flip) {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flag = spRecord.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ;
spRecord.setFlags(flag);
}
- @Override
public boolean getFlipVertical(){
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
return (spRecord.getFlags()& EscherSpRecord.FLAG_FLIPVERT) != 0;
}
- @Override
public void setFlipVertical(boolean flip) {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flag = spRecord.getFlags() | EscherSpRecord.FLAG_FLIPVERT;
spRecord.setFlags(flag);
}
- @Override
public double getRotation(){
int rot = getEscherProperty(EscherProperties.TRANSFORM__ROTATION);
double angle = Units.fixedPointToDouble(rot) % 360.0;
return angle;
}
- @Override
public void setRotation(double theta){
int rot = Units.doubleToFixedPoint(theta % 360.0);
setEscherProperty(EscherProperties.TRANSFORM__ROTATION, rot);
}
- @Override
public boolean isPlaceholder() {
return false;
}
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSheet.java (from r1664935, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSheet.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSheet.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java&r1=1664935&r2=1667902&rev=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSheet.java Thu Mar 19 23:44:23 2015
@@ -18,34 +18,12 @@
package org.apache.poi.hslf.model;
import java.awt.Graphics2D;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherDgRecord;
-import org.apache.poi.ddf.EscherDggRecord;
-import org.apache.poi.ddf.EscherRecord;
-import org.apache.poi.hslf.record.CString;
-import org.apache.poi.hslf.record.ColorSchemeAtom;
-import org.apache.poi.hslf.record.EscherTextboxWrapper;
-import org.apache.poi.hslf.record.MasterTextPropAtom;
-import org.apache.poi.hslf.record.OEPlaceholderAtom;
-import org.apache.poi.hslf.record.PPDrawing;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordContainer;
-import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
-import org.apache.poi.hslf.record.SheetContainer;
-import org.apache.poi.hslf.record.StyleTextProp9Atom;
-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.TextRulerAtom;
-import org.apache.poi.hslf.record.TextSpecInfoAtom;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.sl.usermodel.ShapeContainer;
+import java.util.*;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -57,18 +35,18 @@ import org.apache.poi.util.POILogger;
* @author Yegor Kozlov
*/
-public abstract class Sheet implements ShapeContainer<HSLFShape> {
- private static POILogger logger = POILogFactory.getLogger(Sheet.class);
+public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> {
+ private static POILogger logger = POILogFactory.getLogger(HSLFSheet.class);
/**
* The <code>SlideShow</code> we belong to
*/
- private SlideShow _slideShow;
+ private HSLFSlideShow _slideShow;
/**
* Sheet background
*/
- private Background _background;
+ private HSLFBackground _background;
/**
* Record container that holds sheet data.
@@ -80,7 +58,7 @@ public abstract class Sheet implements S
private int _sheetNo;
- public Sheet(SheetContainer container, int sheetNo) {
+ public HSLFSheet(SheetContainer container, int sheetNo) {
_container = container;
_sheetNo = sheetNo;
}
@@ -88,7 +66,7 @@ public abstract class Sheet implements S
/**
* Returns an array of all the TextRuns in the sheet.
*/
- public abstract TextRun[] getTextRuns();
+ public abstract HSLFTextParagraph[] getTextRuns();
/**
* Returns the (internal, RefID based) sheet number, as used
@@ -116,7 +94,7 @@ public abstract class Sheet implements S
/**
* Fetch the SlideShow we're attached to
*/
- public SlideShow getSlideShow() {
+ public HSLFSlideShow getSlideShow() {
return _slideShow;
}
@@ -131,13 +109,12 @@ public abstract class Sheet implements S
* Set the SlideShow we're attached to.
* Also passes it on to our child RichTextRuns
*/
- public void setSlideShow(SlideShow ss) {
+ public void setSlideShow(HSLFSlideShow ss) {
_slideShow = ss;
- TextRun[] trs = getTextRuns();
- if (trs != null) {
- for (int i = 0; i < trs.length; i++) {
- trs[i].supplySlideShow(_slideShow);
- }
+ HSLFTextParagraph[] trs = getTextRuns();
+ if (trs == null) return;
+ for (HSLFTextParagraph tp : trs) {
+ tp.supplySheet(this);
}
}
@@ -145,8 +122,8 @@ public abstract class Sheet implements S
/**
* For a given PPDrawing, grab all the TextRuns
*/
- public static TextRun[] findTextRuns(PPDrawing ppdrawing) {
- final List<TextRun> runsV = new ArrayList<TextRun>();
+ public static HSLFTextParagraph[] findTextRuns(PPDrawing ppdrawing) {
+ final List<HSLFTextParagraph> runsV = new ArrayList<HSLFTextParagraph>();
final EscherTextboxWrapper[] wrappers = ppdrawing.getTextboxWrappers();
for (int i = 0; i < wrappers.length; i++) {
int s1 = runsV.size();
@@ -156,11 +133,11 @@ public abstract class Sheet implements S
findTextRuns(wrappers[i], runsV);
int s2 = runsV.size();
if (s2 != s1){
- TextRun t = runsV.get(runsV.size()-1);
+ HSLFTextParagraph t = runsV.get(runsV.size()-1);
t.setShapeId(wrappers[i].getShapeId());
}
}
- return runsV.toArray(new TextRun[runsV.size()]);
+ return runsV.toArray(new HSLFTextParagraph[runsV.size()]);
}
/**
* Scans through the supplied record array, looking for
@@ -170,7 +147,7 @@ public abstract class Sheet implements S
* @param records the records to build from
* @param found vector to add any found to
*/
- protected static void findTextRuns(final Record[] records, final List<TextRun> found) {
+ protected static void findTextParagraphs(final Record[] records, final List<HSLFTextParagraph> found) {
findTextRuns(records, found, null);
}
/**
@@ -181,7 +158,7 @@ public abstract class Sheet implements S
* @param wrapper an EscherTextboxWrapper
* @param found vector to add any found to
*/
- protected static void findTextRuns(final EscherTextboxWrapper wrapper, final List<TextRun> found) {
+ protected static void findTextRuns(final EscherTextboxWrapper wrapper, final List<HSLFTextParagraph> found) {
findTextRuns(wrapper.getChildRecords(), found, wrapper.getStyleTextProp9Atom());
}
/**
@@ -193,12 +170,12 @@ public abstract class Sheet implements S
* @param found vector to add any found to
* @param styleTextProp9Atom a StyleTextProp9Atom with numbered lists info
*/
- protected static void findTextRuns(final Record[] records, final List<TextRun> found, final StyleTextProp9Atom styleTextProp9Atom) {
+ protected static void findTextRuns(final Record[] records, final List<HSLFTextParagraph> found, final StyleTextProp9Atom styleTextProp9Atom) {
for (int i = 0, slwtIndex=0; i < (records.length - 1); i++) {
if (records[i] instanceof TextHeaderAtom) {
TextHeaderAtom tha = (TextHeaderAtom) records[i];
StyleTextPropAtom stpa = null;
- TextRun trun = null;
+ HSLFTextParagraph trun = null;
Record next = null;
Record subs = null;
@@ -231,10 +208,10 @@ public abstract class Sheet implements S
// Now, check if the next record is one to record
if (next instanceof TextCharsAtom) {
TextCharsAtom tca = (TextCharsAtom)next;
- trun = new TextRun(tha, tca, stpa);
+ trun = new HSLFTextParagraph(tha, tca, stpa);
} else if (next instanceof TextBytesAtom) {
TextBytesAtom tba = (TextBytesAtom)next;
- trun = new TextRun(tha, tba, stpa);
+ trun = new HSLFTextParagraph(tha, tba, stpa);
} else if (next instanceof StyleTextPropAtom) {
stpa = (StyleTextPropAtom)next;
} else if (next instanceof TextHeaderAtom) {
@@ -372,7 +349,7 @@ public abstract class Sheet implements S
/**
* Return the master sheet .
*/
- public abstract MasterSheet getMasterSheet();
+ public abstract HSLFMasterSheet getMasterSheet();
/**
* Color scheme for this sheet.
@@ -386,7 +363,7 @@ public abstract class Sheet implements S
*
* @return the background shape for this sheet.
*/
- public Background getBackground() {
+ public HSLFBackground getBackground() {
if (_background == null) {
PPDrawing ppdrawing = getPPDrawing();
@@ -400,7 +377,7 @@ public abstract class Sheet implements S
break;
}
}
- _background = new Background(spContainer, null);
+ _background = new HSLFBackground(spContainer, null);
_background.setSheet(this);
}
return _background;
@@ -416,7 +393,7 @@ public abstract class Sheet implements S
*
* @param shape
*/
- protected void onAddTextShape(TextShape shape) {
+ protected void onAddTextShape(HSLFTextShape shape) {
}
@@ -426,12 +403,12 @@ public abstract class Sheet implements S
* @param type type of text, See {@link org.apache.poi.hslf.record.TextHeaderAtom}
* @return <code>TextShape</code> or <code>null</code>
*/
- public TextShape getPlaceholderByTextType(int type){
+ public HSLFTextShape getPlaceholderByTextType(int type){
HSLFShape[] shape = getShapes();
for (int i = 0; i < shape.length; i++) {
- if(shape[i] instanceof TextShape){
- TextShape tx = (TextShape)shape[i];
- TextRun run = tx.getTextRun();
+ if(shape[i] instanceof HSLFTextShape){
+ HSLFTextShape tx = (HSLFTextShape)shape[i];
+ HSLFTextParagraph run = tx.getTextParagraph();
if(run != null && run.getRunType() == type){
return tx;
}
@@ -446,11 +423,11 @@ public abstract class Sheet implements S
* @param type type of placeholder to search. See {@link org.apache.poi.hslf.record.OEPlaceholderAtom}
* @return <code>TextShape</code> or <code>null</code>
*/
- public TextShape getPlaceholder(int type){
+ public HSLFTextShape getPlaceholder(int type){
HSLFShape[] shape = getShapes();
for (int i = 0; i < shape.length; i++) {
- if(shape[i] instanceof TextShape){
- TextShape tx = (TextShape)shape[i];
+ if(shape[i] instanceof HSLFTextShape){
+ HSLFTextShape tx = (HSLFTextShape)shape[i];
int placeholderId = 0;
OEPlaceholderAtom oep = tx.getPlaceholderAtom();
if(oep != null) {
@@ -540,4 +517,14 @@ public abstract class Sheet implements S
return shapeList;
}
+ /**
+ * @return whether shapes on the master sheet should be shown. By default master graphics is turned off.
+ * Sheets that support the notion of master (slide, slideLayout) should override it and
+ * check this setting
+ */
+ public boolean getFollowMasterGraphics() {
+ return false;
+ }
+
+
}
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSimpleShape.java (from r1664935, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSimpleShape.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSimpleShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java&r1=1664935&r2=1667902&rev=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSimpleShape.java Thu Mar 19 23:44:23 2015
@@ -38,8 +38,10 @@ import org.apache.poi.hslf.exceptions.HS
import org.apache.poi.hslf.record.InteractiveInfo;
import org.apache.poi.hslf.record.InteractiveInfoAtom;
import org.apache.poi.hslf.record.Record;
-import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.sl.usermodel.StrokeStyle.*;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.Units;
/**
* An abstract simple (non-group) shape.
@@ -47,7 +49,7 @@ import org.apache.poi.util.LittleEndian;
*
* @author Yegor Kozlov
*/
-public abstract class SimpleShape extends HSLFShape {
+public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
public final static double DEFAULT_LINE_WIDTH = 0.75;
@@ -63,7 +65,7 @@ public abstract class SimpleShape extend
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected SimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
super(escherRecord, parent);
}
@@ -112,7 +114,7 @@ public abstract class SimpleShape extend
public double getLineWidth(){
EscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
- double width = prop == null ? DEFAULT_LINE_WIDTH : (double)prop.getPropertyValue()/EMU_PER_POINT;
+ double width = (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
return width;
}
@@ -122,7 +124,7 @@ public abstract class SimpleShape extend
*/
public void setLineWidth(double width){
EscherOptRecord opt = getEscherOptRecord();
- setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, (int)(width*EMU_PER_POINT));
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, Units.toEMU(width));
}
/**
@@ -155,36 +157,45 @@ public abstract class SimpleShape extend
}
/**
- * Gets line dashing. One of the PEN_* constants defined in this class.
+ * Gets line dashing.
*
* @return dashing of the line.
*/
- public int getLineDashing(){
+ public LineDash getLineDashing(){
EscherOptRecord opt = getEscherOptRecord();
-
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
- return prop == null ? Line.PEN_SOLID : prop.getPropertyValue();
+ return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
}
/**
- * Sets line dashing. One of the PEN_* constants defined in this class.
+ * Sets line dashing.
*
* @param pen new style of the line.
*/
- public void setLineDashing(int pen){
+ public void setLineDashing(LineDash pen){
EscherOptRecord opt = getEscherOptRecord();
-
- setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == Line.PEN_SOLID ? -1 : pen);
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
}
/**
- * Sets line style. One of the constants defined in this class.
+ * Gets the line compound style
+ *
+ * @return the compound style of the line.
+ */
+ public LineCompound getLineCompound() {
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
+ return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
+ }
+
+ /**
+ * Sets the line compound style
*
- * @param style new style of the line.
+ * @param style new compound style of the line.
*/
- public void setLineStyle(int style){
+ public void setLineCompound(LineCompound style){
EscherOptRecord opt = getEscherOptRecord();
- setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == Line.LINE_SIMPLE ? -1 : style);
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
}
/**
@@ -192,10 +203,29 @@ public abstract class SimpleShape extend
*
* @return style of the line.
*/
- public int getStrokeStyle(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
- return prop == null ? Line.LINE_SIMPLE : prop.getPropertyValue();
+ public StrokeStyle getStrokeStyle(){
+ return new StrokeStyle() {
+ public PaintStyle getPaint() {
+ return null;
+ }
+
+ public LineCap getLineCap() {
+ return null;
+ }
+
+ public LineDash getLineDash() {
+ return null;
+ }
+
+ public LineCompound getLineCompound() {
+ return null;
+ }
+
+ public double getLineWidth() {
+ return 0;
+ }
+
+ };
}
/**
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlide.java (from r1664935, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlide.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlide.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java&r1=1664935&r2=1667902&rev=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlide.java Thu Mar 19 23:44:23 2015
@@ -37,7 +37,9 @@ import org.apache.poi.hslf.record.SlideA
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
import org.apache.poi.hslf.record.StyleTextProp9Atom;
import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.sl.usermodel.Slide;
/**
* This class represents a slide in a PowerPoint Document. It allows
@@ -48,11 +50,11 @@ import org.apache.poi.sl.usermodel.Shape
* @author Yegor Kozlov
*/
-public final class Slide extends Sheet {
+public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSlideShow> {
private int _slideNo;
private SlideAtomsSet _atomSet;
- private TextRun[] _runs;
- private Notes _notes; // usermodel needs to set this
+ private HSLFTextParagraph[] _runs;
+ private HSLFNotes _notes; // usermodel needs to set this
/**
* Constructs a Slide from the Slide record, and the SlideAtomsSet
@@ -63,7 +65,7 @@ public final class Slide extends Sheet {
* @param notes the Notes sheet attached to us
* @param atomSet the SlideAtomsSet to get the text from
*/
- public Slide(org.apache.poi.hslf.record.Slide slide, Notes notes, SlideAtomsSet atomSet, int slideIdentifier, int slideNumber) {
+ public HSLFSlide(org.apache.poi.hslf.record.Slide slide, HSLFNotes notes, SlideAtomsSet atomSet, int slideIdentifier, int slideNumber) {
super(slide, slideIdentifier);
_notes = notes;
@@ -71,31 +73,31 @@ public final class Slide extends Sheet {
_slideNo = slideNumber;
// Grab the TextRuns from the PPDrawing
- TextRun[] _otherRuns = findTextRuns(getPPDrawing());
+ HSLFTextParagraph[] _otherRuns = findTextRuns(getPPDrawing());
// For the text coming in from the SlideAtomsSet:
// Build up TextRuns from pairs of TextHeaderAtom and
// one of TextBytesAtom or TextCharsAtom
- final List<TextRun> textRuns = new LinkedList<TextRun>();
+ final List<HSLFTextParagraph> textParagraphs = new LinkedList<HSLFTextParagraph>();
if(_atomSet != null) {
- findTextRuns(_atomSet.getSlideRecords(),textRuns);
+ findTextParagraphs(_atomSet.getSlideRecords(),textParagraphs);
} else {
// No text on the slide, must just be pictures
}
// Build an array, more useful than a vector
- _runs = new TextRun[textRuns.size()+_otherRuns.length];
+ _runs = new HSLFTextParagraph[textParagraphs.size()+_otherRuns.length];
// Grab text from SlideListWithTexts entries
int i=0;
- for(i=0; i<textRuns.size(); i++) {
- _runs[i] = textRuns.get(i);
- _runs[i].setSheet(this);
+ for(HSLFTextParagraph tp : textParagraphs) {
+ _runs[i++] = tp;
+ tp.supplySheet(this);
}
// Grab text from slide's PPDrawing
- for(int k=0; k<_otherRuns.length; i++, k++) {
- _runs[i] = _otherRuns[k];
- _runs[i].setSheet(this);
- _runs[i].setIndex(-1); // runs found in PPDrawing are not linked with SlideListWithTexts
+ for(HSLFTextParagraph tp : _otherRuns) {
+ _runs[i++] = tp;
+ tp.supplySheet(this);
+ tp.setIndex(-1); // runs found in PPDrawing are not linked with SlideListWithTexts
}
}
@@ -104,7 +106,7 @@ public final class Slide extends Sheet {
* @param sheetNumber The internal number of the sheet, as used by PersistPtrHolder
* @param slideNumber The user facing number of the sheet
*/
- public Slide(int sheetNumber, int sheetRefId, int slideNumber){
+ public HSLFSlide(int sheetNumber, int sheetRefId, int slideNumber){
super(new org.apache.poi.hslf.record.Slide(), sheetNumber);
_slideNo = slideNumber;
getSheetContainer().setSheetId(sheetRefId);
@@ -114,7 +116,7 @@ public final class Slide extends Sheet {
* Sets the Notes that are associated with this. Updates the
* references in the records to point to the new ID
*/
- public void setNotes(Notes notes) {
+ public void setNotes(HSLFNotes notes) {
_notes = notes;
// Update the Slide Atom's ID of where to point to
@@ -131,7 +133,7 @@ public final class Slide extends Sheet {
/**
* Changes the Slide's (external facing) page number.
- * @see org.apache.poi.hslf.usermodel.SlideShow#reorderSlide(int, int)
+ * @see org.apache.poi.hslf.usermodel.HSLFSlideShow#reorderSlide(int, int)
*/
public void setSlideNumber(int newSlideNumber) {
_slideNo = newSlideNumber;
@@ -178,10 +180,10 @@ public final class Slide extends Sheet {
*
* @return <code>TextBox</code> object that represents the slide's title.
*/
- public TextBox addTitle() {
+ public HSLFTextBox addTitle() {
Placeholder pl = new Placeholder();
pl.setShapeType(ShapeType.RECT);
- pl.getTextRun().setRunType(TextHeaderAtom.TITLE_TYPE);
+ pl.getTextParagraph().setRunType(TextHeaderAtom.TITLE_TYPE);
pl.setText("Click to edit title");
pl.setAnchor(new java.awt.Rectangle(54, 48, 612, 90));
addShape(pl);
@@ -203,7 +205,7 @@ public final class Slide extends Sheet {
* @return title of this slide
*/
public String getTitle(){
- TextRun[] txt = getTextRuns();
+ HSLFTextParagraph[] txt = getTextRuns();
for (int i = 0; i < txt.length; i++) {
int type = txt[i].getRunType();
if (type == TextHeaderAtom.CENTER_TITLE_TYPE ||
@@ -220,7 +222,7 @@ public final class Slide extends Sheet {
/**
* Returns an array of all the TextRuns found
*/
- public TextRun[] getTextRuns() { return _runs; }
+ public HSLFTextParagraph[] getTextRuns() { return _runs; }
/**
* Returns the (public facing) page number of this slide
@@ -237,7 +239,7 @@ public final class Slide extends Sheet {
/**
* Returns the Notes Sheet for this slide, or null if there isn't one
*/
- public Notes getNotesSheet() { return _notes; }
+ public HSLFNotes getNotesSheet() { return _notes; }
/**
* @return set of records inside <code>SlideListWithtext</code> container
@@ -251,11 +253,11 @@ public final class Slide extends Sheet {
*
* @return the master sheet associated with this slide.
*/
- public MasterSheet getMasterSheet(){
+ public HSLFMasterSheet getMasterSheet(){
SlideMaster[] master = getSlideShow().getSlidesMasters();
SlideAtom sa = getSlideRecord().getSlideAtom();
int masterId = sa.getMasterID();
- MasterSheet sheet = null;
+ HSLFMasterSheet sheet = null;
for (int i = 0; i < master.length; i++) {
if (masterId == master[i]._getSheetNumber()) {
sheet = master[i];
@@ -277,7 +279,7 @@ public final class Slide extends Sheet {
/**
* Change Master of this slide.
*/
- public void setMasterSheet(MasterSheet master){
+ public void setMasterSheet(HSLFMasterSheet master){
SlideAtom sa = getSlideRecord().getSlideAtom();
int sheetNo = master._getSheetNumber();
sa.setMasterID(sheetNo);
@@ -352,7 +354,7 @@ public final class Slide extends Sheet {
/**
* Background for this slide.
*/
- public Background getBackground() {
+ public HSLFBackground getBackground() {
if(getFollowMasterBackground()) {
return getMasterSheet().getBackground();
}
@@ -423,14 +425,14 @@ public final class Slide extends Sheet {
}
public void draw(Graphics2D graphics){
- MasterSheet master = getMasterSheet();
- Background bg = getBackground();
+ HSLFMasterSheet master = getMasterSheet();
+ HSLFBackground bg = getBackground();
if(bg != null)bg.draw(graphics);
if(getFollowMasterObjects()){
HSLFShape[] sh = master.getShapes();
for (int i = 0; i < sh.length; i++) {
- if(MasterSheet.isPlaceholder(sh[i])) continue;
+ if(HSLFMasterSheet.isPlaceholder(sh[i])) continue;
sh[i].draw(graphics);
}
@@ -469,12 +471,12 @@ public final class Slide extends Sheet {
return new HeadersFooters(hdd, this, newRecord, ppt2007);
}
- protected void onAddTextShape(TextShape shape) {
- TextRun run = shape.getTextRun();
+ protected void onAddTextShape(HSLFTextShape shape) {
+ HSLFTextParagraph run = shape.getTextParagraph();
- if(_runs == null) _runs = new TextRun[]{run};
+ if(_runs == null) _runs = new HSLFTextParagraph[]{run};
else {
- TextRun[] tmp = new TextRun[_runs.length + 1];
+ HSLFTextParagraph[] tmp = new HSLFTextParagraph[_runs.length + 1];
System.arraycopy(_runs, 0, tmp, 0, _runs.length);
tmp[tmp.length-1] = run;
_runs = tmp;
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowEncrypted.java (from r1662967, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/EncryptedSlideShow.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowEncrypted.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowEncrypted.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/EncryptedSlideShow.java&r1=1662967&r2=1667902&rev=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/EncryptedSlideShow.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowEncrypted.java Thu Mar 19 23:44:23 2015
@@ -15,7 +15,7 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.hslf;
+package org.apache.poi.hslf.model;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
@@ -49,7 +49,7 @@ import org.apache.poi.util.LittleEndian;
* This class provides helper functions for encrypted PowerPoint documents.
*/
@Internal
-public class EncryptedSlideShow {
+public class HSLFSlideShowEncrypted {
DocumentEncryptionAtom dea;
CryptoAPIEncryptor enc = null;
CryptoAPIDecryptor dec = null;
@@ -58,11 +58,11 @@ public class EncryptedSlideShow {
private static final BitField fieldRecInst = new BitField(0xFFF0);
- protected EncryptedSlideShow(DocumentEncryptionAtom dea) {
+ protected HSLFSlideShowEncrypted(DocumentEncryptionAtom dea) {
this.dea = dea;
}
- protected EncryptedSlideShow(byte[] docstream, NavigableMap<Integer,Record> recordMap) {
+ protected HSLFSlideShowEncrypted(byte[] docstream, NavigableMap<Integer,Record> recordMap) {
// check for DocumentEncryptionAtom, which would be at the last offset
// need to ignore already set UserEdit and PersistAtoms
UserEditAtom userEditAtomWithEncryption = null;
@@ -362,7 +362,7 @@ public class EncryptedSlideShow {
/**
* remove duplicated UserEditAtoms and merge PersistPtrHolder.
* Before this method is called, make sure that the offsets are correct,
- * i.e. call {@link HSLFSlideShow#updateAndWriteDependantRecords(OutputStream, Map)}
+ * i.e. call {@link HSLFSlideShowImpl#updateAndWriteDependantRecords(OutputStream, Map)}
*/
protected static Record[] normalizeRecords(Record records[]) {
// http://msdn.microsoft.com/en-us/library/office/gg615594(v=office.14).aspx
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowImpl.java (from r1662967, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowImpl.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowImpl.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java&r1=1662967&r2=1667902&rev=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlideShowImpl.java Thu Mar 19 23:44:23 2015
@@ -15,7 +15,7 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.hslf;
+package org.apache.poi.hslf.model;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -45,8 +45,8 @@ import org.apache.poi.hslf.record.Positi
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.UserEditAtom;
-import org.apache.poi.hslf.usermodel.ObjectData;
-import org.apache.poi.hslf.usermodel.PictureData;
+import org.apache.poi.hslf.usermodel.HSLFObjectData;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptor;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentEntry;
@@ -64,7 +64,7 @@ import org.apache.poi.util.POILogger;
*
* @author Nick Burch
*/
-public final class HSLFSlideShow extends POIDocument {
+public final class HSLFSlideShowImpl extends POIDocument {
public static final int UNSET_OFFSET = -1;
// For logging
@@ -80,10 +80,10 @@ public final class HSLFSlideShow extends
private Record[] _records;
// Raw Pictures contained in the pictures stream
- private List<PictureData> _pictures;
+ private List<HSLFPictureData> _pictures;
// Embedded objects stored in storage records in the document stream, lazily populated.
- private ObjectData[] _objects;
+ private HSLFObjectData[] _objects;
/**
* Returns the underlying POIFSFileSystem for the document
@@ -108,7 +108,7 @@ public final class HSLFSlideShow extends
* @param fileName The name of the file to read.
* @throws IOException if there is a problem while parsing the document.
*/
- public HSLFSlideShow(String fileName) throws IOException
+ public HSLFSlideShowImpl(String fileName) throws IOException
{
this(new FileInputStream(fileName));
}
@@ -120,7 +120,7 @@ public final class HSLFSlideShow extends
* @param inputStream the source of the data
* @throws IOException if there is a problem while parsing the document.
*/
- public HSLFSlideShow(InputStream inputStream) throws IOException {
+ public HSLFSlideShowImpl(InputStream inputStream) throws IOException {
//do Ole stuff
this(new POIFSFileSystem(inputStream));
}
@@ -132,7 +132,7 @@ public final class HSLFSlideShow extends
* @param filesystem the POIFS FileSystem to read from
* @throws IOException if there is a problem while parsing the document.
*/
- public HSLFSlideShow(POIFSFileSystem filesystem) throws IOException
+ public HSLFSlideShowImpl(POIFSFileSystem filesystem) throws IOException
{
this(filesystem.getRoot());
}
@@ -144,7 +144,7 @@ public final class HSLFSlideShow extends
* @param filesystem the POIFS FileSystem to read from
* @throws IOException if there is a problem while parsing the document.
*/
- public HSLFSlideShow(NPOIFSFileSystem filesystem) throws IOException
+ public HSLFSlideShowImpl(NPOIFSFileSystem filesystem) throws IOException
{
this(filesystem.getRoot());
}
@@ -160,7 +160,7 @@ public final class HSLFSlideShow extends
* @throws IOException if there is a problem while parsing the document.
*/
@Deprecated
- public HSLFSlideShow(DirectoryNode dir, POIFSFileSystem filesystem) throws IOException
+ public HSLFSlideShowImpl(DirectoryNode dir, POIFSFileSystem filesystem) throws IOException
{
this(dir);
}
@@ -173,7 +173,7 @@ public final class HSLFSlideShow extends
* @param dir the POIFS directory to read from
* @throws IOException if there is a problem while parsing the document.
*/
- public HSLFSlideShow(DirectoryNode dir) throws IOException {
+ public HSLFSlideShowImpl(DirectoryNode dir) throws IOException {
super(handleDualStorage(dir));
// First up, grab the "Current User" stream
@@ -202,13 +202,13 @@ public final class HSLFSlideShow extends
/**
* Constructs a new, empty, Powerpoint document.
*/
- public static final HSLFSlideShow create() {
- InputStream is = HSLFSlideShow.class.getResourceAsStream("data/empty.ppt");
+ public static final HSLFSlideShowImpl create() {
+ InputStream is = HSLFSlideShowImpl.class.getResourceAsStream("data/empty.ppt");
if (is == null) {
throw new RuntimeException("Missing resource 'empty.ppt'");
}
try {
- return new HSLFSlideShow(is);
+ return new HSLFSlideShowImpl(is);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -279,7 +279,7 @@ public final class HSLFSlideShow extends
NavigableMap<Integer,Record> records = new TreeMap<Integer,Record>(); // offset -> record
Map<Integer,Integer> persistIds = new HashMap<Integer,Integer>(); // offset -> persistId
initRecordOffsets(docstream, usrOffset, records, persistIds);
- EncryptedSlideShow decryptData = new EncryptedSlideShow(docstream, records);
+ HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(docstream, records);
for (Map.Entry<Integer,Record> entry : records.entrySet()) {
Integer offset = entry.getKey();
@@ -373,12 +373,12 @@ public final class HSLFSlideShow extends
*/
@SuppressWarnings("unused")
private void readPictures() throws IOException {
- _pictures = new ArrayList<PictureData>();
+ _pictures = new ArrayList<HSLFPictureData>();
// if the presentation doesn't contain pictures - will use a null set instead
if (!directory.hasEntry("Pictures")) return;
- EncryptedSlideShow decryptData = new EncryptedSlideShow(getDocumentEncryptionAtom());
+ HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom());
DocumentEntry entry = (DocumentEntry)directory.getEntry("Pictures");
byte[] pictstream = new byte[entry.getSize()];
@@ -423,7 +423,7 @@ public final class HSLFSlideShow extends
} else {
// Build the PictureData object from the data
try {
- PictureData pict = PictureData.create(type - 0xF018);
+ HSLFPictureData pict = HSLFPictureData.create(type - 0xF018);
// Copy the data, ready to pass to PictureData
byte[] imgdata = new byte[imgsize];
@@ -451,7 +451,7 @@ public final class HSLFSlideShow extends
} catch (IOException e) {
throw new CorruptPowerPointFileException(e);
}
- _records = EncryptedSlideShow.normalizeRecords(_records);
+ _records = HSLFSlideShowEncrypted.normalizeRecords(_records);
}
@@ -517,7 +517,7 @@ public final class HSLFSlideShow extends
persistIds.put(oldToNewPositions.get(entry.getValue()), entry.getKey());
}
- EncryptedSlideShow encData = new EncryptedSlideShow(getDocumentEncryptionAtom());
+ HSLFSlideShowEncrypted encData = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom());
for (Record record : _records) {
assert(record instanceof PositionDependentRecord);
@@ -580,7 +580,7 @@ public final class HSLFSlideShow extends
getDocumentSummaryInformation();
// set new encryption settings
- EncryptedSlideShow encryptedSS = new EncryptedSlideShow(getDocumentEncryptionAtom());
+ HSLFSlideShowEncrypted encryptedSS = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom());
_records = encryptedSS.updateEncryptionRecord(_records);
// Get a new Filesystem to write into
@@ -615,7 +615,7 @@ public final class HSLFSlideShow extends
if (_pictures.size() > 0) {
BufAccessBAOS pict = new BufAccessBAOS();
- for (PictureData p : _pictures) {
+ for (HSLFPictureData p : _pictures) {
int offset = pict.size();
p.write(pict);
encryptedSS.encryptPicture(pict.getBuf(), offset);
@@ -704,7 +704,7 @@ public final class HSLFSlideShow extends
*
* @return offset of this picture in the Pictures stream
*/
- public int addPicture(PictureData img) {
+ public int addPicture(HSLFPictureData img) {
// Process any existing pictures if we haven't yet
if(_pictures == null) {
try {
@@ -717,7 +717,7 @@ public final class HSLFSlideShow extends
// Add the new picture in
int offset = 0;
if(_pictures.size() > 0) {
- PictureData prev = _pictures.get(_pictures.size() - 1);
+ HSLFPictureData prev = _pictures.get(_pictures.size() - 1);
offset = prev.getOffset() + prev.getRawData().length + 8;
}
img.setOffset(offset);
@@ -750,7 +750,7 @@ public final class HSLFSlideShow extends
* @return array with the read pictures or <code>null</code> if the
* presentation doesn't contain pictures.
*/
- public PictureData[] getPictures() {
+ public HSLFPictureData[] getPictures() {
if(_pictures == null) {
try {
readPictures();
@@ -759,7 +759,7 @@ public final class HSLFSlideShow extends
}
}
- return _pictures.toArray(new PictureData[_pictures.size()]);
+ return _pictures.toArray(new HSLFPictureData[_pictures.size()]);
}
/**
@@ -767,15 +767,15 @@ public final class HSLFSlideShow extends
*
* @return the embedded objects.
*/
- public ObjectData[] getEmbeddedObjects() {
+ public HSLFObjectData[] getEmbeddedObjects() {
if (_objects == null) {
- List<ObjectData> objects = new ArrayList<ObjectData>();
+ List<HSLFObjectData> objects = new ArrayList<HSLFObjectData>();
for (Record r : _records) {
if (r instanceof ExOleObjStg) {
- objects.add(new ObjectData((ExOleObjStg)r));
+ objects.add(new HSLFObjectData((ExOleObjStg)r));
}
}
- _objects = objects.toArray(new ObjectData[objects.size()]);
+ _objects = objects.toArray(new HSLFObjectData[objects.size()]);
}
return _objects;
}
Copied: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextBox.java (from r1664935, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java)
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextBox.java?p2=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextBox.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java&r1=1664935&r2=1667902&rev=1667902&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextBox.java Thu Mar 19 23:44:23 2015
@@ -30,7 +30,7 @@ import org.apache.poi.sl.usermodel.Shape
*
* @author Yegor Kozlov
*/
-public class TextBox extends TextShape {
+public class HSLFTextBox extends HSLFTextShape {
/**
* Create a TextBox object and initialize it from the supplied Record container.
@@ -38,7 +38,7 @@ public class TextBox extends TextShape {
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected TextBox(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
super(escherRecord, parent);
}
@@ -49,7 +49,7 @@ public class TextBox extends TextShape {
* @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table.
*/
- public TextBox(ShapeContainer<HSLFShape> parent){
+ public HSLFTextBox(ShapeContainer<HSLFShape> parent){
super(parent);
}
@@ -57,7 +57,7 @@ public class TextBox extends TextShape {
* Create a new TextBox. This constructor is used when a new shape is created.
*
*/
- public TextBox(){
+ public HSLFTextBox(){
this(null);
}
@@ -84,8 +84,8 @@ public class TextBox extends TextShape {
return _escherContainer;
}
- protected void setDefaultTextProperties(TextRun _txtrun){
- setVerticalAlignment(TextBox.AnchorTop);
+ protected void setDefaultTextProperties(HSLFTextParagraph _txtrun){
+ setVerticalAlignment(HSLFTextBox.AnchorTop);
setEscherProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20002);
}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextParagraph.java?rev=1667902&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextParagraph.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextParagraph.java Thu Mar 19 23:44:23 2015
@@ -0,0 +1,744 @@
+/* ====================================================================
+ 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.hslf.model;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.PPDrawing;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RecordContainer;
+import org.apache.poi.hslf.record.SlideListWithText;
+import org.apache.poi.hslf.record.StyleTextProp9Atom;
+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.TextRulerAtom;
+import org.apache.poi.hslf.record.TextSpecInfoAtom;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.sl.usermodel.TextParagraph;
+import org.apache.poi.util.StringUtil;
+
+/**
+ * This class represents a run of text in a powerpoint document. That
+ * run could be text on a sheet, or text in a note.
+ * It is only a very basic class for now
+ *
+ * @author Nick Burch
+ */
+
+public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun>
+{
+ // Note: These fields are protected to help with unit testing
+ // Other classes shouldn't really go playing with them!
+ protected TextHeaderAtom _headerAtom;
+ protected TextBytesAtom _byteAtom;
+ protected TextCharsAtom _charAtom;
+ protected StyleTextPropAtom _styleAtom;
+ protected TextRulerAtom _ruler;
+ protected boolean _isUnicode;
+ protected HSLFTextRun[] _rtRuns;
+ protected HSLFTextShape _parentShape;
+ // private SlideShow slideShow;
+ private HSLFSheet _sheet;
+ private int shapeId;
+ private int slwtIndex = -1; //position in the owning SlideListWithText
+ /**
+ * all text run records that follow TextHeaderAtom.
+ * (there can be misc InteractiveInfo, TxInteractiveInfo and other records)
+ */
+ protected Record[] _records;
+ // private StyleTextPropAtom styleTextPropAtom;
+ private StyleTextProp9Atom styleTextProp9Atom;
+
+ /**
+ * Constructs a Text Run from a Unicode text block
+ *
+ * @param tha the TextHeaderAtom that defines what's what
+ * @param tca the TextCharsAtom containing the text
+ * @param sta the StyleTextPropAtom which defines the character stylings
+ */
+ public HSLFTextParagraph(TextHeaderAtom tha, TextCharsAtom tca, StyleTextPropAtom sta) {
+ this(tha,null,tca,sta);
+ }
+
+ /**
+ * Constructs a Text Run from a Ascii text block
+ *
+ * @param tha the TextHeaderAtom that defines what's what
+ * @param tba the TextBytesAtom containing the text
+ * @param sta the StyleTextPropAtom which defines the character stylings
+ */
+ public HSLFTextParagraph(TextHeaderAtom tha, TextBytesAtom tba, StyleTextPropAtom sta) {
+ this(tha,tba,null,sta);
+ }
+
+ /**
+ * Internal constructor and initializer
+ */
+ private HSLFTextParagraph(TextHeaderAtom tha, TextBytesAtom tba, TextCharsAtom tca, StyleTextPropAtom sta) {
+ _headerAtom = tha;
+ _styleAtom = sta;
+ if(tba != null) {
+ _byteAtom = tba;
+ _isUnicode = false;
+ } else {
+ _charAtom = tca;
+ _isUnicode = true;
+ }
+ String runRawText = getText();
+
+ // Figure out the rich text runs
+ LinkedList<TextPropCollection> pStyles = new LinkedList<TextPropCollection>();
+ LinkedList<TextPropCollection> cStyles = new LinkedList<TextPropCollection>();
+ if(_styleAtom != null) {
+ // Get the style atom to grok itself
+ _styleAtom.setParentTextSize(runRawText.length());
+ pStyles = _styleAtom.getParagraphStyles();
+ cStyles = _styleAtom.getCharacterStyles();
+ }
+ buildRichTextRuns(pStyles, cStyles, runRawText);
+ }
+
+ public void buildRichTextRuns(LinkedList<TextPropCollection> pStyles, LinkedList<TextPropCollection> cStyles, String runRawText){
+
+ // Handle case of no current style, with a default
+ if(pStyles.size() == 0 || cStyles.size() == 0) {
+ _rtRuns = new HSLFTextRun[1];
+ _rtRuns[0] = new HSLFTextRun(this, 0, runRawText.length());
+ } else {
+ // Build up Rich Text Runs, one for each
+ // character/paragraph style pair
+ List<HSLFTextRun> rtrs = new ArrayList<HSLFTextRun>();
+
+ int pos = 0;
+
+ int curP = 0;
+ int curC = 0;
+ int pLenRemain = -1;
+ int cLenRemain = -1;
+
+ // Build one for each run with the same style
+ while(pos <= runRawText.length() && curP < pStyles.size() && curC < cStyles.size()) {
+ // Get the Props to use
+ TextPropCollection pProps = pStyles.get(curP);
+ TextPropCollection cProps = cStyles.get(curC);
+
+ int pLen = pProps.getCharactersCovered();
+ int cLen = cProps.getCharactersCovered();
+
+ // Handle new pass
+ boolean freshSet = false;
+ if(pLenRemain == -1 && cLenRemain == -1) { freshSet = true; }
+ if(pLenRemain == -1) { pLenRemain = pLen; }
+ if(cLenRemain == -1) { cLenRemain = cLen; }
+
+ // So we know how to build the eventual run
+ int runLen = -1;
+ boolean pShared = false;
+ boolean cShared = false;
+
+ // Same size, new styles - neither shared
+ if(pLen == cLen && freshSet) {
+ runLen = cLen;
+ pShared = false;
+ cShared = false;
+ curP++;
+ curC++;
+ pLenRemain = -1;
+ cLenRemain = -1;
+ } else {
+ // Some sharing
+
+ // See if we are already in a shared block
+ if(pLenRemain < pLen) {
+ // Existing shared p block
+ pShared = true;
+
+ // Do we end with the c block, or either side of it?
+ if(pLenRemain == cLenRemain) {
+ // We end at the same time
+ cShared = false;
+ runLen = pLenRemain;
+ curP++;
+ curC++;
+ pLenRemain = -1;
+ cLenRemain = -1;
+ } else if(pLenRemain < cLenRemain) {
+ // We end before the c block
+ cShared = true;
+ runLen = pLenRemain;
+ curP++;
+ cLenRemain -= pLenRemain;
+ pLenRemain = -1;
+ } else {
+ // We end after the c block
+ cShared = false;
+ runLen = cLenRemain;
+ curC++;
+ pLenRemain -= cLenRemain;
+ cLenRemain = -1;
+ }
+ } else if(cLenRemain < cLen) {
+ // Existing shared c block
+ cShared = true;
+
+ // Do we end with the p block, or either side of it?
+ if(pLenRemain == cLenRemain) {
+ // We end at the same time
+ pShared = false;
+ runLen = cLenRemain;
+ curP++;
+ curC++;
+ pLenRemain = -1;
+ cLenRemain = -1;
+ } else if(cLenRemain < pLenRemain) {
+ // We end before the p block
+ pShared = true;
+ runLen = cLenRemain;
+ curC++;
+ pLenRemain -= cLenRemain;
+ cLenRemain = -1;
+ } else {
+ // We end after the p block
+ pShared = false;
+ runLen = pLenRemain;
+ curP++;
+ cLenRemain -= pLenRemain;
+ pLenRemain = -1;
+ }
+ } else {
+ // Start of a shared block
+ if(pLenRemain < cLenRemain) {
+ // Shared c block
+ pShared = false;
+ cShared = true;
+ runLen = pLenRemain;
+ curP++;
+ cLenRemain -= pLenRemain;
+ pLenRemain = -1;
+ } else {
+ // Shared p block
+ pShared = true;
+ cShared = false;
+ runLen = cLenRemain;
+ curC++;
+ pLenRemain -= cLenRemain;
+ cLenRemain = -1;
+ }
+ }
+ }
+
+ // Wind on
+ int prevPos = pos;
+ pos += runLen;
+ // Adjust for end-of-run extra 1 length
+ if(pos > runRawText.length()) {
+ runLen--;
+ }
+
+ // Save
+ HSLFTextRun rtr = new HSLFTextRun(this, prevPos, runLen, pProps, cProps, pShared, cShared);
+ rtrs.add(rtr);
+ }
+
+ // Build the array
+ _rtRuns = rtrs.toArray(new HSLFTextRun[rtrs.size()]);
+ }
+
+ }
+
+ // Update methods follow
+
+ /**
+ * Adds the supplied text onto the end of the TextRun,
+ * creating a new RichTextRun (returned) for it to
+ * sit in.
+ * In many cases, before calling this, you'll want to add
+ * a newline onto the end of your last RichTextRun
+ */
+ public HSLFTextRun appendText(String s) {
+ // We will need a StyleTextProp atom
+ ensureStyleAtomPresent();
+
+ // First up, append the text to the
+ // underlying text atom
+ int oldSize = getRawText().length();
+ storeText(
+ getRawText() + s
+ );
+
+ // If either of the previous styles overran
+ // the text by one, we need to shuffle that
+ // extra character onto the new ones
+ int pOverRun = _styleAtom.getParagraphTextLengthCovered() - oldSize;
+ int cOverRun = _styleAtom.getCharacterTextLengthCovered() - oldSize;
+ if(pOverRun > 0) {
+ TextPropCollection tpc = _styleAtom.getParagraphStyles().getLast();
+ tpc.updateTextSize(
+ tpc.getCharactersCovered() - pOverRun
+ );
+ }
+ if(cOverRun > 0) {
+ TextPropCollection tpc = _styleAtom.getCharacterStyles().getLast();
+ tpc.updateTextSize(
+ tpc.getCharactersCovered() - cOverRun
+ );
+ }
+
+ // Next, add the styles for its paragraph and characters
+ TextPropCollection newPTP =
+ _styleAtom.addParagraphTextPropCollection(s.length()+pOverRun);
+ TextPropCollection newCTP =
+ _styleAtom.addCharacterTextPropCollection(s.length()+cOverRun);
+
+ // Now, create the new RichTextRun
+ HSLFTextRun nr = new HSLFTextRun(
+ this, oldSize, s.length(),
+ newPTP, newCTP, false, false
+ );
+
+ // Add the new RichTextRun onto our list
+ HSLFTextRun[] newRuns = new HSLFTextRun[_rtRuns.length+1];
+ System.arraycopy(_rtRuns, 0, newRuns, 0, _rtRuns.length);
+ newRuns[newRuns.length-1] = nr;
+ _rtRuns = newRuns;
+
+ // And return the new run to the caller
+ return nr;
+ }
+
+ /**
+ * Saves the given string to the records. Doesn't
+ * touch the stylings.
+ */
+ private void storeText(String s) {
+ // Store in the appropriate record
+ if(_isUnicode) {
+ // The atom can safely convert to unicode
+ _charAtom.setText(s);
+ } else {
+ // Will it fit in a 8 bit atom?
+ boolean hasMultibyte = StringUtil.hasMultibyte(s);
+ if(! hasMultibyte) {
+ // Fine to go into 8 bit atom
+ byte[] text = new byte[s.length()];
+ StringUtil.putCompressedUnicode(s,text,0);
+ _byteAtom.setText(text);
+ } else {
+ // Need to swap a TextBytesAtom for a TextCharsAtom
+
+ // Build the new TextCharsAtom
+ _charAtom = new TextCharsAtom();
+ _charAtom.setText(s);
+
+ // Use the TextHeaderAtom to do the swap on the parent
+ RecordContainer parent = _headerAtom.getParentRecord();
+ Record[] cr = parent.getChildRecords();
+ for(int i=0; i<cr.length; i++) {
+ // Look for TextBytesAtom
+ if(cr[i].equals(_byteAtom)) {
+ // Found it, so replace, then all done
+ cr[i] = _charAtom;
+ break;
+ }
+ }
+
+ // Flag the change
+ _byteAtom = null;
+ _isUnicode = true;
+ }
+ }
+ /**
+ * If TextSpecInfoAtom is present, we must update the text size in it,
+ * otherwise the ppt will be corrupted
+ */
+ if(_records != null) for (int i = 0; i < _records.length; i++) {
+ if(_records[i] instanceof TextSpecInfoAtom){
+ TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_records[i];
+ if((s.length() + 1) != specAtom.getCharactersCovered()){
+ specAtom.reset(s.length() + 1);
+ }
+ }
+ }
+ }
+
+ /**
+ * Handles an update to the text stored in one of the Rich Text Runs
+ * @param run
+ * @param s
+ */
+ public void changeTextInRichTextRun(HSLFTextRun run, String s) {
+ // Figure out which run it is
+ int runID = -1;
+ for(int i=0; i<_rtRuns.length; i++) {
+ if(run.equals(_rtRuns[i])) {
+ runID = i;
+ }
+ }
+ if(runID == -1) {
+ throw new IllegalArgumentException("Supplied RichTextRun wasn't from this TextRun");
+ }
+
+ // Ensure a StyleTextPropAtom is present, adding if required
+ ensureStyleAtomPresent();
+
+ // Update the text length for its Paragraph and Character stylings
+ // If it's shared:
+ // * calculate the new length based on the run's old text
+ // * this should leave in any +1's for the end of block if needed
+ // If it isn't shared:
+ // * reset the length, to the new string's length
+ // * add on +1 if the last block
+ // The last run needs its stylings to be 1 longer than the raw
+ // text is. This is to define the stylings that any new text
+ // that is added will inherit
+ TextPropCollection pCol = run._getRawParagraphStyle();
+ TextPropCollection cCol = run._getRawCharacterStyle();
+ int newSize = s.length();
+ if(runID == _rtRuns.length-1) {
+ newSize++;
+ }
+
+ if(run._isParagraphStyleShared()) {
+ pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length() );
+ } else {
+ pCol.updateTextSize(newSize);
+ }
+ if(run._isCharacterStyleShared()) {
+ cCol.updateTextSize( cCol.getCharactersCovered() - run.getLength() + s.length() );
+ } else {
+ cCol.updateTextSize(newSize);
+ }
+
+ // Build up the new text
+ // As we go through, update the start position for all subsequent runs
+ // The building relies on the old text still being present
+ StringBuffer newText = new StringBuffer();
+ for(int i=0; i<_rtRuns.length; i++) {
+ int newStartPos = newText.length();
+
+ // Build up the new text
+ if(i != runID) {
+ // Not the affected run, so keep old text
+ newText.append(_rtRuns[i].getRawText());
+ } else {
+ // Affected run, so use new text
+ newText.append(s);
+ }
+
+ // Do we need to update the start position of this run?
+ // (Need to get the text before we update the start pos)
+ if(i <= runID) {
+ // Change is after this, so don't need to change start position
+ } else {
+ // Change has occured, so update start position
+ _rtRuns[i].updateStartPosition(newStartPos);
+ }
+ }
+
+ // Now we can save the new text
+ storeText(newText.toString());
+ }
+
+ /**
+ * Changes the text, and sets it all to have the same styling
+ * as the the first character has.
+ * If you care about styling, do setText on a RichTextRun instead
+ */
+ public void setRawText(String s) {
+ // Save the new text to the atoms
+ storeText(s);
+ HSLFTextRun fst = _rtRuns[0];
+
+ // Finally, zap and re-do the RichTextRuns
+ for(int i=0; i<_rtRuns.length; i++) { _rtRuns[i] = null; }
+ _rtRuns = new HSLFTextRun[1];
+ _rtRuns[0] = fst;
+
+ // Now handle record stylings:
+ // If there isn't styling
+ // no change, stays with no styling
+ // If there is styling:
+ // everthing gets the same style that the first block has
+ // Update the lengths +1 for since these will be the only runs
+ if(_styleAtom != null) {
+ LinkedList<TextPropCollection> pStyles = _styleAtom.getParagraphStyles();
+ while(pStyles.size() > 1) { pStyles.removeLast(); }
+
+ if (!pStyles.isEmpty()) {
+ pStyles.getFirst().updateTextSize( s.length()+1 );
+ }
+
+ LinkedList<TextPropCollection> cStyles = _styleAtom.getCharacterStyles();
+ while(cStyles.size() > 1) { cStyles.removeLast(); }
+
+ if (!cStyles.isEmpty()) {
+ cStyles.getFirst().updateTextSize( s.length()+1 );
+ }
+
+ _rtRuns[0].setText(s);
+ } else {
+ // Recreate rich text run with no styling
+ _rtRuns[0] = new HSLFTextRun(this,0,s.length());
+ }
+
+ }
+
+ /**
+ * Changes the text.
+ * Converts '\r' into '\n'
+ */
+ public void setText(String s) {
+ String text = normalize(s);
+ setRawText(text);
+ }
+
+ /**
+ * Ensure a StyleTextPropAtom is present for this run,
+ * by adding if required. Normally for internal TextRun use.
+ */
+ public void ensureStyleAtomPresent() {
+ if(_styleAtom != null) {
+ // All there
+ return;
+ }
+
+ // Create a new one at the right size
+ _styleAtom = new StyleTextPropAtom(getRawText().length() + 1);
+
+ // Use the TextHeader atom to get at the parent
+ RecordContainer runAtomsParent = _headerAtom.getParentRecord();
+
+ // Add the new StyleTextPropAtom after the TextCharsAtom / TextBytesAtom
+ Record addAfter = _byteAtom;
+ if(_byteAtom == null) { addAfter = _charAtom; }
+ runAtomsParent.addChildAfter(_styleAtom, addAfter);
+
+ // Feed this to our sole rich text run
+ if(_rtRuns.length != 1) {
+ throw new IllegalStateException("Needed to add StyleTextPropAtom when had many rich text runs");
+ }
+ // These are the only styles for now
+ _rtRuns[0].supplyTextProps(
+ _styleAtom.getParagraphStyles().get(0),
+ _styleAtom.getCharacterStyles().get(0),
+ false,
+ false
+ );
+ }
+
+ // Accesser methods follow
+
+ /**
+ * Returns the text content of the run, which has been made safe
+ * for printing and other use.
+ */
+ public String getText() {
+ String rawText = getRawText();
+
+ // 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');
+
+ int type = _headerAtom == null ? 0 : _headerAtom.getTextType();
+ if(type == TextHeaderAtom.TITLE_TYPE || type == TextHeaderAtom.CENTER_TITLE_TYPE){
+ //0xB acts like cariage return in page titles and like blank in the others
+ text = text.replace((char) 0x0B, '\n');
+ } else {
+ text = text.replace((char) 0x0B, ' ');
+ }
+ return text;
+ }
+
+ /**
+ * Returns the raw text content of the run. This hasn't had any
+ * changes applied to it, and so is probably unlikely to print
+ * out nicely.
+ */
+ public String getRawText() {
+ if(_isUnicode) {
+ return _charAtom.getText();
+ }
+ return _byteAtom.getText();
+ }
+
+ /**
+ * Fetch the rich text runs (runs of text with the same styling) that
+ * are contained within this block of text
+ */
+ public HSLFTextRun[] getRichTextRuns() {
+ return _rtRuns;
+ }
+
+ /**
+ * 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() {
+ 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) {
+ _headerAtom.setTextType(type);
+ }
+
+ /**
+ * Supply the Sheet we belong to, which might have an assigned SlideShow
+ * Also passes it on to our child RichTextRuns
+ */
+ public void supplySheet(HSLFSheet sheet){
+ this._sheet = sheet;
+
+ if (_rtRuns == null) return;
+ for(HSLFTextRun rt : _rtRuns) {
+ rt.updateSheet();
+ }
+ }
+
+ public HSLFSheet getSheet(){
+ return this._sheet;
+ }
+
+ /**
+ * @return Shape ID
+ */
+ protected int getShapeId(){
+ return shapeId;
+ }
+
+ /**
+ * @param id Shape ID
+ */
+ protected void setShapeId(int id){
+ shapeId = id;
+ }
+
+ /**
+ * @return 0-based index of the text run in the SLWT container
+ */
+ protected int getIndex(){
+ return slwtIndex;
+ }
+
+ /**
+ * @param id 0-based index of the text run in the SLWT container
+ */
+ protected void setIndex(int id){
+ slwtIndex = id;
+ }
+
+ /**
+ * Is this Text Run one from a {@link PPDrawing}, or is it
+ * one from the {@link SlideListWithText}?
+ */
+ public boolean isDrawingBased() {
+ return (slwtIndex == -1);
+ }
+
+ /**
+ * 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 Hyperlink[] getHyperlinks(){
+ return Hyperlink.find(this);
+ }
+
+ /**
+ * Fetch RichTextRun at a given position
+ *
+ * @param pos 0-based index in the text
+ * @return RichTextRun or null if not found
+ */
+ public HSLFTextRun getRichTextRunAt(int pos){
+ for (int i = 0; i < _rtRuns.length; i++) {
+ int start = _rtRuns[i].getStartIndex();
+ int end = _rtRuns[i].getEndIndex();
+ if(pos >= start && pos < end) return _rtRuns[i];
+ }
+ return null;
+ }
+
+ public TextRulerAtom getTextRuler(){
+ if(_ruler == null){
+ if(_records != null) for (int i = 0; i < _records.length; i++) {
+ if(_records[i] instanceof TextRulerAtom) {
+ _ruler = (TextRulerAtom)_records[i];
+ break;
+ }
+ }
+
+ }
+ return _ruler;
+
+ }
+
+ public TextRulerAtom createTextRuler(){
+ _ruler = getTextRuler();
+ if(_ruler == null){
+ _ruler = TextRulerAtom.getParagraphInstance();
+ _headerAtom.getParentRecord().appendChildRecord(_ruler);
+ }
+ return _ruler;
+ }
+
+ /**
+ * Returns a new string with line breaks converted into internal ppt representation
+ */
+ public String normalize(String s){
+ String ns = s.replaceAll("\\r?\\n", "\r");
+ return ns;
+ }
+
+ /**
+ * Returns records that make up this text run
+ *
+ * @return text run records
+ */
+ public Record[] getRecords(){
+ return _records;
+ }
+ /** Numbered List info */
+ public void setStyleTextProp9Atom(final StyleTextProp9Atom styleTextProp9Atom) {
+ this.styleTextProp9Atom = styleTextProp9Atom;
+ }
+ /** Numbered List info */
+ public StyleTextProp9Atom getStyleTextProp9Atom() {
+ return this.styleTextProp9Atom;
+ }
+
+ /** Characters covered */
+ public StyleTextPropAtom getStyleTextPropAtom() {
+ return this._styleAtom;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org