Added Distributed option to TextAlignment
Added FontAlignment git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1676849 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e6413c3fe7
commit
f0d95c3f8d
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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<HSLFTextRun> {
|
||||
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<HSLFTextRun> {
|
||||
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<HSLFTextRun> {
|
||||
* Returns the bullet character
|
||||
*/
|
||||
public char getBulletChar() {
|
||||
return (char)getParaTextPropVal("bullet.char");
|
||||
int val = getParaTextPropVal("bullet.char");
|
||||
return (char)(val == -1 ? 0 : val);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,21 +21,26 @@ import java.awt.Color;
|
||||
|
||||
|
||||
public interface TextParagraph<T extends TextRun> extends Iterable<T> {
|
||||
|
||||
/**
|
||||
* 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<T extends TextRun> extends Iterable<T> {
|
||||
* 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<T extends TextRun> extends Iterable<T> {
|
||||
*
|
||||
*/
|
||||
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 {
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user