diff options
Diffstat (limited to 'writerfilter/source/dmapper/PropertyMap.cxx')
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 78 |
1 files changed, 59 insertions, 19 deletions
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index ad06b9eee043..d2e1b41801e8 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -36,6 +36,8 @@ #include <com/sun/star/style/XStyle.hpp> #include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/text/RelOrientation.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> #include <com/sun/star/text/WritingMode.hpp> #include <com/sun/star/text/XTextColumns.hpp> #include <com/sun/star/text/XText.hpp> @@ -1021,34 +1023,72 @@ 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 nPageWidth = GetPageWidth(); + sal_Int32 nTextAreaWidth = nPageWidth - 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; + + sal_Int16 nHoriOrientRelation = rInfo.getPropertyValue("HoriOrientRelation").get<sal_Int16>(); + sal_Int16 nVertOrientRelation = rInfo.getPropertyValue("VertOrientRelation").get<sal_Int16>(); + if (nHoriOrientRelation == text::RelOrientation::PAGE_FRAME && nVertOrientRelation == text::RelOrientation::PAGE_FRAME) + { + sal_Int16 nHoriOrient = rInfo.getPropertyValue("HoriOrient").get<sal_Int16>(); + sal_Int16 nVertOrient = rInfo.getPropertyValue("VertOrient").get<sal_Int16>(); + if (nHoriOrient == text::HoriOrientation::NONE && nVertOrient == text::VertOrientation::NONE) + { + // Anchor position is relative to the page horizontally and vertically as well and is an absolute position. + // The more close we are to the left edge, the less likely there will be any wrapping. + // The more close we are to the bottom, the more likely the table will span over to the next page + // So if we're in the bottom left quarter, don't do any conversion. + sal_Int32 nHoriOrientPosition = rInfo.getPropertyValue("HoriOrientPosition").get<sal_Int32>(); + sal_Int32 nVertOrientPosition = rInfo.getPropertyValue("VertOrientPosition").get<sal_Int32>(); + sal_Int32 nPageHeight = getProperty(PROP_HEIGHT)->second.get<sal_Int32>(); + if (nHoriOrientPosition < (nPageWidth / 2) && nVertOrientPosition > (nPageHeight / 2)) + return false; + } + } + + // 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(); |