From 10c85f825f1fb5989490ec731fdba036c0b8e247 Mon Sep 17 00:00:00 2001 From: Szabolcs Toth Date: Tue, 8 Oct 2019 11:21:50 +0200 Subject: tdf#123339 XLSX: fix horizontal alignment in comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Import and export of VML element TextHAlign weren't supported by Calc, losing horizontal aligment of the comments assigned to the spreadsheet cells. Change-Id: I41766d3004dd07ab34a2619e28532281366bf235 Reviewed-on: https://gerrit.libreoffice.org/79963 Tested-by: Jenkins Reviewed-by: László Németh --- sc/qa/unit/data/ods/CommentTextHAlign.ods | Bin 0 -> 7749 bytes sc/qa/unit/subsequent_export-test.cxx | 19 +++++++++++++++++++ sc/source/filter/oox/commentsbuffer.cxx | 16 ++++++++++++++++ sc/source/filter/xcl97/xcl97rec.cxx | 17 +++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 sc/qa/unit/data/ods/CommentTextHAlign.ods (limited to 'sc') diff --git a/sc/qa/unit/data/ods/CommentTextHAlign.ods b/sc/qa/unit/data/ods/CommentTextHAlign.ods new file mode 100644 index 000000000000..2132779cb76a Binary files /dev/null and b/sc/qa/unit/data/ods/CommentTextHAlign.ods differ diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index eaadde60f558..4c53441de68a 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -223,6 +223,7 @@ public: void testTdf126024XLSX(); void testTdf126177XLSX(); void testCommentTextVAlignment(); + void testCommentTextHAlignment(); void testXltxExport(); @@ -351,6 +352,7 @@ public: CPPUNIT_TEST(testTdf126024XLSX); CPPUNIT_TEST(testTdf126177XLSX); CPPUNIT_TEST(testCommentTextVAlignment); + CPPUNIT_TEST(testCommentTextHAlignment); CPPUNIT_TEST(testXltxExport); @@ -4504,6 +4506,23 @@ void ScExportTest::testCommentTextVAlignment() assertXPathContent(pVmlDrawing, "/xml/v:shape/xx:ClientData/xx:TextVAlign", "Center"); } +void ScExportTest::testCommentTextHAlignment() +{ + // Testing comment text alignments. + ScDocShellRef xShell = loadDoc("CommentTextHAlign.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + const xmlDocPtr pVmlDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml"); + CPPUNIT_ASSERT(pVmlDrawing); + + assertXPathContent(pVmlDrawing, "/xml/v:shape/xx:ClientData/xx:TextHAlign", "Center"); +} + + CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/filter/oox/commentsbuffer.cxx b/sc/source/filter/oox/commentsbuffer.cxx index 00045842c9fd..c3c60c3f5a6d 100644 --- a/sc/source/filter/oox/commentsbuffer.cxx +++ b/sc/source/filter/oox/commentsbuffer.cxx @@ -77,6 +77,21 @@ static sal_Int32 lcl_ToVertAlign( sal_Int32 nAlign ) } } +static sal_Int16 lcl_ToParaAlign(sal_Int32 nAlign) +{ + switch ( nAlign ) + { + case XML_Left: + return sal_Int16(css::style::ParagraphAdjust_LEFT); + case XML_Right: + return sal_Int16(css::style::ParagraphAdjust_RIGHT); + case XML_Center: + return sal_Int16(css::style::ParagraphAdjust_CENTER); + default: + return sal_Int16(css::style::ParagraphAdjust_BLOCK); + } +} + CommentModel::CommentModel() : mnAuthorId(-1) , mbAutoFill(false) @@ -171,6 +186,7 @@ void Comment::finalizeImport() // Setting comment text alignment const ::oox::vml::ClientData* xClientData = pNoteShape->getClientData(); aCommentPr.setProperty(PROP_TextVerticalAdjust, lcl_ToVertAlign(xClientData->mnTextVAlign)); + aCommentPr.setProperty(PROP_ParaAdjust, lcl_ToParaAlign(xClientData->mnTextHAlign)); } xAnno->setIsVisible( bVisible ); diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx index f750fdb9ad6c..3384e305185e 100644 --- a/sc/source/filter/xcl97/xcl97rec.cxx +++ b/sc/source/filter/xcl97/xcl97rec.cxx @@ -624,6 +624,21 @@ sal_Int32 VmlCommentExporter::StartShape() return nId; } +static const char* lcl_GetHorizAlignFromItemSetChar(const SfxItemSet& rItemSet) +{ + switch (rItemSet.Get(EE_PARA_JUST).GetAdjust()) + { + case SvxAdjust::Center: + return "Center"; + case SvxAdjust::Right: + return "Right"; + case SvxAdjust::Block: + return "Justify"; + default: + return "Left"; + } +} + static const char* lcl_GetVertAlignFromItemSetChar( const SfxItemSet& rItemSet ) { switch( rItemSet.Get( SDRATTR_TEXT_VERTADJUST ).GetValue() ) @@ -650,6 +665,7 @@ void VmlCommentExporter::EndShape( sal_Int32 nShapeElement ) // Getting comment text alignments const char* pVertAlign = lcl_GetVertAlignFromItemSetChar(mpCaption->GetMergedItemSet()); + const char* pHorizAlign = lcl_GetHorizAlignFromItemSetChar(mpCaption->GetMergedItemSet()); pVmlDrawing->startElement(FSNS(XML_x, XML_ClientData), XML_ObjectType, "Note"); pVmlDrawing->singleElement(FSNS(XML_x, XML_MoveWithCells)); @@ -657,6 +673,7 @@ void VmlCommentExporter::EndShape( sal_Int32 nShapeElement ) XclXmlUtils::WriteElement( pVmlDrawing, FSNS( XML_x, XML_Anchor ), pAnchor ); XclXmlUtils::WriteElement( pVmlDrawing, FSNS( XML_x, XML_AutoFill ), "False" ); XclXmlUtils::WriteElement( pVmlDrawing, FSNS( XML_x, XML_TextVAlign ), pVertAlign ); + XclXmlUtils::WriteElement( pVmlDrawing, FSNS( XML_x, XML_TextHAlign ), pHorizAlign ); XclXmlUtils::WriteElement( pVmlDrawing, FSNS( XML_x, XML_Row ), maScPos.Row() ); XclXmlUtils::WriteElement( pVmlDrawing, FSNS(XML_x, XML_Column), sal_Int32(maScPos.Col())); if(mbVisible) -- cgit