[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - sw/qa writerfilter/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Oct 9 06:53:05 PDT 2013
sw/qa/extras/ooxmlimport/data/bnc779620.docx |binary
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 10 ++++++
writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 25 ++++++---------
writerfilter/source/dmapper/DomainMapper_Impl.hxx | 18 ++++++++++
writerfilter/source/dmapper/PropertyMap.cxx | 15 +++++++++
5 files changed, 54 insertions(+), 14 deletions(-)
New commits:
commit d41fc60d4443e3ff22ac3ef0e56cb9131cd49cc9
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Oct 1 16:57:56 2013 +0200
bnc#779620 DOCX import: try harder to convert floating tables to text frames
Since 78d1f1c2835b9fae0f91ed771fc1d594c7817502, we convert floating
tables to text frames only in case it's possible that there will be
wrapping, to give better results for multi-page tables, which are
multi-page, and technically floating ones, but that has no effect on the
layout.
The problem was that we try to do this decision too early, effectively
the page width and margins were counted from the default letter size,
instead of the actual values, which did not arrive at the time of the
decision. Fix this by moving this logic at the section end.
(cherry picked from commit bbef85c157169efa958ea1014d91d467cb243e6f)
Conflicts:
sw/qa/extras/ooxmlimport/ooxmlimport.cxx
writerfilter/source/dmapper/DomainMapper_Impl.hxx
Change-Id: Ic1fbceb54c8ec223ed01836fafe6220bb3b2410a
Reviewed-on: https://gerrit.libreoffice.org/6104
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/sw/qa/extras/ooxmlimport/data/bnc779620.docx b/sw/qa/extras/ooxmlimport/data/bnc779620.docx
new file mode 100644
index 0000000..23c126d
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/bnc779620.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 913cc16..2076c8c 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -134,6 +134,7 @@ public:
void testFdo68607();
void testVmlTextVerticalAdjust();
void testGroupshapeSdt();
+ void testBnc779620();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
@@ -233,6 +234,7 @@ void Test::run()
{"fdo68607.docx", &Test::testFdo68607},
{"vml-text-vertical-adjust.docx", &Test::testVmlTextVerticalAdjust},
{"groupshape-sdt.docx", &Test::testGroupshapeSdt},
+ {"bnc779620.docx", &Test::testBnc779620},
};
header();
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1642,6 +1644,14 @@ void Test::testGroupshapeSdt()
CPPUNIT_ASSERT_EQUAL(sal_Int32(20), getProperty<sal_Int32>(getRun(getParagraphOfText(1, xShape->getText()), 1), "CharKerning"));
}
+void Test::testBnc779620()
+{
+ // The problem was that the floating table was imported as a non-floating one.
+ uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 7d5c44e..b613c07 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -817,19 +817,7 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
uno::Reference<text::XTextRange> xStart;
uno::Reference<text::XTextRange> xEnd;
- bool bNoFly = false;
- if (SectionPropertyMap* pSectionContext = m_rDMapper_Impl.GetSectionContext())
- {
- sal_Int32 nTextAreaWidth = pSectionContext->GetPageWidth() - pSectionContext->GetLeftMargin() - pSectionContext->GetRightMargin();
- sal_Int32 nTableWidth = 0;
- m_aTableProperties->getValue( TablePropertyMap::TABLE_WIDTH, nTableWidth );
- // If the table is wider than the text area, then don't create a fly
- // for the table: no wrapping will be performed anyway, but multi-page
- // tables will be broken.
- bNoFly = nTableWidth >= nTextAreaWidth;
- }
-
- bool bFloating = aFrameProperties.hasElements() && !bNoFly;
+ bool bFloating = aFrameProperties.hasElements();
// Additional checks: if we can do this.
if (bFloating && (*m_pTableSeq)[0].getLength() > 0 && (*m_pTableSeq)[0][0].getLength() > 0)
{
@@ -916,7 +904,16 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
// A non-zero left margin would move the table out of the frame, move the frame itself instead.
xTableProperties->setPropertyValue("LeftMargin", uno::makeAny(sal_Int32(0)));
- uno::Reference< text::XTextContent > xFrame = m_xText->convertToTextFrame(xStart, xEnd, aFrameProperties);
+ // In case the document ends with a table, we're called after
+ // SectionPropertyMap::CloseSectionGroup(), so we'll have no idea
+ // about the text area width, nor can fix this by delaying the text
+ // frame conversion: just do it here.
+ sal_Int32 nTableWidth = 0;
+ m_aTableProperties->getValue(TablePropertyMap::TABLE_WIDTH, nTableWidth);
+ if (m_rDMapper_Impl.GetSectionContext())
+ m_rDMapper_Impl.m_aPendingFloatingTables.push_back(FloatingTableInfo(xStart, xEnd, aFrameProperties, nTableWidth));
+ else
+ m_xText->convertToTextFrame(xStart, xEnd, aFrameProperties);
}
}
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index c65d804..8bc422f 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -281,6 +281,22 @@ struct LineNumberSettings
};
+/// Contains information about a table that will be potentially converted to a floating one at the section end.
+struct FloatingTableInfo
+{
+ uno::Reference<text::XTextRange> m_xStart;
+ uno::Reference<text::XTextRange> m_xEnd;
+ uno::Sequence<beans::PropertyValue> m_aFrameProperties;
+ sal_Int32 m_nTableWidth;
+
+ FloatingTableInfo(uno::Reference<text::XTextRange> xStart, uno::Reference<text::XTextRange> xEnd, uno::Sequence<beans::PropertyValue> aFrameProperties, sal_Int32 nTableWidth)
+ : m_xStart(xStart),
+ m_xEnd(xEnd),
+ m_aFrameProperties(aFrameProperties),
+ m_nTableWidth(nTableWidth)
+ {
+ }
+};
class DomainMapper;
class WRITERFILTER_DLLPRIVATE DomainMapper_Impl
@@ -700,6 +716,8 @@ public:
* PFInTable SPRM or not).
*/
sal_Int32 m_nTableDepth;
+ /// Pending floating tables: they may be converted to text frames at the section end.
+ std::vector<FloatingTableInfo> m_aPendingFloatingTables;
};
} //namespace dmapper
} //namespace writerfilter
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 83868d4..3c4a470 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -845,6 +845,21 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl)
void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
{
+ // Text area width is known at the end of a section: decide if tables should be converted or not.
+ std::vector<FloatingTableInfo>& rPendingFloatingTables = rDM_Impl.m_aPendingFloatingTables;
+ sal_Int32 nTextAreaWidth = GetPageWidth() - GetLeftMargin() - GetRightMargin();
+ uno::Reference<text::XTextAppendAndConvert> xBodyText( rDM_Impl.GetBodyText(), uno::UNO_QUERY );
+ for (size_t i = 0; i < rPendingFloatingTables.size(); ++i)
+ {
+ FloatingTableInfo& rInfo = rPendingFloatingTables[i];
+ // If the table is wider than the text area, then don't create a fly
+ // for the table: no wrapping will be performed anyway, but multi-page
+ // tables will be broken.
+ if (rInfo.m_nTableWidth < nTextAreaWidth)
+ xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties);
+ }
+ rPendingFloatingTables.clear();
+
PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
if( m_nLnnMod )
{
More information about the Libreoffice-commits
mailing list