Bug 61479 - DOCX style inheritance not respecting style attributes being turned off
Summary: DOCX style inheritance not respecting style attributes being turned off
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
(earliest affected) release
Hardware: Other All
: high normal
Assignee: Not Assigned
Depends on:
Reported: 2013-02-26 05:30 UTC by justin.lipton
Modified: 2015-05-03 23:07 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:

Test case demonstrating extra page break (22.93 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2013-02-26 05:30 UTC, justin.lipton
Test case showing bolding inheritance issue (9.87 KB, application/octet-stream)
2014-03-20 21:08 UTC, justin.lipton

Note You need to log in before you can comment on or make changes to this bug.
Description justin.lipton 2013-02-26 05:30:18 UTC
Created attachment 75547 [details]
Test case demonstrating extra page break

Please see the attached DOCX test case.
There is a style "Opening Words" defined as:
<w:style w:customStyle="1" w:styleId="OpeningWords" w:type="paragraph">
    <w:name w:val="Opening Words"/>
    <w:basedOn w:val="Normal"/>
    <w:rsid w:val="00FA22B5"/>

Then there is a second style "Opening Words NoPB" defined as:
<w:style w:customStyle="1" w:styleId="OpeningWordsNoPB" w:type="paragraph">
    <w:name w:val="Opening Words NoPB"/>
    <w:basedOn w:val="OpeningWords"/>
    <w:rsid w:val="00FA22B5"/>
      <w:pageBreakBefore w:val="0"/>
      <w:spacing w:before="480"/>

The style "Opening Words NoPB" should not have a page break before it and does not in Word but Libre office seems to ignore the <w:pageBreakBefore w:val="0"/>, treating it as if it was <w:pageBreakBefore w:val="1"/>

Other style removal traits seem to be working well such as removal of all caps and bold e.g.

<w:style w:customStyle="1" w:styleId="CPTitlenocapsnobold" w:type="paragraph">
    <w:name w:val="CP Title no caps no bold"/>
    <w:basedOn w:val="CPTitle"/>
    <w:rsid w:val="0089493E"/>
      <w:b w:val="0"/>
      <w:caps w:val="0"/>

The style definitions above are taken from the word/styles.xml component of the DOCX archive
Comment 1 Yifan Jiang 2013-02-26 09:14:09 UTC
Thanks for the nice reporting, this is reproduced.

To verify the problem, from user perspective, the document should have only one page containing all of text.
Comment 2 Cor Nouws 2014-02-06 11:41:23 UTC
Hi Justin, Yifan,

Can you pls explain what is the use-case of such a document?
I see no section breaks in Word, so what is the use of having three 'page-styles' on one page?
Or what do I miss :)

Comment 3 Cor Nouws 2014-02-06 11:43:41 UTC
oh, sorry, I see it now.
Was looking at page styles and it's about paragraph styles.
Comment 4 Chris Sherlock 2014-03-20 14:52:34 UTC
This appears to also be happening in one of our test documents. 

In the unit test sw_ooxmlexport, this tries to process zoom.docx.

In this document, it has the following in styles.xml:

  <w:style w:type="paragraph" w:customStyle="1"
    <w:name w:val="Text body" />
    <w:basedOn w:val="Normal" />
    <w:rsid w:val="00FA71A6" />
      <w:spacing w:after="120" />

Now I've stepped through the code, and the issue seems to be in SfxStyleSheetBase::SetFollow(), because we check to see if the <w:name> value (aName in the code) is the same as the styleId attribute of the <w:style> tag. 


We seem to do some sort of search to find a stylesheet of the name "Textbody", but actually we should be trying to find it based on the value of <w:baseOn>.
Comment 5 Chris Sherlock 2014-03-20 15:05:55 UTC
Ah! I see where we need to make the change. 

Problem is in lcl_SetStyleProperty(), which is part of sw/source/core/unocore/unostyle.cxx

The part that's wrong is:

   1800         case FN_UNO_FOLLOW_STYLE:
   1801         {
   1802             OUString sTmp;
   1803             rValue >>= sTmp;
   1804             OUString aString;
   1805             SwStyleNameMapper::FillUIName(sTmp, aString, lcl_GetSwEnumFromSfxEnum ( eFamily ), true ) ;
   1806             rBase.mxNewBase->SetFollow( aString );
   1807         }

Not sure yet, but I think the solution will be to use getPropertyValue to take the value of the <w:basedOn>. The we pass this to rBase.mxNewBase->SetFollow(). That should resolve the matter. 

We don't seem to support the <w:next> attribute though, which specifies the next paragraph's style. But that's another issue.
Comment 6 Chris Sherlock 2014-03-20 15:47:52 UTC
Drat. Looking at the code very wrongly. This is a different issue entirely. Sorry for the bugspam.
Comment 7 justin.lipton 2014-03-20 21:07:55 UTC
Changing the title on this one and upping the importance.
It seems that any style attributes that are inherited and are then over-written are ignored.
Another simple test case is attached where:
Style 1 is bold
Style 2 is based on style one but is not bold

in this case, Style 2, still renders bold.

This effect is most dramatic when effects like borders, page breaks, all caps etc. are used - the document can really render badly.
Style inheritance is a best practice in Word too - same reasons we do so in CSS. 

In the latest test case, the DOCX style definitions look like this:
<w:style w:customStyle="1" w:styleId="Style1" w:type="paragraph">
    <w:name w:val="Style1"/>
    <w:basedOn w:val="Normal"/>
    <w:rsid w:val="002C755C"/>
      <w:lang w:val="en-US"/>
  <w:style w:customStyle="1" w:styleId="Style2" w:type="paragraph">
    <w:name w:val="Style2"/>
    <w:basedOn w:val="Style1"/>
    <w:rsid w:val="002C755C"/>
      <w:b w:val="0"/>
Comment 8 justin.lipton 2014-03-20 21:08:55 UTC
Created attachment 96125 [details]
Test case showing bolding inheritance issue
Comment 9 Joel Madero 2015-05-02 15:42:37 UTC
** Please read this message in its entirety before responding **

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

   Test to see if the bug is still present on a currently supported version of LibreOffice (4.4.2 or later)

   If the bug is present, please leave a comment that includes the version of LibreOffice and your operating system, and any changes you see in the bug behavior
 If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a short comment that includes your version of LibreOffice and Operating System

Please DO NOT

   Update the version field
   Reply via email (please reply directly on the bug tracker)
   Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not appropriate in this case)

If you want to do more to help you can test to see if your issue is a REGRESSION. To do so: 1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3)


2. Test your bug 3. Leave a comment with your results. 4a. If the bug was present with 3.3 - set version to "inherited from OOo"; 4b. If the bug was not present in 3.3 - add "regression" to keyword

Feel free to come ask questions or to say hello in our QA chat: http://webchat.freenode.net/?channels=libreoffice-qa

Thank you for your help!

-- The LibreOffice QA Team This NEW Message was generated on: 2015-05-02
Comment 10 justin.lipton 2015-05-03 23:07:41 UTC
Version: on Windows 7 Professional
Both test cases worked as expected.