diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/FontAlignmentProp.java similarity index 71% rename from src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java rename to src/scratchpad/src/org/apache/poi/hslf/model/textproperties/FontAlignmentProp.java index c4c2729bf..c9c911ccf 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/FontAlignmentProp.java @@ -18,17 +18,15 @@ package org.apache.poi.hslf.model.textproperties; /** - * Definition for the alignment text property. + * Definition for the font alignment 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 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 AlignmentTextProp() { - super(2, 0x800, "alignment"); + 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 index 000000000..82430f0de --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextAlignmentProp.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index 4e0654a8a..ad43c4dce 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java index 0b90f15a9..c6a1e12bd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel; import java.awt.Color; import java.util.*; +import org.apache.poi.hslf.model.PPFont; import org.apache.poi.hslf.model.textproperties.*; import org.apache.poi.hslf.record.*; import org.apache.poi.sl.usermodel.TextParagraph; @@ -367,13 +368,13 @@ public final class HSLFTextParagraph implements TextParagraph { int alignInt; switch (align) { default: - case LEFT: alignInt = AlignmentTextProp.LEFT; break; - case CENTER: alignInt = AlignmentTextProp.CENTER; break; - case RIGHT: alignInt = AlignmentTextProp.RIGHT; break; - case DIST: // TODO: DIST doesn't not exist within hslf, check mapping - case JUSTIFY: alignInt = AlignmentTextProp.JUSTIFY; break; - case JUSTIFY_LOW: alignInt = AlignmentTextProp.JUSTIFYLOW; break; - case THAI_DIST: alignInt = AlignmentTextProp.THAIDISTRIBUTED; break; + case LEFT: alignInt = TextAlignmentProp.LEFT; break; + case CENTER: alignInt = TextAlignmentProp.CENTER; break; + case RIGHT: alignInt = TextAlignmentProp.RIGHT; break; + case DIST: alignInt = TextAlignmentProp.DISTRIBUTED; break; + case JUSTIFY: alignInt = TextAlignmentProp.JUSTIFY; break; + case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break; + case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break; } setParaTextPropVal("alignment", alignInt); } @@ -382,23 +383,53 @@ public final class HSLFTextParagraph implements TextParagraph { public org.apache.poi.sl.usermodel.TextParagraph.TextAlign getTextAlign() { switch (getParaTextPropVal("alignment")) { default: - case AlignmentTextProp.LEFT: return TextAlign.LEFT; - case AlignmentTextProp.CENTER: return TextAlign.CENTER; - case AlignmentTextProp.RIGHT: return TextAlign.RIGHT; - case AlignmentTextProp.JUSTIFY: return TextAlign.JUSTIFY; - case AlignmentTextProp.JUSTIFYLOW: return TextAlign.JUSTIFY_LOW; - case AlignmentTextProp.THAIDISTRIBUTED: return TextAlign.THAI_DIST; + case TextAlignmentProp.LEFT: return TextAlign.LEFT; + case TextAlignmentProp.CENTER: return TextAlign.CENTER; + case TextAlignmentProp.RIGHT: return TextAlign.RIGHT; + case TextAlignmentProp.JUSTIFY: return TextAlign.JUSTIFY; + case TextAlignmentProp.JUSTIFYLOW: return TextAlign.JUSTIFY_LOW; + case TextAlignmentProp.DISTRIBUTED: return TextAlign.DIST; + case TextAlignmentProp.THAIDISTRIBUTED: return TextAlign.THAI_DIST; } } - public org.apache.poi.sl.usermodel.TextParagraph.FontAlign getFontAlign() { - // TODO Auto-generated method stub - return null; + @Override + public FontAlign getFontAlign() { + switch(getParaTextPropVal("fontAlign")) { + default: + case -1: return FontAlign.AUTO; + case FontAlignmentProp.BASELINE: return FontAlign.BASELINE; + case FontAlignmentProp.TOP: return FontAlign.TOP; + case FontAlignmentProp.CENTER: return FontAlign.CENTER; + case FontAlignmentProp.BOTTOM: return FontAlign.BOTTOM; + } } - public org.apache.poi.sl.usermodel.TextParagraph.BulletStyle getBulletStyle() { - // TODO Auto-generated method stub - return null; + @Override + public BulletStyle getBulletStyle() { + if (getBulletChar() == 0) return null; + + return new BulletStyle() { + public String getBulletCharacter() { + char chr = HSLFTextParagraph.this.getBulletChar(); + return (chr == 0 ? "" : ""+chr); + } + + public String getBulletFont() { + int fontIdx = HSLFTextParagraph.this.getBulletFont(); + if (fontIdx == -1) return getDefaultFontFamily(); + PPFont ppFont = getSheet().getSlideShow().getFont(fontIdx); + return ppFont.getFontName(); + } + + public double getBulletFontSize() { + return HSLFTextParagraph.this.getBulletSize(); + } + + public Color getBulletFontColor() { + return HSLFTextParagraph.this.getBulletColor(); + } + }; } @Override @@ -460,7 +491,8 @@ public final class HSLFTextParagraph implements TextParagraph { * Returns the bullet character */ public char getBulletChar() { - return (char)getParaTextPropVal("bullet.char"); + int val = getParaTextPropVal("bullet.char"); + return (char)(val == -1 ? 0 : val); } /** diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java index c4cf8bc57..102dbae2b 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextParagraph.java @@ -21,21 +21,26 @@ import java.awt.Color; public interface TextParagraph extends Iterable { + /** * Specifies a list of text alignment types */ public enum TextAlign { /** - * Align text to the left margin. + * For horizontal text, left aligned. + * For vertical text, top aligned. */ LEFT, + /** - * Align text in the center. + * For horizontal text, centered. + * For vertical text, middle aligned. */ CENTER, /** - * Align text to the right margin. + * For horizontal text, right aligned. + * For vertical text, bottom aligned. */ RIGHT, @@ -43,10 +48,25 @@ public interface TextParagraph extends Iterable { * Align text so that it is justified across the whole line. It * is smart in the sense that it will not justify sentences * which are short + * + * For horizontal text, flush left and right. + * For vertical text, flush top and bottom. */ JUSTIFY, + + /** + * Kashida justify low. + */ JUSTIFY_LOW, + + /** + * Distribute space between characters. + */ DIST, + + /** + * Thai distribution justification. + */ THAI_DIST } @@ -54,7 +74,31 @@ public interface TextParagraph extends Iterable { * */ public enum FontAlign { - AUTO, TOP, CENTER, BASELINE, BOTTOM; + AUTO, + + /** + * Characters hang from top of line height. + * Also known as "Hanging" + */ + TOP, + + /** + * Characters centered within line height. + */ + CENTER, + + /** + * Place characters on font baseline. + * Also known as "Roman" + */ + BASELINE, + + /** + * Characters are anchored to the very bottom of a single line. + * This is different than BASELINE because of letters such as "g", "q", and "y". + * Also known as "UpholdFixed" + */ + BOTTOM; } public interface BulletStyle { diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java index d38a21eca..bf93fa79d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java @@ -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;