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

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/23901Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 92e33ae1
...@@ -1038,34 +1038,51 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl) ...@@ -1038,34 +1038,51 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl)
PrepareHeaderFooterProperties( false ); 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 ) 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. // 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; 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 ); uno::Reference<text::XTextAppendAndConvert> xBodyText( rDM_Impl.GetBodyText(), uno::UNO_QUERY );
for (size_t i = 0; i < rPendingFloatingTables.size(); ++i) for (size_t i = 0; i < rPendingFloatingTables.size(); ++i)
{ {
FloatingTableInfo& rInfo = rPendingFloatingTables[i]; FloatingTableInfo& rInfo = rPendingFloatingTables[i];
// Count the layout width of the table. if (FloatingTableConversion(rInfo))
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 )
xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties); xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties);
} }
rPendingFloatingTables.clear(); rPendingFloatingTables.clear();
......
...@@ -57,6 +57,7 @@ namespace com{namespace sun{namespace star{ ...@@ -57,6 +57,7 @@ namespace com{namespace sun{namespace star{
namespace writerfilter { namespace writerfilter {
namespace dmapper{ namespace dmapper{
class DomainMapper_Impl; class DomainMapper_Impl;
struct FloatingTableInfo;
enum BorderPosition enum BorderPosition
{ {
...@@ -267,6 +268,8 @@ class SectionPropertyMap : public PropertyMap ...@@ -267,6 +268,8 @@ class SectionPropertyMap : public PropertyMap
sal_Int32 nDistance, sal_Int32 nDistance,
sal_Int32 nOffsetFrom, sal_Int32 nOffsetFrom,
sal_uInt32 nLineWidth); sal_uInt32 nLineWidth);
/// Determintes if conversion of a given floating table is wanted or not.
bool FloatingTableConversion(FloatingTableInfo& rInfo);
public: public:
explicit SectionPropertyMap(bool bIsFirstSection); explicit SectionPropertyMap(bool bIsFirstSection);
......
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