Search in sources :

Example 1 with TextPropCollection

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;
}
Also used : TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 2 with TextPropCollection

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);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 3 with TextPropCollection

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;
}
Also used : TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 4 with TextPropCollection

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();
}
Also used : TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 5 with TextPropCollection

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));
            }
        }
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) MainMaster(org.apache.poi.hslf.record.MainMaster) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection) TxMasterStyleAtom(org.apache.poi.hslf.record.TxMasterStyleAtom) Internal(org.apache.poi.util.Internal)

Aggregations

TextPropCollection (org.apache.poi.hslf.model.textproperties.TextPropCollection)25 TextProp (org.apache.poi.hslf.model.textproperties.TextProp)6 StyleTextPropAtom (org.apache.poi.hslf.record.StyleTextPropAtom)4 List (java.util.List)3 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)3 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)2 TxMasterStyleAtom (org.apache.poi.hslf.record.TxMasterStyleAtom)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 BitMaskTextProp (org.apache.poi.hslf.model.textproperties.BitMaskTextProp)1 ParagraphFlagsTextProp (org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp)1 TextPFException9 (org.apache.poi.hslf.model.textproperties.TextPFException9)1 EscherTextboxWrapper (org.apache.poi.hslf.record.EscherTextboxWrapper)1 MainMaster (org.apache.poi.hslf.record.MainMaster)1 Record (org.apache.poi.hslf.record.Record)1 StyleTextProp9Atom (org.apache.poi.hslf.record.StyleTextProp9Atom)1 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)1