Bug 56513 - Regression: Second header/footer of section lost during FILESAVE as .doc
Summary: Regression: Second header/footer of section lost during FILESAVE as .doc
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
3.5.0 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:4.0.0 target:3.6.5 target:4.1.0
Keywords: regression
Depends on:
Blocks: Writer-Header-Footer
  Show dependency treegraph
 
Reported: 2012-10-29 07:33 UTC by Luke Deller
Modified: 2014-03-06 07:03 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
sample to reproduce issue (22.50 KB, application/msword)
2012-10-29 07:33 UTC, Luke Deller
Details
Sample to reproduce issue (fixed mime type) (22.50 KB, application/msword)
2012-10-29 11:18 UTC, Luke Deller
Details
questionable patch which fixes issue (1.03 KB, patch)
2012-10-29 14:21 UTC, Luke Deller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Deller 2012-10-29 07:33:39 UTC
Created attachment 69209 [details]
sample to reproduce issue

A section can have different headers/footers on the first page of the section vs subsequent pages of the section. (This is a section option in MS Word, and maps to a corresponding chain of page styles in LibreOffice).

When saving as .doc, the headers/footers of the first page of the section become the headers/footers for *all* pages of the section.

This problem does not seem to arise for the very first section of a document.

Attached is a simple sample document to demonstrate the issue.  It has two sections, and the second section has different header/footer on the first page.  It opens correctly in LibreOffice showing:
- page 1 header: "This is the header of the first section"
- page 2 header: "This is the first page header of the second section"
- page 3 header: "This is the non-first page header of the second section"

To reproduce:
1. File->"Save As" another .doc file
2. File->"Close"
3. Open the new .doc file (in LibreOffice or MS Word)
4. Observe that the third page header is now wrong:
- page 1 header: "This is the header of the first section"
- page 2 header: "This is the first page header of the second section"
- page 3 header: "This is the first page header of the second section"

I have tested this sample on the following builds:
- Windows OpenOffice 3.2.1: works correctly
- Windows LibreOffice 3.4.5: works correctly
- Windows LibreOffice 3.5.0: fails
- Windows LibreOffice 3.5.7: fails
- Windows LibreOffice 3.6.1: fails
- (on OpenSUSE Linux) LibreOffice built from latest git 2012-10-28: fails
Comment 1 Luke Deller 2012-10-29 11:18:28 UTC
Created attachment 69218 [details]
Sample to reproduce issue (fixed mime type)
Comment 2 Luke Deller 2012-10-29 14:21:47 UTC
Created attachment 69230 [details]
questionable patch which fixes issue

Attached is a patch which solves the problem for the sample document, though I am not convinced that it is correct.

Some analysis with gdb showed that the problem occurred because the two page styles for the second section did not match.  This is checked by sw::util::IsPlausableSingleWordSection in writerwordglue.cxx.

It seems that when *loaded* from doc the top/bottom margins for the second page are not loaded correctly, as some calculations treat it as though it had no header/footer when it does.  My patch addresses this.  However I am not convinced it is correct because that code has not changed for a long time, and this issue is new in LO 3.5.
Comment 3 Luke Deller 2012-10-31 13:26:06 UTC
I noticed that this problem only occurs when the second section's first page header is marked as "Link to Previous" in Word (which is the default).  This has the effect that the first page header is actually stored against the first section, though not used there because "Different First Page" is not enabled for section 1.  In this case rSection.maSep.grpfIhdt & WW8_HEADER_FIRST is not set which is what broke the logic in wwSectionManager::GetPageULData.  However if "Link to Previous" is unset in Word, then a first page header will be stored against the second section, and rSection.maSep.grpfIhdt & WW8_HEADER_FIRST will be set.

WW8_HEADER_ODD and WW8_HEADER_EVEN seem to be set consistently for all sections in a document regardless of the "Link to Previous" setting.  The anomaly arises only for WW8_HEADER_FIRST. (Same for WW8_FOOTER_*).

(BTW the version of Word whose output I am observing is Word 2010).
Comment 4 Jean-Baptiste Faure 2012-11-04 16:54:01 UTC
Reproducible with LO 3.6.3 and master (Version 3.7.0.0.alpha0+ (Build ID: 0159e9)) under Ubuntu 12.04 x86_64

Hi Cédric, could you have a look at the proposed patch? Thank you very much.

Best regards. JBF
Comment 5 Cédric Bosdonnat 2012-11-05 09:40:25 UTC
Miklos, could you check how this works with your First-page style feature?
Comment 6 Miklos Vajna 2012-11-05 16:12:53 UTC
Cédric,

Seems this is independent, the WW8 filters don't use the new first page API yet.

Luke,

Thanks for looking into this! It seems to me that this will be an export bug, if you try to open the export result of your bugdoc in Word, you get wrong headers as well, so my suggestion is that this should be fixed in the exporter, not in the importer, what you tried.

Even if I spent some time with first page header/footer, I did not touch the WW8 filter regarding this -- I would start debugging around MSWordSections::AppendSection() in wrtw8sty.cxx. SwPageDesc is the class representing a page style.

Given that this is a regression, bisect could be also possible, but I already checked that the first bisectable commit (from 2011-08-22) is already bad.

Let us know if you managed to track this down -- or if it seems to be too hard, then just comment it, then I'll try to have a look (I just want to avoid double work).

Thanks,

Miklos
Comment 7 Luke Deller 2012-11-22 14:54:47 UTC
I found that the regression was introduced by changeset 723f772d for ooo issue 106749.

Reverting this changeset, the output document will contain the appropriate headers and footers on each page.  The output will actually contain *three* sections, which is a consequence of the separate import bug which messes up the margins on the second page during import (addressed by my first patch).

The problem with changeset 723f772d is that the assignment:
    pAktPageDesc = pPageDesc
added by this changeset to MSWordExportBase::OutputSectionBreaks will actually break the logic in MSWordExportBase::SetAktPageDescFromNode:
    if (pCurrent != pAktPageDesc)

So to summarize we have:
- an import bug which messes up margins on page 2
- an export bug which fails to promote the page break on page 2 to a section break
Comment 8 Not Assigned 2012-11-27 17:15:15 UTC
Luke Deller committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=60fa5057039d2413d56813df4d45e5cfdfbb40ac

fdo#56513 second header/footer lost saving as .doc



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 9 Luke Deller 2012-12-05 09:58:55 UTC
I have opened a separate issue for the import problem referred to in comments 2,3:
https://bugs.freedesktop.org/show_bug.cgi?id=57908
Comment 10 Not Assigned 2012-12-06 08:56:50 UTC
Luke Deller committed a patch related to this issue.
It has been pushed to "libreoffice-3-6":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=44dafcf9e29b2286016b9be2ac47c2609c817abc&g=libreoffice-3-6

fdo#56513 second header/footer lost saving as .doc


It will be available in LibreOffice 3.6.5.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 11 Michael Stahl (allotropia) 2012-12-11 19:13:09 UTC
i am assuming that this bug is fixed by the commit in comments #8 and #10
Comment 12 Not Assigned 2013-01-11 16:27:13 UTC
Pierre-Eric Pelloux-Prayer committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=40e0a5d73a5b7a0f23015ee481a94639400f581d

doc export: add unit test for fdo#56513



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 13 Pierre-Eric Pelloux-Prayer 2013-01-11 16:29:45 UTC
@Luke: I created a unit test case based on the document you attached to your bug report. Could you confirm that you're ok with that (otherwise I'll create another document) ?

See: https://gerrit.libreoffice.org/#/c/1644/

Thanks!
Comment 14 Luke Deller 2013-01-12 11:23:07 UTC
@Pierre-Eric yes that's fine, thanks for adding the unit test!