Modern Apps git

← Modern-Apps.git

office: fix heading/paragraph style read after inline parse

Commit
0f297e935af54839210e85432d16a6fb467dfc1a
Author
Vayun Mathur <[email protected]>
When
2026-11-06 18:15 UTC (29 days ago)
Parents
8ea9da4
827ba5556 extracted parseHeading/parseBodyParagraph and ordered collect-inline before resolveStyle, but the pull parser has already advanced past the start tag by then, so getAttr(style-name) reads the wrong element (style lost: alignment null, page breaks missing). Capture style-name and resolve before collecting inline (verified: heading alignment/break tests fail without, pass with).

(cherry picked from commit 6fa59e40df8e82aef07a05b9c9744a868ff6ad2f)

Diff

office/src/main/java/com/vayunmathur/office/odf/OdfParserHeading.kt
diff --git a/office/src/main/java/com/vayunmathur/office/odf/OdfParserHeading.kt b/office/src/main/java/com/vayunmathur/office/odf/OdfParserHeading.ktindex c26bfdf793..063a6af930 100644--- a/office/src/main/java/com/vayunmathur/office/odf/OdfParserHeading.kt+++ b/office/src/main/java/com/vayunmathur/office/odf/OdfParserHeading.kt@@ -29,9 +29,10 @@ internal fun OdfParser.parseHeading(     outlineCounters: IntArray, ) {     val level = getAttr(parser, "outline-level")?.toIntOrNull() ?: 1-    val collected = collectHeadingInline(parser, styles, images, footnotes, objectContents)-    val resolved = resolveStyle(getAttr(parser, "style-name"), styles)+    val styleName = getAttr(parser, "style-name")+    val resolved = resolveStyle(styleName, styles)     if (resolved.breakBefore == "page") content.add(OdfContentBlock.PageBreak)+    val collected = collectHeadingInline(parser, styles, images, footnotes, objectContents)     val para = buildHeadingPara(         level, collected.spans, resolved, listDepth, listStyleStack,         listItemCounter, outlineStyle, outlineCounters)
office/src/main/java/com/vayunmathur/office/odf/OdfParserParagraph.kt
diff --git a/office/src/main/java/com/vayunmathur/office/odf/OdfParserParagraph.kt b/office/src/main/java/com/vayunmathur/office/odf/OdfParserParagraph.ktindex 002e8ae15d..ac4134a994 100644--- a/office/src/main/java/com/vayunmathur/office/odf/OdfParserParagraph.kt+++ b/office/src/main/java/com/vayunmathur/office/odf/OdfParserParagraph.kt@@ -27,7 +27,8 @@ internal fun OdfParser.parseBodyParagraph(     listTypeStack: MutableList<ListType>,     pendingListItemChecked: Boolean, ) {-    val resolved = resolveStyle(getAttr(parser, "style-name"), styles)+    val styleName = getAttr(parser, "style-name")+    val resolved = resolveStyle(styleName, styles)     if (resolved.breakBefore == "page") content.add(OdfContentBlock.PageBreak)     val collected = collectBodyInline(parser, styles, images, footnotes, objectContents)     if (collected.spans.isNotEmpty() || listDepth > 0) {