Search in sources :

Example 1 with TxMasterStyleAtom

use of org.apache.poi.hslf.record.TxMasterStyleAtom 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)

Example 2 with TxMasterStyleAtom

use of org.apache.poi.hslf.record.TxMasterStyleAtom in project poi by apache.

the class HSLFSlideMaster method getStyleAttribute.

/**
     * Pickup a style attribute from the master.
     * This is the "workhorse" which returns the default style attributes.
     */
@Override
public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {
    if (_txmaster.length <= txtype) {
        return null;
    }
    TxMasterStyleAtom t = _txmaster[txtype];
    List<TextPropCollection> styles = isCharacter ? t.getCharacterStyles() : t.getParagraphStyles();
    TextProp prop = null;
    for (int i = Math.min(level, styles.size() - 1); prop == null && i >= 0; i--) {
        prop = styles.get(i).findByName(name);
    }
    if (prop != null) {
        return prop;
    }
    switch(txtype) {
        case TextHeaderAtom.CENTRE_BODY_TYPE:
        case TextHeaderAtom.HALF_BODY_TYPE:
        case TextHeaderAtom.QUARTER_BODY_TYPE:
            txtype = TextHeaderAtom.BODY_TYPE;
            break;
        case TextHeaderAtom.CENTER_TITLE_TYPE:
            txtype = TextHeaderAtom.TITLE_TYPE;
            break;
        default:
            return null;
    }
    return getStyleAttribute(txtype, level, name, isCharacter);
}
Also used : TextProp(org.apache.poi.hslf.model.textproperties.TextProp) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection) TxMasterStyleAtom(org.apache.poi.hslf.record.TxMasterStyleAtom)

Aggregations

TextPropCollection (org.apache.poi.hslf.model.textproperties.TextPropCollection)2 TxMasterStyleAtom (org.apache.poi.hslf.record.TxMasterStyleAtom)2 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)1 TextProp (org.apache.poi.hslf.model.textproperties.TextProp)1 MainMaster (org.apache.poi.hslf.record.MainMaster)1 Internal (org.apache.poi.util.Internal)1