[PATCH] Fix the computation of grid character pitch, fdo#37516.

Jan Holesovsky kendy at suse.cz
Fri Jul 1 01:04:37 PDT 2011


---
 sw/source/filter/ww8/attributeoutputbase.hxx |    3 ++
 sw/source/filter/ww8/docxattributeoutput.cxx |   17 +---------
 sw/source/filter/ww8/ww8atr.cxx              |   47 +++++++++++++++++--------
 3 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx
index 25fc965..84e58f7 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -539,6 +539,9 @@ protected:
     /// Sfx item RES_KEEP
     virtual void FormatKeep( const SvxFmtKeepItem& ) = 0;
 
+    /// Compute the grid character pitch
+    sal_uInt32 GridCharacterPitch( const SwTextGridItem& rGrid ) const;
+
     /// Sfx item RES_TEXTGRID
     virtual void FormatTextGrid( const SwTextGridItem& ) = 0;
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 9fd3150..693549c 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4041,23 +4041,8 @@ void DocxAttributeOutput::FormatTextGrid( const SwTextGridItem& rGrid )
     pGridAttrList->add( FSNS( XML_w, XML_linePitch ),
             OString::valueOf( sal_Int32( nHeight ) ).getStr( ) );
 
-    MSWordStyles * pStyles = m_rExport.pStyles;
-    SwFmt * pSwFmt = pStyles->GetSwFmt();
-
-    sal_uInt32 nPageCharSize = 0;
-
-    if (pSwFmt != NULL)
-    {
-        nPageCharSize = ItemGet<SvxFontHeightItem>
-        (*pSwFmt, RES_CHRATR_FONTSIZE).GetHeight();
-    }
-
-    sal_uInt16 nPitch = rGrid.IsSquaredMode() ? rGrid.GetBaseHeight() :
-        rGrid.GetBaseWidth( );
-    sal_Int32 nCharSpace = ( nPitch - nPageCharSize ) * 4096 / 20;
-
     pGridAttrList->add( FSNS( XML_w, XML_charSpace ),
-            OString::valueOf( sal_Int32( nCharSpace ) ).getStr( ) );
+            OString::valueOf( sal_Int32( GridCharacterPitch( rGrid ) ) ).getStr( ) );
 
     m_pSerializer->singleElementNS( XML_w, XML_docGrid, pGridAttrList );
 }
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 63ee393..6e61641 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3641,6 +3641,37 @@ void WW8AttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* /*pSecti
     m_rWW8Export.ReplaceCr( nC );
 }
 
+sal_uInt32 AttributeOutputBase::GridCharacterPitch( const SwTextGridItem& rGrid ) const
+{
+    MSWordStyles * pStyles = GetExport().pStyles;
+    SwFmt * pSwFmt = pStyles->GetSwFmt();
+
+    sal_uInt32 nPageCharSize = 0;
+
+    if (pSwFmt != NULL)
+    {
+        nPageCharSize = ItemGet<SvxFontHeightItem>
+            (*pSwFmt, RES_CHRATR_FONTSIZE).GetHeight();
+    }
+    sal_uInt16 nPitch = rGrid.IsSquaredMode() ? rGrid.GetBaseHeight() :
+        rGrid.GetBaseWidth( );
+
+    sal_Int32 nCharWidth = nPitch - nPageCharSize;
+    sal_Int32 nFraction = nCharWidth % 20;
+    if ( nCharWidth < 0 )
+        nFraction = 20 + nFraction;
+    nFraction = ( nFraction * 0xFFF ) / 20;
+    nFraction = ( nFraction & 0x00000FFF );
+
+    sal_Int32 nMain = nCharWidth / 20;
+    if ( nCharWidth < 0 )
+        nMain -= 1;
+    nMain = nMain * 0x1000;
+    nMain = ( nMain & 0xFFFFF000 );
+
+    return sal_uInt32( nFraction + nMain );
+}
+
 void WW8AttributeOutput::FormatTextGrid( const SwTextGridItem& rGrid )
 {
     if ( m_rWW8Export.bOutPageDescs && m_rWW8Export.bWrtWW8 )
@@ -3670,22 +3701,8 @@ void WW8AttributeOutput::FormatTextGrid( const SwTextGridItem& rGrid )
         m_rWW8Export.InsUInt16( NS_sprm::LN_SDyaLinePitch );
         m_rWW8Export.InsUInt16( nHeight );
 
-        MSWordStyles * pStyles = m_rWW8Export.pStyles;
-        SwFmt * pSwFmt = pStyles->GetSwFmt();
-
-        sal_uInt32 nPageCharSize = 0;
-
-        if (pSwFmt != NULL)
-        {
-            nPageCharSize = ItemGet<SvxFontHeightItem>
-            (*pSwFmt, RES_CHRATR_FONTSIZE).GetHeight();
-        }
-        sal_uInt16 nPitch = rGrid.IsSquaredMode() ? rGrid.GetBaseHeight() :
-            rGrid.GetBaseWidth( );
-        sal_Int32 nCharSpace = ( nPitch - nPageCharSize ) * 4096 / 20;
-
         m_rWW8Export.InsUInt16( NS_sprm::LN_SDxtCharSpace );
-        m_rWW8Export.InsUInt32( nCharSpace );
+        m_rWW8Export.InsUInt32( GridCharacterPitch( rGrid ) );
     }
 }
 
-- 
1.7.5.4


--=-A9UF5Zz8fhzxDeeKomo4--



More information about the LibreOffice mailing list