diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-04-07 16:47:23 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-04-07 15:54:41 +0000 |
commit | d56deaeb2a1e8007e50fc2334f416fddd4e3cde3 (patch) | |
tree | 801843c261f4cd10802371dfbeaa31749a779887 | |
parent | 92e33ae10d63b5acd8643d33c032dbb022bd75be (diff) |
tdf#99140 Factor out FloatingTableConversion() from CloseSectionGroup()
No logic changes intended, but makes it easier to add new rules when
making the decision.
Change-Id: I84d8e6a2b8a4b9ae6fe5cefd381292c2f68be45f
Reviewed-on: https://gerrit.libreoffice.org/23901
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 55 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.hxx | 3 |
2 files changed, 39 insertions, 19 deletions
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 56e99b6d2d1d..ff8e5f39614e 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1038,34 +1038,51 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl) PrepareHeaderFooterProperties( false ); } +bool SectionPropertyMap::FloatingTableConversion(FloatingTableInfo& rInfo) +{ + // Note that this is just a list of heuristics till sw core can have a + // table that is floating and can span over multiple pages at the same + // time. + + sal_Int32 nTextAreaWidth = GetPageWidth() - GetLeftMargin() - GetRightMargin(); + // Count the layout width of the table. + sal_Int32 nTableWidth = rInfo.m_nTableWidth; + sal_Int32 nLeftMargin = 0; + if (rInfo.getPropertyValue("LeftMargin") >>= nLeftMargin) + nTableWidth += nLeftMargin; + sal_Int32 nRightMargin = 0; + if (rInfo.getPropertyValue("RightMargin") >>= nRightMargin) + nTableWidth += nRightMargin; + + // 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 (nTableWidth < nTextAreaWidth) + return true; + + // If the position is relative to the edge of the page, then we always + // create the fly. + if (rInfo.getPropertyValue("HoriOrientRelation") == text::RelOrientation::PAGE_FRAME) + return true; + + // If there are columns, always create the fly, otherwise the columns would + // restrict geometry of the table. + if (ColumnCount() + 1 >= 2) + return true; + + return false; +} + 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]; - // Count the layout width of the table. - sal_Int32 nTableWidth = rInfo.m_nTableWidth; - sal_Int32 nLeftMargin = 0; - if (rInfo.getPropertyValue("LeftMargin") >>= nLeftMargin) - nTableWidth += nLeftMargin; - sal_Int32 nRightMargin = 0; - if (rInfo.getPropertyValue("RightMargin") >>= nRightMargin) - nTableWidth += nRightMargin; - - // 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 the position is relative to the edge of the page, then we always - // create the fly. - // If there are columns, always create the fly, otherwise the columns would - // restrict geometry of the table. - if ( ( rInfo.getPropertyValue("HoriOrientRelation") == text::RelOrientation::PAGE_FRAME ) || - nTableWidth < nTextAreaWidth || ColumnCount() + 1 >= 2 ) + if (FloatingTableConversion(rInfo)) xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties); } rPendingFloatingTables.clear(); diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index a3a9be176ebf..ac2b8b53b3ac 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -57,6 +57,7 @@ namespace com{namespace sun{namespace star{ namespace writerfilter { namespace dmapper{ class DomainMapper_Impl; +struct FloatingTableInfo; enum BorderPosition { @@ -267,6 +268,8 @@ class SectionPropertyMap : public PropertyMap sal_Int32 nDistance, sal_Int32 nOffsetFrom, sal_uInt32 nLineWidth); + /// Determintes if conversion of a given floating table is wanted or not. + bool FloatingTableConversion(FloatingTableInfo& rInfo); public: explicit SectionPropertyMap(bool bIsFirstSection); |