View | Details | Raw Unified | Return to bug 39256
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (-7 / +24 lines)
Lines 401-407 Link Here
401
	_notes = new Notes[notesV.size()];
401
	_notes = new Notes[notesV.size()];
402
	for(int i=0; i<_notes.length; i++) {
402
	for(int i=0; i<_notes.length; i++) {
403
		_notes[i] = (Notes)notesV.get(i);
403
		_notes[i] = (Notes)notesV.get(i);
404
		
404
        _notes[i].setSlideShow(this);
405
405
		// Now supply ourselves to all the rich text runs
406
		// Now supply ourselves to all the rich text runs
406
		//  of this note's TextRuns
407
		//  of this note's TextRuns
407
		TextRun[] trs = _notes[i].getTextRuns(); 
408
		TextRun[] trs = _notes[i].getTextRuns(); 
Lines 418-423 Link Here
418
	_slides = new Slide[slidesV.size()];
419
	_slides = new Slide[slidesV.size()];
419
	for(int i=0; i<_slides.length; i++) {
420
	for(int i=0; i<_slides.length; i++) {
420
		_slides[i] = (Slide)slidesV.get(i);
421
		_slides[i] = (Slide)slidesV.get(i);
422
        _slides[i].setSlideShow(this);
421
423
422
		// Now supply ourselves to all the rich text runs
424
		// Now supply ourselves to all the rich text runs
423
		//  of this slide's TextRuns
425
		//  of this slide's TextRuns
Lines 474-499 Link Here
474
	/**
476
	/**
475
	 * Returns all the pictures attached to the SlideShow
477
	 * Returns all the pictures attached to the SlideShow
476
	 */
478
	 */
477
	public PictureData[] getPictures() throws IOException {
479
	public PictureData[] getPictureData() {
478
		return _hslfSlideShow.getPictures();
480
		return _hslfSlideShow.getPictures();
479
	}
481
	}
480
	
482
	
481
	/**
483
	/**
482
	 * Return the current page size
484
	 * Return the current page size in points
483
	 */
485
	 */
484
	public Dimension getPageSize(){
486
	public Dimension getPageSize(){
485
		DocumentAtom docatom = _documentRecord.getDocumentAtom();
487
		DocumentAtom docatom = _documentRecord.getDocumentAtom();
486
		return new Dimension((int)docatom.getSlideSizeX(), (int)docatom.getSlideSizeY());
488
        int pgx = (int)docatom.getSlideSizeX()*Shape.POINT_DPI/Shape.MASTER_DPI;
489
        int pgy = (int)docatom.getSlideSizeY()*Shape.POINT_DPI/Shape.MASTER_DPI;
490
		return new Dimension(pgx, pgy);
487
	}
491
	}
488
	
492
493
    /**
494
     * Chage the page size
495
     *
496
     * @param pgsize page size (in points)
497
     */
498
    public void setPageSize(Dimension pgsize){
499
        DocumentAtom docatom = _documentRecord.getDocumentAtom();
500
        docatom.setSlideSizeX(pgsize.width*Shape.MASTER_DPI/Shape.POINT_DPI);
501
        docatom.setSlideSizeY(pgsize.height*Shape.MASTER_DPI/Shape.POINT_DPI);
502
    }
503
    
489
	/**
504
	/**
490
	 * Helper method for usermodel: Get the font collection
505
	 * Helper method for usermodel: Get the font collection
491
	 */
506
	 */
492
	protected FontCollection getFontCollection() { return _fonts; }
507
	protected FontCollection getFontCollection() { return _fonts; }
493
	/**
508
509
    /**
494
	 * Helper method for usermodel: Get the document record
510
	 * Helper method for usermodel: Get the document record
495
	 */
511
	 */
496
	protected Document getDocumentRecord() { return _documentRecord; }
512
	public Document getDocumentRecord() { return _documentRecord; }
497
513
498
	
514
	
499
	/* ===============================================================
515
	/* ===============================================================
Lines 607-612 Link Here
607
  		usr.setLastViewType((short)UserEditAtom.LAST_VIEW_SLIDE_VIEW);
623
  		usr.setLastViewType((short)UserEditAtom.LAST_VIEW_SLIDE_VIEW);
608
  		
624
  		
609
  		// All done and added
625
  		// All done and added
626
        slide.setSlideShow(this);
610
  		return slide;
627
  		return slide;
611
	}
628
	}
612
629
(-)src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java (-2 / +22 lines)
Lines 25-30 Link Here
25
/**
25
/**
26
 * A class that represents the image data contained in the Presentation.
26
 * A class that represents the image data contained in the Presentation.
27
 *
27
 *
28
 *
28
 *  @author Yegor Kozlov
29
 *  @author Yegor Kozlov
29
 */
30
 */
Lines 35-40 Link Here
35
	*/
36
	*/
36
	public static final int HEADER_SIZE = 25;
37
	public static final int HEADER_SIZE = 25;
38
    protected static final int JPEG_HEADER = -266516832;
39
    protected static final int PNG_HEADER = -266441216;
40
37
	/**
41
	/**
38
	* Binary data of the picture
42
	* Binary data of the picture
39
	*/
43
	*/
Lines 118-129 Link Here
118
	*/
122
	*/
119
	public void setType(int format){
123
	public void setType(int format){
120
        switch (format){
124
        switch (format){
121
            case Picture.JPEG: LittleEndian.putInt(header, 0, -266516832); break;
125
            case Picture.JPEG: LittleEndian.putInt(header, 0, PictureData.JPEG_HEADER); break;
122
            case Picture.PNG: LittleEndian.putInt(header, 0, -266441216); break;
126
            case Picture.PNG: LittleEndian.putInt(header, 0, PictureData.PNG_HEADER); break;
123
        }
127
        }
124
	}
128
	}
125
    /**
129
    /**
130
     * Returns type of this picture.
131
     * Must be one of the static constans defined in the <code>Picture<code> class.
132
     *
133
     * @return type of this picture.
134
     */
135
    public int getType(){
136
        int format = 0;
137
        int val = LittleEndian.getInt(header, 0);
138
        switch (val){
139
            case PictureData.JPEG_HEADER: format = Picture.JPEG; break;
140
            case PictureData.PNG_HEADER: format = Picture.PNG; break;
141
        }
142
        return format;
143
    }
144
145
    /**
126
     * Returns the header of the Picture
146
     * Returns the header of the Picture
127
     *
147
     *
128
     * @return the header of the Picture
148
     * @return the header of the Picture
(-)src/scratchpad/src/org/apache/poi/hslf/model/Shape.java (-19 / +87 lines)
Lines 22-36 Link Here
22
import java.util.Iterator;
22
import java.util.Iterator;
23
/**
23
/**
24
 *  <p>
24
  * Represents a Shape which is the elemental object that composes a drawing.
25
  * Represents a Shape which is the elemental object that composes a drawing.
26
 *  This class is a wrapper around EscherSpContainer which holds all information
27
 *  about a shape in PowerPoint document.
28
 *  </p>
29
 *  <p>
30
 *  When you add a shape, you usually specify the dimensions of the shape and the position
31
 *  of the upper­left corner of the bounding box for the shape relative to the upper­left
32
 *  corner of the page, worksheet, or slide. Distances in the drawing layer are measured
33
 *  in points (72 points = 1 inch).
34
 *  </p>
35
 * <p>
25
  *
36
  *
26
  * @author Yegor Kozlov
37
  * @author Yegor Kozlov
27
 */
38
 */
28
public abstract class Shape {
39
public abstract class Shape {
40
    /**
41
     * In Escher absolute distances are specified in
42
     * English Metric Units (EMUs), occasionally referred to as A units;
43
     * there are 360000 EMUs per centimeter, 914400 EMUs per inch, 12700 EMUs per point.
44
     */
45
    public static final int EMU_PER_INCH = 914400;
29
    public static final int EMU_PER_POINT = 12700;
46
    public static final int EMU_PER_POINT = 12700;
47
    public static final int EMU_PER_CENTIMETER = 360000;
30
    /**
48
    /**
49
     * Master DPI (576 pixels per inch).
50
     * Used by the reference coordinate system in PowerPoint.
51
     */
52
    public static final int MASTER_DPI = 576;
53
54
    /**
55
     * Pixels DPI (96 pixels per inch)
56
     */
57
    public static final int PIXEL_DPI = 96;
58
59
    /**
60
     * Points DPI (72 pixels per inch)
61
     */
62
    public static final int POINT_DPI = 72;
63
64
    /**
31
     * Either EscherSpContainer or EscheSpgrContainer record
65
     * Either EscherSpContainer or EscheSpgrContainer record
32
     * which holds information about this shape.
66
     * which holds information about this shape.
33
     */
67
     */
Lines 43-48 Link Here
43
    protected Shape _parent;
77
    protected Shape _parent;
44
    /**
78
    /**
79
     * The <code>Sheet</code> this shape belongs to
80
     */
81
    protected Sheet _sheet;
82
83
    /**
45
     * Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
84
     * Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
46
     *
85
     *
47
     * @param escherRecord       <code>EscherSpContainer</code> container which holds information about this shape
86
     * @param escherRecord       <code>EscherSpContainer</code> container which holds information about this shape
Lines 86-110 Link Here
86
        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
125
        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
87
            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
126
            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
88
            anchor = new java.awt.Rectangle();
127
            anchor = new java.awt.Rectangle();
89
            anchor.x = rec.getDx1();
128
            anchor.x = rec.getDx1()*POINT_DPI/MASTER_DPI;
90
            anchor.y = rec.getDy1();
129
            anchor.y = rec.getDy1()*POINT_DPI/MASTER_DPI;
91
            anchor.width = rec.getDx2() - anchor.x;
130
            anchor.width = (rec.getDx2() - anchor.x)*POINT_DPI/MASTER_DPI;
92
            anchor.height = rec.getDy2() - anchor.y;
131
            anchor.height = (rec.getDy2() - anchor.y)*POINT_DPI/MASTER_DPI;
93
        }
132
        }
94
        else {
133
        else {
95
            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
134
            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
96
            anchor = new java.awt.Rectangle();
135
            anchor = new java.awt.Rectangle();
97
            anchor.y = rec.getFlag();
136
            anchor.y = rec.getFlag()*POINT_DPI/MASTER_DPI;
98
            anchor.x = rec.getCol1();
137
            anchor.x = rec.getCol1()*POINT_DPI/MASTER_DPI;
99
            anchor.width = rec.getDx1() - anchor.x;
138
            anchor.width = (rec.getDx1() - rec.getCol1())*POINT_DPI/MASTER_DPI;
100
            anchor.height = rec.getRow1() - anchor.y;
139
            anchor.height = (rec.getRow1() - rec.getFlag())*POINT_DPI/MASTER_DPI;
101
        }
140
        }
102
        return anchor;
141
        return anchor;
103
    }
142
    }
104
    /**
143
    /**
105
     * Sets the anchor (the bounding box rectangle) of this shape.
144
     * Sets the anchor (the bounding box rectangle) of this shape.
106
     * All coordinates should be expressed in Master units (576 dpi).
145
     * All coordinates should be expressed in poitns (72 dpi).
107
     *
146
     *
108
     * @param anchor new anchor
147
     * @param anchor new anchor
109
     */
148
     */
Lines 113-129 Link Here
113
        int flags = spRecord.getFlags();
152
        int flags = spRecord.getFlags();
114
        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
153
        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
115
            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
154
            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
116
            rec.setDx1(anchor.x);
155
            rec.setDx1(anchor.x*MASTER_DPI/POINT_DPI);
117
            rec.setDy1(anchor.y);
156
            rec.setDy1(anchor.y*MASTER_DPI/POINT_DPI);
118
            rec.setDx2(anchor.width + anchor.x);
157
            rec.setDx2((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI);
119
            rec.setDy2(anchor.height + anchor.y);
158
            rec.setDy2((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI);
120
        }
159
        }
121
        else {
160
        else {
122
            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
161
            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
123
            rec.setFlag((short)anchor.y);
162
            rec.setFlag((short)(anchor.y*MASTER_DPI/POINT_DPI));
124
            rec.setCol1((short)anchor.x);
163
            rec.setCol1((short)(anchor.x*MASTER_DPI/POINT_DPI));
125
            rec.setDx1((short)(anchor.width + anchor.x));
164
            rec.setDx1((short)((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI));
126
            rec.setRow1((short)(anchor.height + anchor.y));
165
            rec.setRow1((short)((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI));
127
        }
166
        }
128
    }
167
    }
Lines 171-181 Link Here
171
    }
210
    }
172
    /**
211
    /**
173
     * Set an escher property in the opt record.
212
     * Set an escher property for this shape.
174
     *
213
     *
175
     * @param opt       The opt record to set the properties to.
214
     * @param opt       The opt record to set the properties to.
176
     * @param propId    The id of the property. One of the constants defined in EscherOptRecord.
215
     * @param propId    The id of the property. One of the constants defined in EscherOptRecord.
177
     * @param value     value of the property
216
     * @param value     value of the property. If value = -1 then the property is removed.
178
     */
217
     */
179
     public static void setEscherProperty(EscherOptRecord opt, short propId, int value){
218
     public static void setEscherProperty(EscherOptRecord opt, short propId, int value){
180
        java.util.List props = opt.getEscherProperties();
219
        java.util.List props = opt.getEscherProperties();
Lines 198-201 Link Here
198
    public EscherContainerRecord getSpContainer(){
237
    public EscherContainerRecord getSpContainer(){
199
        return _escherContainer;
238
        return _escherContainer;
200
    }
239
    }
240
241
    /**
242
     * Event which fires when a shape is inserted in the sheet.
243
     * In some cases we need to propagate changes to upper level containers.
244
     * <br>
245
     * Default implementation does nothing.
246
     *
247
     * @param sh - owning shape
248
     */
249
    protected void afterInsert(Sheet sh){
250
251
    }
252
253
    /**
254
     *  @return the <code>SlideShow</code> this shape belongs to
255
     */
256
    public Sheet getSheet(){
257
        return _sheet;
258
    }
259
260
    /**
261
     * Assign the <code>SlideShow</code> this shape belongs to
262
     *
263
     * @param sheet owner of this shape
264
     */
265
    public void setSheet(Sheet sheet){
266
        _sheet = sheet;
267
    }
268
201
}
269
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/Rectangle.java (-12 / +4 lines)
Lines 21-59 Link Here
21
import java.awt.*;
21
import java.awt.*;
22
/**
22
/**
23
 * Represents a line in a PowerPoint drawing
23
 * Represents a rectangle shae in a PowerPoint drawing
24
 *
24
 *
25
 *  @author Yegor Kozlov
25
 *  @author Yegor Kozlov
26
 */
26
 */
27
public class Rectangle extends SimpleShape {
27
public class Rectangle extends TextBox {
28
    protected Rectangle(EscherContainerRecord escherRecord, Shape parent){
28
    protected Rectangle(EscherContainerRecord escherRecord, Shape parent){
29
        super(escherRecord, parent);
29
        super(escherRecord, parent);
30
    }
30
    }
31
    public Rectangle(Shape parent){
31
    public Rectangle(Shape parent){
32
        super(null, parent);
32
        super(parent);
33
        _escherContainer = createSpContainer(parent instanceof ShapeGroup);
34
    }
33
    }
35
    public Rectangle(){
34
    public Rectangle(){
36
        this(null);
35
        super();
37
    }
36
    }
38
    protected EscherContainerRecord createSpContainer(boolean isChild){
37
    protected EscherContainerRecord createSpContainer(boolean isChild){
39
        EscherContainerRecord spcont = super.createSpContainer(isChild);
38
        EscherContainerRecord spcont = super.createSpContainer(isChild);
40
        spcont.setOptions((short)15);
41
        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
39
        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
42
        short type = (ShapeTypes.Rectangle << 4) + 2;
40
        short type = (ShapeTypes.Rectangle << 4) + 2;
43
        spRecord.setOptions(type);
41
        spRecord.setOptions(type);
44
        //set default properties for a rectangle
45
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
46
47
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 4));
48
        opt.sortProperties();
49
50
        return spcont;
42
        return spcont;
51
    }
43
    }
(-)src/scratchpad/src/org/apache/poi/hslf/model/ShapeTypes.java (-5 / +5 lines)
Lines 82-90 Link Here
82
    public static final int Chevron = 55;
82
    public static final int Chevron = 55;
83
    public static final int Pentagon = 56;
83
    public static final int Pentagon = 56;
84
    public static final int NoSmoking = 57;
84
    public static final int NoSmoking = 57;
85
    public static final int Seal8 = 58;
85
    public static final int Star8 = 58;
86
    public static final int Seal16 = 59;
86
    public static final int Star16 = 59;
87
    public static final int Seal32 = 60;
87
    public static final int Star32 = 60;
88
    public static final int WedgeRectCallout = 61;
88
    public static final int WedgeRectCallout = 61;
89
    public static final int WedgeRRectCallout = 62;
89
    public static final int WedgeRRectCallout = 62;
90
    public static final int WedgeEllipseCallout = 63;
90
    public static final int WedgeEllipseCallout = 63;
Lines 116-122 Link Here
116
    public static final int LeftUpArrow = 89;
116
    public static final int LeftUpArrow = 89;
117
    public static final int BentUpArrow = 90;
117
    public static final int BentUpArrow = 90;
118
    public static final int BentArrow = 91;
118
    public static final int BentArrow = 91;
119
    public static final int Seal24 = 92;
119
    public static final int Star24 = 92;
120
    public static final int StripedRightArrow = 93;
120
    public static final int StripedRightArrow = 93;
121
    public static final int NotchedRightArrow = 94;
121
    public static final int NotchedRightArrow = 94;
122
    public static final int BlockArc = 95;
122
    public static final int BlockArc = 95;
Lines 211-217 Link Here
211
    public static final int Moon = 184;
211
    public static final int Moon = 184;
212
    public static final int BracketPair = 185;
212
    public static final int BracketPair = 185;
213
    public static final int BracePair = 186;
213
    public static final int BracePair = 186;
214
    public static final int Seal4 = 187;
214
    public static final int Star4 = 187;
215
    public static final int DoubleWave = 188;
215
    public static final int DoubleWave = 188;
216
    public static final int ActionButtonBlank = 189;
216
    public static final int ActionButtonBlank = 189;
217
    public static final int ActionButtonHome = 190;
217
    public static final int ActionButtonHome = 190;
(-)src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java (-1 / +29 lines)
Lines 139-144 Link Here
139
    }
139
    }
140
    public void drawString(String string, float x, float y){
140
    public void drawString(String string, float x, float y){
141
142
         TextBox txt = new TextBox(group);
143
         txt.setMarginBottom(0);
144
         txt.setMarginTop(0);
145
         txt.setMarginLeft(0);
146
         txt.setMarginRight(0);
147
         txt.setText(string);
148
         txt.setWordWrap(TextBox.WrapNone);
149
150
         if (font != null){
151
             txt.setFontSize(font.getSize());
152
             txt.setFontName(font.getName());
153
             //if(getColor() != null) txt.setFontColor(getColor());
154
             if (font.isBold()) txt.setBold(true);
155
             if (font.isItalic()) txt.setItalic(true);
156
         }
157
158
         txt.resizeToFitText();
159
         int height = (int)txt.getAnchor().getHeight();
160
161
         /*
162
           In powerpoint anchor of a shape is its top left corner.
163
           Java graphics sets string coordinates by the baseline of the first character
164
           so we need to shift down by the height of the textbox
165
         */
166
        txt.moveTo((int)x, (int)(y - height));
167
168
        group.addShape(txt);
141
    }
169
    }
142
    public void fill(Shape shape){
170
    public void fill(Shape shape){
Lines 212-218 Link Here
212
    }
240
    }
213
    public void drawOval(int x, int y, int width, int height) {
241
    public void drawOval(int x, int y, int width, int height) {
214
        Ellipse ellipse = new Ellipse();
242
        AutoShape ellipse = new AutoShape(ShapeTypes.Ellipse);
215
        ellipse.setAnchor(new java.awt.Rectangle(x-width/2, y-height/2, width, height));
243
        ellipse.setAnchor(new java.awt.Rectangle(x-width/2, y-height/2, width, height));
216
        if (stroke instanceof BasicStroke){
244
        if (stroke instanceof BasicStroke){
217
            BasicStroke bs = (BasicStroke)stroke;
245
            BasicStroke bs = (BasicStroke)stroke;
(-)src/scratchpad/src/org/apache/poi/hslf/model/Line.java (-2 / +1 lines)
Lines 107-119 Link Here
107
        EscherContainerRecord spcont = super.createSpContainer(isChild);
107
        EscherContainerRecord spcont = super.createSpContainer(isChild);
108
        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
108
        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
109
        short type = (ShapeTypes.Line << 4) + 2;
109
        short type = (ShapeTypes.Line << 4) | 0x2;
110
        spRecord.setOptions(type);
110
        spRecord.setOptions(type);
111
        //set default properties for a line
111
        //set default properties for a line
112
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
112
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
113
        //opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 4));
114
        opt.sortProperties();
113
        opt.sortProperties();
115
        return spcont;
114
        return spcont;
(-)src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java (-5 / +33 lines)
Lines 23-28 Link Here
23
import org.apache.poi.ddf.EscherDgRecord;
23
import org.apache.poi.ddf.EscherDgRecord;
24
import org.apache.poi.ddf.EscherRecord;
24
import org.apache.poi.ddf.EscherRecord;
25
import org.apache.poi.hslf.record.*;
25
import org.apache.poi.hslf.record.*;
26
import org.apache.poi.hslf.usermodel.SlideShow;
26
27
27
import java.util.ArrayList;
28
import java.util.ArrayList;
28
import java.util.Iterator;
29
import java.util.Iterator;
Lines 39-44 Link Here
39
public abstract class Sheet
40
public abstract class Sheet
40
{
41
{
41
  /**
42
  /**
43
     * The <code>SlideShow</code> this sheet belongs to
44
     */
45
    private SlideShow _ppt;
46
47
  /**
42
   * Returns an array of all the TextRuns in the sheet.
48
   * Returns an array of all the TextRuns in the sheet.
43
   */
49
   */
44
  public abstract TextRun[] getTextRuns();
50
  public abstract TextRun[] getTextRuns();
Lines 60-66 Link Here
60
   */
66
   */
61
  protected abstract PPDrawing getPPDrawing();
67
  protected abstract PPDrawing getPPDrawing();
62
68
63
  /**
69
    /**
64
   * For a given PPDrawing, grab all the TextRuns
70
   * For a given PPDrawing, grab all the TextRuns
65
   */
71
   */
66
  public static TextRun[] findTextRuns(PPDrawing ppdrawing) {
72
  public static TextRun[] findTextRuns(PPDrawing ppdrawing) {
Lines 140-147 Link Here
140
	for (Iterator it = ch.iterator(); it.hasNext();) {
146
	for (Iterator it = ch.iterator(); it.hasNext();) {
141
		EscherRecord rec = (EscherRecord)it.next();
147
		EscherRecord rec = (EscherRecord)it.next();
142
		if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
148
		if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
143
				spgr = (EscherContainerRecord)rec;
149
			spgr = (EscherContainerRecord)rec;
144
				break;
150
			break;
145
		}
151
		}
146
	}
152
	}
147
	ch = spgr.getChildRecords();
153
	ch = spgr.getChildRecords();
Lines 149-155 Link Here
149
	ArrayList shapes = new ArrayList();
155
	ArrayList shapes = new ArrayList();
150
	for (int i=1;i<ch.size();i++) {
156
	for (int i=1;i<ch.size();i++) {
151
		EscherContainerRecord sp = (EscherContainerRecord)ch.get(i);
157
		EscherContainerRecord sp = (EscherContainerRecord)ch.get(i);
152
		shapes.add(ShapeFactory.createShape(sp, null));
158
        Shape sh = ShapeFactory.createShape(sp, null);
159
        sh.setSheet(this);
160
		shapes.add(sh);
153
	}
161
	}
154
	
162
	
155
	return (Shape[])shapes.toArray(new Shape[shapes.size()]);
163
	return (Shape[])shapes.toArray(new Shape[shapes.size()]);
Lines 169-173 Link Here
169
177
170
	EscherDgRecord dg = (EscherDgRecord)Shape.getEscherChild(dgContainer, EscherDgRecord.RECORD_ID);
178
	EscherDgRecord dg = (EscherDgRecord)Shape.getEscherChild(dgContainer, EscherDgRecord.RECORD_ID);
171
	dg.setNumShapes(dg.getNumShapes()+1);
179
	dg.setNumShapes(dg.getNumShapes()+1);
180
181
    shape.setSheet(this);
182
    shape.afterInsert(this);
172
  }
183
  }
173
} 
184
185
    /**
186
     *  @return the <code>SlideShow</code> this sheet belongs to
187
     */
188
     public SlideShow getSlideShow(){
189
        return _ppt;
190
    }
191
192
    /**
193
     * Assign the <code>SlideShow</code> this sheet belongs to
194
     *
195
     * @param ppt owner of this slide
196
     */
197
    public void setSlideShow(SlideShow ppt){
198
        _ppt = ppt;
199
    }
200
201
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java (-4 / +6 lines)
Lines 25-30 Link Here
25
 */
25
 */
26
public class ShapeFactory {
26
public class ShapeFactory {
27
    /**
28
     * Create a new shape from the data provided.
29
     */
27
    public static Shape createShape(EscherContainerRecord spContainer, Shape parent){
30
    public static Shape createShape(EscherContainerRecord spContainer, Shape parent){
28
        if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
31
        if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
29
            return new ShapeGroup(spContainer, parent);
32
            return new ShapeGroup(spContainer, parent);
Lines 36-41 Link Here
36
        int type = spRecord.getOptions() >> 4;
39
        int type = spRecord.getOptions() >> 4;
37
        switch (type){
40
        switch (type){
38
            case ShapeTypes.TextBox:
41
            case ShapeTypes.TextBox:
42
                shape = new TextBox(spContainer, parent);
43
                break;
39
            case ShapeTypes.Rectangle:
44
            case ShapeTypes.Rectangle:
40
                shape = new Rectangle(spContainer, parent);
45
                shape = new Rectangle(spContainer, parent);
41
                break;
46
                break;
Lines 45-58 Link Here
45
            case ShapeTypes.Line:
50
            case ShapeTypes.Line:
46
                shape = new Line(spContainer, parent);
51
                shape = new Line(spContainer, parent);
47
                break;
52
                break;
48
            case ShapeTypes.Ellipse:
49
                shape = new Ellipse(spContainer, parent);
50
                break;
51
            case ShapeTypes.NotPrimitive:
53
            case ShapeTypes.NotPrimitive:
52
                shape = new ShapeGroup(spContainer, parent);
54
                shape = new ShapeGroup(spContainer, parent);
53
                break;
55
                break;
54
            default:
56
            default:
55
                shape = new SimpleShape(spContainer, parent);
57
                shape = new AutoShape(spContainer, parent);
56
                break;
58
                break;
57
        }
59
        }
58
        return shape;
60
        return shape;
(-)src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java (-2 / +2 lines)
Lines 273-280 Link Here
273
			
273
			
274
			TextPropCollection pCol = (TextPropCollection)pStyles.getFirst();
274
			TextPropCollection pCol = (TextPropCollection)pStyles.getFirst();
275
			TextPropCollection cCol = (TextPropCollection)cStyles.getFirst();
275
			TextPropCollection cCol = (TextPropCollection)cStyles.getFirst();
276
			pCol.updateTextSize(s.length());
276
			pCol.updateTextSize(s.length()+1);
277
			cCol.updateTextSize(s.length());
277
			cCol.updateTextSize(s.length()+1);
278
			
278
			
279
			// Recreate rich text run with first styling
279
			// Recreate rich text run with first styling
280
			_rtRuns[0] = new RichTextRun(this,0,s.length(), pCol, cCol);
280
			_rtRuns[0] = new RichTextRun(this,0,s.length(), pCol, cCol);
(-)src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java (-2 / +13 lines)
Lines 29-34 Link Here
29
 */
29
 */
30
public class SimpleShape extends Shape {
30
public class SimpleShape extends Shape {
31
    /**
32
     * Create a SimpleShape object and initialize it from the supplied Record container.
33
     *
34
     * @param escherRecord    <code>EscherSpContainer</code> container which holds information about this shape
35
     * @param parent    the parent of the shape
36
     */
31
    protected SimpleShape(EscherContainerRecord escherRecord, Shape parent){
37
    protected SimpleShape(EscherContainerRecord escherRecord, Shape parent){
32
        super(escherRecord, parent);
38
        super(escherRecord, parent);
33
    }
39
    }
Lines 102-113 Link Here
102
    }
108
    }
103
    /**
109
    /**
104
     * @return color of the line
110
     * @return color of the line. If color is not set returns <code>java.awt.Color.black</code>
105
     */
111
     */
106
    public Color getLineColor(){
112
    public Color getLineColor(){
107
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
113
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
108
        EscherRGBProperty prop = (EscherRGBProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);
114
        EscherRGBProperty prop = (EscherRGBProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);
109
        Color color = null;
115
        Color color = Color.black;
110
        if (prop != null){
116
        if (prop != null){
111
            Color swp = new Color(prop.getRgbColor());
117
            Color swp = new Color(prop.getRgbColor());
112
            color = new Color(swp.getBlue(), swp.getGreen(), swp.getRed());
118
            color = new Color(swp.getBlue(), swp.getGreen(), swp.getRed());
Lines 136-141 Link Here
136
        return prop == null ? Line.LineSolid : prop.getPropertyValue();
142
        return prop == null ? Line.LineSolid : prop.getPropertyValue();
137
    }
143
    }
144
    /**
145
     * The color used to fill this shape.
146
     *
147
     * @param color the background color
148
     */
138
    public void setFillColor(Color color){
149
    public void setFillColor(Color color){
139
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
150
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
140
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
151
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
(-)src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (-7 / +43 lines)
Lines 3-13 Link Here
3
import org.apache.poi.ddf.*;
3
import org.apache.poi.ddf.*;
4
import org.apache.poi.hslf.usermodel.PictureData;
4
import org.apache.poi.hslf.usermodel.PictureData;
5
import org.apache.poi.hslf.usermodel.SlideShow;
5
import org.apache.poi.hslf.usermodel.SlideShow;
6
import org.apache.poi.hslf.record.Document;
6
import javax.imageio.ImageIO;
7
import javax.imageio.ImageIO;
7
import java.awt.image.BufferedImage;
8
import java.awt.image.BufferedImage;
8
import java.io.ByteArrayInputStream;
9
import java.io.ByteArrayInputStream;
9
import java.io.IOException;
10
import java.io.IOException;
11
import java.util.List;
12
import java.util.Arrays;
10
/**
13
/**
Lines 122-137 Link Here
122
    }
125
    }
123
    /**
126
    /**
124
     * Set default size of the picture
127
     * Resize this picture to the default size.
128
     */
129
    public void setDefaultSize(){
130
        PictureData pict = getPictureData();
131
        try {
132
            BufferedImage img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
133
            setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));
134
        } catch (IOException e){
135
            throw new RuntimeException(e);
136
        }
137
    }
138
139
    /**
140
     * Returns the picture data for this picture.
125
     *
141
     *
126
     * @param ppt presentation which holds the picture
142
     * @return the picture data for this picture.
127
     */
143
     */
128
    public void setDefaultSize(SlideShow ppt) throws IOException {
144
    public PictureData getPictureData(){
129
        int idx = getPictureIndex();
145
        SlideShow ppt = getSheet().getSlideShow();
146
        PictureData[] pict = ppt.getPictureData();
147
        Document doc = ppt.getDocumentRecord();
148
        EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
149
        EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
130
        PictureData pict = ppt.getPictures()[idx-1];
150
        List lst = bstore.getChildRecords();
131
        BufferedImage img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
151
        int idx = getPictureIndex()-1;
152
        EscherBSERecord bse = (EscherBSERecord)lst.get(idx);
153
        for ( int i = 0; i < pict.length; i++ ) {
154
            if (Arrays.equals(bse.getUid(), pict[i].getUID())){
155
                return pict[i];
156
            }
157
        }
158
        return null;
159
    }
132
        setAnchor(new java.awt.Rectangle(0, 0, img.getWidth()*6, img.getHeight()*6));
160
    /**
161
     * By default set the orininal image size
162
     */
163
    protected void afterInsert(Sheet sh){
164
        java.awt.Rectangle anchor = getAnchor();
165
        if (anchor.equals(new java.awt.Rectangle())){
166
            setDefaultSize();
167
        }
133
    }
168
    }
169
134
}
170
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java (+10 lines)
Lines 27-37 Link Here
27
 */
27
 */
28
public class ShapeGroup extends Shape{
28
public class ShapeGroup extends Shape{
29
    /**
30
      * Create a new ShapeGroup. This constructor is used when a new shape is created.
31
      *
32
      */
29
    public ShapeGroup(){
33
    public ShapeGroup(){
30
        this(null, null);
34
        this(null, null);
31
        _escherContainer = createSpContainer(false);
35
        _escherContainer = createSpContainer(false);
32
    }
36
    }
37
    /**
38
      * Create a ShapeGroup object and initilize it from the supplied Record container.
39
      *
40
      * @param escherRecord       <code>EscherSpContainer</code> container which holds information about this shape
41
      * @param parent    the parent of the shape
42
      */
33
    protected ShapeGroup(EscherContainerRecord escherRecord, Shape parent){
43
    protected ShapeGroup(EscherContainerRecord escherRecord, Shape parent){
34
        super(escherRecord, parent);
44
        super(escherRecord, parent);
35
    }
45
    }
(-)src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java (-1 / +10 lines)
Lines 56-62 Link Here
56
56
57
	/* *************** record code follows ********************** */
57
	/* *************** record code follows ********************** */
58
58
59
	/** 
59
    public TextBytesAtom(){
60
        _header = new byte[8];
61
        LittleEndian.putUShort(_header, 0, 0);
62
        LittleEndian.putUShort(_header, 2, (int)_type);
63
        LittleEndian.putInt(_header, 4, 0);
64
65
        _text = new byte[]{};
66
    }
67
68
	/**
60
	 * For the TextBytes Atom
69
	 * For the TextBytes Atom
61
	 */
70
	 */
62
	protected TextBytesAtom(byte[] source, int start, int len) {
71
	protected TextBytesAtom(byte[] source, int start, int len) {
(-)src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java (+22 lines)
Lines 128-133 Link Here
128
	
128
	
129
	/* *************** record code follows ********************** */
129
	/* *************** record code follows ********************** */
130
130
131
    /**
132
     * Construct a new StyleTextPropAtom record
133
     */
134
    public StyleTextPropAtom(){
135
        _header = new byte[8];
136
        LittleEndian.putUShort(_header, 0, 0);
137
        LittleEndian.putUShort(_header, 2, (int)_type);
138
        LittleEndian.putInt(_header, 4, 20);
139
140
        rawContents = new byte[]{};
141
        reserved = new byte[]{};
142
143
        // Set empty linked lists, ready for when they call setParentTextSize
144
        TextPropCollection defaultParagraphTextProps = new TextPropCollection(0, (short)0);
145
        paragraphStyles = new LinkedList();
146
        paragraphStyles.add(defaultParagraphTextProps);
147
148
        TextPropCollection defaultCharacterTextProps = new TextPropCollection(0);
149
        charStyles = new LinkedList();
150
        charStyles.add(defaultCharacterTextProps);
151
    }
152
131
	/** 
153
	/** 
132
	 * For the Text Style Properties (StyleTextProp) Atom
154
	 * For the Text Style Properties (StyleTextProp) Atom
133
	 */
155
	 */
(-)src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java (-1 / +11 lines)
Lines 19-24 Link Here
19
package org.apache.poi.hslf.record;
19
package org.apache.poi.hslf.record;
20
20
21
import org.apache.poi.ddf.*;
21
import org.apache.poi.ddf.*;
22
import org.apache.poi.util.LittleEndian;
22
23
23
import java.io.IOException;
24
import java.io.IOException;
24
import java.io.OutputStream;
25
import java.io.OutputStream;
Lines 44-53 Link Here
44
	 */
45
	 */
45
	public EscherTextboxRecord getEscherRecord() { return _escherRecord; }
46
	public EscherTextboxRecord getEscherRecord() { return _escherRecord; }
46
47
48
    public EscherTextboxWrapper(){
49
        _escherRecord = new EscherTextboxRecord();
50
        _escherRecord.setRecordId(EscherTextboxRecord.RECORD_ID);
51
        _escherRecord.setOptions((short)15);
52
53
        _children = new Record[]{
54
        };
55
    }
56
47
	/** 
57
	/** 
48
	 * Creates the wrapper for the given DDF Escher Record and children
58
	 * Creates the wrapper for the given DDF Escher Record and children
49
	 */
59
	 */
50
	protected EscherTextboxWrapper(EscherTextboxRecord textbox) {
60
	public EscherTextboxWrapper(EscherTextboxRecord textbox) {
51
		_escherRecord = textbox;
61
		_escherRecord = textbox;
52
		_type = (long)_escherRecord.getRecordId();
62
		_type = (long)_escherRecord.getRecordId();
53
63
(-)src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java (+12 lines)
Lines 262-265 Link Here
262
			dgContainer
262
			dgContainer
263
		};
263
		};
264
	}
264
	}
265
266
    /**
267
     * If we add a new EscherTextbox we need to tell
268
     * about it to the owning <code>PPDrawing</code>.
269
     */
270
    public void addTextboxWrapper(EscherTextboxWrapper txtbox){
271
        EscherTextboxWrapper[] tw = new EscherTextboxWrapper[textboxWrappers.length + 1];
272
        System.arraycopy(textboxWrappers, 0, tw, 0, textboxWrappers.length);
273
        tw[textboxWrappers.length] = txtbox;
274
        textboxWrappers = tw;
275
    }
276
265
}
277
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java (-1 / +13 lines)
Lines 56-62 Link Here
56
56
57
	/* *************** record code follows ********************** */
57
	/* *************** record code follows ********************** */
58
58
59
	/** 
59
    /**
60
     * Construct a new TextHeaderAtom record
61
     */
62
    public TextHeaderAtom(){
63
        _header = new byte[8];
64
        LittleEndian.putUShort(_header, 0, 0);
65
        LittleEndian.putUShort(_header, 2, (int)_type);
66
        LittleEndian.putInt(_header, 4, 4);
67
68
        textType = OTHER_TYPE;
69
    }
70
71
	/**
60
	 * For the TextHeader Atom
72
	 * For the TextHeader Atom
61
	 */
73
	 */
62
	protected TextHeaderAtom(byte[] source, int start, int len) {
74
	protected TextHeaderAtom(byte[] source, int start, int len) {
(-)src/scratchpad/testcases/org/apache/poi/TestPOIDocument.java (-1 / +1 lines)
Lines 57-63 Link Here
57
		
57
		
58
		FileInputStream fisHWPF = new FileInputStream(filenameHWPF);
58
		FileInputStream fisHWPF = new FileInputStream(filenameHWPF);
59
		pfs2 = new POIFSFileSystem(fisHWPF);
59
		pfs2 = new POIFSFileSystem(fisHWPF);
60
		doc2 = new HWPFDocument(pfs2);
60
		//doc2 = new HWPFDocument(pfs2);
61
	}
61
	}
62
    
62
    
63
    public void testReadProperties() throws Exception {
63
    public void testReadProperties() throws Exception {
(-)src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java (-3 / +28 lines)
Lines 50-59 Link Here
50
            BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
50
            BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
51
            assertNotNull(img);
51
            assertNotNull(img);
52
            assertEquals(Picture.PNG, pict[i].getType());
52
        }
53
        }
53
        ppt.close();
54
        ppt.close();
54
    }
55
    }
56
    public void testReadPicturesForSlide() throws Exception {
57
58
        SlideShow ppt = new SlideShow(new HSLFSlideShow(filename));
59
60
        Slide[] slide = ppt.getSlides();
61
        for (int i = 0; i < slide.length; i++) {
62
            Slide sl = slide[i];
63
            Shape[] sh = sl.getShapes();
64
            for (int j = 0; j < sh.length; j++) {
65
                Shape shape = sh[j];
66
                if (shape instanceof Picture){
67
                    Picture picture = (Picture)shape;
68
69
                    PictureData pictdata = picture.getPictureData();
70
                    assertEquals(Picture.PNG, pictdata.getType());
71
72
                    //raw data.
73
                    byte[] data = pictdata.getData();
74
                    BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
75
                    assertNotNull(img);
76
                }
77
            }
78
79
        }
80
    }
81
55
    public void testSerializePictures() throws Exception {
82
    public void testSerializePictures() throws Exception {
56
        HSLFSlideShow ppt = new HSLFSlideShow(filename);
83
        HSLFSlideShow ppt = new HSLFSlideShow(filename);
57
        PictureData[] pict = ppt.getPictures();
84
        PictureData[] pict = ppt.getPictures();
Lines 78-89 Link Here
78
        idx = ppt.addPicture(new File(dirname + "/clock.jpg"), Picture.JPEG);
105
        idx = ppt.addPicture(new File(dirname + "/clock.jpg"), Picture.JPEG);
79
        slide = ppt.createSlide();
106
        slide = ppt.createSlide();
80
        pict = new Picture(idx);
107
        pict = new Picture(idx);
81
        pict.setDefaultSize(ppt);
82
        slide.addShape(pict);
108
        slide.addShape(pict);
83
        idx = ppt.addPicture(new File(dirname + "/painting.png"), Picture.PNG);
109
        idx = ppt.addPicture(new File(dirname + "/painting.png"), Picture.PNG);
84
        pict = new Picture(idx);
110
        pict = new Picture(idx);
85
        pict.setDefaultSize(ppt);
86
        slide.addShape(pict);
111
        slide.addShape(pict);
87
        ByteArrayOutputStream out = new ByteArrayOutputStream();
112
        ByteArrayOutputStream out = new ByteArrayOutputStream();
Lines 91-97 Link Here
91
        out.close();
116
        out.close();
92
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
117
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
93
        assertTrue(ppt.getPictures().length == 2 );
118
        assertTrue(ppt.getPictureData().length == 2 );
94
    }
119
    }
95
}
120
}
(-)src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java (-9 / +99 lines)
Lines 17-28 Link Here
17
import junit.framework.TestCase;
17
import junit.framework.TestCase;
18
import org.apache.poi.hslf.usermodel.SlideShow;
18
import org.apache.poi.hslf.usermodel.SlideShow;
19
import org.apache.poi.hslf.usermodel.RichTextRun;
19
import org.apache.poi.hslf.HSLFSlideShow;
20
import org.apache.poi.hslf.HSLFSlideShow;
20
import java.awt.*;
21
import java.awt.*;
21
import java.awt.Rectangle;
22
import java.awt.Rectangle;
22
import java.io.ByteArrayOutputStream;
23
import java.io.ByteArrayOutputStream;
23
import java.io.ByteArrayInputStream;
24
import java.io.ByteArrayInputStream;
25
import java.io.FileOutputStream;
24
/**
26
/**
25
 * Test drawing shapes via Graphics2D
27
 * Test drawing shapes via Graphics2D
Lines 36-56 Link Here
36
		String dirname = System.getProperty("HSLF.testdata.path");
38
		String dirname = System.getProperty("HSLF.testdata.path");
37
		String filename = dirname + "/empty.ppt";
39
		String filename = dirname + "/empty.ppt";
38
		ppt = new SlideShow(new HSLFSlideShow(filename));
40
		ppt = new SlideShow(new HSLFSlideShow(filename));
39
        getClass().getResourceAsStream("");
40
    }
41
    }
41
    public void testGraphics() throws Exception {
42
    public void testGraphics() throws Exception {
42
        Slide slide = ppt.createSlide();
43
        Slide slide = ppt.createSlide();
43
        Line line = new Line();
44
        Line line = new Line();
44
        line.setAnchor(new Rectangle(1296, 2544, 1344, 528));
45
        java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
46
        line.setAnchor(lineAnchor);
47
        System.out.println(line.getAnchor());
45
        line.setLineWidth(3);
48
        line.setLineWidth(3);
46
        line.setLineStyle(Line.LineDashSys);
49
        line.setLineStyle(Line.LineDashSys);
47
        line.setLineColor(Color.red);
50
        line.setLineColor(Color.red);
48
        slide.addShape(line);
51
        slide.addShape(line);
49
        Ellipse ellipse = new Ellipse();
52
        AutoShape ellipse = new AutoShape(ShapeTypes.Ellipse);
50
        ellipse.setAnchor(new Rectangle(4000, 1000, 1000, 1000));
53
        java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);
54
        ellipse.setAnchor(ellipseAnchor);
51
        ellipse.setLineWidth(2);
55
        ellipse.setLineWidth(2);
52
        ellipse.setLineStyle(Line.LineSolid);
56
        ellipse.setLineStyle(Line.LineSolid);
53
        ellipse.setLineColor(Color.green);
57
        ellipse.setLineColor(Color.green);
Lines 64-80 Link Here
64
        //read ppt from byte array
68
        //read ppt from byte array
65
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
69
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
66
        assertEquals(ppt.getSlides().length, 1);
70
        assertEquals(1, ppt.getSlides().length);
67
        slide = ppt.getSlides()[0];
71
        slide = ppt.getSlides()[0];
68
        Shape[] shape = slide.getShapes();
72
        Shape[] shape = slide.getShapes();
69
        assertEquals(shape.length, 2);
73
        assertEquals(2, shape.length);
70
        assertTrue(shape[0] instanceof Line); //group shape
74
        assertTrue(shape[0] instanceof Line); //group shape
71
        assertEquals(shape[0].getAnchor(), new Rectangle(1296, 2544, 1344, 528)); //group shape
75
        assertEquals(lineAnchor, shape[0].getAnchor()); //group shape
72
        assertTrue(shape[1] instanceof Ellipse); //group shape
76
        assertTrue(shape[1] instanceof AutoShape); //group shape
73
        assertEquals(shape[1].getAnchor(), new Rectangle(4000, 1000, 1000, 1000)); //group shape
77
        assertEquals(ellipseAnchor, shape[1].getAnchor()); //group shape
74
    }
78
    }
79
    /**
80
     * Verify that we can read TextBox shapes
81
     * @throws Exception
82
     */
83
    public void testTextBoxRead() throws Exception {
84
        String dirname = System.getProperty("HSLF.testdata.path");
85
        String filename = dirname + "/with_textbox.ppt";
86
        ppt = new SlideShow(new HSLFSlideShow(filename));
87
        Slide sl = ppt.getSlides()[0];
88
        Shape[] sh = sl.getShapes();
89
        for (int i = 0; i < sh.length; i++) {
90
            assertTrue(sh[i] instanceof TextBox);
91
            TextBox txtbox = (TextBox)sh[i];
92
            String text = txtbox.getText();
93
            assertNotNull(text);
94
95
            assertEquals(txtbox.getRichTextRuns().length, 1);
96
            RichTextRun rt = txtbox.getRichTextRuns()[0];
97
98
            if (text.equals("Hello, World!!!")){
99
                assertEquals(32, rt.getFontSize());
100
                assertTrue(rt.isBold());
101
                assertTrue(rt.isItalic());
102
            } else if (text.equals("I am just a poor boy")){
103
                assertEquals(44, rt.getFontSize());
104
                assertTrue(rt.isBold());
105
            } else if (text.equals("This is Times New Roman")){
106
                assertEquals(16, rt.getFontSize());
107
                assertTrue(rt.isBold());
108
                assertTrue(rt.isItalic());
109
                assertTrue(rt.isUnderlined());
110
            } else if (text.equals("Plain Text")){
111
                assertEquals(18, rt.getFontSize());
112
            }
113
        }
114
    }
115
116
    /**
117
     * Verify that we can add TextBox shapes to a slide
118
     * @throws Exception
119
     */
120
    public void testTextBoxWrite() throws Exception {
121
        ppt = new SlideShow();
122
        Slide sl = ppt.createSlide();
123
124
        TextBox txtbox = new TextBox();
125
        txtbox.setText("Hello, World!");
126
        txtbox.setFontSize(42);
127
        txtbox.setBold(true);
128
        txtbox.setItalic(true);
129
130
        sl.addShape(txtbox);
131
132
        txtbox = new TextBox();
133
        txtbox.setText("Plain text in default font");
134
        sl.addShape(txtbox);
135
136
        assertEquals(sl.getShapes().length, 2);
137
138
        //serialize and read again
139
        ByteArrayOutputStream out = new ByteArrayOutputStream();
140
        ppt.write(out);
141
        out.close();
142
143
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
144
        sl = ppt.getSlides()[0];
145
        assertEquals(sl.getShapes().length, 2);
146
147
        Shape[] sh = sl.getShapes();
148
        for (int i = 0; i < sh.length; i++) {
149
            assertTrue(sh[i] instanceof TextBox);
150
            txtbox = (TextBox)sh[i];
151
            String text = txtbox.getText();
152
            assertNotNull(text);
153
154
            assertEquals(txtbox.getRichTextRuns().length, 1);
155
            RichTextRun rt = txtbox.getRichTextRuns()[0];
156
157
            if (text.equals("Hello, World!")){
158
                assertEquals(42, rt.getFontSize());
159
                assertTrue(rt.isBold());
160
                assertTrue(rt.isItalic());
161
            }
162
        }
163
    }
164
75
}
165
}

Return to bug 39256