Bug 164263 - Table of Contents in certain DOCX does not start on new page with SAL_DISABLE_PRINTERLIST
Summary: Table of Contents in certain DOCX does not start on new page with SAL_DISABLE...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
24.2.1.2 release
Hardware: All All
: medium normal
Assignee: Justin L
URL:
Whiteboard: target:25.8.0 target:25.2.0.0.beta2
Keywords: bibisected, bisected, regression
Depends on:
Blocks: DOCX-TableofContents
  Show dependency treegraph
 
Reported: 2024-12-10 05:33 UTC by Aron Budea
Modified: 2024-12-19 20:45 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Minimized reproducer (25.83 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-12-10 06:37 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aron Budea 2024-12-10 05:33:28 UTC
Open attachment 89463 [details] from bug 71785 with SAL_DISABLE_PRINTERLIST environment variable set to true, eg.:
SAL_DISABLE_PRINTERLIST=true ./soffice SC2012SP1_VMM_CTP2.docx

Note how the Table of Contents doesn't start on a new page, but as a continuation of page 2. It should start on the next page, and it does without the SAL_DISABLE_PRINTERLIST environment variable set.

It was also fine with the environment variable, until the following commit in 24.8, and its backport in 24.2:

https://cgit.freedesktop.org/libreoffice/core/commit/?id=e6f75eb50bc5d1ebccda0c0f80a7b353d991106e
author		Oliver Specht <oliver.specht@cib.de>	2024-01-18 08:48:10 +0100
committer	Thorsten Behrens <thorsten.behrens@allotropia.de>	2024-01-19 23:33:03 +0100

tdf#159254 import paper bin/paper source from rtf/docx files
Comment 1 Mike Kaganski 2024-12-10 06:37:59 UTC
Created attachment 198026 [details]
Minimized reproducer
Comment 2 Justin L 2024-12-17 00:33:37 UTC
Note that SAL_DISABLE_PRINTERLIST=false is still treated as if it was true.

This SHOULD be SAL_DISABLE_PRINTERLIST=1 (or 0 to force the default).
Comment 3 Commit Notification 2024-12-17 01:34:22 UTC Comment hidden (obsolete, reverted)
Comment 4 Justin L 2024-12-18 19:05:22 UTC
(In reply to Justin L from comment #2)
> Note that SAL_DISABLE_PRINTERLIST=false is still treated as if it was true.
So is SAL_DISABLE_PRINTERLIST=0 actually.

The only thing that I can see that isn't treated as true is 
    SAL_DISABLE_PRINTERLIST= 
with nothing after the equal sign.
Comment 5 Justin L 2024-12-18 20:31:29 UTC
The situation is rather interesting, with the interesting code being in vcl/source/gdi/print.cxx.  

When the printer-list is not disabled (so the normal situation), ApplyPaperSource(to bin 0) ALWAYS exceptions (in a controlled way) because GetPaperBinBySourceIndex always returns -1 (at least for Linux's vcl/unx/generic/print/genprnpsp.cxx). Thus the value never changes (i.e. it stays at the special value of -1), which SwXStyle::GetStyleProperty always recognizes as
    [From printer settings]

But when printer-list is disabled, ApplyPaperSource(to bin 0) works because GetPaperBinBySourceIndex always returns 0 since IsDisplayPrinter().
And since it isn't the special -1 value any more, GetStyleProperty asks the printer to GetPaperBinName(0), to which IsDisplayPrinter() simply returns an empty string.

That empty string that getPropertyValue returns MAY NOT be used to setPropertyValue - that's why we were getting the exception.

So probably it is probably best to just avoid setting any properties in unoStyle when IsDisplayPrinter().
Comment 6 Commit Notification 2024-12-19 12:49:01 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/662b5eaf86b5fc15d67ef4f0cf43fd31630ac77e

tdf#164263: avoid exception when SAL_DISABLE_PRINTERLIST #2

It will be available in 25.8.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 7 Justin L 2024-12-19 12:58:20 UTC
Comment 6 includes a revert of comment 3.
Comment 8 Commit Notification 2024-12-19 20:43:19 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/1dc4846e76570ab19c028ac23786e4ffd8fc4679

tdf#164263: avoid exception when SAL_DISABLE_PRINTERLIST #2

It will be available in 25.2.0.0.beta2.

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.