Kaydet (Commit) bbef85c1 authored tarafından Miklos Vajna's avatar Miklos Vajna

bnc#779620 DOCX import: try harder to convert floating tables to text frames

Since 78d1f1c2, 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.

Change-Id: Ic1fbceb54c8ec223ed01836fafe6220bb3b2410a
üst e85eadc8
......@@ -137,6 +137,7 @@ public:
void testDefaultSectBreakCols();
void testFdo69636();
void testChartProp();
void testBnc779620();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
......@@ -238,6 +239,7 @@ void Test::run()
{"default-sect-break-cols.docx", &Test::testDefaultSectBreakCols},
{"fdo69636.docx", &Test::testFdo69636},
{"chart-prop.docx", &Test::testChartProp},
{"bnc779620.docx", &Test::testBnc779620},
};
header();
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
......@@ -1584,6 +1586,14 @@ void Test::testChartProp()
CPPUNIT_ASSERT_EQUAL(sal_Int32(8886), getProperty<sal_Int32>(xPropertySet, "Height"));
}
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();
......
......@@ -824,19 +824,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)
{
......@@ -923,7 +911,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);
}
}
......
......@@ -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
......@@ -710,6 +726,8 @@ public:
/// If the next newline should be ignored, used by the special footnote separator paragraph.
bool m_bIgnoreNextPara;
bool m_bFrameBtLr; ///< Bottom to top, left to right text frame direction is requested for the current text frame.
/// Pending floating tables: they may be converted to text frames at the section end.
std::vector<FloatingTableInfo> m_aPendingFloatingTables;
};
} //namespace dmapper
} //namespace writerfilter
......
......@@ -877,6 +877,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 )
{
......
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