use of org.apache.poi.hslf.record.StyleTextProp9Atom in project poi by apache.
the class HSLFTextParagraph method findTextParagraphs.
/**
* Scans through the supplied record array, looking for
* a TextHeaderAtom followed by one of a TextBytesAtom or
* a TextCharsAtom. Builds up TextRuns from these
*
* @param wrapper an EscherTextboxWrapper
*/
protected static List<HSLFTextParagraph> findTextParagraphs(EscherTextboxWrapper wrapper, HSLFSheet sheet) {
// propagate parents to parent-aware records
RecordContainer.handleParentAwareRecords(wrapper);
int shapeId = wrapper.getShapeId();
List<HSLFTextParagraph> rv = null;
OutlineTextRefAtom ota = (OutlineTextRefAtom) wrapper.findFirstOfType(OutlineTextRefAtom.typeID);
if (ota != null) {
// if we are based on an outline, there are no further records to be parsed from the wrapper
if (sheet == null) {
throw new HSLFException("Outline atom reference can't be solved without a sheet record");
}
List<List<HSLFTextParagraph>> sheetRuns = sheet.getTextParagraphs();
assert (sheetRuns != null);
int idx = ota.getTextIndex();
for (List<HSLFTextParagraph> r : sheetRuns) {
if (r.isEmpty()) {
continue;
}
int ridx = r.get(0).getIndex();
if (ridx > idx) {
break;
}
if (ridx == idx) {
if (rv == null) {
rv = r;
} else {
// create a new container
// TODO: ... is this case really happening?
rv = new ArrayList<HSLFTextParagraph>(rv);
rv.addAll(r);
}
}
}
if (rv == null || rv.isEmpty()) {
logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
}
} else {
if (sheet != null) {
// check sheet runs first, so we get exactly the same paragraph list
List<List<HSLFTextParagraph>> sheetRuns = sheet.getTextParagraphs();
assert (sheetRuns != null);
for (List<HSLFTextParagraph> paras : sheetRuns) {
if (!paras.isEmpty() && paras.get(0)._headerAtom.getParentRecord() == wrapper) {
rv = paras;
break;
}
}
}
if (rv == null) {
// if we haven't found the wrapper in the sheet runs, create a new paragraph list from its record
List<List<HSLFTextParagraph>> rvl = findTextParagraphs(wrapper.getChildRecords());
switch(rvl.size()) {
// nothing found
case 0:
break;
// normal case
case 1:
rv = rvl.get(0);
break;
default:
throw new HSLFException("TextBox contains more than one list of paragraphs.");
}
}
}
if (rv != null) {
StyleTextProp9Atom styleTextProp9Atom = wrapper.getStyleTextProp9Atom();
for (HSLFTextParagraph htp : rv) {
htp.setShapeId(shapeId);
htp.setStyleTextProp9Atom(styleTextProp9Atom);
}
}
return rv;
}
use of org.apache.poi.hslf.record.StyleTextProp9Atom in project poi by apache.
the class TestNumberedList2 method checkSlide0.
private void checkSlide0(final HSLFSlide s) {
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
assertNotNull(numberedListArray);
assertEquals(2, numberedListArray.length);
final StyleTextProp9Atom numberedListInfoForTextBox0 = numberedListArray[0];
final StyleTextProp9Atom numberedListInfoForTextBox1 = numberedListArray[1];
assertNotNull(numberedListInfoForTextBox0);
assertNotNull(numberedListInfoForTextBox1);
final TextPFException9[] autoNumbersOfTextBox0 = numberedListInfoForTextBox0.getAutoNumberTypes();
assertEquals(Short.valueOf((short) 1), autoNumbersOfTextBox0[0].getfBulletHasAutoNumber());
//Default value = 1 will be used
assertEquals(Short.valueOf((short) 1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());
assertTrue(AutoNumberingScheme.arabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
final TextPFException9[] autoNumbersOfTextBox1 = numberedListInfoForTextBox1.getAutoNumberTypes();
assertEquals(Short.valueOf((short) 1), autoNumbersOfTextBox1[0].getfBulletHasAutoNumber());
//Default value = 1 will be used
assertEquals(Short.valueOf((short) 6), autoNumbersOfTextBox1[0].getAutoNumberStartNumber());
assertTrue(AutoNumberingScheme.arabicPeriod == autoNumbersOfTextBox1[0].getAutoNumberScheme());
List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
assertEquals(2, textParass.size());
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());
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(textParass.size(), styleAtoms.length);
checkSingleRunWrapper(44, styleAtoms[0]);
checkSingleRunWrapper(130, styleAtoms[1]);
}
use of org.apache.poi.hslf.record.StyleTextProp9Atom in project poi by apache.
the class TestNumberedList2 method checkSlide1.
private void checkSlide1(final HSLFSlide s) {
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
assertNotNull(numberedListArray);
assertEquals(1, numberedListArray.length);
final StyleTextProp9Atom numberedListInfoForTextBox = numberedListArray[0];
assertNotNull(numberedListInfoForTextBox);
final TextPFException9[] autoNumbersOfTextBox = numberedListInfoForTextBox.getAutoNumberTypes();
assertEquals(Short.valueOf((short) 1), autoNumbersOfTextBox[0].getfBulletHasAutoNumber());
//Default value = 1 will be used
assertEquals(Short.valueOf((short) 1), autoNumbersOfTextBox[0].getAutoNumberStartNumber());
assertTrue(AutoNumberingScheme.arabicPeriod == autoNumbersOfTextBox[0].getAutoNumberScheme());
List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
assertEquals(3, textParass.size());
List<HSLFTextParagraph> textParas = textParass.get(0);
assertEquals("Bulleted list\rMore bullets", HSLFTextParagraph.getRawText(textParas));
assertEquals(2, textParas.size());
assertTrue(textParas.get(0).isBullet());
String expected = "Numbered list between two bulleted lists\rSecond numbered list item";
assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
expected = "Second bulleted list – should appear after numbered list\rMore bullets";
assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(2)));
final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
assertEquals(textParass.size(), styleAtoms.length);
checkSingleRunWrapper(27, styleAtoms[0]);
checkSingleRunWrapper(67, styleAtoms[1]);
checkSingleRunWrapper(70, styleAtoms[2]);
}
use of org.apache.poi.hslf.record.StyleTextProp9Atom in project poi by apache.
the class TestNumberedList3 method checkSlide.
private void checkSlide(final HSLFSlide s) {
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
assertNotNull(numberedListArray);
assertEquals(1, numberedListArray.length);
final StyleTextProp9Atom numberedListInfoForTextBox = numberedListArray[0];
assertNotNull(numberedListInfoForTextBox);
final TextPFException9[] autoNumbersOfTextBox0 = numberedListInfoForTextBox.getAutoNumberTypes();
assertEquals(Short.valueOf((short) 1), autoNumbersOfTextBox0[0].getfBulletHasAutoNumber());
//Default value = 1 will be used
assertEquals(Short.valueOf((short) 1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());
assertTrue(AutoNumberingScheme.arabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
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 – 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());
//Default value = 1 will be used
assertEquals(Short.valueOf((short) 1), autoNumbers[0].getAutoNumberStartNumber());
assertTrue(AutoNumberingScheme.arabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
int chCovered = 0;
for (HSLFTextParagraph htp : textParass.get(1)) {
for (HSLFTextRun htr : htp.getTextRuns()) {
TextPropCollection textProp = htr.getCharacterStyle();
chCovered += textProp.getCharactersCovered();
}
}
assertEquals(67, chCovered);
assertTrue(textParass.get(0).get(0).isBullet());
final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
assertEquals(textParass.size(), styleAtoms.length);
checkSingleRunWrapper(43, styleAtoms[0]);
checkSingleRunWrapper(67, styleAtoms[1]);
}
Aggregations