001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hslf.model;
019:
020: import org.apache.poi.hslf.model.textproperties.TextProp;
021: import org.apache.poi.hslf.model.textproperties.TextPropCollection;
022: import org.apache.poi.hslf.record.*;
023: import org.apache.poi.hslf.usermodel.SlideShow;
024: import org.apache.poi.hslf.record.StyleTextPropAtom.*;
025: import org.apache.poi.ddf.EscherContainerRecord;
026: import org.apache.poi.ddf.EscherRecord;
027:
028: import java.util.List;
029: import java.util.Iterator;
030:
031: /**
032: * SlideMaster determines the graphics, layout, and formatting for all the slides in a given presentation.
033: * It stores information about default font styles, placeholder sizes and positions,
034: * background design, and color schemes.
035: *
036: * @author Yegor Kozlov
037: */
038: public class SlideMaster extends MasterSheet {
039: private TextRun[] _runs;
040:
041: /**
042: * all TxMasterStyleAtoms available in this master
043: */
044: private TxMasterStyleAtom[] _txmaster;
045:
046: /**
047: * Constructs a SlideMaster from the MainMaster record,
048: *
049: */
050: public SlideMaster(MainMaster record, int sheetNo) {
051: super (record, sheetNo);
052:
053: _runs = findTextRuns(getPPDrawing());
054: for (int i = 0; i < _runs.length; i++)
055: _runs[i].setSheet(this );
056: }
057:
058: /**
059: * Returns an array of all the TextRuns found
060: */
061: public TextRun[] getTextRuns() {
062: return _runs;
063: }
064:
065: /**
066: * Returns <code>null</code> since SlideMasters doen't have master sheet.
067: */
068: public MasterSheet getMasterSheet() {
069: return null;
070: }
071:
072: /**
073: * Pickup a style attribute from the master.
074: * This is the "workhorse" which returns the default style attrubutes.
075: */
076: public TextProp getStyleAttribute(int txtype, int level,
077: String name, boolean isCharacter) {
078:
079: TextProp prop = null;
080: for (int i = level; i >= 0; i--) {
081: TextPropCollection[] styles = isCharacter ? _txmaster[txtype]
082: .getCharacterStyles()
083: : _txmaster[txtype].getParagraphStyles();
084: if (i < styles.length)
085: prop = styles[i].findByName(name);
086: if (prop != null)
087: break;
088: }
089: if (prop == null) {
090: switch (txtype) {
091: case TextHeaderAtom.CENTRE_BODY_TYPE:
092: case TextHeaderAtom.HALF_BODY_TYPE:
093: case TextHeaderAtom.QUARTER_BODY_TYPE:
094: txtype = TextHeaderAtom.BODY_TYPE;
095: break;
096: case TextHeaderAtom.CENTER_TITLE_TYPE:
097: txtype = TextHeaderAtom.TITLE_TYPE;
098: break;
099: default:
100: return null;
101: }
102: prop = getStyleAttribute(txtype, level, name, isCharacter);
103: }
104: return prop;
105: }
106:
107: /**
108: * Assign SlideShow for this slide master.
109: * (Used interanlly)
110: */
111: public void setSlideShow(SlideShow ss) {
112: super .setSlideShow(ss);
113:
114: //after the slide show is assigned collect all available style records
115: if (_txmaster == null) {
116: _txmaster = new TxMasterStyleAtom[9];
117:
118: TxMasterStyleAtom txdoc = getSlideShow()
119: .getDocumentRecord().getEnvironment()
120: .getTxMasterStyleAtom();
121: _txmaster[txdoc.getTextType()] = txdoc;
122:
123: TxMasterStyleAtom[] txrec = ((MainMaster) getSheetContainer())
124: .getTxMasterStyleAtoms();
125: for (int i = 0; i < txrec.length; i++) {
126: _txmaster[txrec[i].getTextType()] = txrec[i];
127: }
128: }
129: }
130: }
|