Kaydet (Commit) 167d4a99 authored tarafından Patrick Jaap's avatar Patrick Jaap Kaydeden (comit) Miklos Vajna

Fix: Use correct relative table width in docx export

It removes the HACK where the doc model was changed.
We introduce a pointer to a surrounding frame: an indicator
telling us that the table was placed in a frame to make it
floating.

During export, remove the frame and use the relative width of the
surrounding frame.

Change-Id: I43b45d9a9e67ee755782c9f18df22ae1d4014689
Reviewed-on: https://gerrit.libreoffice.org/67775
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
üst f7643f5a
...@@ -138,6 +138,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf116371, "tdf116371.odt") ...@@ -138,6 +138,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf116371, "tdf116371.odt")
CPPUNIT_ASSERT_EQUAL(sal_Int32(24188), frameRect.Width); CPPUNIT_ASSERT_EQUAL(sal_Int32(24188), frameRect.Width);
} }
DECLARE_OOXMLEXPORT_TEST(testFrameSizeExport, "floating-tables-anchor.docx")
{
// Make sure the table width is 4000
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl[1]/w:tblPr/w:tblW", "w", "4000");
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -61,6 +61,7 @@ public: ...@@ -61,6 +61,7 @@ public:
void testTdf122942(); void testTdf122942();
void testTdf52391(); void testTdf52391();
void testTdf101873(); void testTdf101873();
void testTableWidth();
CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST_SUITE(SwUiWriterTest2);
CPPUNIT_TEST(testRedlineMoveInsertInDelete); CPPUNIT_TEST(testRedlineMoveInsertInDelete);
...@@ -83,6 +84,7 @@ public: ...@@ -83,6 +84,7 @@ public:
CPPUNIT_TEST(testTdf122942); CPPUNIT_TEST(testTdf122942);
CPPUNIT_TEST(testTdf52391); CPPUNIT_TEST(testTdf52391);
CPPUNIT_TEST(testTdf101873); CPPUNIT_TEST(testTdf101873);
CPPUNIT_TEST(testTableWidth);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
...@@ -914,6 +916,23 @@ void SwUiWriterTest2::testTdf101873() ...@@ -914,6 +916,23 @@ void SwUiWriterTest2::testTdf101873()
CPPUNIT_ASSERT_EQUAL(OUString("something"), pShellCursor->GetText()); CPPUNIT_ASSERT_EQUAL(OUString("something"), pShellCursor->GetText());
} }
void SwUiWriterTest2::testTableWidth()
{
load(DATA_DIRECTORY, "frame_size_export.docx");
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text");
xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
// after exporting: table width was overwritten in the doc model
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int16(100),
getProperty<sal_Int16>(xTables->getByIndex(0), "RelativeWidth"));
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -330,10 +330,14 @@ void DocxAttributeOutput::WriteFloatingTable(ww8::Frame const* pParentFrame) ...@@ -330,10 +330,14 @@ void DocxAttributeOutput::WriteFloatingTable(ww8::Frame const* pParentFrame)
//Save data here and restore when out of scope //Save data here and restore when out of scope
ExportDataSaveRestore aDataGuard(GetExport(), nStt, nEnd, pParentFrame); ExportDataSaveRestore aDataGuard(GetExport(), nStt, nEnd, pParentFrame);
// unset parent frame, otherwise exporter thinks we are still in a frame // set a floatingTableFrame AND unset parent frame,
// otherwise exporter thinks we are still in a frame
m_rExport.SetFloatingTableFrame(pParentFrame);
m_rExport.m_pParentFrame = nullptr; m_rExport.m_pParentFrame = nullptr;
GetExport().WriteText(); GetExport().WriteText();
m_rExport.SetFloatingTableFrame(nullptr);
} }
static void checkAndWriteFloatingTables(DocxAttributeOutput& rDocxAttributeOutput) static void checkAndWriteFloatingTables(DocxAttributeOutput& rDocxAttributeOutput)
...@@ -383,15 +387,7 @@ static void checkAndWriteFloatingTables(DocxAttributeOutput& rDocxAttributeOutpu ...@@ -383,15 +387,7 @@ static void checkAndWriteFloatingTables(DocxAttributeOutput& rDocxAttributeOutpu
if (aTableGrabBag.find("TablePosition") == aTableGrabBag.end()) if (aTableGrabBag.find("TablePosition") == aTableGrabBag.end())
continue; continue;
// overwrite the table size from the surrounding frame format // write table to docx
// TODO remove this de-const HACK
const SwFormatFrameSize& aFramesize = pFrameFormat->GetFrameSize();
SwFormatFrameSize* pFormatFrameSize = const_cast<SwFormatFrameSize*>(&pTableFormat->GetFrameSize());
if(pFormatFrameSize)
{
*pFormatFrameSize = aFramesize;
}
ww8::Frame aFrame(*pFrameFormat,*pPosition); ww8::Frame aFrame(*pFrameFormat,*pPosition);
rDocxAttributeOutput.WriteFloatingTable(&aFrame); rDocxAttributeOutput.WriteFloatingTable(&aFrame);
} }
...@@ -3702,6 +3698,13 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t ...@@ -3702,6 +3698,13 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t
SwFrameFormat *pTableFormat = pTable->GetFrameFormat( ); SwFrameFormat *pTableFormat = pTable->GetFrameFormat( );
const SwFormatFrameSize &rSize = pTableFormat->GetFrameSize(); const SwFormatFrameSize &rSize = pTableFormat->GetFrameSize();
int nWidthPercent = rSize.GetWidthPercent(); int nWidthPercent = rSize.GetWidthPercent();
// If we export a floating table: we use the widthPercent of the surrounding frame
const ww8::Frame* pFloatingTableFrame = m_rExport.GetFloatingTableFrame();
if (pFloatingTableFrame)
{
const SwFormatFrameSize &rFrameSize = pFloatingTableFrame->GetFrameFormat().GetFrameSize();
nWidthPercent = rFrameSize.GetWidthPercent();
}
uno::Reference<beans::XPropertySet> xPropertySet(SwXTextTables::GetObject(*pTable->GetFrameFormat( )),uno::UNO_QUERY); uno::Reference<beans::XPropertySet> xPropertySet(SwXTextTables::GetObject(*pTable->GetFrameFormat( )),uno::UNO_QUERY);
bool isWidthRelative = false; bool isWidthRelative = false;
xPropertySet->getPropertyValue("IsWidthRelative") >>= isWidthRelative; xPropertySet->getPropertyValue("IsWidthRelative") >>= isWidthRelative;
......
...@@ -113,11 +113,16 @@ class DocxExport : public MSWordExportBase ...@@ -113,11 +113,16 @@ class DocxExport : public MSWordExportBase
DocxSettingsData m_aSettings; DocxSettingsData m_aSettings;
/// Pointer to the Frame of a floating table it is nested in
const ww8::Frame *m_pFloatingTableFrame = nullptr;
public: public:
DocxExportFilter& GetFilter() { return *m_pFilter; }; DocxExportFilter& GetFilter() { return *m_pFilter; };
const DocxExportFilter& GetFilter() const { return *m_pFilter; }; const DocxExportFilter& GetFilter() const { return *m_pFilter; };
const ww8::Frame* GetFloatingTableFrame() { return m_pFloatingTableFrame; }
/// Access to the attribute output class. /// Access to the attribute output class.
virtual AttributeOutputBase& AttrOutput() const override; virtual AttributeOutputBase& AttrOutput() const override;
...@@ -287,6 +292,8 @@ public: ...@@ -287,6 +292,8 @@ public:
void SetFS(::sax_fastparser::FSHelperPtr const & mpFS); void SetFS(::sax_fastparser::FSHelperPtr const & mpFS);
void SetFloatingTableFrame(const ww8::Frame* pF) { m_pFloatingTableFrame = pF; }
private: private:
DocxExport( const DocxExport& ) = delete; DocxExport( const DocxExport& ) = delete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment