From: Andreas Beeker Date: Fri, 26 Dec 2014 00:11:23 +0000 (+0000) Subject: Unified access to escher opt record X-Git-Tag: REL_3_12_BETA1~75 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee2ccafd0b9d8f3e5830861918f6773f409d83d0;p=poi.git Unified access to escher opt record git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647927 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java index c9b55082b3..f18e84e48c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java @@ -159,7 +159,7 @@ public final class ActiveXShape extends Picture { String name = ctrl.getProgId() + "-" + getControlIndex(); byte[] data = (name + '\u0000').getBytes("UTF-16LE"); EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data); - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); opt.addEscherProperty(prop); } catch (UnsupportedEncodingException e){ throw new HSLFException(e); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java b/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java index 10c468ced7..ca647f32d0 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java @@ -136,7 +136,7 @@ public final class Freeform extends AutoShape { if(!isClosed) segInfo.add(SEGMENTINFO_LINETO); segInfo.add(new byte[]{0x00, (byte)0x80}); - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null); @@ -176,7 +176,7 @@ public final class Freeform extends AutoShape { * @return the freeform path */ public GeneralPath getPath(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); EscherArrayProperty verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000)); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Line.java b/src/scratchpad/src/org/apache/poi/hslf/model/Line.java index e40a46519c..2a23d24819 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Line.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Line.java @@ -116,7 +116,7 @@ public final class Line extends SimpleShape { spRecord.setOptions(type); //set default properties for a line - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); //default line properties setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java b/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java index 8ffb111cc0..14d71f9194 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java @@ -111,7 +111,7 @@ public class Picture extends SimpleShape { * @return the index to this picture (1 based). */ public int getPictureIndex(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY); return prop == null ? 0 : prop.getPropertyValue(); } @@ -130,7 +130,7 @@ public class Picture extends SimpleShape { spRecord.setOptions((short)((ShapeTypes.PictureFrame << 4) | 0x2)); //set default properties for a picture - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080); //another weird feature of powerpoint: for picture id we must add 0x4000. @@ -214,7 +214,7 @@ public class Picture extends SimpleShape { * @return name of this picture */ public String getPictureName(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherComplexProperty prop = (EscherComplexProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPFILENAME); String name = null; if(prop != null){ @@ -235,7 +235,7 @@ public class Picture extends SimpleShape { * @param name of this picture */ public void setPictureName(String name){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); try { byte[] data = (name + '\u0000').getBytes("UTF-16LE"); EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, false, data); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java b/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java index 945d3195c4..a3eb1b978d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java @@ -56,7 +56,7 @@ public final class Placeholder extends TextBox { EscherClientDataRecord cldata = new EscherClientDataRecord(); cldata.setOptions((short)15); - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); //Placeholders can't be grouped setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java b/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java index 4e2eb3ed10..09637a65ee 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java @@ -71,7 +71,7 @@ public final class Polygon extends AutoShape { float left = findSmallest(xPoints); float top = findSmallest(yPoints); - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)((right - left)*POINT_DPI/MASTER_DPI))); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)((bottom - top)*POINT_DPI/MASTER_DPI))); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java b/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java index ef4c4c8a60..1ae07e2b8d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java @@ -299,7 +299,7 @@ public abstract class Shape { * @param value value of the property. If value = -1 then the property is removed. */ public void setEscherProperty(short propId, int value){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, propId, value); } @@ -309,7 +309,7 @@ public abstract class Shape { * @param propId The id of the property. One of the constants defined in EscherOptRecord. */ public int getEscherProperty(short propId){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, propId); return prop == null ? 0 : prop.getPropertyValue(); } @@ -320,7 +320,7 @@ public abstract class Shape { * @param propId The id of the property. One of the constants defined in EscherOptRecord. */ public int getEscherProperty(short propId, int defaultValue){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, propId); return prop == null ? defaultValue : prop.getPropertyValue(); } @@ -364,7 +364,7 @@ public abstract class Shape { } Color getColor(short colorProperty, short opacityProperty, int defaultColor){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty p = (EscherSimpleProperty)getEscherProperty(opt, colorProperty); if(p == null && defaultColor == -1) return null; @@ -483,4 +483,8 @@ public abstract class Shape { public java.awt.Shape getOutline(){ return getLogicalAnchor2D(); } + + protected EscherOptRecord getEscherOptRecord() { + return (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java index 1a4ae896b3..4a8bdf692e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java @@ -102,7 +102,7 @@ public abstract class SimpleShape extends Shape { * Returns width of the line in in points */ public double getLineWidth(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH); double width = prop == null ? DEFAULT_LINE_WIDTH : (double)prop.getPropertyValue()/EMU_PER_POINT; return width; @@ -113,7 +113,7 @@ public abstract class SimpleShape extends Shape { * @param width the width of line in in points */ public void setLineWidth(double width){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, (int)(width*EMU_PER_POINT)); } @@ -123,7 +123,7 @@ public abstract class SimpleShape extends Shape { * @param color new color of the line */ public void setLineColor(Color color){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); if (color == null) { setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000); } else { @@ -137,7 +137,7 @@ public abstract class SimpleShape extends Shape { * @return color of the line. If color is not set returns java.awt.Color.black */ public Color getLineColor(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty p = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH); if(p != null && (p.getPropertyValue() & 0x8) == 0) return null; @@ -152,7 +152,7 @@ public abstract class SimpleShape extends Shape { * @return dashing of the line. */ public int getLineDashing(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING); return prop == null ? Line.PEN_SOLID : prop.getPropertyValue(); @@ -164,7 +164,7 @@ public abstract class SimpleShape extends Shape { * @param pen new style of the line. */ public void setLineDashing(int pen){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == Line.PEN_SOLID ? -1 : pen); } @@ -175,7 +175,7 @@ public abstract class SimpleShape extends Shape { * @param style new style of the line. */ public void setLineStyle(int style){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == Line.LINE_SIMPLE ? -1 : style); } @@ -185,7 +185,7 @@ public abstract class SimpleShape extends Shape { * @return style of the line. */ public int getLineStyle(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE); return prop == null ? Line.LINE_SIMPLE : prop.getPropertyValue(); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Table.java b/src/scratchpad/src/org/apache/poi/hslf/model/Table.java index d85fa09772..c494789917 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Table.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Table.java @@ -332,7 +332,7 @@ public final class Table extends ShapeGroup { public Line createBorder(){ Line line = new Line(this); - EscherOptRecord opt = (EscherOptRecord)getEscherChild(line.getSpContainer(), EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1); setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1); setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java b/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java index d03fc1db19..864d55eae4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java @@ -61,7 +61,7 @@ public final class TableCell extends TextBox { protected EscherContainerRecord createSpContainer(boolean isChild){ _escherContainer = super.createSpContainer(isChild); - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0); setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000); setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java index 2ab57380a9..77af6eab9b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java @@ -280,7 +280,7 @@ public abstract class TextShape extends SimpleShape { * @return the type of alignment */ public int getVerticalAlignment(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT); int valign = TextShape.AnchorTop; if (prop == null){ @@ -351,7 +351,7 @@ public abstract class TextShape extends SimpleShape { * @return the botom margin */ public float getMarginBottom(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM); int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; @@ -376,7 +376,7 @@ public abstract class TextShape extends SimpleShape { * @return the left margin */ public float getMarginLeft(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT); int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; @@ -401,7 +401,7 @@ public abstract class TextShape extends SimpleShape { * @return the right margin */ public float getMarginRight(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT); int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; @@ -425,7 +425,7 @@ public abstract class TextShape extends SimpleShape { * @return the top margin */ public float getMarginTop(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP); int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; @@ -449,7 +449,7 @@ public abstract class TextShape extends SimpleShape { * Must be one of the Wrap* constants defined in this class. */ public int getWordWrap(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT); return prop == null ? WrapSquare : prop.getPropertyValue(); } @@ -468,7 +468,7 @@ public abstract class TextShape extends SimpleShape { * @return id for the text. */ public int getTextId(){ - EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); + EscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTID); return prop == null ? 0 : prop.getPropertyValue(); }