use of org.apache.poi.hslf.record.RecordContainer in project poi by apache.
the class HSLFTextParagraph method updateTextAtom.
/**
* Set the correct text atom depending on the multibyte usage
*/
private static void updateTextAtom(List<HSLFTextParagraph> paragraphs) {
final String rawText = toInternalString(getRawText(paragraphs));
// Will it fit in a 8 bit atom?
boolean isUnicode = StringUtil.hasMultibyte(rawText);
// isUnicode = true;
TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom;
TextBytesAtom byteAtom = paragraphs.get(0)._byteAtom;
TextCharsAtom charAtom = paragraphs.get(0)._charAtom;
StyleTextPropAtom styleAtom = findStyleAtomPresent(headerAtom, rawText.length());
// Store in the appropriate record
Record oldRecord = null, newRecord = null;
if (isUnicode) {
if (byteAtom != null || charAtom == null) {
oldRecord = byteAtom;
charAtom = new TextCharsAtom();
}
newRecord = charAtom;
charAtom.setText(rawText);
} else {
if (charAtom != null || byteAtom == null) {
oldRecord = charAtom;
byteAtom = new TextBytesAtom();
}
newRecord = byteAtom;
byte[] byteText = new byte[rawText.length()];
StringUtil.putCompressedUnicode(rawText, byteText, 0);
byteAtom.setText(byteText);
}
assert (newRecord != null);
RecordContainer _txtbox = headerAtom.getParentRecord();
Record[] cr = _txtbox.getChildRecords();
int /* headerIdx = -1, */
textIdx = -1, styleIdx = -1;
for (int i = 0; i < cr.length; i++) {
Record r = cr[i];
if (r == headerAtom) {
// headerIdx = i;
} else if (r == oldRecord || r == newRecord) {
textIdx = i;
} else if (r == styleAtom) {
styleIdx = i;
}
}
if (textIdx == -1) {
// the old record was never registered, ignore it
_txtbox.addChildAfter(newRecord, headerAtom);
// textIdx = headerIdx + 1;
} else {
// swap not appropriated records - noop if unchanged
cr[textIdx] = newRecord;
}
if (styleIdx == -1) {
// Add the new StyleTextPropAtom after the TextCharsAtom / TextBytesAtom
_txtbox.addChildAfter(styleAtom, newRecord);
}
for (HSLFTextParagraph p : paragraphs) {
if (newRecord == byteAtom) {
p._byteAtom = byteAtom;
p._charAtom = null;
} else {
p._byteAtom = null;
p._charAtom = charAtom;
}
}
}
use of org.apache.poi.hslf.record.RecordContainer in project poi by apache.
the class HSLFSheet method getProgrammableTag.
/**
* Return programmable tag associated with this sheet, e.g. <code>___PPT12</code>.
*
* @return programmable tag associated with this sheet.
*/
public String getProgrammableTag() {
String tag = null;
RecordContainer progTags = (RecordContainer) getSheetContainer().findFirstOfType(RecordTypes.ProgTags.typeID);
if (progTags != null) {
RecordContainer progBinaryTag = (RecordContainer) progTags.findFirstOfType(RecordTypes.ProgBinaryTag.typeID);
if (progBinaryTag != null) {
CString binaryTag = (CString) progBinaryTag.findFirstOfType(RecordTypes.CString.typeID);
if (binaryTag != null) {
tag = binaryTag.getText();
}
}
}
return tag;
}
use of org.apache.poi.hslf.record.RecordContainer in project poi by apache.
the class HSLFSlide method getComments.
/**
* Get the comment(s) for this slide.
* Note - for now, only works on PPT 2000 and
* PPT 2003 files. Doesn't work for PPT 97
* ones, as they do their comments oddly.
*/
public Comment[] getComments() {
// If there are any, they're in
// ProgTags -> ProgBinaryTag -> BinaryTagData
RecordContainer progTags = (RecordContainer) getSheetContainer().findFirstOfType(RecordTypes.ProgTags.typeID);
if (progTags != null) {
RecordContainer progBinaryTag = (RecordContainer) progTags.findFirstOfType(RecordTypes.ProgBinaryTag.typeID);
if (progBinaryTag != null) {
RecordContainer binaryTags = (RecordContainer) progBinaryTag.findFirstOfType(RecordTypes.BinaryTagData.typeID);
if (binaryTags != null) {
// This is where they'll be
int count = 0;
for (int i = 0; i < binaryTags.getChildRecords().length; i++) {
if (binaryTags.getChildRecords()[i] instanceof Comment2000) {
count++;
}
}
// Now build
Comment[] comments = new Comment[count];
count = 0;
for (int i = 0; i < binaryTags.getChildRecords().length; i++) {
if (binaryTags.getChildRecords()[i] instanceof Comment2000) {
comments[i] = new Comment((Comment2000) binaryTags.getChildRecords()[i]);
count++;
}
}
return comments;
}
}
}
// None found
return new Comment[0];
}
use of org.apache.poi.hslf.record.RecordContainer in project poi by apache.
the class HSLFTextParagraph method updateHyperlinks.
private static void updateHyperlinks(List<HSLFTextParagraph> paragraphs) {
TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom;
RecordContainer _txtbox = headerAtom.getParentRecord();
// remove existing hyperlink records
for (Record r : _txtbox.getChildRecords()) {
if (r instanceof InteractiveInfo || r instanceof TxInteractiveInfoAtom) {
_txtbox.removeChild(r);
}
}
// now go through all the textruns and check for hyperlinks
HSLFHyperlink lastLink = null;
for (HSLFTextParagraph para : paragraphs) {
for (HSLFTextRun run : para) {
HSLFHyperlink thisLink = run.getHyperlink();
if (thisLink != null && thisLink == lastLink) {
// the hyperlink extends over this text run, increase its length
// TODO: the text run might be longer than the hyperlink
thisLink.setEndIndex(thisLink.getEndIndex() + run.getLength());
} else {
if (lastLink != null) {
InteractiveInfo info = lastLink.getInfo();
TxInteractiveInfoAtom txinfo = lastLink.getTextRunInfo();
assert (info != null && txinfo != null);
_txtbox.appendChildRecord(info);
_txtbox.appendChildRecord(txinfo);
}
}
lastLink = thisLink;
}
}
if (lastLink != null) {
InteractiveInfo info = lastLink.getInfo();
TxInteractiveInfoAtom txinfo = lastLink.getTextRunInfo();
assert (info != null && txinfo != null);
_txtbox.appendChildRecord(info);
_txtbox.appendChildRecord(txinfo);
}
}
use of org.apache.poi.hslf.record.RecordContainer in project poi by apache.
the class HSLFTextParagraph method refreshRecords.
/**
* Writes the textbox records back to the document record
*/
private static void refreshRecords(List<HSLFTextParagraph> paragraphs) {
TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom;
RecordContainer _txtbox = headerAtom.getParentRecord();
if (_txtbox instanceof EscherTextboxWrapper) {
try {
((EscherTextboxWrapper) _txtbox).writeOut(null);
} catch (IOException e) {
throw new HSLFException("failed dummy write", e);
}
}
}
Aggregations