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

(-)src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java (-33 / +69 lines)
Lines 20-28 Link Here
20
package org.apache.poi.hslf.usermodel;
20
package org.apache.poi.hslf.usermodel;
21
21
22
import org.apache.poi.hslf.model.TextRun;
22
import org.apache.poi.hslf.model.TextRun;
23
import org.apache.poi.hslf.model.Sheet;
24
import org.apache.poi.hslf.model.SlideMaster;
23
import org.apache.poi.hslf.record.StyleTextPropAtom.CharFlagsTextProp;
25
import org.apache.poi.hslf.record.StyleTextPropAtom.CharFlagsTextProp;
24
import org.apache.poi.hslf.record.StyleTextPropAtom.TextProp;
26
import org.apache.poi.hslf.record.StyleTextPropAtom.TextProp;
25
import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
27
import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
28
import org.apache.poi.hslf.record.ColorSchemeAtom;
26
29
27
import java.awt.*;
30
import java.awt.*;
28
31
Lines 47-53 Link Here
47
	/** How long a string (in the parent TextRun) we represent */
50
	/** How long a string (in the parent TextRun) we represent */
48
	private int length;
51
	private int length;
49
	
52
	
50
	/** 
53
    private String _fontname;
54
    /**
51
	 * Our paragraph and character style.
55
	 * Our paragraph and character style.
52
	 * Note - we may share these styles with other RichTextRuns
56
	 * Note - we may share these styles with other RichTextRuns
53
	 */
57
	 */
Lines 56-62 Link Here
56
	private boolean sharingParagraphStyle;
60
	private boolean sharingParagraphStyle;
57
	private boolean sharingCharacterStyle;
61
	private boolean sharingCharacterStyle;
58
	
62
	
59
    private String _fontname;
60
	/**
63
	/**
61
	 * Create a new wrapper around a (currently not)
64
	 * Create a new wrapper around a (currently not)
62
	 *  rich text string
65
	 *  rich text string
Lines 158-171 Link Here
158
	 *  text property won't be set if there's no CharFlagsTextProp.
161
	 *  text property won't be set if there's no CharFlagsTextProp.
159
	 */
162
	 */
160
	private boolean isCharFlagsTextPropVal(int index) {
163
	private boolean isCharFlagsTextPropVal(int index) {
161
		if(characterStyle == null) { return false; }
164
        CharFlagsTextProp cftp = null;
162
		
165
        if (characterStyle != null){
163
		CharFlagsTextProp cftp = (CharFlagsTextProp)
166
            cftp = (CharFlagsTextProp)characterStyle.findByName("char_flags");
164
			characterStyle.findByName("char_flags");
167
        }
165
		
168
        if (cftp == null){
166
		if(cftp == null) { return false; }
169
            Sheet sheet = parentRun.getSheet();
167
		return cftp.getSubValue(index);
170
            int txtype = parentRun.getRunType();
171
            SlideMaster master = (SlideMaster)sheet.getMasterSheet();
172
            cftp = (CharFlagsTextProp)master.getStyleAttribute(txtype, getIndentLevel(), "char_flags", true);
173
        }
174
175
		return cftp == null ? false : cftp.getSubValue(index);
168
	}
176
	}
177
169
	/**
178
	/**
170
	 * Set the value of the given flag in the CharFlagsTextProp, adding
179
	 * Set the value of the given flag in the CharFlagsTextProp, adding
171
	 *  it if required. 
180
	 *  it if required. 
Lines 204-227 Link Here
204
	 *  Master Sheet will apply.
213
	 *  Master Sheet will apply.
205
	 */
214
	 */
206
	private int getCharTextPropVal(String propName) {
215
	private int getCharTextPropVal(String propName) {
207
		if(characterStyle == null) { return -1; }
216
        TextProp prop = null;
208
		
217
        if (characterStyle != null){
209
		TextProp cTextProp = characterStyle.findByName(propName);
218
            prop = characterStyle.findByName(propName);
210
		if(cTextProp == null) { return -1; }
219
        }
211
		return cTextProp.getValue();
220
221
        if (prop == null){
222
            Sheet sheet = parentRun.getSheet();
223
            int txtype = parentRun.getRunType();
224
            SlideMaster master = (SlideMaster)sheet.getMasterSheet();
225
            prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true);
226
        }
227
		return prop == null ? -1 : prop.getValue();
212
	}
228
	}
213
	/**
229
	/**
214
	 * Fetch the value of the given Paragraph related TextProp. 
230
	 * Fetch the value of the given Paragraph related TextProp.
215
	 * Returns -1 if that TextProp isn't present. 
231
	 * Returns -1 if that TextProp isn't present.
216
	 * If the TextProp isn't present, the value from the appropriate 
232
	 * If the TextProp isn't present, the value from the appropriate
217
	 *  Master Sheet will apply.
233
	 *  Master Sheet will apply.
218
	 */
234
	 */
219
	private int getParaTextPropVal(String propName) {
235
	private int getParaTextPropVal(String propName) {
220
		if(paragraphStyle == null) { return -1; }
236
        TextProp prop = null;
221
		
237
        if (paragraphStyle != null){
222
		TextProp pTextProp = paragraphStyle.findByName(propName);
238
            prop = paragraphStyle.findByName(propName);
223
		if(pTextProp == null) { return -1; }
239
        }
224
		return pTextProp.getValue();
240
        if (prop == null){
241
            Sheet sheet = parentRun.getSheet();
242
            int txtype = parentRun.getRunType();
243
            SlideMaster master = (SlideMaster)sheet.getMasterSheet();
244
            prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
245
        }
246
247
		return prop == null ? -1 : prop.getValue();
225
	}
248
	}
226
	
249
	
227
	/**
250
	/**
Lines 290-316 Link Here
290
        if (slideShow == null) {
313
        if (slideShow == null) {
291
            //we can't set font since slideshow is not assigned yet
314
            //we can't set font since slideshow is not assigned yet
292
            _fontname = fontName;
315
            _fontname = fontName;
293
        } else{
316
        } else {
294
		// Get the index for this font (adding if needed)
317
    		// Get the index for this font (adding if needed)
295
		int fontIdx = slideShow.getFontCollection().addFont(fontName);
318
	    	int fontIdx = slideShow.getFontCollection().addFont(fontName);
296
		setCharTextPropVal("font.index", fontIdx);
319
		    setCharTextPropVal("font.index", fontIdx);
320
        }
297
	}
321
	}
298
	}
299
	public String getFontName() {
322
	public String getFontName() {
300
		int fontIdx = getCharTextPropVal("font.index");
323
        if (slideShow == null) {
301
		if(fontIdx == -1) { return null; }
324
            return _fontname;
302
		return slideShow.getFontCollection().getFontWithId(fontIdx);
325
        } else {
326
            int fontIdx = getCharTextPropVal("font.index");
327
            if(fontIdx == -1) { return null; }
328
            return slideShow.getFontCollection().getFontWithId(fontIdx);
329
        }
303
	}
330
	}
304
	
331
	
305
	/**
332
	/**
306
	 * @return font color as RGB value
333
	 * @return font color as RGB value
307
	 * @see java.awt.Color
334
	 * @see java.awt.Color
308
	 */
335
	 */
309
	public int getFontColor() {
336
	public Color getFontColor() {
310
		return getCharTextPropVal("font.color");
337
        int rgb = getCharTextPropVal("font.color");
338
        if (rgb >= 0x8000000) {
339
            int idx = rgb % 0x8000000;
340
            ColorSchemeAtom ca = parentRun.getSheet().getColorScheme();
341
            if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
342
        }
343
344
        Color tmp = new Color(rgb, true);
345
        return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
311
	}
346
	}
347
312
	/**
348
	/**
313
	 * Sets color of the text, as a RGB value
349
	 * Sets color of the text, as a int rgb
314
	 * @see java.awt.Color
350
	 * @see java.awt.Color
315
	 */
351
	 */
316
	public void setFontColor(int rgb) {
352
	public void setFontColor(int rgb) {
(-)src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (-5 / +23 lines)
Lines 80-90 Link Here
80
  private Document _documentRecord;
80
  private Document _documentRecord;
81
81
82
  // Friendly objects for people to deal with
82
  // Friendly objects for people to deal with
83
  private SlideMaster[] _masters;
83
  private Slide[] _slides;
84
  private Slide[] _slides;
84
  private Notes[] _notes;
85
  private Notes[] _notes;
85
  private FontCollection _fonts;
86
  private FontCollection _fonts;
86
  // MetaSheets (eg masters) not yet supported
87
  // private MetaSheets[] _msheets;
88
87
89
  
88
  
90
  /* ===============================================================
89
  /* ===============================================================
Lines 305-310 Link Here
305
	SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
304
	SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
306
	SlideListWithText notesSLWT  = _documentRecord.getNotesSlideListWithText();
305
	SlideListWithText notesSLWT  = _documentRecord.getNotesSlideListWithText();
307
	
306
	
307
    //find master slides
308
    SlideAtomsSet[] masterSets = new SlideAtomsSet[0];
309
    org.apache.poi.hslf.record.MainMaster[] masterRecords = null;
310
    if (masterSLWT != null){
311
312
        masterSets = masterSLWT.getSlideAtomsSets();
313
        masterRecords = new org.apache.poi.hslf.record.MainMaster[masterSets.length];
314
        for(int i=0; i<masterRecords.length; i++) {
315
            masterRecords[i] = (org.apache.poi.hslf.record.MainMaster)getCoreRecordForSAS(masterSets[i]);
316
        }
317
    }
318
308
	// Start by finding the notes records to go with the entries in
319
	// Start by finding the notes records to go with the entries in
309
	//  notesSLWT
320
	//  notesSLWT
310
	org.apache.poi.hslf.record.Notes[] notesRecords;
321
	org.apache.poi.hslf.record.Notes[] notesRecords;
Lines 359-364 Link Here
359
	}
370
	}
360
	
371
	
361
	// Finally, generate model objects for everything
372
	// Finally, generate model objects for everything
373
    _masters = new SlideMaster[masterRecords.length];
374
    for(int i=0; i<_masters.length; i++) {
375
        SlideAtomsSet sas = masterSets[i];
376
        int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
377
        _masters[i] = new SlideMaster(masterRecords[i], sheetNo);
378
        _masters[i].setSlideShow(this);
379
    }
380
362
	// Notes first
381
	// Notes first
363
	_notes = new Notes[notesRecords.length];
382
	_notes = new Notes[notesRecords.length];
364
	for(int i=0; i<_notes.length; i++) {
383
	for(int i=0; i<_notes.length; i++) {
Lines 420-429 Link Here
420
	public Notes[] getNotes() { return _notes; }
439
	public Notes[] getNotes() { return _notes; }
421
440
422
	/**
441
	/**
423
	 * Returns an array of all the meta Sheets (master sheets etc) 
442
     * Returns an array of all the normal Slides found in the slideshow
424
	 * found in the slideshow
425
	 */
443
	 */
426
	//public MetaSheet[] getMetaSheets() { return _msheets; }
444
    public SlideMaster[] getSlidesMasters() { return _masters; }
427
445
428
	/**
446
	/**
429
	 * Returns the data of all the pictures attached to the SlideShow
447
	 * Returns the data of all the pictures attached to the SlideShow
(-)src/scratchpad/src/org/apache/poi/hslf/model/Slide.java (-2 / +35 lines)
Lines 24-29 Link Here
24
import org.apache.poi.hslf.record.PPDrawing;
24
import org.apache.poi.hslf.record.PPDrawing;
25
import org.apache.poi.hslf.record.SlideAtom;
25
import org.apache.poi.hslf.record.SlideAtom;
26
import org.apache.poi.hslf.record.TextHeaderAtom;
26
import org.apache.poi.hslf.record.TextHeaderAtom;
27
import org.apache.poi.hslf.record.ColorSchemeAtom;
27
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
28
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
28
29
29
/**
30
/**
Lines 81-90 Link Here
81
		int i=0;
82
		int i=0;
82
		for(i=0; i<textRuns.size(); i++) {
83
		for(i=0; i<textRuns.size(); i++) {
83
			_runs[i] = (TextRun)textRuns.get(i);
84
			_runs[i] = (TextRun)textRuns.get(i);
85
            _runs[i].setSheet(this);
84
		}
86
		}
85
		// Grab text from slide's PPDrawing
87
		// Grab text from slide's PPDrawing
86
		for(int k=0; k<_otherRuns.length; i++, k++) {
88
		for(int k=0; k<_otherRuns.length; i++, k++) {
87
			_runs[i] = _otherRuns[k];
89
			_runs[i] = _otherRuns[k];
90
            _runs[i].setSheet(this);
88
		}
91
		}
89
	}
92
	}
90
  
93
  
Lines 135-141 Link Here
135
	public TextBox addTitle() {
138
	public TextBox addTitle() {
136
		Placeholder pl = new Placeholder();
139
		Placeholder pl = new Placeholder();
137
		pl.setShapeType(ShapeTypes.Rectangle);
140
		pl.setShapeType(ShapeTypes.Rectangle);
138
		pl.setTextType(TextHeaderAtom.TITLE_TYPE);
141
		pl.getTextRun().setRunType(TextHeaderAtom.TITLE_TYPE);
139
		pl.setText("Click to edit title");
142
		pl.setText("Click to edit title");
140
		pl.setAnchor(new java.awt.Rectangle(54, 48, 612, 90));
143
		pl.setAnchor(new java.awt.Rectangle(54, 48, 612, 90));
141
		addShape(pl);
144
		addShape(pl);
Lines 212-215 Link Here
212
	 *  which hold text data for this slide (typically for placeholders).
215
	 *  which hold text data for this slide (typically for placeholders).
213
	 */
216
	 */
214
	protected SlideAtomsSet getSlideAtomsSet() { return _atomSet;  }
217
	protected SlideAtomsSet getSlideAtomsSet() { return _atomSet;  }
215
} 
218
219
    /**
220
     * Returns the slide master associated with this slide.
221
     *
222
     * @return the slide master associated with this slide.
223
     */
224
     public MasterSheet getMasterSheet(){
225
        SlideMaster[] master = getSlideShow().getSlidesMasters();
226
        SlideAtom sa = _slide.getSlideAtom();
227
        int masterId = sa.getMasterID();
228
        for (int i = 0; i < master.length; i++) {
229
            if (masterId == master[i]._getSheetNumber()) return master[i];
230
        }
231
        throw new RuntimeException("Master slide not found for slide " + _slideNo);
232
    }
233
234
    /**
235
     * Change Master of this slide.
236
     */
237
    public void setMasterSheet(MasterSheet master){
238
        SlideAtom sa = _slide.getSlideAtom();
239
        int sheetNo = master._getSheetNumber();
240
        sa.setMasterID(sheetNo);
241
    }
242
243
244
    public ColorSchemeAtom getColorScheme(){
245
        return _slide.getColorScheme();
246
    }
247
248
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java (-1 / +15 lines)
Lines 209-212 Link Here
209
		ppdrawing.addTextboxWrapper(tbox._txtbox);
209
		ppdrawing.addTextboxWrapper(tbox._txtbox);
210
	}
210
	}
211
  }
211
  }
212
} 
212
    
213
    /**
214
     * Return the master sheet .
215
     */
216
    public MasterSheet getMasterSheet(){
217
        return null;
218
    }
219
220
    /**
221
     * Color scheme for this sheet.
222
     */
223
     public  ColorSchemeAtom getColorScheme(){
224
        return null;
225
    }
226
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java (-13 / +14 lines)
Lines 47-52 Link Here
47
	protected boolean _isUnicode;
47
	protected boolean _isUnicode;
48
	protected RichTextRun[] _rtRuns;
48
	protected RichTextRun[] _rtRuns;
49
	private SlideShow slideShow;
49
	private SlideShow slideShow;
50
    private Sheet sheet;
50
51
51
	/**
52
	/**
52
	* Constructs a Text Run from a Unicode text block
53
	* Constructs a Text Run from a Unicode text block
Lines 378-387 Link Here
378
	public synchronized void setText(String s) {
379
	public synchronized void setText(String s) {
379
		// Save the new text to the atoms
380
		// Save the new text to the atoms
380
		storeText(s);
381
		storeText(s);
381
		
382
		RichTextRun fst = _rtRuns[0];
383
382
		// Finally, zap and re-do the RichTextRuns
384
		// Finally, zap and re-do the RichTextRuns
383
		for(int i=0; i<_rtRuns.length; i++) { _rtRuns[i] = null; }
385
		for(int i=0; i<_rtRuns.length; i++) { _rtRuns[i] = null; }
384
		_rtRuns = new RichTextRun[1];
386
		_rtRuns = new RichTextRun[1];
387
        _rtRuns[0] = fst;
385
388
386
		// Now handle record stylings:
389
		// Now handle record stylings:
387
		// If there isn't styling
390
		// If there isn't styling
Lines 395-411 Link Here
395
			LinkedList cStyles = _styleAtom.getCharacterStyles();
398
			LinkedList cStyles = _styleAtom.getCharacterStyles();
396
			while(cStyles.size() > 1) { cStyles.removeLast(); }
399
			while(cStyles.size() > 1) { cStyles.removeLast(); }
397
			
400
			
398
			// Note - TextPropCollection's idea of the text length must
401
			_rtRuns[0].setText(s);
399
			//         be one larger than it actually is!
400
			// (This indicates that new text added to the end should
401
			//   get the same styling as the current text)
402
			TextPropCollection pCol = (TextPropCollection)pStyles.getFirst();
403
			TextPropCollection cCol = (TextPropCollection)cStyles.getFirst();
404
			pCol.updateTextSize(s.length()+1);
405
			cCol.updateTextSize(s.length()+1);
406
			
407
			// Recreate rich text run with first styling
408
			_rtRuns[0] = new RichTextRun(this,0,s.length(), pCol, cCol, false, false);
409
		} else {
402
		} else {
410
			// Recreate rich text run with no styling
403
			// Recreate rich text run with no styling
411
			_rtRuns[0] = new RichTextRun(this,0,s.length());
404
			_rtRuns[0] = new RichTextRun(this,0,s.length());
Lines 515-518 Link Here
515
			}
508
			}
516
		}
509
		}
517
	}
510
	}
518
} 
511
512
    public void setSheet(Sheet sheet){
513
        this.sheet = sheet;
514
    }
515
516
    public Sheet getSheet(){
517
        return this.sheet;        
518
    }
519
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java (-11 / +70 lines)
Lines 18-23 Link Here
18
18
19
import org.apache.poi.ddf.*;
19
import org.apache.poi.ddf.*;
20
import org.apache.poi.util.LittleEndian;
20
import org.apache.poi.util.LittleEndian;
21
import org.apache.poi.hslf.record.ColorSchemeAtom;
21
22
22
import java.awt.*;
23
import java.awt.*;
23
24
Lines 105-110 Link Here
105
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
106
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
106
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
107
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
107
        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);
108
        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);
109
        setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, color == null ? 0x180010 : 0x180018);
108
    }
110
    }
109
111
110
    /**
112
    /**
Lines 112-134 Link Here
112
     */
114
     */
113
    public Color getLineColor(){
115
    public Color getLineColor(){
114
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
116
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
115
        EscherRGBProperty prop = (EscherRGBProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);
117
116
        Color color = Color.black;
118
        EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);
117
        if (prop != null){
119
        EscherSimpleProperty p2 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
118
            Color swp = new Color(prop.getRgbColor());
120
        int p2val = p2 == null ? 0 : p2.getPropertyValue();
119
            color = new Color(swp.getBlue(), swp.getGreen(), swp.getRed());
121
        Color clr = null;
122
        if (p1 != null && (p2val  & 0x8) != 0){
123
            int rgb = p1.getPropertyValue();
124
            if (rgb >= 0x8000000) {
125
                int idx = rgb % 0x8000000;
126
                ColorSchemeAtom ca = getSheet().getColorScheme();
127
                if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
128
            }
129
            Color tmp = new Color(rgb, true);
130
            clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
120
        }
131
        }
121
        return color;
132
        return clr;
122
    }
133
    }
123
134
124
    /**
135
    /**
136
     * Gets line dashing. One of the PEN_* constants defined in this class.
137
     *
138
     * @return dashing of the line.
139
     */
140
    public int getLineDashing(){
141
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
142
143
        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
144
        return prop == null ? Line.PEN_SOLID : prop.getPropertyValue();
145
    }
146
147
    /**
148
     * Sets line dashing. One of the PEN_* constants defined in this class.
149
     *
150
     * @param pen new style of the line.
151
     */
152
    public void setLineDashing(int pen){
153
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
154
155
        setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == Line.PEN_SOLID ? -1 : pen);
156
    }
157
158
    /**
125
     * Sets line style. One of the constants defined in this class.
159
     * Sets line style. One of the constants defined in this class.
126
     *
160
     *
127
     * @param style new style of the line.
161
     * @param style new style of the line.
128
     */
162
     */
129
    public void setLineStyle(int style){
163
    public void setLineStyle(int style){
130
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
164
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
131
        setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, style == Line.LineSolid ? -1 : style);
165
        setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == Line.LINE_SIMPLE ? -1 : style);
132
    }
166
    }
133
167
134
    /**
168
    /**
Lines 138-145 Link Here
138
     */
172
     */
139
    public int getLineStyle(){
173
    public int getLineStyle(){
140
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
174
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
141
        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
175
        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
142
        return prop == null ? Line.LineSolid : prop.getPropertyValue();
176
        return prop == null ? Line.LINE_SIMPLE : prop.getPropertyValue();
143
    }
177
    }
144
178
145
    /**
179
    /**
Lines 147-158 Link Here
147
     *
181
     *
148
     * @param color the background color
182
     * @param color the background color
149
     */
183
     */
184
    public Color getFillColor(Color color){
185
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
186
        EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.FILL__FILLCOLOR);
187
        EscherSimpleProperty p2= (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
188
189
        int p2val = p2 == null ? 0 : p2.getPropertyValue();
190
191
        Color clr = null;
192
        if (p1 != null && (p2val  & 0x10) != 0){
193
            int rgb = p1.getPropertyValue();
194
            if (rgb >= 0x8000000) {
195
                int idx = rgb % 0x8000000;
196
                ColorSchemeAtom ca = getSheet().getColorScheme();
197
                rgb = ca.getColor(idx);
198
            }
199
            Color tmp = new Color(rgb, true);
200
            clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
201
        }
202
        return clr;
203
    }
204
205
    /**
206
     * The color used to fill this shape.
207
     *
208
     * @param color the background color
209
     */
150
    public void setFillColor(Color color){
210
    public void setFillColor(Color color){
151
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
211
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
152
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
212
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
153
        setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
213
        setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
154
        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 1376273);
214
        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, color == null ? 0x150010 : 0x150011);
155
    }
215
    }
156
216
157
158
}
217
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java (+146 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2002-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
17
package org.apache.poi.hslf.model;
18
19
import org.apache.poi.hslf.record.*;
20
import org.apache.poi.hslf.usermodel.SlideShow;
21
import org.apache.poi.hslf.record.StyleTextPropAtom.*;
22
23
/**
24
 * SlideMaster determines the graphics, layout, and formatting for all the slides in a given presentation.
25
 * It stores information about default font styles, placeholder sizes and positions,
26
 * background design, and color schemes.
27
 *
28
 * @author Yegor Kozlov
29
 */
30
public class SlideMaster extends MasterSheet {
31
    private int _refSheetNo;
32
    private int _sheetNo;
33
    private MainMaster _master;
34
    private TextRun[] _runs;
35
36
    /**
37
     * all TxMasterStyleAtoms available in this master
38
     */
39
    private TxMasterStyleAtom[] _txmaster;
40
41
    /**
42
     * Constructs a SlideMaster from the MainMaster record,
43
     *
44
     */
45
    public SlideMaster(org.apache.poi.hslf.record.MainMaster rec, int slideId) {
46
        _master = rec;
47
48
        // Grab our internal sheet ID
49
        _refSheetNo = rec.getSheetId();
50
51
        // Grab the number of the slide we're for, via the NotesAtom
52
        _sheetNo = slideId;
53
54
        _runs = findTextRuns(_master.getPPDrawing());
55
    }
56
57
    /**
58
     * Returns an array of all the TextRuns found
59
     */
60
    public TextRun[] getTextRuns() {
61
        return _runs;
62
    }
63
64
    /**
65
     * Returns the (internal, RefID based) sheet number, as used
66
     * to in PersistPtr stuff.
67
     */
68
    public int _getSheetRefId() {
69
        return _refSheetNo;
70
    }
71
72
    /**
73
     * Returns the (internal, SlideIdentifer based) number of the
74
     * slide we're attached to
75
     */
76
    public int _getSheetNumber() {
77
        return _sheetNo;
78
    }
79
80
    /**
81
     * Returns the PPDrawing associated with this slide master
82
     */
83
    protected PPDrawing getPPDrawing() {
84
        return _master.getPPDrawing();
85
    }
86
87
    /**
88
     * Pickup a style attribute from the master.
89
     * This is the "workhorse" which returns the default style attrubutes. 
90
     */
91
    public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {
92
93
        TextProp prop = null;
94
        for (int i = level; i >= 0; i--) {
95
            TextPropCollection[] styles =
96
                    isCharacter ? _txmaster[txtype].getCharacterStyles() : _txmaster[txtype].getParagraphStyles();
97
            if (i < styles.length) prop = styles[i].findByName(name);
98
            if (prop != null) break;
99
        }
100
        if (prop == null) {
101
            switch (txtype) {
102
                case TextHeaderAtom.CENTRE_BODY_TYPE:
103
                case TextHeaderAtom.HALF_BODY_TYPE:
104
                case TextHeaderAtom.QUARTER_BODY_TYPE:
105
                    txtype = TextHeaderAtom.BODY_TYPE;
106
                    break;
107
                case TextHeaderAtom.CENTER_TITLE_TYPE:
108
                    txtype = TextHeaderAtom.TITLE_TYPE;
109
                    break;
110
                default:
111
                    return null;
112
            }
113
            prop = getStyleAttribute(txtype, level, name, isCharacter);
114
        }
115
        return prop;
116
    }
117
118
    /**
119
     * Assign SlideShow for this slide master.
120
     * (Used interanlly)
121
     */ 
122
    public void setSlideShow(SlideShow ss) {
123
        super.setSlideShow(ss);
124
125
        //after the slide show is assigned collect all available style records
126
        if (_txmaster == null) {
127
            _txmaster = new TxMasterStyleAtom[9];
128
129
            TxMasterStyleAtom txdoc = getSlideShow().getDocumentRecord().getEnvironment().getTxMasterStyleAtom();
130
            _txmaster[txdoc.getTextType()] = txdoc;
131
132
            TxMasterStyleAtom[] txrec = _master.getTxMasterStyleAtoms();
133
            for (int i = 0; i < txrec.length; i++) {
134
                _txmaster[txrec[i].getTextType()] = txrec[i];
135
            }
136
        }
137
    }
138
139
    /**
140
     * Returns the ColorSchemeAtom associated with this slide master
141
     */
142
    public ColorSchemeAtom getColorScheme(){
143
        return _master.getColorScheme();
144
    }
145
146
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java (-8 / +17 lines)
Lines 95-111 Link Here
95
        LittleEndian.putInt(header, 4, 8);
95
        LittleEndian.putInt(header, 4, 8);
96
        clientAnchor.fillFields(header, 0, null);
96
        clientAnchor.fillFields(header, 0, null);
97
97
98
        clientAnchor.setFlag((short)anchor.y);
98
        clientAnchor.setFlag((short)(anchor.y*MASTER_DPI/POINT_DPI));
99
        clientAnchor.setCol1((short)anchor.x);
99
        clientAnchor.setCol1((short)(anchor.x*MASTER_DPI/POINT_DPI));
100
        clientAnchor.setDx1((short)(anchor.width + anchor.x));
100
        clientAnchor.setDx1((short)((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI));
101
        clientAnchor.setRow1((short)(anchor.height + anchor.y));
101
        clientAnchor.setRow1((short)((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI));
102
102
103
        EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
103
        EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
104
104
105
        spgr.setRectX1(anchor.x);
105
        spgr.setRectX1(anchor.x*MASTER_DPI/POINT_DPI);
106
        spgr.setRectY1(anchor.y);
106
        spgr.setRectY1(anchor.y*MASTER_DPI/POINT_DPI);
107
        spgr.setRectX2(anchor.x + anchor.width);
107
        spgr.setRectX2((anchor.x + anchor.width)*MASTER_DPI/POINT_DPI);
108
        spgr.setRectY2(anchor.y + anchor.height);
108
        spgr.setRectY2((anchor.y + anchor.height)*MASTER_DPI/POINT_DPI);
109
    }
109
    }
110
110
111
    /**
111
    /**
Lines 145-150 Link Here
145
     */
145
     */
146
    public void addShape(Shape shape){
146
    public void addShape(Shape shape){
147
        _escherContainer.addChildRecord(shape.getSpContainer());
147
        _escherContainer.addChildRecord(shape.getSpContainer());
148
149
        Sheet sheet = getSheet();
150
        shape.setSheet(sheet);
151
        shape.afterInsert(sheet);
152
153
        if(shape instanceof TextBox) {
154
            TextBox tbox = (TextBox)shape;
155
            getSheet().getPPDrawing().addTextboxWrapper(tbox._txtbox);
156
        }
148
    }
157
    }
149
158
150
    /**
159
    /**
(-)src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java (+12 lines)
Line 0 Link Here
1
package org.apache.poi.hslf.model;
2
3
/**
4
 * The superclass of all master sheets - Slide masters, Notes masters, etc.
5
 *
6
 * For now it's empty. When we understand more about masters in ppt we will add the common functionality here.
7
 * 
8
 * @author Yegor Kozlov
9
 */
10
public abstract class MasterSheet extends Sheet {
11
12
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java (-18 / +68 lines)
Lines 26-33 Link Here
26
import java.awt.geom.PathIterator;
26
import java.awt.geom.PathIterator;
27
import java.text.AttributedCharacterIterator;
27
import java.text.AttributedCharacterIterator;
28
import java.util.Map;
28
import java.util.Map;
29
import java.util.ArrayList;
29
30
30
import org.apache.poi.ddf.EscherProperties;
31
import org.apache.poi.ddf.EscherProperties;
32
import org.apache.poi.hslf.usermodel.RichTextRun;
31
33
32
/**
34
/**
33
 * Translates Graphics2D calls into PowerPoint.
35
 * Translates Graphics2D calls into PowerPoint.
Lines 45-53 Link Here
45
    private Color foreground;
47
    private Color foreground;
46
    private Color background = Color.white;
48
    private Color background = Color.white;
47
    private Shape clip;
49
    private Shape clip;
48
50
    int count = 0;
49
    /**
51
    /**
50
     * Construct an powerpoint Graphics object.
52
     * Construct Java Graphics object which translates graphic calls in ppt drawing layer.
51
     *
53
     *
52
     * @param group           The shape group to write the graphics calls into.
54
     * @param group           The shape group to write the graphics calls into.
53
     */
55
     */
Lines 106-113 Link Here
106
108
107
    public void draw(Shape shape){
109
    public void draw(Shape shape){
108
        if(clip != null) {
110
        if(clip != null) {
109
            if (!clip.getBounds().contains(transform.createTransformedShape(shape).getBounds())) {
111
            java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
110
                //return;
112
            if (bounds.width == 0) bounds.width = 1;
113
            if (bounds.height == 0) bounds.height = 1;
114
            if (!clip.getBounds().contains(bounds)) {
115
                return;
111
            }
116
            }
112
        }
117
        }
113
118
Lines 123-128 Link Here
123
                if (stroke instanceof BasicStroke){
128
                if (stroke instanceof BasicStroke){
124
                    BasicStroke bs = (BasicStroke)stroke;
129
                    BasicStroke bs = (BasicStroke)stroke;
125
                    line.setLineWidth(bs.getLineWidth());
130
                    line.setLineWidth(bs.getLineWidth());
131
                    float[] dash = bs.getDashArray();
132
                    if (dash != null) line.setLineDashing(Line.PEN_DASH);
126
                }
133
                }
127
                if(getColor() != null) line.setLineColor(getColor());
134
                if(getColor() != null) line.setLineColor(getColor());
128
                if (type == PathIterator.SEG_LINETO) {
135
                if (type == PathIterator.SEG_LINETO) {
Lines 139-162 Link Here
139
    }
146
    }
140
147
141
    public void drawString(String string, float x, float y){
148
    public void drawString(String string, float x, float y){
149
         TextBox txt = new TextBox(group);
150
         txt.getTextRun().supplySlideShow(group.getSheet().getSlideShow());
151
         txt.getTextRun().setSheet(group.getSheet());
152
         txt.setText(string);
142
153
143
         TextBox txt = new TextBox(group);
154
         RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
155
         rt.setFontSize(font.getSize());
156
         rt.setFontName(font.getFamily());
157
158
        if(getColor() != null) rt.setFontColor(getColor());
159
        if (font.isBold()) rt.setBold(true);
160
        if (font.isItalic()) rt.setItalic(true);
161
144
         txt.setMarginBottom(0);
162
         txt.setMarginBottom(0);
145
         txt.setMarginTop(0);
163
         txt.setMarginTop(0);
146
         txt.setMarginLeft(0);
164
         txt.setMarginLeft(0);
147
         txt.setMarginRight(0);
165
         txt.setMarginRight(0);
148
         txt.setText(string);
149
         txt.setWordWrap(TextBox.WrapNone);
166
         txt.setWordWrap(TextBox.WrapNone);
150
        
151
         if (font != null){
152
             txt.setFontSize(font.getSize());
153
             txt.setFontName(font.getName());
154
             if(getColor() != null) txt.setFontColor(getColor());
155
             if (font.isBold()) txt.setBold(true);
156
             if (font.isItalic()) txt.setItalic(true);
157
         }
158
167
159
         txt.resizeToFitText();
168
         if (!"".equals(string)) txt.resizeToFitText();
160
         int height = (int)txt.getAnchor().getHeight();
169
         int height = (int)txt.getAnchor().getHeight();
161
170
162
         /*
171
         /*
Lines 166-180 Link Here
166
         */
175
         */
167
        txt.moveTo((int)x, (int)(y - height));
176
        txt.moveTo((int)x, (int)(y - height));
168
177
169
        group.addShape(txt);
178
        if(clip != null) {
179
            if (!clip.getBounds().contains(txt.getAnchor())) {
180
                ;//return;
181
            }
182
        }
183
       group.addShape(txt);
170
    }
184
    }
171
185
172
    public void fill(Shape shape){
186
    public void fill(Shape shape){
187
        if(clip != null) {
188
            java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
189
            if (bounds.width == 0) bounds.width = 1;
190
            if (bounds.height == 0) bounds.height = 1;
191
             if (!clip.getBounds().contains(bounds)) {
192
                return;
193
            }
194
        }
195
        PathIterator it = shape.getPathIterator(transform);
196
        ArrayList pnt = new ArrayList();
197
        double[] coords = new double[6];
198
        while(!it.isDone()){
199
            int type = it.currentSegment(coords);
200
            if (type != PathIterator.SEG_CLOSE) {
201
                pnt.add(new Point((int)coords[0], (int)coords[1]));
202
            }
203
            it.next();
204
        }
205
        int[] xPoints= new int[pnt.size()];
206
        int[] yPoints= new int[pnt.size()];
207
        for (int i = 0; i < pnt.size(); i++) {
208
            Point p = (Point)pnt.get(i);
209
            xPoints[i] = p.x;
210
            yPoints[i] = p.y;
211
        }
212
213
        AutoShape r = new AutoShape(ShapeTypes.Rectangle);
173
        if (paint instanceof Color){
214
        if (paint instanceof Color){
174
            Color color = (Color)paint;
215
            Color color = (Color)paint;
216
            r.setFillColor(color);
175
        }
217
        }
218
        if(getColor() != null) r.setLineColor(getColor());
219
        if (stroke instanceof BasicStroke){
220
            BasicStroke bs = (BasicStroke)stroke;
221
            r.setLineWidth(bs.getLineWidth());
222
            float[] dash = bs.getDashArray();
223
            if (dash != null) r.setLineDashing(Line.PEN_DASH);
224
        }
176
225
177
        throw new RuntimeException("Not implemented");
226
        java.awt.Rectangle bounds = transform.createTransformedShape(shape).getBounds();
227
        r.setAnchor(bounds);
228
        group.addShape(r);
178
    }
229
    }
179
230
180
    public void translate(int x, int y) {
231
    public void translate(int x, int y) {
Lines 458-462 Link Here
458
    public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) {
509
    public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) {
459
        throw new RuntimeException("Not implemented");
510
        throw new RuntimeException("Not implemented");
460
    }
511
    }
461
462
}
512
}
(-)src/scratchpad/src/org/apache/poi/hslf/model/Line.java (-22 / +31 lines)
Lines 27-93 Link Here
27
    /**
27
    /**
28
    * Solid (continuous) pen
28
    * Solid (continuous) pen
29
    */
29
    */
30
    public static final int LineSolid = 1;
30
    public static final int PEN_SOLID = 1;
31
    /**
31
    /**
32
     *  PS_DASH system   dash style
32
     *  PS_DASH system   dash style
33
     */
33
     */
34
    public static final int LineDashSys = 2;
34
    public static final int PEN_PS_DASH = 2;
35
    /**
35
    /**
36
     *  PS_DOT system   dash style
36
     *  PS_DOT system   dash style
37
     */
37
     */
38
    public static final int LineDotSys = 3;
38
    public static final int PEN_DOT = 3;
39
    /**
39
    /**
40
     * PS_DASHDOT system dash style
40
     * PS_DASHDOT system dash style
41
     */
41
     */
42
    public static final int LineDashDotSys = 4;
42
    public static final int PEN_DASHDOT = 4;
43
44
    /**
43
    /**
45
     * PS_DASHDOTDOT system dash style
44
     * PS_DASHDOTDOT system dash style
46
     */
45
     */
47
    public static final int LineDashDotDotSys = 5;
46
    public static final int PEN_DASHDOTDOT = 5;
48
    /**
47
    /**
49
     *  square dot style
48
     *  square dot style
50
     */
49
     */
51
    public static final int LineDotGEL = 6;
50
    public static final int PEN_DOTGEL = 6;
52
    /**
51
    /**
53
     *  dash style
52
     *  dash style
54
     */
53
     */
55
    public static final int LineDashGEL = 7;
54
    public static final int PEN_DASH = 7;
56
    /**
55
    /**
57
     *  long dash style
56
     *  long dash style
58
     */
57
     */
59
    public static final int LineLongDashGEL = 8;
58
    public static final int PEN_LONGDASHGEL = 8;
60
    /**
59
    /**
61
     * dash short dash
60
     * dash short dash
62
     */
61
     */
63
    public static final int LineDashDotGEL = 9;
62
    public static final int PEN_DASHDOTGEL = 9;
64
    /**
63
    /**
65
     * long dash short dash
64
     * long dash short dash
66
     */
65
     */
67
    public static final int LineLongDashDotGEL = 10;
66
    public static final int PEN_LONGDASHDOTGEL = 10;
68
    /**
67
    /**
69
     * long dash short dash short dash
68
     * long dash short dash short dash
70
     */
69
     */
71
    public static final int LineLongDashDotDotGEL = 11;
70
    public static final int PEN_LONGDASHDOTDOTGEL = 11;
72
71
73
    /**
72
    /**
74
     * Decoration of the end of line,
73
     *  Single line (of width lineWidth)
75
     * reserved in API but not supported.
76
     */
74
     */
77
75
    public static final int LINE_SIMPLE = 0;
78
    /**
76
    /**
79
     *  Line ends at end point
77
     * Double lines of equal width
80
     */
78
     */
81
    public static final int EndCapFlat = 0;
79
    public static final int LINE_DOUBLE = 1;
82
    /**
80
    /**
83
     *  Rounded ends - the default
81
     * Double lines, one thick, one thin
84
     */
82
     */
85
    public static final int EndCapRound = 1;
83
    public static final int LINE_THICKTHIN = 2;
86
    /**
84
    /**
87
     * Square protrudes by half line width
85
     *  Double lines, reverse order
88
     */
86
     */
89
    public static final int EndCapSquare = 2;
87
    public static final int LINE_THINTHICK = 3;
88
    /**
89
     * Three lines, thin, thick, thin
90
     */
91
    public static final int LINE_TRIPLE = 4;
90
92
93
91
    protected Line(EscherContainerRecord escherRecord, Shape parent){
94
    protected Line(EscherContainerRecord escherRecord, Shape parent){
92
        super(escherRecord, parent);
95
        super(escherRecord, parent);
93
    }
96
    }
Lines 111-117 Link Here
111
        //set default properties for a line
114
        //set default properties for a line
112
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
115
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
113
116
114
        opt.sortProperties();
117
        //default line properties
118
        setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
119
        setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, 0x10000);
120
        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
121
        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
122
        setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);
123
        setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
115
124
116
        return spcont;
125
        return spcont;
117
    }
126
    }
(-)src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java (-11 / +11 lines)
Lines 37-55 Link Here
37
37
38
        int type = spRecord.getOptions() >> 4;
38
        int type = spRecord.getOptions() >> 4;
39
        switch (type){
39
        switch (type){
40
            case ShapeTypes.TextBox:
41
                shape = new TextBox(spContainer, parent);
42
                break;
40
            case ShapeTypes.Rectangle:
43
            case ShapeTypes.Rectangle:
41
                EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
44
                EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
42
                if (txtbox == null) shape = new AutoShape(spContainer, parent);
45
                if (txtbox == null)
43
                else{
46
                    shape = new AutoShape(spContainer, parent);
44
                    if(Shape.getEscherChild(spContainer, EscherClientDataRecord.RECORD_ID) != null )
47
                else
45
                        shape = new Placeholder(spContainer, parent);
48
                    shape = new TextBox(spContainer, parent);
46
                    else
47
                        shape = new TextBox(spContainer, parent);
48
                }
49
                break;
49
                break;
50
            case ShapeTypes.TextBox:
51
                shape = new TextBox(spContainer, parent);
52
                break;
53
            case ShapeTypes.PictureFrame:
50
            case ShapeTypes.PictureFrame:
54
                shape = new Picture(spContainer, parent);
51
                shape = new Picture(spContainer, parent);
55
                break;
52
                break;
Lines 57-63 Link Here
57
                shape = new Line(spContainer, parent);
54
                shape = new Line(spContainer, parent);
58
                break;
55
                break;
59
            case ShapeTypes.NotPrimitive:
56
            case ShapeTypes.NotPrimitive:
60
                shape = new ShapeGroup(spContainer, parent);
57
                if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)
58
                     shape = new ShapeGroup(spContainer, parent);
59
                else
60
                    shape = new AutoShape(spContainer, parent);
61
                break;
61
                break;
62
            default:
62
            default:
63
                shape = new AutoShape(spContainer, parent);
63
                shape = new AutoShape(spContainer, parent);
(-)src/scratchpad/src/org/apache/poi/hslf/model/AutoShape.java (-9 / +7 lines)
Lines 45-62 Link Here
45
        short type = (short)((shapeType << 4) | 0x2);
45
        short type = (short)((shapeType << 4) | 0x2);
46
        spRecord.setOptions(type);
46
        spRecord.setOptions(type);
47
47
48
        //set default properties for a line
48
        //set default properties for an autoshape
49
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
49
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
50
50
51
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 134217732));
51
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004));
52
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 134217728));
52
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000));
53
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 1048592));
53
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100010));
54
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 134217729));
54
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001));
55
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 524296));
55
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008));
56
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 134217730));
56
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002));
57
57
58
        opt.sortProperties();
59
60
        return spcont;
58
        return spcont;
61
    }
59
    }
62
60
(-)src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java (-158 / +36 lines)
Lines 70-80 Link Here
70
    public static final int AlignJustify = 3;
70
    public static final int AlignJustify = 3;
71
71
72
    /**
72
    /**
73
     * Default font size
74
     */
75
    public static final int DefaultFontSize = 24;
76
77
    /**
78
     * Low-level object which holds actual text and format data
73
     * Low-level object which holds actual text and format data
79
     */
74
     */
80
    protected TextRun _txtrun;
75
    protected TextRun _txtrun;
Lines 139-153 Link Here
139
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
134
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
140
        setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
135
        setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
141
136
142
        setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, 134217732);
137
        setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, 0x8000004);
143
        setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, 134217728);
138
        setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
144
        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 1048576);
139
        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
145
        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 134217729);
140
        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
146
        setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 524288);
141
        setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
147
        setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 134217730);
142
        setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
148
143
149
        opt.sortProperties();
150
151
        //create EscherTextboxWrapper
144
        //create EscherTextboxWrapper
152
        _txtbox = new EscherTextboxWrapper();
145
        _txtbox = new EscherTextboxWrapper();
153
146
Lines 155-167 Link Here
155
        tha.setParentRecord(_txtbox); // TextHeaderAtom is parent aware
148
        tha.setParentRecord(_txtbox); // TextHeaderAtom is parent aware
156
        _txtbox.appendChildRecord(tha);
149
        _txtbox.appendChildRecord(tha);
157
150
158
        TextBytesAtom tba = new TextBytesAtom();
151
        TextCharsAtom tca = new TextCharsAtom();
159
        _txtbox.appendChildRecord(tba);
152
        _txtbox.appendChildRecord(tca);
160
153
161
        StyleTextPropAtom sta = new StyleTextPropAtom(0);
154
        StyleTextPropAtom sta = new StyleTextPropAtom(0);
162
        _txtbox.appendChildRecord(sta);
155
        _txtbox.appendChildRecord(sta);
163
156
164
        _txtrun = new TextRun(tha,tba,sta);
157
        _txtrun = new TextRun(tha,tca,sta);
165
        _txtrun.setText("");
158
        _txtrun.setText("");
166
        spcont.addChildRecord(_txtbox.getEscherRecord());
159
        spcont.addChildRecord(_txtbox.getEscherRecord());
167
160
Lines 205-244 Link Here
205
    }
198
    }
206
199
207
    /**
200
    /**
208
     * Returns the bounds of this <code>TextFrame</code>.
201
     * Adjust the size of the TextBox so it encompasses the text inside it.
209
     * <code>Note</b>, this is very primitive estimation, the precision is poor.
210
     *
211
     * @return  the bounds of this <code>TextFrame</code>.
212
     */
202
     */
213
    protected Dimension getTextDimensions(){
203
    public void resizeToFitText(){
204
        try{
214
        FontRenderContext frc = new FontRenderContext(null, true, true);
205
        FontRenderContext frc = new FontRenderContext(null, true, true);
215
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
206
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
216
        int size = rt.getFontSize();
207
        int size = rt.getFontSize();
217
        if (size == -1) size = TextBox.DefaultFontSize;
218
        int style = 0;
208
        int style = 0;
219
        if (rt.isBold()) style |= Font.BOLD;
209
        if (rt.isBold()) style |= Font.BOLD;
220
        if (rt.isItalic()) style |= Font.ITALIC;
210
        if (rt.isItalic()) style |= Font.ITALIC;
221
        String fntname = rt.getFontName();
211
        String fntname = rt.getFontName();
222
        if (fntname == null) //get the default font from Document.Environment.FontCollection
223
            fntname = getSheet().getSlideShow().getDocumentRecord().getEnvironment().getFontCollection().getFontWithId(0);
224
        Font font = new Font(fntname, style, size);
212
        Font font = new Font(fntname, style, size);
225
213
226
        TextLayout layout = new TextLayout(getText(), font, frc);
214
        TextLayout layout = new TextLayout(getText(), font, frc);
227
        int width = Math.round(layout.getAdvance());
215
        int width = Math.round(layout.getAdvance());
228
        width += getMarginLeft() + getMarginRight() + 2;
229
        int height = Math.round(layout.getAscent());
216
        int height = Math.round(layout.getAscent());
230
        height += getMarginTop() + getMarginBottom() + 12;
231
        return new Dimension(width, height);
232
    }
233
217
234
    /**
218
        Dimension txsize = new Dimension(width, height);
235
     * Adjust the size of the TextBox so it encompasses the text inside it.
236
     */
237
    public void resizeToFitText(){
238
        Dimension size = getTextDimensions();
239
        java.awt.Rectangle anchor = getAnchor();
219
        java.awt.Rectangle anchor = getAnchor();
240
        anchor.setSize(size);
220
        anchor.setSize(txsize);
241
        setAnchor(anchor);
221
        setAnchor(anchor);
222
        } catch (Exception e){
223
            e.printStackTrace();
224
225
        }
242
    }
226
    }
243
227
244
    /**
228
    /**
Lines 250-256 Link Here
250
    public int getVerticalAlignment(){
234
    public int getVerticalAlignment(){
251
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
235
        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
252
        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
236
        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
253
        return prop == null ? AlignCenter : prop.getPropertyValue();
237
        int valign;
238
        if (prop == null){
239
            int type = getTextRun().getRunType();
240
            switch (type){
241
                case TextHeaderAtom.TITLE_TYPE:
242
                case TextHeaderAtom.CENTER_TITLE_TYPE:
243
                    valign = TextBox.AnchorMiddle;
244
                    break;
245
                default:
246
                    valign = TextBox.AnchorTop;
247
                    break;
248
            }
249
        } else {
250
            valign = prop.getPropertyValue();
251
        }
252
        return valign;
254
    }
253
    }
255
254
256
    /**
255
    /**
Lines 425-553 Link Here
425
         return _txtrun;
424
         return _txtrun;
426
     }
425
     }
427
426
428
    /**
427
     public void setSheet(Sheet sheet){
429
      * @return  array of RichTextRun objects which control text formatting in this text box
430
      */
431
     public RichTextRun[] getRichTextRuns(){
432
         return _txtrun.getRichTextRuns();
433
     }
434
435
    /**
436
     * Sets the <code>Font</code> object for this text frame
437
     *
438
     * @param size  the size of the font
439
	 *
440
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
441
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
442
	 */
443
    public void setFontSize(int size){
444
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
445
        rt.setFontSize(size);
446
    }
447
448
    /**
449
     *
450
     * @return  the size of the font applied to this text shape
451
     *
452
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
453
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
454
     */
455
    public int getFontSize(){
456
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
457
        return rt.getFontSize();
458
    }
459
460
    /**
461
     *
462
     * @return  the size of the font applied to this text shape
463
     *
464
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
465
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
466
     */
467
    public Color getFontColor(){
468
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
469
        Color color = new Color(rt.getFontColor());
470
        //in PowerPont RGB bytes are swapped,
471
        return new Color(color.getBlue(), color.getGreen(), color.getRed(), 255);
472
    }
473
474
    /**
475
     * Set whether to use bold or not
476
     *
477
     * @param bold  <code>true</code>   if the text should be bold, <code>false</code>  otherwise
478
     *
479
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
480
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
481
     */
482
    public void setBold(boolean bold){
483
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
484
        rt.setBold(bold);
485
    }
486
487
    /**
488
     * Set whether to use italic or not
489
     *
490
     * @param italic  <code>true</code>   if the text should be italic, <code>false</code>  otherwise
491
     *
492
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
493
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
494
     */
495
    public void setItalic(boolean italic){
496
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
497
        rt.setItalic(italic);
498
    }
499
500
    /**
501
     * Set whether to use underline or not
502
     *
503
     * @param underline  <code>true</code>   if the text should be underlined, <code>false</code>  otherwise
504
     *
505
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
506
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
507
     */
508
    public void setUnderline(boolean underline){
509
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
510
        rt.setUnderlined(underline);
511
    }
512
513
    /**
514
     *  Sets the font of this text shape
515
     *
516
     * @param name  the name of the font to be applied to this text shape
517
     *
518
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
519
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
520
     */
521
    public void setFontName(String name){
522
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
523
        rt.setFontName(name);
524
    }
525
526
    /**
527
     * Sets the font color
528
     * @param color  the font color
529
     *
530
	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
531
	 * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
532
     */
533
    public void setFontColor(Color color){
534
        //in PowerPont RGB bytes are swapped,
535
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
536
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
537
        rt.setFontColor(rgb);
538
    }
539
540
    /**
541
     * Set type of the text.
542
     * Must be one of the static constants defined in <code>TextHeaderAtom</code>
543
     *
544
     * @param type type of the text
545
     */
546
    public void setTextType(int type){
547
        _txtrun._headerAtom.setTextType(type);
548
    }
549
    
550
    public void setSheet(Sheet sheet){
551
        _sheet = sheet;
428
        _sheet = sheet;
552
429
553
        // Initialize _txtrun object.
430
        // Initialize _txtrun object.
Lines 564-569 Link Here
564
        }
441
        }
565
        
442
        
566
        // Supply the sheet to our child RichTextRuns
443
        // Supply the sheet to our child RichTextRuns
444
        _txtrun.setSheet(sheet);
567
        RichTextRun[] rt = _txtrun.getRichTextRuns();
445
        RichTextRun[] rt = _txtrun.getRichTextRuns();
568
        for (int i = 0; i < rt.length; i++) {
446
        for (int i = 0; i < rt.length; i++) {
569
            rt[i].supplySlideShow(_sheet.getSlideShow());
447
            rt[i].supplySlideShow(_sheet.getSlideShow());
(-)src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java (+111 lines)
Line 0 Link Here
1
2
/* ====================================================================
3
   Copyright 2002-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
        
18
19
package org.apache.poi.hslf.record;
20
21
import java.io.IOException;
22
import java.io.OutputStream;
23
import java.util.ArrayList;
24
25
import org.apache.poi.util.LittleEndian;
26
27
/**
28
 * Master slide
29
 *
30
 * @author Yegor Kozlov
31
 */
32
33
public class MainMaster extends PositionDependentRecordContainer
34
{
35
	private byte[] _header;
36
	private static long _type = 1016;
37
38
	// Links to our more interesting children
39
	private SlideAtom slideAtom;
40
	private PPDrawing ppDrawing;
41
    private TxMasterStyleAtom[] txmasters;
42
    private ColorSchemeAtom[] clrscheme;
43
    private ColorSchemeAtom _colorScheme;
44
45
	/**
46
	 * Returns the SlideAtom of this Slide
47
	 */
48
	public SlideAtom getSlideAtom() { return slideAtom; }
49
50
	/**
51
	 * Returns the PPDrawing of this Slide, which has all the 
52
	 *  interesting data in it
53
	 */
54
	public PPDrawing getPPDrawing() { return ppDrawing; }
55
56
    public TxMasterStyleAtom[] getTxMasterStyleAtoms() { return txmasters; }
57
58
    public ColorSchemeAtom[] getColorSchemeAtoms() { return clrscheme; }
59
60
	/** 
61
	 * Set things up, and find our more interesting children
62
	 */
63
	protected MainMaster(byte[] source, int start, int len) {
64
		// Grab the header
65
		_header = new byte[8];
66
		System.arraycopy(source,start,_header,0,8);
67
68
		// Find our children
69
		_children = Record.findChildRecords(source,start+8,len-8);
70
71
        ArrayList tx = new ArrayList();
72
        ArrayList clr = new ArrayList();
73
		// Find the interesting ones in there
74
		for(int i=0; i<_children.length; i++) {
75
			if(_children[i] instanceof SlideAtom) {
76
				slideAtom = (SlideAtom)_children[i];
77
			} else if(_children[i] instanceof PPDrawing) {
78
				ppDrawing = (PPDrawing)_children[i];
79
            } else if(_children[i] instanceof TxMasterStyleAtom) {
80
                tx.add(_children[i]);
81
            } else if(_children[i] instanceof ColorSchemeAtom) {
82
                clr.add(_children[i]);
83
			}
84
85
            if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
86
                _colorScheme = (ColorSchemeAtom)_children[i];
87
            }
88
89
		}
90
        txmasters = (TxMasterStyleAtom[])tx.toArray(new TxMasterStyleAtom[tx.size()]);
91
        clrscheme = (ColorSchemeAtom[])clr.toArray(new ColorSchemeAtom[clr.size()]);
92
	}
93
94
	/**
95
	 * We are of type 1016
96
	 */
97
	public long getRecordType() { return _type; }
98
	
99
	/**
100
	 * Write the contents of the record back, so it can be written
101
	 *  to disk
102
	 */
103
	public void writeOut(OutputStream out) throws IOException {
104
		writeOut(_header[0],_header[1],_type,_children,out);
105
	}
106
107
    public ColorSchemeAtom getColorScheme(){
108
        return _colorScheme;
109
    }
110
    
111
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java (-1 / +1 lines)
Lines 44-50 Link Here
44
    public static final Type Environment = new Type(1010,Environment.class);
44
    public static final Type Environment = new Type(1010,Environment.class);
45
    public static final Type SlidePersistAtom = new Type(1011,SlidePersistAtom.class);
45
    public static final Type SlidePersistAtom = new Type(1011,SlidePersistAtom.class);
46
    public static final Type SSlideLayoutAtom = new Type(1015,null);
46
    public static final Type SSlideLayoutAtom = new Type(1015,null);
47
    public static final Type MainMaster = new Type(1016,DummyPositionSensitiveRecordWithChildren.class);
47
    public static final Type MainMaster = new Type(1016,MainMaster.class);
48
    public static final Type SSSlideInfoAtom = new Type(1017,null);
48
    public static final Type SSSlideInfoAtom = new Type(1017,null);
49
    public static final Type SlideViewInfo = new Type(1018,null);
49
    public static final Type SlideViewInfo = new Type(1018,null);
50
    public static final Type GuideAtom = new Type(1019,null);
50
    public static final Type GuideAtom = new Type(1019,null);
(-)src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java (+2 lines)
Lines 49-54 Link Here
49
49
50
	/** Get the ID of the master slide used. 0 if this is a master slide, otherwise -2147483648 */
50
	/** Get the ID of the master slide used. 0 if this is a master slide, otherwise -2147483648 */
51
	public int getMasterID() { return masterID; }
51
	public int getMasterID() { return masterID; }
52
    /** Change slide master.  */ 
53
    public void setMasterID(int id) { masterID = id; }
52
	/** Get the ID of the notes for this slide. 0 if doesn't have one */
54
	/** Get the ID of the notes for this slide. 0 if doesn't have one */
53
	public int getNotesID()  { return notesID; }
55
	public int getNotesID()  { return notesID; }
54
	/** Get the embeded SSlideLayoutAtom */
56
	/** Get the embeded SSlideLayoutAtom */
(-)src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java (+13 lines)
Lines 205-208 Link Here
205
		writeLittleEndian(accentAndHyperlinkColourRGB,out);
205
		writeLittleEndian(accentAndHyperlinkColourRGB,out);
206
		writeLittleEndian(accentAndFollowingHyperlinkColourRGB,out);
206
		writeLittleEndian(accentAndFollowingHyperlinkColourRGB,out);
207
	}
207
	}
208
209
    /**
210
     * Returns color by its index
211
     *
212
     * @param idx 0-based color index
213
     * @return color by its index
214
     */
215
    public int getColor(int idx){
216
        int[] clr = {backgroundColourRGB, textAndLinesColourRGB, shadowsColourRGB, titleTextColourRGB,
217
            fillsColourRGB, accentColourRGB, accentAndHyperlinkColourRGB, accentAndFollowingHyperlinkColourRGB};
218
        return clr[idx];
219
    }
220
208
}
221
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/Slide.java (-1 / +10 lines)
Lines 38-43 Link Here
38
	// Links to our more interesting children
38
	// Links to our more interesting children
39
	private SlideAtom slideAtom;
39
	private SlideAtom slideAtom;
40
	private PPDrawing ppDrawing;
40
	private PPDrawing ppDrawing;
41
    private ColorSchemeAtom _colorScheme;
41
42
42
	/**
43
	/**
43
	 * Returns the SlideAtom of this Slide
44
	 * Returns the SlideAtom of this Slide
Lines 67-75 Link Here
67
			if(_children[i] instanceof SlideAtom) {
68
			if(_children[i] instanceof SlideAtom) {
68
				slideAtom = (SlideAtom)_children[i];
69
				slideAtom = (SlideAtom)_children[i];
69
			}
70
			}
70
			if(_children[i] instanceof PPDrawing) {
71
			else if(_children[i] instanceof PPDrawing) {
71
				ppDrawing = (PPDrawing)_children[i];
72
				ppDrawing = (PPDrawing)_children[i];
72
			}
73
			}
74
75
            if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
76
                _colorScheme = (ColorSchemeAtom)_children[i];
77
            }
73
		}
78
		}
74
	}
79
	}
75
80
Lines 107-110 Link Here
107
	public void writeOut(OutputStream out) throws IOException {
112
	public void writeOut(OutputStream out) throws IOException {
108
		writeOut(_header[0],_header[1],_type,_children,out);
113
		writeOut(_header[0],_header[1],_type,_children,out);
109
	}
114
	}
115
116
    public ColorSchemeAtom getColorScheme(){
117
        return _colorScheme;
118
    }
110
}
119
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/Environment.java (-1 / +8 lines)
Lines 34-39 Link Here
34
34
35
	// Links to our more interesting children
35
	// Links to our more interesting children
36
	private FontCollection fontCollection;
36
	private FontCollection fontCollection;
37
    //master style for text with type=TextHeaderAtom.OTHER_TYPE
38
    private TxMasterStyleAtom txmaster;
37
39
38
	/**
40
	/**
39
	 * Returns the FontCollection of this Environment
41
	 * Returns the FontCollection of this Environment
Lines 56-62 Link Here
56
		for(int i=0; i<_children.length; i++) {
58
		for(int i=0; i<_children.length; i++) {
57
			if(_children[i] instanceof FontCollection) {
59
			if(_children[i] instanceof FontCollection) {
58
				fontCollection = (FontCollection)_children[i];
60
				fontCollection = (FontCollection)_children[i];
59
			}
61
			} else if (_children[i] instanceof TxMasterStyleAtom){
62
                txmaster = (TxMasterStyleAtom)_children[i];
63
            }
60
		}
64
		}
61
		
65
		
62
		if(fontCollection == null) {
66
		if(fontCollection == null) {
Lines 64-69 Link Here
64
		}
68
		}
65
	}
69
	}
66
70
71
    public TxMasterStyleAtom getTxMasterStyleAtom(){
72
        return txmaster;
73
    }
67
74
68
	/**
75
	/**
69
	 * We are of type 1010
76
	 * We are of type 1010
(-)src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java (-7 / +12 lines)
Lines 8-13 Link Here
8
import org.apache.poi.hslf.HSLFSlideShow;
8
import org.apache.poi.hslf.HSLFSlideShow;
9
import org.apache.poi.hslf.model.Slide;
9
import org.apache.poi.hslf.model.Slide;
10
import org.apache.poi.hslf.model.TextRun;
10
import org.apache.poi.hslf.model.TextRun;
11
import org.apache.poi.hslf.model.SlideMaster;
11
import org.apache.poi.hslf.record.Record;
12
import org.apache.poi.hslf.record.Record;
12
import org.apache.poi.hslf.record.SlideListWithText;
13
import org.apache.poi.hslf.record.SlideListWithText;
13
14
Lines 114-120 Link Here
114
	 *  rich text runs
115
	 *  rich text runs
115
	 */
116
	 */
116
	public void testFontSize() throws Exception {
117
	public void testFontSize() throws Exception {
117
		Slide slideOne = ss.getSlides()[0];
118
		SlideMaster master;
119
        Slide slideOne = ss.getSlides()[0];
118
		TextRun[] textRuns = slideOne.getTextRuns();
120
		TextRun[] textRuns = slideOne.getTextRuns();
119
		RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
121
		RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
120
		
122
		
Lines 124-136 Link Here
124
		RichTextRun rtrRb = textRunsR[1].getRichTextRuns()[0];
126
		RichTextRun rtrRb = textRunsR[1].getRichTextRuns()[0];
125
		RichTextRun rtrRc = textRunsR[1].getRichTextRuns()[3];
127
		RichTextRun rtrRc = textRunsR[1].getRichTextRuns()[3];
126
128
129
        String defaultFont = "Arial";
130
127
		// Start off with rich one
131
		// Start off with rich one
128
		// First run has defaults
132
		// First run has defaults
129
		assertEquals(-1, rtrRa.getFontSize());
133
        assertEquals(44, rtrRa.getFontSize());
130
		assertEquals(null, rtrRa.getFontName());
134
		assertEquals(defaultFont, rtrRa.getFontName());
135
131
		// Second is size 20, default font
136
		// Second is size 20, default font
132
		assertEquals(20, rtrRb.getFontSize());
137
		assertEquals(20, rtrRb.getFontSize());
133
		assertEquals(null, rtrRb.getFontName());
138
		assertEquals(defaultFont, rtrRb.getFontName());
134
		// Third is size 24, alt font
139
		// Third is size 24, alt font
135
		assertEquals(24, rtrRc.getFontSize());
140
		assertEquals(24, rtrRc.getFontSize());
136
		assertEquals("Times New Roman", rtrRc.getFontName());
141
		assertEquals("Times New Roman", rtrRc.getFontName());
Lines 145-152 Link Here
145
		
150
		
146
		
151
		
147
		// Now do non rich one
152
		// Now do non rich one
148
		assertEquals(-1, rtr.getFontSize());
153
		assertEquals(44, rtr.getFontSize());
149
		assertEquals(null, rtr.getFontName());
154
		assertEquals(defaultFont, rtr.getFontName());
150
		assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
155
		assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
151
		assertNull(rtr._getRawCharacterStyle());
156
		assertNull(rtr._getRawCharacterStyle());
152
		assertNull(rtr._getRawParagraphStyle());
157
		assertNull(rtr._getRawParagraphStyle());
Lines 154-160 Link Here
154
		// Change Font size
159
		// Change Font size
155
		rtr.setFontSize(99);
160
		rtr.setFontSize(99);
156
		assertEquals(99, rtr.getFontSize());
161
		assertEquals(99, rtr.getFontSize());
157
		assertEquals(null, rtr.getFontName());
162
		assertEquals(defaultFont, rtr.getFontName());
158
		assertNotNull(rtr._getRawCharacterStyle());
163
		assertNotNull(rtr._getRawCharacterStyle());
159
		assertNotNull(rtr._getRawParagraphStyle());
164
		assertNotNull(rtr._getRawParagraphStyle());
160
		assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
165
		assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
(-)src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java (-6 / +7 lines)
Lines 46-60 Link Here
46
46
47
        // Create a new textbox, and give it lots of properties
47
        // Create a new textbox, and give it lots of properties
48
        TextBox txtbox = new TextBox();
48
        TextBox txtbox = new TextBox();
49
        rt = txtbox.getTextRun().getRichTextRuns()[0];
49
        txtbox.setText(val);
50
        txtbox.setText(val);
50
        txtbox.setFontSize(42);
51
        rt.setFontSize(42);
51
        txtbox.setBold(true);
52
        rt.setBold(true);
52
        txtbox.setItalic(true);
53
        rt.setItalic(true);
53
        txtbox.setUnderline(false);
54
        rt.setUnderlined(false);
54
        sl.addShape(txtbox);
55
        sl.addShape(txtbox);
55
56
56
        // Check it before save
57
        // Check it before save
57
        rt = txtbox.getRichTextRuns()[0];
58
        rt = txtbox.getTextRun().getRichTextRuns()[0];
58
        assertEquals(val, rt.getText());
59
        assertEquals(val, rt.getText());
59
        assertEquals(42, rt.getFontSize());
60
        assertEquals(42, rt.getFontSize());
60
        assertTrue(rt.isBold());
61
        assertTrue(rt.isBold());
Lines 69-75 Link Here
69
        sl = ppt.getSlides()[0];
70
        sl = ppt.getSlides()[0];
70
71
71
        txtbox = (TextBox)sl.getShapes()[0];
72
        txtbox = (TextBox)sl.getShapes()[0];
72
        rt = txtbox.getRichTextRuns()[0];
73
        rt = txtbox.getTextRun().getRichTextRuns()[0];
73
74
74
        // Check after save
75
        // Check after save
75
        assertEquals(val, rt.getText());
76
        assertEquals(val, rt.getText());
(-)src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java (-15 / +15 lines)
Lines 50-58 Link Here
50
        Line line = new Line();
50
        Line line = new Line();
51
        java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
51
        java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
52
        line.setAnchor(lineAnchor);
52
        line.setAnchor(lineAnchor);
53
        System.out.println(line.getAnchor());
54
        line.setLineWidth(3);
53
        line.setLineWidth(3);
55
        line.setLineStyle(Line.LineDashSys);
54
        line.setLineStyle(Line.PEN_DASH);
56
        line.setLineColor(Color.red);
55
        line.setLineColor(Color.red);
57
        slide.addShape(line);
56
        slide.addShape(line);
58
57
Lines 60-66 Link Here
60
        java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);
59
        java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);
61
        ellipse.setAnchor(ellipseAnchor);
60
        ellipse.setAnchor(ellipseAnchor);
62
        ellipse.setLineWidth(2);
61
        ellipse.setLineWidth(2);
63
        ellipse.setLineStyle(Line.LineSolid);
62
        ellipse.setLineStyle(Line.PEN_SOLID);
64
        ellipse.setLineColor(Color.green);
63
        ellipse.setLineColor(Color.green);
65
        ellipse.setFillColor(Color.lightGray);
64
        ellipse.setFillColor(Color.lightGray);
66
        slide.addShape(ellipse);
65
        slide.addShape(ellipse);
Lines 101-108 Link Here
101
            String text = txtbox.getText();
100
            String text = txtbox.getText();
102
            assertNotNull(text);
101
            assertNotNull(text);
103
102
104
            assertEquals(txtbox.getRichTextRuns().length, 1);
103
            assertEquals(txtbox.getTextRun().getRichTextRuns().length, 1);
105
            RichTextRun rt = txtbox.getRichTextRuns()[0];
104
            RichTextRun rt = txtbox.getTextRun().getRichTextRuns()[0];
106
105
107
            if (text.equals("Hello, World!!!")){
106
            if (text.equals("Hello, World!!!")){
108
                assertEquals(32, rt.getFontSize());
107
                assertEquals(32, rt.getFontSize());
Lines 135-158 Link Here
135
134
136
        // Create a new textbox, and give it lots of properties
135
        // Create a new textbox, and give it lots of properties
137
        TextBox txtbox = new TextBox();
136
        TextBox txtbox = new TextBox();
137
        rt = txtbox.getTextRun().getRichTextRuns()[0];
138
        txtbox.setText(val);
138
        txtbox.setText(val);
139
        txtbox.setFontName("Arial");
139
        rt.setFontName("Arial");
140
        txtbox.setFontSize(42);
140
        rt.setFontSize(42);
141
        txtbox.setBold(true);
141
        rt.setBold(true);
142
        txtbox.setItalic(true);
142
        rt.setItalic(true);
143
        txtbox.setUnderline(false);
143
        rt.setUnderlined(false);
144
        txtbox.setFontColor(Color.red);
144
        rt.setFontColor(Color.red);
145
        sl.addShape(txtbox);
145
        sl.addShape(txtbox);
146
146
147
        // Check it before save
147
        // Check it before save
148
        rt = txtbox.getRichTextRuns()[0];
148
        rt = txtbox.getTextRun().getRichTextRuns()[0];
149
        assertEquals(val, rt.getText());
149
        assertEquals(val, rt.getText());
150
        assertEquals(42, rt.getFontSize());
150
        assertEquals(42, rt.getFontSize());
151
        assertTrue(rt.isBold());
151
        assertTrue(rt.isBold());
152
        assertTrue(rt.isItalic());
152
        assertTrue(rt.isItalic());
153
        assertFalse(rt.isUnderlined());
153
        assertFalse(rt.isUnderlined());
154
        assertEquals("Arial", rt.getFontName());
154
        assertEquals("Arial", rt.getFontName());
155
        assertEquals(Color.red, txtbox.getFontColor());
155
        assertEquals(Color.red, rt.getFontColor());
156
156
157
        // Serialize and read again
157
        // Serialize and read again
158
        ByteArrayOutputStream out = new ByteArrayOutputStream();
158
        ByteArrayOutputStream out = new ByteArrayOutputStream();
Lines 162-168 Link Here
162
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
162
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
163
163
164
        txtbox = (TextBox)sl.getShapes()[0];
164
        txtbox = (TextBox)sl.getShapes()[0];
165
        rt = txtbox.getRichTextRuns()[0];
165
        rt = txtbox.getTextRun().getRichTextRuns()[0];
166
166
167
        // Check after save
167
        // Check after save
168
        assertEquals(val, rt.getText());
168
        assertEquals(val, rt.getText());
Lines 171-177 Link Here
171
        assertTrue(rt.isItalic());
171
        assertTrue(rt.isItalic());
172
        assertFalse(rt.isUnderlined());
172
        assertFalse(rt.isUnderlined());
173
        assertEquals("Arial", rt.getFontName());
173
        assertEquals("Arial", rt.getFontName());
174
        assertEquals(Color.red, txtbox.getFontColor());
174
        assertEquals(Color.red, rt.getFontColor());
175
    }
175
    }
176
    
176
    
177
    /**
177
    /**
(-)src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java (+133 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2002-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
package org.apache.poi.hslf.model;
17
18
import junit.framework.*;
19
20
import java.io.FileOutputStream;
21
import java.awt.*;
22
23
import org.apache.poi.hslf.usermodel.SlideShow;
24
import org.apache.poi.hslf.HSLFSlideShow;
25
26
/**
27
 * Test Line shape.
28
 * 
29
 * @author Yegor Kozlov
30
 */
31
public class TestLine extends TestCase {
32
33
    public void setUp() throws Exception {
34
35
    }
36
37
    public void testCreateLines() throws Exception {
38
        SlideShow ppt = new SlideShow();
39
40
        Slide slide = ppt.createSlide();
41
42
        slide.addTitle().setText("Lines tester");
43
44
        Line line;
45
46
        /**
47
         * line styles
48
         */
49
        line = new Line();
50
        line.setAnchor(new Rectangle(75, 200, 300, 0));
51
        line.setLineStyle(Line.LINE_SIMPLE);
52
        line.setLineColor(Color.blue);
53
        slide.addShape(line);
54
55
        line = new Line();
56
        line.setAnchor(new java.awt.Rectangle(75, 230, 300, 0));
57
        line.setLineStyle(Line.LINE_DOUBLE);
58
        line.setLineWidth(3.5);
59
        slide.addShape(line);
60
61
        line = new Line();
62
        line.setAnchor(new java.awt.Rectangle(75, 260, 300, 0));
63
        line.setLineStyle(Line.LINE_TRIPLE);
64
        line.setLineWidth(6);
65
        slide.addShape(line);
66
67
        line = new Line();
68
        line.setAnchor(new java.awt.Rectangle(75, 290, 300, 0));
69
        line.setLineStyle(Line.LINE_THICKTHIN);
70
        line.setLineWidth(4.5);
71
        slide.addShape(line);
72
73
        line = new Line();
74
        line.setAnchor(new java.awt.Rectangle(75, 320, 300, 0));
75
        line.setLineStyle(Line.LINE_THINTHICK);
76
        line.setLineWidth(5.5);
77
        slide.addShape(line);
78
79
        /**
80
         * line dashing
81
         */
82
        line = new Line();
83
        line.setAnchor(new java.awt.Rectangle(450, 200, 300, 0));
84
        line.setLineDashing(Line.PEN_SOLID);
85
        slide.addShape(line);
86
87
        line = new Line();
88
        line.setAnchor(new java.awt.Rectangle(450, 230, 300, 0));
89
        line.setLineDashing(Line.PEN_PS_DASH);
90
        slide.addShape(line);
91
92
        line = new Line();
93
        line.setAnchor(new java.awt.Rectangle(450, 260, 300, 0));
94
        line.setLineDashing(Line.PEN_DOT);
95
        slide.addShape(line);
96
97
        line = new Line();
98
        line.setAnchor(new java.awt.Rectangle(450, 290, 300, 0));
99
        line.setLineDashing(Line.PEN_DOTGEL);
100
        slide.addShape(line);
101
102
        line = new Line();
103
        line.setAnchor(new java.awt.Rectangle(450, 320, 300, 0));
104
        line.setLineDashing(Line.PEN_LONGDASHDOTDOTGEL);
105
        slide.addShape(line);
106
107
        /**
108
         * Combinations
109
         */
110
        line = new Line();
111
        line.setAnchor(new java.awt.Rectangle(75, 400, 300, 0));
112
        line.setLineDashing(Line.PEN_DASHDOT);
113
        line.setLineStyle(Line.LINE_TRIPLE);
114
        line.setLineWidth(5.0);
115
        slide.addShape(line);
116
117
        line = new Line();
118
        line.setAnchor(new java.awt.Rectangle(75, 430, 300, 0));
119
        line.setLineDashing(Line.PEN_DASH);
120
        line.setLineStyle(Line.LINE_THICKTHIN);
121
        line.setLineWidth(4.0);
122
        slide.addShape(line);
123
124
        line = new Line();
125
        line.setAnchor(new java.awt.Rectangle(75, 460, 300, 0));
126
        line.setLineDashing(Line.PEN_DOT);
127
        line.setLineStyle(Line.LINE_DOUBLE);
128
        line.setLineWidth(8.0);
129
        slide.addShape(line);
130
131
    }
132
133
}
(-)src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java (+201 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2002-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
17
package org.apache.poi.hslf.model;
18
19
import junit.framework.TestCase;
20
import org.apache.poi.hslf.usermodel.SlideShow;
21
import org.apache.poi.hslf.usermodel.RichTextRun;
22
import org.apache.poi.hslf.HSLFSlideShow;
23
import org.apache.poi.hslf.record.*;
24
import org.apache.poi.hslf.record.StyleTextPropAtom.*;
25
26
import java.io.ByteArrayOutputStream;
27
import java.io.ByteArrayInputStream;
28
29
/**
30
 * Tests for SlideMaster
31
 * 
32
 * @author Yegor Kozlov
33
 */
34
public class TestSlideMaster extends TestCase{
35
    String home;
36
37
    public void setUp() throws Exception {
38
        home = System.getProperty("HSLF.testdata.path");
39
    }
40
41
    /**
42
     * The reference ppt has two masters.
43
     * Check we can read their attributes.
44
     */
45
    public void testSlideMaster() throws Exception {
46
        SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
47
48
        Environment env = ppt.getDocumentRecord().getEnvironment();
49
50
        SlideMaster[] master = ppt.getSlidesMasters();
51
        assertEquals(2, master.length);
52
53
        //character attributes
54
        assertEquals(40, master[0].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
55
        assertEquals(48, master[1].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
56
57
        int font1 = master[0].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
58
        int font2 = master[1].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
59
        assertEquals("Arial", env.getFontCollection().getFontWithId(font1));
60
        assertEquals("Georgia", env.getFontCollection().getFontWithId(font2));
61
62
        CharFlagsTextProp prop1 = (CharFlagsTextProp)master[0].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
63
        assertEquals(false, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
64
        assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
65
        assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
66
67
        CharFlagsTextProp prop2 = (CharFlagsTextProp)master[1].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
68
        assertEquals(false, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
69
        assertEquals(true, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
70
        assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
71
72
        //now paragraph attributes
73
        assertEquals(0x266B, master[0].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
74
        assertEquals(0x2022, master[1].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
75
76
        int b1 = master[0].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
77
        int b2 = master[1].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
78
        assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
79
        assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
80
    }
81
82
    /**
83
     * If a style attribute is not set ensure it is read from the master
84
     */
85
    public void testMasterAttributes() throws Exception {
86
        SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
87
        Slide[] slide = ppt.getSlides();
88
        assertEquals(2, slide.length);
89
        TextRun[] trun;
90
91
        trun = slide[0].getTextRuns();
92
        for (int i = 0; i < trun.length; i++) {
93
            if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
94
                RichTextRun rt = trun[i].getRichTextRuns()[0];
95
                assertEquals(40, rt.getFontSize());
96
                assertEquals(true, rt.isUnderlined());
97
                assertEquals("Arial", rt.getFontName());
98
            } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
99
                RichTextRun rt;
100
                rt = trun[i].getRichTextRuns()[0];
101
                assertEquals(0, rt.getIndentLevel());
102
                assertEquals(32, rt.getFontSize());
103
                assertEquals("Arial", rt.getFontName());
104
105
                rt = trun[i].getRichTextRuns()[1];
106
                assertEquals(1, rt.getIndentLevel());
107
                assertEquals(28, rt.getFontSize());
108
                assertEquals("Arial", rt.getFontName());
109
110
            }
111
        }
112
113
        trun = slide[1].getTextRuns();
114
        for (int i = 0; i < trun.length; i++) {
115
            if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
116
                RichTextRun rt = trun[i].getRichTextRuns()[0];
117
                assertEquals(48, rt.getFontSize());
118
                assertEquals(true, rt.isItalic());
119
                assertEquals("Georgia", rt.getFontName());
120
            } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
121
                RichTextRun rt;
122
                rt = trun[i].getRichTextRuns()[0];
123
                assertEquals(0, rt.getIndentLevel());
124
                assertEquals(32, rt.getFontSize());
125
                assertEquals("Courier New", rt.getFontName());
126
            }
127
        }
128
129
    }
130
131
    /**
132
     * Check we can dynamically assign a slide master to a slide.
133
     */
134
    public void testChangeSlideMaster() throws Exception {
135
        SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
136
        SlideMaster[] master = ppt.getSlidesMasters();
137
        Slide[] slide = ppt.getSlides();
138
        int sheetNo;
139
140
        //each slide uses its own master
141
        assertEquals(slide[0].getMasterSheet()._getSheetNumber(), master[0]._getSheetNumber());
142
        assertEquals(slide[1].getMasterSheet()._getSheetNumber(), master[1]._getSheetNumber());
143
144
        //all slides use the first master slide
145
        sheetNo = master[0]._getSheetNumber();
146
        for (int i = 0; i < slide.length; i++) {
147
            slide[i].setMasterSheet(master[0]);
148
        }
149
150
        ByteArrayOutputStream out;
151
152
        out = new ByteArrayOutputStream();
153
        ppt.write(out);
154
        out.close();
155
156
        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
157
        master = ppt.getSlidesMasters();
158
        slide = ppt.getSlides();
159
        for (int i = 0; i < slide.length; i++) {
160
            assertEquals(sheetNo, slide[i].getMasterSheet()._getSheetNumber());
161
        }
162
    }
163
164
    /**
165
     * Varify we can read attrubutes for different identtation levels.
166
     * (typical for the "bullted body" placeholder)
167
     */
168
    public void testIndentation() throws Exception {
169
        SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
170
        Slide slide = ppt.getSlides()[0];
171
        TextRun[] trun;
172
173
        trun = slide.getTextRuns();
174
        for (int i = 0; i < trun.length; i++) {
175
            if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
176
                RichTextRun rt = trun[i].getRichTextRuns()[0];
177
                assertEquals(40, rt.getFontSize());
178
                assertEquals(true, rt.isUnderlined());
179
                assertEquals("Arial", rt.getFontName());
180
            } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
181
                RichTextRun[] rt = trun[i].getRichTextRuns();
182
                for (int j = 0; j < rt.length; j++) {
183
                    int indent = rt[j].getIndentLevel();
184
                    switch (indent){
185
                        case 0:
186
                            assertEquals(32, rt[j].getFontSize());
187
                            break;
188
                        case 1:
189
                            assertEquals(28, rt[j].getFontSize());
190
                            break;
191
                        case 2:
192
                            assertEquals(24, rt[j].getFontSize());
193
                            break;
194
                    }
195
                }
196
            }
197
        }
198
199
    }
200
201
}
(-)build.xml (-2 / +2 lines)
Lines 192-198 Link Here
192
       </clover-report>
192
       </clover-report>
193
    </target>
193
    </target>
194
194
195
    <target name="init" depends="check-jars,fetch-jars">
195
    <target name="init" >
196
196
197
        <tstamp>
197
        <tstamp>
198
          <format property="tstamp.year" pattern="yyyy"/>
198
          <format property="tstamp.year" pattern="yyyy"/>
Lines 584-590 Link Here
584
          file="${build.site.src}/src/documentation/content/xdocs/status.xml"
584
          file="${build.site.src}/src/documentation/content/xdocs/status.xml"
585
          tofile="${build.site.src}/status.xml"/>
585
          tofile="${build.site.src}/status.xml"/>
586
586
587
        <ant antfile="${forrest.home}/forrest.antproxy.xml" target="site">
587
        <ant antfile="${forrest.home}/forrest.build.xml" target="site">
588
            <property name="project.home" location="${build.site.src}"/>
588
            <property name="project.home" location="${build.site.src}"/>
589
        </ant>
589
        </ant>
590
590

Return to bug 40753