office: PPTX notes import no longer swallows date, footer and slide-number fields
- Commit
afacc3bebe7762dd532610bde28028b2f8a1b762- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 07:07 UTC (5 days ago)
- Parents
f71eca4
OoxmlPptx.parseNotes scanned the whole notesSlide part and imported every <p:txBody> as notes. A notes page normally carries four text placeholders — the notes body plus date (dt), footer (ftr) and slide number (sldNum) — so a slide's notes came back as ['remember this', '2026-12-01', 'Confidential footer', '7'], and the re-save baked the generated fields into the notes themselves. The importer now tracks the enclosing shape's placeholder type (a <p:ph> without type defaults to body, matching the existing normalization) and returns body-placeholder text when any body placeholder exists, falling back to all text bodies for producers that don't mark placeholders (unchanged behaviour there). Three regression tests failed pre-fix on exactly those arrays and pass now. ODF sheets, lists, formula translation and the sync surface were audited and cleared. Verified: :office:testDevUnitTest 552 tests pass; lint errors are pre-existing on untouched files.
Diff
office/src/main/java/com/vayunmathur/office/data/odf/OoxmlPptx.kt
diff --git a/office/src/main/java/com/vayunmathur/office/data/odf/OoxmlPptx.kt b/office/src/main/java/com/vayunmathur/office/data/odf/OoxmlPptx.ktindex 5889e391fd..748b7972d4 100644--- a/office/src/main/java/com/vayunmathur/office/data/odf/OoxmlPptx.kt+++ b/office/src/main/java/com/vayunmathur/office/data/odf/OoxmlPptx.kt@@ -739,17 +739,40 @@ internal object OoxmlPptx { val xml = pkg.entries[notesPart] ?: return emptyList() val ctx = SlideCtx(pkg, notesPart, OoxmlTheme.DEFAULT, pkg.relsFor(notesPart)) val parser = OoxmlXml.newParser(xml)- val paras = mutableListOf<OdfParagraph>()+ // A notes page carries date/footer/slide-number placeholders beside the+ // notes body; only the body placeholder (<p:ph type="body"/>, the type+ // default) is speaker notes. Collect both, then prefer the body when+ // any placeholder is marked so unmarked producers keep working.+ val bodyParas = mutableListOf<OdfParagraph>()+ val allParas = mutableListOf<OdfParagraph>()+ var hasBody = false+ var shapeDepth = -1+ var shapePhType: String? = null var e = parser.eventType- var inBody = false while (e != XmlPullParser.END_DOCUMENT) {- if (e == XmlPullParser.START_TAG && parser.name == "txBody") { OoxmlPptxText.parseTxBody(- parser,- ctx,- paras); inBody = true }+ when {+ e == XmlPullParser.START_TAG && parser.name == "sp" -> {+ shapeDepth = parser.depth+ shapePhType = null+ }+ e == XmlPullParser.START_TAG && parser.name == "ph" && shapeDepth >= 0 ->+ shapePhType = OoxmlXml.attr(parser, "type") ?: "body"+ e == XmlPullParser.END_TAG && parser.name == "sp" && parser.depth == shapeDepth -> {+ shapeDepth = -1+ shapePhType = null+ }+ e == XmlPullParser.START_TAG && parser.name == "txBody" -> {+ val txParas = mutableListOf<OdfParagraph>()+ OoxmlPptxText.parseTxBody(parser, ctx, txParas)+ allParas.addAll(txParas)+ if (shapePhType == "body") {+ hasBody = true+ bodyParas.addAll(txParas)+ }+ }+ } e = parser.next() }- @Suppress("UNUSED_VALUE") run { inBody = inBody }- return paras+ return if (hasBody) bodyParas else allParas } }
office/src/test/java/com/vayunmathur/office/data/odf/OoxmlPptxNotesPlaceholderTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/data/odf/OoxmlPptxNotesPlaceholderTest.kt b/office/src/test/java/com/vayunmathur/office/data/odf/OoxmlPptxNotesPlaceholderTest.ktnew file mode 100644index 0000000000..4299c1b3d9--- /dev/null+++ b/office/src/test/java/com/vayunmathur/office/data/odf/OoxmlPptxNotesPlaceholderTest.kt@@ -0,0 +1,83 @@+package com.vayunmathur.office.data.odf++import com.vayunmathur.library.ui.odf.OdfDocument+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Regression: a PPTX notes page carries several placeholder shapes besides the+ * notes body (date, footer, slide number). Only the body placeholder+ * (<p:ph type="body"/>) is the speaker notes; the other placeholders' text must+ * not be imported as notes.+ */+class OoxmlPptxNotesPlaceholderTest {++ private fun notesShape(phType: String?, phIdx: String?, text: String, field: Boolean = false): String {+ val ph = if (phType == null) "" else {+ val idx = if (phIdx == null) "" else " idx=\"$phIdx\""+ "<p:nvSpPr><p:nvPr><p:ph type=\"$phType\"$idx/></p:nvPr></p:nvSpPr>"+ }+ val run = if (field) {+ "<a:fld type=\"x\"><a:t>$text</a:t></a:fld>"+ } else {+ "<a:r><a:t>$text</a:t></a:r>"+ }+ return "<p:sp>$ph<p:txBody><a:bodyPr/><a:p>$run</a:p></p:txBody></p:sp>"+ }++ private fun pptxWithNotes(vararg notesShapes: String): OdfDocument.Presentation {+ val notes = "<p:notes xmlns:p=\"p\" xmlns:a=\"a\"><p:cSld><p:spTree>" ++ notesShapes.joinToString("") ++ "</p:spTree></p:cSld></p:notes>"+ val entries = mapOf(+ "ppt/slides/slide1.xml" to+ "<p:sld xmlns:p=\"p\" xmlns:a=\"a\"><p:cSld><p:spTree/></p:cSld></p:sld>",+ "ppt/slides/_rels/slide1.xml.rels" to+ ("<Relationships xmlns=\"p\">" ++ "<Relationship Id=\"n1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide\" " ++ "Target=\"../notesSlides/notesSlide1.xml\"/></Relationships>"),+ "ppt/notesSlides/notesSlide1.xml" to notes,+ )+ val bos = java.io.ByteArrayOutputStream()+ java.util.zip.ZipOutputStream(bos).use { zos ->+ for ((n, c) in entries) {+ zos.putNextEntry(java.util.zip.ZipEntry(n))+ zos.write(c.toByteArray(Charsets.UTF_8))+ zos.closeEntry()+ }+ }+ return OoxmlImporter.import(bos.toByteArray(), "n.pptx") as OdfDocument.Presentation+ }++ private fun noteTexts(doc: OdfDocument.Presentation): List<String> =+ doc.slides[0].notes.map { p -> p.spans.joinToString("") { it.text } }++ @Test+ fun notes_only_body_placeholder_is_imported() {+ val doc = pptxWithNotes(+ notesShape("body", "1", "remember this"),+ notesShape("dt", null, "2026-12-01", field = true),+ notesShape("ftr", null, "Confidential footer"),+ notesShape("sldNum", null, "7", field = true),+ )+ assertEquals(listOf("remember this"), noteTexts(doc))+ }++ @Test+ fun notes_body_found_regardless_of_placeholder_order() {+ val doc = pptxWithNotes(+ notesShape("dt", null, "2026-12-01", field = true),+ notesShape("sldNum", null, "7", field = true),+ notesShape("body", "1", "remember this"),+ )+ assertEquals(listOf("remember this"), noteTexts(doc))+ }++ @Test+ fun notes_without_placeholder_marking_still_imported() {+ // Producers that omit <p:ph> entirely keep the old behaviour (every+ // text body on the notes page is treated as notes).+ val doc = pptxWithNotes(notesShape(null, null, "loose notes"))+ assertEquals(listOf("loose notes"), noteTexts(doc))+ }+}