Skip to content

Commit

Permalink
Support for Master Sheets from Yegor (bug 40753)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@464982 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Gagravarr committed Oct 17, 2006
1 parent 966759c commit 5f167f0
Show file tree
Hide file tree
Showing 26 changed files with 1,068 additions and 323 deletions.
16 changes: 7 additions & 9 deletions src/scratchpad/src/org/apache/poi/hslf/model/AutoShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ protected EscherContainerRecord createSpContainer(int shapeType, boolean isChild
short type = (short)((shapeType << 4) | 0x2);
spRecord.setOptions(type);

//set default properties for a line
//set default properties for an autoshape
EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);

opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 134217732));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 134217728));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 1048592));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 134217729));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 524296));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 134217730));

opt.sortProperties();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100010));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002));

return spcont;
}
Expand Down
53 changes: 31 additions & 22 deletions src/scratchpad/src/org/apache/poi/hslf/model/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,66 +27,69 @@ public class Line extends SimpleShape {
/**
* Solid (continuous) pen
*/
public static final int LineSolid = 1;
public static final int PEN_SOLID = 1;
/**
* PS_DASH system dash style
*/
public static final int LineDashSys = 2;
public static final int PEN_PS_DASH = 2;
/**
* PS_DOT system dash style
*/
public static final int LineDotSys = 3;
public static final int PEN_DOT = 3;
/**
* PS_DASHDOT system dash style
*/
public static final int LineDashDotSys = 4;

public static final int PEN_DASHDOT = 4;
/**
* PS_DASHDOTDOT system dash style
*/
public static final int LineDashDotDotSys = 5;
public static final int PEN_DASHDOTDOT = 5;
/**
* square dot style
*/
public static final int LineDotGEL = 6;
public static final int PEN_DOTGEL = 6;
/**
* dash style
*/
public static final int LineDashGEL = 7;
public static final int PEN_DASH = 7;
/**
* long dash style
*/
public static final int LineLongDashGEL = 8;
public static final int PEN_LONGDASHGEL = 8;
/**
* dash short dash
*/
public static final int LineDashDotGEL = 9;
public static final int PEN_DASHDOTGEL = 9;
/**
* long dash short dash
*/
public static final int LineLongDashDotGEL = 10;
public static final int PEN_LONGDASHDOTGEL = 10;
/**
* long dash short dash short dash
*/
public static final int LineLongDashDotDotGEL = 11;
public static final int PEN_LONGDASHDOTDOTGEL = 11;

/**
* Decoration of the end of line,
* reserved in API but not supported.
* Single line (of width lineWidth)
*/

public static final int LINE_SIMPLE = 0;
/**
* Line ends at end point
* Double lines of equal width
*/
public static final int EndCapFlat = 0;
public static final int LINE_DOUBLE = 1;
/**
* Rounded ends - the default
* Double lines, one thick, one thin
*/
public static final int EndCapRound = 1;
public static final int LINE_THICKTHIN = 2;
/**
* Square protrudes by half line width
* Double lines, reverse order
*/
public static final int EndCapSquare = 2;
public static final int LINE_THINTHICK = 3;
/**
* Three lines, thin, thick, thin
*/
public static final int LINE_TRIPLE = 4;


protected Line(EscherContainerRecord escherRecord, Shape parent){
super(escherRecord, parent);
Expand All @@ -111,7 +114,13 @@ protected EscherContainerRecord createSpContainer(boolean isChild){
//set default properties for a line
EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);

opt.sortProperties();
//default line properties
setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, 0x10000);
setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);
setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);

return spcont;
}
Expand Down
12 changes: 12 additions & 0 deletions src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.apache.poi.hslf.model;

/**
* The superclass of all master sheets - Slide masters, Notes masters, etc.
*
* For now it's empty. When we understand more about masters in ppt we will add the common functionality here.
*
* @author Yegor Kozlov
*/
public abstract class MasterSheet extends Sheet {

}
88 changes: 69 additions & 19 deletions src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.awt.geom.PathIterator;
import java.text.AttributedCharacterIterator;
import java.util.Map;
import java.util.ArrayList;

import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.hslf.usermodel.RichTextRun;

/**
* Translates Graphics2D calls into PowerPoint.
Expand All @@ -45,9 +47,9 @@ public class PPGraphics2D extends Graphics2D {
private Color foreground;
private Color background = Color.white;
private Shape clip;

int count = 0;
/**
* Construct an powerpoint Graphics object.
* Construct Java Graphics object which translates graphic calls in ppt drawing layer.
*
* @param group The shape group to write the graphics calls into.
*/
Expand Down Expand Up @@ -106,8 +108,11 @@ public void setTransform(AffineTransform trans) {

public void draw(Shape shape){
if(clip != null) {
if (!clip.getBounds().contains(transform.createTransformedShape(shape).getBounds())) {
//return;
java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
if (bounds.width == 0) bounds.width = 1;
if (bounds.height == 0) bounds.height = 1;
if (!clip.getBounds().contains(bounds)) {
return;
}
}

Expand All @@ -123,6 +128,8 @@ public void draw(Shape shape){
if (stroke instanceof BasicStroke){
BasicStroke bs = (BasicStroke)stroke;
line.setLineWidth(bs.getLineWidth());
float[] dash = bs.getDashArray();
if (dash != null) line.setLineDashing(Line.PEN_DASH);
}
if(getColor() != null) line.setLineColor(getColor());
if (type == PathIterator.SEG_LINETO) {
Expand All @@ -139,24 +146,26 @@ public void draw(Shape shape){
}

public void drawString(String string, float x, float y){

TextBox txt = new TextBox(group);
txt.getTextRun().supplySlideShow(group.getSheet().getSlideShow());
txt.getTextRun().setSheet(group.getSheet());
txt.setText(string);

RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
rt.setFontSize(font.getSize());
rt.setFontName(font.getFamily());

if(getColor() != null) rt.setFontColor(getColor());
if (font.isBold()) rt.setBold(true);
if (font.isItalic()) rt.setItalic(true);

txt.setMarginBottom(0);
txt.setMarginTop(0);
txt.setMarginLeft(0);
txt.setMarginRight(0);
txt.setText(string);
txt.setWordWrap(TextBox.WrapNone);

if (font != null){
txt.setFontSize(font.getSize());
txt.setFontName(font.getName());
if(getColor() != null) txt.setFontColor(getColor());
if (font.isBold()) txt.setBold(true);
if (font.isItalic()) txt.setItalic(true);
}

txt.resizeToFitText();

if (!"".equals(string)) txt.resizeToFitText();
int height = (int)txt.getAnchor().getHeight();

/*
Expand All @@ -166,15 +175,57 @@ public void drawString(String string, float x, float y){
*/
txt.moveTo((int)x, (int)(y - height));

group.addShape(txt);
if(clip != null) {
if (!clip.getBounds().contains(txt.getAnchor())) {
;//return;
}
}
group.addShape(txt);
}

public void fill(Shape shape){
if(clip != null) {
java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
if (bounds.width == 0) bounds.width = 1;
if (bounds.height == 0) bounds.height = 1;
if (!clip.getBounds().contains(bounds)) {
return;
}
}
PathIterator it = shape.getPathIterator(transform);
ArrayList pnt = new ArrayList();
double[] coords = new double[6];
while(!it.isDone()){
int type = it.currentSegment(coords);
if (type != PathIterator.SEG_CLOSE) {
pnt.add(new Point((int)coords[0], (int)coords[1]));
}
it.next();
}
int[] xPoints= new int[pnt.size()];
int[] yPoints= new int[pnt.size()];
for (int i = 0; i < pnt.size(); i++) {
Point p = (Point)pnt.get(i);
xPoints[i] = p.x;
yPoints[i] = p.y;
}

AutoShape r = new AutoShape(ShapeTypes.Rectangle);
if (paint instanceof Color){
Color color = (Color)paint;
r.setFillColor(color);
}
if(getColor() != null) r.setLineColor(getColor());
if (stroke instanceof BasicStroke){
BasicStroke bs = (BasicStroke)stroke;
r.setLineWidth(bs.getLineWidth());
float[] dash = bs.getDashArray();
if (dash != null) r.setLineDashing(Line.PEN_DASH);
}

throw new RuntimeException("Not implemented");
java.awt.Rectangle bounds = transform.createTransformedShape(shape).getBounds();
r.setAnchor(bounds);
group.addShape(r);
}

public void translate(int x, int y) {
Expand Down Expand Up @@ -458,5 +509,4 @@ public void setRenderingHints(Map map) {
public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) {
throw new RuntimeException("Not implemented");
}

}
22 changes: 11 additions & 11 deletions src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ public static Shape createShape(EscherContainerRecord spContainer, Shape parent)

int type = spRecord.getOptions() >> 4;
switch (type){
case ShapeTypes.Rectangle:
EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
if (txtbox == null) shape = new AutoShape(spContainer, parent);
else{
if(Shape.getEscherChild(spContainer, EscherClientDataRecord.RECORD_ID) != null )
shape = new Placeholder(spContainer, parent);
else
shape = new TextBox(spContainer, parent);
}
break;
case ShapeTypes.TextBox:
shape = new TextBox(spContainer, parent);
break;
case ShapeTypes.Rectangle:
EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
if (txtbox == null)
shape = new AutoShape(spContainer, parent);
else
shape = new TextBox(spContainer, parent);
break;
case ShapeTypes.PictureFrame:
shape = new Picture(spContainer, parent);
break;
case ShapeTypes.Line:
shape = new Line(spContainer, parent);
break;
case ShapeTypes.NotPrimitive:
shape = new ShapeGroup(spContainer, parent);
if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)
shape = new ShapeGroup(spContainer, parent);
else
shape = new AutoShape(spContainer, parent);
break;
default:
shape = new AutoShape(spContainer, parent);
Expand Down
25 changes: 17 additions & 8 deletions src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ public void setAnchor(java.awt.Rectangle anchor){
LittleEndian.putInt(header, 4, 8);
clientAnchor.fillFields(header, 0, null);

clientAnchor.setFlag((short)anchor.y);
clientAnchor.setCol1((short)anchor.x);
clientAnchor.setDx1((short)(anchor.width + anchor.x));
clientAnchor.setRow1((short)(anchor.height + anchor.y));
clientAnchor.setFlag((short)(anchor.y*MASTER_DPI/POINT_DPI));
clientAnchor.setCol1((short)(anchor.x*MASTER_DPI/POINT_DPI));
clientAnchor.setDx1((short)((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI));
clientAnchor.setRow1((short)((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI));

EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);

spgr.setRectX1(anchor.x);
spgr.setRectY1(anchor.y);
spgr.setRectX2(anchor.x + anchor.width);
spgr.setRectY2(anchor.y + anchor.height);
spgr.setRectX1(anchor.x*MASTER_DPI/POINT_DPI);
spgr.setRectY1(anchor.y*MASTER_DPI/POINT_DPI);
spgr.setRectX2((anchor.x + anchor.width)*MASTER_DPI/POINT_DPI);
spgr.setRectY2((anchor.y + anchor.height)*MASTER_DPI/POINT_DPI);
}

/**
Expand Down Expand Up @@ -145,6 +145,15 @@ protected EscherContainerRecord createSpContainer(boolean isChild) {
*/
public void addShape(Shape shape){
_escherContainer.addChildRecord(shape.getSpContainer());

Sheet sheet = getSheet();
shape.setSheet(sheet);
shape.afterInsert(sheet);

if(shape instanceof TextBox) {
TextBox tbox = (TextBox)shape;
getSheet().getPPDrawing().addTextboxWrapper(tbox._txtbox);
}
}

/**
Expand Down
16 changes: 15 additions & 1 deletion src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,18 @@ public void addShape(Shape shape){
ppdrawing.addTextboxWrapper(tbox._txtbox);
}
}
}

/**
* Return the master sheet .
*/
public MasterSheet getMasterSheet(){
return null;
}

/**
* Color scheme for this sheet.
*/
public ColorSchemeAtom getColorScheme(){
return null;
}
}
Loading

0 comments on commit 5f167f0

Please sign in to comment.