#58144 - Behaviour for headers and footers of slides is inconsistent between slideshows created in 2003 and 2007
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1743769 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4a3acf4de0
commit
401a9fb477
@ -364,4 +364,14 @@ public interface TextParagraph<
|
||||
* Fetch the text runs that are contained within this block of text
|
||||
*/
|
||||
List<T> getTextRuns();
|
||||
|
||||
/**
|
||||
* Convenience method to determine if this text paragraph is part of
|
||||
* the slide header or footer
|
||||
*
|
||||
* @return true if this paragraph is part of a header or footer placeholder
|
||||
*
|
||||
* @since POI 3.15-beta2
|
||||
*/
|
||||
boolean isHeaderOrFooter();
|
||||
}
|
@ -1047,4 +1047,19 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
|
||||
_runs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHeaderOrFooter() {
|
||||
CTPlaceholder ph = _shape.getCTPlaceholder();
|
||||
int phId = (ph == null ? -1 : ph.getType().intValue());
|
||||
switch (phId) {
|
||||
case STPlaceholderType.INT_SLD_NUM:
|
||||
case STPlaceholderType.INT_DT:
|
||||
case STPlaceholderType.INT_FTR:
|
||||
case STPlaceholderType.INT_HDR:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.apache.poi.sl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.apache.poi.sl.TestTable.openSampleSlideshow;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hslf.model.HeadersFooters;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
|
||||
import org.apache.poi.sl.usermodel.Shape;
|
||||
import org.apache.poi.sl.usermodel.Slide;
|
||||
import org.apache.poi.sl.usermodel.SlideShow;
|
||||
import org.apache.poi.sl.usermodel.TextParagraph;
|
||||
import org.apache.poi.sl.usermodel.TextShape;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestHeadersFooters {
|
||||
@Test
|
||||
public void bug58144() throws IOException {
|
||||
SlideShow<?,?> ppt1 = openSampleSlideshow("bug58144-headers-footers-2003.ppt");
|
||||
HSLFSlide sl1 = (HSLFSlide)ppt1.getSlides().get(0);
|
||||
HeadersFooters hfs1 = sl1.getHeadersFooters();
|
||||
assertNull(hfs1.getHeaderText());
|
||||
assertEquals("Confidential", hfs1.getFooterText());
|
||||
List<List<HSLFTextParagraph>> llp1 = sl1.getTextParagraphs();
|
||||
assertEquals("Test", HSLFTextParagraph.getText(llp1.get(0)));
|
||||
assertFalse(llp1.get(0).get(0).isHeaderOrFooter());
|
||||
ppt1.close();
|
||||
|
||||
String ppt2007s[] = {
|
||||
"bug58144-headers-footers-2007.ppt", "bug58144-headers-footers-2007.pptx"
|
||||
};
|
||||
|
||||
for (String pptName : ppt2007s) {
|
||||
SlideShow<?,?> ppt2 = openSampleSlideshow(pptName);
|
||||
Slide<?,?> sl2 = ppt2.getSlides().get(0);
|
||||
|
||||
if (ppt2 instanceof HSLFSlideShow) {
|
||||
HeadersFooters hfs2 = ((HSLFSlide)sl2).getHeadersFooters();
|
||||
assertNull(hfs2.getHeaderText());
|
||||
assertEquals("Slide footer", hfs2.getFooterText());
|
||||
}
|
||||
|
||||
List<? extends Shape<?,?>> shapes = sl2.getShapes();
|
||||
TextShape<?,?> ts0 = (TextShape<?,?>)shapes.get(0);
|
||||
assertEquals("Test file", ts0.getText());
|
||||
TextShape<?,?> ts1 = (TextShape<?,?>)shapes.get(1);
|
||||
assertEquals("Has some text in the headers and footers", ts1.getText());
|
||||
TextShape<?,?> ts2 = (TextShape<?,?>)shapes.get(2);
|
||||
assertEquals("Slide footer", ts2.getText());
|
||||
List<? extends TextParagraph<?,?,?>> ltp2 = ts2.getTextParagraphs();
|
||||
assertTrue(ltp2.get(0).isHeaderOrFooter());
|
||||
ppt2.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -17,37 +17,65 @@
|
||||
|
||||
package org.apache.poi.hslf.model;
|
||||
|
||||
import org.apache.poi.hslf.record.*;
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
import org.apache.poi.hslf.record.CString;
|
||||
import org.apache.poi.hslf.record.Document;
|
||||
import org.apache.poi.hslf.record.HeadersFootersAtom;
|
||||
import org.apache.poi.hslf.record.HeadersFootersContainer;
|
||||
import org.apache.poi.hslf.record.OEPlaceholderAtom;
|
||||
import org.apache.poi.hslf.record.Record;
|
||||
import org.apache.poi.hslf.record.RecordTypes;
|
||||
import org.apache.poi.hslf.record.SheetContainer;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSheet;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||
import org.apache.poi.hslf.usermodel.HSLFTextShape;
|
||||
|
||||
/**
|
||||
* Header / Footer settings.
|
||||
*
|
||||
* You can get these on slides, or across all notes
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class HeadersFooters {
|
||||
|
||||
private HeadersFootersContainer _container;
|
||||
private boolean _newRecord;
|
||||
private HSLFSlideShow _ppt;
|
||||
private HSLFSheet _sheet;
|
||||
private boolean _ppt2007;
|
||||
private final HeadersFootersContainer _container;
|
||||
private final HSLFSheet _sheet;
|
||||
private final boolean _ppt2007;
|
||||
|
||||
|
||||
public HeadersFooters(HeadersFootersContainer rec, HSLFSlideShow ppt, boolean newRecord, boolean isPpt2007){
|
||||
_container = rec;
|
||||
_newRecord = newRecord;
|
||||
_ppt = ppt;
|
||||
_ppt2007 = isPpt2007;
|
||||
public HeadersFooters(HSLFSlideShow ppt, short headerFooterType) {
|
||||
this(ppt.getSlideMasters().get(0), headerFooterType);
|
||||
}
|
||||
|
||||
public HeadersFooters(HeadersFootersContainer rec, HSLFSheet sheet, boolean newRecord, boolean isPpt2007){
|
||||
_container = rec;
|
||||
_newRecord = newRecord;
|
||||
public HeadersFooters(HSLFSheet sheet, short headerFooterType) {
|
||||
_sheet = sheet;
|
||||
_ppt2007 = isPpt2007;
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
HSLFSlideShow ppt = _sheet.getSlideShow();
|
||||
Document doc = ppt.getDocumentRecord();
|
||||
|
||||
// detect if this ppt was saved in Office2007
|
||||
String tag = ppt.getSlideMasters().get(0).getProgrammableTag();
|
||||
_ppt2007 = "___PPT12".equals(tag);
|
||||
|
||||
SheetContainer sc = _sheet.getSheetContainer();
|
||||
HeadersFootersContainer hdd = (HeadersFootersContainer)sc.findFirstOfType(RecordTypes.HeadersFooters.typeID);
|
||||
// boolean ppt2007 = sc.findFirstOfType(RecordTypes.RoundTripContentMasterId.typeID) != null;
|
||||
|
||||
if (hdd == null) {
|
||||
for (Record ch : doc.getChildRecords()) {
|
||||
if (ch instanceof HeadersFootersContainer
|
||||
&& ((HeadersFootersContainer) ch).getOptions() == headerFooterType) {
|
||||
hdd = (HeadersFootersContainer) ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hdd == null) {
|
||||
hdd = new HeadersFootersContainer(headerFooterType);
|
||||
Record lst = doc.findFirstOfType(RecordTypes.List.typeID);
|
||||
doc.addChildAfter(hdd, lst);
|
||||
}
|
||||
_container = hdd;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,11 +94,11 @@ public final class HeadersFooters {
|
||||
* @param text headers's text
|
||||
*/
|
||||
public void setHeaderText(String text){
|
||||
if(_newRecord) attach();
|
||||
|
||||
setHeaderVisible(true);
|
||||
CString cs = _container.getHeaderAtom();
|
||||
if(cs == null) cs = _container.addHeaderAtom();
|
||||
if (cs == null) {
|
||||
cs = _container.addHeaderAtom();
|
||||
}
|
||||
|
||||
cs.setText(text);
|
||||
}
|
||||
@ -91,11 +119,11 @@ public final class HeadersFooters {
|
||||
* @param text footers's text
|
||||
*/
|
||||
public void setFootersText(String text){
|
||||
if(_newRecord) attach();
|
||||
|
||||
setFooterVisible(true);
|
||||
CString cs = _container.getFooterAtom();
|
||||
if(cs == null) cs = _container.addFooterAtom();
|
||||
if (cs == null) {
|
||||
cs = _container.addFooterAtom();
|
||||
}
|
||||
|
||||
cs.setText(text);
|
||||
}
|
||||
@ -116,12 +144,12 @@ public final class HeadersFooters {
|
||||
* @param text custom user date
|
||||
*/
|
||||
public void setDateTimeText(String text){
|
||||
if(_newRecord) attach();
|
||||
|
||||
setUserDateVisible(true);
|
||||
setDateTimeVisible(true);
|
||||
CString cs = _container.getUserDateAtom();
|
||||
if(cs == null) cs = _container.addUserDateAtom();
|
||||
if (cs == null) {
|
||||
cs = _container.addUserDateAtom();
|
||||
}
|
||||
|
||||
cs.setText(text);
|
||||
}
|
||||
@ -137,8 +165,7 @@ public final class HeadersFooters {
|
||||
* whether the footer text is displayed.
|
||||
*/
|
||||
public void setFooterVisible(boolean flag){
|
||||
if(_newRecord) attach();
|
||||
_container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasFooter, flag);
|
||||
setFlag(HeadersFootersAtom.fHasFooter, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,8 +179,7 @@ public final class HeadersFooters {
|
||||
* whether the header text is displayed.
|
||||
*/
|
||||
public void setHeaderVisible(boolean flag){
|
||||
if(_newRecord) attach();
|
||||
_container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasHeader, flag);
|
||||
setFlag(HeadersFootersAtom.fHasHeader, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,8 +193,7 @@ public final class HeadersFooters {
|
||||
* whether the date is displayed in the footer.
|
||||
*/
|
||||
public void setDateTimeVisible(boolean flag){
|
||||
if(_newRecord) attach();
|
||||
_container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasDate, flag);
|
||||
setFlag(HeadersFootersAtom.fHasDate, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,8 +207,7 @@ public final class HeadersFooters {
|
||||
* whether the date is displayed in the footer.
|
||||
*/
|
||||
public void setUserDateVisible(boolean flag){
|
||||
if(_newRecord) attach();
|
||||
_container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasUserDate, flag);
|
||||
setFlag(HeadersFootersAtom.fHasUserDate, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,8 +221,7 @@ public final class HeadersFooters {
|
||||
* whether the slide number is displayed in the footer.
|
||||
*/
|
||||
public void setSlideNumberVisible(boolean flag){
|
||||
if(_newRecord) attach();
|
||||
_container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasSlideNumber, flag);
|
||||
setFlag(HeadersFootersAtom.fHasSlideNumber, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,32 +239,13 @@ public final class HeadersFooters {
|
||||
* @param formatId an integer that specifies the format ID to be used to style the datetime.
|
||||
*/
|
||||
public void setDateTimeFormat(int formatId){
|
||||
if(_newRecord) attach();
|
||||
_container.getHeadersFootersAtom().setFormatId(formatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach this HeadersFootersContainer to the parent Document record
|
||||
*/
|
||||
private void attach(){
|
||||
Document doc = _ppt.getDocumentRecord();
|
||||
Record[] ch = doc.getChildRecords();
|
||||
Record lst = null;
|
||||
for (int i=0; i < ch.length; i++){
|
||||
if(ch[i].getRecordType() == RecordTypes.List.typeID){
|
||||
lst = ch[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
doc.addChildAfter(_container, lst);
|
||||
_newRecord = false;
|
||||
}
|
||||
|
||||
private boolean isVisible(int flag, int placeholderId){
|
||||
boolean visible;
|
||||
if(_ppt2007){
|
||||
HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlideMasters().get(0);
|
||||
HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
|
||||
HSLFTextShape placeholder = _sheet.getPlaceholder(placeholderId);
|
||||
visible = placeholder != null && placeholder.getText() != null;
|
||||
} else {
|
||||
visible = _container.getHeadersFootersAtom().getFlag(flag);
|
||||
@ -251,17 +255,23 @@ public final class HeadersFooters {
|
||||
|
||||
private String getPlaceholderText(int placeholderId, CString cs){
|
||||
String text = null;
|
||||
if(_ppt2007){
|
||||
HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlideMasters().get(0);
|
||||
HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
|
||||
if(placeholder != null) text = placeholder.getText();
|
||||
if (_ppt2007) {
|
||||
HSLFTextShape placeholder = _sheet.getPlaceholder(placeholderId);
|
||||
if (placeholder != null) {
|
||||
text = placeholder.getText();
|
||||
}
|
||||
|
||||
//default text in master placeholders is not visible
|
||||
if("*".equals(text)) text = null;
|
||||
// default text in master placeholders is not visible
|
||||
if("*".equals(text)) {
|
||||
text = null;
|
||||
}
|
||||
} else {
|
||||
text = cs == null ? null : cs.getText();
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private void setFlag(int type, boolean flag) {
|
||||
_container.getHeadersFootersAtom().setFlag(type, flag);
|
||||
}
|
||||
}
|
||||
|
@ -120,9 +120,9 @@ public abstract class RecordContainer extends Record
|
||||
* given type. Does not descend.
|
||||
*/
|
||||
public Record findFirstOfType(long type) {
|
||||
for(int i=0; i<_children.length; i++) {
|
||||
if(_children[i].getRecordType() == type) {
|
||||
return _children[i];
|
||||
for (Record r : _children) {
|
||||
if (r.getRecordType() == type) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -31,7 +31,6 @@ import org.apache.poi.hslf.record.ColorSchemeAtom;
|
||||
import org.apache.poi.hslf.record.Comment2000;
|
||||
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
||||
import org.apache.poi.hslf.record.HeadersFootersContainer;
|
||||
import org.apache.poi.hslf.record.Record;
|
||||
import org.apache.poi.hslf.record.RecordContainer;
|
||||
import org.apache.poi.hslf.record.RecordTypes;
|
||||
import org.apache.poi.hslf.record.SSSlideInfoAtom;
|
||||
@ -423,25 +422,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
|
||||
* @return Header / Footer settings for this slide
|
||||
*/
|
||||
public HeadersFooters getHeadersFooters(){
|
||||
HeadersFootersContainer hdd = null;
|
||||
Record[] ch = getSheetContainer().getChildRecords();
|
||||
boolean ppt2007 = false;
|
||||
for (int i = 0; i < ch.length; i++) {
|
||||
if(ch[i] instanceof HeadersFootersContainer){
|
||||
hdd = (HeadersFootersContainer)ch[i];
|
||||
} else if (ch[i].getRecordType() == RecordTypes.RoundTripContentMasterId.typeID){
|
||||
ppt2007 = true;
|
||||
}
|
||||
}
|
||||
boolean newRecord = false;
|
||||
if(hdd == null && !ppt2007) {
|
||||
return getSlideShow().getSlideHeadersFooters();
|
||||
}
|
||||
if(hdd == null) {
|
||||
hdd = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer);
|
||||
newRecord = true;
|
||||
}
|
||||
return new HeadersFooters(hdd, this, newRecord, ppt2007);
|
||||
return new HeadersFooters(this, HeadersFootersContainer.SlideHeadersFootersContainer);
|
||||
}
|
||||
|
||||
protected void onAddTextShape(HSLFTextShape shape) {
|
||||
|
@ -33,7 +33,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.poi.hslf.record.MainMaster;
|
||||
import org.apache.poi.ddf.EscherBSERecord;
|
||||
import org.apache.poi.ddf.EscherContainerRecord;
|
||||
import org.apache.poi.ddf.EscherOptRecord;
|
||||
@ -49,8 +48,6 @@ import org.apache.poi.hslf.record.ExAviMovie;
|
||||
import org.apache.poi.hslf.record.ExControl;
|
||||
import org.apache.poi.hslf.record.ExEmbed;
|
||||
import org.apache.poi.hslf.record.ExEmbedAtom;
|
||||
import org.apache.poi.hslf.record.ExHyperlink;
|
||||
import org.apache.poi.hslf.record.ExHyperlinkAtom;
|
||||
import org.apache.poi.hslf.record.ExMCIMovie;
|
||||
import org.apache.poi.hslf.record.ExObjList;
|
||||
import org.apache.poi.hslf.record.ExObjListAtom;
|
||||
@ -60,6 +57,7 @@ import org.apache.poi.hslf.record.ExVideoContainer;
|
||||
import org.apache.poi.hslf.record.FontCollection;
|
||||
import org.apache.poi.hslf.record.FontEntityAtom;
|
||||
import org.apache.poi.hslf.record.HeadersFootersContainer;
|
||||
import org.apache.poi.hslf.record.MainMaster;
|
||||
import org.apache.poi.hslf.record.Notes;
|
||||
import org.apache.poi.hslf.record.PersistPtrHolder;
|
||||
import org.apache.poi.hslf.record.PositionDependentRecord;
|
||||
@ -905,24 +903,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||
* @return Header / Footer settings for slides
|
||||
*/
|
||||
public HeadersFooters getSlideHeadersFooters() {
|
||||
// detect if this ppt was saved in Office2007
|
||||
String tag = getSlideMasters().get(0).getProgrammableTag();
|
||||
boolean ppt2007 = "___PPT12".equals(tag);
|
||||
|
||||
HeadersFootersContainer hdd = null;
|
||||
for (Record ch : _documentRecord.getChildRecords()) {
|
||||
if (ch instanceof HeadersFootersContainer
|
||||
&& ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer) {
|
||||
hdd = (HeadersFootersContainer) ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean newRecord = false;
|
||||
if (hdd == null) {
|
||||
hdd = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer);
|
||||
newRecord = true;
|
||||
}
|
||||
return new HeadersFooters(hdd, this, newRecord, ppt2007);
|
||||
return new HeadersFooters(this, HeadersFootersContainer.SlideHeadersFootersContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -931,28 +912,12 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
||||
* @return Header / Footer settings for notes
|
||||
*/
|
||||
public HeadersFooters getNotesHeadersFooters() {
|
||||
// detect if this ppt was saved in Office2007
|
||||
String tag = getSlideMasters().get(0).getProgrammableTag();
|
||||
boolean ppt2007 = "___PPT12".equals(tag);
|
||||
|
||||
HeadersFootersContainer hdd = null;
|
||||
for (Record ch : _documentRecord.getChildRecords()) {
|
||||
if (ch instanceof HeadersFootersContainer
|
||||
&& ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer) {
|
||||
hdd = (HeadersFootersContainer) ch;
|
||||
break;
|
||||
if (_notes.isEmpty()) {
|
||||
return new HeadersFooters(this, HeadersFootersContainer.NotesHeadersFootersContainer);
|
||||
} else {
|
||||
return new HeadersFooters(_notes.get(0), HeadersFootersContainer.NotesHeadersFootersContainer);
|
||||
}
|
||||
}
|
||||
boolean newRecord = false;
|
||||
if (hdd == null) {
|
||||
hdd = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer);
|
||||
newRecord = true;
|
||||
}
|
||||
if (ppt2007 && !_notes.isEmpty()) {
|
||||
return new HeadersFooters(hdd, _notes.get(0), newRecord, ppt2007);
|
||||
}
|
||||
return new HeadersFooters(hdd, this, newRecord, ppt2007);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a movie in this presentation
|
||||
|
@ -41,11 +41,13 @@ import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
||||
import org.apache.poi.hslf.record.FontCollection;
|
||||
import org.apache.poi.hslf.record.InteractiveInfo;
|
||||
import org.apache.poi.hslf.record.MasterTextPropAtom;
|
||||
import org.apache.poi.hslf.record.OEPlaceholderAtom;
|
||||
import org.apache.poi.hslf.record.OutlineTextRefAtom;
|
||||
import org.apache.poi.hslf.record.PPDrawing;
|
||||
import org.apache.poi.hslf.record.Record;
|
||||
import org.apache.poi.hslf.record.RecordContainer;
|
||||
import org.apache.poi.hslf.record.RecordTypes;
|
||||
import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
|
||||
import org.apache.poi.hslf.record.SlideListWithText;
|
||||
import org.apache.poi.hslf.record.SlidePersistAtom;
|
||||
import org.apache.poi.hslf.record.StyleTextProp9Atom;
|
||||
@ -256,7 +258,6 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
|
||||
|
||||
public TextRulerAtom getTextRuler() {
|
||||
return _ruler;
|
||||
|
||||
}
|
||||
|
||||
public TextRulerAtom createTextRuler() {
|
||||
@ -1571,4 +1572,32 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see RoundTripHFPlaceholder12
|
||||
*/
|
||||
@Override
|
||||
public boolean isHeaderOrFooter() {
|
||||
HSLFShape s = getParentShape();
|
||||
if (s == null) {
|
||||
return false;
|
||||
}
|
||||
RoundTripHFPlaceholder12 hfPl = s.getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID);
|
||||
if (hfPl == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int plId = hfPl.getPlaceholderId();
|
||||
switch (plId) {
|
||||
case OEPlaceholderAtom.MasterDate:
|
||||
case OEPlaceholderAtom.MasterSlideNumber:
|
||||
case OEPlaceholderAtom.MasterFooter:
|
||||
case OEPlaceholderAtom.MasterHeader:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,13 +17,17 @@
|
||||
|
||||
package org.apache.poi.hslf.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hslf.HSLFTestDataSamples;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||
import org.junit.Test;
|
||||
@ -37,8 +41,10 @@ public final class TestHeadersFooters
|
||||
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("headers_footers.ppt"));
|
||||
public void testRead() throws IOException {
|
||||
InputStream is = _slTests.openResourceAsStream("headers_footers.ppt");
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(is);
|
||||
is.close();
|
||||
|
||||
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
|
||||
assertTrue(slideHdd.isFooterVisible());
|
||||
@ -75,6 +81,8 @@ public final class TestHeadersFooters
|
||||
assertEquals("per-slide footer", hd2.getFooterText());
|
||||
assertEquals(true, hd2.isUserDateVisible());
|
||||
assertEquals("custom date format", hd2.getDateTimeText());
|
||||
|
||||
ppt.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +90,9 @@ public final class TestHeadersFooters
|
||||
*/
|
||||
@Test
|
||||
public void testReadNoHeadersFooters() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
||||
InputStream is = _slTests.openResourceAsStream("basic_test_ppt_file.ppt");
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(is);
|
||||
is.close();
|
||||
|
||||
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
|
||||
assertFalse(slideHdd.isFooterVisible());
|
||||
@ -111,14 +121,18 @@ public final class TestHeadersFooters
|
||||
assertFalse(hd1.isUserDateVisible());
|
||||
assertNull(hd1.getDateTimeText());
|
||||
}
|
||||
|
||||
ppt.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extraction of headers / footers from PPTs saved in Office 2007
|
||||
*/
|
||||
@Test
|
||||
public void testRead2007() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("headers_footers_2007.ppt"));
|
||||
public void testRead2007() throws IOException {
|
||||
InputStream is = _slTests.openResourceAsStream("headers_footers_2007.ppt");
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(is);
|
||||
is.close();
|
||||
|
||||
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
|
||||
assertTrue(slideHdd.isFooterVisible());
|
||||
@ -174,44 +188,44 @@ public final class TestHeadersFooters
|
||||
assertTrue(hd3.isUserDateVisible());
|
||||
assertTrue(hd3.isDateTimeVisible());
|
||||
assertEquals("Wednesday, August 06, 2008", hd3.getDateTimeText());
|
||||
|
||||
ppt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSlideFooters() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||
HeadersFooters hdd = ppt.getSlideHeadersFooters();
|
||||
public void testCreateSlideFooters() throws IOException {
|
||||
HSLFSlideShow ppt1 = new HSLFSlideShow();
|
||||
HeadersFooters hdd = ppt1.getSlideHeadersFooters();
|
||||
hdd.setFootersText("My slide footer");
|
||||
hdd.setSlideNumberVisible(true);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ppt.write(out);
|
||||
byte[] b = out.toByteArray();
|
||||
|
||||
HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(b));
|
||||
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
||||
HeadersFooters hdd2 = ppt2.getSlideHeadersFooters();
|
||||
assertTrue(hdd2.isSlideNumberVisible());
|
||||
assertTrue(hdd2.isFooterVisible());
|
||||
assertEquals("My slide footer", hdd2.getFooterText());
|
||||
|
||||
ppt2.close();
|
||||
ppt1.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNotesFooters() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||
HeadersFooters hdd = ppt.getNotesHeadersFooters();
|
||||
public void testCreateNotesFooters() throws IOException {
|
||||
HSLFSlideShow ppt1 = new HSLFSlideShow();
|
||||
HeadersFooters hdd = ppt1.getNotesHeadersFooters();
|
||||
hdd.setFootersText("My notes footer");
|
||||
hdd.setHeaderText("My notes header");
|
||||
hdd.setSlideNumberVisible(true);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ppt.write(out);
|
||||
byte[] b = out.toByteArray();
|
||||
|
||||
HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(b));
|
||||
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
||||
HeadersFooters hdd2 = ppt2.getNotesHeadersFooters();
|
||||
assertTrue(hdd2.isSlideNumberVisible());
|
||||
assertTrue(hdd2.isFooterVisible());
|
||||
assertEquals("My notes footer", hdd2.getFooterText());
|
||||
assertTrue(hdd2.isHeaderVisible());
|
||||
assertEquals("My notes header", hdd2.getHeaderText());
|
||||
|
||||
ppt2.close();
|
||||
ppt1.close();
|
||||
}
|
||||
}
|
||||
|
BIN
test-data/slideshow/bug58144-headers-footers-2003.ppt
Normal file
BIN
test-data/slideshow/bug58144-headers-footers-2003.ppt
Normal file
Binary file not shown.
BIN
test-data/slideshow/bug58144-headers-footers-2007.ppt
Normal file
BIN
test-data/slideshow/bug58144-headers-footers-2007.ppt
Normal file
Binary file not shown.
BIN
test-data/slideshow/bug58144-headers-footers-2007.pptx
Normal file
BIN
test-data/slideshow/bug58144-headers-footers-2007.pptx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user