oox/source/drawingml/table/predefined-table-styles.cxx | 2 oox/source/drawingml/table/tablecell.cxx | 59 ++++++++++------- sd/qa/unit/data/pptx/tdf151767.pptx |binary sd/qa/unit/export-tests-ooxml3.cxx | 28 ++++---- sd/qa/unit/import-tests.cxx | 30 ++++++++ 5 files changed, 83 insertions(+), 36 deletions(-)
New commits: commit d83a016823dceaeb48f34d4e94f9a230bebd9169 Author: Tibor Nagy <nagy.tib...@nisz.hu> AuthorDate: Wed Oct 26 16:44:01 2022 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Thu Oct 27 20:35:01 2022 +0200 tdf#151767 PPTX import: fix table border width There is a "Clear Table" function in PP. In this case, the table uses the default border value of MSO, which was imported as missing table border. (Note: commit ff0387e726b59e374029d2f635ce00308d99eff6 "tdf#135843: sd_export_tests-ooxml3: Add unittest for the export part" If attachment from tdf#106011 is opened in PowerPoint, the table is visible it, but was not in LO. This patch fixed that. Therefore the borders of table are not missing after export.) Change-Id: I92dfe2e42f5f58b15af23cc24e931fb12d7c2794 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141880 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/oox/source/drawingml/table/predefined-table-styles.cxx b/oox/source/drawingml/table/predefined-table-styles.cxx index 7d420038856a..531e20b14512 100644 --- a/oox/source/drawingml/table/predefined-table-styles.cxx +++ b/oox/source/drawingml/table/predefined-table-styles.cxx @@ -884,6 +884,8 @@ std::unique_ptr<TableStyle> CreateTableStyle(const OUString& styleId) // End to handle all style groups. // Create a TableStyle from handled properties. + pTableStyle->getStyleId() = styleId; + pTableStyle->getStyleName() = style_name; pTableStyle->getWholeTbl().getTextColor() = wholeTblTextColor; pTableStyle->getFirstRow().getTextColor() = firstRowTextColor; diff --git a/oox/source/drawingml/table/tablecell.cxx b/oox/source/drawingml/table/tablecell.cxx index 77b69b8e4e3e..17b13526084d 100644 --- a/oox/source/drawingml/table/tablecell.cxx +++ b/oox/source/drawingml/table/tablecell.cxx @@ -61,26 +61,41 @@ TableCell::TableCell() { } -static void applyLineAttributes( const ::oox::core::XmlFilterBase& rFilterBase, - Reference< XPropertySet > const & rxPropSet, oox::drawingml::LineProperties const & rLineProperties, - sal_Int32 nPropId ) +static void applyLineAttributes(const ::oox::core::XmlFilterBase& rFilterBase, + Reference<XPropertySet> const& rxPropSet, + oox::drawingml::table::TableStyle const& rTableStyle, + oox::drawingml::LineProperties const& rLineProperties, + sal_Int32 nPropId) { BorderLine2 aBorderLine; - if ( rLineProperties.maLineFill.moFillType.has_value() && rLineProperties.maLineFill.moFillType.value() != XML_noFill ) + TableStyle& rTable(const_cast<TableStyle&>(rTableStyle)); + if (!rTable.getStyleId().isEmpty()) { Color aColor = rLineProperties.maLineFill.getBestSolidColor(); - aBorderLine.Color = sal_Int32(aColor.getColor( rFilterBase.getGraphicHelper() )); - aBorderLine.OuterLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.value_or( 0 ) ) / 4 ); - aBorderLine.InnerLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.value_or( 0 ) ) / 4 ); - aBorderLine.LineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.value_or( 0 ) ) / 2 ); + aBorderLine.Color = sal_Int32(aColor.getColor(rFilterBase.getGraphicHelper())); + aBorderLine.OuterLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 4); + aBorderLine.InnerLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 4); + aBorderLine.LineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 2); aBorderLine.LineDistance = 0; } else { - aBorderLine.Color = sal_Int32( COL_AUTO ); - aBorderLine.OuterLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.value_or( 0 ) ) / 4 ); - aBorderLine.InnerLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.value_or( 0 ) ) / 4 ); - aBorderLine.LineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.value_or( 0 ) ) / 2 ); + if (rLineProperties.maLineFill.moFillType.has_value()) + { + if (rLineProperties.maLineFill.moFillType.value() != XML_noFill) + { + Color aColor = rLineProperties.maLineFill.getBestSolidColor(); + aBorderLine.Color = sal_Int32(aColor.getColor(rFilterBase.getGraphicHelper())); + } + else + aBorderLine.Color = sal_Int32(COL_AUTO); + } + else + aBorderLine.Color = sal_Int32(COL_BLACK); + + aBorderLine.OuterLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 4); + aBorderLine.InnerLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 4); + aBorderLine.LineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 2); aBorderLine.LineDistance = 0; } @@ -475,33 +490,33 @@ void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, cons aLinePropertiesTopLeftToBottomRight.assignUsed( maLinePropertiesTopLeftToBottomRight ); aLinePropertiesBottomLeftToTopRight.assignUsed( maLinePropertiesBottomLeftToTopRight ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesLeft, PROP_LeftBorder ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesRight, PROP_RightBorder ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTop, PROP_TopBorder ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottom, PROP_BottomBorder ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesLeft, PROP_LeftBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesRight, PROP_RightBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesTop, PROP_TopBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesBottom, PROP_BottomBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR ); // Convert insideH to Top and Bottom, InsideV to Left and Right. Exclude the outer borders. if(nRow != 0) { aLinePropertiesInsideH.assignUsed( aLinePropertiesTop ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesInsideH, PROP_TopBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideH, PROP_TopBorder ); } if(nRow != nMaxRow) { aLinePropertiesInsideH.assignUsed( aLinePropertiesBottom ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesInsideH, PROP_BottomBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideH, PROP_BottomBorder ); } if(nColumn != 0) { aLinePropertiesInsideV.assignUsed( aLinePropertiesLeft ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesInsideV, PROP_LeftBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideV, PROP_LeftBorder ); } if(nColumn != nMaxColumn) { aLinePropertiesInsideV.assignUsed( aLinePropertiesRight ); - applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesInsideV, PROP_RightBorder ); + applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideV, PROP_RightBorder ); } if (rProperties.getBgColor().isUsed() && !maFillProperties.maFillColor.isUsed() && diff --git a/sd/qa/unit/data/pptx/tdf151767.pptx b/sd/qa/unit/data/pptx/tdf151767.pptx new file mode 100644 index 000000000000..689a641701a5 Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf151767.pptx differ diff --git a/sd/qa/unit/export-tests-ooxml3.cxx b/sd/qa/unit/export-tests-ooxml3.cxx index 128528f15844..aa0249a56d7d 100644 --- a/sd/qa/unit/export-tests-ooxml3.cxx +++ b/sd/qa/unit/export-tests-ooxml3.cxx @@ -1232,20 +1232,20 @@ void SdOOXMLExportTest3::testTdf135843() xmlDocUniquePtr pXmlDoc = parseExport(tempFile, "ppt/slides/slide1.xml"); const OString sPathStart("/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnL/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnR/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnT/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnB/a:noFill"); - - assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnL/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnR/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnT/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnB/a:noFill"); - - assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnL/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnR/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnT/a:noFill"); - assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnB/a:noFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnL/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnR/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnT/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[1]/a:tc[1]/a:tcPr/a:lnB/a:solidFill"); + + assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnL/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnR/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnT/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[2]/a:tc[1]/a:tcPr/a:lnB/a:solidFill"); + + assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnL/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnR/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnT/a:solidFill"); + assertXPath(pXmlDoc, sPathStart + "/a:tr[3]/a:tc[1]/a:tcPr/a:lnB/a:solidFill"); } void SdOOXMLExportTest3::testSmartArtPreserve() diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index 4c2742a34521..5de224453d53 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -153,6 +153,7 @@ public: void testTdf62255(); void testTdf89927(); void testTdf103800(); + void testTdf151767(); CPPUNIT_TEST_SUITE(SdImportTest); @@ -226,6 +227,7 @@ public: CPPUNIT_TEST(testTdf62255); CPPUNIT_TEST(testTdf89927); CPPUNIT_TEST(testTdf103800); + CPPUNIT_TEST(testTdf151767); CPPUNIT_TEST_SUITE_END(); }; @@ -1962,6 +1964,34 @@ void SdImportTest::testTdf103800() xDocShRef->DoClose(); } +void SdImportTest::testTdf151767() +{ + sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf151767.pptx"), PPTX); + + const SdrPage* pPage = GetPage(1, xDocShRef); + sdr::table::SdrTableObj* pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0)); + uno::Reference<table::XCellRange> xTable(pTableObj->getTable(), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xCell(xTable->getCellByPosition(0, 0), uno::UNO_QUERY_THROW); + + table::BorderLine2 aLeft; + xCell->getPropertyValue("LeftBorder") >>= aLeft; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The left border is missing!", true, aLeft.LineWidth > 0); + + table::BorderLine2 aRight; + xCell->getPropertyValue("RightBorder") >>= aRight; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The right border is missing!", true, aRight.LineWidth > 0); + + table::BorderLine2 aTop; + xCell->getPropertyValue("TopBorder") >>= aTop; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The top border is missing!", true, aTop.LineWidth > 0); + + table::BorderLine2 aBottom; + xCell->getPropertyValue("BottomBorder") >>= aBottom; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The bottom border is missing!", true, aBottom.LineWidth > 0); + + xDocShRef->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest); CPPUNIT_PLUGIN_IMPLEMENT();