]> source.dussan.org Git - poi.git/commitdiff
misc improvements in slide rendering
authorYegor Kozlov <yegor@apache.org>
Sat, 19 Apr 2008 11:17:37 +0000 (11:17 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 19 Apr 2008 11:17:37 +0000 (11:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@649798 13f79535-47bb-0310-9956-ffa450edef68

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

index b2eb353439500129644fdfe387ec158a70bd40c8..2c146817ed490b45a3305d84317657beff513d46 100644 (file)
@@ -273,7 +273,7 @@ public class ShapeGroup extends Shape{
         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(),
index 8f31e1f27cb4d83c49076c63168f1cee8f370290..c4eac3d066ed361e17a3e1733d707a884cecaec7 100755 (executable)
@@ -103,13 +103,12 @@ public class TextPainter {
             int startIndex = measurer.getPosition();\r
             int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);\r
 \r
-            int rtIdx = startIndex == 0 ? 0 : startIndex + 1;\r
-            if(startIndex == 0 || startIndex == text.length() - 1) rtIdx = startIndex;\r
-            else rtIdx = startIndex + 1;\r
+            boolean prStart = text.charAt(startIndex) == '\n';\r
+            if(prStart) measurer.setPosition(startIndex++);\r
 \r
-            RichTextRun rt = getRichTextRunAt(rtIdx);\r
+            RichTextRun rt = getRichTextRunAt(startIndex);\r
             if(rt == null) {\r
-                logger.log(POILogger.WARN,  "RichTextRun not found at pos" + (startIndex + 1) + "; text.length: " + text.length());\r
+                logger.log(POILogger.WARN,  "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());\r
                 break;\r
             }\r
 \r
@@ -135,21 +134,24 @@ public class TextPainter {
             int endIndex = measurer.getPosition();\r
 \r
             TextElement el = new TextElement();\r
+            el.ascent = textLayout.getAscent();\r
             el._startIndex = startIndex;\r
             el._endIndex = endIndex;\r
             el._align = rt.getAlignment();\r
             el._text = textLayout;\r
             el._textOffset = rt.getTextOffset();\r
 \r
-            boolean prStart = text.charAt(startIndex) == '\n' || startIndex == 0;\r
-            if (text.charAt(startIndex) == '\n'){\r
+            textHeight += textLayout.getAscent();\r
+            if (prStart || startIndex == 0){\r
                 int spaceBefore = rt.getSpaceBefore();\r
                 if (spaceBefore != 0) {\r
-                    float val = (textLayout.getAscent() + textLayout.getDescent()) * spaceBefore/100;\r
+                    float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceBefore/100;\r
                     textHeight += val;\r
+                    el.ascent += val;\r
                 }\r
             }\r
-            if(rt.isBullet() && prStart){\r
+\r
+            if(rt.isBullet() && (prStart || startIndex == 0)){\r
                 it.setIndex(startIndex);\r
 \r
                 AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()), it.getAttributes());\r
@@ -166,13 +168,22 @@ public class TextPainter {
                 }\r
             }\r
 \r
-            textHeight += textLayout.getAscent() + textLayout.getDescent();\r
 \r
+            float descent = textLayout.getDescent();\r
             int lineSpacing = rt.getLineSpacing();\r
-            if(lineSpacing != 0) el._spacing = textLayout.getLeading()*lineSpacing/100;\r
-            else el._spacing = textLayout.getLeading();\r
-\r
-            textHeight += el._spacing;\r
+            if(lineSpacing != 0) descent += textLayout.getLeading()*lineSpacing/100;\r
+            else descent = textLayout.getLeading();\r
+            textHeight += descent;\r
+\r
+            el.descent = descent;\r
+            if (prStart){\r
+                int spaceAfter = rt.getSpaceAfter();\r
+                if (spaceAfter != 0) {\r
+                    float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceAfter/100;\r
+                    textHeight += val;\r
+                    el.descent += val;\r
+                }\r
+            }\r
 \r
             lines.add(el);\r
         }\r
@@ -180,15 +191,15 @@ public class TextPainter {
         int valign = _shape.getVerticalAlignment();\r
         double y0 = anchor.getY();\r
         switch (valign){\r
-            case TextBox.AnchorTopBaseline:\r
-            case TextBox.AnchorTop:\r
+            case TextShape.AnchorTopBaseline:\r
+            case TextShape.AnchorTop:\r
                 y0 += _shape.getMarginTop();\r
                 break;\r
-            case TextBox.AnchorBottom:\r
+            case TextShape.AnchorBottom:\r
                 y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();\r
                 break;\r
             default:\r
-            case TextBox.AnchorMiddle:\r
+            case TextShape.AnchorMiddle:\r
                 float delta =  (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();\r
                 y0 += _shape.getMarginTop()  + delta/2;\r
                 break;\r
@@ -197,11 +208,12 @@ public class TextPainter {
         //finally draw the text fragments\r
         for (int i = 0; i < lines.size(); i++) {\r
             TextElement elem = (TextElement)lines.get(i);\r
-            y0 += elem._text.getAscent();\r
+            y0 += elem.ascent;\r
 \r
             Point2D.Double pen = new Point2D.Double();\r
             pen.y = y0;\r
             switch (elem._align) {\r
+                default:\r
                 case TextShape.AlignLeft:\r
                     pen.x = anchor.getX() + _shape.getMarginLeft();\r
                     break;\r
@@ -213,24 +225,18 @@ public class TextPainter {
                     pen.x = anchor.getX() + _shape.getMarginLeft() +\r
                             (anchor.getWidth() - elem._text.getAdvance() - _shape.getMarginLeft() - _shape.getMarginRight());\r
                     break;\r
-                default:\r
-                    pen.x = anchor.getX() + _shape.getMarginLeft();\r
-                    break;\r
             }\r
             if(elem._bullet != null){\r
                 elem._bullet.draw(graphics, (float)(pen.x + elem._bulletOffset), (float)pen.y);\r
             }\r
             elem._text.draw(graphics, (float)(pen.x + elem._textOffset), (float)pen.y);\r
 \r
-            y0 += elem._text.getDescent();\r
-            y0 += elem._text.getLeading();\r
-\r
-            y0 += elem._spacing;\r
+            y0 += elem.descent;\r
         }\r
     }\r
 \r
 \r
-    public static class TextElement {\r
+    static class TextElement {\r
         public TextLayout _text;\r
         public int _textOffset;\r
         public TextLayout _bullet;\r
@@ -239,5 +245,6 @@ public class TextPainter {
         public int _startIndex;\r
         public int _endIndex;\r
         public float _spacing;\r
+        public float ascent, descent;\r
     }\r
 }\r
index 52d6f1fd0773e4efdf1b45b7b22dd6f051404418..c58979757e3fbfe181a68f9de1bd6cb5cfbc53df 100644 (file)
@@ -716,6 +716,31 @@ public class RichTextRun {
         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! -------
        
        /**