diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-06-05 00:19:06 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-06-08 14:51:57 +0200 |
commit | 486a11ad6fdae1714200229462b69f328be06b5a (patch) | |
tree | 592469c652c8919cc1e864d20ea10f5d5b8b167a /oox | |
parent | d0a1616ccad0dd5f5a02c1b0204f537b57d0b4b5 (diff) |
editengine-columns: PPTX support (tdf#118458)
The unit tests that used to check the workaround using tables to
emulate columns (implemented in tdf#120028) are changed to test
import of the columns.
This reverts some commits related to the mentioned workaround,
namely aef569ed83a3ccc02639e5b2a1c7cc131ba262fc,
c50ae6a282ed83762bf634fed5c91033eb305c88,
7b64bd90637a6722438bf873b1ded74ab3424c46,
33696b2820ce3c8b21b753d2c2bf92345ecb9276,
99dff69b561a8fe2d9437e6aa67a9581a6666f41.
Change-Id: I97693ad4a981780e822070938992f274920df5a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116738
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/inc/drawingml/table/tableproperties.hxx | 3 | ||||
-rw-r--r-- | oox/inc/drawingml/textbodyproperties.hxx | 2 | ||||
-rw-r--r-- | oox/source/drawingml/table/tableproperties.cxx | 61 | ||||
-rw-r--r-- | oox/source/drawingml/textbodypropertiescontext.cxx | 16 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 19 | ||||
-rw-r--r-- | oox/source/ppt/pptimport.cxx | 1 | ||||
-rw-r--r-- | oox/source/ppt/pptshape.cxx | 33 | ||||
-rw-r--r-- | oox/source/ppt/slidepersist.cxx | 33 | ||||
-rw-r--r-- | oox/source/token/properties.txt | 1 |
9 files changed, 38 insertions, 131 deletions
diff --git a/oox/inc/drawingml/table/tableproperties.hxx b/oox/inc/drawingml/table/tableproperties.hxx index ec8b3c4c5b60..34e361b18add 100644 --- a/oox/inc/drawingml/table/tableproperties.hxx +++ b/oox/inc/drawingml/table/tableproperties.hxx @@ -58,9 +58,6 @@ public: const css::uno::Reference < css::beans::XPropertySet > & xPropSet, const ::oox::drawingml::TextListStylePtr& pMasterTextListStyle ); - /// Distributes text body with multiple columns in table cells. - void pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sal_Int32 nShapeWidth, bool bhasSameSubTypeIndex, bool bMaster); - private: const TableStyle& getUsedTableStyle(const ::oox::core::XmlFilterBase& rFilterBase, std::unique_ptr<TableStyle>& rTableStyleToDelete); diff --git a/oox/inc/drawingml/textbodyproperties.hxx b/oox/inc/drawingml/textbodyproperties.hxx index 8a51c2bb906e..41fbb832a5d8 100644 --- a/oox/inc/drawingml/textbodyproperties.hxx +++ b/oox/inc/drawingml/textbodyproperties.hxx @@ -42,8 +42,6 @@ struct TextBodyProperties std::optional< sal_Int32 > moTextOffRight; css::drawing::TextVerticalAdjust meVA; OUString msPrst; - /// Number of requested columns. - sal_Int32 mnNumCol = 1; /// Normal autofit: font scale (default: 100%). sal_Int32 mnFontScale = 100000; OUString msHorzOverflow; diff --git a/oox/source/drawingml/table/tableproperties.cxx b/oox/source/drawingml/table/tableproperties.cxx index 1c12c10eda47..69117123dca8 100644 --- a/oox/source/drawingml/table/tableproperties.cxx +++ b/oox/source/drawingml/table/tableproperties.cxx @@ -145,7 +145,7 @@ void TableProperties::pushToPropSet(const ::oox::core::XmlFilterBase& rFilterBas for (auto& tableRow : mvTableRows) { sal_Int32 nColumn = 0; - sal_Int32 nColumnSize = mvTableGrid.size(); + sal_Int32 nColumnSize = tableRow.getTableCells().size(); sal_Int32 nRemovedColumn = 0; // for (sal_Int32 nColIndex = 0; nColIndex < nColumnSize; nColIndex++) @@ -206,65 +206,6 @@ void TableProperties::pushToPropSet(const ::oox::core::XmlFilterBase& rFilterBas xTableStyleToDelete.reset(); } - -void TableProperties::pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sal_Int32 nShapeWidth, bool bhasSameSubTypeIndex, bool bMaster) -{ - // Create table grid and a single row. - sal_Int32 nNumCol = pTextBody->getTextProperties().mnNumCol; - std::vector<sal_Int32>& rTableGrid(getTableGrid()); - std::vector<drawingml::table::TableRow>& rTableRows(getTableRows()); - sal_Int32 nColWidth = nShapeWidth / nNumCol; - - if(!bhasSameSubTypeIndex) - { - for (sal_Int32 nCol = 0; nCol < nNumCol; ++nCol) - rTableGrid.push_back(nColWidth); - - rTableRows.emplace_back(); - } - - if(rTableRows.empty()) - rTableRows.emplace_back(); - - oox::drawingml::table::TableRow& rTableRow = rTableRows.back(); - std::vector<oox::drawingml::table::TableCell>& rTableCells = rTableRow.getTableCells(); - - // Create the cells and distribute the paragraphs from pTextBody. - sal_Int32 nNumPara = pTextBody->getParagraphs().size(); - sal_Int32 nParaPerCol = std::ceil(double(nNumPara) / nNumCol); - // Font scale of text body will be applied at a text run level. - sal_Int32 nFontScale = pTextBody->getTextProperties().mnFontScale; - size_t nPara = 0; - for (sal_Int32 nCol = 0; nCol < nNumCol; ++nCol) - { - rTableCells.emplace_back(); - oox::drawingml::table::TableCell& rTableCell = rTableCells.at(nCol); - TextBodyPtr pCellTextBody = std::make_shared<TextBody>(); - rTableCell.setTextBody(pCellTextBody); - - // Copy properties provided by <a:lstStyle>. - pCellTextBody->getTextListStyle() = pTextBody->getTextListStyle(); - - if (bMaster) - continue; - - for (sal_Int32 nParaInCol = 0; nParaInCol < nParaPerCol; ++nParaInCol) - { - if (nPara < pTextBody->getParagraphs().size()) - { - std::shared_ptr<oox::drawingml::TextParagraph> pParagraph - = pTextBody->getParagraphs()[nPara]; - if (nFontScale != 100000) - { - for (auto& pRun : pParagraph->getRuns()) - pRun->getTextCharacterProperties().moFontScale = nFontScale; - } - pCellTextBody->appendParagraph(pParagraph); - } - ++nPara; - } - } -} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/textbodypropertiescontext.cxx b/oox/source/drawingml/textbodypropertiescontext.cxx index 4d94191dcfc7..f7d4abd4e685 100644 --- a/oox/source/drawingml/textbodypropertiescontext.cxx +++ b/oox/source/drawingml/textbodypropertiescontext.cxx @@ -22,16 +22,19 @@ #include <com/sun/star/text/WritingMode.hpp> #include <com/sun/star/drawing/TextFitToSizeType.hpp> #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> +#include <com/sun/star/text/XTextColumns.hpp> #include <drawingml/textbodyproperties.hxx> #include <drawingml/textbody.hxx> #include <drawingml/customshapegeometry.hxx> #include <drawingml/scene3dcontext.hxx> +#include <o3tl/unit_conversion.hxx> #include <oox/drawingml/drawingmltypes.hxx> #include <oox/helper/attributelist.hxx> #include <oox/helper/propertymap.hxx> #include <oox/token/namespaces.hxx> #include <oox/token/properties.hxx> #include <oox/token/tokens.hxx> +#include <svx/SvxXTextColumns.hxx> using namespace ::oox::core; using namespace ::com::sun::star; @@ -85,7 +88,18 @@ TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper cons mrTextBodyProp.msVertOverflow = rAttribs.getString(XML_vertOverflow, ""); // ST_TextColumnCount - mrTextBodyProp.mnNumCol = rAttribs.getInteger( XML_numCol, 1 ); + if (const sal_Int32 nColumns = rAttribs.getInteger(XML_numCol, 0); nColumns > 0) + { + css::uno::Reference<css::text::XTextColumns> xCols(SvxXTextColumns_createInstance(), + css::uno::UNO_QUERY_THROW); + xCols->setColumnCount(nColumns); + css::uno::Reference<css::beans::XPropertySet> xProps(xCols, css::uno::UNO_QUERY_THROW); + // ST_PositiveCoordinate32 + const sal_Int32 nSpacing = o3tl::convert(rAttribs.getInteger(XML_spcCol, 0), + o3tl::Length::emu, o3tl::Length::mm100); + xProps->setPropertyValue("AutomaticDistance", css::uno::Any(nSpacing)); + mrTextBodyProp.maPropertyMap.setAnyProperty(PROP_TextColumns, css::uno::Any(xCols)); + } // ST_Angle mrTextBodyProp.moRotation = rAttribs.getInteger( XML_rot ); diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 684623a41813..4d2212b2d50f 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -85,6 +85,7 @@ #include <com/sun/star/text/WritingMode2.hpp> #include <com/sun/star/text/GraphicCrop.hpp> #include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextColumns.hpp> #include <com/sun/star/text/XTextContent.hpp> #include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/text/XTextRange.hpp> @@ -3133,6 +3134,22 @@ void DrawingML::WriteText(const Reference<XInterface>& rXIface, bool bBodyPr, bo sal_Int32 nShapeTextRotateAngle = 0; if (GetProperty(xTextSet, "RotateAngle")) nShapeTextRotateAngle = rXPropSet->getPropertyValue("RotateAngle").get<sal_Int32>() / 300; + sal_Int16 nCols = 0; + sal_Int32 nColSpacing = -1; + if (GetProperty(rXPropSet, "TextColumns")) + { + if (css::uno::Reference<css::text::XTextColumns> xCols{ mAny, css::uno::UNO_QUERY }) + { + nCols = xCols->getColumnCount(); + if (css::uno::Reference<css::beans::XPropertySet> xProps{ mAny, + css::uno::UNO_QUERY }) + { + if (GetProperty(xProps, "AutomaticDistance")) + mAny >>= nColSpacing; + } + } + } + std::optional<OString> isUpright; if (GetProperty(rXPropSet, "InteropGrabBag")) { @@ -3187,6 +3204,8 @@ void DrawingML::WriteText(const Reference<XInterface>& rXIface, bool bBodyPr, bo } mpFS->startElementNS( (nXmlNamespace ? nXmlNamespace : XML_a), XML_bodyPr, + XML_numCol, sax_fastparser::UseIf(OString::number(nCols), nCols > 0), + XML_spcCol, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nColSpacing)), nCols > 0 && nColSpacing >= 0), XML_wrap, pWrap, XML_horzOverflow, sHorzOverflow, XML_vertOverflow, sVertOverflow, diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx index 573dbd0c4234..1f569d099876 100644 --- a/oox/source/ppt/pptimport.cxx +++ b/oox/source/ppt/pptimport.cxx @@ -70,7 +70,6 @@ PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxCont PowerPointImport::~PowerPointImport() { - maPPTShapes.clear(); } bool PowerPointImport::importDocument() diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index 2f346cca2192..1756ad9e32ab 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -116,8 +116,7 @@ void PPTShape::addShape( const oox::drawingml::Theme* pTheme, const Reference< XShapes >& rxShapes, basegfx::B2DHomMatrix& aTransformation, - ::oox::drawingml::ShapeIdMap* pShapeMap, - bool bhasSameSubTypeIndex ) + ::oox::drawingml::ShapeIdMap* pShapeMap ) { SAL_INFO("oox.ppt","add shape id: " << msId << " location: " << ((meShapeLocation == Master) ? "master" : ((meShapeLocation == Slide) ? "slide" : ((meShapeLocation == Layout) ? "layout" : "other"))) << " subtype: " << mnSubType << " service: " << msServiceName); // only placeholder from layout are being inserted @@ -227,36 +226,6 @@ void PPTShape::addShape( } } - if (sServiceName != "com.sun.star.drawing.TableShape") - { - if (TextBodyPtr pTextBody = getTextBody()) - { - // If slide shape has not numCol but placeholder has we should inherit from placeholder. - if (pTextBody->getTextProperties().mnNumCol == 1 && - mnSubType && - getSubTypeIndex().has() && - rSlidePersist.getMasterPersist()) - { - oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( - getSubTypeIndex().get(), - rSlidePersist.getMasterPersist()->getShapes()->getChildren()); - if (pPlaceholder && pPlaceholder->getTableProperties()) - pTextBody->getTextProperties().mnNumCol = pPlaceholder->getTableProperties()->getTableGrid().size(); - } - - sal_Int32 nNumCol = pTextBody->getTextProperties().mnNumCol; - if (nNumCol > 1) - { - // This shape is not a table, but has multiple columns, - // represent that as a table. - sServiceName = "com.sun.star.drawing.TableShape"; - oox::drawingml::table::TablePropertiesPtr pTableProperties = getTableProperties(); - pTableProperties->pullFromTextBody(pTextBody, maSize.Width, bhasSameSubTypeIndex, meShapeLocation == Layout); - setTextBody(nullptr); - } - } - } - SAL_INFO("oox.ppt","shape service: " << sServiceName); if (mnSubType && getSubTypeIndex().has() && meShapeLocation == Layout) diff --git a/oox/source/ppt/slidepersist.cxx b/oox/source/ppt/slidepersist.cxx index fae4e5541d96..ae9f0f567a7c 100644 --- a/oox/source/ppt/slidepersist.cxx +++ b/oox/source/ppt/slidepersist.cxx @@ -23,7 +23,6 @@ #include <com/sun/star/frame/XModel.hpp> #include <oox/ppt/timenode.hxx> #include <oox/ppt/pptshape.hxx> -#include <oox/ppt/pptimport.hxx> #include <oox/ppt/slidepersist.hxx> #include <drawingml/fillproperties.hxx> #include <oox/drawingml/shapepropertymap.hxx> @@ -35,7 +34,6 @@ #include <oox/core/xmlfilterbase.hxx> #include <drawingml/textliststyle.hxx> #include <drawingml/textparagraphproperties.hxx> -#include <drawingml/textbody.hxx> #include <osl/diagnose.h> @@ -54,8 +52,6 @@ using namespace ::com::sun::star::animations; namespace oox::ppt { -std::vector< PPTShape* > PowerPointImport::maPPTShapes; - SlidePersist::SlidePersist( XmlFilterBase& rFilter, bool bMaster, bool bNotes, const css::uno::Reference< css::drawing::XDrawPage >& rxPage, oox::drawingml::ShapePtr const & pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle ) @@ -132,29 +128,12 @@ sal_Int16 SlidePersist::getLayoutFromValueToken() const return nLayout; } -static bool hasSameSubTypeIndex(sal_Int32 checkSubTypeIndex) -{ - sal_Int32 nSubTypeIndex = -1; - for(PPTShape* pPPTShape : PowerPointImport::maPPTShapes) - { - if(!pPPTShape->getSubTypeIndex().has()) - continue; - - nSubTypeIndex = pPPTShape->getSubTypeIndex().get(); - - if( nSubTypeIndex == checkSubTypeIndex ) - return true; - } - return false; -} void SlidePersist::createXShapes( XmlFilterBase& rFilterBase ) { applyTextStyles( rFilterBase ); Reference< XShapes > xShapes( getPage() ); std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() ); - bool bhasSameSubTypeIndex = false; - sal_Int32 nNumCol = 1; for (auto const& shape : rShapes) { @@ -164,17 +143,7 @@ void SlidePersist::createXShapes( XmlFilterBase& rFilterBase ) PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() ); basegfx::B2DHomMatrix aTransformation; if ( pPPTShape ) - { - bhasSameSubTypeIndex = hasSameSubTypeIndex( pPPTShape->getSubTypeIndex().get()); - - if(pPPTShape->getTextBody()) - nNumCol = pPPTShape->getTextBody()->getTextProperties().mnNumCol; - - if(pPPTShape->getSubTypeIndex().has() && nNumCol > 1 ) - PowerPointImport::maPPTShapes.push_back(pPPTShape); - - pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap(), bhasSameSubTypeIndex ); - } + pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap() ); else child->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &getShapeMap() ); } diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index d50cd4bb124d..980c1bb8c0f2 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -528,6 +528,7 @@ TextBox TextBreak TextCameraZRotateAngle TextColor +TextColumns TextFitToSize TextFrames TextHorizontalAdjust |