Fixed several test drivers or the implementation
renamed font functions in HSLFTextRun git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1682356 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
063e74acf6
commit
d1f9035400
@ -153,7 +153,7 @@ public final class ApacheconEU08 {
|
||||
cell.setText(txt1[i][j]);
|
||||
HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt.setFontSize(10);
|
||||
rt.setFontName("Arial");
|
||||
rt.setFontFamily("Arial");
|
||||
rt.setBold(true);
|
||||
if(i == 0){
|
||||
rt.setFontSize(32);
|
||||
@ -232,7 +232,7 @@ public final class ApacheconEU08 {
|
||||
|
||||
HSLFTextBox box3 = new HSLFTextBox();
|
||||
HSLFTextRun rt3 = box3.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt3.setFontName("Courier New");
|
||||
rt3.setFontFamily("Courier New");
|
||||
rt3.setFontSize(8);
|
||||
box3.setText(
|
||||
"SlideShow ppt = new SlideShow();\u000b" +
|
||||
@ -341,7 +341,7 @@ public final class ApacheconEU08 {
|
||||
|
||||
HSLFTextBox box3 = new HSLFTextBox();
|
||||
HSLFTextRun rt3 = box3.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt3.setFontName("Courier New");
|
||||
rt3.setFontFamily("Courier New");
|
||||
rt3.setFontSize(8);
|
||||
box3.setText(
|
||||
"//bar chart data. The first value is the bar color, the second is the width\u000b" +
|
||||
|
@ -54,7 +54,7 @@ public final class TableDemo {
|
||||
for (int j = 0; j < txt1[i].length; j++) {
|
||||
TableCell cell = table1.getCell(i, j);
|
||||
HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt.setFontName("Arial");
|
||||
rt.setFontFamily("Arial");
|
||||
rt.setFontSize(10);
|
||||
if(i == 0){
|
||||
cell.getFill().setForegroundColor(new Color(227, 227, 227));
|
||||
@ -94,7 +94,7 @@ public final class TableDemo {
|
||||
TableCell cell = table2.getCell(i, j);
|
||||
HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt.setFontSize(10);
|
||||
rt.setFontName("Arial");
|
||||
rt.setFontFamily("Arial");
|
||||
if(i == 0){
|
||||
cell.getFill().setForegroundColor(new Color(0, 51, 102));
|
||||
rt.setFontColor(Color.white);
|
||||
|
@ -170,49 +170,41 @@ public class HexDump {
|
||||
* @return output string
|
||||
*/
|
||||
|
||||
public static String dump(final byte [] data, final long offset,
|
||||
final int index) {
|
||||
StringBuffer buffer;
|
||||
if ((index < 0) || (index >= data.length))
|
||||
public static String dump(final byte [] data, final long offset, final int index) {
|
||||
if ((index < 0) || (index > data.length))
|
||||
{
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"illegal index: " + index + " into array of length "
|
||||
+ data.length);
|
||||
}
|
||||
long display_offset = offset + index;
|
||||
buffer = new StringBuffer(74);
|
||||
StringBuilder buffer = new StringBuilder(74);
|
||||
|
||||
for (int j = index; j < data.length; j += 16)
|
||||
{
|
||||
for (int j = index; j <= data.length; j += 16) {
|
||||
int chars_read = data.length - j;
|
||||
|
||||
if (chars_read > 16)
|
||||
{
|
||||
if (chars_read > 16) {
|
||||
chars_read = 16;
|
||||
}
|
||||
|
||||
buffer.append(dump(display_offset)).append(' ');
|
||||
for (int k = 0; k < 16; k++)
|
||||
{
|
||||
if (k < chars_read)
|
||||
{
|
||||
buffer.append(dump(data[ k + j ]));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.append(" ");
|
||||
}
|
||||
for (int k = 0; k < 16; k++) {
|
||||
String hexDmp = (k < chars_read) ? dump(data[ k + j ]) : " ";
|
||||
buffer.append(hexDmp);
|
||||
buffer.append(' ');
|
||||
}
|
||||
for (int k = 0; k < chars_read; k++)
|
||||
{
|
||||
if ((data[ k + j ] >= ' ') && (data[ k + j ] < 127))
|
||||
{
|
||||
buffer.append(( char ) data[ k + j ]);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.append('.');
|
||||
for (int k = 0; k < chars_read; k++) {
|
||||
byte dataB = data[ k + j ];
|
||||
char charB = (char)(dataB & 0xFF);
|
||||
switch (charB) {
|
||||
case 127: case 128: case 129: case 141: case 142: case 143: case 144: case 157: case 158:
|
||||
charB = '.';
|
||||
break;
|
||||
default:
|
||||
if (charB < ' ') charB = '.';
|
||||
break;
|
||||
}
|
||||
buffer.append(charB);
|
||||
}
|
||||
buffer.append(EOL);
|
||||
display_offset += chars_read;
|
||||
|
@ -257,7 +257,7 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
|
||||
|
||||
HSLFTextRun rt = txt.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt.setFontSize(_font.getSize());
|
||||
rt.setFontName(_font.getFamily());
|
||||
rt.setFontFamily(_font.getFamily());
|
||||
|
||||
if (getColor() != null) rt.setFontColor(getColor());
|
||||
if (_font.isBold()) rt.setBold(true);
|
||||
|
@ -247,14 +247,14 @@ public final class PPDrawing extends RecordAtom {
|
||||
*/
|
||||
public void writeOut(OutputStream out) throws IOException {
|
||||
// Ensure the escher layer reflects the text changes
|
||||
for(int i=0; i<textboxWrappers.length; i++) {
|
||||
textboxWrappers[i].writeOut(null);
|
||||
for (EscherTextboxWrapper w : textboxWrappers) {
|
||||
w.writeOut(null);
|
||||
}
|
||||
|
||||
// Find the new size of the escher children;
|
||||
int newSize = 0;
|
||||
for(int i=0; i<childRecords.length; i++) {
|
||||
newSize += childRecords[i].getRecordSize();
|
||||
for(EscherRecord er : childRecords) {
|
||||
newSize += er.getRecordSize();
|
||||
}
|
||||
|
||||
// Update the size (header bytes 5-8)
|
||||
|
@ -17,11 +17,12 @@
|
||||
|
||||
package org.apache.poi.hslf.record;
|
||||
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.apache.poi.util.LittleEndianByteArrayInputStream;
|
||||
|
||||
/**
|
||||
* The special info runs contained in this text.
|
||||
@ -42,6 +43,15 @@ public final class TextSpecInfoAtom extends RecordAtom {
|
||||
*/
|
||||
private byte[] _data;
|
||||
|
||||
/**
|
||||
* Constructs an empty atom, with a default run of size 1
|
||||
*/
|
||||
public TextSpecInfoAtom() {
|
||||
_header = new byte[8];
|
||||
LittleEndian.putUInt(_header, 4, _type);
|
||||
reset(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the link related atom record from its
|
||||
* source data.
|
||||
@ -50,7 +60,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
|
||||
* @param start the start offset into the byte array.
|
||||
* @param len the length of the slice in the byte array.
|
||||
*/
|
||||
protected TextSpecInfoAtom(byte[] source, int start, int len) {
|
||||
public TextSpecInfoAtom(byte[] source, int start, int len) {
|
||||
// Get the header.
|
||||
_header = new byte[8];
|
||||
System.arraycopy(source,start,_header,0,8);
|
||||
@ -92,13 +102,44 @@ public final class TextSpecInfoAtom extends RecordAtom {
|
||||
* @param size the site of parent text
|
||||
*/
|
||||
public void reset(int size){
|
||||
_data = new byte[10];
|
||||
// 01 00 00 00
|
||||
LittleEndian.putInt(_data, 0, size);
|
||||
// 01 00 00 00
|
||||
LittleEndian.putInt(_data, 4, 1); //mask
|
||||
// 00 00
|
||||
LittleEndian.putShort(_data, 8, (short)0); //langId
|
||||
TextSpecInfoRun sir = new TextSpecInfoRun(size);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
try {
|
||||
sir.writeOut(bos);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
_data = bos.toByteArray();
|
||||
|
||||
// Update the size (header bytes 5-8)
|
||||
LittleEndian.putInt(_header, 4, _data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts the size by enlarging the last {@link TextSpecInfoRun}
|
||||
* or chopping the runs to the given length
|
||||
*
|
||||
* @param size
|
||||
*/
|
||||
public void setParentSize(int size) {
|
||||
assert(size > 0);
|
||||
int covered = 0;
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
TextSpecInfoRun runs[] = getTextSpecInfoRuns();
|
||||
assert(runs.length > 0);
|
||||
for (int i=0; i<runs.length && covered < size; i++) {
|
||||
TextSpecInfoRun run = runs[i];
|
||||
if (covered + run.getLength() > size || i == runs.length-1) {
|
||||
run.setLength(size-covered);
|
||||
}
|
||||
covered += run.getLength();
|
||||
try {
|
||||
run.writeOut(bos);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
_data = bos.toByteArray();
|
||||
|
||||
// Update the size (header bytes 5-8)
|
||||
LittleEndian.putInt(_header, 4, _data.length);
|
||||
@ -111,92 +152,17 @@ public final class TextSpecInfoAtom extends RecordAtom {
|
||||
*/
|
||||
public int getCharactersCovered(){
|
||||
int covered = 0;
|
||||
TextSpecInfoRun[] runs = getTextSpecInfoRuns();
|
||||
for (int i = 0; i < runs.length; i++) covered += runs[i].len;
|
||||
for (TextSpecInfoRun r : getTextSpecInfoRuns()) covered += r.length;
|
||||
return covered;
|
||||
}
|
||||
|
||||
public TextSpecInfoRun[] getTextSpecInfoRuns(){
|
||||
ArrayList<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
|
||||
int pos = 0;
|
||||
int[] bits = {1, 0, 2};
|
||||
while(pos < _data.length) {
|
||||
TextSpecInfoRun run = new TextSpecInfoRun();
|
||||
run.len = LittleEndian.getInt(_data, pos); pos += 4;
|
||||
run.mask = LittleEndian.getInt(_data, pos); pos += 4;
|
||||
for (int i = 0; i < bits.length; i++) {
|
||||
if((run.mask & 1 << bits[i]) != 0){
|
||||
switch (bits[i]){
|
||||
case 0:
|
||||
run.spellInfo = LittleEndian.getShort(_data, pos); pos += 2;
|
||||
break;
|
||||
case 1:
|
||||
run.langId = LittleEndian.getShort(_data, pos); pos += 2;
|
||||
break;
|
||||
case 2:
|
||||
run.altLangId = LittleEndian.getShort(_data, pos); pos += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lst.add(run);
|
||||
LittleEndianByteArrayInputStream bis = new LittleEndianByteArrayInputStream(_data);
|
||||
List<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
|
||||
while (bis.available() > 0) {
|
||||
lst.add(new TextSpecInfoRun(bis));
|
||||
}
|
||||
return lst.toArray(new TextSpecInfoRun[lst.size()]);
|
||||
}
|
||||
|
||||
public static class TextSpecInfoRun {
|
||||
//Length of special info run.
|
||||
protected int len;
|
||||
|
||||
//Special info mask of this run;
|
||||
protected int mask;
|
||||
|
||||
// info fields as indicated by the mask.
|
||||
// -1 means the bit is not set
|
||||
protected short spellInfo = -1;
|
||||
protected short langId = -1;
|
||||
protected short altLangId = -1;
|
||||
|
||||
/**
|
||||
* Spelling status of this text. See Spell Info table below.
|
||||
*
|
||||
* <p>Spell Info Types:</p>
|
||||
* <li>0 Unchecked
|
||||
* <li>1 Previously incorrect, needs rechecking
|
||||
* <li>2 Correct
|
||||
* <li>3 Incorrect
|
||||
*
|
||||
* @return Spelling status of this text
|
||||
*/
|
||||
public short getSpellInfo(){
|
||||
return spellInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows LANGID for this text.
|
||||
*
|
||||
* @return Windows LANGID for this text.
|
||||
*/
|
||||
public short getLangId(){
|
||||
return spellInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternate Windows LANGID of this text;
|
||||
* must be a valid non-East Asian LANGID if the text has an East Asian language,
|
||||
* otherwise may be an East Asian LANGID or language neutral (zero).
|
||||
*
|
||||
* @return Alternate Windows LANGID of this text
|
||||
*/
|
||||
public short getAltLangId(){
|
||||
return altLangId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Length of special info run.
|
||||
*/
|
||||
public int length(){
|
||||
return len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,346 @@
|
||||
/* ====================================================================
|
||||
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.record;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.poi.util.*;
|
||||
|
||||
public class TextSpecInfoRun {
|
||||
/**
|
||||
* A enum that specifies the spelling status of a run of text.
|
||||
*/
|
||||
public enum SpellInfoEnum {
|
||||
/** the text is spelled incorrectly. */
|
||||
error(new BitField(1)),
|
||||
/** the text needs rechecking. */
|
||||
clean(new BitField(2)),
|
||||
/** the text has a grammar error. */
|
||||
grammar(new BitField(4)),
|
||||
/** the text is spelled correct */
|
||||
correct(new BitField(0));
|
||||
|
||||
final BitField bitField;
|
||||
|
||||
SpellInfoEnum(BitField bitField) {
|
||||
this.bitField = bitField;
|
||||
}
|
||||
}
|
||||
|
||||
/** A bit that specifies whether the spellInfo field exists. */
|
||||
private static final BitField spellFld = new BitField(0X00000001);
|
||||
/** A bit that specifies whether the lid field exists. */
|
||||
private static final BitField langFld = new BitField(0X00000002);
|
||||
/** A bit that specifies whether the altLid field exists. */
|
||||
private static final BitField altLangFld = new BitField(0X00000004);
|
||||
// unused1, unused2 - Undefined and MUST be ignored.
|
||||
/** A bit that specifies whether the pp10runid, reserved3, and grammarError fields exist. */
|
||||
private static final BitField pp10extFld = new BitField(0X00000020);
|
||||
/** A bit that specifies whether the bidi field exists. */
|
||||
private static final BitField bidiFld = new BitField(0X00000040);
|
||||
// unused3 - Undefined and MUST be ignored.
|
||||
// reserved1 - MUST be zero and MUST be ignored.
|
||||
/** A bit that specifies whether the smartTags field exists. */
|
||||
private static final BitField smartTagFld = new BitField(0X00000200);
|
||||
// reserved2 - MUST be zero and MUST be ignored.
|
||||
|
||||
/**
|
||||
* An optional unsigned integer that specifies an identifier for a character
|
||||
* run that contains StyleTextProp11 data. It MUST exist if and only if pp10ext is TRUE.
|
||||
**/
|
||||
private static final BitField pp10runidFld = new BitField(0X0000000F);
|
||||
// reserved3 - An optional unsigned integer that MUST be zero, and MUST be ignored. It
|
||||
// MUST exist if and only if fPp10ext is TRUE.
|
||||
/**
|
||||
* An optional bit that specifies a grammar error. It MUST exist if and
|
||||
* only if fPp10ext is TRUE.
|
||||
**/
|
||||
private static final BitField grammarErrorFld = new BitField(0X80000000);
|
||||
|
||||
//Length of special info run.
|
||||
protected int length;
|
||||
|
||||
//Special info mask of this run;
|
||||
protected int mask;
|
||||
|
||||
// info fields as indicated by the mask.
|
||||
// -1 means the bit is not set
|
||||
|
||||
/**
|
||||
* An optional SpellingFlags structure that specifies the spelling status of this
|
||||
* text. It MUST exist if and only if spell is TRUE.
|
||||
* The spellInfo.grammar sub-field MUST be zero.
|
||||
* <br>
|
||||
* error (1 bit): A bit that specifies whether the text is spelled incorrectly.<br>
|
||||
* clean (1 bit): A bit that specifies whether the text needs rechecking.<br>
|
||||
* grammar (1 bit): A bit that specifies whether the text has a grammar error.<br>
|
||||
* reserved (13 bits): MUST be zero and MUST be ignored.
|
||||
*/
|
||||
protected short spellInfo = -1;
|
||||
|
||||
/**
|
||||
* An optional TxLCID that specifies the language identifier of this text.
|
||||
* It MUST exist if and only if lang is TRUE.
|
||||
* <br>
|
||||
* 0x0000 = No language.<br>
|
||||
* 0x0013 = Any Dutch language is preferred over non-Dutch languages when proofing the text.<br>
|
||||
* 0x0400 = No proofing is performed on the text.<br>
|
||||
* > 0x0400 = A valid LCID as specified by [MS-LCID].
|
||||
*/
|
||||
protected short langId = -1;
|
||||
|
||||
/**
|
||||
* An optional TxLCID that specifies the alternate language identifier of this text.
|
||||
* It MUST exist if and only if altLang is TRUE.
|
||||
*/
|
||||
protected short altLangId = -1;
|
||||
|
||||
/**
|
||||
* An optional signed integer that specifies whether the text contains bidirectional
|
||||
* characters. It MUST exist if and only if fBidi is TRUE.
|
||||
* 0x0000 = Contains no bidirectional characters,
|
||||
* 0x0001 = Contains bidirectional characters.
|
||||
*/
|
||||
protected short bidi = -1;
|
||||
|
||||
protected int pp10extMask = -1;
|
||||
protected byte[] smartTagsBytes = null;
|
||||
|
||||
/**
|
||||
* Inits a TextSpecInfoRun with default values
|
||||
*
|
||||
* @param len the length of the one and only run
|
||||
*/
|
||||
public TextSpecInfoRun(int len) {
|
||||
setLength(len);
|
||||
setLangId((short)0);
|
||||
}
|
||||
|
||||
public TextSpecInfoRun(LittleEndianByteArrayInputStream source) {
|
||||
length = source.readInt();
|
||||
mask = source.readInt();
|
||||
if (spellFld.isSet(mask)) {
|
||||
spellInfo = source.readShort();
|
||||
}
|
||||
if (langFld.isSet(mask)) {
|
||||
langId = source.readShort();
|
||||
}
|
||||
if (altLangFld.isSet(mask)) {
|
||||
altLangId = source.readShort();
|
||||
}
|
||||
if (bidiFld.isSet(mask)) {
|
||||
bidi = source.readShort();
|
||||
}
|
||||
if (pp10extFld.isSet(mask)) {
|
||||
pp10extMask = source.readInt();
|
||||
}
|
||||
if (smartTagFld.isSet(mask)) {
|
||||
// An unsigned integer specifies the count of items in rgSmartTagIndex.
|
||||
int count = source.readInt();
|
||||
smartTagsBytes = new byte[4+count*4];
|
||||
LittleEndian.putInt(smartTagsBytes, 0, count);
|
||||
// An array of SmartTagIndex that specifies the indices.
|
||||
// The count of items in the array is specified by count.
|
||||
source.readFully(smartTagsBytes, 4, count*4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of the record back, so it can be written
|
||||
* to disk
|
||||
*
|
||||
* @param out the output stream to write to.
|
||||
* @throws java.io.IOException if an error occurs.
|
||||
*/
|
||||
public void writeOut(OutputStream out) throws IOException {
|
||||
final byte buf[] = new byte[4];
|
||||
LittleEndian.putInt(buf, 0, length);
|
||||
out.write(buf);
|
||||
LittleEndian.putInt(buf, 0, mask);
|
||||
out.write(buf);
|
||||
Object flds[] = {
|
||||
spellFld, spellInfo, "spell info",
|
||||
langFld, langId, "lang id",
|
||||
altLangFld, altLangId, "alt lang id",
|
||||
bidiFld, bidi, "bidi",
|
||||
pp10extFld, pp10extMask, "pp10 extension field",
|
||||
smartTagFld, smartTagsBytes, "smart tags"
|
||||
};
|
||||
|
||||
for (int i=0; i<flds.length; i+=3) {
|
||||
BitField fld = (BitField)flds[i+0];
|
||||
Object valO = flds[i+1];
|
||||
if (!fld.isSet(mask)) continue;
|
||||
boolean valid;
|
||||
if (valO instanceof byte[]) {
|
||||
byte bufB[] = (byte[])valO;
|
||||
valid = bufB.length > 0;
|
||||
out.write(bufB);
|
||||
} else if (valO instanceof Integer) {
|
||||
int valI = ((Integer)valO);
|
||||
valid = (valI != -1);
|
||||
LittleEndian.putInt(buf, 0, valI);
|
||||
out.write(buf);
|
||||
} else if (valO instanceof Short) {
|
||||
short valS = ((Short)valO);
|
||||
valid = (valS != -1);
|
||||
LittleEndian.putShort(buf, 0, valS);
|
||||
out.write(buf, 0, 2);
|
||||
} else {
|
||||
valid = false;
|
||||
}
|
||||
if (!valid) {
|
||||
throw new IOException(flds[i+2]+" is activated, but its value is invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Spelling status of this text. null if not defined.
|
||||
*/
|
||||
public SpellInfoEnum getSpellInfo(){
|
||||
if (spellInfo == -1) return null;
|
||||
for (SpellInfoEnum si : new SpellInfoEnum[]{SpellInfoEnum.clean,SpellInfoEnum.error,SpellInfoEnum.grammar}) {
|
||||
if (si.bitField.isSet(spellInfo)) return si;
|
||||
}
|
||||
return SpellInfoEnum.correct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param spellInfo Spelling status of this text. null if not defined.
|
||||
*/
|
||||
public void setSpellInfo(SpellInfoEnum spellInfo) {
|
||||
this.spellInfo = (spellInfo == null)
|
||||
? -1
|
||||
: (short)spellInfo.bitField.set(0);
|
||||
mask = spellFld.setBoolean(mask, spellInfo != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows LANGID for this text.
|
||||
*
|
||||
* @return Windows LANGID for this text, -1 if it's not set
|
||||
*/
|
||||
public short getLangId(){
|
||||
return langId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param langId Windows LANGID for this text, -1 to unset
|
||||
*/
|
||||
public void setLangId(short langId) {
|
||||
this.langId = langId;
|
||||
mask = langFld.setBoolean(mask, langId != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternate Windows LANGID of this text;
|
||||
* must be a valid non-East Asian LANGID if the text has an East Asian language,
|
||||
* otherwise may be an East Asian LANGID or language neutral (zero).
|
||||
*
|
||||
* @return Alternate Windows LANGID of this text, -1 if it's not set
|
||||
*/
|
||||
public short getAltLangId(){
|
||||
return altLangId;
|
||||
}
|
||||
|
||||
public void setAltLangId(short altLangId) {
|
||||
this.altLangId = altLangId;
|
||||
mask = altLangFld.setBoolean(mask, altLangId != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Length of special info run.
|
||||
*/
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param length Length of special info run.
|
||||
*/
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the bidirectional characters flag. false = not bidi, true = is bidi, null = not set
|
||||
*/
|
||||
public Boolean getBidi() {
|
||||
return (bidi == -1 ? null : bidi != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bidi the bidirectional characters flag. false = not bidi, true = is bidi, null = not set
|
||||
*/
|
||||
public void setBidi(Boolean bidi) {
|
||||
this.bidi = (bidi == null) ? -1 : (short)(bidi ? 1 : 0);
|
||||
mask = bidiFld.setBoolean(mask, bidi != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unparsed smart tags
|
||||
*/
|
||||
public byte[] getSmartTagsBytes() {
|
||||
return smartTagsBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param smartTagsBytes the unparsed smart tags, null to unset
|
||||
*/
|
||||
public void setSmartTagsBytes(byte[] smartTagsBytes) {
|
||||
this.smartTagsBytes = smartTagsBytes;
|
||||
mask = smartTagFld.setBoolean(mask, smartTagsBytes != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an identifier for a character run that contains StyleTextProp11 data.
|
||||
*/
|
||||
public int getPP10RunId() {
|
||||
return (pp10extMask == -1 || !pp10extFld.isSet(mask)) ? -1 : pp10runidFld.getValue(pp10extMask);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pp10RunId an identifier for a character run that contains StyleTextProp11 data, -1 to unset
|
||||
*/
|
||||
public void setPP10RunId(int pp10RunId) {
|
||||
if (pp10RunId == -1) {
|
||||
pp10extMask = (getGrammarError() == null) ? -1 : pp10runidFld.clear(pp10extMask);
|
||||
} else {
|
||||
pp10extMask = pp10runidFld.setValue(pp10extMask, pp10RunId);
|
||||
}
|
||||
// if both parameters are invalid, remove the extension mask
|
||||
mask = pp10extFld.setBoolean(mask, pp10extMask != -1);
|
||||
}
|
||||
|
||||
public Boolean getGrammarError() {
|
||||
return (pp10extMask == -1 || !pp10extFld.isSet(mask)) ? null : grammarErrorFld.isSet(pp10extMask);
|
||||
}
|
||||
|
||||
public void getGrammarError(Boolean grammarError) {
|
||||
if (grammarError == null) {
|
||||
pp10extMask = (getPP10RunId() == -1) ? -1 : grammarErrorFld.clear(pp10extMask);
|
||||
} else {
|
||||
pp10extMask = grammarErrorFld.set(pp10extMask);
|
||||
}
|
||||
// if both parameters are invalid, remove the extension mask
|
||||
mask = pp10extFld.setBoolean(mask, pp10extMask != -1);
|
||||
}
|
||||
}
|
@ -127,7 +127,36 @@ public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> {
|
||||
*/
|
||||
@Override
|
||||
public List<HSLFShape> getShapes() {
|
||||
return getShapeList();
|
||||
PPDrawing ppdrawing = getPPDrawing();
|
||||
|
||||
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
||||
EscherContainerRecord spgr = null;
|
||||
|
||||
for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
|
||||
EscherRecord rec = it.next();
|
||||
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
|
||||
spgr = (EscherContainerRecord) rec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (spgr == null) {
|
||||
throw new IllegalStateException("spgr not found");
|
||||
}
|
||||
|
||||
List<HSLFShape> shapeList = new ArrayList<HSLFShape>();
|
||||
Iterator<EscherRecord> it = spgr.getChildIterator();
|
||||
if (it.hasNext()) {
|
||||
// skip first item
|
||||
it.next();
|
||||
}
|
||||
for (; it.hasNext();) {
|
||||
EscherContainerRecord sp = (EscherContainerRecord) it.next();
|
||||
HSLFShape sh = HSLFShapeFactory.createShape(sp, null);
|
||||
sh.setSheet(this);
|
||||
shapeList.add(sh);
|
||||
}
|
||||
|
||||
return shapeList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -347,48 +376,10 @@ public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> {
|
||||
}
|
||||
|
||||
public Iterator<HSLFShape> iterator() {
|
||||
return getShapeList().iterator();
|
||||
return getShapes().iterator();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all shapes contained in this Sheet
|
||||
*
|
||||
* @return all shapes contained in this Sheet (Slide or Notes)
|
||||
*/
|
||||
protected List<HSLFShape> getShapeList() {
|
||||
PPDrawing ppdrawing = getPPDrawing();
|
||||
|
||||
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
||||
EscherContainerRecord spgr = null;
|
||||
|
||||
for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
|
||||
EscherRecord rec = it.next();
|
||||
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
|
||||
spgr = (EscherContainerRecord) rec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (spgr == null) {
|
||||
throw new IllegalStateException("spgr not found");
|
||||
}
|
||||
|
||||
List<HSLFShape> shapeList = new ArrayList<HSLFShape>();
|
||||
Iterator<EscherRecord> it = spgr.getChildIterator();
|
||||
if (it.hasNext()) {
|
||||
// skip first item
|
||||
it.next();
|
||||
}
|
||||
for (; it.hasNext();) {
|
||||
EscherContainerRecord sp = (EscherContainerRecord) it.next();
|
||||
HSLFShape sh = HSLFShapeFactory.createShape(sp, null);
|
||||
sh.setSheet(this);
|
||||
shapeList.add(sh);
|
||||
}
|
||||
|
||||
return shapeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether shapes on the master sheet should be shown. By default master graphics is turned off.
|
||||
* Sheets that support the notion of master (slide, slideLayout) should override it and
|
||||
|
@ -571,10 +571,6 @@ public final class HSLFSlideShow implements SlideShow {
|
||||
+ _slides.size() + ")");
|
||||
}
|
||||
|
||||
_slides.get(newSlideNumber).setSlideNumber(oldSlideNumber);
|
||||
_slides.get(oldSlideNumber).setSlideNumber(newSlideNumber);
|
||||
Collections.swap(_slides, oldSlideNumber-1, newSlideNumber-1);
|
||||
|
||||
// The order of slides is defined by the order of slide atom sets in the
|
||||
// SlideListWithText container.
|
||||
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
|
||||
@ -584,11 +580,16 @@ public final class HSLFSlideShow implements SlideShow {
|
||||
sas[oldSlideNumber - 1] = sas[newSlideNumber - 1];
|
||||
sas[newSlideNumber - 1] = tmp;
|
||||
|
||||
Collections.swap(_slides, oldSlideNumber - 1, newSlideNumber - 1);
|
||||
_slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber);
|
||||
_slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber);
|
||||
|
||||
ArrayList<Record> lst = new ArrayList<Record>();
|
||||
for (SlideAtomsSet s : sas) {
|
||||
lst.add(s.getSlidePersistAtom());
|
||||
lst.addAll(Arrays.asList(s.getSlideRecords()));
|
||||
}
|
||||
|
||||
Record[] r = lst.toArray(new Record[lst.size()]);
|
||||
slwt.setChildRecord(r);
|
||||
}
|
||||
@ -628,7 +629,7 @@ public final class HSLFSlideShow implements SlideShow {
|
||||
records.add(s.getSlidePersistAtom());
|
||||
records.addAll(Arrays.asList(s.getSlideRecords()));
|
||||
}
|
||||
if (sa.size() == 0) {
|
||||
if (sa.isEmpty()) {
|
||||
_documentRecord.removeSlideListWithText(slwt);
|
||||
} else {
|
||||
slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()]));
|
||||
|
@ -241,8 +241,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
hardAttribute = maskProp != null && maskProp.getValue() == 0;
|
||||
}
|
||||
if (prop == null && !hardAttribute){
|
||||
HSLFSheet sheet = _parentShape.getSheet();
|
||||
int txtype = _parentShape.getRunType();
|
||||
HSLFSheet sheet = getSheet();
|
||||
int txtype = getRunType();
|
||||
HSLFMasterSheet master = sheet.getMasterSheet();
|
||||
if (master != null)
|
||||
prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
|
||||
@ -600,7 +600,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
|
||||
if (prop == null) {
|
||||
if (_sheet != null) {
|
||||
int txtype = getParentShape().getRunType();
|
||||
int txtype = getRunType();
|
||||
HSLFMasterSheet master = _sheet.getMasterSheet();
|
||||
if (master != null) {
|
||||
prop = (BitMaskTextProp) master.getStyleAttribute(txtype, getIndentLevel(), ParagraphFlagsTextProp.NAME, false);
|
||||
@ -789,10 +789,11 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
* If TextSpecInfoAtom is present, we must update the text size in it,
|
||||
* otherwise the ppt will be corrupted
|
||||
*/
|
||||
TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_txtbox.findFirstOfType(RecordTypes.TextSpecInfoAtom.typeID);
|
||||
int len = rawText.length() + 1;
|
||||
if(specAtom != null && len != specAtom.getCharactersCovered()) {
|
||||
specAtom.reset(len);
|
||||
for (Record r : paragraphs.get(0)._records) {
|
||||
if (r instanceof TextSpecInfoAtom) {
|
||||
((TextSpecInfoAtom)r).setParentSize(rawText.length()+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -870,6 +871,12 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
return appendText(paragraphs, text, false);
|
||||
}
|
||||
|
||||
public static String getText(List<HSLFTextParagraph> paragraphs) {
|
||||
assert(!paragraphs.isEmpty());
|
||||
String rawText = getRawText(paragraphs);
|
||||
return toExternalString(rawText, paragraphs.get(0).getRunType());
|
||||
}
|
||||
|
||||
public static String getRawText(List<HSLFTextParagraph> paragraphs) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (HSLFTextParagraph p : paragraphs) {
|
||||
@ -1151,7 +1158,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
wrapper.appendChildRecord(tha);
|
||||
|
||||
TextBytesAtom tba = new TextBytesAtom();
|
||||
tba.setText("\r".getBytes());
|
||||
tba.setText("".getBytes());
|
||||
wrapper.appendChildRecord(tba);
|
||||
|
||||
StyleTextPropAtom sta = new StyleTextPropAtom(1);
|
||||
@ -1162,16 +1169,10 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
HSLFTextParagraph htp = new HSLFTextParagraph(tha, tba, null, sta);
|
||||
htp.setParagraphStyle(paraStyle);
|
||||
htp._records = new Record[0];
|
||||
// htp.setBullet(false);
|
||||
// htp.setLineSpacing(100);
|
||||
// htp.setLeftMargin(0);
|
||||
// htp.setIndent(0);
|
||||
// set wrap flags
|
||||
|
||||
HSLFTextRun htr = new HSLFTextRun(htp);
|
||||
htr.setCharacterStyle(charStyle);
|
||||
htr.setText("\r");
|
||||
// htr.setFontColor(Color.black);
|
||||
htr.setText("");
|
||||
htp.addTextRun(htr);
|
||||
|
||||
return Arrays.asList(htp);
|
||||
|
@ -39,7 +39,7 @@ public final class HSLFTextRun implements TextRun {
|
||||
/** The TextRun we belong to */
|
||||
private HSLFTextParagraph parentParagraph;
|
||||
private String _runText = "";
|
||||
private String _fontname;
|
||||
private String _fontFamily;
|
||||
|
||||
/**
|
||||
* Our paragraph and character style.
|
||||
@ -68,9 +68,9 @@ public final class HSLFTextRun implements TextRun {
|
||||
* Supply the SlideShow we belong to
|
||||
*/
|
||||
public void updateSheet() {
|
||||
if (_fontname != null) {
|
||||
setFontName(_fontname);
|
||||
_fontname = null;
|
||||
if (_fontFamily != null) {
|
||||
setFontFamily(_fontFamily);
|
||||
_fontFamily = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ public final class HSLFTextRun implements TextRun {
|
||||
|
||||
if (prop == null){
|
||||
HSLFSheet sheet = parentParagraph.getSheet();
|
||||
int txtype = parentParagraph.getParentShape().getRunType();
|
||||
int txtype = parentParagraph.getRunType();
|
||||
HSLFMasterSheet master = sheet.getMasterSheet();
|
||||
if (master != null)
|
||||
prop = master.getStyleAttribute(txtype, parentParagraph.getIndentLevel(), propName, true);
|
||||
@ -306,16 +306,16 @@ public final class HSLFTextRun implements TextRun {
|
||||
/**
|
||||
* Sets the font name to use
|
||||
*/
|
||||
public void setFontName(String fontName) {
|
||||
public void setFontFamily(String fontFamily) {
|
||||
HSLFSheet sheet = parentParagraph.getSheet();
|
||||
HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow();
|
||||
if (sheet == null || slideShow == null) {
|
||||
//we can't set font since slideshow is not assigned yet
|
||||
_fontname = fontName;
|
||||
_fontFamily = fontFamily;
|
||||
return;
|
||||
}
|
||||
// Get the index for this font (adding if needed)
|
||||
int fontIdx = slideShow.getFontCollection().addFont(fontName);
|
||||
int fontIdx = slideShow.getFontCollection().addFont(fontFamily);
|
||||
setCharTextPropVal("font.index", fontIdx);
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ public final class HSLFTextRun implements TextRun {
|
||||
HSLFSheet sheet = parentParagraph.getSheet();
|
||||
HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow();
|
||||
if (sheet == null || slideShow == null) {
|
||||
return _fontname;
|
||||
return _fontFamily;
|
||||
}
|
||||
int fontIdx = getCharTextPropVal("font.index");
|
||||
if(fontIdx == -1) { return null; }
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package org.apache.poi.hslf.model;
|
||||
|
||||
import org.apache.poi.hslf.usermodel.TestTextRun;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
@ -36,7 +35,6 @@ import org.junit.runners.Suite;
|
||||
TestOleEmbedding.class,
|
||||
TestPPFont.class,
|
||||
TestPPGraphics2D.class,
|
||||
TestPicture.class,
|
||||
TestSetBoldItalic.class,
|
||||
TestShapes.class,
|
||||
TestSheet.class,
|
||||
@ -44,9 +42,7 @@ import org.junit.runners.Suite;
|
||||
TestSlideMaster.class,
|
||||
TestSlides.class,
|
||||
TestTable.class,
|
||||
TestTextRun.class,
|
||||
TestTextRunReWrite.class,
|
||||
TestTextShape.class
|
||||
TestTextRunReWrite.class
|
||||
})
|
||||
public class AllHSLFModelTests {
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public final class TestPPGraphics2D {
|
||||
private HSLFSlideShow ppt;
|
||||
|
||||
@Before
|
||||
protected void setUp() throws Exception {
|
||||
public void setUp() throws Exception {
|
||||
ppt = new HSLFSlideShow(_slTests.openResourceAsStream("empty.ppt"));
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.Rectangle2D.Double;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -29,11 +28,8 @@ 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.*;
|
||||
import org.apache.poi.sl.usermodel.ShapeType;
|
||||
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;
|
||||
|
||||
@ -138,6 +134,7 @@ public final class TestShapes {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void testParagraphs() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||
@ -196,7 +193,7 @@ public final class TestShapes {
|
||||
HSLFTextBox txtbox = new HSLFTextBox();
|
||||
rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
txtbox.setText(val);
|
||||
rt.setFontName("Arial");
|
||||
rt.setFontFamily("Arial");
|
||||
rt.setFontSize(42);
|
||||
rt.setBold(true);
|
||||
rt.setItalic(true);
|
||||
|
@ -82,10 +82,13 @@ public final class TestSheet {
|
||||
assertTrue(sheet._getSheetNumber() != 0);
|
||||
assertTrue(sheet._getSheetRefId() != 0);
|
||||
|
||||
List<HSLFTextParagraph> txt = sheet.getTextParagraphs();
|
||||
assertTrue("no text runs", txt != null && !txt.isEmpty());
|
||||
for (HSLFTextParagraph t : txt) {
|
||||
assertNotNull(t.getSheet());
|
||||
List<List<HSLFTextParagraph>> txt = sheet.getTextParagraphs();
|
||||
// assertTrue("no text runs", txt != null && !txt.isEmpty());
|
||||
// backgrounds.ppt has no texts
|
||||
for (List<HSLFTextParagraph> t : txt) {
|
||||
for (HSLFTextParagraph tp : t) {
|
||||
assertNotNull(tp.getSheet());
|
||||
}
|
||||
}
|
||||
|
||||
List<HSLFShape> shape = sheet.getShapes();
|
||||
|
@ -113,10 +113,9 @@ public final class TestSlideMaster {
|
||||
HSLFMasterSheet masterSheet = slide.getMasterSheet();
|
||||
assertTrue(masterSheet instanceof HSLFTitleMaster);
|
||||
|
||||
List<HSLFTextParagraph> txt = slide.getTextParagraphs();
|
||||
for (int i = 0; i < txt.size(); i++) {
|
||||
HSLFTextRun rt = txt.get(i).getTextRuns().get(0);
|
||||
switch(txt.get(i).getRunType()){
|
||||
for (List<HSLFTextParagraph> txt : slide.getTextParagraphs()) {
|
||||
HSLFTextRun rt = txt.get(0).getTextRuns().get(0);
|
||||
switch(txt.get(0).getRunType()){
|
||||
case TextHeaderAtom.CENTER_TITLE_TYPE:
|
||||
assertEquals("Arial", rt.getFontFamily());
|
||||
assertEquals(32, rt.getFontSize(), 0);
|
||||
@ -141,20 +140,22 @@ public final class TestSlideMaster {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
||||
List<HSLFSlide> slide = ppt.getSlides();
|
||||
assertEquals(3, slide.size());
|
||||
for (HSLFTextParagraph trun : slide.get(0).getTextParagraphs()) {
|
||||
if (trun.getRunType() == TextHeaderAtom.TITLE_TYPE){
|
||||
HSLFTextRun rt = trun.getTextRuns().get(0);
|
||||
for (List<HSLFTextParagraph> tparas : slide.get(0).getTextParagraphs()) {
|
||||
HSLFTextParagraph tpara = tparas.get(0);
|
||||
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
|
||||
HSLFTextRun rt = tpara.getTextRuns().get(0);
|
||||
assertEquals(40, rt.getFontSize(), 0);
|
||||
assertEquals(true, rt.isUnderlined());
|
||||
assertEquals("Arial", rt.getFontFamily());
|
||||
} else if (trun.getRunType() == TextHeaderAtom.BODY_TYPE){
|
||||
HSLFTextRun rt = trun.getTextRuns().get(0);
|
||||
assertEquals(0, trun.getIndentLevel());
|
||||
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
|
||||
HSLFTextRun rt = tpara.getTextRuns().get(0);
|
||||
assertEquals(0, tpara.getIndentLevel());
|
||||
assertEquals(32, rt.getFontSize(), 0);
|
||||
assertEquals("Arial", rt.getFontFamily());
|
||||
|
||||
rt = trun.getTextRuns().get(1);
|
||||
assertEquals(1, trun.getIndentLevel());
|
||||
tpara = tparas.get(1);
|
||||
rt = tpara.getTextRuns().get(0);
|
||||
assertEquals(1, tpara.getIndentLevel());
|
||||
assertEquals(28, rt.getFontSize(), 0);
|
||||
assertEquals("Arial", rt.getFontFamily());
|
||||
|
||||
@ -162,16 +163,17 @@ public final class TestSlideMaster {
|
||||
}
|
||||
|
||||
;
|
||||
for (HSLFTextParagraph trun : slide.get(1).getTextParagraphs()) {
|
||||
if (trun.getRunType() == TextHeaderAtom.TITLE_TYPE){
|
||||
HSLFTextRun rt = trun.getTextRuns().get(0);
|
||||
for (List<HSLFTextParagraph> tparas : slide.get(1).getTextParagraphs()) {
|
||||
HSLFTextParagraph tpara = tparas.get(0);
|
||||
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
|
||||
HSLFTextRun rt = tpara.getTextRuns().get(0);
|
||||
assertEquals(48, rt.getFontSize(), 0);
|
||||
assertEquals(true, rt.isItalic());
|
||||
assertEquals("Georgia", rt.getFontFamily());
|
||||
} else if (trun.getRunType() == TextHeaderAtom.BODY_TYPE){
|
||||
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
|
||||
HSLFTextRun rt;
|
||||
rt = trun.getTextRuns().get(0);
|
||||
assertEquals(0, trun.getIndentLevel());
|
||||
rt = tpara.getTextRuns().get(0);
|
||||
assertEquals(0, tpara.getIndentLevel());
|
||||
assertEquals(32, rt.getFontSize(), 0);
|
||||
assertEquals("Courier New", rt.getFontFamily());
|
||||
}
|
||||
@ -222,16 +224,17 @@ public final class TestSlideMaster {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
|
||||
for (HSLFTextParagraph trun : slide.getTextParagraphs()) {
|
||||
if (trun.getRunType() == TextHeaderAtom.TITLE_TYPE){
|
||||
HSLFTextRun rt = trun.getTextRuns().get(0);
|
||||
for (List<HSLFTextParagraph> tparas : slide.getTextParagraphs()) {
|
||||
HSLFTextParagraph tpara = tparas.get(0);
|
||||
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
|
||||
HSLFTextRun rt = tpara.getTextRuns().get(0);
|
||||
assertEquals(40, rt.getFontSize(), 0);
|
||||
assertEquals(true, rt.isUnderlined());
|
||||
assertEquals("Arial", rt.getFontFamily());
|
||||
} else if (trun.getRunType() == TextHeaderAtom.BODY_TYPE){
|
||||
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
|
||||
int indents[] = { 32, 28, 24 };
|
||||
for (HSLFTextRun rt : trun.getTextRuns()) {
|
||||
int indent = trun.getIndentLevel();
|
||||
for (HSLFTextRun rt : tpara.getTextRuns()) {
|
||||
int indent = tpara.getIndentLevel();
|
||||
assertEquals(indents[indent], rt.getFontSize(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
@ -58,34 +59,37 @@ public final class TestTextRunReWrite {
|
||||
|
||||
@Test
|
||||
public void testWritesOutTheSameNonRich() throws Exception {
|
||||
// Grab the first text run on the first sheet
|
||||
HSLFTextParagraph tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
|
||||
HSLFTextParagraph tr2 = ss.getSlides().get(0).getTextParagraphs().get(1);
|
||||
|
||||
// Ensure the text lengths are as we'd expect to start with
|
||||
assertEquals(1, ss.getSlides().length);
|
||||
assertEquals(2, ss.getSlides().get(0).getTextParagraphs().length);
|
||||
assertEquals(30, tr1.getRawText().length());
|
||||
assertEquals(179, tr2.getRawText().length());
|
||||
assertEquals(1, ss.getSlides().size());
|
||||
assertEquals(2, ss.getSlides().get(0).getTextParagraphs().size());
|
||||
|
||||
assertEquals(1, tr1.getTextRuns().length);
|
||||
assertEquals(30, tr1.getTextRuns().get(0).getLength());
|
||||
assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
|
||||
assertEquals(31, tr1.getTextRuns().get(0)._getRawCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, tr1.getTextRuns().get(0)._getRawParagraphStyle().getCharactersCovered());
|
||||
// Grab the first text run on the first sheet
|
||||
List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
|
||||
List<HSLFTextParagraph> tr2 = ss.getSlides().get(0).getTextParagraphs().get(1);
|
||||
|
||||
|
||||
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
|
||||
assertEquals(179, HSLFTextParagraph.getRawText(tr2).length());
|
||||
|
||||
assertEquals(1, tr1.size());
|
||||
assertEquals(30, HSLFTextParagraph.getText(tr1).length());
|
||||
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
|
||||
assertEquals(31, tr1.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
|
||||
|
||||
// Set the text to be as it is now
|
||||
tr1.setText( tr1.getRawText() );
|
||||
HSLFTextParagraph.setText(tr1, HSLFTextParagraph.getRawText(tr1));
|
||||
tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
|
||||
|
||||
// Check the text lengths are still right
|
||||
assertEquals(30, tr1.getRawText().length());
|
||||
assertEquals(179, tr2.getRawText().length());
|
||||
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
|
||||
assertEquals(179, HSLFTextParagraph.getRawText(tr2).length());
|
||||
|
||||
assertEquals(1, tr1.getTextRuns().length);
|
||||
assertEquals(30, tr1.getTextRuns().get(0).getLength());
|
||||
assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
|
||||
assertEquals(31, tr1.getTextRuns().get(0)._getRawCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, tr1.getTextRuns().get(0)._getRawParagraphStyle().getCharactersCovered());
|
||||
assertEquals(1, tr1.size());
|
||||
assertEquals(30, HSLFTextParagraph.getText(tr1).length());
|
||||
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
|
||||
assertEquals(31, tr1.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
|
||||
|
||||
|
||||
// Write the slideshow out to a byte array
|
||||
@ -117,33 +121,32 @@ public final class TestTextRunReWrite {
|
||||
@Test
|
||||
public void testWritesOutTheSameRich() throws Exception {
|
||||
// Grab the first text run on the first sheet
|
||||
HSLFTextParagraph tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
|
||||
List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
|
||||
|
||||
// Get the first rich text run
|
||||
HSLFTextRun rtr1 = tr1.getTextRuns().get(0);
|
||||
HSLFTextRun rtr1 = tr1.get(0).getTextRuns().get(0);
|
||||
|
||||
|
||||
// Check that the text sizes are as expected
|
||||
assertEquals(1, tr1.getTextRuns().length);
|
||||
assertEquals(30, tr1.getRawText().length());
|
||||
assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
|
||||
assertEquals(1, tr1.get(0).getTextRuns().size());
|
||||
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
|
||||
assertEquals(30, rtr1.getLength());
|
||||
assertEquals(30, rtr1.getRawText().length());
|
||||
assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
|
||||
assertEquals(31, rtr1.getCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
|
||||
|
||||
// Set the text to be as it is now
|
||||
rtr1.setText( rtr1.getRawText() );
|
||||
rtr1 = tr1.getTextRuns().get(0);
|
||||
rtr1 = tr1.get(0).getTextRuns().get(0);
|
||||
|
||||
// Check that the text sizes are still as expected
|
||||
assertEquals(1, tr1.getTextRuns().length);
|
||||
assertEquals(30, tr1.getRawText().length());
|
||||
assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
|
||||
assertEquals(1, tr1.get(0).getTextRuns().size());
|
||||
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
|
||||
assertEquals(30, tr1.get(0).getTextRuns().get(0).getRawText().length());
|
||||
assertEquals(30, rtr1.getLength());
|
||||
assertEquals(30, rtr1.getRawText().length());
|
||||
assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
|
||||
assertEquals(31, rtr1.getCharacterStyle().getCharactersCovered());
|
||||
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
|
||||
|
||||
|
||||
// Write the slideshow out to a byte array
|
||||
|
@ -1,52 +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;
|
||||
|
||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
||||
import org.apache.poi.hslf.record.TextCharsAtom;
|
||||
import org.apache.poi.hslf.record.TextHeaderAtom;
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
import org.apache.poi.hssf.usermodel.DummyGraphics2d;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TextPainterTest {
|
||||
@Test
|
||||
public void testTextPainter() {
|
||||
HSLFTextShape shape = new Polygon();
|
||||
TextPainter painter = new TextPainter(shape);
|
||||
painter.getAttributedString(new HSLFTextParagraph(null, new TextCharsAtom(), null));
|
||||
painter.paint(new DummyGraphics2d());
|
||||
painter.getTextElements((float)1.0, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextPainterWithText() {
|
||||
HSLFTextShape shape = new Polygon();
|
||||
TextPainter painter = new TextPainter(shape);
|
||||
TextCharsAtom tca = new TextCharsAtom();
|
||||
tca.setText("some text to read");
|
||||
HSLFTextParagraph txrun = new HSLFTextParagraph(new TextHeaderAtom(), tca, new StyleTextPropAtom(10));
|
||||
HSLFSlide sheet = new HSLFSlide(1, 1, 1);
|
||||
sheet.setSlideShow(new HSLFSlideShow());
|
||||
txrun.setSheet(sheet);
|
||||
|
||||
painter.getAttributedString(txrun, new DummyGraphics2d());
|
||||
painter.paint(new DummyGraphics2d());
|
||||
painter.getTextElements((float)1.0, null);
|
||||
}
|
||||
}
|
@ -42,14 +42,14 @@ public final class TestTextSpecInfoAtom extends TestCase {
|
||||
|
||||
public void testRead() {
|
||||
TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
|
||||
TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
|
||||
TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
|
||||
assertEquals(5, run.length);
|
||||
|
||||
assertEquals(10, run[0].length());
|
||||
assertEquals(1, run[1].length());
|
||||
assertEquals(70, run[2].length());
|
||||
assertEquals(9, run[3].length());
|
||||
assertEquals(32, run[4].length());
|
||||
assertEquals(10, run[0].getLength());
|
||||
assertEquals(1, run[1].getLength());
|
||||
assertEquals(70, run[2].getLength());
|
||||
assertEquals(9, run[3].getLength());
|
||||
assertEquals(32, run[4].getLength());
|
||||
|
||||
}
|
||||
|
||||
@ -66,10 +66,10 @@ public final class TestTextSpecInfoAtom extends TestCase {
|
||||
TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
|
||||
spec.reset(32); //length of the parent text
|
||||
|
||||
TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
|
||||
TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
|
||||
assertEquals(1, run.length);
|
||||
|
||||
assertEquals(32, run[0].length());
|
||||
assertEquals(32, run[0].getLength());
|
||||
|
||||
//serialize and read again
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
@ -77,9 +77,9 @@ public final class TestTextSpecInfoAtom extends TestCase {
|
||||
|
||||
byte[] result = out.toByteArray();
|
||||
TextSpecInfoAtom spec2 = new TextSpecInfoAtom(result, 0, result.length);
|
||||
TextSpecInfoAtom.TextSpecInfoRun[] run2 = spec2.getTextSpecInfoRuns();
|
||||
TextSpecInfoRun[] run2 = spec2.getTextSpecInfoRuns();
|
||||
assertEquals(1, run2.length);
|
||||
|
||||
assertEquals(32, run2[0].length());
|
||||
assertEquals(32, run2[0].getLength());
|
||||
}
|
||||
}
|
||||
|
@ -84,13 +84,13 @@ public final class TestTxMasterStyleAtom extends TestCase {
|
||||
TextProp prop;
|
||||
|
||||
//paragraph styles
|
||||
props = txmaster.getParagraphStyles()[0];
|
||||
props = txmaster.getParagraphStyles().get(0);
|
||||
|
||||
prop = props.findByName("alignment");
|
||||
assertEquals(1, prop.getValue()); //title has center alignment
|
||||
|
||||
//character styles
|
||||
props = txmaster.getCharacterStyles()[0];
|
||||
props = txmaster.getCharacterStyles().get(0);
|
||||
|
||||
prop = props.findByName("font.color");
|
||||
assertEquals(0x3000000, prop.getValue());
|
||||
@ -110,27 +110,27 @@ public final class TestTxMasterStyleAtom extends TestCase {
|
||||
TextPropCollection props;
|
||||
TextProp prop;
|
||||
|
||||
TextPropCollection[] prstyles = txmaster.getParagraphStyles();
|
||||
TextPropCollection[] chstyles = txmaster.getCharacterStyles();
|
||||
List<TextPropCollection> prstyles = txmaster.getParagraphStyles();
|
||||
List<TextPropCollection> chstyles = txmaster.getCharacterStyles();
|
||||
assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
|
||||
"must contain styles for 5 indentation levels", 5, prstyles.length);
|
||||
"must contain styles for 5 indentation levels", 5, prstyles.size());
|
||||
assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
|
||||
"must contain styles for 5 indentation levels", 5, chstyles.length);
|
||||
"must contain styles for 5 indentation levels", 5, chstyles.size());
|
||||
|
||||
//paragraph styles
|
||||
props = prstyles[0];
|
||||
props = prstyles.get(0);
|
||||
|
||||
prop = props.findByName("alignment");
|
||||
assertEquals(0, prop.getValue());
|
||||
|
||||
|
||||
for (int i = 0; i < prstyles.length; i++) {
|
||||
assertNotNull("text.offset is null for indentation level " + i, prstyles[i].findByName("text.offset"));
|
||||
assertNotNull("bullet.offset is null for indentation level " + i, prstyles[i].findByName("bullet.offset"));
|
||||
for (int i = 0; i < prstyles.size(); i++) {
|
||||
assertNotNull("text.offset is null for indentation level " + i, prstyles.get(i).findByName("text.offset"));
|
||||
assertNotNull("bullet.offset is null for indentation level " + i, prstyles.get(i).findByName("bullet.offset"));
|
||||
}
|
||||
|
||||
//character styles
|
||||
props = chstyles[0];
|
||||
props = chstyles.get(0);
|
||||
|
||||
prop = props.findByName("font.color");
|
||||
assertEquals(0x1000000, prop.getValue());
|
||||
@ -150,13 +150,13 @@ public final class TestTxMasterStyleAtom extends TestCase {
|
||||
TextProp prop;
|
||||
|
||||
//paragraph styles
|
||||
props = txmaster.getParagraphStyles()[0];
|
||||
props = txmaster.getParagraphStyles().get(0);
|
||||
|
||||
prop = props.findByName("alignment");
|
||||
assertEquals(0, prop.getValue());
|
||||
|
||||
//character styles
|
||||
props = txmaster.getCharacterStyles()[0];
|
||||
props = txmaster.getCharacterStyles().get(0);
|
||||
|
||||
prop = props.findByName("font.color");
|
||||
assertEquals(0x1000000, prop.getValue());
|
||||
@ -176,13 +176,13 @@ public final class TestTxMasterStyleAtom extends TestCase {
|
||||
TextProp prop;
|
||||
|
||||
//paragraph styles
|
||||
props = txmaster.getParagraphStyles()[0];
|
||||
props = txmaster.getParagraphStyles().get(0);
|
||||
|
||||
prop = props.findByName("alignment");
|
||||
assertEquals(0, prop.getValue()); //title has center alignment
|
||||
|
||||
//character styles
|
||||
props = txmaster.getCharacterStyles()[0];
|
||||
props = txmaster.getCharacterStyles().get(0);
|
||||
|
||||
prop = props.findByName("font.color");
|
||||
assertEquals(0x1000000, prop.getValue());
|
||||
|
@ -37,7 +37,10 @@ import org.junit.runners.Suite;
|
||||
TestSheetText.class,
|
||||
TestSlideOrdering.class,
|
||||
TestSoundData.class,
|
||||
TestFontRendering.class
|
||||
TestFontRendering.class,
|
||||
TestPicture.class,
|
||||
TestTextRun.class,
|
||||
TestTextShape.class
|
||||
})
|
||||
public class AllHSLFUserModelTests {
|
||||
}
|
||||
|
@ -19,17 +19,15 @@
|
||||
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPFException9;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
||||
import org.apache.poi.hslf.record.StyleTextProp9Atom;
|
||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
||||
import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.record.*;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
@ -37,21 +35,20 @@ import org.apache.poi.POIDataSamples;
|
||||
*
|
||||
* @author Alex Nikiforov [mailto:anikif@gmail.com]
|
||||
*/
|
||||
public final class TestNumberedList extends TestCase {
|
||||
public final class TestNumberedList {
|
||||
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumberedList() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers.ppt"));
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
final HSLFSlide[] slides = ppt.getSlides();
|
||||
assertEquals(2, slides.length);
|
||||
checkSlide0(slides[0]);
|
||||
checkSlide1(slides[1]);
|
||||
final List<HSLFSlide> slides = ppt.getSlides();
|
||||
assertEquals(2, slides.size());
|
||||
checkSlide0(slides.get(0));
|
||||
checkSlide1(slides.get(1));
|
||||
}
|
||||
|
||||
private void checkSlide0(final HSLFSlide s) {
|
||||
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
|
||||
assertNotNull(numberedListArray);
|
||||
@ -68,26 +65,32 @@ public final class TestNumberedList extends TestCase {
|
||||
assertNull(autoNumbers[1].getAutoNumberScheme());
|
||||
assertTrue(TextAutoNumberSchemeEnum.ANM_AlphaLcParenRight == autoNumbers[2].getAutoNumberScheme());
|
||||
|
||||
HSLFTextParagraph[] textRuns = s.getTextParagraphs();
|
||||
assertEquals(2, textRuns.length);
|
||||
List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
|
||||
assertEquals(2, textParass.size());
|
||||
|
||||
HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
|
||||
assertEquals("titTe", textRun.getRawText());
|
||||
assertEquals(1, textRuns[0].getTextRuns().length);
|
||||
assertFalse(textRun.isBullet());
|
||||
List<HSLFTextParagraph> textParas = textParass.get(0);
|
||||
assertEquals("titTe", HSLFTextParagraph.getRawText(textParas));
|
||||
assertEquals(1, textParas.size());
|
||||
assertFalse(textParas.get(0).isBullet());
|
||||
|
||||
assertEquals("This is a text placeholder that \rfollows the design pattern\rJust a test\rWithout any paragraph\rSecond paragraph first line c) ;\rSecond paragraph second line d) . \r", textRuns[1].getRawText());
|
||||
String expected =
|
||||
"This is a text placeholder that \r" +
|
||||
"follows the design pattern\r" +
|
||||
"Just a test\rWithout any paragraph\r" +
|
||||
"Second paragraph first line c) ;\r" +
|
||||
"Second paragraph second line d) . \r";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
|
||||
|
||||
final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
|
||||
assertEquals(textRuns.length, styleAtoms.length);
|
||||
assertEquals(textParass.size(), styleAtoms.length);
|
||||
final EscherTextboxWrapper wrapper = styleAtoms[1];
|
||||
final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
|
||||
final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
|
||||
final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
|
||||
assertEquals(60, props[0].getCharactersCovered());
|
||||
assertEquals(34, props[1].getCharactersCovered());
|
||||
assertEquals(68, props[2].getCharactersCovered());
|
||||
assertEquals(60, textProps.get(0).getCharactersCovered());
|
||||
assertEquals(34, textProps.get(1).getCharactersCovered());
|
||||
assertEquals(68, textProps.get(2).getCharactersCovered());
|
||||
}
|
||||
|
||||
private void checkSlide1(final HSLFSlide s) {
|
||||
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
|
||||
assertNotNull(numberedListArray);
|
||||
@ -104,25 +107,30 @@ public final class TestNumberedList extends TestCase {
|
||||
assertNull(autoNumbers[1].getAutoNumberScheme());
|
||||
assertTrue(TextAutoNumberSchemeEnum.ANM_AlphaUcPeriod == autoNumbers[2].getAutoNumberScheme());
|
||||
|
||||
final HSLFTextParagraph[] textRuns = s.getTextParagraphs();
|
||||
assertEquals(2, textRuns.length);
|
||||
final List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
|
||||
assertEquals(2, textParass.size());
|
||||
|
||||
HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
|
||||
assertEquals("Second Slide Title", textRun.getRawText());
|
||||
assertEquals(1, textRuns[0].getTextRuns().length);
|
||||
assertFalse(textRun.isBullet());
|
||||
List<HSLFTextParagraph> textParas = textParass.get(0);
|
||||
assertEquals("Second Slide Title", HSLFTextParagraph.getRawText(textParas));
|
||||
assertEquals(1, textParas.size());
|
||||
assertFalse(textParas.get(0).isBullet());
|
||||
|
||||
assertEquals("This is a text placeholder that \rfollows the design pattern\rJust a test\rWithout any paragraph\rSecond paragraph first line c) ;\rSecond paragraph second line d) . \r", textRuns[1].getRawText());
|
||||
String expected =
|
||||
"This is a text placeholder that \r" +
|
||||
"follows the design pattern\r" +
|
||||
"Just a test\rWithout any paragraph\r" +
|
||||
"Second paragraph first line c) ;\r" +
|
||||
"Second paragraph second line d) . \r";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
|
||||
|
||||
final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
|
||||
assertEquals(textRuns.length, styleAtoms.length);
|
||||
assertEquals(textParass.size(), styleAtoms.length);
|
||||
final EscherTextboxWrapper wrapper = styleAtoms[1];
|
||||
final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
|
||||
final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
|
||||
|
||||
final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
|
||||
assertEquals(33, props[0].getCharactersCovered());
|
||||
assertEquals(61, props[1].getCharactersCovered());
|
||||
assertEquals(68, props[2].getCharactersCovered());
|
||||
assertEquals(33, textProps.get(0).getCharactersCovered());
|
||||
assertEquals(61, textProps.get(1).getCharactersCovered());
|
||||
assertEquals(68, textProps.get(2).getCharactersCovered());
|
||||
}
|
||||
}
|
||||
|
@ -19,17 +19,15 @@
|
||||
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPFException9;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
||||
import org.apache.poi.hslf.record.StyleTextProp9Atom;
|
||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
||||
import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.record.*;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
@ -40,20 +38,18 @@ import org.apache.poi.POIDataSamples;
|
||||
*
|
||||
* @author Alex Nikiforov [mailto:anikif@gmail.com]
|
||||
*/
|
||||
public final class TestNumberedList2 extends TestCase {
|
||||
public final class TestNumberedList2 {
|
||||
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumberedList() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers2.ppt"));
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
final HSLFSlide[] slides = ppt.getSlides();
|
||||
assertEquals(2, slides.length);
|
||||
checkSlide0(slides[0]);
|
||||
checkSlide1(slides[1]);
|
||||
final List<HSLFSlide> slides = ppt.getSlides();
|
||||
assertEquals(2, slides.size());
|
||||
checkSlide0(slides.get(0));
|
||||
checkSlide1(slides.get(1));
|
||||
}
|
||||
private void checkSlide0(final HSLFSlide s) {
|
||||
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
|
||||
@ -73,18 +69,22 @@ public final class TestNumberedList2 extends TestCase {
|
||||
assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox1[0].getAutoNumberScheme());
|
||||
|
||||
|
||||
HSLFTextParagraph[] textRuns = s.getTextParagraphs();
|
||||
assertEquals(2, textRuns.length);
|
||||
List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
|
||||
assertEquals(2, textParass.size());
|
||||
|
||||
HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
|
||||
assertEquals("List Item One\rList Item Two\rList Item Three", textRun.getRawText());
|
||||
assertEquals(1, textRuns[0].getTextRuns().length);
|
||||
assertTrue(textRun.isBullet());
|
||||
List<HSLFTextParagraph> textParas = textParass.get(0);
|
||||
assertEquals("List Item One\rList Item Two\rList Item Three", HSLFTextParagraph.getRawText(textParas));
|
||||
assertEquals(3, textParas.size());
|
||||
assertTrue(textParas.get(0).isBullet());
|
||||
|
||||
assertEquals("A numbered list may start at any number \rThis would be used as a continuation list on another page\rThis list should start with #6", textRuns[1].getRawText());
|
||||
String expected =
|
||||
"A numbered list may start at any number \r" +
|
||||
"This would be used as a continuation list on another page\r" +
|
||||
"This list should start with #6";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
|
||||
|
||||
final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
|
||||
assertEquals(textRuns.length, styleAtoms.length);
|
||||
assertEquals(textParass.size(), styleAtoms.length);
|
||||
checkSingleRunWrapper(44, styleAtoms[0]);
|
||||
checkSingleRunWrapper(130, styleAtoms[1]);
|
||||
}
|
||||
@ -99,19 +99,21 @@ public final class TestNumberedList2 extends TestCase {
|
||||
assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox[0].getAutoNumberStartNumber());//Default value = 1 will be used
|
||||
assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox[0].getAutoNumberScheme());
|
||||
|
||||
HSLFTextParagraph[] textRuns = s.getTextParagraphs();
|
||||
assertEquals(3, textRuns.length);
|
||||
List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
|
||||
assertEquals(3, textParass.size());
|
||||
|
||||
HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
|
||||
assertEquals("Bulleted list\rMore bullets", textRun.getRawText());
|
||||
assertEquals(1, textRuns[0].getTextRuns().length);
|
||||
assertTrue(textRun.isBullet());
|
||||
List<HSLFTextParagraph> textParas = textParass.get(0);
|
||||
assertEquals("Bulleted list\rMore bullets", HSLFTextParagraph.getRawText(textParas));
|
||||
assertEquals(2, textParas.size());
|
||||
assertTrue(textParas.get(0).isBullet());
|
||||
|
||||
assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", textRuns[1].getRawText());
|
||||
assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", textRuns[2].getRawText());
|
||||
String expected = "Numbered list between two bulleted lists\rSecond numbered list item";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
|
||||
expected = "Second bulleted list \u2013 should appear after numbered list\rMore bullets";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(2)));
|
||||
|
||||
final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
|
||||
assertEquals(textRuns.length, styleAtoms.length);
|
||||
assertEquals(textParass.size(), styleAtoms.length);
|
||||
checkSingleRunWrapper(27, styleAtoms[0]);
|
||||
checkSingleRunWrapper(67, styleAtoms[1]);
|
||||
checkSingleRunWrapper(70, styleAtoms[2]);
|
||||
@ -120,7 +122,6 @@ public final class TestNumberedList2 extends TestCase {
|
||||
final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
|
||||
final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
|
||||
assertEquals(1, textProps.size());
|
||||
final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
|
||||
assertEquals(exceptedLength, props[0].getCharactersCovered());
|
||||
assertEquals(exceptedLength, textProps.get(0).getCharactersCovered());
|
||||
}
|
||||
}
|
||||
|
@ -19,17 +19,15 @@
|
||||
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPFException9;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
||||
import org.apache.poi.hslf.record.StyleTextProp9Atom;
|
||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
||||
import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.record.*;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
@ -40,19 +38,17 @@ import org.apache.poi.POIDataSamples;
|
||||
*
|
||||
* @author Alex Nikiforov [mailto:anikif@gmail.com]
|
||||
*/
|
||||
public final class TestNumberedList3 extends TestCase {
|
||||
public final class TestNumberedList3 {
|
||||
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumberedList() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers3.ppt"));
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
final HSLFSlide[] slides = ppt.getSlides();
|
||||
assertEquals(1, slides.length);
|
||||
final HSLFSlide slide = slides[0];
|
||||
final List<HSLFSlide> slides = ppt.getSlides();
|
||||
assertEquals(1, slides.size());
|
||||
final HSLFSlide slide = slides.get(0);
|
||||
checkSlide(slide);
|
||||
}
|
||||
private void checkSlide(final HSLFSlide s) {
|
||||
@ -66,35 +62,32 @@ public final class TestNumberedList3 extends TestCase {
|
||||
assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());//Default value = 1 will be used
|
||||
assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
|
||||
|
||||
final HSLFTextParagraph[] textRuns = s.getTextParagraphs();
|
||||
assertEquals(3, textRuns.length);
|
||||
assertEquals("Bulleted list\rMore bullets\rNo bullets here", textRuns[0].getRawText());
|
||||
assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", textRuns[1].getRawText());
|
||||
assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", textRuns[2].getRawText());
|
||||
assertEquals(2, textRuns[0].getTextRuns().length);
|
||||
assertEquals(1, textRuns[1].getTextRuns().length);
|
||||
assertEquals(1, textRuns[2].getTextRuns().length);
|
||||
assertNull(textRuns[0].getStyleTextProp9Atom());
|
||||
assertNotNull(textRuns[1].getStyleTextProp9Atom());
|
||||
assertNull(textRuns[2].getStyleTextProp9Atom());
|
||||
final TextPFException9[] autoNumbers = textRuns[1].getStyleTextProp9Atom().getAutoNumberTypes();
|
||||
final List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
|
||||
assertEquals(3, textParass.size());
|
||||
assertEquals("Bulleted list\rMore bullets\rNo bullets here", HSLFTextParagraph.getRawText(textParass.get(0)));
|
||||
assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", HSLFTextParagraph.getRawText(textParass.get(1)));
|
||||
assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", HSLFTextParagraph.getRawText(textParass.get(2)));
|
||||
assertEquals(3, textParass.get(0).size());
|
||||
assertEquals(2, textParass.get(1).size());
|
||||
assertEquals(2, textParass.get(2).size());
|
||||
assertNull(textParass.get(0).get(0).getStyleTextProp9Atom());
|
||||
assertNotNull(textParass.get(1).get(0).getStyleTextProp9Atom());
|
||||
assertNull(textParass.get(2).get(0).getStyleTextProp9Atom());
|
||||
final TextPFException9[] autoNumbers = textParass.get(1).get(0).getStyleTextProp9Atom().getAutoNumberTypes();
|
||||
assertEquals(1, autoNumbers.length);
|
||||
assertEquals(Short.valueOf((short)1), autoNumbers[0].getfBulletHasAutoNumber());
|
||||
assertEquals(Short.valueOf((short)1), autoNumbers[0].getAutoNumberStartNumber());//Default value = 1 will be used
|
||||
assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
|
||||
|
||||
final List<TextPropCollection> textProps = textRuns[1].getStyleTextPropAtom().getCharacterStyles();
|
||||
final List<TextPropCollection> textProps = textParass.get(1).get(0).getStyleTextPropAtom().getCharacterStyles();
|
||||
assertEquals(1, textProps.size());
|
||||
final TextPropCollection textProp = textProps.get(0);
|
||||
assertEquals(67, textProp.getCharactersCovered());
|
||||
|
||||
|
||||
HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
|
||||
assertTrue(textRun.isBullet());
|
||||
|
||||
assertTrue(textParass.get(0).get(0).isBullet());
|
||||
|
||||
final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
|
||||
assertEquals(textRuns.length, styleAtoms.length);
|
||||
assertEquals(textParass.size(), styleAtoms.length);
|
||||
checkSingleRunWrapper(43, styleAtoms[0]);
|
||||
checkSingleRunWrapper(67, styleAtoms[1]);
|
||||
}
|
||||
@ -102,7 +95,6 @@ public final class TestNumberedList3 extends TestCase {
|
||||
final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
|
||||
final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
|
||||
assertEquals(1, textProps.size());
|
||||
final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
|
||||
assertEquals(exceptedLength, props[0].getCharactersCovered());
|
||||
assertEquals(exceptedLength, textProps.get(0).getCharactersCovered());
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.hslf.model;
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
@ -18,21 +18,21 @@
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hslf.*;
|
||||
import org.apache.poi.hslf.model.*;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests that SlideShow can re-order slides properly
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public final class TestReOrderingSlides extends TestCase {
|
||||
public final class TestReOrderingSlides {
|
||||
// A SlideShow with one slide
|
||||
private HSLFSlideShowImpl hss_one;
|
||||
private HSLFSlideShow ss_one;
|
||||
@ -48,6 +48,7 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
/**
|
||||
* Create/open the slideshows
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
@ -64,10 +65,11 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
/**
|
||||
* Test that we can "re-order" a slideshow with only 1 slide on it
|
||||
*/
|
||||
@Test
|
||||
public void testReOrder1() throws Exception {
|
||||
// Has one slide
|
||||
assertEquals(1, ss_one.getSlides().length);
|
||||
HSLFSlide s1 = ss_one.getSlides()[0];
|
||||
assertEquals(1, ss_one.getSlides().size());
|
||||
HSLFSlide s1 = ss_one.getSlides().get(0);
|
||||
|
||||
// Check slide 1 is as expected
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
@ -86,10 +88,10 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it still has 1 slide
|
||||
assertEquals(1, ss_read.getSlides().length);
|
||||
assertEquals(1, ss_read.getSlides().size());
|
||||
|
||||
// And check it's as expected
|
||||
s1 = ss_read.getSlides()[0];
|
||||
s1 = ss_read.getSlides().get(0);
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
assertEquals(3, s1._getSheetRefId());
|
||||
assertEquals(1, s1.getSlideNumber());
|
||||
@ -99,11 +101,12 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
* Test doing a dummy re-order on a slideshow with
|
||||
* two slides in it
|
||||
*/
|
||||
@Test
|
||||
public void testReOrder2() throws Exception {
|
||||
// Has two slides
|
||||
assertEquals(2, ss_two.getSlides().length);
|
||||
HSLFSlide s1 = ss_two.getSlides()[0];
|
||||
HSLFSlide s2 = ss_two.getSlides()[1];
|
||||
assertEquals(2, ss_two.getSlides().size());
|
||||
HSLFSlide s1 = ss_two.getSlides().get(0);
|
||||
HSLFSlide s2 = ss_two.getSlides().get(1);
|
||||
|
||||
// Check slide 1 is as expected
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
@ -126,11 +129,11 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it still has 2 slides
|
||||
assertEquals(2, ss_read.getSlides().length);
|
||||
assertEquals(2, ss_read.getSlides().size());
|
||||
|
||||
// And check it's as expected
|
||||
s1 = ss_read.getSlides()[0];
|
||||
s2 = ss_read.getSlides()[1];
|
||||
s1 = ss_read.getSlides().get(0);
|
||||
s2 = ss_read.getSlides().get(1);
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
assertEquals(4, s1._getSheetRefId());
|
||||
assertEquals(1, s1.getSlideNumber());
|
||||
@ -142,11 +145,12 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
/**
|
||||
* Test re-ordering slides in a slideshow with 2 slides on it
|
||||
*/
|
||||
@Test
|
||||
public void testReOrder2swap() throws Exception {
|
||||
// Has two slides
|
||||
assertEquals(2, ss_two.getSlides().length);
|
||||
HSLFSlide s1 = ss_two.getSlides()[0];
|
||||
HSLFSlide s2 = ss_two.getSlides()[1];
|
||||
assertEquals(2, ss_two.getSlides().size());
|
||||
HSLFSlide s1 = ss_two.getSlides().get(0);
|
||||
HSLFSlide s2 = ss_two.getSlides().get(1);
|
||||
|
||||
// Check slide 1 is as expected
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
@ -169,11 +173,11 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it still has 2 slides
|
||||
assertEquals(2, ss_read.getSlides().length);
|
||||
assertEquals(2, ss_read.getSlides().size());
|
||||
|
||||
// And check it's as expected
|
||||
s1 = ss_read.getSlides()[0];
|
||||
s2 = ss_read.getSlides()[1];
|
||||
s1 = ss_read.getSlides().get(0);
|
||||
s2 = ss_read.getSlides().get(1);
|
||||
assertEquals(257, s1._getSheetNumber());
|
||||
assertEquals(6, s1._getSheetRefId());
|
||||
assertEquals(1, s1.getSlideNumber());
|
||||
@ -186,12 +190,13 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
* Test doing a dummy re-order on a slideshow with
|
||||
* three slides in it
|
||||
*/
|
||||
@Test
|
||||
public void testReOrder3() throws Exception {
|
||||
// Has three slides
|
||||
assertEquals(3, ss_three.getSlides().length);
|
||||
HSLFSlide s1 = ss_three.getSlides()[0];
|
||||
HSLFSlide s2 = ss_three.getSlides()[1];
|
||||
HSLFSlide s3 = ss_three.getSlides()[2];
|
||||
assertEquals(3, ss_three.getSlides().size());
|
||||
HSLFSlide s1 = ss_three.getSlides().get(0);
|
||||
HSLFSlide s2 = ss_three.getSlides().get(1);
|
||||
HSLFSlide s3 = ss_three.getSlides().get(2);
|
||||
|
||||
// Check slide 1 is as expected
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
@ -218,12 +223,12 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it still has 3 slides
|
||||
assertEquals(3, ss_read.getSlides().length);
|
||||
assertEquals(3, ss_read.getSlides().size());
|
||||
|
||||
// And check it's as expected
|
||||
s1 = ss_read.getSlides()[0];
|
||||
s2 = ss_read.getSlides()[1];
|
||||
s3 = ss_read.getSlides()[2];
|
||||
s1 = ss_read.getSlides().get(0);
|
||||
s2 = ss_read.getSlides().get(1);
|
||||
s3 = ss_read.getSlides().get(2);
|
||||
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
assertEquals(3, s1._getSheetRefId());
|
||||
@ -239,12 +244,13 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
/**
|
||||
* Test re-ordering slides in a slideshow with 3 slides on it
|
||||
*/
|
||||
@Test
|
||||
public void testReOrder3swap() throws Exception {
|
||||
// Has three slides
|
||||
assertEquals(3, ss_three.getSlides().length);
|
||||
HSLFSlide s1 = ss_three.getSlides()[0];
|
||||
HSLFSlide s2 = ss_three.getSlides()[1];
|
||||
HSLFSlide s3 = ss_three.getSlides()[2];
|
||||
assertEquals(3, ss_three.getSlides().size());
|
||||
HSLFSlide s1 = ss_three.getSlides().get(0);
|
||||
HSLFSlide s2 = ss_three.getSlides().get(1);
|
||||
HSLFSlide s3 = ss_three.getSlides().get(2);
|
||||
|
||||
// Check slide 1 is as expected
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
@ -263,6 +269,18 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
// (1 -> 2, 2 -> 3)
|
||||
ss_three.reorderSlide(3, 1);
|
||||
|
||||
// refresh the slides
|
||||
s1 = ss_three.getSlides().get(0);
|
||||
s2 = ss_three.getSlides().get(1);
|
||||
s3 = ss_three.getSlides().get(2);
|
||||
|
||||
assertEquals(1, s1.getSlideNumber());
|
||||
assertEquals(2, s2.getSlideNumber());
|
||||
assertEquals(3, s3.getSlideNumber());
|
||||
|
||||
assertEquals("Slide 3", ((HSLFTextShape)s1.getShapes().get(0)).getText());
|
||||
assertEquals("Slide 1", ((HSLFTextShape)s3.getShapes().get(0)).getText());
|
||||
|
||||
// Write out, and read back in
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
hss_three.write(baos);
|
||||
@ -272,16 +290,16 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it still has 3 slides
|
||||
assertEquals(3, ss_read.getSlides().length);
|
||||
assertEquals(3, ss_read.getSlides().size());
|
||||
|
||||
// And check it's as expected
|
||||
HSLFSlide _s1 = ss_read.getSlides()[0];
|
||||
HSLFSlide _s2 = ss_read.getSlides()[1];
|
||||
HSLFSlide _s3 = ss_read.getSlides()[2];
|
||||
HSLFSlide _s1 = ss_read.getSlides().get(0);
|
||||
HSLFSlide _s2 = ss_read.getSlides().get(1);
|
||||
HSLFSlide _s3 = ss_read.getSlides().get(2);
|
||||
|
||||
// 1 --> 3
|
||||
assertEquals(s1._getSheetNumber(), _s3._getSheetNumber());
|
||||
assertEquals(s1._getSheetRefId(), _s3._getSheetRefId());
|
||||
assertEquals(s1._getSheetNumber(), _s1._getSheetNumber());
|
||||
assertEquals(s1._getSheetRefId(), _s1._getSheetRefId());
|
||||
assertEquals(1, s1.getSlideNumber());
|
||||
|
||||
// 2nd slide is not updated
|
||||
@ -290,8 +308,8 @@ public final class TestReOrderingSlides extends TestCase {
|
||||
assertEquals(2, s2.getSlideNumber());
|
||||
|
||||
// 3 --> 1
|
||||
assertEquals(s3._getSheetNumber(), _s1._getSheetNumber());
|
||||
assertEquals(s3._getSheetRefId(), _s1._getSheetRefId());
|
||||
assertEquals(s3._getSheetNumber(), _s3._getSheetNumber());
|
||||
assertEquals(s3._getSheetRefId(), _s3._getSheetRefId());
|
||||
assertEquals(3, s3.getSlideNumber());
|
||||
}
|
||||
}
|
||||
|
@ -17,14 +17,12 @@
|
||||
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hslf.*;
|
||||
import org.apache.poi.hslf.record.ParentAwareRecord;
|
||||
import org.apache.poi.hslf.record.Record;
|
||||
import org.apache.poi.hslf.record.RecordContainer;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.record.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests that the record setup done by SlideShow
|
||||
@ -33,17 +31,20 @@ import org.apache.poi.POIDataSamples;
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public final class TestRecordSetup extends TestCase {
|
||||
public final class TestRecordSetup {
|
||||
// SlideShow primed on the test data
|
||||
@SuppressWarnings("unused")
|
||||
private HSLFSlideShow ss;
|
||||
private HSLFSlideShowImpl hss;
|
||||
|
||||
public TestRecordSetup() throws Exception {
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
||||
ss = new HSLFSlideShow(hss);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleParentAwareRecords() {
|
||||
Record[] records = hss.getRecords();
|
||||
for(int i=0; i<records.length; i++) {
|
||||
|
@ -17,22 +17,25 @@
|
||||
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.apache.poi.POITestCase.assertContains;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.POITestCase;
|
||||
import org.apache.poi.hslf.model.*;
|
||||
import org.apache.poi.hslf.record.Record;
|
||||
import org.apache.poi.hslf.record.SlideListWithText;
|
||||
import org.apache.poi.hslf.record.*;
|
||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test that the friendly getters and setters on RichTextRun
|
||||
* behave as expected.
|
||||
* (model.TestTextRun tests the other functionality)
|
||||
*/
|
||||
public final class TestRichTextRun extends POITestCase {
|
||||
public final class TestRichTextRun {
|
||||
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
// SlideShow primed on the test data
|
||||
@ -48,7 +51,8 @@ public final class TestRichTextRun extends POITestCase {
|
||||
private HSLFSlideShowImpl hssChinese;
|
||||
private static String filenameC;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Basic (non rich) test file
|
||||
hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
||||
ss = new HSLFSlideShow(hss);
|
||||
@ -76,27 +80,30 @@ public final class TestRichTextRun extends POITestCase {
|
||||
* Test the stuff about getting/setting bold
|
||||
* on a non rich text run
|
||||
*/
|
||||
@Test
|
||||
public void testBoldNonRich() {
|
||||
HSLFSlide slideOne = ss.getSlides()[0];
|
||||
HSLFTextParagraph[] textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextRun rtr = textRuns[0].getTextRuns()[0];
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
List<HSLFTextParagraph> textParas = textParass.get(0);
|
||||
HSLFTextRun rtr = textParas.get(0).getTextRuns().get(0);
|
||||
|
||||
assertNull(rtr._getRawCharacterStyle());
|
||||
assertNull(rtr._getRawParagraphStyle());
|
||||
assertNotNull(rtr.getCharacterStyle());
|
||||
assertNotNull(textParas.get(0).getParagraphStyle());
|
||||
assertFalse(rtr.isBold());
|
||||
|
||||
// Now set it to not bold
|
||||
rtr.setBold(false);
|
||||
//setting bold=false doesn't change the internal state
|
||||
assertNull(rtr._getRawCharacterStyle());
|
||||
assertNull(rtr._getRawParagraphStyle());
|
||||
// in Pre 3.12: setting bold=false doesn't change the internal state
|
||||
// now: also allow explicitly disable styles and there aren't any non rich text runs anymore
|
||||
assertNotNull(rtr.getCharacterStyle());
|
||||
assertNotNull(textParas.get(0).getParagraphStyle());
|
||||
|
||||
assertFalse(rtr.isBold());
|
||||
|
||||
// And now make it bold
|
||||
rtr.setBold(true);
|
||||
assertNotNull(rtr._getRawCharacterStyle());
|
||||
assertNotNull(rtr._getRawParagraphStyle());
|
||||
assertNotNull(rtr.getCharacterStyle());
|
||||
assertNotNull(textParas.get(0).getParagraphStyle());
|
||||
assertTrue(rtr.isBold());
|
||||
}
|
||||
|
||||
@ -104,115 +111,116 @@ public final class TestRichTextRun extends POITestCase {
|
||||
* Test the stuff about getting/setting bold
|
||||
* on a rich text run
|
||||
*/
|
||||
@Test
|
||||
public void testBoldRich() {
|
||||
HSLFSlide slideOneR = ssRichA.getSlides()[0];
|
||||
HSLFTextParagraph[] textRunsR = slideOneR.getTextParagraphs();
|
||||
HSLFTextRun[] rtrs = textRunsR[1].getTextRuns();
|
||||
assertEquals(3, rtrs.length);
|
||||
HSLFSlide slideOneR = ssRichA.getSlides().get(0);
|
||||
List<List<HSLFTextParagraph>> textParass = slideOneR.getTextParagraphs();
|
||||
List<HSLFTextParagraph> textParas = textParass.get(1);
|
||||
assertEquals(3, textParas.size());
|
||||
|
||||
assertTrue(rtrs[0].isBold());
|
||||
assertFalse(rtrs[1].isBold());
|
||||
assertFalse(rtrs[2].isBold());
|
||||
assertTrue(textParas.get(0).getTextRuns().get(0).isBold());
|
||||
assertFalse(textParas.get(1).getTextRuns().get(0).isBold());
|
||||
assertFalse(textParas.get(2).getTextRuns().get(0).isBold());
|
||||
|
||||
rtrs[0].setBold(true);
|
||||
rtrs[1].setBold(true);
|
||||
textParas.get(0).getTextRuns().get(0).setBold(true);
|
||||
textParas.get(1).getTextRuns().get(0).setBold(true);
|
||||
|
||||
assertTrue(rtrs[0].isBold());
|
||||
assertTrue(rtrs[1].isBold());
|
||||
assertTrue(textParas.get(0).getTextRuns().get(0).isBold());
|
||||
assertTrue(textParas.get(1).getTextRuns().get(0).isBold());
|
||||
|
||||
rtrs[0].setBold(false);
|
||||
rtrs[1].setBold(false);
|
||||
textParas.get(0).getTextRuns().get(0).setBold(false);
|
||||
textParas.get(1).getTextRuns().get(0).setBold(false);
|
||||
|
||||
assertFalse(rtrs[0].isBold());
|
||||
assertFalse(rtrs[1].isBold());
|
||||
assertFalse(textParas.get(0).getTextRuns().get(0).isBold());
|
||||
assertFalse(textParas.get(1).getTextRuns().get(0).isBold());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getting and setting the font size on rich and non
|
||||
* rich text runs
|
||||
*/
|
||||
@Test
|
||||
public void testFontSize() {
|
||||
|
||||
HSLFSlide slideOne = ss.getSlides()[0];
|
||||
HSLFTextParagraph[] textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextRun rtr = textRuns[0].getTextRuns()[0];
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
HSLFTextRun rtr = textParass.get(0).get(0).getTextRuns().get(0);
|
||||
|
||||
HSLFSlide slideOneR = ssRichB.getSlides()[0];
|
||||
HSLFTextParagraph[] textRunsR = slideOneR.getTextParagraphs();
|
||||
HSLFTextRun rtrRa = textRunsR[0].getTextRuns()[0];
|
||||
HSLFTextRun rtrRb = textRunsR[1].getTextRuns()[0];
|
||||
HSLFTextRun rtrRc = textRunsR[1].getTextRuns()[3];
|
||||
HSLFSlide slideOneR = ssRichB.getSlides().get(0);
|
||||
List<List<HSLFTextParagraph>> textParassR = slideOneR.getTextParagraphs();
|
||||
HSLFTextRun rtrRa = textParassR.get(0).get(0).getTextRuns().get(0);
|
||||
HSLFTextRun rtrRb = textParassR.get(1).get(0).getTextRuns().get(0);
|
||||
HSLFTextRun rtrRc = textParassR.get(1).get(3).getTextRuns().get(0);
|
||||
|
||||
String defaultFont = "Arial";
|
||||
|
||||
// Start off with rich one
|
||||
// First run has defaults
|
||||
assertEquals(44, rtrRa.getFontSize());
|
||||
assertEquals(defaultFont, rtrRa.getFontName());
|
||||
assertEquals(44, rtrRa.getFontSize(), 0);
|
||||
assertEquals(defaultFont, rtrRa.getFontFamily());
|
||||
|
||||
// Second is size 20, default font
|
||||
assertEquals(20, rtrRb.getFontSize());
|
||||
assertEquals(defaultFont, rtrRb.getFontName());
|
||||
assertEquals(20, rtrRb.getFontSize(), 0);
|
||||
assertEquals(defaultFont, rtrRb.getFontFamily());
|
||||
// Third is size 24, alt font
|
||||
assertEquals(24, rtrRc.getFontSize());
|
||||
assertEquals("Times New Roman", rtrRc.getFontName());
|
||||
assertEquals(24, rtrRc.getFontSize(), 0);
|
||||
assertEquals("Times New Roman", rtrRc.getFontFamily());
|
||||
|
||||
// Change 2nd to different size and font
|
||||
assertEquals(2, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR
|
||||
rtrRb.setFontSize(18);
|
||||
rtrRb.setFontName("Courier");
|
||||
rtrRb.setFontFamily("Courier");
|
||||
assertEquals(3, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR + Courier
|
||||
assertEquals(18, rtrRb.getFontSize());
|
||||
assertEquals("Courier", rtrRb.getFontName());
|
||||
assertEquals(18, rtrRb.getFontSize(), 0);
|
||||
assertEquals("Courier", rtrRb.getFontFamily());
|
||||
|
||||
|
||||
// Now do non rich one
|
||||
assertEquals(44, rtr.getFontSize());
|
||||
assertEquals(defaultFont, rtr.getFontName());
|
||||
assertEquals(44, rtr.getFontSize(), 0);
|
||||
assertEquals(defaultFont, rtr.getFontFamily());
|
||||
assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
|
||||
assertNull(rtr._getRawCharacterStyle());
|
||||
assertNull(rtr._getRawParagraphStyle());
|
||||
assertNotNull(rtr.getCharacterStyle());
|
||||
assertNotNull(rtr.getTextParagraph().getParagraphStyle());
|
||||
|
||||
// Change Font size
|
||||
rtr.setFontSize(99);
|
||||
assertEquals(99, rtr.getFontSize());
|
||||
assertEquals(defaultFont, rtr.getFontName());
|
||||
assertNotNull(rtr._getRawCharacterStyle());
|
||||
assertNotNull(rtr._getRawParagraphStyle());
|
||||
assertEquals(99, rtr.getFontSize(), 0);
|
||||
assertEquals(defaultFont, rtr.getFontFamily());
|
||||
assertNotNull(rtr.getCharacterStyle());
|
||||
assertNotNull(rtr.getTextParagraph().getParagraphStyle());
|
||||
assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
|
||||
|
||||
// Change Font size and name
|
||||
rtr.setFontSize(25);
|
||||
rtr.setFontName("Times New Roman");
|
||||
assertEquals(25, rtr.getFontSize());
|
||||
assertEquals("Times New Roman", rtr.getFontName());
|
||||
assertNotNull(rtr._getRawCharacterStyle());
|
||||
assertNotNull(rtr._getRawParagraphStyle());
|
||||
rtr.setFontFamily("Times New Roman");
|
||||
assertEquals(25, rtr.getFontSize(), 0);
|
||||
assertEquals("Times New Roman", rtr.getFontFamily());
|
||||
assertNotNull(rtr.getCharacterStyle());
|
||||
assertNotNull(rtr.getTextParagraph().getParagraphStyle());
|
||||
assertEquals(2, ss.getFontCollection().getChildRecords().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChangeWriteRead() throws Exception {
|
||||
HSLFSlideShowImpl[] h = new HSLFSlideShowImpl[] { hss, hssRichA, hssRichB };
|
||||
HSLFSlide[] s = new HSLFSlide[] { ss.getSlides()[0], ssRichA.getSlides()[0], ssRichB.getSlides()[0] };
|
||||
|
||||
for(int i=0; i<h.length; i++) {
|
||||
for(HSLFSlideShow h : new HSLFSlideShow[] { ss, ssRichA, ssRichB }) {
|
||||
// Change
|
||||
HSLFSlide slideOne = s[i];
|
||||
HSLFTextParagraph[] textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextRun rtr = textRuns[0].getTextRuns()[0];
|
||||
HSLFSlide slideOne = h.getSlides().get(0);
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
HSLFTextRun rtr = textParass.get(0).get(0).getTextRuns().get(0);
|
||||
|
||||
rtr.setBold(true);
|
||||
rtr.setFontSize(18);
|
||||
rtr.setFontName("Courier");
|
||||
rtr.setFontFamily("Courier");
|
||||
HSLFTextParagraph.storeText(textParass.get(0));
|
||||
|
||||
// Check it took those
|
||||
assertEquals(true, rtr.isBold());
|
||||
assertEquals(18, rtr.getFontSize());
|
||||
assertEquals("Courier", rtr.getFontName());
|
||||
assertTrue(rtr.isBold());
|
||||
assertEquals(18., rtr.getFontSize(), 0);
|
||||
assertEquals("Courier", rtr.getFontFamily());
|
||||
|
||||
// Write out and back in
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
h[i].write(baos);
|
||||
h.write(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
|
||||
HSLFSlideShowImpl readHSLF = new HSLFSlideShowImpl(bais);
|
||||
@ -221,23 +229,23 @@ public final class TestRichTextRun extends POITestCase {
|
||||
// Tweak existing one again, to ensure really worked
|
||||
rtr.setBold(false);
|
||||
rtr.setFontSize(17);
|
||||
rtr.setFontName("CourierZZ");
|
||||
rtr.setFontFamily("CourierZZ");
|
||||
|
||||
// Check it took those changes
|
||||
assertEquals(false, rtr.isBold());
|
||||
assertEquals(17, rtr.getFontSize());
|
||||
assertEquals("CourierZZ", rtr.getFontName());
|
||||
assertFalse(rtr.isBold());
|
||||
assertEquals(17., rtr.getFontSize(), 0);
|
||||
assertEquals("CourierZZ", rtr.getFontFamily());
|
||||
|
||||
|
||||
// Now, look at the one we changed, wrote out, and read back in
|
||||
// Ensure it does contain our original modifications
|
||||
HSLFSlide slideOneRR = readS.getSlides()[0];
|
||||
HSLFTextParagraph[] textRunsRR = slideOneRR.getTextParagraphs();
|
||||
HSLFTextRun rtrRRa = textRunsRR[0].getTextRuns()[0];
|
||||
HSLFSlide slideOneRR = readS.getSlides().get(0);
|
||||
List<List<HSLFTextParagraph>> textParassRR = slideOneRR.getTextParagraphs();
|
||||
HSLFTextRun rtrRRa = textParassRR.get(0).get(0).getTextRuns().get(0);
|
||||
|
||||
assertEquals(true, rtrRRa.isBold());
|
||||
assertEquals(18, rtrRRa.getFontSize());
|
||||
assertEquals("Courier", rtrRRa.getFontName());
|
||||
assertTrue(rtrRRa.isBold());
|
||||
assertEquals(18., rtrRRa.getFontSize(), 0);
|
||||
assertEquals("Courier", rtrRRa.getFontFamily());
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,16 +253,17 @@ public final class TestRichTextRun extends POITestCase {
|
||||
* Test that we can do the right things when the paragraph styles
|
||||
* run out before the character styles do
|
||||
*/
|
||||
@Test
|
||||
public void testParagraphStylesShorterTheCharStyles() {
|
||||
// Check we have the right number of sheets
|
||||
HSLFSlide[] slides = ssRichC.getSlides();
|
||||
assertEquals(14, slides.length);
|
||||
List<HSLFSlide> slides = ssRichC.getSlides();
|
||||
assertEquals(14, slides.size());
|
||||
|
||||
// Check the number of text runs on interesting sheets
|
||||
HSLFSlide slideThreeC = ssRichC.getSlides()[2];
|
||||
HSLFSlide slideSevenC = ssRichC.getSlides()[6];
|
||||
assertEquals(3, slideThreeC.getTextParagraphs().length);
|
||||
assertEquals(5, slideSevenC.getTextParagraphs().length);
|
||||
HSLFSlide slideThreeC = ssRichC.getSlides().get(2);
|
||||
HSLFSlide slideSevenC = ssRichC.getSlides().get(6);
|
||||
assertEquals(4, slideThreeC.getTextParagraphs().size());
|
||||
assertEquals(5, slideSevenC.getTextParagraphs().size());
|
||||
|
||||
// On slide three, we should have:
|
||||
// TR:
|
||||
@ -266,32 +275,20 @@ public final class TestRichTextRun extends POITestCase {
|
||||
// Illustrative Example
|
||||
// .
|
||||
|
||||
HSLFTextParagraph[] s3tr = slideThreeC.getTextParagraphs();
|
||||
HSLFTextRun[] s3rtr0 = s3tr[0].getTextRuns();
|
||||
HSLFTextRun[] s3rtr1 = s3tr[1].getTextRuns();
|
||||
HSLFTextRun[] s3rtr2 = s3tr[2].getTextRuns();
|
||||
List<List<HSLFTextParagraph>> s3tr = slideThreeC.getTextParagraphs();
|
||||
List<HSLFTextRun> s3rtr0 = s3tr.get(0).get(0).getTextRuns();
|
||||
List<HSLFTextRun> s3rtr1 = s3tr.get(2).get(0).getTextRuns();
|
||||
List<HSLFTextRun> s3rtr2 = s3tr.get(3).get(0).getTextRuns();
|
||||
|
||||
assertEquals(2, s3rtr0.length);
|
||||
assertEquals(1, s3rtr1.length);
|
||||
assertEquals(2, s3rtr2.length);
|
||||
assertEquals(2, s3rtr0.size());
|
||||
assertEquals(1, s3rtr1.size());
|
||||
assertEquals(2, s3rtr2.size());
|
||||
|
||||
assertEquals("You are an important supplier of various items that I need", s3rtr0[0].getRawText());
|
||||
assertEquals("", s3rtr0[1].getRawText());
|
||||
assertEquals("Source: Internal focus groups", s3rtr1[0].getRawText());
|
||||
assertEquals("Illustrative Example", s3rtr2[0].getRawText());
|
||||
assertEquals("", s3rtr2[1].getRawText());
|
||||
|
||||
assertTrue(s3rtr0[0]._isParagraphStyleShared());
|
||||
assertTrue(s3rtr0[1]._isParagraphStyleShared());
|
||||
assertFalse(s3rtr1[0]._isParagraphStyleShared());
|
||||
assertTrue(s3rtr2[0]._isParagraphStyleShared());
|
||||
assertTrue(s3rtr2[1]._isParagraphStyleShared());
|
||||
|
||||
assertFalse(s3rtr0[0]._isCharacterStyleShared());
|
||||
assertFalse(s3rtr0[1]._isCharacterStyleShared());
|
||||
assertFalse(s3rtr1[0]._isCharacterStyleShared());
|
||||
assertFalse(s3rtr2[0]._isCharacterStyleShared());
|
||||
assertFalse(s3rtr2[1]._isCharacterStyleShared());
|
||||
assertEquals("You are an important supplier of various items that I need", s3rtr0.get(0).getRawText());
|
||||
assertEquals("", s3rtr0.get(1).getRawText());
|
||||
assertEquals("Source: Internal focus groups", s3rtr1.get(0).getRawText());
|
||||
assertEquals("Illustrative Example", s3rtr2.get(0).getRawText());
|
||||
assertEquals("", s3rtr2.get(1).getRawText());
|
||||
|
||||
// On slide seven, we have:
|
||||
// TR:
|
||||
@ -300,26 +297,14 @@ public final class TestRichTextRun extends POITestCase {
|
||||
// <ps>(text a)</ps><ps>(text a)(text b)</ps>
|
||||
// TR:
|
||||
// (text)
|
||||
HSLFTextParagraph[] s7tr = slideSevenC.getTextParagraphs();
|
||||
HSLFTextRun[] s7rtr0 = s7tr[0].getTextRuns();
|
||||
HSLFTextRun[] s7rtr1 = s7tr[1].getTextRuns();
|
||||
HSLFTextRun[] s7rtr2 = s7tr[2].getTextRuns();
|
||||
List<List<HSLFTextParagraph>> s7tr = slideSevenC.getTextParagraphs();
|
||||
List<HSLFTextParagraph> s7rtr0 = s7tr.get(0);
|
||||
List<HSLFTextParagraph> s7rtr1 = s7tr.get(1);
|
||||
List<HSLFTextParagraph> s7rtr2 = s7tr.get(2);
|
||||
|
||||
assertEquals(1, s7rtr0.length);
|
||||
assertEquals(3, s7rtr1.length);
|
||||
assertEquals(1, s7rtr2.length);
|
||||
|
||||
assertFalse(s7rtr0[0]._isParagraphStyleShared());
|
||||
assertFalse(s7rtr1[0]._isParagraphStyleShared());
|
||||
assertTrue(s7rtr1[1]._isParagraphStyleShared());
|
||||
assertTrue(s7rtr1[2]._isParagraphStyleShared());
|
||||
assertFalse(s7rtr2[0]._isParagraphStyleShared());
|
||||
|
||||
assertFalse(s7rtr0[0]._isCharacterStyleShared());
|
||||
assertTrue(s7rtr1[0]._isCharacterStyleShared());
|
||||
assertTrue(s7rtr1[1]._isCharacterStyleShared());
|
||||
assertFalse(s7rtr1[2]._isCharacterStyleShared());
|
||||
assertFalse(s7rtr2[0]._isCharacterStyleShared());
|
||||
assertEquals(1, s7rtr0.size());
|
||||
assertEquals(8, s7rtr1.size());
|
||||
assertEquals(1, s7rtr2.size());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,39 +312,44 @@ public final class TestRichTextRun extends POITestCase {
|
||||
* run out before the character styles do, when we tweak something
|
||||
* and write back out.
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unused")
|
||||
public void testParagraphStylesShorterTheCharStylesWrite() throws Exception {
|
||||
assertMatchesSLTWC(ssRichC);
|
||||
assertMatchesFileC(ssRichC);
|
||||
|
||||
HSLFSlide slideSevenC = ssRichC.getSlides()[6];
|
||||
HSLFTextParagraph[] s7tr = slideSevenC.getTextParagraphs();
|
||||
HSLFTextRun[] s7rtr0 = s7tr[0].getTextRuns();
|
||||
HSLFTextRun[] s7rtr1 = s7tr[1].getTextRuns();
|
||||
HSLFTextRun[] s7rtr2 = s7tr[2].getTextRuns();
|
||||
HSLFSlide slideSevenC = ssRichC.getSlides().get(6);
|
||||
List<List<HSLFTextParagraph>> s7tr = slideSevenC.getTextParagraphs();
|
||||
List<HSLFTextRun> s7rtr0 = s7tr.get(0).get(0).getTextRuns();
|
||||
List<HSLFTextRun> s7rtr1 = s7tr.get(1).get(0).getTextRuns();
|
||||
List<HSLFTextRun> s7rtr2 = s7tr.get(2).get(0).getTextRuns();
|
||||
|
||||
String oldText;
|
||||
|
||||
// Reset the text on the last run
|
||||
// Need to ensure it's a run that really has styles!
|
||||
oldText = s7rtr2[0].getRawText();
|
||||
s7rtr2[0].setText( oldText );
|
||||
assertEquals(oldText, s7rtr2[0].getRawText());
|
||||
assertEquals(oldText, s7tr[2].getRawText());
|
||||
assertEquals(oldText.length() + 1, s7rtr2[0]._getRawCharacterStyle().getCharactersCovered());
|
||||
assertEquals(oldText.length() + 1, s7rtr2[0]._getRawParagraphStyle().getCharactersCovered());
|
||||
oldText = s7rtr2.get(0).getRawText();
|
||||
s7rtr2.get(0).setText( oldText );
|
||||
HSLFTextParagraph.storeText(s7tr.get(2));
|
||||
assertEquals(oldText, s7rtr2.get(0).getRawText());
|
||||
assertEquals(oldText, HSLFTextParagraph.getRawText(s7tr.get(2)));
|
||||
assertEquals(oldText.length() + 1, s7rtr2.get(0).getCharacterStyle().getCharactersCovered());
|
||||
assertEquals(oldText.length() + 1, s7rtr2.get(0).getTextParagraph().getParagraphStyle().getCharactersCovered());
|
||||
assertMatchesSLTWC(ssRichC);
|
||||
assertMatchesFileC(ssRichC);
|
||||
|
||||
// Reset the text on a shared paragraph
|
||||
oldText = s7rtr1[2].getRawText();
|
||||
s7rtr1[2].setText( oldText );
|
||||
assertEquals(oldText, s7rtr1[2].getRawText());
|
||||
assertEquals(oldText.length() + 1, s7rtr1[2]._getRawCharacterStyle().getCharactersCovered());
|
||||
oldText = s7rtr1.get(0).getRawText();
|
||||
s7rtr1.get(0).setText( oldText );
|
||||
HSLFTextParagraph.storeText(s7tr.get(1));
|
||||
assertEquals(oldText, s7rtr1.get(0).getRawText());
|
||||
assertEquals(oldText.length(), s7rtr1.get(0).getCharacterStyle().getCharactersCovered());
|
||||
assertMatchesSLTWC(ssRichC);
|
||||
assertMatchesFileC(ssRichC);
|
||||
|
||||
// Reset the text on a shared paragraph+character
|
||||
s7rtr1[1].setText( s7rtr1[1].getRawText() );
|
||||
s7rtr1.get(0).setText( s7rtr1.get(0).getRawText() );
|
||||
HSLFTextParagraph.storeText(s7tr.get(1));
|
||||
assertMatchesSLTWC(ssRichC);
|
||||
assertMatchesFileC(ssRichC);
|
||||
}
|
||||
@ -391,17 +381,11 @@ public final class TestRichTextRun extends POITestCase {
|
||||
|
||||
byte[] r_rb = writeRecord(ref_r);
|
||||
byte[] s_rb = writeRecord(s_r);
|
||||
assertEquals(r_rb.length, s_rb.length);
|
||||
for(int j=0; j<r_rb.length; j++) {
|
||||
assertEquals(r_rb[j],s_rb[j]);
|
||||
}
|
||||
assertArrayEquals(r_rb, s_rb);
|
||||
}
|
||||
|
||||
// Check the bytes are the same
|
||||
assertEquals(raw_slwt.length, s_slwt.length);
|
||||
for(int i=0; i<raw_slwt.length; i++) {
|
||||
assertEquals(raw_slwt[i], s_slwt[i]);
|
||||
}
|
||||
assertArrayEquals(raw_slwt, s_slwt);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -409,35 +393,35 @@ public final class TestRichTextRun extends POITestCase {
|
||||
* of slideshow c
|
||||
*/
|
||||
private static void assertMatchesFileC(HSLFSlideShow s) throws Exception {
|
||||
if (true) { // TODO - test is disabled, pending fix of bug #39800
|
||||
// System.err.println("Skipping test, as would be marked as failed due to bug #39800"); //
|
||||
return;
|
||||
}
|
||||
if(false) {
|
||||
// Grab the bytes of the file
|
||||
FileInputStream fin = new FileInputStream(filenameC);
|
||||
ByteArrayOutputStream fb = new ByteArrayOutputStream();
|
||||
byte[] b = new byte[4096];
|
||||
int read = 0;
|
||||
while(read != -1) {
|
||||
read = fin.read(b);
|
||||
if(read > 0) {
|
||||
fb.write(b, 0, read);
|
||||
}
|
||||
}
|
||||
byte[] raw_file = fb.toByteArray();
|
||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(_slTests.getFile(filenameC));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
InputStream is = fs.createDocumentInputStream("PowerPoint Document");
|
||||
IOUtils.copy(is, baos);
|
||||
is.close();
|
||||
fs.close();
|
||||
byte[] raw_file = baos.toByteArray();
|
||||
|
||||
// Now write out the slideshow
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
baos.reset();
|
||||
s.write(baos);
|
||||
fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
|
||||
baos.reset();
|
||||
is = fs.createDocumentInputStream("PowerPoint Document");
|
||||
IOUtils.copy(is, baos);
|
||||
is.close();
|
||||
fs.close();
|
||||
byte[] raw_ss = baos.toByteArray();
|
||||
|
||||
FileOutputStream fos = new FileOutputStream("PowerPoint Document.new.stream");
|
||||
fos.write(raw_ss);
|
||||
fos.close();
|
||||
|
||||
// different paragraph mask, because of sanitizing
|
||||
raw_ss[169030] = 0x0a;
|
||||
|
||||
// Ensure they're the same
|
||||
assertEquals(raw_file.length, raw_ss.length);
|
||||
for(int i=0; i<raw_file.length; i++) {
|
||||
assertEquals(raw_file[i], raw_ss[i]);
|
||||
}
|
||||
}
|
||||
assertArrayEquals(raw_file, raw_ss);
|
||||
}
|
||||
|
||||
private byte[] writeRecord(Record r) throws Exception {
|
||||
@ -446,15 +430,13 @@ if(false) {
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndentationLevel() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
|
||||
HSLFSlide[] sl = ppt.getSlides();
|
||||
for (int i = 0; i < sl.length; i++) {
|
||||
HSLFTextParagraph[] txt = sl[i].getTextParagraphs();
|
||||
for (int j = 0; j < txt.length; j++) {
|
||||
HSLFTextRun[] rt = txt[j].getTextRuns();
|
||||
for (int k = 0; k < rt.length; k++) {
|
||||
int indent = rt[k].getIndentLevel();
|
||||
for (HSLFSlide sl : ppt.getSlides()) {
|
||||
for (List<HSLFTextParagraph> txt : sl.getTextParagraphs()) {
|
||||
for (HSLFTextParagraph p : txt) {
|
||||
int indent = p.getIndentLevel();
|
||||
assertTrue(indent >= 0 && indent <= 4 );
|
||||
}
|
||||
|
||||
@ -462,78 +444,84 @@ if(false) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadParagraphStyles() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt"));
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
HSLFTextRun rt;
|
||||
HSLFTextParagraph[] txt;
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
assertEquals(2, slide.length);
|
||||
HSLFTextParagraph rt;
|
||||
List<List<HSLFTextParagraph>> txt;
|
||||
List<HSLFSlide> slide = ppt.getSlides();
|
||||
assertEquals(2, slide.size());
|
||||
|
||||
txt = slide[0].getTextParagraphs();
|
||||
assertEquals(2, txt.length);
|
||||
txt = slide.get(0).getTextParagraphs();
|
||||
assertEquals(2, txt.size());
|
||||
|
||||
assertEquals("Title text", txt[0].getRawText());
|
||||
assertEquals(1, txt[0].getTextRuns().length);
|
||||
rt = txt[0].getTextRuns()[0];
|
||||
assertEquals("Title text", HSLFTextParagraph.getRawText(txt.get(0)));
|
||||
assertEquals(1, txt.get(0).size());
|
||||
rt = txt.get(0).get(0);
|
||||
assertFalse(rt.isBullet());
|
||||
|
||||
assertEquals(
|
||||
String expected =
|
||||
"This is a text placeholder that \r" +
|
||||
"follows the design pattern\r" +
|
||||
"Defined in the slide master\r" +
|
||||
"and has bullets by default", txt[1].getRawText());
|
||||
assertEquals(1, txt[1].getTextRuns().length);
|
||||
rt = txt[1].getTextRuns()[0];
|
||||
"and has bullets by default";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(1)));
|
||||
assertEquals(4, txt.get(1).size());
|
||||
rt = txt.get(1).get(0);
|
||||
assertEquals('\u2022', rt.getBulletChar());
|
||||
assertTrue(rt.isBullet());
|
||||
|
||||
|
||||
txt = slide[1].getTextParagraphs();
|
||||
assertEquals(2, txt.length);
|
||||
txt = slide.get(1).getTextParagraphs();
|
||||
assertEquals(2, txt.size());
|
||||
|
||||
assertEquals(
|
||||
expected =
|
||||
"I\u2019m a text box\r" +
|
||||
"With bullets\r" +
|
||||
"That follow the design pattern\r" +
|
||||
"From the slide master", txt[0].getRawText());
|
||||
assertEquals(1, txt[0].getTextRuns().length);
|
||||
rt = txt[0].getTextRuns()[0];
|
||||
"From the slide master";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(0)));
|
||||
assertEquals(4, txt.get(0).size());
|
||||
rt = txt.get(0).get(0);
|
||||
assertTrue(rt.isBullet());
|
||||
assertEquals('\u2022', rt.getBulletChar());
|
||||
|
||||
assertEquals(
|
||||
expected =
|
||||
"I\u2019m a text box with user-defined\r" +
|
||||
"bullet character", txt[1].getRawText());
|
||||
assertEquals(1, txt[1].getTextRuns().length);
|
||||
rt = txt[1].getTextRuns()[0];
|
||||
"bullet character";
|
||||
assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(1)));
|
||||
assertEquals(2, txt.get(1).size());
|
||||
rt = txt.get(1).get(0);
|
||||
assertTrue(rt.isBullet());
|
||||
assertEquals('\u263A', rt.getBulletChar());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetParagraphStyles() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||
|
||||
HSLFSlide slide = ppt.createSlide();
|
||||
|
||||
HSLFTextBox shape = new HSLFTextBox();
|
||||
HSLFTextRun rt = shape.getTextParagraphs().getTextRuns()[0];
|
||||
shape.setText(
|
||||
"Hello, World!\r" +
|
||||
"This should be\r" +
|
||||
"Multiline text");
|
||||
rt.setFontSize(42);
|
||||
HSLFTextParagraph rt = shape.getTextParagraphs().get(0);
|
||||
HSLFTextRun tr = rt.getTextRuns().get(0);
|
||||
tr.setFontSize(42);
|
||||
rt.setBullet(true);
|
||||
rt.setTextOffset(50);
|
||||
rt.setBulletOffset(0);
|
||||
rt.setLeftMargin(50);
|
||||
rt.setIndent(0);
|
||||
rt.setBulletChar('\u263A');
|
||||
slide.addShape(shape);
|
||||
|
||||
assertEquals(42, rt.getFontSize());
|
||||
assertEquals(42.0, tr.getFontSize(), 0);
|
||||
assertEquals(true, rt.isBullet());
|
||||
assertEquals(50, rt.getTextOffset());
|
||||
assertEquals(0, rt.getBulletOffset());
|
||||
assertEquals(50.0, rt.getLeftMargin(), 0);
|
||||
assertEquals(0, rt.getIndent(), 0);
|
||||
assertEquals('\u263A', rt.getBulletChar());
|
||||
|
||||
shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300));
|
||||
@ -545,57 +533,67 @@ if(false) {
|
||||
out.close();
|
||||
|
||||
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
|
||||
slide = ppt.getSlides()[0];
|
||||
shape = (HSLFTextBox)slide.getShapes()[0];
|
||||
rt = shape.getTextParagraphs().getTextRuns()[0];
|
||||
assertEquals(42, rt.getFontSize());
|
||||
slide = ppt.getSlides().get(0);
|
||||
shape = (HSLFTextBox)slide.getShapes().get(0);
|
||||
rt = shape.getTextParagraphs().get(0);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertEquals(42.0, tr.getFontSize(), 0);
|
||||
assertEquals(true, rt.isBullet());
|
||||
assertEquals(50, rt.getTextOffset());
|
||||
assertEquals(0, rt.getBulletOffset());
|
||||
assertEquals(50.0, rt.getLeftMargin(), 0);
|
||||
assertEquals(0, rt.getIndent(), 0);
|
||||
assertEquals('\u263A', rt.getBulletChar());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddText() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt"));
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
HSLFTextRun rt;
|
||||
HSLFTextParagraph[] txt;
|
||||
HSLFSlide[] slides = ppt.getSlides();
|
||||
HSLFTextParagraph rt;
|
||||
HSLFTextRun tr;
|
||||
List<List<HSLFTextParagraph>> txt;
|
||||
List<HSLFSlide> slides = ppt.getSlides();
|
||||
|
||||
assertEquals(2, slides.length);
|
||||
txt = slides[0].getTextParagraphs();
|
||||
assertEquals(2, txt.length);
|
||||
assertEquals(2, slides.size());
|
||||
txt = slides.get(0).getTextParagraphs();
|
||||
assertEquals(2, txt.size());
|
||||
|
||||
assertEquals("Title text", txt[0].getRawText());
|
||||
assertEquals(1, txt[0].getTextRuns().length);
|
||||
rt = txt[0].getTextRuns()[0];
|
||||
assertEquals("Title text", HSLFTextParagraph.getRawText(txt.get(0)));
|
||||
assertEquals(1, txt.get(0).size());
|
||||
rt = txt.get(0).get(0);
|
||||
assertFalse(rt.isBullet());
|
||||
|
||||
// Add some new text
|
||||
txt[0].appendText("Foo! I'm new!");
|
||||
assertEquals(2, txt[0].getTextRuns().length);
|
||||
HSLFTextParagraph.appendText(txt.get(0), "Foo! I'm new!", true);
|
||||
assertEquals(2, txt.get(0).size());
|
||||
|
||||
rt = txt[0].getTextRuns()[0];
|
||||
assertFalse(rt.isBold());
|
||||
assertEquals("Title text", rt.getRawText());
|
||||
rt = txt[0].getTextRuns()[1];
|
||||
assertFalse(rt.isBold());
|
||||
assertEquals("Foo! I'm new!", rt.getRawText());
|
||||
rt.setBold(true);
|
||||
rt = txt.get(0).get(0);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertFalse(tr.isBold());
|
||||
assertEquals("Title text\r", tr.getRawText());
|
||||
rt = txt.get(0).get(1);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertFalse(tr.isBold());
|
||||
assertEquals("Foo! I'm new!", tr.getRawText());
|
||||
tr.setBold(true);
|
||||
HSLFTextParagraph.storeText(txt.get(0));
|
||||
|
||||
// And some more
|
||||
txt[0].appendText("Me too!");
|
||||
assertEquals(3, txt[0].getTextRuns().length);
|
||||
rt = txt[0].getTextRuns()[0];
|
||||
assertFalse(rt.isBold());
|
||||
assertEquals("Title text", rt.getRawText());
|
||||
rt = txt[0].getTextRuns()[1];
|
||||
assertTrue(rt.isBold());
|
||||
assertEquals("Foo! I'm new!", rt.getRawText());
|
||||
rt = txt[0].getTextRuns()[2];
|
||||
assertFalse(rt.isBold());
|
||||
assertEquals("Me too!", rt.getRawText());
|
||||
// And some more, attributes will be copied from previous run
|
||||
HSLFTextParagraph.appendText(txt.get(0), "Me too!", true);
|
||||
HSLFTextParagraph.storeText(txt.get(0));
|
||||
assertEquals(3, txt.get(0).size());
|
||||
rt = txt.get(0).get(0);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertFalse(tr.isBold());
|
||||
assertEquals("Title text\r", tr.getRawText());
|
||||
rt = txt.get(0).get(1);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertTrue(tr.isBold());
|
||||
assertEquals("Foo! I'm new!\r", tr.getRawText());
|
||||
rt = txt.get(0).get(2);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertTrue(tr.isBold());
|
||||
assertEquals("Me too!", tr.getRawText());
|
||||
|
||||
// Save and re-open
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
@ -605,55 +603,59 @@ if(false) {
|
||||
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
|
||||
slides = ppt.getSlides();
|
||||
|
||||
assertEquals(2, slides.length);
|
||||
assertEquals(2, slides.size());
|
||||
|
||||
txt = slides[0].getTextParagraphs();
|
||||
assertEquals(2, txt.length);
|
||||
assertEquals(3, txt[0].getTextRuns().length);
|
||||
rt = txt[0].getTextRuns()[0];
|
||||
assertFalse(rt.isBold());
|
||||
assertEquals("Title text", rt.getRawText());
|
||||
rt = txt[0].getTextRuns()[1];
|
||||
assertTrue(rt.isBold());
|
||||
assertEquals("Foo! I'm new!", rt.getRawText());
|
||||
rt = txt[0].getTextRuns()[2];
|
||||
assertFalse(rt.isBold());
|
||||
assertEquals("Me too!", rt.getRawText());
|
||||
txt = slides.get(0).getTextParagraphs();
|
||||
assertEquals(2, txt.size());
|
||||
assertEquals(3, txt.get(0).size());
|
||||
rt = txt.get(0).get(0);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertFalse(tr.isBold());
|
||||
assertEquals("Title text\r", tr.getRawText());
|
||||
rt = txt.get(0).get(1);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertTrue(tr.isBold());
|
||||
assertEquals("Foo! I'm new!\r", tr.getRawText());
|
||||
rt = txt.get(0).get(2);
|
||||
tr = rt.getTextRuns().get(0);
|
||||
assertTrue(tr.isBold());
|
||||
assertEquals("Me too!", tr.getRawText());
|
||||
|
||||
// FileOutputStream fout = new FileOutputStream("/tmp/foo.ppt");
|
||||
// ppt.write(fout);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChineseParagraphs() throws Exception {
|
||||
HSLFTextRun[] rts;
|
||||
List<HSLFTextRun> rts;
|
||||
HSLFTextRun rt;
|
||||
HSLFTextParagraph[] txt;
|
||||
HSLFSlide[] slides = ssChinese.getSlides();
|
||||
List<List<HSLFTextParagraph>> txt;
|
||||
List<HSLFSlide> slides = ssChinese.getSlides();
|
||||
|
||||
// One slide
|
||||
assertEquals(1, slides.length);
|
||||
assertEquals(1, slides.size());
|
||||
|
||||
// One block of text within that
|
||||
txt = slides[0].getTextParagraphs();
|
||||
assertEquals(1, txt.length);
|
||||
txt = slides.get(0).getTextParagraphs();
|
||||
assertEquals(1, txt.size());
|
||||
|
||||
// One rich block of text in that - text is all the same style
|
||||
// TODO Is this completely correct?
|
||||
rts = txt[0].getTextRuns();
|
||||
assertEquals(1, rts.length);
|
||||
rt = rts[0];
|
||||
rts = txt.get(0).get(0).getTextRuns();
|
||||
assertEquals(1, rts.size());
|
||||
rt = rts.get(0);
|
||||
|
||||
// Check we can get the english text out of that
|
||||
String text = rt.getRawText();
|
||||
assertContains(text, "Single byte");
|
||||
// And the chinese
|
||||
assertContains(text, "\uff8a\uff9d\uff76\uff78");
|
||||
assertContains(txt.get(0).get(3).getTextRuns().get(0).getRawText(), "\uff8a\uff9d\uff76\uff78");
|
||||
|
||||
// It isn't bold or italic
|
||||
assertFalse(rt.isBold());
|
||||
assertFalse(rt.isItalic());
|
||||
|
||||
// Font is Calibri
|
||||
assertEquals("Calibri", rt.getFontName());
|
||||
assertEquals("Calibri", rt.getFontFamily());
|
||||
}
|
||||
}
|
||||
|
@ -17,44 +17,49 @@
|
||||
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hslf.*;
|
||||
import org.apache.poi.hslf.model.*;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests that SlideShow returns Sheets which have the right text in them
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public final class TestSheetText extends TestCase {
|
||||
public final class TestSheetText {
|
||||
// SlideShow primed on the test data
|
||||
private HSLFSlideShow ss;
|
||||
|
||||
public TestSheetText() throws Exception {
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
||||
ss = new HSLFSlideShow(hss);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSheetOne() {
|
||||
HSLFSheet slideOne = ss.getSlides()[0];
|
||||
HSLFSheet slideOne = ss.getSlides().get(0);
|
||||
|
||||
String[] expectText = new String[] {"This is a test title","This is a test subtitle\nThis is on page 1"};
|
||||
assertEquals(expectText.length, slideOne.getTextParagraphs().length);
|
||||
for(int i=0; i<expectText.length; i++) {
|
||||
assertEquals(expectText[i], slideOne.getTextParagraphs()[i].getRawText());
|
||||
String[] expectText = new String[] {"This is a test title","This is a test subtitle\rThis is on page 1"};
|
||||
assertEquals(expectText.length, slideOne.getTextParagraphs().size());
|
||||
int i = 0;
|
||||
for(List<HSLFTextParagraph> textParas : slideOne.getTextParagraphs()) {
|
||||
assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSheetTwo() {
|
||||
HSLFSheet slideTwo = ss.getSlides()[1];
|
||||
String[] expectText = new String[] {"This is the title on page 2","This is page two\nIt has several blocks of text\nNone of them have formatting"};
|
||||
assertEquals(expectText.length, slideTwo.getTextParagraphs().length);
|
||||
for(int i=0; i<expectText.length; i++) {
|
||||
assertEquals(expectText[i], slideTwo.getTextParagraphs()[i].getRawText());
|
||||
HSLFSheet slideTwo = ss.getSlides().get(1);
|
||||
String[] expectText = new String[] {"This is the title on page 2","This is page two\rIt has several blocks of text\rNone of them have formatting"};
|
||||
assertEquals(expectText.length, slideTwo.getTextParagraphs().size());
|
||||
int i = 0;
|
||||
for(List<HSLFTextParagraph> textParas : slideTwo.getTextParagraphs()) {
|
||||
assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas));
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,11 +74,11 @@ public final class TestSheetText extends TestCase {
|
||||
HSLFSlideShow sss = new HSLFSlideShow(hss);
|
||||
|
||||
// Should come out with 10 slides, no notes
|
||||
assertEquals(10, sss.getSlides().length);
|
||||
assertEquals(0, sss.getNotes().length);
|
||||
assertEquals(10, sss.getSlides().size());
|
||||
assertEquals(0, sss.getNotes().size());
|
||||
|
||||
// Check text on first slide
|
||||
HSLFSlide s = sss.getSlides()[0];
|
||||
HSLFSlide s = sss.getSlides().get(0);
|
||||
String exp =
|
||||
"Realizing the Development Dividend:\n" +
|
||||
"Community Capacity Building and CDM.\n" +
|
||||
@ -83,7 +88,7 @@ public final class TestSheetText extends TestCase {
|
||||
"COP 11 \u2013 MOP 1\n" + // special long hyphen
|
||||
"December 5, 2005\n";
|
||||
|
||||
assertEquals(1, s.getTextParagraphs().length);
|
||||
assertEquals(exp, s.getTextParagraphs()[0].getRawText());
|
||||
assertEquals(1, s.getTextParagraphs().size());
|
||||
assertEquals(exp, HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
|
||||
}
|
||||
}
|
||||
|
@ -17,18 +17,20 @@
|
||||
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hslf.*;
|
||||
import org.apache.poi.hslf.model.*;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests that SlideShow returns Sheets in the right order
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public final class TestSlideOrdering extends TestCase {
|
||||
public final class TestSlideOrdering {
|
||||
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
// Simple slideshow, record order matches slide order
|
||||
@ -36,7 +38,8 @@ public final class TestSlideOrdering extends TestCase {
|
||||
// Complex slideshow, record order doesn't match slide order
|
||||
private HSLFSlideShow ssB;
|
||||
|
||||
public TestSlideOrdering() throws Exception {
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
HSLFSlideShowImpl hssA = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
||||
ssA = new HSLFSlideShow(hssA);
|
||||
|
||||
@ -47,33 +50,29 @@ public final class TestSlideOrdering extends TestCase {
|
||||
/**
|
||||
* Test the simple case - record order matches slide order
|
||||
*/
|
||||
@Test
|
||||
public void testSimpleCase() {
|
||||
assertEquals(2, ssA.getSlides().length);
|
||||
assertEquals(2, ssA.getSlides().size());
|
||||
|
||||
HSLFSlide s1 = ssA.getSlides()[0];
|
||||
HSLFSlide s2 = ssA.getSlides()[1];
|
||||
HSLFSlide s1 = ssA.getSlides().get(0);
|
||||
HSLFSlide s2 = ssA.getSlides().get(1);
|
||||
|
||||
String[] firstTRs = new String[] { "This is a test title", "This is the title on page 2" };
|
||||
|
||||
assertEquals(firstTRs[0], s1.getTextParagraphs()[0].getRawText());
|
||||
assertEquals(firstTRs[1], s2.getTextParagraphs()[0].getRawText());
|
||||
assertEquals(firstTRs[0], HSLFTextParagraph.getRawText(s1.getTextParagraphs().get(0)));
|
||||
assertEquals(firstTRs[1], HSLFTextParagraph.getRawText(s2.getTextParagraphs().get(0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the complex case - record order differs from slide order
|
||||
*/
|
||||
@Test
|
||||
public void testComplexCase() {
|
||||
assertEquals(3, ssB.getSlides().length);
|
||||
|
||||
HSLFSlide s1 = ssB.getSlides()[0];
|
||||
HSLFSlide s2 = ssB.getSlides()[1];
|
||||
HSLFSlide s3 = ssB.getSlides()[2];
|
||||
|
||||
String[] firstTRs = new String[] { "Slide 1", "Slide 2", "Slide 3" };
|
||||
|
||||
assertEquals(firstTRs[0], s1.getTextParagraphs()[0].getRawText());
|
||||
assertEquals(firstTRs[1], s2.getTextParagraphs()[0].getRawText());
|
||||
assertEquals(firstTRs[2], s3.getTextParagraphs()[0].getRawText());
|
||||
assertEquals(3, ssB.getSlides().size());
|
||||
int i=1;
|
||||
for (HSLFSlide s : ssB.getSlides()) {
|
||||
assertEquals("Slide "+(i++), HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,15 +87,16 @@ public final class TestSlideOrdering extends TestCase {
|
||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream(filename));
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
List<HSLFSlide> slide = ppt.getSlides();
|
||||
|
||||
assertEquals(titles.length, slide.length);
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
String title = slide[i].getTitle();
|
||||
assertEquals(titles.length, slide.size());
|
||||
for (int i = 0; i < slide.size(); i++) {
|
||||
String title = slide.get(i).getTitle();
|
||||
assertEquals("Wrong slide title in " + filename, titles[i], title);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitles() throws Exception {
|
||||
assertSlideOrdering("basic_test_ppt_file.ppt", new String[] {
|
||||
"This is a test title", "This is the title on page 2" });
|
||||
|
@ -19,15 +19,11 @@ package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.model.Table;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||
import org.apache.poi.hslf.record.*;
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -59,28 +55,28 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testGetText() {
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textParas = slideOne.getTextParagraphs();
|
||||
List<List<HSLFTextParagraph>> textParas = slideOne.getTextParagraphs();
|
||||
|
||||
assertEquals(2, textParas.size());
|
||||
|
||||
// Get text works with \n
|
||||
assertEquals("This is a test title", textParas.get(0).getTextRuns().get(0).getRawText());
|
||||
assertEquals("This is a test subtitle\nThis is on page 1", textParas.get(1).getTextRuns().get(0).getRawText());
|
||||
assertEquals("This is a test title", HSLFTextParagraph.getText(textParas.get(0)));
|
||||
assertEquals("This is a test subtitle\nThis is on page 1", HSLFTextParagraph.getText(textParas.get(1)));
|
||||
|
||||
// Raw text has \r instead
|
||||
assertEquals("This is a test title", textParas.get(0).getTextRuns().get(0).getRawText());
|
||||
assertEquals("This is a test subtitle\rThis is on page 1", textParas.get(1).getTextRuns().get(0).getRawText());
|
||||
assertEquals("This is a test title", HSLFTextParagraph.getRawText(textParas.get(0)));
|
||||
assertEquals("This is a test subtitle\rThis is on page 1", HSLFTextParagraph.getRawText(textParas.get(1)));
|
||||
|
||||
|
||||
// Now check on a rich text run
|
||||
HSLFSlide slideOneR = ssRich.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRunsR = slideOneR.getTextParagraphs();
|
||||
textParas = slideOneR.getTextParagraphs();
|
||||
|
||||
assertEquals(2, textRunsR.size());
|
||||
assertEquals("This is a title, it\u2019s in black", textRunsR.get(0).getTextRuns().get(0).getRawText());
|
||||
assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", textRunsR.get(1).getTextRuns().get(0).getRawText());
|
||||
assertEquals("This is a title, it\u2019s in black", textRunsR.get(0).getTextRuns().get(0).getRawText());
|
||||
assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", textRunsR.get(1).getTextRuns().get(0).getRawText());
|
||||
assertEquals(2, textParas.size());
|
||||
assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getText(textParas.get(0)));
|
||||
assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", HSLFTextParagraph.getText(textParas.get(1)));
|
||||
assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getRawText(textParas.get(0)));
|
||||
assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", HSLFTextParagraph.getRawText(textParas.get(1)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,8 +85,8 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testSetText() {
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextParagraph run = textRuns.get(0);
|
||||
List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextParagraph run = textRuns.get(0).get(0);
|
||||
HSLFTextRun tr = run.getTextRuns().get(0);
|
||||
|
||||
// Check current text
|
||||
@ -110,10 +106,11 @@ public final class TestTextRun {
|
||||
* Test to ensure that changing non rich text between bytes and
|
||||
* chars works correctly
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void testAdvancedSetText() {
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<HSLFTextParagraph> paras = slideOne.getTextParagraphs();
|
||||
List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0);
|
||||
HSLFTextParagraph para = paras.get(0);
|
||||
|
||||
TextHeaderAtom tha = null;
|
||||
@ -192,21 +189,21 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testGetRichTextNonRich() {
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
|
||||
assertEquals(2, textRuns.size());
|
||||
assertEquals(2, textParass.size());
|
||||
|
||||
HSLFTextParagraph trA = textRuns.get(0);
|
||||
HSLFTextParagraph trB = textRuns.get(1);
|
||||
List<HSLFTextParagraph> trA = textParass.get(0);
|
||||
List<HSLFTextParagraph> trB = textParass.get(1);
|
||||
|
||||
assertEquals(1, trA.getTextRuns().size());
|
||||
assertEquals(1, trB.getTextRuns().size());
|
||||
assertEquals(1, trA.size());
|
||||
assertEquals(1, trB.size());
|
||||
|
||||
HSLFTextRun rtrA = trA.getTextRuns().get(0);
|
||||
HSLFTextRun rtrB = trB.getTextRuns().get(0);
|
||||
HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
|
||||
HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
|
||||
|
||||
assertEquals(HSLFTextParagraph.getRawText(textRuns.subList(0, 0)), rtrA.getRawText());
|
||||
assertEquals(HSLFTextParagraph.getRawText(textRuns.subList(1, 1)), rtrB.getRawText());
|
||||
assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
|
||||
assertEquals(HSLFTextParagraph.getRawText(trB), rtrB.getRawText());
|
||||
|
||||
// assertNull(rtrA._getRawCharacterStyle());
|
||||
// assertNull(rtrA._getRawParagraphStyle());
|
||||
@ -220,45 +217,36 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testGetRichText() {
|
||||
HSLFSlide slideOne = ssRich.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
|
||||
assertEquals(2, textRuns.size());
|
||||
assertEquals(2, textParass.size());
|
||||
|
||||
HSLFTextParagraph trA = textRuns.get(0);
|
||||
HSLFTextParagraph trB = textRuns.get(1);
|
||||
List<HSLFTextParagraph> trA = textParass.get(0);
|
||||
List<HSLFTextParagraph> trB = textParass.get(1);
|
||||
|
||||
assertEquals(1, trA.getTextRuns().size());
|
||||
assertEquals(3, trB.getTextRuns().size());
|
||||
assertEquals(1, trA.size());
|
||||
assertEquals(3, trB.size());
|
||||
|
||||
HSLFTextRun rtrA = trA.getTextRuns().get(0);
|
||||
HSLFTextRun rtrB = trB.getTextRuns().get(0);
|
||||
HSLFTextRun rtrC = trB.getTextRuns().get(1);
|
||||
HSLFTextRun rtrD = trB.getTextRuns().get(2);
|
||||
HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
|
||||
HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
|
||||
HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
|
||||
HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
|
||||
|
||||
assertEquals(HSLFTextParagraph.getRawText(textRuns.subList(0, 0)), rtrA.getRawText());
|
||||
assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
|
||||
|
||||
String trBstr = HSLFTextParagraph.getRawText(textRuns.subList(1, 1));
|
||||
String trBstr = HSLFTextParagraph.getRawText(trB);
|
||||
assertEquals(trBstr.substring(0, 30), rtrB.getRawText());
|
||||
assertEquals(trBstr.substring(30,58), rtrC.getRawText());
|
||||
assertEquals(trBstr.substring(58,82), rtrD.getRawText());
|
||||
|
||||
// assertNull(rtrA._getRawCharacterStyle());
|
||||
// assertNull(rtrA._getRawParagraphStyle());
|
||||
// assertNotNull(rtrB._getRawCharacterStyle());
|
||||
// assertNotNull(rtrB._getRawParagraphStyle());
|
||||
// assertNotNull(rtrC._getRawCharacterStyle());
|
||||
// assertNotNull(rtrC._getRawParagraphStyle());
|
||||
// assertNotNull(rtrD._getRawCharacterStyle());
|
||||
// assertNotNull(rtrD._getRawParagraphStyle());
|
||||
|
||||
// Same paragraph styles
|
||||
// assertEquals(rtrB._getRawParagraphStyle(), rtrC._getRawParagraphStyle());
|
||||
// assertEquals(rtrB._getRawParagraphStyle(), rtrD._getRawParagraphStyle());
|
||||
assertEquals(trB.get(0).getParagraphStyle(), trB.get(1).getParagraphStyle());
|
||||
assertEquals(trB.get(0).getParagraphStyle(), trB.get(2).getParagraphStyle());
|
||||
|
||||
// Different char styles
|
||||
// assertFalse( rtrB._getRawCharacterStyle().equals( rtrC._getRawCharacterStyle() ));
|
||||
// assertFalse( rtrB._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
|
||||
// assertFalse( rtrC._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
|
||||
assertNotEquals(rtrB.getCharacterStyle(), rtrC.getCharacterStyle());
|
||||
assertNotEquals(rtrB.getCharacterStyle(), rtrD.getCharacterStyle());
|
||||
assertNotEquals(rtrC.getCharacterStyle(), rtrD.getCharacterStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,22 +256,18 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testSetTextWhereNotRich() {
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextParagraph trB = textRuns.get(1);
|
||||
// assertEquals(1, trB.getTextRuns().length);
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
List<HSLFTextParagraph> trB = textParass.get(0);
|
||||
assertEquals(1, trB.size());
|
||||
|
||||
HSLFTextRun rtrB = trB.getTextRuns().get(0);
|
||||
// assertEquals(trB.getRawText(), rtrB.getRawText());
|
||||
// assertNull(rtrB._getRawCharacterStyle());
|
||||
// assertNull(rtrB._getRawParagraphStyle());
|
||||
HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
|
||||
assertEquals(HSLFTextParagraph.getText(trB), rtrB.getRawText());
|
||||
|
||||
// Change text via normal
|
||||
// trB.setText("Test Foo Test");
|
||||
rtrB = trB.getTextRuns().get(0);
|
||||
// assertEquals("Test Foo Test", trB.getRawText());
|
||||
// assertEquals("Test Foo Test", rtrB.getRawText());
|
||||
// assertNull(rtrB._getRawCharacterStyle());
|
||||
// assertNull(rtrB._getRawParagraphStyle());
|
||||
HSLFTextParagraph.setText(trB, "Test Foo Test");
|
||||
rtrB = trB.get(0).getTextRuns().get(0);
|
||||
assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
|
||||
assertEquals("Test Foo Test", rtrB.getRawText());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,13 +277,13 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testSetTextWhereRich() {
|
||||
HSLFSlide slideOne = ssRich.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextParagraph trB = textRuns.get(1);
|
||||
assertEquals(3, trB.getTextRuns().size());
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
List<HSLFTextParagraph> trB = textParass.get(1);
|
||||
assertEquals(3, trB.size());
|
||||
|
||||
HSLFTextRun rtrB = trB.getTextRuns().get(0);
|
||||
HSLFTextRun rtrC = trB.getTextRuns().get(1);
|
||||
HSLFTextRun rtrD = trB.getTextRuns().get(2);
|
||||
HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
|
||||
HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
|
||||
HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
|
||||
// TextPropCollection tpBP = rtrB._getRawParagraphStyle();
|
||||
// TextPropCollection tpBC = rtrB._getRawCharacterStyle();
|
||||
// TextPropCollection tpCP = rtrC._getRawParagraphStyle();
|
||||
@ -342,8 +326,8 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testChangeTextInRichTextRunNonRich() {
|
||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextParagraph trB = textRuns.get(1);
|
||||
List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
|
||||
List<HSLFTextParagraph> trB = textRuns.get(1);
|
||||
// assertEquals(1, trB.getTextRuns().length);
|
||||
//
|
||||
// HSLFTextRun rtrB = trB.getTextRuns().get(0);
|
||||
@ -368,15 +352,15 @@ public final class TestTextRun {
|
||||
@Test
|
||||
public void testChangeTextInRichTextRun() {
|
||||
HSLFSlide slideOne = ssRich.getSlides().get(0);
|
||||
List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
|
||||
HSLFTextParagraph trB = textRuns.get(1);
|
||||
assertEquals(3, trB.getTextRuns().size());
|
||||
List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
|
||||
List<HSLFTextParagraph> trB = textParass.get(1);
|
||||
assertEquals(3, trB.size());
|
||||
|
||||
// We start with 3 text runs, each with their own set of styles,
|
||||
// but all sharing the same paragraph styles
|
||||
HSLFTextRun rtrB = trB.getTextRuns().get(0);
|
||||
HSLFTextRun rtrC = trB.getTextRuns().get(1);
|
||||
HSLFTextRun rtrD = trB.getTextRuns().get(2);
|
||||
HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
|
||||
HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
|
||||
HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
|
||||
// TextPropCollection tpBP = rtrB._getRawParagraphStyle();
|
||||
// TextPropCollection tpBC = rtrB._getRawCharacterStyle();
|
||||
// TextPropCollection tpCP = rtrC._getRawParagraphStyle();
|
||||
@ -400,8 +384,8 @@ public final class TestTextRun {
|
||||
// assertFalse(tpCC.equals(tpDC));
|
||||
|
||||
// Check text in the rich runs
|
||||
assertEquals("This is the subtitle, in bold\n", rtrB.getRawText());
|
||||
assertEquals("This bit is blue and italic\n", rtrC.getRawText());
|
||||
assertEquals("This is the subtitle, in bold\r", rtrB.getRawText());
|
||||
assertEquals("This bit is blue and italic\r", rtrC.getRawText());
|
||||
assertEquals("This bit is red (normal)", rtrD.getRawText());
|
||||
|
||||
String newBText = "New Subtitle, will still be bold\n";
|
||||
@ -452,23 +436,24 @@ public final class TestTextRun {
|
||||
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug-41015.ppt"));
|
||||
HSLFSlide sl = ppt.getSlides().get(0);
|
||||
List<HSLFTextParagraph> txt = sl.getTextParagraphs();
|
||||
assertEquals(2, txt.size());
|
||||
List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
|
||||
assertEquals(2, textParass.size());
|
||||
|
||||
rt = txt.get(0).getTextRuns();
|
||||
List<HSLFTextParagraph> textParas = textParass.get(0);
|
||||
rt = textParass.get(0).get(0).getTextRuns();
|
||||
assertEquals(1, rt.size());
|
||||
assertEquals(0, txt.get(0).getIndentLevel());
|
||||
assertEquals(0, textParass.get(0).get(0).getIndentLevel());
|
||||
assertEquals("sdfsdfsdf", rt.get(0).getRawText());
|
||||
|
||||
rt = txt.get(1).getTextRuns();
|
||||
assertEquals(2, rt.size());
|
||||
assertEquals(0, txt.get(0).getIndentLevel());
|
||||
assertEquals("Sdfsdfsdf\n" +
|
||||
"Dfgdfg\n" +
|
||||
"Dfgdfgdfg\n", rt.get(0).getRawText());
|
||||
assertEquals(1, txt.get(1).getIndentLevel());
|
||||
assertEquals("Sdfsdfs\n" +
|
||||
"Sdfsdf\n", rt.get(1).getRawText());
|
||||
textParas = textParass.get(1);
|
||||
String texts[] = {"Sdfsdfsdf\r","Dfgdfg\r","Dfgdfgdfg\r","Sdfsdfs\r","Sdfsdf\r"};
|
||||
int indents[] = {0,0,0,1,1};
|
||||
int i=0;
|
||||
for (HSLFTextParagraph p : textParas) {
|
||||
assertEquals(texts[i], p.getTextRuns().get(0).getRawText());
|
||||
assertEquals(indents[i], p.getIndentLevel());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -479,7 +464,7 @@ public final class TestTextRun {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||
HSLFSlide slide = ppt.createSlide();
|
||||
|
||||
assertNull(slide.getTextParagraphs());
|
||||
assertEquals(0, slide.getTextParagraphs().size());
|
||||
|
||||
HSLFTextBox shape1 = new HSLFTextBox();
|
||||
// HSLFTextParagraph run1 = shape1.getTextParagraphs();
|
||||
@ -565,17 +550,14 @@ public final class TestTextRun {
|
||||
public void test52244() throws IOException {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52244.ppt"));
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
List<HSLFTextParagraph> runs = slide.getTextParagraphs();
|
||||
|
||||
assertEquals("Arial", runs.get(0).getTextRuns().get(0).getFontFamily());
|
||||
assertEquals(36, runs.get(0).getTextRuns().get(0).getFontSize(), 0);
|
||||
|
||||
assertEquals("Arial", runs.get(1).getTextRuns().get(0).getFontFamily());
|
||||
assertEquals(24, runs.get(1).getTextRuns().get(0).getFontSize(), 0);
|
||||
|
||||
assertEquals("Arial", runs.get(2).getTextRuns().get(0).getFontFamily());
|
||||
assertEquals(32, runs.get(2).getTextRuns().get(0).getFontSize(), 0);
|
||||
int sizes[] = { 36, 24, 12, 32, 12, 12 };
|
||||
|
||||
int i=0;
|
||||
for (List<HSLFTextParagraph> textParas : slide.getTextParagraphs()) {
|
||||
assertEquals("Arial", textParas.get(0).getTextRuns().get(0).getFontFamily());
|
||||
assertEquals(sizes[i++], (int)textParas.get(0).getTextRuns().get(0).getFontSize());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,26 +15,15 @@
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.hslf.model;
|
||||
package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.record.TextHeaderAtom;
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
import org.apache.poi.sl.usermodel.ShapeType;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -49,28 +38,21 @@ public final class TestTextShape {
|
||||
@Test
|
||||
public void createAutoShape(){
|
||||
HSLFTextShape shape = new HSLFAutoShape(ShapeType.TRAPEZOID);
|
||||
assertNull(shape.getTextParagraphs());
|
||||
assertNull(shape.getText());
|
||||
assertNull(shape.getEscherTextboxWrapper());
|
||||
|
||||
HSLFTextParagraph run = shape.createTextRun();
|
||||
assertNotNull(run);
|
||||
assertNotNull(shape.getTextParagraphs());
|
||||
assertNotNull(shape.getEscherTextboxWrapper());
|
||||
assertEquals("", shape.getText());
|
||||
assertSame(run, shape.createTextRun());
|
||||
assertEquals(-1, run.getIndex());
|
||||
assertEquals(-1, shape.getTextParagraphs().get(0).getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTextBox(){
|
||||
HSLFTextShape shape = new HSLFTextBox();
|
||||
HSLFTextParagraph run = shape.getTextParagraphs();
|
||||
assertNotNull(run);
|
||||
List<HSLFTextParagraph> paras = shape.getTextParagraphs();
|
||||
assertNotNull(paras);
|
||||
assertNotNull(shape.getText());
|
||||
assertNotNull(shape.getEscherTextboxWrapper());
|
||||
|
||||
assertSame(run, shape.createTextRun());
|
||||
assertNotNull(shape.getTextParagraphs());
|
||||
assertNotNull(shape.getEscherTextboxWrapper());
|
||||
assertEquals("", shape.getText());
|
||||
@ -88,46 +70,45 @@ public final class TestTextShape {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text_shapes.ppt"));
|
||||
|
||||
List<String> lst1 = new ArrayList<String>();
|
||||
HSLFSlide slide = ppt.getSlides()[0];
|
||||
HSLFShape[] shape = slide.getShapes();
|
||||
for (int i = 0; i < shape.length; i++) {
|
||||
assertTrue("Expected TextShape but found " + shape[i].getClass().getName(), shape[i] instanceof HSLFTextShape);
|
||||
HSLFTextShape tx = (HSLFTextShape)shape[i];
|
||||
HSLFTextParagraph run = tx.getTextParagraphs();
|
||||
assertNotNull(run);
|
||||
int runType = run.getRunType();
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
for (HSLFShape shape : slide.getShapes()) {
|
||||
assertTrue("Expected TextShape but found " + shape.getClass().getName(), shape instanceof HSLFTextShape);
|
||||
HSLFTextShape tx = (HSLFTextShape)shape;
|
||||
List<HSLFTextParagraph> paras = tx.getTextParagraphs();
|
||||
assertNotNull(paras);
|
||||
int runType = paras.get(0).getRunType();
|
||||
|
||||
ShapeType type = shape[i].getShapeType();
|
||||
ShapeType type = shape.getShapeType();
|
||||
String rawText = HSLFTextParagraph.getRawText(paras);
|
||||
switch (type){
|
||||
case TEXT_BOX:
|
||||
assertEquals("Text in a TextBox", run.getRawText());
|
||||
assertEquals("Text in a TextBox", rawText);
|
||||
break;
|
||||
case RECT:
|
||||
if(runType == TextHeaderAtom.OTHER_TYPE)
|
||||
assertEquals("Rectangle", run.getRawText());
|
||||
assertEquals("Rectangle", rawText);
|
||||
else if(runType == TextHeaderAtom.TITLE_TYPE)
|
||||
assertEquals("Title Placeholder", run.getRawText());
|
||||
assertEquals("Title Placeholder", rawText);
|
||||
break;
|
||||
case OCTAGON:
|
||||
assertEquals("Octagon", run.getRawText());
|
||||
assertEquals("Octagon", rawText);
|
||||
break;
|
||||
case ELLIPSE:
|
||||
assertEquals("Ellipse", run.getRawText());
|
||||
assertEquals("Ellipse", rawText);
|
||||
break;
|
||||
case ROUND_RECT:
|
||||
assertEquals("RoundRectangle", run.getRawText());
|
||||
assertEquals("RoundRectangle", rawText);
|
||||
break;
|
||||
default:
|
||||
fail("Unexpected shape: " + shape[i].getShapeName());
|
||||
fail("Unexpected shape: " + shape.getShapeName());
|
||||
|
||||
}
|
||||
lst1.add(run.getRawText());
|
||||
lst1.add(rawText);
|
||||
}
|
||||
|
||||
List<String> lst2 = new ArrayList<String>();
|
||||
HSLFTextParagraph[] run = slide.getTextParagraphs();
|
||||
for (int i = 0; i < run.length; i++) {
|
||||
lst2.add(run[i].getRawText());
|
||||
for (List<HSLFTextParagraph> paras : slide.getTextParagraphs()) {
|
||||
lst2.add(HSLFTextParagraph.getRawText(paras));
|
||||
}
|
||||
|
||||
assertTrue(lst1.containsAll(lst2));
|
||||
@ -139,15 +120,13 @@ public final class TestTextShape {
|
||||
HSLFSlide slide = ppt.createSlide();
|
||||
|
||||
HSLFTextShape shape1 = new HSLFTextBox();
|
||||
HSLFTextParagraph run1 = shape1.createTextRun();
|
||||
run1.setText("Hello, World!");
|
||||
shape1.setText("Hello, World!");
|
||||
slide.addShape(shape1);
|
||||
|
||||
shape1.moveTo(100, 100);
|
||||
|
||||
HSLFTextShape shape2 = new HSLFAutoShape(ShapeType.RIGHT_ARROW);
|
||||
HSLFTextParagraph run2 = shape2.createTextRun();
|
||||
run2.setText("Testing TextShape");
|
||||
shape2.setText("Testing TextShape");
|
||||
slide.addShape(shape2);
|
||||
shape2.moveTo(300, 300);
|
||||
|
||||
@ -156,31 +135,30 @@ public final class TestTextShape {
|
||||
out.close();
|
||||
|
||||
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
|
||||
slide = ppt.getSlides()[0];
|
||||
HSLFShape[] shape = slide.getShapes();
|
||||
slide = ppt.getSlides().get(0);
|
||||
List<HSLFShape> shape = slide.getShapes();
|
||||
|
||||
assertTrue(shape[0] instanceof HSLFTextShape);
|
||||
shape1 = (HSLFTextShape)shape[0];
|
||||
assertTrue(shape.get(0) instanceof HSLFTextShape);
|
||||
shape1 = (HSLFTextShape)shape.get(0);
|
||||
assertEquals(ShapeType.TEXT_BOX, shape1.getShapeType());
|
||||
assertEquals("Hello, World!", shape1.getTextParagraphs().getRawText());
|
||||
assertEquals("Hello, World!", shape1.getText());
|
||||
|
||||
assertTrue(shape[1] instanceof HSLFTextShape);
|
||||
shape1 = (HSLFTextShape)shape[1];
|
||||
assertTrue(shape.get(1) instanceof HSLFTextShape);
|
||||
shape1 = (HSLFTextShape)shape.get(1);
|
||||
assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType());
|
||||
assertEquals("Testing TextShape", shape1.getTextParagraphs().getRawText());
|
||||
assertEquals("Testing TextShape", shape1.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void margins() throws IOException {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text-margins.ppt"));
|
||||
|
||||
HSLFSlide slide = ppt.getSlides()[0];
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
|
||||
Map<String,HSLFTextShape> map = new HashMap<String,HSLFTextShape>();
|
||||
HSLFShape[] shape = slide.getShapes();
|
||||
for (int i = 0; i < shape.length; i++) {
|
||||
if(shape[i] instanceof HSLFTextShape){
|
||||
HSLFTextShape tx = (HSLFTextShape)shape[i];
|
||||
for (HSLFShape shape : slide.getShapes()) {
|
||||
if(shape instanceof HSLFTextShape){
|
||||
HSLFTextShape tx = (HSLFTextShape)shape;
|
||||
map.put(tx.getText(), tx);
|
||||
}
|
||||
}
|
||||
@ -216,20 +194,20 @@ public final class TestTextShape {
|
||||
public void bug52599() throws IOException {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52599.ppt"));
|
||||
|
||||
HSLFSlide slide = ppt.getSlides()[0];
|
||||
HSLFShape[] sh = slide.getShapes();
|
||||
assertEquals(3, sh.length);
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
List<HSLFShape> sh = slide.getShapes();
|
||||
assertEquals(3, sh.size());
|
||||
|
||||
HSLFTextShape sh0 = (HSLFTextShape)sh[0];
|
||||
assertEquals(null, sh0.getText());
|
||||
assertEquals(null, sh0.getTextParagraphs());
|
||||
HSLFTextShape sh0 = (HSLFTextShape)sh.get(0);
|
||||
assertNotNull(sh0.getTextParagraphs());
|
||||
assertEquals("", sh0.getText());
|
||||
|
||||
HSLFTextShape sh1 = (HSLFTextShape)sh[1];
|
||||
assertEquals(null, sh1.getText());
|
||||
assertEquals(null, sh1.getTextParagraphs());
|
||||
HSLFTextShape sh1 = (HSLFTextShape)sh.get(1);
|
||||
assertNotNull(sh1.getTextParagraphs());
|
||||
assertEquals("", sh1.getText());
|
||||
|
||||
HSLFTextShape sh2 = (HSLFTextShape)sh[2];
|
||||
HSLFTextShape sh2 = (HSLFTextShape)sh.get(2);
|
||||
assertEquals("this box should be shown just once", sh2.getText());
|
||||
assertEquals(-1, sh2.getTextParagraphs().getIndex());
|
||||
assertEquals(-1, sh2.getTextParagraphs().get(0).getIndex());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user