Bug 155736 - Fileopen DOCX:Page numbers (from field of course, but inside a nested block SDT) are missing in the footer for a particular file
Summary: Fileopen DOCX:Page numbers (from field of course, but inside a nested block S...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
4.2.6.2 release
Hardware: All All
: medium normal
Assignee: SATYA SRINIVAS K
URL:
Whiteboard: target:24.2.0 target:7.6.1
Keywords: bibisected, bisected, filter:docx, regression
Depends on:
Blocks: DOCX-Content_Control
  Show dependency treegraph
 
Reported: 2023-06-08 13:12 UTC by SATYA SRINIVAS K
Modified: 2023-08-01 11:18 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample file which can be used to duplicate the issue. (25.50 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2023-06-08 13:12 UTC, SATYA SRINIVAS K
Details
Missing_Page_Numbers (59.94 KB, image/png)
2023-06-08 13:15 UTC, SATYA SRINIVAS K
Details

Note You need to log in before you can comment on or make changes to this bug.
Description SATYA SRINIVAS K 2023-06-08 13:12:18 UTC
Fileopen DOCX:Page numbers are missing on the footer for a particualr file.

Steps to Reproduce:
1.Please open attached "Page_Numbers_Issue_Lo.docx"in Lo
2.Observe that the page numbers are missing at the bottom.

Expected Result:
Page numbers should be visible Page 1 of 2 Page 2 of 2 

Actual Results:
Page numbers are missing only text is visible as "Page of "

Reproducible : Not happens with every file.

Additional Info: The problem can be reproducible with latest(7.6.0.0 alpha1+master) and previous builds also.
Comment 1 SATYA SRINIVAS K 2023-06-08 13:12:48 UTC
Created attachment 187786 [details]
Sample file which can be used to duplicate the issue.
Comment 2 SATYA SRINIVAS K 2023-06-08 13:13:26 UTC
MS office is displaying the page numbers properly for the attached file.
Comment 3 SATYA SRINIVAS K 2023-06-08 13:15:02 UTC
Created attachment 187787 [details]
Missing_Page_Numbers
Comment 4 Justin L 2023-06-08 14:29:06 UTC
This is a field inside of a content control (regular SDT with a blockSDT)

Nothing was seen in the footer in OOo 3.3.
It was working in 4.0, and broke in 4.2.6.

Using bibisect-43max, I hit a short range of 5 commits that had to be skipped. Almost certainly due to this commit, since it was backported to 4.2.6:
commit 9679e9c23216decb5f9f25f85b04cb3f25211111
Author: Vinaya Mandke on Mon Dec 30 16:22:30 2013 +0530
    tdf#69649 Fix for pre-rendered Table Of Contents
Comment 6 Gabor Kelemen (allotropia) 2023-06-08 16:52:04 UTC
This also seems to do with the footer placement: If I copy the paragraph from the footer and insert it in the document body in Word, then it works in Writer, the initial values are visible and adding a page break increases the second number (of pages).
Comment 7 SATYA SRINIVAS K 2023-06-09 10:21:48 UTC
Justin, It looks like the commit you pointed out is the culprit. 
Page numbers are displaying as expected if I comment this line m_bStartTOC = true; in DomainMapper_Impl::handleToc method.

I still need to track down how this member m_bStartTOC is causing this issue when set to true.

Please let me know, if you have a direct answer or guess.
Comment 8 Justin L 2023-06-09 12:24:12 UTC
(In reply to SATYA SRINIVAS K from comment #7) 
> Please let me know, if you have a direct answer or guess.
IIUC, this is a lot of hacky stuff, so it all could be dreadfully wrong. I believe there was a lot of code changes/research into this area recently, and some of it dealt with exceptions.
So, it will take a fair amount of work to try and wrap your mind around what the code is doing here.
I suggest adding SAL_WARN statements when TOC starts and stops, when Push/PopPageHeaderFooter, at Push/PopSdt, and when CloseSectionGroup so that you get a feel for the flow of the code.

In general, we have a LOT of problems in writerfilter because we don't have a stack. For example, you may be working in a paragraph, and then begin a content control (which also has its own paragraph) which contains a shape (which also has its own paragraph). So now, which of the writerfilter properties can you believe? You can't trust the "this is the first paragraph in the section" or pretty much any other property. Likely the same thing is true for m_bStartTOC.

I tried to create stack properties once, but failed because RTF format doesn't track closely enough with DOCX (and they both share the same code).

But in this case you can probably say "since I am in a footer, I can ignore any TOC flags because obviously I am not building a TOC right now". You will find lots of IsInHeaderFooter() examples similar to this in writerfilter.
Comment 9 Justin L 2023-06-09 14:21:15 UTC
(In reply to Justin L from comment #8)
> IIUC, this is a lot of hacky stuff, so it all could be dreadfully wrong. I
> believe there was a lot of code changes/research into this area recently
See bug 154478 which replaces a similar fix made for bug 154481.
Comment 10 Commit Notification 2023-06-15 21:39:52 UTC
Satya committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d7dd39e124f8a1fa199dd8322b642e8be04ed360

tdf#155736 Modified IsInTOC() to handle IsInHeaderFooter() case.

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2023-06-16 14:45:48 UTC
Satya committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4da11a5d39ccd9f59e326011d4de7ffee8a71d10

tdf#155736 replaced m_bStartTOC condition with a method IsInTOC()

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Justin L 2023-06-17 11:06:52 UTC
Satya - next time you are done submitting patches and the bug is resolved, please mark as resolved/fixed.
Comment 13 Commit Notification 2023-08-01 11:18:19 UTC
Satya committed a patch related to this issue.
It has been pushed to "libreoffice-7-6":

https://git.libreoffice.org/core/commit/d3cf473ceb2a0711ca723ed680034b9251dccbbd

tdf#155736 Modified IsInTOC() to handle IsInHeaderFooter() case.

It will be available in 7.6.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.