use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.
the class StyleTextPropAtom method setParentTextSize.
/**
* Tell us how much text the parent TextCharsAtom or TextBytesAtom
* contains, so we can go ahead and initialise ourselves.
*/
public void setParentTextSize(int size) {
if (initialised) {
return;
}
int pos = 0;
int textHandled = 0;
paragraphStyles.clear();
charStyles.clear();
// While we have text in need of paragraph stylings, go ahead and
// grok the contents as paragraph formatting data
int prsize = size;
while (pos < rawContents.length && textHandled < prsize) {
// First up, fetch the number of characters this applies to
int textLen = LittleEndian.getInt(rawContents, pos);
textLen = checkTextLength(textLen, textHandled, size);
textHandled += textLen;
pos += 4;
short indent = LittleEndian.getShort(rawContents, pos);
pos += 2;
// Grab the 4 byte value that tells us what properties follow
int paraFlags = LittleEndian.getInt(rawContents, pos);
pos += 4;
// Now make sense of those properties
TextPropCollection thisCollection = new TextPropCollection(textLen, TextPropType.paragraph);
thisCollection.setIndentLevel(indent);
int plSize = thisCollection.buildTextPropList(paraFlags, rawContents, pos);
pos += plSize;
// Save this properties set
paragraphStyles.add(thisCollection);
// Handle extra 1 paragraph styles at the end
if (pos < rawContents.length && textHandled == size) {
prsize++;
}
}
if (rawContents.length > 0 && textHandled != (size + 1)) {
logger.log(POILogger.WARN, "Problem reading paragraph style runs: textHandled = " + textHandled + ", text.size+1 = " + (size + 1));
}
// Now do the character stylings
textHandled = 0;
int chsize = size;
while (pos < rawContents.length && textHandled < chsize) {
// First up, fetch the number of characters this applies to
int textLen = LittleEndian.getInt(rawContents, pos);
textLen = checkTextLength(textLen, textHandled, size);
textHandled += textLen;
pos += 4;
// Grab the 4 byte value that tells us what properties follow
int charFlags = LittleEndian.getInt(rawContents, pos);
pos += 4;
// Now make sense of those properties
// (Assuming we actually have some)
TextPropCollection thisCollection = new TextPropCollection(textLen, TextPropType.character);
int chSize = thisCollection.buildTextPropList(charFlags, rawContents, pos);
pos += chSize;
// Save this properties set
charStyles.add(thisCollection);
// Handle extra 1 char styles at the end
if (pos < rawContents.length && textHandled == size) {
chsize++;
}
}
if (rawContents.length > 0 && textHandled != (size + 1)) {
logger.log(POILogger.WARN, "Problem reading character style runs: textHandled = " + textHandled + ", text.size+1 = " + (size + 1));
}
// Handle anything left over
if (pos < rawContents.length) {
reserved = new byte[rawContents.length - pos];
System.arraycopy(rawContents, pos, reserved, 0, reserved.length);
}
initialised = true;
}
use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.
the class StyleTextPropAtom method updateRawContents.
/**
* Updates the cache of the raw contents. Serialised the styles out.
*/
private void updateRawContents() throws IOException {
if (initialised) {
// Only update the style bytes, if the styles have been potentially
// changed
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// First up, we need to serialise the paragraph properties
for (TextPropCollection tpc : paragraphStyles) {
tpc.writeOut(baos);
}
// Now, we do the character ones
for (TextPropCollection tpc : charStyles) {
tpc.writeOut(baos);
}
rawContents = baos.toByteArray();
}
// Now ensure that the header size is correct
int newSize = rawContents.length + reserved.length;
LittleEndian.putInt(_header, 4, newSize);
}
use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.
the class StyleTextPropAtom method addParagraphTextPropCollection.
/**
* Create a new Paragraph TextPropCollection, and add it to the list
* @param charactersCovered The number of characters this TextPropCollection will cover
* @return the new TextPropCollection, which will then be in the list
*/
public TextPropCollection addParagraphTextPropCollection(int charactersCovered) {
TextPropCollection tpc = new TextPropCollection(charactersCovered, TextPropType.paragraph);
paragraphStyles.add(tpc);
return tpc;
}
use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.
the class StyleTextPropAtom method toString.
/* ************************************************************************ */
/**
* Dump the record content into <code>StringBuffer</code>
*
* @return the string representation of the record data
*/
@Override
public String toString() {
StringBuffer out = new StringBuffer();
out.append("StyleTextPropAtom:\n");
if (!initialised) {
out.append("Uninitialised, dumping Raw Style Data\n");
} else {
out.append("Paragraph properties\n");
for (TextPropCollection pr : getParagraphStyles()) {
out.append(pr);
}
out.append("Character properties\n");
for (TextPropCollection pr : getCharacterStyles()) {
out.append(pr);
}
out.append("Reserved bytes\n");
out.append(HexDump.dump(reserved, 0, 0));
}
out.append(" original byte stream \n");
byte[] buf = new byte[rawContents.length + reserved.length];
System.arraycopy(rawContents, 0, buf, 0, rawContents.length);
System.arraycopy(reserved, 0, buf, rawContents.length, reserved.length);
out.append(HexDump.dump(buf, 0, 0));
return out.toString();
}
use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.
the class HSLFSlideMaster method setSlideShow.
/**
* Assign SlideShow for this slide master.
*/
@Internal
@Override
protected void setSlideShow(HSLFSlideShow ss) {
super.setSlideShow(ss);
//after the slide show is assigned collect all available style records
assert (_txmaster == null);
_txmaster = new TxMasterStyleAtom[9];
TxMasterStyleAtom txdoc = getSlideShow().getDocumentRecord().getEnvironment().getTxMasterStyleAtom();
_txmaster[txdoc.getTextType()] = txdoc;
TxMasterStyleAtom[] txrec = ((MainMaster) getSheetContainer()).getTxMasterStyleAtoms();
for (int i = 0; i < txrec.length; i++) {
int txType = txrec[i].getTextType();
if (txType < _txmaster.length && _txmaster[txType] == null) {
_txmaster[txType] = txrec[i];
}
}
for (List<HSLFTextParagraph> paras : getTextParagraphs()) {
for (HSLFTextParagraph htp : paras) {
int txType = htp.getRunType();
if (txType >= _txmaster.length || _txmaster[txType] == null) {
throw new HSLFException("Master styles not initialized");
}
int level = htp.getIndentLevel();
List<TextPropCollection> charStyles = _txmaster[txType].getCharacterStyles();
List<TextPropCollection> paragraphStyles = _txmaster[txType].getParagraphStyles();
if (charStyles == null || paragraphStyles == null || charStyles.size() <= level || paragraphStyles.size() <= level) {
throw new HSLFException("Master styles not initialized");
}
htp.setMasterStyleReference(paragraphStyles.get(level));
for (HSLFTextRun htr : htp.getTextRuns()) {
htr.setMasterStyleReference(charStyles.get(level));
}
}
}
}
Aggregations