poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r448004 - in /jakarta/poi/trunk/src: documentation/content/xdocs/hslf/ scratchpad/src/org/apache/poi/hslf/model/ scratchpad/src/org/apache/poi/hslf/record/ scratchpad/src/org/apache/poi/hslf/usermodel/ scratchpad/testcases/org/apache/poi/hs...
Date Tue, 19 Sep 2006 22:47:45 GMT
Author: nick
Date: Tue Sep 19 15:47:44 2006
New Revision: 448004

URL: http://svn.apache.org/viewvc?view=rev&rev=448004
Log:
Support alignment and indent levels for HSLF - patch from Yegor in bug #40324

Modified:
    jakarta/poi/trunk/src/documentation/content/xdocs/hslf/how-to-shapes.xml
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java

Modified: jakarta/poi/trunk/src/documentation/content/xdocs/hslf/how-to-shapes.xml
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/documentation/content/xdocs/hslf/how-to-shapes.xml?view=diff&rev=448004&r1=448003&r2=448004
==============================================================================
--- jakarta/poi/trunk/src/documentation/content/xdocs/hslf/how-to-shapes.xml (original)
+++ jakarta/poi/trunk/src/documentation/content/xdocs/hslf/how-to-shapes.xml Tue Sep 19 15:47:44
2006
@@ -120,17 +120,17 @@
   //TextBox
   TextBox txt = new TextBox();
   txt.setText("Hello, World!");
-        txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));
+  txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));
 
-        //use RichTextRun to work with the text format
-        RichTextRun rt = txt.getRichTextRuns()[0];
-        rt.setFontSize(32);
-        rt.setFontName("Arial");
-        rt.setBold(true);
-        rt.setItalic(true);
-        rt.setUnderlined(true);
-        rt.setFontColor(Color.red);
-        rt.setAlignment(TextBox.AlignRight);
+  //use RichTextRun to work with the text format
+  RichTextRun rt = txt.getRichTextRuns()[0];
+  rt.setFontSize(32);
+  rt.setFontName("Arial");
+  rt.setBold(true);
+  rt.setItalic(true);
+  rt.setUnderlined(true);
+  rt.setFontColor(Color.red);
+  rt.setAlignment(TextBox.AlignRight);
 
   slide.addShape(txt);
 

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java?view=diff&rev=448004&r1=448003&r2=448004
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java Tue Sep 19
15:47:44 2006
@@ -85,8 +85,6 @@
      */
     protected EscherTextboxWrapper _txtbox;
 
-    private String _fontname;
-
     /**
      * Create a TextBox object and initialize it from the supplied Record container.
      * 
@@ -432,7 +430,10 @@
      * Sets the <code>Font</code> object for this text frame
      *
      * @param size  the size of the font
-     */
+	 *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
+	 */
     public void setFontSize(int size){
         RichTextRun rt = _txtrun.getRichTextRuns()[0];
         rt.setFontSize(size);
@@ -441,6 +442,9 @@
     /**
      *
      * @return  the size of the font applied to this text shape
+     *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
      */
     public int getFontSize(){
         RichTextRun rt = _txtrun.getRichTextRuns()[0];
@@ -450,6 +454,9 @@
     /**
      *
      * @return  the size of the font applied to this text shape
+     *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
      */
     public Color getFontColor(){
         RichTextRun rt = _txtrun.getRichTextRuns()[0];
@@ -462,6 +469,9 @@
      * Set whether to use bold or not
      *
      * @param bold  <code>true</code>   if the text should be bold, <code>false</code>
 otherwise
+     *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
      */
     public void setBold(boolean bold){
         RichTextRun rt = _txtrun.getRichTextRuns()[0];
@@ -472,6 +482,9 @@
      * Set whether to use italic or not
      *
      * @param italic  <code>true</code>   if the text should be italic, <code>false</code>
 otherwise
+     *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
      */
     public void setItalic(boolean italic){
         RichTextRun rt = _txtrun.getRichTextRuns()[0];
@@ -482,6 +495,9 @@
      * Set whether to use underline or not
      *
      * @param underline  <code>true</code>   if the text should be underlined,
<code>false</code>  otherwise
+     *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
      */
     public void setUnderline(boolean underline){
         RichTextRun rt = _txtrun.getRichTextRuns()[0];
@@ -492,20 +508,21 @@
      *  Sets the font of this text shape
      *
      * @param name  the name of the font to be applied to this text shape
+     *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
      */
     public void setFontName(String name){
-        if (_sheet == null) {
-            //we can't set font since slideshow is not assigned yet
-            _fontname = name;
-        } else{
         RichTextRun rt = _txtrun.getRichTextRuns()[0];
         rt.setFontName(name);
     }
-    }
 
     /**
      * Sets the font color
      * @param color  the font color
+     *
+	 * @deprecated Use <code>RichTextRun</code> to work with the text format.
+	 * <p>This method will be permanently removed in a future version of the POI HSLF
API.</p>
      */
     public void setFontColor(Color color){
         //in PowerPont RGB bytes are swapped,
@@ -535,11 +552,6 @@
         for (int i = 0; i < rt.length; i++) {
             rt[i].supplySlideShow(_sheet.getSlideShow());
         }
-        if (_fontname != null) {
-            setFontName(_fontname);
-            _fontname = null;
-        }
-
     }
 
     private void initTextRun(){

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?view=diff&rev=448004&r1=448003&r2=448004
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
Tue Sep 19 15:47:44 2006
@@ -490,6 +490,14 @@
 				}
 			}
 		}
+
+        public short getReservedField(){
+            return reservedField;
+        }
+
+        public void setReservedField(short val){
+            reservedField = val;
+        }
 	}
 
 

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java?view=diff&rev=448004&r1=448003&r2=448004
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java Tue
Sep 19 15:47:44 2006
@@ -24,6 +24,8 @@
 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
  * 
@@ -54,6 +56,7 @@
 	private boolean sharingParagraphStyle;
 	private boolean sharingCharacterStyle;
 	
+    private String _fontname;
 	/**
 	 * Create a new wrapper around a (currently not)
 	 *  rich text string
@@ -104,6 +107,10 @@
 	 */
 	public void supplySlideShow(SlideShow ss) {
 		slideShow = ss;
+        if (_fontname != null) {
+            setFontName(_fontname);
+            _fontname = null;
+        }
 	}
 	
 	/**
@@ -280,10 +287,15 @@
 	}
 	
 	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; }
@@ -305,6 +317,41 @@
 		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! -------
 	

Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java?view=diff&rev=448004&r1=448003&r2=448004
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
Tue Sep 19 15:47:44 2006
@@ -3,6 +3,7 @@
 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;
@@ -420,4 +421,20 @@
 		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 );
+                }
+
+            }
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message