diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-11-01 14:11:09 +0500 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-12-07 15:29:16 +0100 |
commit | 1b4b1e0659d7dff79d031ff5c8fbb34fad2c71a1 (patch) | |
tree | b227856b2d9ddf446a3513e7b9c294c6d9d84201 | |
parent | 4d4bbb85c74869f4e9ea8a89bfc046fa2e8c081a (diff) |
tdf#163703: export formats for FIELD_ID_ANNOTATION
It was omitted from commit 842160190e2996efbd936191eed787f3f79ed7b7
(INTEGRATION: CWS notes2 (1.77.24); FILE MERGED, 2008-02-19), and
the field type was skipped from autostyle export phase. With commit
69ed893087f89d176a5ec4b263ce8d75774be72b (tdf#160253: fix list
identifier export decision code, 2024-04-24), this surfaced by not
exporting comments' formatting.
Change-Id: I84a8d5616c37af093404fefb4d1ed3a212000f8d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175899
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175931
-rw-r--r-- | sw/qa/extras/odfexport/data/italics-in-comment.fodt | 29 | ||||
-rw-r--r-- | sw/qa/extras/odfexport/odfexport2.cxx | 35 | ||||
-rw-r--r-- | xmloff/source/text/txtflde.cxx | 30 |
3 files changed, 82 insertions, 12 deletions
diff --git a/sw/qa/extras/odfexport/data/italics-in-comment.fodt b/sw/qa/extras/odfexport/data/italics-in-comment.fodt new file mode 100644 index 000000000000..5bf227f3a1f4 --- /dev/null +++ b/sw/qa/extras/odfexport/data/italics-in-comment.fodt @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible: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:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:font-face-decls> + <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/> + </office:font-face-decls> + <office:styles> + <style:default-style style:family="paragraph"> + <style:text-properties style:font-name="Liberation Serif" fo:font-size="12pt"/> + </style:default-style> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:style style:name="Comment" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> + <style:paragraph-properties fo:margin-left="1mm" fo:margin-right="1mm" fo:margin-top="1mm" fo:margin-bottom="0"/> + <style:text-properties fo:font-size="10pt"/> + </style:style> + </office:styles> + <office:automatic-styles> + <style:style style:name="T1" style:family="text"> + <style:text-properties fo:font-style="italic"/> + </style:style> + </office:automatic-styles> + <office:body> + <office:text> + <text:p><office:annotation> + <text:p text:style-name="Comment">lo<text:span text:style-name="T1">r</text:span>em</text:p> + </office:annotation></text:p> + </office:text> + </office:body> +</office:document>
\ No newline at end of file diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index e13119cffe07..219561f30287 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -9,6 +9,7 @@ #include <swmodeltestbase.hxx> +#include <com/sun/star/awt/FontSlant.hpp> #include <com/sun/star/drawing/BarCode.hpp> #include <com/sun/star/drawing/BarCodeErrorCorrection.hpp> #include <com/sun/star/drawing/GraphicExportFilter.hpp> @@ -1719,6 +1720,40 @@ CPPUNIT_TEST_FIXTURE(Test, testMidnightRedlineDatetime) u"2001-01-01T00:00:00"_ustr); } +CPPUNIT_TEST_FIXTURE(Test, testTdf163703) +{ + // Given a document with italics autostyle in a comment + loadAndReload("italics-in-comment.fodt"); + + auto xFields( + mxComponent.queryThrow<text::XTextFieldsSupplier>()->getTextFields()->createEnumeration()); + auto xComment(xFields->nextElement().queryThrow<text::XTextContent>()); + CPPUNIT_ASSERT(xComment.queryThrow<lang::XServiceInfo>()->supportsService( + u"com.sun.star.text.textfield.Annotation"_ustr)); + + auto xCommentText(getProperty<uno::Reference<css::text::XText>>(xComment, u"TextRange"_ustr)); + CPPUNIT_ASSERT(xCommentText); + CPPUNIT_ASSERT_EQUAL(1, getParagraphs(xCommentText)); + auto xCommentPara(getParagraphOrTable(1, xCommentText).queryThrow<css::text::XTextRange>()); + CPPUNIT_ASSERT_EQUAL(u"lorem"_ustr, xCommentPara->getString()); + + // Without the fix, this would fail with + // - Expected: lo + // - Actual : lorem + // - run does not contain expected content + // because direct formatting was dropped on export, and the comment was exported in one chunk + auto x1stRun = getRun(xCommentPara, 1, "lo"); + CPPUNIT_ASSERT_EQUAL(css::awt::FontSlant_NONE, + getProperty<css::awt::FontSlant>(x1stRun, u"CharPosture"_ustr)); + + auto x2ndRun = getRun(xCommentPara, 2, "r"); + CPPUNIT_ASSERT_EQUAL(css::awt::FontSlant_ITALIC, + getProperty<css::awt::FontSlant>(x2ndRun, u"CharPosture"_ustr)); + + auto x3rdRun = getRun(xCommentPara, 3, "em"); + CPPUNIT_ASSERT_EQUAL(css::awt::FontSlant_NONE, + getProperty<css::awt::FontSlant>(x3rdRun, u"CharPosture"_ustr)); +} } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index 80a98f3dc5c6..1c8d9fb56847 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -176,6 +176,18 @@ uno::Reference<text::XText> GetToplevelText(const uno::Reference<text::XText>& x } return xRet; } + +uno::Reference<css::text::XText> XTextFromTextRangeProp(const Reference<XPropertySet>& xPropSet) +{ + try + { + return xPropSet->getPropertyValue(u"TextRange"_ustr).query<css::text::XText>(); + } + catch (css::uno::Exception&) + { + return {}; + } +} } SvXMLEnumStringMapEntry<FieldIdEnum> const aFieldServiceNameMapping[] = @@ -368,7 +380,6 @@ constexpr OUString gsPropertyValue(u"Value"_ustr); constexpr OUString gsPropertyVariableName(u"VariableName"_ustr); constexpr OUString gsPropertyHelp(u"Help"_ustr); constexpr OUString gsPropertyTooltip(u"Tooltip"_ustr); -constexpr OUStringLiteral gsPropertyTextRange(u"TextRange"); XMLTextFieldExport::XMLTextFieldExport( SvXMLExport& rExp, std::unique_ptr<XMLPropertyState> pCombinedCharState) @@ -909,8 +920,12 @@ void XMLTextFieldExport::ExportFieldAutoStyle( break; } - case FIELD_ID_SCRIPT: case FIELD_ID_ANNOTATION: + if (auto xText = XTextFromTextRangeProp(xPropSet)) + GetExport().GetTextParagraphExport()->collectTextAutoStyles(xText, bProgress); + break; + + case FIELD_ID_SCRIPT: case FIELD_ID_BIBLIOGRAPHY: case FIELD_ID_DDE: case FIELD_ID_REF_REFERENCE: @@ -1837,16 +1852,7 @@ void XMLTextFieldExport::ExportFieldHelper( } } - css::uno::Reference < css::text::XText > xText; - try - { - css::uno::Any aRet = rPropSet->getPropertyValue(gsPropertyTextRange); - aRet >>= xText; - } - catch ( css::uno::Exception& ) - {} - - if ( xText.is() ) + if (auto xText = XTextFromTextRangeProp(rPropSet)) GetExport().GetTextParagraphExport()->exportText( xText ); else ProcessParagraphSequence(GetStringProperty(gsPropertyContent,rPropSet)); |