You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/04/19 13:17:47 UTC

svn commit: r649798 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hslf: model/ShapeGroup.java model/TextPainter.java usermodel/RichTextRun.java

Author: yegor
Date: Sat Apr 19 04:17:37 2008
New Revision: 649798

URL: http://svn.apache.org/viewvc?rev=649798&view=rev
Log:
misc improvements in slide rendering

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java?rev=649798&r1=649797&r2=649798&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java Sat Apr 19 04:17:37 2008
@@ -273,7 +273,7 @@
         AffineTransform at = graphics.getTransform();
 
         if(!anchor.equals(coords)){
-            graphics.scale(coords.getWidth()/anchor.getWidth(), coords.getHeight()/anchor.getHeight());
+            graphics.scale(anchor.getWidth()/coords.getWidth(), anchor.getHeight()/coords.getHeight());
 
             graphics.translate(
                     anchor.getX()*coords.getWidth()/anchor.getWidth() - coords.getX(),

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java?rev=649798&r1=649797&r2=649798&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java Sat Apr 19 04:17:37 2008
@@ -103,13 +103,12 @@
             int startIndex = measurer.getPosition();
             int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);
 
-            int rtIdx = startIndex == 0 ? 0 : startIndex + 1;
-            if(startIndex == 0 || startIndex == text.length() - 1) rtIdx = startIndex;
-            else rtIdx = startIndex + 1;
+            boolean prStart = text.charAt(startIndex) == '\n';
+            if(prStart) measurer.setPosition(startIndex++);
 
-            RichTextRun rt = getRichTextRunAt(rtIdx);
+            RichTextRun rt = getRichTextRunAt(startIndex);
             if(rt == null) {
-                logger.log(POILogger.WARN,  "RichTextRun not found at pos" + (startIndex + 1) + "; text.length: " + text.length());
+                logger.log(POILogger.WARN,  "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());
                 break;
             }
 
@@ -135,21 +134,24 @@
             int endIndex = measurer.getPosition();
 
             TextElement el = new TextElement();
+            el.ascent = textLayout.getAscent();
             el._startIndex = startIndex;
             el._endIndex = endIndex;
             el._align = rt.getAlignment();
             el._text = textLayout;
             el._textOffset = rt.getTextOffset();
 
-            boolean prStart = text.charAt(startIndex) == '\n' || startIndex == 0;
-            if (text.charAt(startIndex) == '\n'){
+            textHeight += textLayout.getAscent();
+            if (prStart || startIndex == 0){
                 int spaceBefore = rt.getSpaceBefore();
                 if (spaceBefore != 0) {
-                    float val = (textLayout.getAscent() + textLayout.getDescent()) * spaceBefore/100;
+                    float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceBefore/100;
                     textHeight += val;
+                    el.ascent += val;
                 }
             }
-            if(rt.isBullet() && prStart){
+
+            if(rt.isBullet() && (prStart || startIndex == 0)){
                 it.setIndex(startIndex);
 
                 AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()), it.getAttributes());
@@ -166,13 +168,22 @@
                 }
             }
 
-            textHeight += textLayout.getAscent() + textLayout.getDescent();
 
+            float descent = textLayout.getDescent();
             int lineSpacing = rt.getLineSpacing();
-            if(lineSpacing != 0) el._spacing = textLayout.getLeading()*lineSpacing/100;
-            else el._spacing = textLayout.getLeading();
-
-            textHeight += el._spacing;
+            if(lineSpacing != 0) descent += textLayout.getLeading()*lineSpacing/100;
+            else descent = textLayout.getLeading();
+            textHeight += descent;
+
+            el.descent = descent;
+            if (prStart){
+                int spaceAfter = rt.getSpaceAfter();
+                if (spaceAfter != 0) {
+                    float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceAfter/100;
+                    textHeight += val;
+                    el.descent += val;
+                }
+            }
 
             lines.add(el);
         }
@@ -180,15 +191,15 @@
         int valign = _shape.getVerticalAlignment();
         double y0 = anchor.getY();
         switch (valign){
-            case TextBox.AnchorTopBaseline:
-            case TextBox.AnchorTop:
+            case TextShape.AnchorTopBaseline:
+            case TextShape.AnchorTop:
                 y0 += _shape.getMarginTop();
                 break;
-            case TextBox.AnchorBottom:
+            case TextShape.AnchorBottom:
                 y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();
                 break;
             default:
-            case TextBox.AnchorMiddle:
+            case TextShape.AnchorMiddle:
                 float delta =  (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();
                 y0 += _shape.getMarginTop()  + delta/2;
                 break;
@@ -197,11 +208,12 @@
         //finally draw the text fragments
         for (int i = 0; i < lines.size(); i++) {
             TextElement elem = (TextElement)lines.get(i);
-            y0 += elem._text.getAscent();
+            y0 += elem.ascent;
 
             Point2D.Double pen = new Point2D.Double();
             pen.y = y0;
             switch (elem._align) {
+                default:
                 case TextShape.AlignLeft:
                     pen.x = anchor.getX() + _shape.getMarginLeft();
                     break;
@@ -213,24 +225,18 @@
                     pen.x = anchor.getX() + _shape.getMarginLeft() +
                             (anchor.getWidth() - elem._text.getAdvance() - _shape.getMarginLeft() - _shape.getMarginRight());
                     break;
-                default:
-                    pen.x = anchor.getX() + _shape.getMarginLeft();
-                    break;
             }
             if(elem._bullet != null){
                 elem._bullet.draw(graphics, (float)(pen.x + elem._bulletOffset), (float)pen.y);
             }
             elem._text.draw(graphics, (float)(pen.x + elem._textOffset), (float)pen.y);
 
-            y0 += elem._text.getDescent();
-            y0 += elem._text.getLeading();
-
-            y0 += elem._spacing;
+            y0 += elem.descent;
         }
     }
 
 
-    public static class TextElement {
+    static class TextElement {
         public TextLayout _text;
         public int _textOffset;
         public TextLayout _bullet;
@@ -239,5 +245,6 @@
         public int _startIndex;
         public int _endIndex;
         public float _spacing;
+        public float ascent, descent;
     }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java?rev=649798&r1=649797&r2=649798&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java Sat Apr 19 04:17:37 2008
@@ -716,6 +716,31 @@
         int val = getParaTextPropVal("spacebefore");
         return val == -1 ? 0 : val;
     }
+
+    /**
+     * Sets spacing after a paragraph.
+     * <p>
+     * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
+     * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
+     * </p>
+     */
+    public void setSpaceAfter(int val) {
+        setParaTextPropVal("spaceafter", val);
+    }
+
+    /**
+     * Returns spacing after a paragraph
+     * <p>
+     * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
+     * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
+     * </p>
+     *
+     * @return the spacing before a paragraph
+     */
+    public int getSpaceAfter() {
+        int val = getParaTextPropVal("spaceafter");
+        return val == -1 ? 0 : val;
+    }
 	// --------------- Internal HSLF methods, not intended for end-user use! -------
 	
 	/**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org