[Libreoffice-commits] core.git: writerfilter/source

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 1 12:42:03 UTC 2020


 writerfilter/source/dmapper/DomainMapper.cxx |   10 +++++---
 writerfilter/source/dmapper/PropertyMap.cxx  |   31 +++++++++++++--------------
 2 files changed, 22 insertions(+), 19 deletions(-)

New commits:
commit e6b0def979c8e6076f2548a2f4c376867c9e7fdc
Author:     Justin Luth <justin.luth at collabora.com>
AuthorDate: Sat Aug 1 10:11:30 2020 +0300
Commit:     Justin Luth <justin_luth at sil.org>
CommitDate: Sat Aug 1 14:41:27 2020 +0200

    NFC writerfilter: change m_nColumnCount to be the # of cols
    
    Change-Id: I00f6fea1ee93bf2598d0cfde73fb2de17f0eb379
    
    --- and not # of columns - 1.
    Life is already too confusing to add that complication to it.
    
    Not quite NFC. There is one place where a column
    count of 1 would have set column separator/space.
    I didn't think that would be necessary.
    
    Change-Id: I87a7bfb5e746e8b7e4c57ddf40b0740d0ef35aba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99930
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 1bec709d0f51..adb2f8359662 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2134,10 +2134,11 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
             pProperties->resolve(*pSectHdl);
             if(pSectionContext && !m_pImpl->isInIndexContext())
             {
+                sal_Int16 nColumnCount = pSectHdl->GetNum() == 1 ? 0 : pSectHdl->GetNum();
                 if( pSectHdl->IsEqualWidth() )
                 {
                     pSectionContext->SetEvenlySpaced( true );
-                    pSectionContext->SetColumnCount( static_cast<sal_Int16>(pSectHdl->GetNum() - 1) );
+                    pSectionContext->SetColumnCount( nColumnCount );
                     pSectionContext->SetColumnDistance( pSectHdl->GetSpace() );
                     pSectionContext->SetSeparatorLine( pSectHdl->IsSeparator() );
                 }
@@ -2145,7 +2146,8 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
                 {
                     pSectionContext->SetEvenlySpaced( false );
                     pSectionContext->SetColumnDistance( pSectHdl->GetSpace() );
-                    pSectionContext->SetColumnCount( static_cast<sal_Int16>(pSectHdl->GetColumns().size() -1));
+                    nColumnCount = pSectHdl->GetColumns().size();
+                    pSectionContext->SetColumnCount( nColumnCount == 1 ? 0 : nColumnCount );
                     std::vector<Column_>::const_iterator tmpIter = pSectHdl->GetColumns().begin();
                     for (; tmpIter != pSectHdl->GetColumns().end(); ++tmpIter)
                     {
@@ -2155,9 +2157,9 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
                     }
                     pSectionContext->SetSeparatorLine( pSectHdl->IsSeparator() );
                 }
-                else if( pSectHdl->GetNum() > 0 )
+                else if( nColumnCount )
                 {
-                    pSectionContext->SetColumnCount( static_cast<sal_Int16>(pSectHdl->GetNum()) - 1 );
+                    pSectionContext->SetColumnCount( nColumnCount );
                     pSectionContext->SetColumnDistance( pSectHdl->GetSpace() );
                     pSectionContext->SetSeparatorLine( pSectHdl->IsSeparator() );
                 }
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 44e34fad585c..5f8d9a906ba3 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -721,6 +721,7 @@ uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties(
                                                                                 DomainMapper_Impl& rDM_Impl )
 {
     uno::Reference< text::XTextColumns > xColumns;
+    assert( m_nColumnCount > 1 && "ApplyColumnProperties called without any columns" );
     try
     {
         const OUString sTextColumns = getPropertyName( PROP_TEXT_COLUMNS );
@@ -728,13 +729,13 @@ uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties(
             xColumnContainer->getPropertyValue( sTextColumns ) >>= xColumns;
         uno::Reference< beans::XPropertySet > xColumnPropSet( xColumns, uno::UNO_QUERY_THROW );
         if ( !m_bEvenlySpaced &&
-             ( sal_Int32(m_aColWidth.size()) == (m_nColumnCount + 1) ) &&
-             ( (sal_Int32(m_aColDistance.size()) == m_nColumnCount) || (sal_Int32(m_aColDistance.size()) == m_nColumnCount + 1) ) )
+             ( sal_Int32(m_aColWidth.size()) == m_nColumnCount ) &&
+             ( (sal_Int32(m_aColDistance.size()) == m_nColumnCount - 1) || (sal_Int32(m_aColDistance.size()) == m_nColumnCount) ) )
         {
             // the column width in word is an absolute value, in OOo it's relative
             // the distances are both absolute
             sal_Int32 nColSum = 0;
-            for ( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol )
+            for ( sal_Int32 nCol = 0; nCol < m_nColumnCount; ++nCol )
             {
                 nColSum += m_aColWidth[nCol];
                 if ( nCol )
@@ -743,29 +744,29 @@ uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties(
 
             sal_Int32 nRefValue = xColumns->getReferenceValue();
             double fRel = nColSum ? double( nRefValue ) / double( nColSum ) : 0.0;
-            uno::Sequence< text::TextColumn > aColumns( m_nColumnCount + 1 );
+            uno::Sequence< text::TextColumn > aColumns( m_nColumnCount );
             text::TextColumn* pColumn = aColumns.getArray();
 
             nColSum = 0;
-            for ( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol )
+            for ( sal_Int32 nCol = 0; nCol < m_nColumnCount; ++nCol )
             {
                 const double fLeft = nCol ? m_aColDistance[nCol - 1] / 2 : 0;
                 pColumn[nCol].LeftMargin = fLeft;
-                const double fRight = nCol == m_nColumnCount ? 0 : m_aColDistance[nCol] / 2;
+                const double fRight = (nCol == m_nColumnCount - 1) ? 0 : m_aColDistance[nCol] / 2;
                 pColumn[nCol].RightMargin = fRight;
                 const double fWidth = m_aColWidth[nCol];
                 pColumn[nCol].Width = (fWidth + fLeft + fRight) * fRel;
                 nColSum += pColumn[nCol].Width;
             }
             if ( nColSum != nRefValue )
-                pColumn[m_nColumnCount].Width += (nRefValue - nColSum);
-            assert( pColumn[m_nColumnCount].Width >= 0 );
+                pColumn[m_nColumnCount - 1].Width += (nRefValue - nColSum);
+            assert( pColumn[m_nColumnCount - 1].Width >= 0 );
 
             xColumns->setColumns( aColumns );
         }
         else
         {
-            xColumns->setColumnCount( m_nColumnCount + 1 );
+            xColumns->setColumnCount( m_nColumnCount );
             xColumnPropSet->setPropertyValue( getPropertyName( PROP_AUTOMATIC_DISTANCE ), uno::makeAny( m_nColumnDistance ) );
         }
 
@@ -1189,7 +1190,7 @@ bool SectionPropertyMap::FloatingTableConversion( const DomainMapper_Impl& rDM_I
 
     // If there are columns, always create the fly, otherwise the columns would
     // restrict geometry of the table.
-    if ( ColumnCount() + 1 >= 2 )
+    if ( ColumnCount() > 1 )
         return true;
 
     return false;
@@ -1416,7 +1417,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
             rDM_Impl.appendTextSectionAfter( m_xStartingRange );
         if ( xSection.is() )
         {
-            if ( m_nColumnCount > 0 )
+            if ( m_nColumnCount > 1 )
                 ApplyColumnProperties( xSection, rDM_Impl );
 
             ApplyProtectionProperties( xSection, rDM_Impl );
@@ -1515,7 +1516,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
     // But only if there actually are columns on the page, otherwise a column break
     // seems to be handled like a page break by MSO.
     else if (m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_nextColumn)
-            && 0 < m_nColumnCount && !rDM_Impl.IsInComments())
+            && m_nColumnCount > 1 && !rDM_Impl.IsInComments())
     {
         try
         {
@@ -1549,7 +1550,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
             Insert( PROP_PAGE_STYLE_LAYOUT, uno::makeAny( style::PageStyleLayout_MIRRORED ) );
         }
         uno::Reference< text::XTextColumns > xColumns;
-        if ( m_nColumnCount > 0 )
+        if ( m_nColumnCount > 1 )
         {
             // prefer setting column properties into a section, not a page style if at all possible.
             if ( !xSection.is() )
@@ -1744,13 +1745,13 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
 
     // Now that the margins are known, resize relative width shapes because some shapes in LO do not support percentage-sizes
     sal_Int32 nParagraphWidth = GetPageWidth() - m_nLeftMargin - m_nRightMargin;
-    if ( m_nColumnCount > 0 )
+    if ( m_nColumnCount > 1 )
     {
         // skip custom-width columns since we don't know what column the shape is in.
         if ( !m_aColWidth.empty() )
             nParagraphWidth = 0;
         else
-            nParagraphWidth = (nParagraphWidth - (m_nColumnDistance * m_nColumnCount)) / (m_nColumnCount + 1);
+            nParagraphWidth = (nParagraphWidth - (m_nColumnDistance * (m_nColumnCount - 1))) / m_nColumnCount;
     }
     if ( nParagraphWidth > 0 )
     {


More information about the Libreoffice-commits mailing list