]> source.dussan.org Git - poi.git/commitdiff
Added Distributed option to TextAlignment
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 29 Apr 2015 20:26:05 +0000 (20:26 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 29 Apr 2015 20:26:05 +0000 (20:26 +0000)
Added FontAlignment

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1676849 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java [deleted file]
src/scratchpad/src/org/apache/poi/hslf/model/textproperties/FontAlignmentProp.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextAlignmentProp.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java

diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java
deleted file mode 100644 (file)
index c4c2729..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.model.textproperties;
-
-/**
- * Definition for the alignment text property.
- */
-public class AlignmentTextProp extends TextProp {
-       public static final int LEFT = 0;
-       public static final int CENTER = 1;
-       public static final int RIGHT = 2;
-       public static final int JUSTIFY = 3;
-       public static final int THAIDISTRIBUTED = 5;
-       public static final int JUSTIFYLOW = 6;
-
-       public AlignmentTextProp() {
-               super(2, 0x800, "alignment");
-       }
-}
\ No newline at end of file
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/FontAlignmentProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/FontAlignmentProp.java
new file mode 100644 (file)
index 0000000..c9c911c
--- /dev/null
@@ -0,0 +1,32 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model.textproperties;
+
+/**
+ * Definition for the font alignment property.
+ */
+public class FontAlignmentProp extends TextProp {
+       public static final int BASELINE = 0;
+       public static final int TOP = 1;
+       public static final int CENTER = 2;
+       public static final int BOTTOM = 3;
+
+       public FontAlignmentProp() {
+               super(2, 0x10000, "fontAlign");
+       }
+}
\ No newline at end of file
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextAlignmentProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextAlignmentProp.java
new file mode 100644 (file)
index 0000000..82430f0
--- /dev/null
@@ -0,0 +1,66 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model.textproperties;
+
+/**
+ * Definition for the text alignment property.
+ */
+public class TextAlignmentProp extends TextProp {
+       /**
+        * For horizontal text, left aligned.
+        * For vertical text, top aligned.
+        */
+    public static final int LEFT = 0;
+    
+    /**
+     * For horizontal text, centered.
+     * For vertical text, middle aligned.
+     */
+       public static final int CENTER = 1;
+       
+       /**
+        * For horizontal text, right aligned.
+        * For vertical text, bottom aligned.
+        */
+       public static final int RIGHT = 2;
+       
+       /**
+        * For horizontal text, flush left and right.
+        * For vertical text, flush top and bottom.
+        */
+       public static final int JUSTIFY = 3;
+       
+       /**
+        * Distribute space between characters.
+        */
+       public static final int DISTRIBUTED = 4;
+       
+       /**
+        * Thai distribution justification.
+        */
+       public static final int THAIDISTRIBUTED = 5;
+       
+       /**
+        * Kashida justify low.
+        */
+       public static final int JUSTIFYLOW = 6;
+
+       public TextAlignmentProp() {
+               super(2, 0x800, "alignment");
+       }
+}
\ No newline at end of file
index 4e0654a8a6f7b34775521dcfb7fad59b7c9a14d6..ad43c4dce8a111400e9f86caa1e752d310e77ed2 100644 (file)
@@ -126,7 +126,7 @@ public final class StyleTextPropAtom extends RecordAtom
         new TextProp(2, 0x10, "bullet.font"),
         new TextProp(2, 0x40, "bullet.size"),
         new TextProp(4, 0x20, "bullet.color"),
-        new AlignmentTextProp(),
+        new TextAlignmentProp(),
         new TextProp(2, 0x1000, "linespacing"),
         new TextProp(2, 0x2000, "spacebefore"),
         new TextProp(2, 0x4000, "spaceafter"),
@@ -135,7 +135,7 @@ public final class StyleTextPropAtom extends RecordAtom
         new TextProp(2, 0x400, "bullet.offset"), // indent
         new TextProp(2, 0x8000, "defaultTabSize"),
         new TabStopPropCollection(), // tabstops size is variable!
-        new TextProp(2, 0x10000, "fontAlign"),
+        new FontAlignmentProp(),
         new TextProp(2, 0xE0000, "wrapFlags"), // charWrap | wordWrap | overflow
         new TextProp(2, 0x200000, "textDirection"),
         // 0x400000 MUST be zero and MUST be ignored
index 0b90f15a9d2c56964fbbe499bb47b2213b0b8ab1..c6a1e12bd6822620e9644e782f09440d39cc7e8e 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel;
 import java.awt.Color;\r
 import java.util.*;\r
 \r
+import org.apache.poi.hslf.model.PPFont;\r
 import org.apache.poi.hslf.model.textproperties.*;\r
 import org.apache.poi.hslf.record.*;\r
 import org.apache.poi.sl.usermodel.TextParagraph;\r
@@ -367,13 +368,13 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         int alignInt;\r
         switch (align) {\r
         default:\r
-        case LEFT: alignInt = AlignmentTextProp.LEFT; break;\r
-        case CENTER: alignInt = AlignmentTextProp.CENTER; break;\r
-        case RIGHT: alignInt = AlignmentTextProp.RIGHT; break;\r
-        case DIST: // TODO: DIST doesn't not exist within hslf, check mapping\r
-        case JUSTIFY: alignInt = AlignmentTextProp.JUSTIFY; break;\r
-        case JUSTIFY_LOW: alignInt = AlignmentTextProp.JUSTIFYLOW; break;\r
-        case THAI_DIST: alignInt = AlignmentTextProp.THAIDISTRIBUTED; break;\r
+        case LEFT: alignInt = TextAlignmentProp.LEFT; break;\r
+        case CENTER: alignInt = TextAlignmentProp.CENTER; break;\r
+        case RIGHT: alignInt = TextAlignmentProp.RIGHT; break;\r
+        case DIST: alignInt = TextAlignmentProp.DISTRIBUTED; break;\r
+        case JUSTIFY: alignInt = TextAlignmentProp.JUSTIFY; break;\r
+        case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break;\r
+        case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break;\r
         }\r
         setParaTextPropVal("alignment", alignInt);\r
     }\r
@@ -382,23 +383,53 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
     public org.apache.poi.sl.usermodel.TextParagraph.TextAlign getTextAlign() {\r
         switch (getParaTextPropVal("alignment")) {\r
             default:\r
-            case AlignmentTextProp.LEFT: return TextAlign.LEFT;\r
-            case AlignmentTextProp.CENTER: return TextAlign.CENTER;\r
-            case AlignmentTextProp.RIGHT: return TextAlign.RIGHT;\r
-            case AlignmentTextProp.JUSTIFY: return TextAlign.JUSTIFY;\r
-            case AlignmentTextProp.JUSTIFYLOW: return TextAlign.JUSTIFY_LOW;\r
-            case AlignmentTextProp.THAIDISTRIBUTED: return TextAlign.THAI_DIST;\r
+            case TextAlignmentProp.LEFT: return TextAlign.LEFT;\r
+            case TextAlignmentProp.CENTER: return TextAlign.CENTER;\r
+            case TextAlignmentProp.RIGHT: return TextAlign.RIGHT;\r
+            case TextAlignmentProp.JUSTIFY: return TextAlign.JUSTIFY;\r
+            case TextAlignmentProp.JUSTIFYLOW: return TextAlign.JUSTIFY_LOW;\r
+            case TextAlignmentProp.DISTRIBUTED: return TextAlign.DIST;\r
+            case TextAlignmentProp.THAIDISTRIBUTED: return TextAlign.THAI_DIST;\r
         }\r
     }\r
 \r
-    public org.apache.poi.sl.usermodel.TextParagraph.FontAlign getFontAlign() {\r
-        // TODO Auto-generated method stub\r
-        return null;\r
+    @Override\r
+    public FontAlign getFontAlign() {\r
+        switch(getParaTextPropVal("fontAlign")) {\r
+            default:\r
+            case -1: return FontAlign.AUTO;\r
+            case FontAlignmentProp.BASELINE: return FontAlign.BASELINE;\r
+            case FontAlignmentProp.TOP: return FontAlign.TOP;\r
+            case FontAlignmentProp.CENTER: return FontAlign.CENTER;\r
+            case FontAlignmentProp.BOTTOM: return FontAlign.BOTTOM;\r
+        }\r
     }\r
 \r
-    public org.apache.poi.sl.usermodel.TextParagraph.BulletStyle getBulletStyle() {\r
-        // TODO Auto-generated method stub\r
-        return null;\r
+    @Override\r
+    public BulletStyle getBulletStyle() {\r
+        if (getBulletChar() == 0) return null;\r
+        \r
+        return new BulletStyle() {\r
+            public String getBulletCharacter() {\r
+                char chr =  HSLFTextParagraph.this.getBulletChar();\r
+                return (chr == 0 ? "" : ""+chr);\r
+            }\r
+\r
+            public String getBulletFont() {\r
+                int fontIdx = HSLFTextParagraph.this.getBulletFont();\r
+                if (fontIdx == -1) return getDefaultFontFamily();\r
+                PPFont ppFont = getSheet().getSlideShow().getFont(fontIdx);\r
+                return ppFont.getFontName();\r
+            }\r
+\r
+            public double getBulletFontSize() {\r
+                return HSLFTextParagraph.this.getBulletSize();\r
+            }\r
+\r
+            public Color getBulletFontColor() {\r
+                return HSLFTextParagraph.this.getBulletColor();\r
+            }\r
+        };\r
     }\r
 \r
     @Override\r
@@ -460,7 +491,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
     * Returns the bullet character\r
     */\r
    public char getBulletChar() {\r
-       return (char)getParaTextPropVal("bullet.char");\r
+       int val = getParaTextPropVal("bullet.char");\r
+       return (char)(val == -1 ? 0 : val);\r
    }\r
 \r
    /**\r
index c4cf8bc57e90b131bf965fd524fba08b9b197fbe..102dbae2bcc61253dcaed07e3a9b70e1167bfbae 100644 (file)
@@ -21,21 +21,26 @@ import java.awt.Color;
 \r
 \r
 public interface TextParagraph<T extends TextRun> extends Iterable<T> {\r
+\r
     /**\r
      * Specifies a list of text alignment types\r
      */\r
     public enum TextAlign {\r
         /**\r
-         * Align text to the left margin.\r
+         * For horizontal text, left aligned.\r
+         * For vertical text, top aligned.\r
          */\r
         LEFT,\r
+\r
         /**\r
-         * Align text in the center.\r
+         * For horizontal text, centered.\r
+         * For vertical text, middle aligned.\r
          */\r
         CENTER,\r
 \r
         /**\r
-         * Align text to the right margin.\r
+         * For horizontal text, right aligned.\r
+         * For vertical text, bottom aligned.\r
          */\r
         RIGHT,\r
 \r
@@ -43,10 +48,25 @@ public interface TextParagraph<T extends TextRun> extends Iterable<T> {
          * Align text so that it is justified across the whole line. It\r
          * is smart in the sense that it will not justify sentences\r
          * which are short\r
+         * \r
+         * For horizontal text, flush left and right.\r
+         * For vertical text, flush top and bottom.\r
          */\r
         JUSTIFY,\r
+        \r
+        /**\r
+         * Kashida justify low.\r
+         */    \r
         JUSTIFY_LOW,\r
+\r
+        /**\r
+         * Distribute space between characters.\r
+         */\r
         DIST,\r
+        \r
+        /**\r
+         * Thai distribution justification.\r
+         */\r
         THAI_DIST\r
     }\r
 \r
@@ -54,7 +74,31 @@ public interface TextParagraph<T extends TextRun> extends Iterable<T> {
      * \r
      */\r
     public enum FontAlign {\r
-        AUTO, TOP, CENTER, BASELINE, BOTTOM; \r
+        AUTO,\r
+        \r
+        /**\r
+         * Characters hang from top of line height.\r
+         * Also known as "Hanging"\r
+         */\r
+        TOP,\r
+        \r
+        /**\r
+         * Characters centered within line height.\r
+         */\r
+        CENTER,\r
+        \r
+        /**\r
+         * Place characters on font baseline.\r
+         * Also known as "Roman" \r
+         */\r
+        BASELINE,\r
+        \r
+        /**\r
+         * Characters are anchored to the very bottom of a single line.\r
+         * This is different than BASELINE because of letters such as "g", "q", and "y".\r
+         * Also known as "UpholdFixed"\r
+         */\r
+        BOTTOM; \r
     }\r
     \r
     public interface BulletStyle {\r
index d38a21ecab8d1b3741f0e5def7b73339d3f93941..bf93fa79d3f69c39023c8986a22d44ed895957c7 100644 (file)
@@ -27,8 +27,11 @@ import java.util.List;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.ddf.*;
 import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.sl.usermodel.*;
 import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
+import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
+import org.apache.poi.sl.usermodel.TextParagraph.FontAlign;
+import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
 import org.junit.Before;
 import org.junit.Test;