Search in sources :

Example 11 with TextPropCollection

use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.

the class TxMasterStyleAtom method updateStyles.

/**
     * Updates the rawdata from the modified paragraph/character styles
     * 
     * @since POI 3.14-beta1
     */
public void updateStyles() {
    int type = getTextType();
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
        int levels = paragraphStyles.size();
        leos.writeShort(levels);
        TextPropCollection prdummy = new TextPropCollection(0, TextPropType.paragraph);
        TextPropCollection chdummy = new TextPropCollection(0, TextPropType.character);
        for (int i = 0; i < levels; i++) {
            prdummy.copy(paragraphStyles.get(i));
            chdummy.copy(charStyles.get(i));
            if (type >= TextHeaderAtom.CENTRE_BODY_TYPE) {
                leos.writeShort(prdummy.getIndentLevel());
            }
            // Indent level is not written for master styles
            prdummy.setIndentLevel((short) -1);
            prdummy.writeOut(bos, true);
            chdummy.writeOut(bos, true);
        }
        _data = bos.toByteArray();
        leos.close();
        LittleEndian.putInt(_header, 4, _data.length);
    } catch (IOException e) {
        throw new HSLFException("error in updating master style properties", e);
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 12 with TextPropCollection

use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.

the class TestTxMasterStyleAtom method checkOtherType.

/**
     * Test styles for type=TextHeaderAtom.OTHER_TYPE
     */
private void checkOtherType(TxMasterStyleAtom txmaster) {
    TextPropCollection props;
    TextProp prop;
    //paragraph styles
    props = txmaster.getParagraphStyles().get(0);
    prop = props.findByName("alignment");
    assertEquals(0, prop.getValue());
    //character styles
    props = txmaster.getCharacterStyles().get(0);
    prop = props.findByName("font.color");
    assertEquals(0x1000000, prop.getValue());
    prop = props.findByName("font.index");
    assertEquals(0, prop.getValue());
    prop = props.findByName("font.size");
    assertEquals(18, prop.getValue());
}
Also used : TextProp(org.apache.poi.hslf.model.textproperties.TextProp) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 13 with TextPropCollection

use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.

the class TestTxMasterStyleAtom method checkTitleType.

/**
     * Test styles for type=TextHeaderAtom.TITLE_TYPE
     */
private void checkTitleType(TxMasterStyleAtom txmaster) {
    TextPropCollection props;
    TextProp prop;
    //paragraph styles
    props = txmaster.getParagraphStyles().get(0);
    prop = props.findByName("alignment");
    //title has center alignment
    assertEquals(1, prop.getValue());
    //character styles
    props = txmaster.getCharacterStyles().get(0);
    prop = props.findByName("font.color");
    assertEquals(0x3000000, prop.getValue());
    prop = props.findByName("font.index");
    assertEquals(0, prop.getValue());
    prop = props.findByName("font.size");
    assertEquals(44, prop.getValue());
}
Also used : TextProp(org.apache.poi.hslf.model.textproperties.TextProp) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 14 with TextPropCollection

use of org.apache.poi.hslf.model.textproperties.TextPropCollection 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)

Example 15 with TextPropCollection

use of org.apache.poi.hslf.model.textproperties.TextPropCollection in project poi by apache.

the class TxMasterStyleAtom method init.

/**
     * parse the record data and initialize styles
     */
protected void init() {
    //type of the text
    int type = getTextType();
    int head;
    int pos = 0;
    //number of indentation levels
    short levels = LittleEndian.getShort(_data, 0);
    pos += LittleEndian.SHORT_SIZE;
    paragraphStyles = new ArrayList<TextPropCollection>(levels);
    charStyles = new ArrayList<TextPropCollection>(levels);
    for (short i = 0; i < levels; i++) {
        TextPropCollection prprops = new TextPropCollection(0, TextPropType.paragraph);
        if (type >= TextHeaderAtom.CENTRE_BODY_TYPE) {
            // Fetch the 2 byte value, that is safe to ignore for some types of text
            short indentLevel = LittleEndian.getShort(_data, pos);
            prprops.setIndentLevel(indentLevel);
            pos += LittleEndian.SHORT_SIZE;
        } else {
            prprops.setIndentLevel((short) -1);
        }
        head = LittleEndian.getInt(_data, pos);
        pos += LittleEndian.INT_SIZE;
        pos += prprops.buildTextPropList(head, _data, pos);
        paragraphStyles.add(prprops);
        head = LittleEndian.getInt(_data, pos);
        pos += LittleEndian.INT_SIZE;
        TextPropCollection chprops = new TextPropCollection(0, TextPropType.character);
        pos += chprops.buildTextPropList(head, _data, pos);
        charStyles.add(chprops);
    }
}
Also used : TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

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