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);
}
}
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());
}
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());
}
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);
}
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);
}
}
Aggregations