summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2013-10-01 16:57:56 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-10-01 17:28:18 +0200
commitbbef85c157169efa958ea1014d91d467cb243e6f (patch)
tree0160faef29a7ef7bf33b4b37e8bcdc307e4d7f29 /writerfilter
parente85eadc888285a42561cc52133172cf5f4317da2 (diff)
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. Change-Id: Ic1fbceb54c8ec223ed01836fafe6220bb3b2410a
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableHandler.cxx25
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx18
-rw-r--r--writerfilter/source/dmapper/PropertyMap.cxx15
3 files changed, 44 insertions, 14 deletions
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index b32351ac3c80..f65cfcae52c4 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -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);
}
}
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 9210184b47c2..fc2c7c220cb1 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
@@ -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
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 86382bbf7fb2..c016a41aadb4 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -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 )
{