use of org.apache.poi.hslf.record.TextBytesAtom in project poi by apache.
the class PPDrawingTextListing method main.
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Need to give a filename");
System.exit(1);
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find PPDrawings at any second level position
Record[] records = ss.getRecords();
for (int i = 0; i < records.length; i++) {
Record[] children = records[i].getChildRecords();
if (children != null && children.length != 0) {
for (int j = 0; j < children.length; j++) {
if (children[j] instanceof PPDrawing) {
System.out.println("Found PPDrawing at " + j + " in top level record " + i + " (" + records[i].getRecordType() + ")");
// Look for EscherTextboxWrapper's
PPDrawing ppd = (PPDrawing) children[j];
EscherTextboxWrapper[] wrappers = ppd.getTextboxWrappers();
System.out.println(" Has " + wrappers.length + " textbox wrappers within");
// Loop over the wrappers, showing what they contain
for (int k = 0; k < wrappers.length; k++) {
EscherTextboxWrapper tbw = wrappers[k];
System.out.println(" " + k + " has " + tbw.getChildRecords().length + " PPT atoms within");
// Loop over the records, printing the text
Record[] pptatoms = tbw.getChildRecords();
for (int l = 0; l < pptatoms.length; l++) {
String text = null;
if (pptatoms[l] instanceof TextBytesAtom) {
TextBytesAtom tba = (TextBytesAtom) pptatoms[l];
text = tba.getText();
}
if (pptatoms[l] instanceof TextCharsAtom) {
TextCharsAtom tca = (TextCharsAtom) pptatoms[l];
text = tca.getText();
}
if (text != null) {
text = text.replace('\r', '\n');
System.out.println(" ''" + text + "''");
}
}
}
}
}
}
}
ss.close();
}
use of org.apache.poi.hslf.record.TextBytesAtom in project poi by apache.
the class HSLFTextShape method createEmptyParagraph.
private void createEmptyParagraph() {
TextHeaderAtom tha = (TextHeaderAtom) _txtbox.findFirstOfType(TextHeaderAtom._type);
if (tha == null) {
tha = new TextHeaderAtom();
tha.setParentRecord(_txtbox);
_txtbox.appendChildRecord(tha);
}
TextBytesAtom tba = (TextBytesAtom) _txtbox.findFirstOfType(TextBytesAtom._type);
TextCharsAtom tca = (TextCharsAtom) _txtbox.findFirstOfType(TextCharsAtom._type);
if (tba == null && tca == null) {
tba = new TextBytesAtom();
tba.setText(new byte[0]);
_txtbox.appendChildRecord(tba);
}
final String text = ((tba != null) ? tba.getText() : tca.getText());
StyleTextPropAtom sta = (StyleTextPropAtom) _txtbox.findFirstOfType(StyleTextPropAtom._type);
TextPropCollection paraStyle = null, charStyle = null;
if (sta == null) {
int parSiz = text.length();
sta = new StyleTextPropAtom(parSiz + 1);
if (_paragraphs.isEmpty()) {
paraStyle = sta.addParagraphTextPropCollection(parSiz + 1);
charStyle = sta.addCharacterTextPropCollection(parSiz + 1);
} else {
for (HSLFTextParagraph htp : _paragraphs) {
int runsLen = 0;
for (HSLFTextRun htr : htp.getTextRuns()) {
runsLen += htr.getLength();
charStyle = sta.addCharacterTextPropCollection(htr.getLength());
htr.setCharacterStyle(charStyle);
}
paraStyle = sta.addParagraphTextPropCollection(runsLen);
htp.setParagraphStyle(paraStyle);
}
assert (paraStyle != null && charStyle != null);
}
_txtbox.appendChildRecord(sta);
} else {
paraStyle = sta.getParagraphStyles().get(0);
charStyle = sta.getCharacterStyles().get(0);
}
if (_paragraphs.isEmpty()) {
HSLFTextParagraph htp = new HSLFTextParagraph(tha, tba, tca, _paragraphs);
htp.setParagraphStyle(paraStyle);
htp.setParentShape(this);
_paragraphs.add(htp);
HSLFTextRun htr = new HSLFTextRun(htp);
htr.setCharacterStyle(charStyle);
htr.setText(text);
htp.addTextRun(htr);
}
}
use of org.apache.poi.hslf.record.TextBytesAtom in project poi by apache.
the class TextStyleListing method main.
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Need to give a filename");
System.exit(1);
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
for (int i = 0; i < records.length; i++) {
if (records[i].getRecordType() == 1000l) {
Record docRecord = records[i];
Record[] docChildren = docRecord.getChildRecords();
for (int j = 0; j < docChildren.length; j++) {
if (docChildren[j] instanceof SlideListWithText) {
Record[] slwtChildren = docChildren[j].getChildRecords();
int lastTextLen = -1;
for (int k = 0; k < slwtChildren.length; k++) {
if (slwtChildren[k] instanceof TextCharsAtom) {
lastTextLen = ((TextCharsAtom) slwtChildren[k]).getText().length();
}
if (slwtChildren[k] instanceof TextBytesAtom) {
lastTextLen = ((TextBytesAtom) slwtChildren[k]).getText().length();
}
if (slwtChildren[k] instanceof StyleTextPropAtom) {
StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChildren[k];
stpa.setParentTextSize(lastTextLen);
showStyleTextPropAtom(stpa);
}
}
}
}
}
}
ss.close();
}
use of org.apache.poi.hslf.record.TextBytesAtom in project poi by apache.
the class SLWTTextListing method main.
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Need to give a filename");
System.exit(1);
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
for (int i = 0; i < records.length; i++) {
if (records[i] instanceof Document) {
Record docRecord = records[i];
Record[] docChildren = docRecord.getChildRecords();
for (int j = 0; j < docChildren.length; j++) {
if (docChildren[j] instanceof SlideListWithText) {
System.out.println("Found SLWT at pos " + j + " in the Document at " + i);
System.out.println(" Has " + docChildren[j].getChildRecords().length + " children");
// Grab the SlideAtomSet's, which contain
// a SlidePersistAtom and then a bunch of text
// + related records
SlideListWithText slwt = (SlideListWithText) docChildren[j];
SlideListWithText.SlideAtomsSet[] thisSets = slwt.getSlideAtomsSets();
System.out.println(" Has " + thisSets.length + " AtomSets in it");
// Loop over the sets, showing what they contain
for (int k = 0; k < thisSets.length; k++) {
SlidePersistAtom spa = thisSets[k].getSlidePersistAtom();
System.out.println(" " + k + " has slide id " + spa.getSlideIdentifier());
System.out.println(" " + k + " has ref id " + spa.getRefID());
// Loop over the records, printing the text
Record[] slwtc = thisSets[k].getSlideRecords();
for (int l = 0; l < slwtc.length; l++) {
String text = null;
if (slwtc[l] instanceof TextBytesAtom) {
TextBytesAtom tba = (TextBytesAtom) slwtc[l];
text = tba.getText();
}
if (slwtc[l] instanceof TextCharsAtom) {
TextCharsAtom tca = (TextCharsAtom) slwtc[l];
text = tca.getText();
}
if (text != null) {
text = text.replace('\r', '\n');
System.out.println(" ''" + text + "''");
}
}
}
}
}
}
}
ss.close();
}
Aggregations