Author: fanningpj
Date: Tue May 27 18:02:22 2025
New Revision: 1925870
URL: http://svn.apache.org/viewvc?rev=1925870&view=rev
Log:
[bug-69669] revert some changes in HSLF placeholder creation due to issue with
addTitle
Added:
poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestHSLF.java
(with props)
Modified:
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
Modified:
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java?rev=1925870&r1=1925869&r2=1925870&view=diff
==============================================================================
---
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
(original)
+++
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
Tue May 27 18:02:22 2025
@@ -20,6 +20,9 @@ package org.apache.poi.hslf.usermodel;
import java.awt.Color;
import org.apache.logging.log4j.Logger;
+import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
+import org.apache.poi.hslf.record.OEPlaceholderAtom;
+import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
import org.apache.poi.logging.PoiLogManager;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherChildAnchorRecord;
@@ -579,7 +582,99 @@ public abstract class HSLFSimpleShape ex
@Override
public void setPlaceholder(Placeholder placeholder) {
- getPlaceholderDetails().setPlaceholder(placeholder);
+ EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
+ int flags = spRecord.getFlags();
+ if (placeholder == null) {
+ flags ^= EscherSpRecord.FLAG_HAVEMASTER;
+ } else {
+ flags |= EscherSpRecord.FLAG_HAVEANCHOR |
EscherSpRecord.FLAG_HAVEMASTER;
+ }
+ spRecord.setFlags(flags);
+
+ // Placeholders can't be grouped
+ setEscherProperty(EscherPropertyTypes.PROTECTION__LOCKAGAINSTGROUPING,
(placeholder == null ? -1 : 262144));
+
+ HSLFEscherClientDataRecord clientData = getClientData(false);
+ if (placeholder == null) {
+ if (clientData != null) {
+ clientData.removeChild(OEPlaceholderAtom.class);
+ clientData.removeChild(RoundTripHFPlaceholder12.class);
+ // remove client data if the placeholder was the only child to
be carried
+ if (clientData.getChildRecords().isEmpty()) {
+ getSpContainer().removeChildRecord(clientData);
+ }
+ }
+ return;
+ }
+
+ if (clientData == null) {
+ clientData = getClientData(true);
+ }
+
+ // OEPlaceholderAtom tells powerpoint that this shape is a placeholder
+ OEPlaceholderAtom oep = null;
+ RoundTripHFPlaceholder12 rtp = null;
+ for (org.apache.poi.hslf.record.Record r :
clientData.getHSLFChildRecords()) {
+ if (r instanceof OEPlaceholderAtom) {
+ oep = (OEPlaceholderAtom)r;
+ break;
+ }
+ if (r instanceof RoundTripHFPlaceholder12) {
+ rtp = (RoundTripHFPlaceholder12)r;
+ break;
+ }
+ }
+
+ /**
+ * Extract from MSDN:
+ *
+ * There is a special case when the placeholder does not have a
position in the layout.
+ * This occurs when the user has moved the placeholder from its
original position.
+ * In this case the placeholder ID is -1.
+ */
+ byte phId;
+ HSLFSheet sheet = getSheet();
+ // TODO: implement/switch NotesMaster
+ if (sheet instanceof HSLFSlideMaster) {
+ phId = (byte)placeholder.nativeSlideMasterId;
+ } else if (sheet instanceof HSLFNotes) {
+ phId = (byte)placeholder.nativeNotesId;
+ } else {
+ phId = (byte)placeholder.nativeSlideId;
+ }
+
+ if (phId == -2) {
+ throw new HSLFException("Placeholder "+placeholder.name()+" not
supported for this sheet type ("+sheet.getClass()+")");
+ }
+
+ switch (placeholder) {
+ case HEADER:
+ case FOOTER:
+ if (rtp == null) {
+ rtp = new RoundTripHFPlaceholder12();
+ rtp.setPlaceholderId(phId);
+ clientData.addChild(rtp);
+ }
+ if (oep != null) {
+ clientData.removeChild(OEPlaceholderAtom.class);
+ }
+ break;
+ default:
+ if (rtp != null) {
+ clientData.removeChild(RoundTripHFPlaceholder12.class);
+ }
+ if (oep == null) {
+ oep = new OEPlaceholderAtom();
+
oep.setPlaceholderSize((byte)OEPlaceholderAtom.PLACEHOLDER_FULLSIZE);
+ // TODO: placement id only "SHOULD" be unique ... check
other placeholders on sheet for unique id
+ oep.setPlacementId(-1);
+ oep.setPlaceholderId(phId);
+ clientData.addChild(oep);
+ }
+ break;
+ }
+ // reverted this call because of
https://bz.apache.org/bugzilla/show_bug.cgi?id=69669
+ //getPlaceholderDetails().setPlaceholder(placeholder);
}
Added: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestHSLF.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestHSLF.java?rev=1925870&view=auto
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestHSLF.java
(added)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestHSLF.java
Tue May 27 18:02:22 2025
@@ -0,0 +1,21 @@
+package org.apache.poi.hslf;
+
+import org.apache.poi.hslf.usermodel.*;
+import org.junit.jupiter.api.Test;
+
+import java.io.FileOutputStream;
+
+public class TestHSLF {
+ @Test
+ public void testHSLF() throws Exception {
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
+ //HSLFTextBox title = slide.createTextBox();
+ HSLFTextBox title = slide.addTitle();
+ title.setText("Hello, World!");
+// save changes
+ FileOutputStream out = new FileOutputStream("slideshow.ppt");
+ ppt.write(out);
+ out.close();
+ }
+}
\ No newline at end of file
Propchange:
poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestHSLF.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]