tdf#163894 sw DOCX: fix style-ref with character style

Refer only the text formatted by character style instead
of the whole paragraph text content, when style-ref
field is used with character styles. Since a continuous
text can consist of several hints, concatenate them.

This fixes OOXML/DOCX interoperability, when not the
full paragraph is formatted with the referred character
style (see also DOCX unit tests of the upcoming commits).

Follow-up to commit d4fdafa103
"tdf#160402 writerfilter,sw: STYLEREF field can refer to character
style" and commit 32c588dd11
"tdf#86790: Add support for a word-style styleref".

Change-Id: I73f7a23e0124894c9fdcae516473caac0b5e4169
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199589
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: Jenkins
This commit is contained in:
László Németh
2026-02-18 13:49:03 +01:00
parent d6a656b8d9
commit 955f0f9b5e
3 changed files with 54 additions and 4 deletions
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:rpt="http://openoffice.org/2005/report" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.text">
<office:settings>
</office:settings>
<office:styles>
<style:style style:name="Emphasis" style:family="text">
<style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/>
</style:style>
</office:styles>
<office:automatic-styles>
<style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
<style:paragraph-properties style:writing-mode="lr-tb"/>
</style:style>
</office:automatic-styles>
<office:master-styles>
<style:master-page style:name="Standard">
<style:header>
<text:p text:style-name="Header">Styleref: <loext:style-ref text:reference-format="text" text:ref-name="Emphasis">Etiam eget dui. </loext:style-ref></text:p>
</style:header>
</style:master-page>
</office:master-styles>
<office:body>
<office:text>
<text:p text:style-name="P1"><text:span text:style-name="T2">Mauris </text:span><text:span text:style-name="Emphasis"><text:span text:style-name="T2">Etiam eget dui. </text:span></text:span><text:span text:style-name="Emphasis"><text:span text:style-name="T1">A</text:span></text:span><text:span text:style-name="Emphasis"><text:span text:style-name="T2">liquet pede. </text:span></text:span><text:span text:style-name="Emphasis">Donec. </text:span>Suspendisse dui purus. Ut nonummy.</text:p>
</office:text>
</office:body>
</office:document>
+10
View File
@@ -1406,6 +1406,16 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf40277)
CPPUNIT_ASSERT(xSpell->isValid(sWord3, static_cast<sal_uInt16>(eLang), aProperties));
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf163894)
{
createSwDoc("tdf163894.fodt");
xmlDocUniquePtr pLayout = parseLayoutDump();
// This was "Mauris ... nonummy.", i.e. full text of the paragraph containing the text
// formatted by the character style "Emphasis"
assertXPath(pLayout, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
"expand", u"Etiam eget dui. Aliquet pede. Donec. ");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testRedlineNumberInFootnote)
{
createSwDoc("tdf85610.fodt");
+16 -4
View File
@@ -632,8 +632,8 @@ void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, SwFrame* pFra
return;
case ReferencesSubtype::Style:
nStart = 0;
nEnd = nLen;
nStart = nNumStart;
nEnd = nNumEnd;
break;
default:
@@ -1316,6 +1316,7 @@ namespace
return pTextNode;
}
bool bHasHint = false;
if (auto const pHints = pTextNode->GetpSwpHints())
{
for (size_t i = 0, nCnt = pHints->Count(); i < nCnt; ++i)
@@ -1327,15 +1328,26 @@ namespace
? pHint->GetCharFormat().GetCharFormat()->HasName(rStyleName)
: pHint->GetCharFormat().GetCharFormat()->GetName().toString().equalsIgnoreAsciiCase(rStyleName))
{
*pStart = pHint->GetStart();
if ( !bHasHint )
{
*pStart = pHint->GetStart();
bHasHint = true;
}
// if the next hint is not adjacent, return with the last end stored in pEnd,
// i.e. with the first continuous text in the paragraph, which is formatted
// with the requested character style
else if ( !pEnd || *pEnd != pHint->GetStart() )
return pTextNode;
if (pEnd)
{
*pEnd = *pHint->End();
}
return pTextNode;
}
}
}
if ( bHasHint )
return pTextNode;
}
return nullptr;