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

(-)src/documentation/content/xdocs/hslf/how-to-shapes.xml (-6 / +14 lines)
Lines 106-112 Link Here
106
                     corner of the slide. Distances in the drawing layer are measured in points (72 points = 1 inch).
106
                     corner of the slide. Distances in the drawing layer are measured in points (72 points = 1 inch).
107
                   </p>
107
                   </p>
108
                    <source>
108
                    <source>
109
  SlideShow ppt = new SlideShow);
109
        SlideShow ppt = new SlideShow();
110
110
111
  Slide slide = ppt.createSlide();
111
  Slide slide = ppt.createSlide();
112
112
Lines 120-129 Link Here
120
  //TextBox
120
  //TextBox
121
  TextBox txt = new TextBox();
121
  TextBox txt = new TextBox();
122
  txt.setText("Hello, World!");
122
  txt.setText("Hello, World!");
123
  txt.setAnchor(new java.awt.Rectangle(100, 100, 200, 50));
123
        txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));
124
  txt.setFontSize(32);
124
125
  txt.setFontName("Arial");
125
        //use RichTextRun to work with the text format
126
  txt.setBold(true);
126
        RichTextRun rt = txt.getRichTextRuns()[0];
127
        rt.setFontSize(32);
128
        rt.setFontName("Arial");
129
        rt.setBold(true);
130
        rt.setItalic(true);
131
        rt.setUnderlined(true);
132
        rt.setFontColor(Color.red);
133
        rt.setAlignment(TextBox.AlignRight);
134
127
  slide.addShape(txt);
135
  slide.addShape(txt);
128
136
129
  //Autoshape
137
  //Autoshape
Lines 140-146 Link Here
140
  slide.addShape(sh2);
148
  slide.addShape(sh2);
141
149
142
  FileOutputStream out = new FileOutputStream("slideshow.ppt");
150
  FileOutputStream out = new FileOutputStream("slideshow.ppt");
143
  wb.write(out);
151
        ppt.write(out);
144
  out.close();
152
  out.close();
145
                  </source>
153
                  </source>
146
                </section>
154
                </section>
(-)src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java (+47 lines)
Lines 24-29 Link Here
24
import org.apache.poi.hslf.record.StyleTextPropAtom.TextProp;
24
import org.apache.poi.hslf.record.StyleTextPropAtom.TextProp;
25
import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
25
import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
26
26
27
import java.awt.*;
28
27
/**
29
/**
28
 * Represents a run of text, all with the same style
30
 * Represents a run of text, all with the same style
29
 * 
31
 * 
Lines 54-59 Link Here
54
	private boolean sharingParagraphStyle;
56
	private boolean sharingParagraphStyle;
55
	private boolean sharingCharacterStyle;
57
	private boolean sharingCharacterStyle;
56
	
58
	
59
    private String _fontname;
57
	/**
60
	/**
58
	 * Create a new wrapper around a (currently not)
61
	 * Create a new wrapper around a (currently not)
59
	 *  rich text string
62
	 *  rich text string
Lines 104-109 Link Here
104
	 */
107
	 */
105
	public void supplySlideShow(SlideShow ss) {
108
	public void supplySlideShow(SlideShow ss) {
106
		slideShow = ss;
109
		slideShow = ss;
110
        if (_fontname != null) {
111
            setFontName(_fontname);
112
            _fontname = null;
113
        }
107
	}
114
	}
108
	
115
	
109
	/**
116
	/**
Lines 280-289 Link Here
280
	}
287
	}
281
	
288
	
282
	public void setFontName(String fontName) {
289
	public void setFontName(String fontName) {
290
        if (slideShow == null) {
291
            //we can't set font since slideshow is not assigned yet
292
            _fontname = fontName;
293
        } else{
283
		// Get the index for this font (adding if needed)
294
		// Get the index for this font (adding if needed)
284
		int fontIdx = slideShow.getFontCollection().addFont(fontName);
295
		int fontIdx = slideShow.getFontCollection().addFont(fontName);
285
		setCharTextPropVal("font.index", fontIdx);
296
		setCharTextPropVal("font.index", fontIdx);
286
	}
297
	}
298
	}
287
	public String getFontName() {
299
	public String getFontName() {
288
		int fontIdx = getCharTextPropVal("font.index");
300
		int fontIdx = getCharTextPropVal("font.index");
289
		if(fontIdx == -1) { return null; }
301
		if(fontIdx == -1) { return null; }
Lines 305-310 Link Here
305
		setCharTextPropVal("font.color", rgb);
317
		setCharTextPropVal("font.color", rgb);
306
	}
318
	}
307
	
319
	
320
    /**
321
     * Sets color of the text, as a java.awt.Color
322
     */
323
    public void setFontColor(Color color) {
324
        //in PowerPont RGB bytes are swapped,
325
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
326
        setFontColor(rgb);
327
    }
328
329
    /**
330
     * Sets the type of horizontal alignment for the text.
331
     * One of the <code>Align*</code> constants defined in the <code>TextBox</code> class.
332
     *
333
     * @param align - the type of alignment
334
     */
335
    public void setAlignment(int align) {
336
        setParaTextPropVal("alignment", align);
337
    }
338
    /**
339
     * Returns the type of horizontal alignment for the text.
340
     * One of the <code>Align*</code> constants defined in the <code>TextBox</class> class.
341
     *
342
     * @return the type of alignment
343
     */
344
    public int getAlignment() {
345
        return getParaTextPropVal("alignment");
346
    }
347
348
    /**
349
     *
350
     * @return indentation level
351
     */
352
    public int getIndentLevel() {
353
        return paragraphStyle == null ? 0 : paragraphStyle.getReservedField();
354
    }
308
	
355
	
309
	// --------------- Internal HSLF methods, not intended for end-user use! -------
356
	// --------------- Internal HSLF methods, not intended for end-user use! -------
310
	
357
	
(-)src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java (-12 / +24 lines)
Lines 85-92 Link Here
85
     */
85
     */
86
    protected EscherTextboxWrapper _txtbox;
86
    protected EscherTextboxWrapper _txtbox;
87
87
88
    private String _fontname;
89
90
    /**
88
    /**
91
     * Create a TextBox object and initialize it from the supplied Record container.
89
     * Create a TextBox object and initialize it from the supplied Record container.
92
     * 
90
     * 
Lines 432-437 Link Here
432
     * Sets the <code>Font</code> object for this text frame
430
     * Sets the <code>Font</code> object for this text frame
433
     *
431
     *
434
     * @param size  the size of the font
432
     * @param size  the size of the font
433
     *
434
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
435
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
435
     */
436
     */
436
    public void setFontSize(int size){
437
    public void setFontSize(int size){
437
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
438
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
Lines 441-446 Link Here
441
    /**
442
    /**
442
     *
443
     *
443
     * @return  the size of the font applied to this text shape
444
     * @return  the size of the font applied to this text shape
445
     *
446
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
447
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
444
     */
448
     */
445
    public int getFontSize(){
449
    public int getFontSize(){
446
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
450
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
Lines 450-455 Link Here
450
    /**
454
    /**
451
     *
455
     *
452
     * @return  the size of the font applied to this text shape
456
     * @return  the size of the font applied to this text shape
457
     *
458
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
459
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
453
     */
460
     */
454
    public Color getFontColor(){
461
    public Color getFontColor(){
455
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
462
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
Lines 462-467 Link Here
462
     * Set whether to use bold or not
469
     * Set whether to use bold or not
463
     *
470
     *
464
     * @param bold  <code>true</code>   if the text should be bold, <code>false</code>  otherwise
471
     * @param bold  <code>true</code>   if the text should be bold, <code>false</code>  otherwise
472
     *
473
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
474
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
465
     */
475
     */
466
    public void setBold(boolean bold){
476
    public void setBold(boolean bold){
467
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
477
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
Lines 472-477 Link Here
472
     * Set whether to use italic or not
482
     * Set whether to use italic or not
473
     *
483
     *
474
     * @param italic  <code>true</code>   if the text should be italic, <code>false</code>  otherwise
484
     * @param italic  <code>true</code>   if the text should be italic, <code>false</code>  otherwise
485
     *
486
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
487
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
475
     */
488
     */
476
    public void setItalic(boolean italic){
489
    public void setItalic(boolean italic){
477
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
490
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
Lines 482-487 Link Here
482
     * Set whether to use underline or not
495
     * Set whether to use underline or not
483
     *
496
     *
484
     * @param underline  <code>true</code>   if the text should be underlined, <code>false</code>  otherwise
497
     * @param underline  <code>true</code>   if the text should be underlined, <code>false</code>  otherwise
498
     *
499
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
500
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
485
     */
501
     */
486
    public void setUnderline(boolean underline){
502
    public void setUnderline(boolean underline){
487
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
503
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
Lines 492-511 Link Here
492
     *  Sets the font of this text shape
508
     *  Sets the font of this text shape
493
     *
509
     *
494
     * @param name  the name of the font to be applied to this text shape
510
     * @param name  the name of the font to be applied to this text shape
511
     *
512
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
513
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
495
     */
514
     */
496
    public void setFontName(String name){
515
    public void setFontName(String name){
497
        if (_sheet == null) {
498
            //we can't set font since slideshow is not assigned yet
499
            _fontname = name;
500
        } else{
501
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
516
        RichTextRun rt = _txtrun.getRichTextRuns()[0];
502
        rt.setFontName(name);
517
        rt.setFontName(name);
503
    }
518
    }
504
    }
505
519
506
    /**
520
    /**
507
     * Sets the font color
521
     * Sets the font color
508
     * @param color  the font color
522
     * @param color  the font color
523
     *
524
     * @deprecated Use <code>RichTextRun</code> to work with the text format.
525
     * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>
509
     */
526
     */
510
    public void setFontColor(Color color){
527
    public void setFontColor(Color color){
511
        //in PowerPont RGB bytes are swapped,
528
        //in PowerPont RGB bytes are swapped,
Lines 535-545 Link Here
535
        for (int i = 0; i < rt.length; i++) {
552
        for (int i = 0; i < rt.length; i++) {
536
            rt[i].supplySlideShow(_sheet.getSlideShow());
553
            rt[i].supplySlideShow(_sheet.getSlideShow());
537
        }
554
        }
538
        if (_fontname != null) {
539
            setFontName(_fontname);
540
            _fontname = null;
541
        }
542
543
    }
555
    }
544
556
545
    private void initTextRun(){
557
    private void initTextRun(){
(-)src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java (+8 lines)
Lines 490-495 Link Here
490
				}
490
				}
491
			}
491
			}
492
		}
492
		}
493
494
        public short getReservedField(){
495
            return reservedField;
496
        }
497
498
        public void setReservedField(short val){
499
            reservedField = val;
500
        }
493
	}
501
	}
494
502
495
503
(-)src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java (+17 lines)
Lines 3-8 Link Here
3
import java.io.ByteArrayInputStream;
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.FileInputStream;
5
import java.io.FileInputStream;
6
import java.io.File;
6
7
7
import org.apache.poi.hslf.HSLFSlideShow;
8
import org.apache.poi.hslf.HSLFSlideShow;
8
import org.apache.poi.hslf.model.Slide;
9
import org.apache.poi.hslf.model.Slide;
Lines 420-423 Link Here
420
		r.writeOut(baos);
421
		r.writeOut(baos);
421
		return baos.toByteArray();
422
		return baos.toByteArray();
422
	}
423
	}
424
425
    public void testIndentationLevel() throws Exception {
426
        SlideShow ppt = new SlideShow(new HSLFSlideShow(new File(System.getProperty("HSLF.testdata.path"), "ParagraphStylesShorterThanCharStyles.ppt").getPath()));
427
        Slide[] sl = ppt.getSlides();
428
        for (int i = 0; i < sl.length; i++) {
429
            TextRun[] txt = sl[i].getTextRuns();
430
            for (int j = 0; j < txt.length; j++) {
431
                RichTextRun[] rt = txt[j].getRichTextRuns();
432
                for (int k = 0; k < rt.length; k++) {
433
                    int indent = rt[k].getIndentLevel();
434
                    assertTrue(indent >= 0 && indent <= 4 );
435
                }
436
437
            }
438
        }
439
    }
423
}
440
}

Return to bug 40324