//TextBox\r
TextBox txt = new TextBox();\r
txt.setText("Hello, World!");\r
- txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));\r
+ txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));\r
\r
- //use RichTextRun to work with the text format\r
- RichTextRun rt = txt.getRichTextRuns()[0];\r
- rt.setFontSize(32);\r
- rt.setFontName("Arial");\r
- rt.setBold(true);\r
- rt.setItalic(true);\r
- rt.setUnderlined(true);\r
- rt.setFontColor(Color.red);\r
- rt.setAlignment(TextBox.AlignRight);\r
+ //use RichTextRun to work with the text format\r
+ RichTextRun rt = txt.getRichTextRuns()[0];\r
+ rt.setFontSize(32);\r
+ rt.setFontName("Arial");\r
+ rt.setBold(true);\r
+ rt.setItalic(true);\r
+ rt.setUnderlined(true);\r
+ rt.setFontColor(Color.red);\r
+ rt.setAlignment(TextBox.AlignRight);\r
\r
slide.addShape(txt);\r
\r
*/\r
protected EscherTextboxWrapper _txtbox;\r
\r
- private String _fontname;\r
-\r
/**\r
* Create a TextBox object and initialize it from the supplied Record container.\r
* \r
* Sets the <code>Font</code> object for this text frame\r
*\r
* @param size the size of the font\r
- */\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
+ */\r
public void setFontSize(int size){\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
rt.setFontSize(size);\r
/**\r
*\r
* @return the size of the font applied to this text shape\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
*/\r
public int getFontSize(){\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
/**\r
*\r
* @return the size of the font applied to this text shape\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
*/\r
public Color getFontColor(){\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
* Set whether to use bold or not\r
*\r
* @param bold <code>true</code> if the text should be bold, <code>false</code> otherwise\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
*/\r
public void setBold(boolean bold){\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
* Set whether to use italic or not\r
*\r
* @param italic <code>true</code> if the text should be italic, <code>false</code> otherwise\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
*/\r
public void setItalic(boolean italic){\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
* Set whether to use underline or not\r
*\r
* @param underline <code>true</code> if the text should be underlined, <code>false</code> otherwise\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
*/\r
public void setUnderline(boolean underline){\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
* Sets the font of this text shape\r
*\r
* @param name the name of the font to be applied to this text shape\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
*/\r
public void setFontName(String name){\r
- if (_sheet == null) {\r
- //we can't set font since slideshow is not assigned yet\r
- _fontname = name;\r
- } else{\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
rt.setFontName(name);\r
}\r
- }\r
\r
/**\r
* Sets the font color\r
* @param color the font color\r
+ *\r
+ * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
+ * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
*/\r
public void setFontColor(Color color){\r
//in PowerPont RGB bytes are swapped,\r
for (int i = 0; i < rt.length; i++) {\r
rt[i].supplySlideShow(_sheet.getSlideShow());\r
}\r
- if (_fontname != null) {\r
- setFontName(_fontname);\r
- _fontname = null;\r
- }\r
-\r
}\r
\r
private void initTextRun(){\r
}
}
}
+
+ public short getReservedField(){
+ return reservedField;
+ }
+
+ public void setReservedField(short val){
+ reservedField = val;
+ }
}
import org.apache.poi.hslf.record.StyleTextPropAtom.TextProp;
import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
+import java.awt.*;
+
/**
* Represents a run of text, all with the same style
*
private boolean sharingParagraphStyle;
private boolean sharingCharacterStyle;
+ private String _fontname;
/**
* Create a new wrapper around a (currently not)
* rich text string
*/
public void supplySlideShow(SlideShow ss) {
slideShow = ss;
+ if (_fontname != null) {
+ setFontName(_fontname);
+ _fontname = null;
+ }
}
/**
}
public void setFontName(String fontName) {
+ if (slideShow == null) {
+ //we can't set font since slideshow is not assigned yet
+ _fontname = fontName;
+ } else{
// Get the index for this font (adding if needed)
int fontIdx = slideShow.getFontCollection().addFont(fontName);
setCharTextPropVal("font.index", fontIdx);
}
+ }
public String getFontName() {
int fontIdx = getCharTextPropVal("font.index");
if(fontIdx == -1) { return null; }
setCharTextPropVal("font.color", rgb);
}
+ /**
+ * Sets color of the text, as a java.awt.Color
+ */
+ public void setFontColor(Color color) {
+ //in PowerPont RGB bytes are swapped,
+ int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
+ setFontColor(rgb);
+ }
+
+ /**
+ * Sets the type of horizontal alignment for the text.
+ * One of the <code>Align*</code> constants defined in the <code>TextBox</code> class.
+ *
+ * @param align - the type of alignment
+ */
+ public void setAlignment(int align) {
+ setParaTextPropVal("alignment", align);
+ }
+ /**
+ * Returns the type of horizontal alignment for the text.
+ * One of the <code>Align*</code> constants defined in the <code>TextBox</class> class.
+ *
+ * @return the type of alignment
+ */
+ public int getAlignment() {
+ return getParaTextPropVal("alignment");
+ }
+
+ /**
+ *
+ * @return indentation level
+ */
+ public int getIndentLevel() {
+ return paragraphStyle == null ? 0 : paragraphStyle.getReservedField();
+ }
// --------------- Internal HSLF methods, not intended for end-user use! -------
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
+import java.io.File;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
r.writeOut(baos);
return baos.toByteArray();
}
+
+ public void testIndentationLevel() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(new File(System.getProperty("HSLF.testdata.path"), "ParagraphStylesShorterThanCharStyles.ppt").getPath()));
+ Slide[] sl = ppt.getSlides();
+ for (int i = 0; i < sl.length; i++) {
+ TextRun[] txt = sl[i].getTextRuns();
+ for (int j = 0; j < txt.length; j++) {
+ RichTextRun[] rt = txt[j].getRichTextRuns();
+ for (int k = 0; k < rt.length; k++) {
+ int indent = rt[k].getIndentLevel();
+ assertTrue(indent >= 0 && indent <= 4 );
+ }
+
+ }
+ }
+ }
}