summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-09-21 11:50:57 +0200
committerAndras Timar <andras.timar@collabora.com>2018-10-02 21:02:38 +0200
commit6f1fb474694876bc4ffeb552dcc7bed8f32cd221 (patch)
tree0a568258c3d99132d2057013b6f13501477abb23
parentc5d9823a5726d06aaa816360bc0d48e7ae882085 (diff)
tdf#120028 PPTX import: map shapes with multiple columns to table shapes
This is a combination of 3 commits. 1st commit: Longer term the core Impress shape has to be improved so that it can have text in multiple columns. Shorter term, map text with multiple columns to table shapes, that gives correct layout in many cases and requires changes to the import filter only. (cherry picked from commit aef569ed83a3ccc02639e5b2a1c7cc131ba262fc) Commit #2: Related: tdf#120028 PPTX import: fix font size of multi-col shape text Normal shapes have a TextFitToSize property for this, but table cell content has to be scaled manually, as the rendering has no automatic support for them. Luckily the file format has the info we need to scale at import time. (cherry picked from commit c8b2849d140677f7b35523096eb2bc715b3dc507) Commit #3: Related: tdf#120028 PPTX import: fix font color of multi-col shape text Not just font color, anything defined via list styles were not imported. (cherry picked from commit 800bf1071a30955ff70373b2fb5886eadce59dee) Conflicts: oox/inc/drawingml/textbodyproperties.hxx Change-Id: Id7942b16882ab1f083ded2f0e577e8c9e128697c Reviewed-on: https://gerrit.libreoffice.org/61244 Tested-by: Jenkins Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--oox/inc/drawingml/table/tableproperties.hxx3
-rw-r--r--oox/inc/drawingml/textbody.hxx2
-rw-r--r--oox/inc/drawingml/textbodyproperties.hxx4
-rw-r--r--oox/inc/drawingml/textcharacterproperties.hxx2
-rw-r--r--oox/source/drawingml/table/tableproperties.cxx48
-rw-r--r--oox/source/drawingml/textbody.cxx5
-rw-r--r--oox/source/drawingml/textbodypropertiescontext.cxx7
-rw-r--r--oox/source/drawingml/textcharacterproperties.cxx3
-rw-r--r--oox/source/ppt/pptshape.cxx18
-rw-r--r--sd/qa/unit/data/pptx/tdf120028.pptxbin0 -> 30465 bytes
-rw-r--r--sd/qa/unit/data/pptx/tdf120028b.pptxbin0 -> 29838 bytes
-rw-r--r--sd/qa/unit/import-tests.cxx77
12 files changed, 167 insertions, 2 deletions
diff --git a/oox/inc/drawingml/table/tableproperties.hxx b/oox/inc/drawingml/table/tableproperties.hxx
index 578230daa876..cdd905b809ff 100644
--- a/oox/inc/drawingml/table/tableproperties.hxx
+++ b/oox/inc/drawingml/table/tableproperties.hxx
@@ -60,6 +60,9 @@ 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);
+
private:
const TableStyle& getUsedTableStyle(const ::oox::core::XmlFilterBase& rFilterBase, TableStyle*& rTableStyleToDelete);
diff --git a/oox/inc/drawingml/textbody.hxx b/oox/inc/drawingml/textbody.hxx
index c2b0c5acc762..835f1c34b792 100644
--- a/oox/inc/drawingml/textbody.hxx
+++ b/oox/inc/drawingml/textbody.hxx
@@ -45,6 +45,8 @@ public:
const TextParagraphVector& getParagraphs() const { return maParagraphs; }
TextParagraph& addParagraph();
+ /// Appends an existing paragraph to this text body.
+ void appendParagraph(std::shared_ptr<TextParagraph> pTextParagraph);
const TextListStyle& getTextListStyle() const { return maTextListStyle; }
TextListStyle& getTextListStyle() { return maTextListStyle; }
diff --git a/oox/inc/drawingml/textbodyproperties.hxx b/oox/inc/drawingml/textbodyproperties.hxx
index bcb75546a688..0f066bb7556e 100644
--- a/oox/inc/drawingml/textbodyproperties.hxx
+++ b/oox/inc/drawingml/textbodyproperties.hxx
@@ -41,6 +41,10 @@ struct TextBodyProperties
boost::optional< sal_Int32 > moTextOffLower;
boost::optional< sal_Int32 > moTextOffRight;
css::drawing::TextVerticalAdjust meVA;
+ /// Number of requested columns.
+ sal_Int32 mnNumCol = 1;
+ /// Normal autofit: font scale (default: 100%).
+ sal_Int32 mnFontScale = 100000;
explicit TextBodyProperties();
diff --git a/oox/inc/drawingml/textcharacterproperties.hxx b/oox/inc/drawingml/textcharacterproperties.hxx
index 4dfab74e3c1f..a034121e47d0 100644
--- a/oox/inc/drawingml/textcharacterproperties.hxx
+++ b/oox/inc/drawingml/textcharacterproperties.hxx
@@ -47,6 +47,8 @@ struct TextCharacterProperties
Color maHighlightColor;
OptValue< OUString > moLang;
OptValue< sal_Int32 > moHeight;
+ /// If a font scale has to be applied manually to moHeight.
+ OptValue< double > moFontScale;
OptValue< sal_Int32 > moSpacing;
OptValue< sal_Int32 > moUnderline;
OptValue< sal_Int32 > moBaseline;
diff --git a/oox/source/drawingml/table/tableproperties.cxx b/oox/source/drawingml/table/tableproperties.cxx
index 527b65829d17..8f8993ad0035 100644
--- a/oox/source/drawingml/table/tableproperties.cxx
+++ b/oox/source/drawingml/table/tableproperties.cxx
@@ -19,6 +19,8 @@
#include <drawingml/table/tableproperties.hxx>
#include <drawingml/table/tablestylelist.hxx>
+#include <drawingml/textbody.hxx>
+#include <drawingml/textparagraph.hxx>
#include <oox/drawingml/drawingmltypes.hxx>
#include <com/sun/star/table/XTable.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
@@ -311,6 +313,52 @@ void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBa
delete pTableStyleToDelete;
}
+void TableProperties::pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sal_Int32 nShapeWidth)
+{
+ // Create table grid and a single row.
+ sal_Int32 nNumCol = pTextBody->getTextProperties().mnNumCol;
+ std::vector<sal_Int32>& rTableGrid(getTableGrid());
+ sal_Int32 nColWidth = nShapeWidth / nNumCol;
+ for (sal_Int32 nCol = 0; nCol < nNumCol; ++nCol)
+ rTableGrid.push_back(nColWidth);
+ std::vector<drawingml::table::TableRow>& rTableRows(getTableRows());
+ 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.back();
+ TextBodyPtr pCellTextBody(new TextBody);
+ rTableCell.setTextBody(pCellTextBody);
+
+ // Copy properties provided by <a:lstStyle>.
+ pCellTextBody->getTextListStyle() = pTextBody->getTextListStyle();
+
+ 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/textbody.cxx b/oox/source/drawingml/textbody.cxx
index eb27bda831ac..72b7ef752c07 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -54,6 +54,11 @@ TextParagraph& TextBody::addParagraph()
return *xPara;
}
+void TextBody::appendParagraph(std::shared_ptr<TextParagraph> pTextParagraph)
+{
+ maParagraphs.push_back(pTextParagraph);
+}
+
void TextBody::insertAt(
const ::oox::core::XmlFilterBase& rFilterBase,
const Reference < XText > & xText,
diff --git a/oox/source/drawingml/textbodypropertiescontext.cxx b/oox/source/drawingml/textbodypropertiescontext.cxx
index 13c50aa1b07a..1a15c6c77b62 100644
--- a/oox/source/drawingml/textbodypropertiescontext.cxx
+++ b/oox/source/drawingml/textbodypropertiescontext.cxx
@@ -73,7 +73,7 @@ TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper cons
// sal_Int32 nVertOverflow = rAttribs.getToken( XML_vertOverflow, XML_overflow );
// ST_TextColumnCount
-// sal_Int32 nNumCol = rAttribs.getInteger( XML_numCol, 1 );
+ mrTextBodyProp.mnNumCol = rAttribs.getInteger( XML_numCol, 1 );
// ST_Angle
mrTextBodyProp.moRotation = rAttribs.getInteger( XML_rot );
@@ -111,7 +111,7 @@ TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper cons
mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, drawing::TextFitToSizeType_NONE);
}
-ContextHandlerRef TextBodyPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& /*rAttribs*/)
+ContextHandlerRef TextBodyPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs)
{
switch( aElementToken )
{
@@ -125,9 +125,12 @@ ContextHandlerRef TextBodyPropertiesContext::onCreateContext( sal_Int32 aElement
mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false); // CT_TextNoAutofit
break;
case A_TOKEN( normAutofit ): // CT_TextNormalAutofit
+ {
mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, TextFitToSizeType_AUTOFIT);
mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
+ mrTextBodyProp.mnFontScale = rAttribs.getInteger(XML_fontScale, 100000);
break;
+ }
case A_TOKEN( spAutoFit ):
{
const sal_Int32 tVert = mrTextBodyProp.moVert.get( XML_horz );
diff --git a/oox/source/drawingml/textcharacterproperties.cxx b/oox/source/drawingml/textcharacterproperties.cxx
index b389d74c225f..ed110a1e3005 100644
--- a/oox/source/drawingml/textcharacterproperties.cxx
+++ b/oox/source/drawingml/textcharacterproperties.cxx
@@ -52,6 +52,7 @@ void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSource
maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
moHeight.assignIfUsed( rSourceProps.moHeight );
+ moFontScale.assignIfUsed(rSourceProps.moFontScale);
moSpacing.assignIfUsed( rSourceProps.moSpacing );
moUnderline.assignIfUsed( rSourceProps.moUnderline );
moBaseline.assignIfUsed( rSourceProps.moBaseline );
@@ -117,6 +118,8 @@ void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFil
if( moHeight.has() )
{
float fHeight = GetFontHeight( moHeight.get() );
+ if (moFontScale.has())
+ fHeight *= (moFontScale.get() / 100000);
rPropMap.setProperty( PROP_CharHeight, fHeight);
rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx
index e0cea6729fc2..1657e2a18a95 100644
--- a/oox/source/ppt/pptshape.cxx
+++ b/oox/source/ppt/pptshape.cxx
@@ -20,6 +20,7 @@
#include <oox/ppt/pptshape.hxx>
#include <oox/core/xmlfilterbase.hxx>
#include <drawingml/textbody.hxx>
+#include <drawingml/table/tableproperties.hxx>
#include <com/sun/star/awt/Rectangle.hpp>
#include <com/sun/star/container/XNamed.hpp>
@@ -223,6 +224,23 @@ void PPTShape::addShape(
}
}
+ if (sServiceName != "com.sun.star.drawing.TableShape")
+ {
+ if (TextBodyPtr pTextBody = getTextBody())
+ {
+ 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);
+ setTextBody(nullptr);
+ }
+ }
+ }
+
SAL_INFO("oox.ppt","shape service: " << sServiceName);
if (mnSubType && getSubTypeIndex().has() && meShapeLocation == Layout)
diff --git a/sd/qa/unit/data/pptx/tdf120028.pptx b/sd/qa/unit/data/pptx/tdf120028.pptx
new file mode 100644
index 000000000000..035c36730663
--- /dev/null
+++ b/sd/qa/unit/data/pptx/tdf120028.pptx
Binary files differ
diff --git a/sd/qa/unit/data/pptx/tdf120028b.pptx b/sd/qa/unit/data/pptx/tdf120028b.pptx
new file mode 100644
index 000000000000..7d50da36c120
--- /dev/null
+++ b/sd/qa/unit/data/pptx/tdf120028b.pptx
Binary files differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 8b4dea443a9d..942ac353f8a7 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -174,6 +174,8 @@ public:
bool checkPattern(sd::DrawDocShellRef const & rDocRef, int nShapeNumber, std::vector<sal_uInt8>& rExpected);
void testPatternImport();
void testTdf119015();
+ void testTdf120028();
+ void testTdf120028b();
CPPUNIT_TEST_SUITE(SdImportTest);
@@ -247,6 +249,8 @@ public:
CPPUNIT_TEST(testTdf51340);
CPPUNIT_TEST(testTdf116266);
CPPUNIT_TEST(testTdf119015);
+ CPPUNIT_TEST(testTdf120028);
+ CPPUNIT_TEST(testTdf120028b);
CPPUNIT_TEST_SUITE_END();
};
@@ -2355,6 +2359,79 @@ void SdImportTest::testTdf119015()
xDocShRef->DoClose();
}
+void SdImportTest::testTdf120028()
+{
+ // Check that the table shape has 4 columns.
+ ::sd::DrawDocShellRef xDocShRef
+ = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf120028.pptx"), PPTX);
+ uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(),
+ uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xDoc.is());
+
+ uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xPage.is());
+
+ // This failed, shape was not a table, all text was rendered in a single
+ // column.
+ uno::Reference<beans::XPropertySet> xShape(getShape(0, xPage));
+ uno::Reference<table::XColumnRowRange> xModel(xShape->getPropertyValue("Model"),
+ uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xModel.is());
+
+ uno::Reference<table::XTableColumns> xColumns = xModel->getColumns();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), xColumns->getCount());
+
+ // Check font size in the A1 cell.
+ uno::Reference<table::XCellRange> xCells(xModel, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xCell(xCells->getCellByPosition(0, 0), uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xParagraph(getParagraphFromShape(0, xCell));
+ uno::Reference<text::XTextRange> xRun(getRunFromParagraph(0, xParagraph));
+ uno::Reference<beans::XPropertySet> xPropSet(xRun, uno::UNO_QUERY);
+ double fCharHeight = 0;
+ xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
+ // This failed, non-scaled height was 13.5.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(11.5, fCharHeight, 1E-12);
+
+ xDocShRef->DoClose();
+}
+
+void SdImportTest::testTdf120028b()
+{
+ // Check that the table shape has 4 columns.
+ ::sd::DrawDocShellRef xDocShRef
+ = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf120028b.pptx"), PPTX);
+ uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(),
+ uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xDoc.is());
+
+ uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xPage.is());
+
+ uno::Reference<beans::XPropertySet> xShape(getShape(0, xPage));
+ CPPUNIT_ASSERT(xShape.is());
+
+ uno::Reference<table::XColumnRowRange> xModel(xShape->getPropertyValue("Model"),
+ uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xModel.is());
+
+ uno::Reference<table::XTableColumns> xColumns = xModel->getColumns();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), xColumns->getCount());
+
+ // Check font color in the A1 cell.
+ uno::Reference<table::XCellRange> xCells(xModel, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xCell(xCells->getCellByPosition(0, 0), uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xParagraph(getParagraphFromShape(0, xCell));
+ uno::Reference<text::XTextRange> xRun(getRunFromParagraph(0, xParagraph));
+ uno::Reference<beans::XPropertySet> xPropSet(xRun, uno::UNO_QUERY);
+ sal_Int32 nCharColor = 0;
+ xPropSet->getPropertyValue("CharColor") >>= nCharColor;
+ // This was 0x1f497d, not white: text list style from placeholder shape
+ // from slide layout was ignored.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xffffff), nCharColor);
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();